summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/symbols.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2012-11-22 11:03:39 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-23 17:04:00 +0100
commitaea68c93ae437a761584719f0f1ca93eaf6f7484 (patch)
tree09f7bb24a1ec26c96db27be9bfeb61ed6c3da8e4 /src/tools/moc/symbols.h
parent436e3dc4f961b4ea6c541d1fdf82e476ac10597c (diff)
Proper macro replacment and branch evaluation
Correclty replace macros according to the C++ standard. Use the correct replacement method also to evaluate With this moc correctly processes boost headers. Task-number: QTBUG-27546 Change-Id: I001b3054c5fcdc34d46cfa53d1387bd19436f361 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/tools/moc/symbols.h')
-rw-r--r--src/tools/moc/symbols.h55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/tools/moc/symbols.h b/src/tools/moc/symbols.h
index c5efbd8cb4..fb2ec03b4b 100644
--- a/src/tools/moc/symbols.h
+++ b/src/tools/moc/symbols.h
@@ -46,6 +46,7 @@
#include <qstring.h>
#include <qhash.h>
#include <qvector.h>
+#include <qstack.h>
#include <qdebug.h>
QT_BEGIN_NAMESPACE
@@ -128,9 +129,61 @@ struct Symbol
};
Q_DECLARE_TYPEINFO(Symbol, Q_MOVABLE_TYPE);
-
typedef QVector<Symbol> Symbols;
+struct SafeSymbols {
+ Symbols symbols;
+ QByteArray expandedMacro;
+ int index;
+};
+
+class SymbolStack : public QStack<SafeSymbols>
+{
+public:
+ inline bool hasNext() {
+ while (!isEmpty() && top().index >= top().symbols.size())
+ pop();
+ return !isEmpty();
+ }
+ inline Token next() {
+ while (!isEmpty() && top().index >= top().symbols.size())
+ pop();
+ if (isEmpty())
+ return NOTOKEN;
+ return top().symbols.at(top().index++).token;
+ }
+ bool test(Token);
+ inline const Symbol &symbol() const { return top().symbols.at(top().index-1); }
+ inline Token token() { return symbol().token; }
+ inline QByteArray lexem() const { return symbol().lexem(); }
+ inline QByteArray unquotedLexem() { return symbol().unquotedLexem(); }
+
+ bool dontReplaceSymbol(const QByteArray &name);
+};
+
+inline bool SymbolStack::test(Token token)
+{
+ int stackPos = size() - 1;
+ while (stackPos >= 0 && at(stackPos).index >= at(stackPos).symbols.size())
+ --stackPos;
+ if (stackPos < 0)
+ return false;
+ if (at(stackPos).symbols.at(at(stackPos).index).token == token) {
+ next();
+ return true;
+ }
+ return false;
+}
+
+inline bool SymbolStack::dontReplaceSymbol(const QByteArray &name)
+{
+ for (int i = 0; i < size(); ++i) {
+ if (name == at(i).expandedMacro)
+ return true;
+ }
+ return false;
+}
+
QT_END_NAMESPACE
#endif // SYMBOLS_H