diff options
| author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-06-03 16:53:18 +0200 |
|---|---|---|
| committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-06-03 16:53:18 +0200 |
| commit | bb9ae8aa4f9bdcf72fd3d62cefdfdb1622635ef1 (patch) | |
| tree | 3a4cacfc06457c27c2593da21240205e50c4072f /src/plugins/cpptools/cppmodelmanager.cpp | |
| parent | 4bc6256942b24a9ce5ff82e12e08f952898f9b62 (diff) | |
| download | qt-creator-bb9ae8aa4f9bdcf72fd3d62cefdfdb1622635ef1.tar.gz | |
Check for missing Q_OBJECT macro.
Diffstat (limited to 'src/plugins/cpptools/cppmodelmanager.cpp')
| -rw-r--r-- | src/plugins/cpptools/cppmodelmanager.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 9a1e750d5b..e4daf77cb3 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -275,6 +275,67 @@ protected: getTokenStartPosition(ast->firstToken(), &line, &col); _context = lookupContext(line, col); } + + bool hasQ_OBJECT_CHECK = false; + + if (ast->symbol) { + Class *klass = ast->symbol->asClass(); + + for (unsigned i = 0; i < klass->memberCount(); ++i) { + Symbol *symbol = klass->memberAt(i); + + if (symbol->name() && symbol->name()->isNameId()) { + NameId *nameId = symbol->name()->asNameId(); + + if (! qstrcmp(nameId->identifier()->chars(), "qt_check_for_QOBJECT_macro")) { + hasQ_OBJECT_CHECK = true; + break; + } + } + } + } + + _qobjectStack.append(hasQ_OBJECT_CHECK); + + return true; + } + + virtual void endVisit(ClassSpecifierAST *) + { _qobjectStack.removeLast(); } + + bool qobjectCheck() const + { + if (_qobjectStack.isEmpty()) + return false; + + return _qobjectStack.last(); + } + + virtual bool visit(FunctionDefinitionAST *ast) + { + if (ast->symbol) { + Function *fun = ast->symbol->asFunction(); + if ((fun->isSignal() || fun->isSlot()) && ! qobjectCheck()) { + translationUnit()->warning(ast->firstToken(), + "you forgot the Q_OBJECT macro"); + } + } + return true; + } + + virtual bool visit(SimpleDeclarationAST *ast) + { + const bool check = qobjectCheck(); + for (List<Declaration *> *it = ast->symbols; it; it = it->next) { + Declaration *decl = it->value; + + if (Function *fun = decl->type()->asFunctionType()) { + if ((fun->isSignal() || fun->isSlot()) && ! check) { + translationUnit()->warning(ast->firstToken(), + "you forgot the Q_OBJECT macro"); + } + } + } return true; } @@ -323,6 +384,7 @@ private: Document::Ptr _doc; LookupContext _context; NamespaceBindingPtr _globalNamespaceBinding; + QList<bool> _qobjectStack; }; class Process: public std::unary_function<Document::Ptr, void> |
