aaronp-zomg 1.0.2.20080827232412
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +25 -0
- data/Manifest.txt +238 -0
- data/README.txt +59 -0
- data/Rakefile +43 -0
- data/bin/omfg +56 -0
- data/lib/scanner.rex +169 -0
- data/lib/yacc.y +861 -0
- data/lib/zomg.rb +22 -0
- data/lib/zomg/idl.rb +14 -0
- data/lib/zomg/idl/nodes/attribute.rb +15 -0
- data/lib/zomg/idl/nodes/binary.rb +19 -0
- data/lib/zomg/idl/nodes/constant.rb +15 -0
- data/lib/zomg/idl/nodes/interface.rb +13 -0
- data/lib/zomg/idl/nodes/interface_header.rb +14 -0
- data/lib/zomg/idl/nodes/member.rb +14 -0
- data/lib/zomg/idl/nodes/node.rb +54 -0
- data/lib/zomg/idl/nodes/operation.rb +17 -0
- data/lib/zomg/idl/nodes/parameter.rb +18 -0
- data/lib/zomg/idl/nodes/typedef.rb +13 -0
- data/lib/zomg/idl/nodes/union.rb +14 -0
- data/lib/zomg/idl/parser.rb +54 -0
- data/lib/zomg/idl/visitable.rb +15 -0
- data/lib/zomg/idl/visitors/duhr.rb +24 -0
- data/lib/zomg/idl/visitors/ruby_sexp.rb +204 -0
- data/lib/zomg/idl/visitors/sexp.rb +274 -0
- data/lib/zomg/version.rb +3 -0
- data/test/assets/array/array1.idl +60 -0
- data/test/assets/array/array2.idl +38 -0
- data/test/assets/array/array3.idl +8 -0
- data/test/assets/array/array4.idl +7 -0
- data/test/assets/array/array5.idl +80 -0
- data/test/assets/attribute/grid_0attribs_2methods.idl +16 -0
- data/test/assets/attribute/grid_1ROattribs_1attribs_0methods.idl +19 -0
- data/test/assets/attribute/grid_1ROattribs_1attribs_1methods.idl +19 -0
- data/test/assets/attribute/grid_1ROattribs_1attribs_2methods.idl +17 -0
- data/test/assets/attribute/grid_1ROattribs_1methods.idl +16 -0
- data/test/assets/attribute/grid_1ROattribs_2methods.idl +16 -0
- data/test/assets/attribute/grid_1attribs_1methods.idl +17 -0
- data/test/assets/attribute/grid_1attribs_2methods.idl +17 -0
- data/test/assets/attribute/grid_2ROattribs_0methods.idl +16 -0
- data/test/assets/attribute/grid_2ROattribs_1methods.idl +16 -0
- data/test/assets/attribute/grid_2ROattribs_2methods.idl +16 -0
- data/test/assets/attribute/grid_2attribs_0methods.idl +19 -0
- data/test/assets/attribute/grid_2attribs_1methods.idl +19 -0
- data/test/assets/attribute/grid_2attribs_2methods.idl +19 -0
- data/test/assets/comment/c_style_comments.idl +63 -0
- data/test/assets/comment/comment1.idl +57 -0
- data/test/assets/comment/cpp_style_comments.idl +168 -0
- data/test/assets/comment/shortform.idl +0 -0
- data/test/assets/complex/TestCodeSets.idl +10 -0
- data/test/assets/complex/TestIntfContext.idl +13 -0
- data/test/assets/complex/TestIntfLongLong.idl +51 -0
- data/test/assets/complex/TestIntfWChar.idl +52 -0
- data/test/assets/complex/any1.idl +22 -0
- data/test/assets/complex/complex1.idl +495 -0
- data/test/assets/complex/complex2.idl +730 -0
- data/test/assets/complex/complex3.idl +181 -0
- data/test/assets/complex/complex4.idl +181 -0
- data/test/assets/complex/interop_wchar.idl +60 -0
- data/test/assets/constant/constant1.idl +37 -0
- data/test/assets/constant/constant2.idl +29 -0
- data/test/assets/constant/constant3.idl +50 -0
- data/test/assets/constant/constant4.idl +21 -0
- data/test/assets/constant/constant5.idl +65 -0
- data/test/assets/constant/constant6.idl +144 -0
- data/test/assets/constant/constant7.idl +30 -0
- data/test/assets/enum/enum1.idl +13 -0
- data/test/assets/exception/TestIntfExceptions.idl +69 -0
- data/test/assets/exception/TestIntfExceptionsExt_2_0.idl +34 -0
- data/test/assets/exception/TestIntfExceptionsExt_2_3.idl +24 -0
- data/test/assets/exception/ex1.idl +6 -0
- data/test/assets/exception/ex2.idl +18 -0
- data/test/assets/exception/ex3.idl +10 -0
- data/test/assets/exception/ex4.idl +20 -0
- data/test/assets/exception/sc.idl +0 -0
- data/test/assets/exception/simple1.idl +18 -0
- data/test/assets/exception/simple2.idl +25 -0
- data/test/assets/factory/factory1.idl +77 -0
- data/test/assets/factory/objref.idl +25 -0
- data/test/assets/forward/forward.idl +15 -0
- data/test/assets/forward/forward1.idl +13 -0
- data/test/assets/forward/fwd_incl1.idl +6 -0
- data/test/assets/forward/fwd_incl2.idl +7 -0
- data/test/assets/include/a.idl +23 -0
- data/test/assets/include/b.idl +16 -0
- data/test/assets/include/employee.idl +12 -0
- data/test/assets/include/include1.idl +10 -0
- data/test/assets/include/include2.idl +5 -0
- data/test/assets/include/manager.idl +10 -0
- data/test/assets/include/pragma.idl +41 -0
- data/test/assets/include/rookie.idl +13 -0
- data/test/assets/include/rookiemanager.idl +15 -0
- data/test/assets/include/sample.idl +58 -0
- data/test/assets/include/sample_incl.idl +406 -0
- data/test/assets/inherit/IDL1.idl +18 -0
- data/test/assets/inherit/IDL2.idl +18 -0
- data/test/assets/inherit/IDL3.idl +18 -0
- data/test/assets/inherit/IDL4.idl +17 -0
- data/test/assets/inherit/diamond_inheritance.idl +31 -0
- data/test/assets/inherit/inherit.idl +27 -0
- data/test/assets/limit/longidentifiers.idl +25 -0
- data/test/assets/limit/namelens.idl +26 -0
- data/test/assets/limit/tpztest.idl +21 -0
- data/test/assets/module/module1.idl +29 -0
- data/test/assets/module/module2.idl +34 -0
- data/test/assets/module/module3.idl +20 -0
- data/test/assets/module/module4.idl +15 -0
- data/test/assets/nested/nested1.idl +5 -0
- data/test/assets/nested/nested2.idl +11 -0
- data/test/assets/operations/Benchmark.idl +331 -0
- data/test/assets/operations/CCS.idl +82 -0
- data/test/assets/operations/TestIntf.idl +40 -0
- data/test/assets/operations/TestIntfBasic.idl +653 -0
- data/test/assets/operations/atomic.idl +40 -0
- data/test/assets/operations/dif2.idl +48 -0
- data/test/assets/operations/interface1.idl +16 -0
- data/test/assets/operations/parameters.idl +111 -0
- data/test/assets/operations/perf.idl +84 -0
- data/test/assets/operations/timer.idl +104 -0
- data/test/assets/preprocess/base_for_diamond_inheritance_with_macros.idl +17 -0
- data/test/assets/preprocess/basic_macro_marshalling.idl +54 -0
- data/test/assets/preprocess/diamond_inheritance_with_macros.idl +74 -0
- data/test/assets/preprocess/macro1.idl +52 -0
- data/test/assets/preprocess/preprocess1.idl +246 -0
- data/test/assets/preprocess/preprocess2.idl +3 -0
- data/test/assets/recursion/loop.idl +28 -0
- data/test/assets/recursion/recursion1.idl +47 -0
- data/test/assets/recursion/recursion2.idl +74 -0
- data/test/assets/scenarios/filestat.idl +69 -0
- data/test/assets/scenarios/gateway.idl +176 -0
- data/test/assets/scenarios/library.idl +20 -0
- data/test/assets/scenarios/phone.idl +24 -0
- data/test/assets/scenarios/ticketservice.idl +118 -0
- data/test/assets/scope/scope01.idl +58 -0
- data/test/assets/scope/scope02.idl +25 -0
- data/test/assets/scope/scope03.idl +22 -0
- data/test/assets/scope/scope04.idl +27 -0
- data/test/assets/scope/scope05.idl +30 -0
- data/test/assets/scope/scope06.idl +51 -0
- data/test/assets/scope/scope07.idl +20 -0
- data/test/assets/scope/scope08.idl +88 -0
- data/test/assets/scope/scope09.idl +21 -0
- data/test/assets/scope/scope10.idl +95 -0
- data/test/assets/scope/scope11.idl +62 -0
- data/test/assets/scope/scope12.idl +117 -0
- data/test/assets/scope/scope13.idl +117 -0
- data/test/assets/scope/scope14.idl +117 -0
- data/test/assets/scope/scope15.idl +117 -0
- data/test/assets/scope/scope16.idl +117 -0
- data/test/assets/scope/scope17.idl +117 -0
- data/test/assets/scope/scope18.idl +117 -0
- data/test/assets/scope/scope19.idl +117 -0
- data/test/assets/scope/scope20.idl +215 -0
- data/test/assets/scope/scope21.idl +215 -0
- data/test/assets/scope/scope22.idl +205 -0
- data/test/assets/scope/scope23.idl +261 -0
- data/test/assets/scope/scope24.idl +376 -0
- data/test/assets/scope/scope25.idl +266 -0
- data/test/assets/scope/scope26.idl +180 -0
- data/test/assets/scope/scope27.idl +184 -0
- data/test/assets/scope/scope28.idl +182 -0
- data/test/assets/scope/scope29.idl +182 -0
- data/test/assets/scope/scope30.idl +40 -0
- data/test/assets/scope/scope31.idl +33 -0
- data/test/assets/scope/scope32.idl +37 -0
- data/test/assets/scope/scope33.idl +50 -0
- data/test/assets/scope/scope34.idl +97 -0
- data/test/assets/scope/scope35.idl +72 -0
- data/test/assets/scope/scope36.idl +167 -0
- data/test/assets/scope/scope37.idl +57 -0
- data/test/assets/scope/scope38.idl +38 -0
- data/test/assets/scope/scope39.idl +38 -0
- data/test/assets/scope/scope40.idl +38 -0
- data/test/assets/scope/scope41.idl +24 -0
- data/test/assets/scope/scope42.idl +64 -0
- data/test/assets/scope/scope43.idl +66 -0
- data/test/assets/scope/scope44.idl +52 -0
- data/test/assets/sequence/sequence1.idl +24 -0
- data/test/assets/sequence/sequence2.idl +9 -0
- data/test/assets/simple/basictypes1.idl +80 -0
- data/test/assets/simple/basictypes2.idl +197 -0
- data/test/assets/simple/basictypes3.idl +23 -0
- data/test/assets/simple/basictypes4.idl +73 -0
- data/test/assets/simple/basictypes5.idl +29 -0
- data/test/assets/simple/basictypes6.idl +63 -0
- data/test/assets/simple/simple1.idl +45 -0
- data/test/assets/simple/simple2.idl +61 -0
- data/test/assets/simple/simple3.idl +36 -0
- data/test/assets/string/string1.idl +11 -0
- data/test/assets/string/string2.idl +29 -0
- data/test/assets/struct/struct1.idl +20 -0
- data/test/assets/struct/struct2.idl +21 -0
- data/test/assets/struct/struct3.idl +42 -0
- data/test/assets/struct/struct4.idl +57 -0
- data/test/assets/struct/struct5.idl +71 -0
- data/test/assets/typecode/orb.idl +0 -0
- data/test/assets/typecode/pseudo.idl +25 -0
- data/test/assets/typedef/shorthand_typedef_struct_insideIF.idl +17 -0
- data/test/assets/typedef/shorthand_typedef_struct_insideIF_noMO.idl +16 -0
- data/test/assets/typedef/shorthand_typedef_struct_insideMO.idl +17 -0
- data/test/assets/typedef/shorthand_typedef_struct_outsideMO.idl +17 -0
- data/test/assets/typedef/typedef1.idl +8 -0
- data/test/assets/typedef/typedef2.idl +22 -0
- data/test/assets/typedef/typedef_struct_insideIF.idl +18 -0
- data/test/assets/typedef/typedef_struct_insideMO.idl +18 -0
- data/test/assets/typedef/typedef_struct_outsideMO.idl +18 -0
- data/test/assets/union/union1.idl +31 -0
- data/test/assets/union/union2.idl +22 -0
- data/test/assets/union/union3.idl +26 -0
- data/test/conversions/test_attribute.rb +46 -0
- data/test/conversions/test_enum.rb +25 -0
- data/test/conversions/test_exception.rb +24 -0
- data/test/conversions/test_forward_declaration.rb +22 -0
- data/test/conversions/test_interface.rb +30 -0
- data/test/conversions/test_module.rb +24 -0
- data/test/conversions/test_struct.rb +25 -0
- data/test/conversions/test_typedef.rb +22 -0
- data/test/conversions/test_union.rb +27 -0
- data/test/conversions/test_value_box_dcl.rb +22 -0
- data/test/helper.rb +23 -0
- data/test/simple/test_basictypes1.rb +87 -0
- data/test/simple/test_basictypes2.rb +18 -0
- data/test/simple/test_basictypes3.rb +32 -0
- data/test/simple/test_basictypes4.rb +25 -0
- data/test/simple/test_basictypes5.rb +17 -0
- data/test/simple/test_basictypes6.rb +19 -0
- data/test/simple/test_simple1.rb +40 -0
- data/test/simple/test_simple2.rb +48 -0
- data/test/simple/test_simple3.rb +20 -0
- data/test/test_array.rb +22 -0
- data/test/test_assets.rb +33 -0
- data/test/test_complex.rb +17 -0
- data/test/test_node.rb +16 -0
- data/test/test_parser.rb +17 -0
- data/test/test_scanner.rb +234 -0
- metadata +334 -0
data/lib/zomg.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'ruby2ruby'
|
2
|
+
require 'zomg/version'
|
3
|
+
require 'zomg/idl'
|
4
|
+
|
5
|
+
%w{
|
6
|
+
node
|
7
|
+
attribute
|
8
|
+
binary
|
9
|
+
constant
|
10
|
+
interface
|
11
|
+
interface_header
|
12
|
+
member
|
13
|
+
operation
|
14
|
+
parameter
|
15
|
+
typedef
|
16
|
+
union
|
17
|
+
}.each { |node_type|
|
18
|
+
require "zomg/idl/nodes/#{node_type}"
|
19
|
+
}
|
20
|
+
require 'zomg/idl/scanner'
|
21
|
+
require 'zomg/idl/lexer'
|
22
|
+
require 'zomg/idl/parser'
|
data/lib/zomg/idl.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'zomg/idl/visitable'
|
2
|
+
require 'zomg/idl/visitors/sexp'
|
3
|
+
require 'zomg/idl/visitors/ruby_sexp'
|
4
|
+
require 'zomg/idl/visitors/duhr'
|
5
|
+
|
6
|
+
module ZOMG
|
7
|
+
module IDL
|
8
|
+
class << self
|
9
|
+
def parse(contents)
|
10
|
+
ZOMG::IDL::Parser.parse(contents)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Nodes
|
4
|
+
class Attribute < Node
|
5
|
+
alias :names :children
|
6
|
+
attr_accessor :type, :readonly
|
7
|
+
def initialize(type, names, readonly = false)
|
8
|
+
super(names)
|
9
|
+
@type = type
|
10
|
+
@readonly = readonly
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Nodes
|
4
|
+
class Binary < Node
|
5
|
+
attr_accessor :left
|
6
|
+
alias :right :children
|
7
|
+
def initialize(left, right)
|
8
|
+
@left = left
|
9
|
+
super(right)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
%w{ MultiplyExpr PlusExpr ModulusExpr ShiftLeftExpr MinusExpr
|
13
|
+
DivideExpr OrExpr AmpersandExpr
|
14
|
+
}.each do |type|
|
15
|
+
const_set(type.to_sym, Class.new(Binary))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Nodes
|
4
|
+
class InterfaceHeader < Node
|
5
|
+
attr_accessor :abstract, :name
|
6
|
+
def initialize(abstract, name, inheritance_spec = [])
|
7
|
+
@abstract = abstract
|
8
|
+
@name = name
|
9
|
+
super(inheritance_spec)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Nodes
|
4
|
+
class Node
|
5
|
+
include Visitable
|
6
|
+
include Visitors
|
7
|
+
|
8
|
+
attr_accessor :children, :name
|
9
|
+
def initialize(children = [], options = {})
|
10
|
+
@children = children
|
11
|
+
options.each { |k,v| send(:"#{k}=", v) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_i
|
15
|
+
children.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def duhr
|
19
|
+
Duhr.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_sexp
|
23
|
+
Sexp.new.accept(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_ruby_sexp
|
27
|
+
RubySexp.new.accept(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_ruby(prefix = nil)
|
31
|
+
r2r = Ruby2Ruby.new
|
32
|
+
ruby_code = r2r.process(to_ruby_sexp)
|
33
|
+
if prefix
|
34
|
+
modules = prefix.split(/::/).map { |m| "module #{m}\n" }
|
35
|
+
ends = modules.map { |m| "end" }.join("\n")
|
36
|
+
"#{modules}#{ruby_code}\n#{ends}"
|
37
|
+
else
|
38
|
+
ruby_code
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
%w{ Boolean Char Double Float Long Octet Short UnsignedLong
|
43
|
+
UnsignedShort ElementSpec CaseLabel DefaultLabel IntegerLiteral
|
44
|
+
Sequence ArraySize Void In Out InOut CharacterLiteral
|
45
|
+
UnsignedLongLong LongLong Any ForwardDeclaration WChar
|
46
|
+
FloatingPointLiteral BooleanLiteral Context StringLiteral
|
47
|
+
WideStringLiteral WideCharacterLiteral UnaryMinus Object
|
48
|
+
UnaryPlus WString String Case Enum Exception ValueBoxDcl
|
49
|
+
Struct ScopedName Module ArrayDeclarator SimpleDeclarator
|
50
|
+
Specification
|
51
|
+
}.each { |type| const_set(type.to_sym, Class.new(Node)) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Nodes
|
4
|
+
class Operation < Node
|
5
|
+
attr_accessor :attribute, :returns, :name, :raises, :context
|
6
|
+
def initialize(attribute, returns, name, params, raises, context)
|
7
|
+
super(params)
|
8
|
+
@attribute = attribute
|
9
|
+
@returns = returns
|
10
|
+
@name = name
|
11
|
+
@raises = raises
|
12
|
+
@context = context
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Nodes
|
4
|
+
class Parameter < Node
|
5
|
+
attr_accessor :attribute, :type, :declarator
|
6
|
+
def initialize(attribute, type, declarator)
|
7
|
+
@attribute = attribute
|
8
|
+
@type = type
|
9
|
+
@declarator = declarator
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
declarator.name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
class Parser < Lexer
|
4
|
+
class << self
|
5
|
+
def parse_file(filename)
|
6
|
+
new.parse_file(filename)
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse(string)
|
10
|
+
new.parse(string)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@scanner = Scanner.new
|
16
|
+
@yydebug = false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse an IDL string
|
20
|
+
def parse(contents)
|
21
|
+
@scanner.scan_evaluate(contents)
|
22
|
+
do_parse
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_file(filename)
|
26
|
+
contents = File.read(filename)
|
27
|
+
if contents =~ /^\s*#/
|
28
|
+
dir = File.dirname(File.expand_path(filename))
|
29
|
+
contents = IO.popen("gcc -E -I #{dir} -I . -", 'w+') { |io|
|
30
|
+
io.write(contents)
|
31
|
+
io.close_write
|
32
|
+
io.read
|
33
|
+
}
|
34
|
+
end
|
35
|
+
parse(contents)
|
36
|
+
end
|
37
|
+
|
38
|
+
def next_token
|
39
|
+
token = @scanner.next_token
|
40
|
+
return [false, false] unless token
|
41
|
+
token = next_token() if token[0] == :T_COMMENT
|
42
|
+
token = next_token() if token[0] == :T_PREPROCESSOR
|
43
|
+
token = next_token() if token[0] == :T_PRAGMA
|
44
|
+
token
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_error(error_token_id, error_value, value_stack)
|
48
|
+
puts token_to_str(error_token_id)
|
49
|
+
puts error_value
|
50
|
+
p value_stack.last
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Visitable
|
4
|
+
# Based off the visitor pattern from RubyGarden
|
5
|
+
def accept(visitor, &block)
|
6
|
+
klass = self.class
|
7
|
+
method_name = :"visit_#{klass.name.split(/::/).last}"
|
8
|
+
unless visitor.respond_to?(method_name)
|
9
|
+
raise "No visitor for #{self.class}"
|
10
|
+
end
|
11
|
+
visitor.send(method_name, self, &block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Visitors
|
4
|
+
# Stupid path navigation
|
5
|
+
class Duhr
|
6
|
+
attr_accessor :tree
|
7
|
+
def initialize(tree)
|
8
|
+
@tree = tree
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_sexp; @tree.to_sexp; end
|
12
|
+
|
13
|
+
def [](i)
|
14
|
+
Duhr.new(@tree[i])
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(sym, *args)
|
18
|
+
klass = ZOMG::IDL::Nodes.const_get(sym)
|
19
|
+
Duhr.new(tree.children.find_all { |child| child.is_a?(klass) })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
module ZOMG
|
2
|
+
module IDL
|
3
|
+
module Visitors
|
4
|
+
class RubySexp
|
5
|
+
def visit_Specification(o)
|
6
|
+
[:block] + o.children.map { |c| c.accept(self) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def visit_Module(o)
|
10
|
+
[ :module,
|
11
|
+
classify(o.name),
|
12
|
+
[:scope, [:block] +
|
13
|
+
o.children.map { |c| c.accept(self) }.compact
|
14
|
+
]
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def visit_Interface(o)
|
19
|
+
header = o.header.accept(self)
|
20
|
+
header = header ? [:block, header] : [:block]
|
21
|
+
o.children.each { |c|
|
22
|
+
list = c.accept(self)
|
23
|
+
if list
|
24
|
+
if list.first.is_a?(Symbol)
|
25
|
+
header << list
|
26
|
+
else
|
27
|
+
header += list
|
28
|
+
end
|
29
|
+
end
|
30
|
+
}
|
31
|
+
[ :module,
|
32
|
+
classify(o.header.name),
|
33
|
+
[:scope,
|
34
|
+
header
|
35
|
+
]
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def visit_InterfaceHeader(o)
|
40
|
+
if o.children.length > 0
|
41
|
+
[:fcall, :include,
|
42
|
+
[:array] + o.children.map { |c|
|
43
|
+
[:const, classify(c.accept(self))]
|
44
|
+
} ]
|
45
|
+
else
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def visit_Exception(o)
|
51
|
+
attributes = o.children.length > 0 ?
|
52
|
+
[:scope, [:fcall,
|
53
|
+
:attr_accessor,
|
54
|
+
[:array] +
|
55
|
+
o.children.map { |c|
|
56
|
+
c.accept(self)
|
57
|
+
}.flatten.map { |att| [:lit, att] }
|
58
|
+
]] : [:scope]
|
59
|
+
|
60
|
+
[:class, classify(o.name), [:const, :Exception], attributes]
|
61
|
+
end
|
62
|
+
|
63
|
+
def visit_Attribute(o)
|
64
|
+
attributes = []
|
65
|
+
o.children.each { |name|
|
66
|
+
name = name.accept(self)
|
67
|
+
|
68
|
+
# Reader
|
69
|
+
attributes <<
|
70
|
+
[:defn, :"get#{name.to_s.capitalize}",
|
71
|
+
[:scope, [:block, [:args],
|
72
|
+
[:fcall, :raise, [:array,
|
73
|
+
[:call, [:const, :NotImplementedError], :new]]
|
74
|
+
]
|
75
|
+
]]
|
76
|
+
]
|
77
|
+
unless o.readonly
|
78
|
+
attributes <<
|
79
|
+
[:defn, :"set#{name.to_s.capitalize}",
|
80
|
+
[:scope, [:block, [:args, :_],
|
81
|
+
[:fcall, :raise, [:array,
|
82
|
+
[:call, [:const, :NotImplementedError], :new]]
|
83
|
+
]
|
84
|
+
]]
|
85
|
+
]
|
86
|
+
end
|
87
|
+
}
|
88
|
+
attributes
|
89
|
+
end
|
90
|
+
|
91
|
+
def visit_ScopedName(o)
|
92
|
+
o.name.to_sym
|
93
|
+
end
|
94
|
+
|
95
|
+
def visit_Operation(o)
|
96
|
+
[ :defn,
|
97
|
+
o.name.to_sym,
|
98
|
+
[:scope,
|
99
|
+
[:block,
|
100
|
+
[:args] + o.children.map { |c| paramify(c.accept(self)) },
|
101
|
+
[:fcall, :raise, [:array,
|
102
|
+
[:call, [:const, :NotImplementedError], :new]]
|
103
|
+
]
|
104
|
+
]
|
105
|
+
]
|
106
|
+
]
|
107
|
+
end
|
108
|
+
|
109
|
+
def visit_Parameter(o)
|
110
|
+
o.declarator.accept(self)
|
111
|
+
end
|
112
|
+
|
113
|
+
def visit_Constant(o)
|
114
|
+
[:cdecl, o.name.upcase.to_sym, o.value.accept(self)]
|
115
|
+
end
|
116
|
+
|
117
|
+
def visit_Enum(o)
|
118
|
+
[ :cdecl,
|
119
|
+
o.name.to_sym,
|
120
|
+
[:hash] + o.children.inject([]) { |m,c|
|
121
|
+
m += [[:lit, c.to_sym], [:lit, c.to_sym]]
|
122
|
+
}
|
123
|
+
]
|
124
|
+
end
|
125
|
+
|
126
|
+
def visit_IntegerLiteral(o)
|
127
|
+
[:lit, o.to_i]
|
128
|
+
end
|
129
|
+
|
130
|
+
def visit_ValueBoxDcl(o)
|
131
|
+
end
|
132
|
+
|
133
|
+
def visit_Struct(o)
|
134
|
+
[ :cdecl,
|
135
|
+
classify(o.name),
|
136
|
+
[ :call, [:const, :Struct],
|
137
|
+
:new,
|
138
|
+
[:array] + o.children.map { |c|
|
139
|
+
c.accept(self)
|
140
|
+
}.flatten.map { |lit| [:lit, lit] }
|
141
|
+
]
|
142
|
+
]
|
143
|
+
end
|
144
|
+
|
145
|
+
def visit_Union(o)
|
146
|
+
[ :cdecl,
|
147
|
+
o.name.to_sym,
|
148
|
+
[ :call, [:const, :Struct],
|
149
|
+
:new,
|
150
|
+
[:array] + o.children.map { |c|
|
151
|
+
val = c.accept(self)
|
152
|
+
val && [:lit, val]
|
153
|
+
}.compact
|
154
|
+
]
|
155
|
+
]
|
156
|
+
end
|
157
|
+
|
158
|
+
def visit_CaseLabel(o)
|
159
|
+
end
|
160
|
+
|
161
|
+
def visit_Case(o)
|
162
|
+
o.children.last.accept(self)
|
163
|
+
end
|
164
|
+
|
165
|
+
def visit_ElementSpec(o)
|
166
|
+
o.children[1].accept(self)
|
167
|
+
end
|
168
|
+
|
169
|
+
def visit_Member(o)
|
170
|
+
o.children.map { |c| c.accept(self) }
|
171
|
+
end
|
172
|
+
|
173
|
+
def visit_SimpleDeclarator(o)
|
174
|
+
o.name.to_sym
|
175
|
+
end
|
176
|
+
|
177
|
+
def visit_ArrayDeclarator(o)
|
178
|
+
o.name.to_sym
|
179
|
+
end
|
180
|
+
|
181
|
+
def visit_Typedef(o)
|
182
|
+
end
|
183
|
+
|
184
|
+
def visit_ForwardDeclaration(o)
|
185
|
+
end
|
186
|
+
|
187
|
+
def accept(target)
|
188
|
+
target.accept(self)
|
189
|
+
end
|
190
|
+
|
191
|
+
private
|
192
|
+
def classify(string)
|
193
|
+
s = string.to_s
|
194
|
+
:"#{s.slice(0,1).upcase}#{s[1..-1]}"
|
195
|
+
end
|
196
|
+
|
197
|
+
def paramify(string)
|
198
|
+
s = string.to_s
|
199
|
+
:"#{s.slice(0,1).downcase}#{s[1..-1]}"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|