ridl 2.8.2 → 2.10.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.
@@ -13,9 +13,11 @@ require 'ridl/node'
13
13
 
14
14
  module IDL
15
15
  class Expression
16
- attr_reader :idltype
17
- attr_reader :value
18
- def typename; @idltype.typename; end
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
- if not IDL::AST::Enumerator === node
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
- if not self::Applicable.include? t.class
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
- def set_type
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
@@ -139,16 +148,19 @@ module IDL
139
148
  IDL::Type::LongLong, IDL::Type::ULongLong,
140
149
  IDL::Type::Long, IDL::Type::ULong,
141
150
  IDL::Type::Short, IDL::Type::UShort,
151
+ IDL::Type::TinyShort, IDL::Type::UTinyShort,
142
152
  IDL::Type::Octet
143
153
  ]
144
154
 
145
155
  def Integer2.suite_sign(_t, _v)
146
- [ [IDL::Type::LongLong, IDL::Type::ULongLong],
156
+ [[IDL::Type::LongLong, IDL::Type::ULongLong],
147
157
  [IDL::Type::Long, IDL::Type::ULong],
148
- [IDL::Type::Short, IDL::Type::UShort]
149
- ].each do |t|
158
+ [IDL::Type::Short, IDL::Type::UShort],
159
+ [IDL::Type::TinyShort, IDL::Type::UTinyShort]
160
+ ].each do |t|
150
161
  next unless t.include? _t
151
- return (if _v < 0 then t[0] else t[1] end)
162
+
163
+ return (if _v.negative? then t[0] else t[1] end)
152
164
  end
153
165
  end
154
166
 
@@ -184,7 +196,8 @@ module IDL
184
196
  superclass.checktype(*types)
185
197
 
186
198
  # it's expected that Double, LongDouble is a Float.
187
- s1, s2 = IDL::Type::Float, IDL::Type::Fixed
199
+ s1 = IDL::Type::Float
200
+ s2 = IDL::Type::Fixed
188
201
  if (t1 === s1 && t2 === s2) or (t1 === s2 && t2 === s1)
189
202
  raise "#{self.name} about #{t1.typename} and #{t2.typename} is illegal."
190
203
  end
@@ -197,19 +210,22 @@ module IDL
197
210
  op
198
211
  end
199
212
  end
213
+
200
214
  class UnaryMinus < Unary
201
215
  Applicable = Float2::Applicable
202
216
  def calculate(op)
203
217
  -op
204
218
  end
219
+
205
220
  def set_type
206
221
  @idltype = Integer2.suite_sign(@idltype, @value)
207
222
  end
208
223
  end
224
+
209
225
  class UnaryNot < Unary
210
226
  Applicable = Integer2::Applicable
211
227
  def calculate(op)
212
- if @idltype.is_unsigned?()
228
+ if @idltype.is_unsigned?
213
229
  (2**@idltype.bits - 1) - op
214
230
  else
215
231
  ~op
@@ -218,29 +234,39 @@ module IDL
218
234
  end
219
235
 
220
236
  class Or < Boolean2
221
- def calculate(lop, rop); lop | rop; end
237
+ def calculate(lop, rop)
238
+ lop | rop
239
+ end
222
240
  end
241
+
223
242
  class And < Boolean2
224
- def calculate(lop, rop); lop & rop; end
243
+ def calculate(lop, rop)
244
+ lop & rop
245
+ end
225
246
  end
247
+
226
248
  class Xor < Boolean2
227
- def calculate(lop, rop); lop ^ rop; end
249
+ def calculate(lop, rop)
250
+ lop ^ rop
251
+ end
228
252
  end
229
253
 
230
254
  class Shift < Integer2
231
255
  protected
232
256
  def check_rop(rop)
233
- if not (0...64) === rop
257
+ unless (0...64) === rop
234
258
  raise "right operand for shift must be in the range 0 <= right operand < 64: #{rop}."
235
259
  end
236
260
  end
237
261
  end
262
+
238
263
  class LShift < Shift
239
264
  def calculate(lop, rop)
240
265
  check_rop(rop)
241
266
  lop << rop
242
267
  end
243
268
  end
269
+
244
270
  class RShift < Shift
245
271
  def calculate(lop, rop)
246
272
  check_rop(rop)
@@ -249,20 +275,34 @@ module IDL
249
275
  end
250
276
 
251
277
  class Add < Float2
252
- def calculate(lop, rop); lop + rop; end
278
+ def calculate(lop, rop)
279
+ lop + rop
280
+ end
253
281
  end
282
+
254
283
  class Minus < Float2
255
- def calculate(lop, rop); lop - rop; end
284
+ def calculate(lop, rop)
285
+ lop - rop
286
+ end
256
287
  end
288
+
257
289
  class Mult < Float2
258
- def calculate(lop, rop); lop * rop; end
290
+ def calculate(lop, rop)
291
+ lop * rop
292
+ end
259
293
  end
294
+
260
295
  class Div < Float2
261
- def calculate(lop, rop); lop / rop; end
296
+ def calculate(lop, rop)
297
+ lop / rop
298
+ end
262
299
  end
300
+
263
301
  class Mod < Integer2
264
- def calculate(lop, rop); lop % rop; end
302
+ def calculate(lop, rop)
303
+ lop % rop
304
+ end
265
305
  end
266
- end #of class Operation
267
- end #of class Expression
306
+ end # of class Operation
307
+ end # of class Expression
268
308
  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; true }
38
+ _transaction.reject! { |fgen| fgen.save
39
+ true }
41
40
  end
42
41
 
43
42
  def _rollback
44
- _transaction.reject! { |fgen| fgen.remove; true } if _transaction
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; m }
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
- :regenerate => false,
105
- :regen_marker_prefix => '//',
106
- :regen_marker_postfix => nil,
107
- :regen_marker => REGEN_MARKER_DEFAULT,
108
- :regen_keep_header => true,
109
- :output_file => nil,
110
- :create_missing_dir => false
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"; s }.join) unless default_content.empty?
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 ) && (0 == in_section.last)
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