Class: FunctionGraph

Inherits:
Graph
  • Object
show all
Includes:
Digest
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
@@match =
{
  :c => {},
  :f => {}
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Graph

#empty?

Constructor Details

#initialize(config) ⇒ FunctionGraph

Returns a new instance of FunctionGraph.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/codegraph.rb', line 140

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(@debug)
  @parser.read(*@config[:filelist])
  @funx     = @parser.funx
end

Instance Attribute Details

#addsObject

Returns the value of attribute adds.



127
128
129
# File 'lib/codegraph.rb', line 127

def adds
  @adds
end

#debugObject

Returns the value of attribute debug.



127
128
129
# File 'lib/codegraph.rb', line 127

def debug
  @debug
end

#excludesObject

Returns the value of attribute excludes.



127
128
129
# File 'lib/codegraph.rb', line 127

def excludes
  @excludes
end

#funxObject

Returns the value of attribute funx.



127
128
129
# File 'lib/codegraph.rb', line 127

def funx
  @funx
end

Instance Method Details

#scanObject



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
182
183
184
185
186
187
188
189
190
# File 'lib/codegraph.rb', line 157

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 = hexencode(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



192
193
194
# File 'lib/codegraph.rb', line 192

def showBody(name)
  @funx[name]
end