博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
understand学习笔记
阅读量:5275 次
发布时间:2019-06-14

本文共 4325 字,大约阅读时间需要 14 分钟。

Understand软件的功能主要定位于代码的阅读理解。界面用Qt开发的。

一:具备如下特性:
  1、支持多语言:Ada, C, C++, C#, Java, FORTRAN, Delphi, Jovial, and PL/M ,混合语言的project也支持
  2、多平台: Windows/Linux/Solaris/HP-UX/IRIX/MAC OS X
  3、代码语法高亮、代码折迭、交叉跳转、书签等基本阅读功能。
  4、可以对整个project的architecture、metrics进行分析并输出报表。
  5、可以对代码生成多种图(butterfly graph、call graph、called by graph、control flow graph、UML class graph等),在图上点击节点可以跳转到对应的源代码位置。
  6、提供Perl API便于扩展。作图全部是用Perl插件实现的,直接读取分析好的数据库作图。
  7、内置的目录和文件比较器。
  8、支持project的snapshot,并能和自家的TrackBack集成便于监视project的变化。

二:用understand获取函数调用关系:

use Understand;  $db = Understand::open("newtank.udb");  foreach $method ($db->ents("Method")) {		foreach $references ($method->refs("Call","Method")){		print $references->kind->longname()."   ".$method->name()."   ".$references->ent()->name()."\n";	}  }

三:understand修改flowchart来获取函数控制流:

use base ("Understand::Graph::Gv");use Understand::Flowchart;use strict;sub name { return "Control Flow"; }sub description {  return "A plugin for generation of simple flowcharts.";}sub test_entity {  my $entity = shift;  my $result = isValidFlowchartEntity($entity);  return $result ? 1 : -1;}sub test_global { return -1; }sub init {  my $graph = shift;  $graph->options->define("Collapse", ["On", "Off"], "On");  $graph->options->define("Display Preceding Comments",["Off","IF Statements","On","On With Code"],"Off");  $graph->options->define("Display Assembly",["On","Off"],"Off");  $graph->options->define("Display Entity Name",["On","Off"],"Off");  $graph->options->define("Overview Mode",["On","Off"],"Off");  $graph->options->define("Macro Expansion",["Off","On (\"Save Macro Expansion Text\" must be enabled)"],"Off");}sub do_load {  my $g = shift;  my $entity = shift;      my $expandmacros = $g->options->lookup("Macro Expansion") ne "Off";  my $collapse     = $g->options->lookup("Collapse") eq "On";  my $comment_conditional = $g->options->lookup("Display Preceding Comments") eq "IF Statements";  my $allComments = $g->options->lookup("Display Preceding Comments") eq "On";  my $codeAndComments = $g->options->lookup("Display Preceding Comments") eq "On With Code";  my $displayAsm = $g->options->lookup("Display Assembly") eq "On";  my $overviewMode  = $g->options->lookup("Overview Mode") eq "On";  $g->default("shape", "box", "node");  $g->default("color", "blue", "node");  $g->default("color", "black", "edge");  $g->default("style", "solid", "edge");  my @nodes = createFlowchart($entity,$expandmacros,$collapse);  open CONTROLFLOW,">D:/controlflow.txt";    my @graphNodes; my @nodehash;    #Draw the nodes  foreach my $node(@nodes){    my $nodeid = $node->get("id");    my $startName = $nodeid eq 0 && $g->options->lookup("Display Entity Name") eq "On";        my $graphNode = $g->node($nodeid);       $graphNode->sync($node->get("file_ent"), $node->get("line"), 0);    #Node Text    my $text = $node->get("label") ;    $text .= "\n(".$entity->longname.")" if $startName;	    my $nodeComment = $node->get("comment");    if ($nodeComment){      $text = $nodeComment if $allComments;      $text ="/*".$nodeComment."*/\n".$text if $codeAndComments;      $text = $nodeComment if  $comment_conditional && $node->get("type") eq "conditional";    }        $text = "" if $overviewMode;    $graphNode->set("label", $text);        #Other node properties    $graphNode->set("color", $node->get("color")) if $node->get("color");    $graphNode->set("shape", $node->get("shape")) if $node->get("shape");    $graphNode->set("color", "red") if $node->get("unreachable");    $graphNode->set("shape", "box") if $startName;        $graphNodes[$nodeid] = $graphNode;     $nodehash[$nodeid] = $node;  }  #Draw the edges  foreach my $node(@nodes){    foreach my $edge ($node->edgeList()){
$source = $edge->get("source");    $target = $edge->get("target");     my $srcGraphNode = $graphNodes[$source]; my $targetGraphNode = $graphNodes[$target]; my $graphEdge = $g->edge($srcGraphNode, $targetGraphNode); $graphEdge->set("color",$edge->get("color")); $graphEdge->set("label",$edge->get("type")) unless $overviewMode; print CONTROLFLOW $nodehash[$source]->get("label")." ".$nodehash[$target]->get("label")."\n"; } } close HELLO; } 当用命令行运行函数的draw(“control flow”)方法时,内部调用上面这个文件,在D盘生成我们所需要的含有控制流信息的文件。

转载于:https://www.cnblogs.com/salious/archive/2011/10/23/2222075.html

你可能感兴趣的文章
[小北De编程手记] : Lesson 05 玩转 xUnit.Net 之 从Assert谈UT框架实践
查看>>
我的记忆,我的年
查看>>
search Paths $(SRCROOT)和$(PROJECT_DIR)区别
查看>>
项目中坑(一)
查看>>
bam文件测序深度统计-bamdst
查看>>
JS 小数的常用处理方法
查看>>
Dom4J两种节点添加方法比较
查看>>
BZOJ2212——线段树合并
查看>>
背包九讲之四(混合三种背包问题)
查看>>
radio选中
查看>>
uva 725 Division(暴力模拟)
查看>>
上传文件、上传按钮、Form组件上传文件
查看>>
一个项目中既有移动端,同时也有PC端的代码,并且 他们的代码分开写的,那么如何实现在手机跳转手机页面,pc点击跳转pc页面...
查看>>
无限循环小数POJ1930
查看>>
如何选择适合自己公司的移动办公系统?
查看>>
Linux下批量添加用户的两种方法
查看>>
JS-DOM
查看>>
ubuntu install wiznote
查看>>
nginx 入门配置
查看>>
poj 1014 Dividing 【多重背包】
查看>>