diff options
author | Lars Knoll <lars.knoll@digia.com> | 2012-11-22 10:31:14 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-23 17:04:00 +0100 |
commit | 436e3dc4f961b4ea6c541d1fdf82e476ac10597c (patch) | |
tree | 086aa4b971c22ec393fc04ea67b2d3780f05eef5 /src/tools | |
parent | 863e44a42bb91d9e2ba8024dfa594ecebe9d3b58 (diff) |
Correctly expand arguments in function macros
Arguments in function macros are only expanded if they
aren't used in conjunction with a # or ## operator.
Change-Id: I8c80e11902a592128504c4637545e75866566965
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index b49ab9c210..49700a0992 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -565,7 +565,6 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac const Macro ¯o = macros.value(s); safeset += s; - // don't expand macros with arguments for now if (macro.isFunction) { while (test(PP_WHITESPACE)) {} if (!test(PP_LPAREN)) { @@ -593,11 +592,7 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac } argument += symbol(); } - - // each argument undoergoes macro expansion - Symbols expanded; - macroExpandSymbols(lineNum, argument, expanded, safeset); - arguments += expanded; + arguments += argument; if (nesting < 0) break; @@ -630,13 +625,19 @@ void Preprocessor::macroExpandIdentifier(int lineNum, Symbols &preprocessed, Mac } int index = macro.arguments.indexOf(s); if (mode == Normal) { - if (index >= 0) - expansion += arguments.at(index); - else + if (index >= 0) { + // each argument undoergoes macro expansion if it's not used as part of a # or ## + if (i < macro.symbols.size() - 1 && macro.symbols.at(i + 1).token != PP_HASHHASH) { + Symbols expanded; + macroExpandSymbols(lineNum, arguments.at(index), expanded, safeset); + expansion += expanded; + } else { + expansion += arguments.at(index); + } + } else { expansion += s; + } } else if (mode == Hash) { - if (s.token == WHITESPACE) - continue; if (index < 0) error("'#' is not followed by a macro parameter"); |