Class: Johnson::SpiderMonkey::MutableTreeVisitor

Inherits:
Object
  • Object
show all
Includes:
Nodes
Defined in:
lib/johnson/spidermonkey/mutable_tree_visitor.rb

Constant Summary

Constants included from Nodes

Nodes::BINARY_NODES, Nodes::LIST_NODES, Nodes::SINGLE_NODES, Nodes::TERNARY_NODES

Instance Method Summary collapse

Instance Method Details

#accept(target) ⇒ Object



237
238
239
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 237

def accept(target)
  target.accept(self)
end

#visit_For(ro_node) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 6

def visit_For(ro_node)
  For.new(  ro_node.line,
            ro_node.index,
            ro_node.pn_left.pn_kid1 && ro_node.pn_left.pn_kid1.accept(self),
            ro_node.pn_left.pn_kid2 && ro_node.pn_left.pn_kid2.accept(self),
            ro_node.pn_left.pn_kid3 && ro_node.pn_left.pn_kid3.accept(self),
            ro_node.pn_right.accept(self)
         )
end

#visit_Function(ro_node) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 36

def visit_Function(ro_node)
  Function.new( ro_node.line,
                ro_node.index,
                ro_node.function_name,
                ro_node.function_args,
                ro_node.function_body.accept(self) )
end

#visit_LexicalScope(ro_node) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 44

def visit_LexicalScope(ro_node)
  LexicalScope.new(
    ro_node.line,
    ro_node.index,
    Name.new(ro_node.line, ro_node.index, "unnamed"), # lexical scope nodes don't hold a name
    ro_node.pn_expr.accept(self))
end

#visit_Name(ro_node) ⇒ Object



16
17
18
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 16

def visit_Name(ro_node)
  Name.new(ro_node.line, ro_node.index, ro_node.name)
end

#visit_Number(ro_node) ⇒ Object



20
21
22
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 20

def visit_Number(ro_node)
  Number.new(ro_node.line, ro_node.index, ro_node.pn_dval)
end

#visit_Regexp(ro_node) ⇒ Object



30
31
32
33
34
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 30

def visit_Regexp(ro_node)
  Regexp.new( ro_node.line,
              ro_node.index,
              ro_node.regexp )
end

#visit_String(ro_node) ⇒ Object



24
25
26
27
28
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 24

def visit_String(ro_node)
  Nodes::String.new(  ro_node.line,
                      ro_node.index,
                      ro_node.name )
end

#visit_Try(ro_node) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/johnson/spidermonkey/mutable_tree_visitor.rb', line 101

def visit_Try(ro_node)
  Try.new(
    ro_node.line,
    ro_node.index,
    ro_node.pn_kid1 && ro_node.pn_kid1.accept(self),
    if ro_node.pn_kid2
      case ro_node.pn_kid2.pn_type
      when :tok_reserved
        ro_node.pn_kid2.children.map { |x| x.pn_expr.accept(self) }
      else
        raise "HALP some other catch #{ro_node.line}, #{ro_node.index}"
      end
    else
      nil
    end,
    ro_node.pn_kid3 && ro_node.pn_kid3.accept(self)
  )
end