| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-01-11 16:28:15 +01:00
										 |  |  | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** No Commercial Usage | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** This file contains pre-release code and may not be distributed. | 
					
						
							|  |  |  | ** You may use this file in accordance with the terms and conditions | 
					
						
							|  |  |  | ** contained in the Technology Preview License Agreement accompanying | 
					
						
							|  |  |  | ** this package. | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
					
						
							|  |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							|  |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AST.h>
 | 
					
						
							|  |  |  | #include <ASTVisitor.h>
 | 
					
						
							|  |  |  | #include <ASTPatternBuilder.h>
 | 
					
						
							|  |  |  | #include <ASTMatcher.h>
 | 
					
						
							|  |  |  | #include <Control.h>
 | 
					
						
							|  |  |  | #include <Scope.h>
 | 
					
						
							|  |  |  | #include <TranslationUnit.h>
 | 
					
						
							|  |  |  | #include <Literals.h>
 | 
					
						
							|  |  |  | #include <Symbols.h>
 | 
					
						
							|  |  |  | #include <Names.h>
 | 
					
						
							|  |  |  | #include <CoreTypes.h>
 | 
					
						
							|  |  |  | #include <CppDocument.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | #include <SymbolVisitor.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  | #include <Overview.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QFile>
 | 
					
						
							|  |  |  | #include <QList>
 | 
					
						
							|  |  |  | #include <QCoreApplication>
 | 
					
						
							|  |  |  | #include <QStringList>
 | 
					
						
							|  |  |  | #include <QFileInfo>
 | 
					
						
							|  |  |  | #include <QTime>
 | 
					
						
							|  |  |  | #include <QtDebug>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cstdio>
 | 
					
						
							|  |  |  | #include <cstdlib>
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | #include <fstream>
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2010-07-13 11:16:17 +02:00
										 |  |  | #ifdef __GNUC__
 | 
					
						
							|  |  |  | #  include <cxxabi.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace CPlusPlus; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ASTDump: protected ASTVisitor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     ASTDump(TranslationUnit *unit) | 
					
						
							|  |  |  |         : ASTVisitor(unit) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void operator()(AST *ast) { | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         QByteArray basename = translationUnit()->fileName(); | 
					
						
							|  |  |  |         int dotIdx = basename.lastIndexOf('.'); | 
					
						
							|  |  |  |         if (dotIdx != -1) | 
					
						
							|  |  |  |             basename.truncate(dotIdx); | 
					
						
							|  |  |  |         basename.append(".ast.dot"); | 
					
						
							|  |  |  |         out.open(basename.constData()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |         out << "digraph AST { ordering=out;" << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 12:21:42 +01:00
										 |  |  |         // std::cout << "rankdir = \"LR\";" << std::endl;
 | 
					
						
							| 
									
										
										
										
											2010-09-21 18:41:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         generateTokens(); | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |         accept(ast); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |         typedef QPair<QByteArray, QByteArray> Pair; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach (const Pair &conn, _connections) | 
					
						
							|  |  |  |             out << conn.first.constData() << " -> " << conn.second.constData() << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         alignTerminals(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         out << "}" << std::endl; | 
					
						
							|  |  |  |         out.close(); | 
					
						
							|  |  |  |         std::cout << basename.constData() << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     // the following file can be generated by using:
 | 
					
						
							|  |  |  |     //    generate-ast <path to cpp stuff> <path to dumpers.inc>
 | 
					
						
							|  |  |  | #include "dumpers.inc"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |     void alignTerminals() { | 
					
						
							| 
									
										
										
										
											2010-03-08 17:34:32 +01:00
										 |  |  |         out<<"{ rank=same;" << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         foreach (const QByteArray &terminalShape, _terminalShapes) { | 
					
						
							| 
									
										
										
										
											2010-03-08 17:34:32 +01:00
										 |  |  |             out << "  " << std::string(terminalShape) << ";" << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         out<<"}"<<std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     static QByteArray name(AST *ast) { | 
					
						
							| 
									
										
										
										
											2010-07-13 11:16:17 +02:00
										 |  |  | #ifdef __GNUC__
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |         QByteArray name = abi::__cxa_demangle(typeid(*ast).name(), 0, 0, 0) + 11; | 
					
						
							|  |  |  |         name.truncate(name.length() - 3); | 
					
						
							| 
									
										
										
										
											2010-07-13 11:16:17 +02:00
										 |  |  | #else
 | 
					
						
							|  |  |  |         QByteArray name = typeid(*ast).name(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |         return name; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-21 18:41:09 +02:00
										 |  |  |     QByteArray terminalId(unsigned token) | 
					
						
							|  |  |  |     { return 't' + QByteArray::number(token); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     void terminal(unsigned token, AST *node) { | 
					
						
							| 
									
										
										
										
											2010-09-21 18:41:09 +02:00
										 |  |  |         _connections.append(qMakePair(_id[node], terminalId(token))); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void generateTokens() { | 
					
						
							|  |  |  |         for (unsigned token = 1; token < translationUnit()->tokenCount(); ++token) { | 
					
						
							|  |  |  |             if (translationUnit()->tokenKind(token) == T_EOF_SYMBOL) | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             QByteArray t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             t.append(terminalId(token)); | 
					
						
							|  |  |  |             t.append(" [shape=rect label = \""); | 
					
						
							|  |  |  |             t.append(spell(token)); | 
					
						
							|  |  |  |             t.append("\"]"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (token > 1) { | 
					
						
							|  |  |  |                 t.append("; "); | 
					
						
							|  |  |  |                 t.append(terminalId(token - 1)); | 
					
						
							|  |  |  |                 t.append(" -> "); | 
					
						
							|  |  |  |                 t.append(terminalId(token)); | 
					
						
							|  |  |  |                 t.append(" [arrowhead=\"vee\" color=\"transparent\"]"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             _terminalShapes.append(t); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     virtual void nonterminal(AST *ast) { | 
					
						
							|  |  |  |         accept(ast); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     virtual void node(AST *ast) { | 
					
						
							|  |  |  |         out << _id[ast].constData() << " [label=\"" << name(ast).constData() << "\"];" << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool preVisit(AST *ast) { | 
					
						
							|  |  |  |         static int count = 1; | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |         const QByteArray id = 'n' + QByteArray::number(count++); | 
					
						
							|  |  |  |         _id[ast] = id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (! _stack.isEmpty()) | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |             _connections.append(qMakePair(_id[_stack.last()], id)); | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         _stack.append(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |         node(ast); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:21:42 +01:00
										 |  |  |     virtual void postVisit(AST *) { | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         _stack.removeLast(); | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     QHash<AST *, QByteArray> _id; | 
					
						
							|  |  |  |     QList<QPair<QByteArray, QByteArray> > _connections; | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |     QList<AST *> _stack; | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |     QList<QByteArray> _terminalShapes; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |     std::ofstream out; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SymbolDump: protected SymbolVisitor | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     SymbolDump(TranslationUnit *unit) | 
					
						
							|  |  |  |         : translationUnit(unit) | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         o.setShowArgumentNames(true); | 
					
						
							|  |  |  |         o.setShowFunctionSignatures(true); | 
					
						
							|  |  |  |         o.setShowReturnTypes(true); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void operator()(Symbol *s) { | 
					
						
							|  |  |  |         QByteArray basename = translationUnit->fileName(); | 
					
						
							|  |  |  |         int dotIdx = basename.lastIndexOf('.'); | 
					
						
							|  |  |  |         if (dotIdx != -1) | 
					
						
							|  |  |  |             basename.truncate(dotIdx); | 
					
						
							|  |  |  |         basename.append(".symbols.dot"); | 
					
						
							|  |  |  |         out.open(basename.constData()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 19:20:14 +02:00
										 |  |  |         out << "digraph Symbols { ordering=out;" << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         // std::cout << "rankdir = \"LR\";" << std::endl;
 | 
					
						
							|  |  |  |         accept(s); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int i = 0; i < _connections.size(); ++i) { | 
					
						
							|  |  |  |             QPair<Symbol*,Symbol*> connection = _connections.at(i); | 
					
						
							|  |  |  |             QByteArray from = _id.value(connection.first); | 
					
						
							|  |  |  |             if (from.isEmpty()) | 
					
						
							|  |  |  |                 from = name(connection.first); | 
					
						
							|  |  |  |             QByteArray to = _id.value(connection.second); | 
					
						
							|  |  |  |             if (to.isEmpty()) | 
					
						
							|  |  |  |                 to = name(connection.second); | 
					
						
							|  |  |  |             out << from.constData() << " -> " << to.constData() << ";" << std::endl; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         out << "}" << std::endl; | 
					
						
							|  |  |  |         out.close(); | 
					
						
							|  |  |  |         std::cout << basename.constData() << std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     QByteArray name(Symbol *s) { | 
					
						
							| 
									
										
										
										
											2010-07-13 11:16:17 +02:00
										 |  |  | #ifdef __GNUC__
 | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |         QByteArray result = abi::__cxa_demangle(typeid(*s).name(), 0, 0, 0) + 11; | 
					
						
							| 
									
										
										
										
											2010-07-13 11:16:17 +02:00
										 |  |  | #else
 | 
					
						
							|  |  |  |         QByteArray result = typeid(*s).name(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         if (s->identifier()) { | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |             result.append("\\nid: "); | 
					
						
							|  |  |  |             result.append(s->identifier()->chars()); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |         if (s->isDeprecated()) | 
					
						
							|  |  |  |             result.append("\\n(deprecated)"); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |         return result; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool preVisit(Symbol *s) { | 
					
						
							|  |  |  |         static int count = 0; | 
					
						
							|  |  |  |         QByteArray nodeId("s"); | 
					
						
							|  |  |  |         nodeId.append(QByteArray::number(++count)); | 
					
						
							|  |  |  |         _id[s] = nodeId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!_stack.isEmpty()) | 
					
						
							|  |  |  |             _connections.append(qMakePair(_stack.last(), s)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         _stack.append(s); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void postVisit(Symbol *) { | 
					
						
							|  |  |  |         _stack.removeLast(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual void simpleNode(Symbol *symbol) { | 
					
						
							|  |  |  |         out << _id[symbol].constData() << " [label=\"" << name(symbol).constData() << "\"];" << std::endl; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool visit(Class *symbol) { | 
					
						
							|  |  |  |         const char *id = _id.value(symbol).constData(); | 
					
						
							|  |  |  |         out << id << " [label=\""; | 
					
						
							|  |  |  |         if (symbol->isClass()) { | 
					
						
							|  |  |  |             out << "class"; | 
					
						
							|  |  |  |         } else if (symbol->isStruct()) { | 
					
						
							|  |  |  |             out << "struct"; | 
					
						
							|  |  |  |         } else if (symbol->isUnion()) { | 
					
						
							|  |  |  |             out << "union"; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             out << "UNKNOWN"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         out << "\\nid: "; | 
					
						
							|  |  |  |         if (symbol->identifier()) { | 
					
						
							|  |  |  |             out << symbol->identifier()->chars(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             out << "NO ID"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |         if (symbol->isDeprecated()) | 
					
						
							|  |  |  |             out << "\\n(deprecated)"; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         out << "\"];" << std::endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual bool visit(UsingNamespaceDirective *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(UsingDeclaration *symbol) { simpleNode(symbol); return true; } | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual bool visit(Declaration *symbol) { | 
					
						
							|  |  |  |         out << _id[symbol].constData() << " [label=\""; | 
					
						
							|  |  |  |         out << "Declaration\\n"; | 
					
						
							|  |  |  |         out << qPrintable(o(symbol->name())); | 
					
						
							|  |  |  |         out << ": "; | 
					
						
							|  |  |  |         out << qPrintable(o(symbol->type())); | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |         if (symbol->isDeprecated()) | 
					
						
							|  |  |  |             out << "\\n(deprecated)"; | 
					
						
							| 
									
										
										
										
											2010-08-24 12:14:30 +02:00
										 |  |  |         if (Function *funTy = symbol->type()->asFunctionType()) { | 
					
						
							|  |  |  |             if (funTy->isPureVirtual()) | 
					
						
							|  |  |  |                 out << "\\n(pure virtual)"; | 
					
						
							|  |  |  |             else if (funTy->isVirtual()) | 
					
						
							|  |  |  |                 out << "\\n(virtual)"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (funTy->isSignal()) | 
					
						
							|  |  |  |                 out << "\\n(signal)"; | 
					
						
							|  |  |  |             if (funTy->isSlot()) | 
					
						
							|  |  |  |                 out << "\\n(slot)"; | 
					
						
							|  |  |  |             if (funTy->isInvokable()) | 
					
						
							|  |  |  |                 out << "\\n(invokable)"; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  |         out << "\"];" << std::endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |     virtual bool visit(Argument *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(TypenameArgument *symbol) { simpleNode(symbol); return true; } | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     virtual bool visit(BaseClass *symbol) { | 
					
						
							|  |  |  |         out << _id[symbol].constData() << " [label=\"BaseClass\\n"; | 
					
						
							|  |  |  |         out << qPrintable(o(symbol->name())); | 
					
						
							| 
									
										
										
										
											2010-03-23 11:59:32 +01:00
										 |  |  |         if (symbol->isDeprecated()) | 
					
						
							|  |  |  |             out << "\\n(deprecated)"; | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  |         out << "\"];" << std::endl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |     virtual bool visit(Enum *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(Function *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(Namespace *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(Block *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ForwardClassDeclaration *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCBaseClass *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCBaseProtocol *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCClass *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCForwardClassDeclaration *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCProtocol *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCForwardProtocolDeclaration *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCMethod *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  |     virtual bool visit(ObjCPropertyDeclaration *symbol) { simpleNode(symbol); return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     TranslationUnit *translationUnit; | 
					
						
							|  |  |  |     QHash<Symbol *, QByteArray> _id; | 
					
						
							|  |  |  |     QList<QPair<Symbol *,Symbol*> >_connections; | 
					
						
							|  |  |  |     QList<Symbol *> _stack; | 
					
						
							|  |  |  |     std::ofstream out; | 
					
						
							| 
									
										
										
										
											2010-03-08 17:31:14 +01:00
										 |  |  |     Overview o; | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QCoreApplication app(argc, argv); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QStringList files = app.arguments(); | 
					
						
							|  |  |  |     files.removeFirst(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach (const QString &fileName, files) { | 
					
						
							|  |  |  |         QFile file(fileName); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         if (! file.open(QFile::ReadOnly)) { | 
					
						
							|  |  |  |             std::cerr << "Cannot open \"" << qPrintable(fileName) | 
					
						
							|  |  |  |                       << "\", skipping it." << std::endl; | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |             continue; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const QByteArray source = file.readAll(); | 
					
						
							|  |  |  |         file.close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Document::Ptr doc = Document::create(fileName); | 
					
						
							|  |  |  |         doc->control()->setDiagnosticClient(0); | 
					
						
							|  |  |  |         doc->setSource(source); | 
					
						
							|  |  |  |         doc->parse(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  |         doc->check(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |         ASTDump dump(doc->translationUnit()); | 
					
						
							|  |  |  |         dump(doc->translationUnit()->ast()); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:42:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         SymbolDump dump2(doc->translationUnit()); | 
					
						
							|  |  |  |         dump2(doc->globalNamespace()); | 
					
						
							| 
									
										
										
										
											2010-03-08 12:12:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return EXIT_SUCCESS; | 
					
						
							|  |  |  | } |