Hello all, I have read the AST traverse code in FindUsages class. It seems that
a AST just organize all tokens in a file into a tree. Each node in the tree
corresponds a syntax element(For example, a statement, or an expression). Also,
a leaf node will carry a token index, which can be used to query the actual
token by calling ASTVisitor::tokenAt(idx).
Here's my code for building AST.
const CppTools::CppModelManagerInterface::WorkingCopy workingCopy =
mgr->workingCopy();
QString fileName = doc->fileName();
const QByteArray unpreprocessedSource = getSource(fileName, workingCopy);
doc = snapshot.preprocessedDocument(unpreprocessedSource, fileName);
doc->tokenize();
//doc->check(); // This invocation will crash the program, because
Q_ASSERT(!_globalNamespace) in it fails, why ?
doc->parse();
// It seems that both AST are the same, isn't it ?
CPlusPlus::AST* ast = doc->translationUnit()->ast();
CPlusPlus::AST* ast2 = doc->control()->translationUnit()->ast();
CPlusPlus::TranslationUnitAST* trAst = ast->asTranslationUnit();
OK, now I have some problems:
(1) Is the code above right? Why doc->check() will crash?
(2) How to release memory when I don't need the AST any more? Just call
Document::releaseSourceAndAST() ?
(3) Most importantly, as I want to extract the call graph, I want to get the
complete and exact declaration of any function I encounter.
For example, there are several overloaded versions of the following
function:
int ClassA::funcA();
int ClassA::funcA(int varA);
Suppose when I traverse the AST, I encounter "objA->funcA(5);" . So how
can I find its prototype "int ClassA::funcA(int varA);",
instead of "int ClassA::funcA();"? Is there any "binding" for a ast
element, such as the definition of a function?
(4) An extra question, when I debugged the QtCreator code in visual studio, I
found it sometimes took a lot of time for QtCreator to
parse the source after a project was opened, but quite fast (several
seconds) in other times. This was really strange because the
project was the same. That wasted me a lot of time. How to solve it ?_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/qt-creator