[Qt-creator] Qt-creator Digest, Vol 25, Issue 18

dydx 549088764 at qq.com
Mon Oct 21 13:52:12 CEST 2013


Thanks. I think I should show my idea.
Basically, my idea is similar to CodeMap, that is, to show the overall architecture of a software as a map. But there're also some differences:
1. A module (For example: the CPlusPlus plugin) is an island, then a class may be a country, and a function a city.  
2. Main invocations (For example: invocations between different modules, which will cause many other function calls) are shown as roads.  So user can easily know how the modules are coupled with each other.
3. Finally, a user can explore the code using the map, just like a scout exploring unknown places in a game. Here are some examples(some of them already implemented in Codemap):
     (1) A user can mark some invocations, so additional "roads" will appear in the map. Using this method, a user can explore the part of code an invocation will affect.
     (2) A user can search all references of a symbol(variable/class), then some "pins" will appear, just like what we see in the google map.
     (3) The layer of a module / class / function in the architecture level can be implied by its altitude in the map. For example, a function which cause many other invocations will be a city in high altitude.
     (4) Combined with the "breakpoint/tracepoint" function, all the functions that a program enters in a short time can be shown as a  route in the map, so user can just run the program, then trigger a action(For example: open a file), then all parts of code affected by this action(For example: all parts affected by the "Open File" menu item) can be seen in the map. To do this, a naive way is to set a "trace point" at the beginning of all functions and output a function's name when it is invoked, then collect all outputs and show the route in the map.




------------------ Original ------------------
From: "qt-creator-request"; 
Date: 2013年10月21日(星期一) 晚上6:00
To: "qt-creator"; 
Subject: Qt-creator Digest, Vol 25, Issue 18



Send Qt-creator mailing list submissions to
	qt-creator at qt-project.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://lists.qt-project.org/mailman/listinfo/qt-creator
or, via email, send a message with subject or body 'help' to
	qt-creator-request at qt-project.org

You can reach the person managing the list at
	qt-creator-owner at qt-project.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Qt-creator digest..."


Today's Topics:

   1. Re: Extract call graph from QtCreator?2? (Tobias Hunger)
   2. Re: Extract call graph from QtCreator?2? (Jochen Becher)
   3. ???  Extract call graph fromQtCreator?2? ( ???? )
   4. Re: Extract call graph from QtCreator?2? (Nikolai Kosjar)


----------------------------------------------------------------------

Message: 1
Date: Sun, 20 Oct 2013 12:36:21 +0200
From: Tobias Hunger <tobias.hunger at gmail.com>
Subject: Re: [Qt-creator] Extract call graph from QtCreator?2?
To: ???? <549088764 at qq.com>
Cc: qt-creator <qt-creator at qt-project.org>
Message-ID:
	<CAMdWP3GBuR9e6GB_Z95GZhEpqtxK3Riyo5-vJSyNiggBwXyTzg at mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hello,

could you please use plain text mail instead of this multi-part base64
encoded mess? Plain text is way easier to read for the old people on
this list, some of which insist on using text-only mailers. Now that I
complained about non-plain-text mails, I hope my mailer won't end up
sending HTML mail again;-)

Anyway:

On Oct 20, 2013 1:59 AM, "????" <549088764 at qq.com> wrote:
>
> 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.

We actually have a "Extending Qt Creator" manual which is supposed to
help get newbies started with plugin development. That does need quite
a bit more information and is far from complete, but maybe it can help
a bit to get started.

http://doc-snapshot.qt-project.org/qtcreator-extending/extending-index.html

> 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.

Looks cool, go for it:-)

his seems to be based on the master thesis by David Samuel Erni from
2010 at the university of Bern (
http://scg.unibe.ch/archive/masters/Erni10a.pdf ). Did you follow the
research to find out whether there was progress in that area since
2010? Maybe they got something newer and even more shiny by now;-)

The call graph seems like a secondary concern going by that paper,
considering that the call graph is just one overlay over the map of
the project.

This is not exactly my area of expertise, so just general comments from my side:

