Class: FunctionGraph
- Inherits:
-
RGL::DirectedAdjacencyGraph
- Object
- RGL::DirectedAdjacencyGraph
- FunctionGraph
- Defined in:
- lib/codegraph.rb
Direct Known Subclasses
Constant Summary collapse
- Params =
Theses Parameters are used by interactive representation and for the file generation function to_dot and to_type. They can only be given for the whole graph, not for a singel node. This could be done by extending the dot.rb file of the Ruby Graph Library
{'rankdir' => 'LR', 'ranksep' => '4.0', 'concentrate' => 'TRUE', 'label' => '', 'fontsize' => '12'}
- @@home =
`echo $HOME`.chomp
- @@codehomedir =
"#{@@home}/.codegraph"- @@matchBeforFuncName =
'[^A-z0-9_]\s*'- @@matchAfterFuncName =
' *\('- @@map =
Asciify::Mapping.new(:default)
Instance Attribute Summary collapse
-
#adds ⇒ Object
Returns the value of attribute adds.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#excludes ⇒ Object
Returns the value of attribute excludes.
-
#funx ⇒ Object
Returns the value of attribute funx.
Instance Method Summary collapse
-
#display ⇒ Object
Display the graph with an interactive viewer.
- #display_functionbody(name) ⇒ Object
-
#fill(filelist, exclude = []) ⇒ Object
fill the graph with all functions found in <filelist> while all functions from <exclude> aren’t recognized.
-
#initialize ⇒ FunctionGraph
constructor
A new instance of FunctionGraph.
- #limit(depth) ⇒ Object
-
#to_dot(filename) ⇒ Object
Creates a simple dot file according to the above <Params>.
-
#to_txt ⇒ Object
Generates pairs of “func_A -> func_B” to stdout.
-
#to_type(filename, type) ⇒ Object
This function generates a file of the given type using the dot utility.
Constructor Details
#initialize ⇒ FunctionGraph
Returns a new instance of FunctionGraph.
37 38 39 40 41 42 43 |
# File 'lib/codegraph.rb', line 37 def initialize super @debug = false # the following attribute will hold the functionnames and their bodies @funx = Hash.new @lock = Mutex.new end |
Instance Attribute Details
#adds ⇒ Object
Returns the value of attribute adds.
14 15 16 |
# File 'lib/codegraph.rb', line 14 def adds @adds end |
#debug ⇒ Object
Returns the value of attribute debug.
14 15 16 |
# File 'lib/codegraph.rb', line 14 def debug @debug end |
#excludes ⇒ Object
Returns the value of attribute excludes.
14 15 16 |
# File 'lib/codegraph.rb', line 14 def excludes @excludes end |
#funx ⇒ Object
Returns the value of attribute funx.
14 15 16 |
# File 'lib/codegraph.rb', line 14 def funx @funx end |
Instance Method Details
#display ⇒ Object
Display the graph with an interactive viewer
164 165 166 167 |
# File 'lib/codegraph.rb', line 164 def display dotty(Params) system("rm graph.dot") if File.exist?("graph.dot") end |
#display_functionbody(name) ⇒ Object
131 132 133 |
# File 'lib/codegraph.rb', line 131 def display_functionbody(name) @funx[name] end |
#fill(filelist, exclude = []) ⇒ Object
fill the graph with all functions found in <filelist> while all functions from <exclude> aren’t recognized
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/codegraph.rb', line 103 def fill(filelist,exclude=[]) threads = [] # generate the necessary files and fill @funx genFiles(self,filelist,exclude) # scan functions for the function names names = @funx.keys @funx.each_pair {|name,body| # threads << Threads.new(name,body,names) {|name,body| puts "Add func: #{name}" if @debug add_vertex(name) (names - [name] + @adds).each { |func| puts body if @debug add_edge("#{name}","#{func}") if/#@@matchBeforFuncName#{func}#@@matchAfterFuncName/.match(body) } } # } # threads.each {|t| t.join} end |
#limit(depth) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/codegraph.rb', line 123 def limit(depth) dv = RGL::DFSVisitor.new(self) dv.attach_distance_map self.depth_first_search(dv) {|u| self.remove_vertex(u) if dv.distance_to_root(u) > depth } end |
#to_dot(filename) ⇒ Object
Creates a simple dot file according to the above <Params>. Parameters for the nodes are not supported by rgl.
136 137 138 139 140 |
# File 'lib/codegraph.rb', line 136 def to_dot(filename) File.open("#{filename}","w") {|f| print_dotted_on(Params,f) } end |
#to_txt ⇒ Object
Generates pairs of “func_A -> func_B” to stdout
143 144 145 146 147 |
# File 'lib/codegraph.rb', line 143 def to_txt each_edge do |left,right| print left,' -> ',right,"\n" end end |
#to_type(filename, type) ⇒ Object
This function generates a file of the given type using the dot utility. Supported Types are PS, PNG, JPG, DOT and SVG.
151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/codegraph.rb', line 151 def to_type(filename,type) if File.exist?(filename) system("rm #{filename}") end if File.exist?(filename+"."+type) system("rm #{filename}."+type) end to_dot(filename+".dot") system("dot -T#{type} -o #{filename} -Nshape=box #{filename}.dot") system("rm #{filename}.dot") end |