Class: Johnson::TraceMonkey::ImmutableNode

Inherits:
Object
  • Object
show all
Defined in:
lib/johnson/tracemonkey/immutable_node.rb

Instance Method Summary collapse

Instance Method Details

#accept(visitor) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/johnson/tracemonkey/immutable_node.rb', line 4

def accept(visitor)
  case pn_arity
  when :pn_list
    handle_list(visitor)
  when :pn_name
    if !pn_used && pn_expr
      m = {
        :tok_colon  => :visit_Label,
        :tok_name   => :visit_AssignExpr,
        :tok_dot    => :visit_DotAccessor,
        :tok_lexicalscope => :visit_LexicalScope
      }[pn_type]
      raise "Unknown type #{pn_type}" unless m
      visitor.send(m, self)
    else
      visitor.visit_Name(self)
    end
  when :pn_binary
    handle_binary(visitor)
  when :pn_unary
    handle_unary(visitor)
  when :pn_nullary
    handle_nullary(visitor)
  when :pn_func
    visitor.visit_Function(self)
  when :pn_ternary
    m = {
      :tok_hook   => :visit_Ternary,
      :tok_if     => :visit_If,
      :tok_try    => :visit_Try,
      :tok_catch  => :visit_Catch,
    }[pn_type]
    raise "Unknown ternary #{pn_type}" unless m
    visitor.send(m, self)
  else
    raise "unkown arity: #{pn_arity}"
  end
end

#to_mutable_treeObject



43
44
45
# File 'lib/johnson/tracemonkey/immutable_node.rb', line 43

def to_mutable_tree
  MutableTreeVisitor.new.accept(self)
end

#to_sexpObject



47
48
49
# File 'lib/johnson/tracemonkey/immutable_node.rb', line 47

def to_sexp
  to_mutable_tree.to_sexp
end