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



187
188
189
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 187

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

#visit_ArrayDeclarator(o) ⇒ Object



177
178
179
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 177

def visit_ArrayDeclarator(o)
  o.name.to_sym
end

#visit_Attribute(o) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 63

def visit_Attribute(o)
  attributes = []
  o.children.each { |name|
    name = name.accept(self)

    # Reader
    attributes <<
      [:defn, name.to_sym,
        [:scope, [:block, [:args],
          [:fcall, :raise, [:array,
            [:call, [:const, :NotImplementedError], :new]]
          ]
        ]]
      ]
    unless o.readonly
      attributes <<
        [:defn, :"#{name}=",
          [:scope, [:block, [:args, :_],
            [:fcall, :raise, [:array,
              [:call, [:const, :NotImplementedError], :new]]
            ]
          ]]
        ]
    end
  }
  attributes
end

#visit_Case(o) ⇒ Object



161
162
163
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 161

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

#visit_CaseLabel(o) ⇒ Object



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

def visit_CaseLabel(o)
end

#visit_Constant(o) ⇒ Object



113
114
115
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 113

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

#visit_ElementSpec(o) ⇒ Object



165
166
167
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 165

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

#visit_Enum(o) ⇒ Object



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

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



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

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



184
185
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 184

def visit_ForwardDeclaration(o)
end

#visit_IntegerLiteral(o) ⇒ Object



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

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

#visit_Interface(o) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 18

def visit_Interface(o)
  header = o.header.accept(self)
  header = header ? [:block, header] : [:block]
  o.children.each { |c|
    list = c.accept(self)
    if list
      if list.first.is_a?(Symbol)
        header << list
      else
        header += list
      end
    end
  }
  [ :module,
    classify(o.header.name),
    [:scope,
      header
    ]
  ]
end

#visit_InterfaceHeader(o) ⇒ Object



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

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



169
170
171
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 169

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

#visit_Module(o) ⇒ Object



9
10
11
12
13
14
15
16
# 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) }.compact
  ]
  ]
end

#visit_Operation(o) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 95

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



109
110
111
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 109

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

#visit_ScopedName(o) ⇒ Object



91
92
93
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 91

def visit_ScopedName(o)
  o.name.to_sym
end

#visit_SimpleDeclarator(o) ⇒ Object



173
174
175
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 173

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



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 133

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



181
182
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 181

def visit_Typedef(o)
end

#visit_Union(o) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/zomg/idl/visitors/ruby_sexp.rb', line 145

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



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

def visit_ValueBoxDcl(o)
end