On Apr 22, 2:26 am, David Mandelin <[EMAIL PROTECTED]> wrote:
> Benjamin Smedberg wrote:
> > Bo Yang wrote:
>
> >> Hi,
> >>    I think my question has something to do with statically analysis,
> >> so I post here.
> >>    Along with my reading of Mozilla code, I find it is very helpful if
> >> I can gain a part of classes hierarchy graph from the C++ source
> >> code.
> >>    Could anybody please help me and give me some advice about with
> >> which tools under Linux I can achieve my purpose? Thanks in advance!
>
> > dmandelin already wrote a tool to do this, see the first paragraph of
> >http://blog.mozilla.com/dmandelin/2008/02/28/a-few-notes-on-string-apis/
>
> > I think we would dearly love to actually run the analysis every time you
> > build with static analysis, because it's cheap to do... then it wouldn't be
> > hard to implement a "make classgraph" target to build an SVG/HTML/something
> > version of the result.
>
> I should note that my class hierarchy tool is very primitive, and I
> think its use of the Dehydra API is a little behind. I've attached the
> files you can look at them.
>
>   classtree.js -- The Dehydra script. 
> (Seehttp://wiki.mozilla.org/Dehydra_GCC.) This prints out the class
> hierarchy in a text form that's easy to read from Python. Some lines
> contain just a string, and are the name of a class. Others contain a
> pair, and represent an inheritance relationship.
>
>   classtree.py -- Python script to postprocess the results. The input to
> this file is a file containing the output of classtree.js on one or more
> C++ files (just cat'd together). It will collect the relationships and
> output a single Graphviz dot graph.
>
> It's necessary to do this in multiple parts because each run of Dehydra
> will be over one source code file (as Dehydra runs within g++), but the
> desired final output can only be produced by looking at data from all
> the C++ files.
>
> Dave
>
>  classtree.js
> 1KDownload
>
> [classtree.py]import sys
>
> classmap = {}
> edges = set()
>
> for line in sys.stdin:
>     if line.startswith('#'): continue
>     v = eval(line)
>     if isinstance(v, str):
>         if v in classmap: continue
>         classmap[v] = len(classmap)
>     else:
>         src, dst = v
>         edges.add((classmap[src], classmap[dst]))
>
> print 'digraph G {'
> print '  graph [rankdir="BT"];'
> print '  node [shape="rect"];'
> for cls, id in classmap.items():
>     print '  %d [label="%s"];'%(id, cls)
> for src, dst in edges:
>     print '  %d -> %d;'%(src, dst)
> print '}'

Thank you David, I am now following the instructions to make the class
graph. Thanks!

PS: compiling gcc is really time-consuming.
Regards!
Bo
_______________________________________________
Dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis

Reply via email to