diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 7 | ||||
-rw-r--r-- | src/tools/moc/preprocessor.h | 3 | ||||
-rw-r--r-- | src/tools/moc/symbols.h | 15 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index 96b920b7cd..8f4b84a9c8 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. @@ -536,12 +537,14 @@ static Symbols tokenize(const QByteArray &input, int lineNum = 1, TokenizeMode m return symbols; } -Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &index, int lineNum, bool one) +Symbols Preprocessor::macroExpand(Preprocessor *that, Symbols &toExpand, int &index, + int lineNum, bool one, const QSet<QByteArray> &excludeSymbols) { SymbolStack symbols; SafeSymbols sf; sf.symbols = toExpand; sf.index = index; + sf.excludedSymbols = excludeSymbols; symbols.push(sf); Symbols result; @@ -664,7 +667,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym if (i == macro.symbols.size() - 1 || macro.symbols.at(i + 1).token != PP_HASHHASH) { Symbols arg = arguments.at(index); int idx = 1; - expansion += macroExpand(that, arg, idx, lineNum, false); + expansion += macroExpand(that, arg, idx, lineNum, false, symbols.excludeSymbols()); } else { expansion += arguments.at(index); } diff --git a/src/tools/moc/preprocessor.h b/src/tools/moc/preprocessor.h index 55e452a2bd..72d02a3292 100644 --- a/src/tools/moc/preprocessor.h +++ b/src/tools/moc/preprocessor.h @@ -85,7 +85,8 @@ public: void substituteUntilNewline(Symbols &substituted); static Symbols macroExpandIdentifier(Preprocessor *that, SymbolStack &symbols, int lineNum, QByteArray *macroName); - static Symbols macroExpand(Preprocessor *that, Symbols &toExpand, int &index, int lineNum, bool one); + static Symbols macroExpand(Preprocessor *that, Symbols &toExpand, int &index, int lineNum, bool one, + const QSet<QByteArray> &excludeSymbols = QSet<QByteArray>()); int evaluateCondition(); diff --git a/src/tools/moc/symbols.h b/src/tools/moc/symbols.h index 35d4ed6ec9..b588cd5beb 100644 --- a/src/tools/moc/symbols.h +++ b/src/tools/moc/symbols.h @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the tools applications of the Qt Toolkit. @@ -134,6 +135,7 @@ typedef QVector<Symbol> Symbols; struct SafeSymbols { Symbols symbols; QByteArray expandedMacro; + QSet<QByteArray> excludedSymbols; int index; }; @@ -159,6 +161,7 @@ public: inline QByteArray unquotedLexem() { return symbol().unquotedLexem(); } bool dontReplaceSymbol(const QByteArray &name); + QSet<QByteArray> excludeSymbols(); }; inline bool SymbolStack::test(Token token) @@ -178,12 +181,22 @@ inline bool SymbolStack::test(Token token) inline bool SymbolStack::dontReplaceSymbol(const QByteArray &name) { for (int i = 0; i < size(); ++i) { - if (name == at(i).expandedMacro) + if (name == at(i).expandedMacro || at(i).excludedSymbols.contains(name)) return true; } return false; } +inline QSet<QByteArray> SymbolStack::excludeSymbols() +{ + QSet<QByteArray> set; + for (int i = 0; i < size(); ++i) { + set << at(i).expandedMacro; + set += at(i).excludedSymbols; + } + return set; +} + QT_END_NAMESPACE #endif // SYMBOLS_H |