codegraph 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gemspec +2 -2
- data/lib/codegraph.rb +55 -62
- metadata +3 -3
data/gemspec
CHANGED
@@ -2,8 +2,8 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
spec = Gem::Specification.new do |s|
|
4
4
|
s.name = "codegraph"
|
5
|
-
s.version = "0.7.
|
6
|
-
s.date = "2010-11-
|
5
|
+
s.version = "0.7.3"
|
6
|
+
s.date = "2010-11-05"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.bindir = 'bin'
|
9
9
|
s.files = ["lib/codegraph.rb","bin/codegraph"] + ["gemspec","LICENSE"]
|
data/lib/codegraph.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'pp'
|
2
3
|
require 'rgl/adjacency'
|
3
4
|
require 'rgl/dot'
|
4
5
|
require 'rgl/rdot'
|
5
6
|
require 'rgl/traversal'
|
7
|
+
require 'thread'
|
6
8
|
|
7
9
|
class FunctionGraph < RGL::DirectedAdjacencyGraph
|
8
10
|
attr_accessor :funx, :internal
|
@@ -46,7 +48,7 @@ class FunctionGraph < RGL::DirectedAdjacencyGraph
|
|
46
48
|
super
|
47
49
|
# the following attribute will hold the functionnames and their bodies
|
48
50
|
@funx = Hash.new
|
49
|
-
|
51
|
+
@lock = Mutex.new
|
50
52
|
# Should the internal functions be displayed?
|
51
53
|
@internal = false
|
52
54
|
|
@@ -57,86 +59,77 @@ class FunctionGraph < RGL::DirectedAdjacencyGraph
|
|
57
59
|
# 2. One for functions inside the file 1
|
58
60
|
# and fill the @funx hash
|
59
61
|
def genFiles(graph, filelist, exclude=[])
|
60
|
-
|
62
|
+
threads = []
|
61
63
|
|
62
|
-
funxFile = "funxnames"
|
63
|
-
ctagsKinds='--c-kinds=f --fortran-kinds=fs --php-kinds=f --perl-kinds=f'
|
64
64
|
filelist.each {|file|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
65
|
+
threads << Thread.new(file, @@codehomedir) {|file,codehomedir|
|
66
|
+
funxFile = "funxnames"
|
67
|
+
ctagsKinds = '--c-kinds=f --fortran-kinds=fs --php-kinds=f --perl-kinds=f'
|
68
|
+
|
69
|
+
puts "Processing #{file} ..." if false
|
70
|
+
basefile = File.basename(file)
|
71
|
+
temfile = "_" + basefile
|
72
|
+
case File.extname(file)
|
73
|
+
when '.c','.h'
|
74
|
+
cppCommand = "cpp -w -fpreprocessed -E -fdirectives-only #{file} -o #{codehomedir}/#{temfile} 2>/dev/null"
|
75
|
+
cppCommand = "cpp -fpreprocessed #{file} -o #{codehomedir}/#{temfile} 2>/dev/null"
|
76
|
+
grep = "grep -v -e '^$' #{codehomedir}/#{temfile} | grep -v -e '^#' > #{codehomedir}/#{basefile}"
|
77
|
+
when '.f','.f77','.f90','.f95'
|
78
|
+
cppCommand = "cp #{file} #{codehomedir}/#{temfile}"
|
79
|
+
grep = "grep -v -e '^$' #{codehomedir}/#{temfile} | grep -v -e '^ *!' > #{codehomedir}/#{basefile}"
|
80
|
+
else
|
81
|
+
cppCommand = "cp #{file} #{codehomedir}/#{temfile}"
|
82
|
+
grep = "grep -v -e '^$' #{codehomedir}/#{temfile} | grep -v -e '^#' > #{codehomedir}/#{basefile}"
|
83
|
+
end
|
84
|
+
gen4ctags = "ctags -x #{ctagsKinds} #{codehomedir}/#{basefile} | sort -n -k 3"
|
85
|
+
command = [cppCommand,grep].join(";")
|
86
|
+
|
87
|
+
puts command if false
|
88
|
+
system(command)
|
89
|
+
|
90
|
+
code = open(codehomedir+'/'+ File.basename(file)).readlines
|
91
|
+
funxLocations = IO.popen(gen4ctags).readlines.map {|l| l.split[0,4]}
|
92
|
+
funxLocations.each_with_index {|ary,i|
|
93
|
+
name, kind, line, file = ary
|
94
|
+
puts name if false
|
95
|
+
line = line.to_i
|
96
|
+
startLineIndex = line - 1
|
97
|
+
endLineIndex = (i+1 < funxLocations.size) ? funxLocations[i+1][2].to_i - 2 : -1
|
98
|
+
body = code[startLineIndex..endLineIndex].join
|
99
|
+
@lock.synchronize {
|
100
|
+
@funx.store(name,body)
|
101
|
+
}
|
102
|
+
}
|
93
103
|
}
|
94
104
|
}
|
105
|
+
threads.each {|t| t.join}
|
95
106
|
|
96
|
-
|
107
|
+
if @funx.empty?
|
97
108
|
puts "no functions found"
|
98
109
|
exit
|
99
110
|
end
|
100
|
-
|
101
|
-
meta = [names, kinds, lines, files]
|
102
|
-
|
103
|
-
# read the source once and save the function bodies as values
|
104
|
-
# of the function names
|
105
|
-
|
106
|
-
metasize = meta[2].size
|
107
|
-
lastfile,code = nil,nil
|
108
|
-
meta.transpose.each_with_index {|ary,i|
|
109
|
-
name, kind, line, file = ary
|
110
|
-
|
111
|
-
if file != lastfile
|
112
|
-
code = open(@@codehomedir+'/'+ File.basename(file)).readlines
|
113
|
-
codeLength = code.length
|
114
|
-
end
|
115
|
-
startLineIndex = meta[2][i]-1
|
116
|
-
endLineIndex = (i+1 < metasize) ? meta[2][i+1] - 2 : -1
|
117
|
-
# code-Index starts with 0 vs. line numbbers in (meta|m).lines start with 1
|
118
|
-
body = code[startLineIndex..endLineIndex].join
|
119
|
-
|
120
|
-
@funx.store(name,body)
|
121
|
-
lastfile = file
|
122
|
-
}
|
123
111
|
end
|
124
112
|
|
125
113
|
# fill the graph with all functions found in <filelist>
|
126
114
|
# while all functions from <exclude> aren't recognized
|
127
115
|
def fill(filelist,exclude=[])
|
116
|
+
threads = []
|
128
117
|
# generate the necessary files and fill @funx
|
129
118
|
genFiles(self,filelist,exclude)
|
130
119
|
|
131
120
|
# scan functions for the function names
|
132
121
|
names = @funx.keys
|
133
122
|
@funx.each_pair {|name,body|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
123
|
+
# threads << Threads.new(name,body,names) {|name,body|
|
124
|
+
puts "Add func: #{name}" if false
|
125
|
+
add_vertex(name)
|
126
|
+
(names - [name] + @@internal_funx).each { |func|
|
127
|
+
puts body if false
|
128
|
+
add_edge("#{name}","#{func}") if/#@@matchBeforFuncName#{func}#@@matchAfterFuncName/.match(body)
|
129
|
+
}
|
130
|
+
}
|
131
|
+
# }
|
132
|
+
# threads.each {|t| t.join}
|
140
133
|
end
|
141
134
|
|
142
135
|
def limit(depth)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 3
|
9
|
+
version: 0.7.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ralf Mueller
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-05 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|