diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-11-22 09:13:14 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-23 17:04:00 +0100 |
commit | 863e44a42bb91d9e2ba8024dfa594ecebe9d3b58 (patch) | |
tree | 69154da1c8aacd4ad6bc49ff45873133f7d83b68 /src/tools/moc | |
parent | 43619db05d55ca619dac11fdb7327b2b45507cb9 (diff) |
Remove additional whitespaces from the macro tokens
According to the spec, we should ignore whitespace tokens
at the beginning and end of the macro definition. In addition,
whitespaces after a # and around ## should be ignored
Change-Id: I830d0f4aaed3bcfac345d7da6df65693ec3315b8
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/tools/moc')
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index cb53e665d0..b49ab9c210 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -1067,8 +1067,30 @@ void Preprocessor::preprocess(const QByteArray &filename, Symbols &preprocessed) int start = index; until(PP_NEWLINE); macro.symbols.reserve(index - start - 1); - for (int i = start; i < index - 1; ++i) - macro.symbols += symbols.at(i); + + // remove whitespace where there shouldn't be any: + // Before and after the macro, after a # and around ## + Token lastToken = HASH; // skip shitespace at the beginning + for (int i = start; i < index - 1; ++i) { + Token token = symbols.at(i).token; + if (token == PP_WHITESPACE || token == WHITESPACE) { + if (lastToken == PP_HASH || lastToken == HASH || + lastToken == PP_HASHHASH || + lastToken == PP_WHITESPACE || lastToken == WHITESPACE) + continue; + } else if (token == PP_HASHHASH) { + if (!macro.symbols.isEmpty() && + (lastToken == PP_WHITESPACE || lastToken == WHITESPACE)) + macro.symbols.pop_back(); + } + macro.symbols.append(symbols.at(i)); + lastToken = token; + } + // remove trailing whitespace + while (!macro.symbols.isEmpty() && + (macro.symbols.last().token == PP_WHITESPACE || macro.symbols.last().token == WHITESPACE)) + macro.symbols.pop_back(); + macros.insert(name, macro); continue; } |