Module: CodeNode::IR::Graph::BuilderMethods
- Included in:
- CodeNode::IR::Graph
- Defined in:
- lib/code_node/ir/graph/builder_methods.rb
Overview
CodeNode::IR::Graph methods used during the graph building phase
Instance Attribute Summary collapse
- #scope ⇒ Object readonly
Instance Method Summary collapse
-
#add_or_find_duplicate(node) ⇒ Node
Add the given node to the graph and return it.
- #apply_styles ⇒ Object
-
#node_for(node_type, s, opt = {}) {|node| ... } ⇒ Node
Find a node or create it and add it to the graph.
-
#prune ⇒ FixNum
Were any more nodes pruned?.
Instance Attribute Details
#scope ⇒ Object (readonly)
9 10 11 |
# File 'lib/code_node/ir/graph/builder_methods.rb', line 9 def scope @scope end |
Instance Method Details
#add_or_find_duplicate(node) ⇒ Node
Add the given node to the graph and return it. If a node with the same path is already in the graph, do not add it again, and return the original node.
67 68 69 70 |
# File 'lib/code_node/ir/graph/builder_methods.rb', line 67 def add_or_find_duplicate(node) @nodes[node.path] ||= node @nodes[node.path] end |
#apply_styles ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/code_node/ir/graph/builder_methods.rb', line 11 def apply_styles @nodes.each_value do |node| @style_matchers.each do |pair| if pair[0].matches? node node.style.update pair[1] end end end end |
#node_for(node_type, s, opt = {}) {|node| ... } ⇒ Node
Find a node or create it and add it to the graph
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/code_node/ir/graph/builder_methods.rb', line 44 def node_for(node_type, s, opt={}, &block) name = determine_name s return if name.nil? node = if opt[:not_sure_if_nested] search_for_node_in_parent(@scope.last, name) || Node.new(name, :node_type => node_type) else Node.new name, :parent => @scope.last, :node_type => node_type end node = add_or_find_duplicate node unless block.nil? @scope << node block.call node @scope.pop end node end |
#prune ⇒ FixNum
Returns were any more nodes pruned?.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/code_node/ir/graph/builder_methods.rb', line 22 def prune prunees = [] @nodes.each_value do |node| if @exclude_matchers.any? {|m| m.matches? node} prunees << node end end prunees.each do |node| puts " #{node.path}" node.prune @nodes.delete node.path end prunees.length end |