Class: ZOMG::IDL::Visitors::RubySexp

Inherits:
Object
  • Object
show all
Defined in:
lib/zomg/idl/visitors/ruby_sexp.rb

Instance Method Summary collapse

Instance Method Details

#accept(target) ⇒ Object



156
157
158
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 156

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

#visit_ArrayDeclarator(o) ⇒ Object



146
147
148
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 146

def visit_ArrayDeclarator(o)
  o.name.to_sym
end

#visit_Attribute(o) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 52

def visit_Attribute(o)
  [:fcall,
    o.readonly ? :attr_reader : :attr_accessor,
    [:array] +
      o.children.map { |c| [:lit, c.accept(self)] }
  ]
end

#visit_Case(o) ⇒ Object



130
131
132
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 130

def visit_Case(o)
  o.children.last.accept(self)
end

#visit_CaseLabel(o) ⇒ Object



127
128
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 127

def visit_CaseLabel(o)
end

#visit_Constant(o) ⇒ Object



82
83
84
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 82

def visit_Constant(o)
  [:cdecl, o.name.upcase.to_sym, o.value.accept(self)]
end

#visit_ElementSpec(o) ⇒ Object



134
135
136
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 134

def visit_ElementSpec(o)
  o.children[1].accept(self)
end

#visit_Enum(o) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 86

def visit_Enum(o)
  [ :cdecl,
    o.name.to_sym,
    [:hash] + o.children.inject([]) { |m,c| 
      m += [[:lit, c.to_sym], [:lit, c.to_sym]]
    }
  ]
end

#visit_Exception(o) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 39

def visit_Exception(o)
  attributes = o.children.length > 0 ?
    [:scope, [:fcall,
      :attr_accessor,
      [:array] +
        o.children.map { |c|
          c.accept(self)
        }.flatten.map { |att| [:lit, att] }
    ]] : [:scope]

  [:class, classify(o.name), [:const, :Exception], attributes]
end

#visit_ForwardDeclaration(o) ⇒ Object



153
154
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 153

def visit_ForwardDeclaration(o)
end

#visit_IntegerLiteral(o) ⇒ Object



95
96
97
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 95

def visit_IntegerLiteral(o)
  [:lit, o.to_i]
end

#visit_Interface(o) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 16

def visit_Interface(o)
  header = o.header.accept(self)
  header = header ? [:block, header] : [:block]
  [ :module,
    classify(o.header.name),
    [:scope,
      header +
        o.children.map { |c| c.accept(self) }
    ]
  ]
end

#visit_InterfaceHeader(o) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 28

def visit_InterfaceHeader(o)
  if o.children.length > 0
    [:fcall, :include,
      [:array] + o.children.map { |c|
        [:const, classify(c.accept(self))]
    } ]
  else
    nil
  end
end

#visit_Member(o) ⇒ Object



138
139
140
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 138

def visit_Member(o)
  o.children.map { |c| c.accept(self) }
end

#visit_Module(o) ⇒ Object



9
10
11
12
13
14
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 9

def visit_Module(o)
  [ :module,
    classify(o.name),
    [:scope, [:block] + o.children.map { |c| c.accept(self) }]
  ]
end

#visit_Operation(o) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 64

def visit_Operation(o)
  [ :defn,
    o.name.to_sym,
    [:scope,
      [:block,
        [:args] + o.children.map { |c| paramify(c.accept(self)) },
        [:fcall, :raise, [:array,
          [:call, [:const, :NotImplementedError], :new]]
        ]
      ]
    ]
  ]
end

#visit_Parameter(o) ⇒ Object



78
79
80
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 78

def visit_Parameter(o)
  o.declarator.accept(self)
end

#visit_ScopedName(o) ⇒ Object



60
61
62
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 60

def visit_ScopedName(o)
  o.name.to_sym
end

#visit_SimpleDeclarator(o) ⇒ Object



142
143
144
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 142

def visit_SimpleDeclarator(o)
  o.name.to_sym
end

#visit_Specification(o) ⇒ Object



5
6
7
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 5

def visit_Specification(o)
  [:block] + o.children.map { |c| c.accept(self) }
end

#visit_Struct(o) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 102

def visit_Struct(o)
  [ :cdecl,
    classify(o.name),
    [ :call, [:const, :Struct],
      :new,
      [:array] + o.children.map { |c|
        c.accept(self)
      }.flatten.map { |lit| [:lit, lit] }
    ]
  ]
end

#visit_Typedef(o) ⇒ Object



150
151
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 150

def visit_Typedef(o)
end

#visit_Union(o) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 114

def visit_Union(o)
  [ :cdecl,
    o.name.to_sym,
    [ :call, [:const, :Struct],
      :new,
      [:array] + o.children.map { |c|
        val = c.accept(self)
        val && [:lit, val]
      }.compact
    ]
  ]
end

#visit_ValueBoxDcl(o) ⇒ Object



99
100
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 99

def visit_ValueBoxDcl(o)
end