lib/rley/gfg/grm_flow_graph.rb in rley-0.4.06 vs lib/rley/gfg/grm_flow_graph.rb in rley-0.4.07
- old
+ new
@@ -52,34 +52,36 @@
self.to_visit = aVertex.edges.dup
self.visited = []
end
def done?
- self.to_visit.empty?
+ to_visit.empty?
end
def next_edge
- next_one = self.to_visit.shift
- self.visited << next_one.successor unless next_one.nil?
+ next_one = to_visit.shift
+ visited << next_one.successor unless next_one.nil?
return next_one
end
end
# Walk over all the vertices of the graph that are reachable from a given
# start vertex. This is a depth-first graph traversal.
- # @param aStartVertex [StartVertex] the depth-first traversal begins from here
- # @param visitAction [Proc] block code called when a new graph vertex is found
- def traverse_df(aStartVertex, &visitAction)
+ # @param aStartVertex [StartVertex] the depth-first traversal begins
+ # from here
+ # @param visitAction [Proc] block code called when a new graph vertex
+ # is found
+ def traverse_df(aStartVertex, &_visitAction)
visited = Set.new
stack = []
visitee = aStartVertex
begin
first_time = !visited.include?(visitee)
if first_time
- visitAction.call(visitee)
+ yield(visitee)
visited << visitee
end
case visitee
when Rley::GFG::StartVertex
@@ -102,11 +104,11 @@
curr_edge = visitee.edges[0]
end
visitee = curr_edge.successor unless curr_edge.nil?
end until stack.empty?
# Now process the end vertex matching the initial start vertex
- visitAction.call(end_vertex_for[aStartVertex.non_terminal])
+ yield(end_vertex_for[aStartVertex.non_terminal])
end
private
def add_vertex(aVertex)
@@ -163,11 +165,10 @@
new_end_vertex = EndVertex.new(aNonTerminal)
end_vertex_for[aNonTerminal] = new_end_vertex
add_vertex(new_end_vertex)
end
-
def add_single_item(aDottedItem)
new_vertex = ItemVertex.new(aDottedItem)
add_vertex(new_vertex)
build_entry_edge(new_vertex)
build_exit_edge(new_vertex)
@@ -263,11 +264,10 @@
def build_shortcut_edge(fromVertex, toVertex)
ShortcutEdge.new(fromVertex, toVertex)
end
-
# Retrieve the return edge that matches the given
# call edge.
def get_matching_return(aCallEdge)
# Calculate key of return edge from the key of call edge
ret_key = aCallEdge.key.sub(/CALL/, 'RET')
@@ -275,9 +275,10 @@
# Retrieve the corresponding end vertex
end_vertex = end_vertex_for[aCallEdge.successor.non_terminal]
# Retrieve the return edge with specified key
return_edge = end_vertex.edges.find { |edge| edge.key == ret_key }
+ return return_edge
end
# Mark non-terminal symbols that cannot be derived from the start symbol.
# In a GFG, a non-terminal symbol N is unreachable if there is no path
# from the start symbol to the start node .N