class RubyNext::Language::Rewriters::Predicates::Base
Attributes
count[R]
current_path[R]
predicates_by_path[R]
store[R]
terminated[R]
terminated?[R]
Public Class Methods
new()
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 115 def initialize # total number of predicates @count = 0 # cache of all predicates by path @predicates_by_path = {} # all predicates and their dirty state @store = {} @current_path = [] end
Public Instance Methods
pop()
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 135 def pop current_path.pop end
pred?(name)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 151 def pred?(name) predicates_by_path.key?(current_path + [name]) end
predicate_clause(name, node)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 143 def predicate_clause(name, node) if pred?(name) read_pred(name) else write_pred(name, node) end end
process(ast)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 174 def process(ast) Processor.new(self).process(ast) end
push(path)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 131 def push(path) current_path << path end
read_pred(name)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 155 def read_pred(name) lvar = predicates_by_path.fetch(current_path + [name]) # mark as used store[lvar] = true s(:lvar, lvar) end
reset!()
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 126 def reset! @current_path = [] @terminated = false end
terminate!()
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 139 def terminate! @terminated = true end
write_pred(name, node)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 162 def write_pred(name, node) return node if terminated? @count += 1 lvar = :"__p_#{count}__" predicates_by_path[current_path + [name]] = lvar store[lvar] = false s(:lvasgn, lvar, node) end
Private Instance Methods
s(type, *children)
click to toggle source
# File lib/ruby-next/language/rewriters/pattern_matching.rb, line 180 def s(type, *children) ::Parser::AST::Node.new(type, children) end