[Qt-creator] getting AST from a document
Marek Jasovsky
jasovsky.marek at gmail.com
Wed Jan 7 08:56:02 CET 2009
Hi all, hi Roberto
I have finally managed my plugin and mode work, but now I can not get ast of
current document.
first version of code crashed when trying to convert ast to
TranslationUnitAST. then, I found out, that translationUnit for the document
had already been released.
1. TranslationUnit *tu = doc->translationUnit();
2.
3. if (tu)
4. {
5. AST* ast = tu->ast();
6. qDebug("before tu->control()");
7. DumpAST *dump = new DumpAST(tu->control());
8. qDebug("after tu->control()");
9. //ast->accept(dump);
10.
11. if (ast->asTranslationUnit())
12. ast->asTranslationUnit()->accept(dump);
13. }
unfortunately as seen below, I was neither able to parse the document once
more, as the code crashed in MemoryPool::allocate which is inline function.
(ptr pointed to 0x0010)
if (tu && doc->fileName().endsWith(".cpp"))
{
if (!tu->memoryPool())
{
doc->parse();
tu = doc->translationUnit();
AST* ast = tu->ast();
DumpAST *dump = new DumpAST(tu->control());
//ast->accept(dump);
TranslationUnitAST *tast = ast->asTranslationUnit();
//dump->accept(ast->asTranslationUnit());
//ast->asTranslationUnit()->accept(dump);
}
}
I have seen, that CppModelManager is parsing sources similar way , I was.
could you please point me, to the right way, how I can get ast of document,
that already has been parsed, and it's translationUnit has been released?
thanks
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-creator-old/attachments/20090107/227ec855/attachment.html
More information about the Qt-creator-old
mailing list