[Qt-creator] 回复: Extract call graph fromQtCreator(2)

欧三股四 549088764 at qq.com
Mon Oct 21 03:09:32 CEST 2013


Thanks for your help! I will have a try.




------------------ 原始邮件 ------------------
发件人: "Qt Creator's Jochen Becher"; 
发送时间: 2013年10月21日(星期一) 凌晨3:54
收件人: "欧三股四"<549088764 at qq.com>; 
抄送: "qt-creator"; 
主题: Re: [Qt-creator] Extract call graph fromQtCreator(2)




I am currently working on a plugin using the AST as well. It helped me a
lot to look into the classview plugin, and todo plugin.

Here is a code snippet I use to scan the AST and to be signaled when
code changes:

CppTools::CppModelManagerInterface *model_manager =
CppTools::CppModelManagerInterface::instance();

connect(model_manager,
SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), this,
SLOT(onDocumentUpdated(CPlusPlus::Document::Ptr)),
Qt::QueuedConnection);

connect(model_manager, SIGNAL(aboutToRemoveFiles(QStringList)), this,
SLOT(onAboutToRemoveFiles(QStringList)), Qt::QueuedConnection);

CPlusPlus::Snapshot snapshot = model_manager->snapshot();

for (CPlusPlus::Snapshot::const_iterator it = snapshot.begin(); it !=
snapshot.end(); ++it) {
    handleDocument(*it);
}

The methods handleDocument() and onDocumentUpdated() looks into each
global symbol (I am interested in class definitions only). 


for (unsigned i = 0, count = document->globalSymbolCount(); i < count;
++i) {
    handleSymbol(document->globalSymbolAt(i));
}

The handleSymbol() method then calls itself to find nested classes
also: 

if (!symbol->isFunction()) {
    const CPlusPlus::Scope *scope = symbol->asScope();
    if (scope) {
        CPlusPlus::Scope::iterator it = scope->firstMember();
        while (it != scope->lastMember()) {
            const CPlusPlus::Symbol *current_symbol = *it;
            ++it;
            if (current_symbol) {
                handleSymbol(current_symbol);
            }
        }
    }
}


Hope that helps you a bit,

Jochen



Am Sonntag, den 20.10.2013, 07:59 +0800 schrieb 欧三股四:
> Many Thanks for Nikolai Kosjar's help in my last e-mail. However, as
> the code of QtCreator is the largest one I have ever encountered and
> there's few articles about it on the Internet, I have to get more
> details before I start.
> 
> Actually, I want to add a visualization module to QtCreator, which is
> similar to the CodeMap plugin in Eclipse JDT.  
> 
> 
> 
> As you can see above, the plugin visualize the code as a map. An
> island means a cluster of similar files, the red marks indicate the
> places where a symbol appears, and the arrows mean the call graph of a
> function.I think this visual metaphor will help when we navigate the
> code, and I want to introduce it into QtCreator. 
> 
> Specifically, I want to take the following steps:
> 1. I extract all call graphes of functions
> 2. Do some clustering on the graph 
> 3. Map the graph to 2D.
> 
> Now, I want to scan all the project files(include .h, .cpp) and in
> every function, find out which functions it calls in order. I think
> traverse the AST is a choice. Here's my problem:
> 1.  How can I get the AST ?
> 2.  How to filter the symbols I need(For example: all functions)?
> 3.  Is there any other efficient way to do this?
> 
> Thanks a lot.
> 
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator


.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20131021/4bed9d90/attachment.html>


More information about the Qt-creator mailing list