[Qt-creator] getting AST from a document
Roberto Raggi
roberto.raggi at trolltech.com
Wed Jan 7 09:29:49 CET 2009
Hi,
On Jan 7, 2009, at 8:56 AM, Marek Jasovsky wrote:
> 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.
>
> TranslationUnit *tu = doc->translationUnit();
>
> if (tu)
> {
> AST* ast = tu->ast();
> qDebug("before tu->control()");
> DumpAST *dump = new DumpAST(tu->control());
> qDebug("after tu->control()");
> //ast->accept(dump);
>
> if (ast->asTranslationUnit())
> ast->asTranslationUnit()->accept(dump);
> }
>
> 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)
Look at src/plugins/cpptools/cppmodelmanager.cpp around line 410.
407 m_currentDoc->setSource(preprocessedCode);
408 m_currentDoc->parse();
409 m_currentDoc->check();
410 m_currentDoc->releaseTranslationUnit(); // release the AST
and the token stream.
As you can see we dispose the AST as soon as we are done processing
it. So just add your stuff before the call to releaseTranslationUnit().
ciao robe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-creator-old/attachments/20090107/8f54142e/attachment.html
More information about the Qt-creator-old
mailing list