Class: FunctionGraph

Inherits:
Graph
  • Object
show all
Defined in:
lib/codegraph.rb

Direct Known Subclasses

EightFunctionGraph, SingleFunctionGraph

Constant Summary collapse

@@workDir =

internal database for former scans

ENV['HOME'] + '/.codegraph'
@@funxDBfile =
@@workDir+'/funxDB.json'
@@funxDB =
File.exist?(@@funxDBfile) ? JSON.parse(File.open(@@funxDBfile).read) : Hash.new
@@lock =
Mutex.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Graph

#empty?

Constructor Details

#initialize(config) ⇒ FunctionGraph

Returns a new instance of FunctionGraph.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/codegraph.rb', line 131

def initialize(config)
  super(self.class.to_s)
  @config  = config 

  @debug   = @config[:debug]

  @@matchBeforFuncName = @config[:matchBefor].nil? ? '[^A-z0-9_]\s*': @config[:matchBefor]
  @@matchAfterFuncName = @config[:matchAfter].nil? ? '( *\(| |$)'   : @config[:matchAfter]

  @adds     = @config[:adds] || []
  @excludes = @config[:excludes] || []

  @parser   = CodeParser.new
  @parser.read(*@config[:filelist])
  @funx     = @parser.funx
end

Instance Attribute Details

#addsObject

Returns the value of attribute adds.



123
124
125
# File 'lib/codegraph.rb', line 123

def adds
  @adds
end

#debugObject

Returns the value of attribute debug.



123
124
125
# File 'lib/codegraph.rb', line 123

def debug
  @debug
end

#excludesObject

Returns the value of attribute excludes.



123
124
125
# File 'lib/codegraph.rb', line 123

def excludes
  @excludes
end

#funxObject

Returns the value of attribute funx.



123
124
125
# File 'lib/codegraph.rb', line 123

def funx
  @funx
end

Instance Method Details

#scanObject



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/codegraph.rb', line 148

def scan
  jobqueue = JobQueue.new
  # scan functions fo all other function names
  names = @parser.funx.keys + @adds - @excludes
  @parser.funx.each_pair {|name,body|
    next unless names.include?(name)
    jobqueue.push {
      puts "Add func: #{name}" if @debug
      # Check if this body is in the funx DB
      bodyCk = Digest::SHA256.hexdigest(body)
      if @@funxDB.has_key?(bodyCk) and @@funxDB[name] == body
        edges = @@funxDB[bodyCk]
        edges.each {|edge| self.edge(*edge)}
      else
        edges = []
        self.node(name)
        (names - [name]).each { |func|
          if/#@@matchBeforFuncName#{Regexp.escape(func)}#@@matchAfterFuncName/.match(body)
            edge = ["#{name}","#{func}"]
            self.edge(*edge)
            edges << edge
          end
        }
        @@lock.synchronize {
          @@funxDB[bodyCk] = edges
          @@funxDB[name]   = body
        }
      end
    }
  }
  jobqueue.run

  updateFunxDB
end

#showBody(name) ⇒ Object



183
184
185
# File 'lib/codegraph.rb', line 183

def showBody(name)
  @funx[name]
end