ridl 2.8.1 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +9 -3
- data/lib/ridl/backend.rb +11 -12
- data/lib/ridl/delegate.rb +89 -59
- data/lib/ridl/expression.rb +65 -27
- data/lib/ridl/genfile.rb +22 -16
- data/lib/ridl/node.rb +328 -189
- data/lib/ridl/options.rb +9 -11
- data/lib/ridl/optparse_ext.rb +32 -34
- data/lib/ridl/parser.rb +456 -236
- data/lib/ridl/runner.rb +33 -26
- data/lib/ridl/scanner.rb +171 -141
- data/lib/ridl/type.rb +113 -13
- data/lib/ridl/version.rb +2 -4
- metadata +4 -4
data/lib/ridl/expression.rb
CHANGED
@@ -13,9 +13,11 @@ require 'ridl/node'
|
|
13
13
|
|
14
14
|
module IDL
|
15
15
|
class Expression
|
16
|
-
attr_reader :idltype
|
17
|
-
|
18
|
-
def typename
|
16
|
+
attr_reader :idltype, :value
|
17
|
+
|
18
|
+
def typename
|
19
|
+
@idltype.typename
|
20
|
+
end
|
19
21
|
|
20
22
|
def is_template?
|
21
23
|
false
|
@@ -34,6 +36,7 @@ module IDL
|
|
34
36
|
|
35
37
|
class ScopedName < Expression
|
36
38
|
attr_reader :node
|
39
|
+
|
37
40
|
def initialize(node)
|
38
41
|
if $DEBUG
|
39
42
|
unless IDL::AST::Const === node || (IDL::AST::TemplateParam === node && node.idltype.is_a?(IDL::Type::Const))
|
@@ -44,9 +47,11 @@ module IDL
|
|
44
47
|
@idltype = node.idltype
|
45
48
|
@value = @idltype.narrow(node.value) unless node.is_template?
|
46
49
|
end
|
50
|
+
|
47
51
|
def is_template?
|
48
52
|
@node.is_template?
|
49
53
|
end
|
54
|
+
|
50
55
|
def instantiate(instantiation_context)
|
51
56
|
if self.is_template?
|
52
57
|
cp = IDL::AST::TemplateParam.concrete_param(instantiation_context, @node)
|
@@ -55,9 +60,11 @@ module IDL
|
|
55
60
|
self
|
56
61
|
end
|
57
62
|
end
|
63
|
+
|
58
64
|
def is_node?(node_class)
|
59
65
|
@node.is_a?(node_class)
|
60
66
|
end
|
67
|
+
|
61
68
|
def resolved_node
|
62
69
|
@node
|
63
70
|
end
|
@@ -65,9 +72,10 @@ module IDL
|
|
65
72
|
|
66
73
|
class Enumerator < Expression
|
67
74
|
attr_reader :node
|
75
|
+
|
68
76
|
def initialize(node)
|
69
77
|
if $DEBUG
|
70
|
-
|
78
|
+
unless IDL::AST::Enumerator === node
|
71
79
|
raise "#{node.scoped_name} must be enumerator: #{node.class.name}."
|
72
80
|
end
|
73
81
|
end
|
@@ -81,6 +89,7 @@ module IDL
|
|
81
89
|
NUMBER_OF_OPERANDS = nil
|
82
90
|
|
83
91
|
attr_reader :operands
|
92
|
+
|
84
93
|
def initialize(*_operands)
|
85
94
|
n = self.class::NUMBER_OF_OPERANDS
|
86
95
|
|
@@ -90,8 +99,8 @@ module IDL
|
|
90
99
|
end
|
91
100
|
|
92
101
|
unless _operands.any? { |o| o.is_template? }
|
93
|
-
@idltype = self.class.suite_type(*(_operands.collect{|o| o.idltype.resolved_type}))
|
94
|
-
@value = calculate(*(_operands.collect{|o| o.value}))
|
102
|
+
@idltype = self.class.suite_type(*(_operands.collect { |o| o.idltype.resolved_type }))
|
103
|
+
@value = calculate(*(_operands.collect { |o| o.value }))
|
95
104
|
else
|
96
105
|
@idltype = nil
|
97
106
|
@value = nil
|
@@ -110,13 +119,13 @@ module IDL
|
|
110
119
|
|
111
120
|
def Operation.suite_type(*types)
|
112
121
|
types.each do |t|
|
113
|
-
|
122
|
+
unless self::Applicable.include? t.class
|
114
123
|
raise "#{self.name} cannot be applicable for #{t.typename}"
|
115
124
|
end
|
116
125
|
end
|
117
126
|
|
118
127
|
ret = nil
|
119
|
-
types = types.collect {|t| t.class }
|
128
|
+
types = types.collect { |t| t.class }
|
120
129
|
self::Applicable.each do |t|
|
121
130
|
if types.include? t
|
122
131
|
ret = t
|
@@ -125,13 +134,13 @@ module IDL
|
|
125
134
|
end
|
126
135
|
ret
|
127
136
|
end
|
128
|
-
|
129
|
-
end
|
137
|
+
|
138
|
+
def set_type; end
|
130
139
|
|
131
140
|
class Unary < Operation
|
132
141
|
NUMBER_OF_OPERANDS = 1
|
133
142
|
Applicable = nil
|
134
|
-
end #of class Unary
|
143
|
+
end # of class Unary
|
135
144
|
|
136
145
|
class Integer2 < Operation
|
137
146
|
NUMBER_OF_OPERANDS = 2
|
@@ -143,12 +152,13 @@ module IDL
|
|
143
152
|
]
|
144
153
|
|
145
154
|
def Integer2.suite_sign(_t, _v)
|
146
|
-
[
|
155
|
+
[[IDL::Type::LongLong, IDL::Type::ULongLong],
|
147
156
|
[IDL::Type::Long, IDL::Type::ULong],
|
148
157
|
[IDL::Type::Short, IDL::Type::UShort]
|
149
|
-
|
158
|
+
].each do |t|
|
150
159
|
next unless t.include? _t
|
151
|
-
|
160
|
+
|
161
|
+
return (if _v.negative? then t[0] else t[1] end)
|
152
162
|
end
|
153
163
|
end
|
154
164
|
|
@@ -184,7 +194,8 @@ module IDL
|
|
184
194
|
superclass.checktype(*types)
|
185
195
|
|
186
196
|
# it's expected that Double, LongDouble is a Float.
|
187
|
-
s1
|
197
|
+
s1 = IDL::Type::Float
|
198
|
+
s2 = IDL::Type::Fixed
|
188
199
|
if (t1 === s1 && t2 === s2) or (t1 === s2 && t2 === s1)
|
189
200
|
raise "#{self.name} about #{t1.typename} and #{t2.typename} is illegal."
|
190
201
|
end
|
@@ -197,19 +208,22 @@ module IDL
|
|
197
208
|
op
|
198
209
|
end
|
199
210
|
end
|
211
|
+
|
200
212
|
class UnaryMinus < Unary
|
201
213
|
Applicable = Float2::Applicable
|
202
214
|
def calculate(op)
|
203
215
|
-op
|
204
216
|
end
|
217
|
+
|
205
218
|
def set_type
|
206
219
|
@idltype = Integer2.suite_sign(@idltype, @value)
|
207
220
|
end
|
208
221
|
end
|
222
|
+
|
209
223
|
class UnaryNot < Unary
|
210
224
|
Applicable = Integer2::Applicable
|
211
225
|
def calculate(op)
|
212
|
-
if @idltype.is_unsigned?
|
226
|
+
if @idltype.is_unsigned?
|
213
227
|
(2**@idltype.bits - 1) - op
|
214
228
|
else
|
215
229
|
~op
|
@@ -218,29 +232,39 @@ module IDL
|
|
218
232
|
end
|
219
233
|
|
220
234
|
class Or < Boolean2
|
221
|
-
def calculate(lop, rop)
|
235
|
+
def calculate(lop, rop)
|
236
|
+
lop | rop
|
237
|
+
end
|
222
238
|
end
|
239
|
+
|
223
240
|
class And < Boolean2
|
224
|
-
def calculate(lop, rop)
|
241
|
+
def calculate(lop, rop)
|
242
|
+
lop & rop
|
243
|
+
end
|
225
244
|
end
|
245
|
+
|
226
246
|
class Xor < Boolean2
|
227
|
-
def calculate(lop, rop)
|
247
|
+
def calculate(lop, rop)
|
248
|
+
lop ^ rop
|
249
|
+
end
|
228
250
|
end
|
229
251
|
|
230
252
|
class Shift < Integer2
|
231
253
|
protected
|
232
254
|
def check_rop(rop)
|
233
|
-
|
255
|
+
unless (0...64) === rop
|
234
256
|
raise "right operand for shift must be in the range 0 <= right operand < 64: #{rop}."
|
235
257
|
end
|
236
258
|
end
|
237
259
|
end
|
260
|
+
|
238
261
|
class LShift < Shift
|
239
262
|
def calculate(lop, rop)
|
240
263
|
check_rop(rop)
|
241
264
|
lop << rop
|
242
265
|
end
|
243
266
|
end
|
267
|
+
|
244
268
|
class RShift < Shift
|
245
269
|
def calculate(lop, rop)
|
246
270
|
check_rop(rop)
|
@@ -249,20 +273,34 @@ module IDL
|
|
249
273
|
end
|
250
274
|
|
251
275
|
class Add < Float2
|
252
|
-
def calculate(lop, rop)
|
276
|
+
def calculate(lop, rop)
|
277
|
+
lop + rop
|
278
|
+
end
|
253
279
|
end
|
280
|
+
|
254
281
|
class Minus < Float2
|
255
|
-
def calculate(lop, rop)
|
282
|
+
def calculate(lop, rop)
|
283
|
+
lop - rop
|
284
|
+
end
|
256
285
|
end
|
286
|
+
|
257
287
|
class Mult < Float2
|
258
|
-
def calculate(lop, rop)
|
288
|
+
def calculate(lop, rop)
|
289
|
+
lop * rop
|
290
|
+
end
|
259
291
|
end
|
292
|
+
|
260
293
|
class Div < Float2
|
261
|
-
def calculate(lop, rop)
|
294
|
+
def calculate(lop, rop)
|
295
|
+
lop / rop
|
296
|
+
end
|
262
297
|
end
|
298
|
+
|
263
299
|
class Mod < Integer2
|
264
|
-
def calculate(lop, rop)
|
300
|
+
def calculate(lop, rop)
|
301
|
+
lop % rop
|
302
|
+
end
|
265
303
|
end
|
266
|
-
end #of class Operation
|
267
|
-
end #of class Expression
|
304
|
+
end # of class Operation
|
305
|
+
end # of class Expression
|
268
306
|
end
|
data/lib/ridl/genfile.rb
CHANGED
@@ -13,9 +13,7 @@ require 'tempfile'
|
|
13
13
|
require 'fileutils'
|
14
14
|
|
15
15
|
module IDL
|
16
|
-
|
17
16
|
class GenFile
|
18
|
-
|
19
17
|
self.singleton_class.class_eval do
|
20
18
|
private
|
21
19
|
|
@@ -37,11 +35,13 @@ module IDL
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def _commit
|
40
|
-
_transaction.reject! { |fgen| fgen.save
|
38
|
+
_transaction.reject! { |fgen| fgen.save
|
39
|
+
true }
|
41
40
|
end
|
42
41
|
|
43
42
|
def _rollback
|
44
|
-
_transaction.reject! { |fgen| fgen.remove
|
43
|
+
_transaction.reject! { |fgen| fgen.remove
|
44
|
+
true } if _transaction
|
45
45
|
end
|
46
46
|
|
47
47
|
def _push(fgen)
|
@@ -67,7 +67,8 @@ module IDL
|
|
67
67
|
class Content
|
68
68
|
def initialize(sections = {})
|
69
69
|
# copy content map transforming all keys to symbols
|
70
|
-
@sections = sections.inject({}) {|m, (k, v)| m[k.to_sym] = v
|
70
|
+
@sections = sections.inject({}) { |m, (k, v)| m[k.to_sym] = v
|
71
|
+
m }
|
71
72
|
end
|
72
73
|
|
73
74
|
def sections
|
@@ -101,13 +102,13 @@ module IDL
|
|
101
102
|
@path = @fullpath = @name = @ext = ''
|
102
103
|
end
|
103
104
|
@options = {
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
105
|
+
regenerate: false,
|
106
|
+
regen_marker_prefix: '//',
|
107
|
+
regen_marker_postfix: nil,
|
108
|
+
regen_marker: REGEN_MARKER_DEFAULT,
|
109
|
+
regen_keep_header: true,
|
110
|
+
output_file: nil,
|
111
|
+
create_missing_dir: false
|
111
112
|
}.merge(opts)
|
112
113
|
if @options[:regenerate] && File.exist?(@fullpath)
|
113
114
|
parse_regeneration_content
|
@@ -144,7 +145,8 @@ module IDL
|
|
144
145
|
yield # block should yield default content
|
145
146
|
elsif default_content = options[:default_content]
|
146
147
|
default_content = (Array === default_content) ? default_content : default_content.to_s.split("\n")
|
147
|
-
self << (default_content.collect {|l| (s = indent.dup) << l << "\n"
|
148
|
+
self << (default_content.collect { |l| (s = indent.dup) << l << "\n"
|
149
|
+
s }.join) unless default_content.empty?
|
148
150
|
end
|
149
151
|
if options[:header]
|
150
152
|
self << indent << regen_header_end_marker(sectionid) << "\n"
|
@@ -155,6 +157,7 @@ module IDL
|
|
155
157
|
|
156
158
|
def save
|
157
159
|
return if @options[:output_file]
|
160
|
+
|
158
161
|
if @fout
|
159
162
|
fgen = @fout
|
160
163
|
@fout = nil
|
@@ -197,6 +200,7 @@ module IDL
|
|
197
200
|
|
198
201
|
def remove
|
199
202
|
return if @options[:output_file]
|
203
|
+
|
200
204
|
if @fout
|
201
205
|
begin
|
202
206
|
@fout.close(true)
|
@@ -225,16 +229,19 @@ module IDL
|
|
225
229
|
case $1
|
226
230
|
when 'BEGIN'
|
227
231
|
raise "ERROR: Found unterminated regeneration section starting at #{@path}:#{in_section.last}." if in_section
|
232
|
+
|
228
233
|
in_section = [$2, linenr]
|
229
234
|
section = []
|
230
235
|
when 'END'
|
231
236
|
raise "ERROR: Found unmatched regeneration end at #{@path}:#{linenr}." unless in_section && ($2 == in_section.first)
|
237
|
+
|
232
238
|
sections[$2] = section
|
233
239
|
in_section = nil
|
234
240
|
section = []
|
235
241
|
when 'HEADER_END'
|
236
242
|
raise "ERROR: Found illegal header end marker at #{@path}:#{linenr}." unless _keep_header && in_section &&
|
237
|
-
('HEADER' == in_section.first ) && (
|
243
|
+
('HEADER' == in_section.first ) && (in_section.last.zero?)
|
244
|
+
|
238
245
|
sections[$2] = section
|
239
246
|
in_section = nil
|
240
247
|
section = []
|
@@ -249,6 +256,5 @@ module IDL
|
|
249
256
|
sections[in_section.first] = section if in_section
|
250
257
|
@content = Content.new(sections)
|
251
258
|
end
|
252
|
-
|
253
259
|
end
|
254
|
-
end
|
260
|
+
end
|