Add -Werror flag to catch more warnings and errors

Change-Id: I9c39ba24578931944aae8182918ed48a2e82eb39
main
Ken Wakasa 2011-03-19 09:16:42 +09:00
parent 0a7cf81ca2
commit de3070a71b
5 changed files with 73 additions and 27 deletions

View File

@ -3,6 +3,11 @@ include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
LOCAL_CFLAGS += -Werror -Wall
# To suppress compiler warnings for unused variables/functions used for debug features etc.
LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
LOCAL_SRC_FILES := \
jni/com_android_inputmethod_keyboard_ProximityInfo.cpp \
jni/com_android_inputmethod_latin_BinaryDictionary.cpp \

View File

@ -30,8 +30,10 @@ BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength,
: DICT(dict), MAX_WORD_LENGTH(maxWordLength),
MAX_ALTERNATIVES(maxAlternatives), IS_LATEST_DICT_VERSION(isLatestDictVersion),
HAS_BIGRAM(hasBigram), mParentDictionary(parentDictionary) {
if (DEBUG_DICT) LOGI("BigramDictionary - constructor");
if (DEBUG_DICT) LOGI("Has Bigram : %d", hasBigram);
if (DEBUG_DICT) {
LOGI("BigramDictionary - constructor");
LOGI("Has Bigram : %d", hasBigram);
}
}
BigramDictionary::~BigramDictionary() {
@ -54,7 +56,9 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
}
insertAt++;
}
if (DEBUG_DICT) LOGI("Bigram: InsertAt -> %d maxBigrams: %d", insertAt, mMaxBigrams);
if (DEBUG_DICT) {
LOGI("Bigram: InsertAt -> %d maxBigrams: %d", insertAt, mMaxBigrams);
}
if (insertAt < mMaxBigrams) {
memmove((char*) mBigramFreq + (insertAt + 1) * sizeof(mBigramFreq[0]),
(char*) mBigramFreq + insertAt * sizeof(mBigramFreq[0]),
@ -68,7 +72,9 @@ bool BigramDictionary::addWordBigram(unsigned short *word, int length, int frequ
*dest++ = *word++;
}
*dest = 0; // NULL terminate
if (DEBUG_DICT) LOGI("Bigram: Added word at %d", insertAt);
if (DEBUG_DICT) {
LOGI("Bigram: Added word at %d", insertAt);
}
return true;
}
return false;
@ -107,7 +113,9 @@ int BigramDictionary::getBigrams(unsigned short *prevWord, int prevWordLength, i
if (HAS_BIGRAM && IS_LATEST_DICT_VERSION) {
int pos = mParentDictionary->isValidWordRec(
DICTIONARY_HEADER_SIZE, prevWord, 0, prevWordLength);
if (DEBUG_DICT) LOGI("Pos -> %d", pos);
if (DEBUG_DICT) {
LOGI("Pos -> %d", pos);
}
if (pos < 0) {
return 0;
}
@ -151,7 +159,9 @@ void BigramDictionary::searchForTerminalNode(int addressLookingFor, int frequenc
}
pos = followDownBranchAddress; // pos start at count
int count = DICT[pos] & 0xFF;
if (DEBUG_DICT) LOGI("count - %d",count);
if (DEBUG_DICT) {
LOGI("count - %d",count);
}
pos++;
for (int i = 0; i < count; i++) {
// pos at data
@ -225,7 +235,9 @@ void BigramDictionary::searchForTerminalNode(int addressLookingFor, int frequenc
}
depth++;
if (followDownBranchAddress == 0) {
if (DEBUG_DICT) LOGI("ERROR!!! Cannot find bigram!!");
if (DEBUG_DICT) {
LOGI("ERROR!!! Cannot find bigram!!");
}
break;
}
}

View File

@ -77,8 +77,8 @@ static void prof_out(void) {
}
#else // FLAG_DBG
#define LOGE
#define LOGI
#define LOGE(fmt, ...)
#define LOGI(fmt, ...)
#define DEBUG_DICT false
#define DEBUG_DICT_FULL false
#define DEBUG_SHOW_FOUND_WORD false

View File

@ -32,13 +32,13 @@ public:
bool hasSpaceProximity(const int x, const int y) const;
private:
int getStartIndexFromCoordinates(const int x, const int y) const;
const int CELL_WIDTH;
const int CELL_HEIGHT;
const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH;
const int KEYBOARD_HEIGHT;
const int GRID_WIDTH;
const int GRID_HEIGHT;
const int MAX_PROXIMITY_CHARS_SIZE;
const int CELL_WIDTH;
const int CELL_HEIGHT;
uint32_t *mProximityCharsArray;
};
}; // namespace latinime

View File

@ -43,7 +43,9 @@ UnigramDictionary::UnigramDictionary(const unsigned char *dict, int typedLetterM
ROOT_POS(isLatestDictVersion ? DICTIONARY_HEADER_SIZE : 0),
BYTES_IN_ONE_CHAR(MAX_PROXIMITY_CHARS * sizeof(*mInputCodes)),
MAX_UMLAUT_SEARCH_DEPTH(DEFAULT_MAX_UMLAUT_SEARCH_DEPTH) {
if (DEBUG_DICT) LOGI("UnigramDictionary - constructor");
if (DEBUG_DICT) {
LOGI("UnigramDictionary - constructor");
}
}
UnigramDictionary::~UnigramDictionary() {}
@ -183,7 +185,9 @@ void UnigramDictionary::getWordSuggestions(const ProximityInfo *proximityInfo,
// Suggestion with missing character
if (SUGGEST_WORDS_WITH_MISSING_CHARACTER) {
for (int i = 0; i < codesSize; ++i) {
if (DEBUG_DICT) LOGI("--- Suggest missing characters %d", i);
if (DEBUG_DICT) {
LOGI("--- Suggest missing characters %d", i);
}
getSuggestionCandidates(i, -1, -1, NULL, 0, MAX_DEPTH);
}
}
@ -194,7 +198,9 @@ void UnigramDictionary::getWordSuggestions(const ProximityInfo *proximityInfo,
if (SUGGEST_WORDS_WITH_EXCESSIVE_CHARACTER
&& mInputLength >= MIN_USER_TYPED_LENGTH_FOR_EXCESSIVE_CHARACTER_SUGGESTION) {
for (int i = 0; i < codesSize; ++i) {
if (DEBUG_DICT) LOGI("--- Suggest excessive characters %d", i);
if (DEBUG_DICT) {
LOGI("--- Suggest excessive characters %d", i);
}
getSuggestionCandidates(-1, i, -1, NULL, 0, MAX_DEPTH);
}
}
@ -205,7 +211,9 @@ void UnigramDictionary::getWordSuggestions(const ProximityInfo *proximityInfo,
// Only suggest words that length is mInputLength
if (SUGGEST_WORDS_WITH_TRANSPOSED_CHARACTERS) {
for (int i = 0; i < codesSize; ++i) {
if (DEBUG_DICT) LOGI("--- Suggest transposed characters %d", i);
if (DEBUG_DICT) {
LOGI("--- Suggest transposed characters %d", i);
}
getSuggestionCandidates(-1, -1, i, NULL, 0, mInputLength - 1);
}
}
@ -216,7 +224,9 @@ void UnigramDictionary::getWordSuggestions(const ProximityInfo *proximityInfo,
if (SUGGEST_WORDS_WITH_MISSING_SPACE_CHARACTER
&& mInputLength >= MIN_USER_TYPED_LENGTH_FOR_MISSING_SPACE_SUGGESTION) {
for (int i = 1; i < codesSize; ++i) {
if (DEBUG_DICT) LOGI("--- Suggest missing space characters %d", i);
if (DEBUG_DICT) {
LOGI("--- Suggest missing space characters %d", i);
}
getMissingSpaceWords(mInputLength, i);
}
}
@ -226,12 +236,15 @@ void UnigramDictionary::getWordSuggestions(const ProximityInfo *proximityInfo,
if (SUGGEST_WORDS_WITH_SPACE_PROXIMITY) {
// The first and last "mistyped spaces" are taken care of by excessive character handling
for (int i = 1; i < codesSize - 1; ++i) {
if (DEBUG_DICT) LOGI("--- Suggest words with proximity space %d", i);
if (DEBUG_DICT) {
LOGI("--- Suggest words with proximity space %d", i);
}
const int x = xcoordinates[i];
const int y = ycoordinates[i];
if (DEBUG_PROXIMITY_INFO)
if (DEBUG_PROXIMITY_INFO) {
LOGI("Input[%d] x = %d, y = %d, has space proximity = %d",
i, x, y, proximityInfo->hasSpaceProximity(x, y));
}
if (proximityInfo->hasSpaceProximity(x, y)) {
getMistypedSpaceWords(mInputLength, i);
}
@ -242,7 +255,9 @@ void UnigramDictionary::getWordSuggestions(const ProximityInfo *proximityInfo,
void UnigramDictionary::initSuggestions(const int *codes, const int codesSize,
unsigned short *outWords, int *frequencies) {
if (DEBUG_DICT) LOGI("initSuggest");
if (DEBUG_DICT) {
LOGI("initSuggest");
}
mFrequencies = frequencies;
mOutputChars = outWords;
mInputCodes = codes;
@ -266,7 +281,9 @@ bool UnigramDictionary::addWord(unsigned short *word, int length, int frequency)
LOGI("Found word = %s, freq = %d", s, frequency);
}
if (length > MAX_WORD_LENGTH) {
if (DEBUG_DICT) LOGI("Exceeded max word length.");
if (DEBUG_DICT) {
LOGI("Exceeded max word length.");
}
return false;
}
@ -297,7 +314,9 @@ bool UnigramDictionary::addWord(unsigned short *word, int length, int frequency)
*dest++ = *word++;
}
*dest = 0; // NULL terminate
if (DEBUG_DICT) LOGI("Added word at %d", insertAt);
if (DEBUG_DICT) {
LOGI("Added word at %d", insertAt);
}
return true;
}
return false;
@ -409,7 +428,9 @@ bool UnigramDictionary::getSplitTwoWordsSuggestion(const int inputLength,
// Allocating variable length array on stack
unsigned short word[newWordLength];
const int firstFreq = getBestWordFreq(firstWordStartPos, firstWordLength, mWord);
if (DEBUG_DICT) LOGI("First freq: %d", firstFreq);
if (DEBUG_DICT) {
LOGI("First freq: %d", firstFreq);
}
if (firstFreq <= 0) return false;
for (int i = 0; i < firstWordLength; ++i) {
@ -417,7 +438,9 @@ bool UnigramDictionary::getSplitTwoWordsSuggestion(const int inputLength,
}
const int secondFreq = getBestWordFreq(secondWordStartPos, secondWordLength, mWord);
if (DEBUG_DICT) LOGI("Second freq: %d", secondFreq);
if (DEBUG_DICT) {
LOGI("Second freq: %d", secondFreq);
}
if (secondFreq <= 0) return false;
word[firstWordLength] = SPACE;
@ -514,7 +537,9 @@ inline int UnigramDictionary::calculateFinalFreq(const int inputIndex, const int
for (int i = 0; i < depth; ++i) lengthFreq *= TYPED_LETTER_MULTIPLIER;
if (lengthFreq == matchWeight) {
if (depth > 1) {
if (DEBUG_DICT) LOGI("Found full matched word.");
if (DEBUG_DICT) {
LOGI("Found full matched word.");
}
multiplyRate(FULL_MATCHED_WORDS_PROMOTION_RATE, &finalFreq);
}
if (sameLength && transposedPos < 0 && skipPos < 0 && excessivePos < 0) {
@ -768,7 +793,9 @@ inline bool UnigramDictionary::processCurrentNodeForExactMatch(const int firstCh
*siblingPos = Dictionary::setDictionaryValues(DICT, IS_LATEST_DICT_VERSION, firstChildPos, &c,
newChildPosition, newTerminal, newFreq);
const unsigned int inputC = currentChars[0];
if (DEBUG_DICT) assert(inputC <= U_SHORT_MAX);
if (DEBUG_DICT) {
assert(inputC <= U_SHORT_MAX);
}
const unsigned short baseLowerC = toBaseLowerCase(c);
const bool matched = (inputC == baseLowerC || inputC == c);
const bool hasChild = *newChildPosition != 0;
@ -776,7 +803,9 @@ inline bool UnigramDictionary::processCurrentNodeForExactMatch(const int firstCh
word[depth] = c;
if (DEBUG_DICT && DEBUG_NODE) {
LOGI("Node(%c, %c)<%d>, %d, %d", inputC, c, matched, hasChild, *newFreq);
if (*newTerminal) LOGI("Terminal %d", *newFreq);
if (*newTerminal) {
LOGI("Terminal %d", *newFreq);
}
}
if (hasChild) {
*newCount = Dictionary::getCount(DICT, newChildPosition);