ffi-swig-generator 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.hg/branch.cache +2 -0
- data/.hg/dirstate +0 -0
- data/.hg/store/00changelog.i +0 -0
- data/.hg/store/00manifest.i +0 -0
- data/.hg/store/data/.hgignore.i +0 -0
- data/.hg/store/data/.hgtags.i +0 -0
- data/.hg/store/data/_history.txt.i +0 -0
- data/.hg/store/data/_r_e_a_d_m_e.rdoc.i +0 -0
- data/.hg/store/data/_rakefile.i +0 -0
- data/.hg/store/data/cucumber.yml.i +0 -0
- data/.hg/store/data/examples/_rakefile.i +0 -0
- data/.hg/store/data/features/generate.feature.i +0 -0
- data/.hg/store/data/features/step__definitions/generate.rb.i +0 -0
- data/.hg/store/data/features/support/env.rb.i +0 -0
- data/.hg/store/data/features/support/results.rb.i +0 -0
- data/.hg/store/data/features/support/templates.rb.i +0 -0
- data/.hg/store/data/lib/ffi-swig-generator.rb.i +0 -0
- data/.hg/store/data/lib/generator/application.rb.i +0 -0
- data/.hg/store/data/lib/generator/constant.rb.i +0 -0
- data/.hg/store/data/lib/generator/enum.rb.i +0 -0
- data/.hg/store/data/lib/generator/function.rb.i +0 -0
- data/.hg/store/data/lib/generator/generator.rb.i +0 -0
- data/.hg/store/data/lib/generator/generatortask.rb.i +0 -0
- data/.hg/store/data/lib/generator/logger.rb.i +0 -0
- data/.hg/store/data/lib/generator/node.rb.i +0 -0
- data/.hg/store/data/lib/generator/parser.rb.i +0 -0
- data/.hg/store/data/lib/generator/struct.rb.i +0 -0
- data/.hg/store/data/lib/generator/type.rb.i +0 -0
- data/.hg/store/data/lib/generator/types.rb.i +0 -0
- data/.hg/store/data/spec/generator/constant__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/enum__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/function__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/generator__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/node__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/parser__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/struct__spec.rb.i +0 -0
- data/.hg/store/data/spec/generator/swig/constants.i.i +0 -0
- data/.hg/store/data/spec/generator/swig/functions.i.i +0 -0
- data/.hg/store/data/spec/generator/swig/testlib.i.i +0 -0
- data/.hg/store/data/spec/generator/swig/typedefs.i.i +0 -0
- data/.hg/store/data/spec/generator/swig/types.i.i +0 -0
- data/.hg/store/data/spec/generator/type__spec.rb.i +0 -0
- data/.hg/store/data/spec/spec__helper.rb.i +0 -0
- data/.hg/store/data/tasks/cucumber.rake.i +0 -0
- data/.hg/store/undo +0 -0
- data/.hg/undo.dirstate +0 -0
- data/.hgignore +3 -0
- data/.hgtags +1 -0
- data/History.txt +22 -2
- data/README.rdoc +26 -22
- data/Rakefile +2 -3
- data/cucumber.yml +1 -0
- data/examples/Rakefile +5 -3
- data/examples/generated/libc_wrap.rb +18 -0
- data/examples/generated/libc_wrap.xml +597 -0
- data/examples/generated/wiiuse_wrap.rb +322 -0
- data/examples/generated/wiiuse_wrap.xml +9025 -0
- data/features/generate.feature +45 -0
- data/features/step_definitions/generate.rb +32 -0
- data/features/support/env.rb +4 -0
- data/features/support/templates.rb +381 -0
- data/lib/ffi-swig-generator.rb +1 -1
- data/lib/generator/application.rb +1 -1
- data/lib/generator/constant.rb +24 -0
- data/lib/generator/enum.rb +38 -0
- data/lib/generator/function.rb +71 -0
- data/lib/generator/generatortask.rb +21 -9
- data/lib/generator/logger.rb +29 -0
- data/lib/generator/node.rb +19 -0
- data/lib/generator/parser.rb +168 -0
- data/lib/generator/struct.rb +76 -0
- data/lib/generator/type.rb +128 -0
- data/lib/generator/types.rb +36 -0
- data/spec/generator/constant_spec.rb +17 -0
- data/spec/generator/enum_spec.rb +29 -0
- data/spec/generator/function_spec.rb +66 -0
- data/spec/generator/parser_spec.rb +250 -0
- data/spec/generator/struct_spec.rb +77 -0
- data/spec/generator/swig/constants.i +5 -0
- data/spec/generator/swig/functions.i +8 -0
- data/spec/generator/swig/testlib.i +42 -0
- data/spec/generator/swig/typedefs.i +1 -0
- data/spec/generator/swig/types.i +1 -0
- data/spec/generator/type_spec.rb +38 -0
- data/spec/spec_helper.rb +6 -0
- data/tasks/cucumber.rake +8 -0
- metadata +58 -18
- data/lib/generator/generator.rb +0 -344
- data/spec/generator/generator_spec.rb +0 -248
@@ -1,248 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
-
|
3
|
-
include FFI
|
4
|
-
|
5
|
-
share_examples_for "All specs" do
|
6
|
-
after :all do
|
7
|
-
remove_xml
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Generator::Parser do
|
12
|
-
it_should_behave_like 'All specs'
|
13
|
-
before :all do
|
14
|
-
@node = generate_xml_wrap_from('testlib')
|
15
|
-
end
|
16
|
-
it 'should generate ruby ffi wrap code' do
|
17
|
-
Generator::Parser.generate(@node).should == <<EOC
|
18
|
-
|
19
|
-
module TestLib
|
20
|
-
extend FFI::Library
|
21
|
-
CONST_1 = 0x10
|
22
|
-
CONST_2 = 0x20
|
23
|
-
ENUM_1 = 0
|
24
|
-
ENUM_2 = 1
|
25
|
-
ENUM_3 = 2
|
26
|
-
|
27
|
-
class UnionT < FFI::Union
|
28
|
-
layout(
|
29
|
-
:c, :char,
|
30
|
-
:f, :float
|
31
|
-
)
|
32
|
-
end
|
33
|
-
class TestStruct < FFI::Struct
|
34
|
-
layout(
|
35
|
-
:i, :int,
|
36
|
-
:c, :char,
|
37
|
-
:b, :uchar
|
38
|
-
)
|
39
|
-
end
|
40
|
-
class TestStruct3 < FFI::Struct
|
41
|
-
layout(
|
42
|
-
:c, :char
|
43
|
-
)
|
44
|
-
end
|
45
|
-
callback(:cb, [ :string, :string ], :void)
|
46
|
-
class TestStruct2 < FFI::Struct
|
47
|
-
layout(
|
48
|
-
:s, TestStruct,
|
49
|
-
:s_3, TestStruct3,
|
50
|
-
:e, :int,
|
51
|
-
:func, :cb,
|
52
|
-
:u, UnionT
|
53
|
-
)
|
54
|
-
end
|
55
|
-
attach_function :get_int, [ :pointer ], :int
|
56
|
-
attach_function :get_char, [ :pointer ], :char
|
57
|
-
attach_function :func_with_enum, [ :int ], :int
|
58
|
-
attach_function :func_with_enum_2, [ :int ], :int
|
59
|
-
attach_function :func_with_typedef, [ ], :uchar
|
60
|
-
|
61
|
-
end
|
62
|
-
EOC
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe Generator::Constant do
|
67
|
-
it_should_behave_like 'All specs'
|
68
|
-
before :all do
|
69
|
-
@node = generate_xml_wrap_from('constants')
|
70
|
-
end
|
71
|
-
it 'should return a ruby constant assignment' do
|
72
|
-
Generator::Constant.new(:node => @node / 'constant').to_s.should == "CONST_1 = 0x10"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe Generator::Enum do
|
77
|
-
before :all do
|
78
|
-
@node = generate_xml_wrap_from('enums')
|
79
|
-
end
|
80
|
-
it 'should generate constants' do
|
81
|
-
Generator::Enum.new(:node => (@node / 'enum')[0]).to_s.should == <<EOE
|
82
|
-
ENUM_1 = 0
|
83
|
-
ENUM_2 = 1
|
84
|
-
ENUM_3 = 2
|
85
|
-
EOE
|
86
|
-
end
|
87
|
-
it 'should generate constants starting from the latest assignment' do
|
88
|
-
Generator::Enum.new(:node => (@node / 'enum')[1]).to_s.should == <<EOE
|
89
|
-
ENUM_21 = 2
|
90
|
-
ENUM_22 = 3
|
91
|
-
ENUM_23 = 4
|
92
|
-
EOE
|
93
|
-
Generator::Enum.new(:node => (@node / 'enum')[2]).to_s.should == <<EOE
|
94
|
-
ENUM_31 = 0
|
95
|
-
ENUM_32 = 5
|
96
|
-
ENUM_33 = 6
|
97
|
-
EOE
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe Generator::Type do
|
102
|
-
it_should_behave_like 'All specs'
|
103
|
-
before :all do
|
104
|
-
@node = generate_xml_wrap_from('types')
|
105
|
-
end
|
106
|
-
it 'should generate string type' do
|
107
|
-
Generator::Type.new(:node => (@node / 'cdecl')[0]).to_s.should == ':string'
|
108
|
-
end
|
109
|
-
it 'should generate pointer type' do
|
110
|
-
Generator::Type.new(:node => (@node / 'cdecl')[1]).to_s.should == ':pointer'
|
111
|
-
Generator::Type.new(:node => (@node / 'cdecl')[2]).to_s.should == ':pointer'
|
112
|
-
end
|
113
|
-
it 'should generate array type' do
|
114
|
-
Generator::Type.new(:node => (@node / 'cdecl')[3]).to_s.should == '[:int, 5]'
|
115
|
-
Generator::Type.new(:node => (@node / 'cdecl')[4]).to_s.should == '[:string, 5]'
|
116
|
-
end
|
117
|
-
it 'should generate struct type' do
|
118
|
-
Generator::Type.new(:node => (@node / 'cdecl')[6]).to_s.should == 'TestStruct'
|
119
|
-
end
|
120
|
-
it 'should generate struct array type' do
|
121
|
-
Generator::Type.new(:node => (@node / 'cdecl')[7]).to_s.should == '[TestStruct, 5]'
|
122
|
-
end
|
123
|
-
it 'should generate enum array type' do
|
124
|
-
Generator::Type.new(:node => (@node / 'cdecl')[8]).to_s.should == '[:int, 5]'
|
125
|
-
end
|
126
|
-
it 'should generate const type' do
|
127
|
-
Generator::Type.new(:node => (@node / 'cdecl')[9]).to_s.should == ':int'
|
128
|
-
Generator::Type.new(:node => (@node / 'cdecl')[10]).to_s.should == ':string'
|
129
|
-
end
|
130
|
-
Generator::TYPES.sort.each_with_index do |type, i|
|
131
|
-
it "should generate #{type[0]} type" do
|
132
|
-
Generator::Type.new(:node => (@node / 'cdecl')[i + 11]).to_s.should == type[1]
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe Generator::Function do
|
138
|
-
it_should_behave_like 'All specs'
|
139
|
-
before :all do
|
140
|
-
@node = generate_xml_wrap_from('functions')
|
141
|
-
end
|
142
|
-
it 'should return a properly generated attach_method' do
|
143
|
-
Generator::Function.new(:node => (@node / 'cdecl')[0]).to_s.should == "attach_function :func_1, [ :char, :int ], :int"
|
144
|
-
end
|
145
|
-
it 'should properly generate pointer arguments' do
|
146
|
-
Generator::Function.new(:node => (@node / 'cdecl')[1]).to_s.should == "attach_function :func_2, [ :pointer, :pointer, :pointer ], :uint"
|
147
|
-
end
|
148
|
-
it 'should properly generate string arguments' do
|
149
|
-
Generator::Function.new(:node => (@node / 'cdecl')[2]).to_s.should == "attach_function :func_3, [ :string ], :void"
|
150
|
-
end
|
151
|
-
it 'should properly generate return type' do
|
152
|
-
Generator::Function.new(:node => (@node / 'cdecl')[3]).to_s.should == "attach_function :func_4, [ :int ], :string"
|
153
|
-
end
|
154
|
-
it 'should properly generate void return type' do
|
155
|
-
Generator::Function.new(:node => (@node / 'cdecl')[4]).to_s.should == "attach_function :func_5, [ ], :void"
|
156
|
-
end
|
157
|
-
it 'should properly generate pointer of pointer arguments' do
|
158
|
-
Generator::Function.new(:node => (@node / 'cdecl')[5]).to_s.should == "attach_function :func_6, [ :pointer ], :void"
|
159
|
-
end
|
160
|
-
it 'should properly generate enum arguments' do
|
161
|
-
Generator::Function.new(:node => (@node / 'cdecl')[6]).to_s.should == "attach_function :func_7, [ :int ], :void"
|
162
|
-
end
|
163
|
-
it 'should properly generate enum return type' do
|
164
|
-
Generator::Function.new(:node => (@node / 'cdecl')[7]).to_s.should == "attach_function :func_8, [ ], :int"
|
165
|
-
end
|
166
|
-
it 'should properly generate struct arguments' do
|
167
|
-
Generator::Function.new(:node => (@node / 'cdecl')[9]).to_s.should == "attach_function :func_9, [ TestStruct ], :void"
|
168
|
-
end
|
169
|
-
it 'should properly generate struct return type' do
|
170
|
-
Generator::Function.new(:node => (@node / 'cdecl')[10]).to_s.should == "attach_function :func_10, [ ], TestStruct"
|
171
|
-
end
|
172
|
-
it 'should properly generate a function with no parameters' do
|
173
|
-
Generator::Function.new(:node => (@node / 'cdecl')[11]).to_s.should == "attach_function :func_11, [ ], :void"
|
174
|
-
end
|
175
|
-
it 'should properly generate a function that takes a callback as argument' do
|
176
|
-
Generator::Function.new(:node => (@node / 'cdecl')[12]).to_s.should == "attach_function :func_12, [ callback(:callback, [ :float ], :void) ], :void"
|
177
|
-
Generator::Function.new(:node => (@node / 'cdecl')[13]).to_s.should == "attach_function :func_13, [ callback(:callback, [ :double, :float ], :int) ], :void"
|
178
|
-
Generator::Function.new(:node => (@node / 'cdecl')[14]).to_s.should == "attach_function :func_14, [ callback(:callback, [ :string ], :void) ], :void"
|
179
|
-
Generator::Function.new(:node => (@node / 'cdecl')[15]).to_s.should == "attach_function :func_15, [ callback(:callback, [ ], :void) ], :void"
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
describe Generator::Structure do
|
184
|
-
it_should_behave_like 'All specs'
|
185
|
-
before :all do
|
186
|
-
@node = generate_xml_wrap_from('structs')
|
187
|
-
end
|
188
|
-
it 'should properly generate the layout of a FFI::Struct class' do
|
189
|
-
Generator::Structure.new(:node => (@node / 'class')[0]).to_s.should == <<EOC
|
190
|
-
class TestStruct1 < FFI::Struct
|
191
|
-
layout(
|
192
|
-
:i, :int,
|
193
|
-
:c, :char,
|
194
|
-
:s, :string,
|
195
|
-
:a, [:char, 5]
|
196
|
-
)
|
197
|
-
end
|
198
|
-
EOC
|
199
|
-
|
200
|
-
end
|
201
|
-
it 'should properly generate the layout of a FFI::Struct containing pointer field' do
|
202
|
-
Generator::Structure.new(:node => (@node / 'class')[1]).to_s.should == <<EOC
|
203
|
-
class TestStruct2 < FFI::Struct
|
204
|
-
layout(
|
205
|
-
:ptr, :pointer
|
206
|
-
)
|
207
|
-
end
|
208
|
-
EOC
|
209
|
-
end
|
210
|
-
it 'should properly generate the layout of a FFI::Struct containing array field' do
|
211
|
-
Generator::Structure.new(:node => (@node / 'class')[2]).to_s.should == <<EOC
|
212
|
-
class TestStruct3 < FFI::Struct
|
213
|
-
layout(
|
214
|
-
:c, [:char, 5]
|
215
|
-
)
|
216
|
-
end
|
217
|
-
EOC
|
218
|
-
|
219
|
-
end
|
220
|
-
it 'should properly generate the layout of a FFI::Struct containing array field' do
|
221
|
-
Generator::Structure.new(:node => (@node / 'class')[3]).to_s.should == <<EOC
|
222
|
-
class TestStruct4 < FFI::Struct
|
223
|
-
layout(
|
224
|
-
:s, [TestStruct3, 5]
|
225
|
-
)
|
226
|
-
end
|
227
|
-
EOC
|
228
|
-
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
describe Generator::Union do
|
233
|
-
it_should_behave_like 'All specs'
|
234
|
-
before :all do
|
235
|
-
@node = generate_xml_wrap_from('unions')
|
236
|
-
end
|
237
|
-
it 'should properly generate the layout of a FFI::Union class' do
|
238
|
-
Generator::Union.new(:node => (@node / 'class')[0]).to_s.should == <<EOC
|
239
|
-
class UnionT < FFI::Union
|
240
|
-
layout(
|
241
|
-
:c, :char,
|
242
|
-
:f, :float
|
243
|
-
)
|
244
|
-
end
|
245
|
-
EOC
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|