Class: RDG::CFG

Inherits:
Object
  • Object
show all
Defined in:
lib/rdg/cfg.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ CFG

Returns a new instance of CFG.



17
18
19
20
21
# File 'lib/rdg/cfg.rb', line 17

def initialize(ast)
  @context = Analysis::Context.new
  @context.graph.add_vertex(ast.root)
  analyse(ast)
end

Class Method Details

.from_path(path) ⇒ Object



9
10
11
# File 'lib/rdg/cfg.rb', line 9

def self.from_path(path)
  new(Tree::AST.from_path(path))
end

.from_source(source) ⇒ Object



13
14
15
# File 'lib/rdg/cfg.rb', line 13

def self.from_source(source)
  new(Tree::AST.from_source(source))
end

Instance Method Details

#edge?(u, v) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rdg/cfg.rb', line 35

def edge?(u, v)
  @context.graph.has_edge?(u, v)
end

#successors(v) ⇒ Object



31
32
33
# File 'lib/rdg/cfg.rb', line 31

def successors(v)
  @context.graph.each_adjacent(v).to_a
end

#verticesObject



27
28
29
# File 'lib/rdg/cfg.rb', line 27

def vertices
  @context.graph.each_vertex.to_a
end

#write_to_graphic_file(format = 'png', filename = "cfg") ⇒ Object



23
24
25
# File 'lib/rdg/cfg.rb', line 23

def write_to_graphic_file(format = 'png', filename = "cfg")
  @context.graph.write_to_graphic_file(format, filename)
end