diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index ac6fb48639a..5c837db64d2 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -63,6 +63,8 @@ #include #include #include +#include +#include #include #include @@ -70,11 +72,55 @@ #include #include #include +#include +#include using namespace CppTools; using namespace CppTools::Internal; using namespace CPlusPlus; +#if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU) + +#include + +class DumpAST: protected ASTVisitor +{ +public: + int depth; + + DumpAST(Control *control) + : ASTVisitor(control), depth(0) + { } + + void operator()(AST *ast) + { accept(ast); } + +protected: + virtual bool preVisit(AST *ast) + { + std::ostringstream s; + PrettyPrinter pp(control(), s); + pp(ast); + QString code = QString::fromStdString(s.str()); + code.replace('\n', ' '); + code.replace(QRegExp("\\s+"), " "); + + const char *name = abi::__cxa_demangle(typeid(*ast).name(), 0, 0, 0) + 11; + + QByteArray ind(depth, ' '); + ind += name; + + printf("%-40s %s\n", ind.constData(), qPrintable(code)); + ++depth; + return true; + } + + virtual void postVisit(AST *) + { --depth; } +}; + +#endif QTCREATOR_WITH_DUMP_AST + static const char pp_configuration_file[] = ""; static const char pp_configuration[] = @@ -413,6 +459,12 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type, m_currentDoc->setSource(preprocessedCode); m_currentDoc->parse(); + +#if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU) + DumpAST dump(m_currentDoc->control()); + dump(m_currentDoc->translationUnit()->ast()); +#endif + m_currentDoc->check(); m_currentDoc->releaseTranslationUnit(); // release the AST and the token stream.