Class: RDL::Typecheck::ASTMapper
- Defined in:
- lib/rdl/typecheck.rb
Overview
Create mapping from file/line numbers to the def that appears at that location
Instance Attribute Summary collapse
-
#line_defs ⇒ Object
Returns the value of attribute line_defs.
Instance Method Summary collapse
- #handler_missing(node) ⇒ Object
-
#initialize(file) ⇒ ASTMapper
constructor
A new instance of ASTMapper.
- #on_def(node) ⇒ Object
- #on_defs(node) ⇒ Object
Constructor Details
#initialize(file) ⇒ ASTMapper
Returns a new instance of ASTMapper.
12 13 14 15 |
# File 'lib/rdl/typecheck.rb', line 12 def initialize(file) @file = file @line_defs = Hash.new # map from line numbers to defs end |
Instance Attribute Details
#line_defs ⇒ Object
Returns the value of attribute line_defs.
10 11 12 |
# File 'lib/rdl/typecheck.rb', line 10 def line_defs @line_defs end |
Instance Method Details
#handler_missing(node) ⇒ Object
17 18 19 |
# File 'lib/rdl/typecheck.rb', line 17 def handler_missing(node) node.children.each { |n| process n if n.is_a?(AST::Node) } end |
#on_def(node) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rdl/typecheck.rb', line 21 def on_def(node) # (def name args body) name, _, body = *node if @line_defs[node.loc.line] raise RuntimeError, "Multiple defs per line (#{name} and #{@line_defs[node.loc.line].children[1]} in #{@file}) currently not allowed" end @line_defs[node.loc.line] = node process body node.updated(nil, nil) end |
#on_defs(node) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rdl/typecheck.rb', line 32 def on_defs(node) # (defs (self) name args body) _, name, _, body = *node if @line_defs[node.loc.line] raise RuntimeError, "Multiple defs per line (#{name} and #{@line_defs[node.loc.line].children[1]} in #{@file}) currently not allowed" end @line_defs[node.loc.line] = node process body node.updated(nil, nil) end |