> Specifically, I want to take the following steps:
> 1. I extract all call graphes of functions

I would get started with a "show call graph" action that you can
trigger on any function and that displays where the function is called
from as well as what the function is calling in turn. Something like
"show usages" on steroids. That should be reasonably easy to test to
make sure the next steps are on a stable foundation.

Only in the second step I would use that code to generate all call
graphs of functions.

Best Regards,
Tobias


------------------------------

Message: 2
Date: Sun, 20 Oct 2013 21:54:08 +0200
From: Jochen Becher <jochen_becher at gmx.de>
Subject: Re: [Qt-creator] Extract call graph from QtCreator?2?
To: ???? <549088764 at qq.com>
Cc: qt-creator <qt-creator at qt-project.org>
Message-ID: <1382298848.13962.11.camel at gondolin>
Content-Type: text/plain; charset="UTF-8"


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




------------------------------

Message: 3
Date: Mon, 21 Oct 2013 09:09:32 +0800
From: " ???? " <549088764 at qq.com>
Subject: [Qt-creator] ???  Extract call graph fromQtCreator?2?
To: " Qt Creator's Jochen Becher " <jochen_becher at gmx.de>
Cc: qt-creator <qt-creator at qt-project.org>
Message-ID: <tencent_46722C355C46689269F946C5 at qq.com>
Content-Type: text/plain; charset="gb18030"

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-0001.html 

------------------------------

Message: 4
Date: Mon, 21 Oct 2013 11:37:41 +0200
From: Nikolai Kosjar <nikolai.kosjar at digia.com>
Subject: Re: [Qt-creator] Extract call graph from QtCreator?2?
To: <qt-creator at qt-project.org>
Message-ID: <5264F5E5.6050205 at digia.com>
Content-Type: text/plain; charset="UTF-8"; format=flowed

Hi!

I agree with Tobias regarding the two-step procedure.

How are "similar files" defined and why do you need "all call graphes of 
functions"? This might get quite expensive and only a fraction of it 
might be relevant to the user. I'm not familar with the CodeMap plugin 
of eclipse, but according to the screenshot it display the call graph 
only for a single function?

On 10/20/2013 01:59 AM, ???? wrote:
> 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 ?

Document::Ptr document = ...;
AST *ast = document->translationUnit()->ast();

Where do you get the document from? Documents are typically kept in a 
Snapshot, which is basically a filePath -> Document::Ptr map. Note that 
the documents in the CppModelManagerInterface::instance()->snapshot() 
have only symbol information, but no source text and AST information 
attached (would take too much memory).

For source files that are opened in an editor you can get the "full" 
document including the AST via CPPEditorWidget::semanticInfo().doc. If 
the source files you are interested in are not opened in an editor, you 
have to read the soure file and parse it by yourself to get a document 
with AST. That's what we are doing for Find Usages, see 
ProcessFile::operator() in cppfindreferences.cpp ("doc->check()" parses 
the document and keeps the AST around). That document is then passed on 
to FindUsages, which is an ASTVisitor.

I recommend you to first study the mentioned code references and their 
code paths.

> 2.  How to filter the symbols I need(For example: all functions)?

As written in a previous reply, you can use CppLocatorData::functions() 
to get all function symbols for the function definitions.

For a given AST, see FindUsages.

> 3.  Is there any other efficient way to do this?

Basically it's fine.

For the call hierarchy of a certain function:

1. Get the symbol for the declaration/definition/call under cursor.
2. Apply your customized version of FindUsages to find all callers and 
callees for the function symbol.
3. Display the call hierachy, e.g. in the side bar.

For the call graph:

...see my question above regarding all call graphs of all functions.

Nikolai


------------------------------

_______________________________________________
Qt-creator mailing list
Qt-creator at qt-project.org
http://lists.qt-project.org/mailman/listinfo/qt-creator


End of Qt-creator Digest, Vol 25, Issue 18
******************************************
.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20131021/1df6f6ae/attachment.html>


More information about the Qt-creator mailing list