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.
data/lib/ridl/parser.ry CHANGED
@@ -521,6 +521,8 @@ rule
521
521
  | union_forward_dcl
522
522
  | enum_type
523
523
  | "native" native_declarator
524
+ | bitmask_type
525
+ | bitset_type
524
526
 
525
527
  type_declarator : type_spec declarators
526
528
  {
@@ -551,10 +553,13 @@ rule
551
553
  | string_type
552
554
  | wide_string_type
553
555
  | fixed_pt_type
556
+ | map_type
554
557
 
555
558
  constr_type_spec : struct_type
556
559
  | union_type
557
560
  | enum_type
561
+ | bitmask_type
562
+ | bitset_type
558
563
 
559
564
  declarators : declarator { [val[0]] }
560
565
  | declarators "," declarator { val[0] << val[2] }
@@ -578,23 +583,34 @@ rule
578
583
  signed_int : signed_short_int
579
584
  | signed_long_int
580
585
  | signed_longlong_int
586
+ | tiny_short_int
587
+
588
+ tiny_short_int : "int8" { if @idlversion < 4 then raise "int8 is only supported with IDL4 or newer" else ::IDL::Type::TinyShort.new end }
581
589
 
582
590
  signed_short_int : "short" { ::IDL::Type::Short.new }
591
+ | "int16" { if @idlversion < 4 then raise "int16 is only supported with IDL4 or newer" else ::IDL::Type::Short.new end }
583
592
 
584
- signed_long_int : "long" { ::IDL::Type::Long.new }
593
+ signed_long_int : "long" { ::IDL::Type::Long.new }
594
+ | "int32" { if @idlversion < 4 then raise "int32 is only supported with IDL4 or newer" else ::IDL::Type::Long.new end }
585
595
 
586
596
  signed_longlong_int : "long" "long" { ::IDL::Type::LongLong.new }
597
+ | "int64" { if @idlversion < 4 then raise "int64 is only supported with IDL4 or newer" else ::IDL::Type::LongLong.new end }
587
598
 
588
599
  unsigned_int : unsigned_short_int
589
600
  | unsigned_long_int
590
601
  | unsigned_longlong_int
602
+ | unsigned_tiny_short_int
603
+
604
+ unsigned_tiny_short_int : "uint8" { if @idlversion < 4 then raise "uint8 is only supported with IDL4 or newer" else ::IDL::Type::UTinyShort.new end }
591
605
 
592
606
  unsigned_short_int : "unsigned" "short" { ::IDL::Type::UShort.new }
607
+ | "uint16" { if @idlversion < 4 then raise "uint16 is only supported with IDL4 or newer" else ::IDL::Type::UShort.new end }
593
608
 
594
609
  unsigned_long_int : "unsigned" "long" { ::IDL::Type::ULong.new }
610
+ | "uint32" { if @idlversion < 4 then raise "uint32 is only supported with IDL4 or newer" else ::IDL::Type::ULong.new end }
595
611
 
596
- unsigned_longlong_int : "unsigned" "long" "long"
597
- { ::IDL::Type::ULongLong.new }
612
+ unsigned_longlong_int : "unsigned" "long" "long" { ::IDL::Type::ULongLong.new }
613
+ | "uint64" { if @idlversion < 4 then raise "uint64 is only supported with IDL4 or newer" else ::IDL::Type::ULongLong.new end }
598
614
 
599
615
  char_type : "char" { ::IDL::Type::Char.new }
600
616
 
@@ -610,13 +626,15 @@ rule
610
626
 
611
627
  struct_forward_dcl : struct_def identifier { @d.declare_struct(val[1]) }
612
628
 
613
- struct_type : struct_header "{" member_list "}"
614
- { @d.end_struct(val[0]) }
629
+ struct_type : struct_header "{" member_list "}" { @d.end_struct(val[0]) }
630
+ | struct_header "{" "}" { if @idlversion < 4 then raise "empty struct is only supported with IDL4 or newer" else @d.end_struct(val[0]) end }
615
631
 
616
- struct_header : struct_def identifier { @d.define_struct(val[1]) }
632
+ struct_header : struct_def identifier { @d.define_struct(val[1]) }
633
+ | struct_def identifier ":" struct_inheritance_spec { if @idlversion < 4 then raise "struct inheritance is only supported with IDL4 or newer" else @d.define_struct(val[1], val[3]) end }
617
634
 
618
635
  struct_def : "struct" { nil }
619
636
 
637
+ struct_inheritance_spec : scoped_name
620
638
 
621
639
  member_list : member
622
640
  | member_list member
@@ -651,6 +669,8 @@ rule
651
669
  | boolean_type
652
670
  | enum_type
653
671
  | scoped_name
672
+ | octet_type { if @idlversion < 4 then raise "union with octect discriminator type is only supported with IDL4 or newer" else ::IDL::Type::Octet.new end }
673
+ | wide_char_type { if @idlversion < 4 then raise "union with octect discriminator type is only supported with IDL4 or newer" else ::IDL::Type::WChar.new end }
654
674
 
655
675
  union_body : union_case
656
676
  | union_body union_case
@@ -672,14 +692,45 @@ rule
672
692
  element_spec : type_spec declarator
673
693
  { val }
674
694
 
675
- enum_type : _enum_header _enum_body
676
- { @d.end_enum(val[0]) }
695
+ bitmask_type : bitmask_header bitmask_body { @d.end_bitmask(val[0]) }
696
+
697
+ bitmask_header : "bitmask" identifier { @d.define_bitmask(val[1]) }
698
+
699
+ bitmask_body : "{" bitmask_list "}"
700
+
701
+ bitmask_list : bit_value
702
+ | bitmask_list "," bit_value
703
+
704
+ bit_value : identifier { @d.declare_bitvalue (val[0]) }
705
+
706
+ bitset_type : bitset_header bitset_body { @d.end_bitset(val[0]) }
707
+
708
+ bitset_header : "bitset" identifier ":" bitset_inheritance_spec { @d.define_bitset(val[1], val[3]) }
709
+ | "bitset" identifier { @d.define_bitset(val[1]) }
710
+
711
+ bitset_inheritance_spec : scoped_name
712
+
713
+ bitset_body : "{" bitfield_list "}"
714
+
715
+ bitfield_list : bitset_field ";"
716
+ | bitfield_list bitset_field ";"
717
+
718
+ bitset_field : "bitfield" "<" positive_int_const ">" identifier { @d.declare_bitfield(val[4], val[2], nil) }
719
+ | "bitfield" "<" positive_int_const "," bitfield_destination_type ">" identifier { @d.declare_bitfield(val[6], val[2], val[4]) }
720
+ | "bitfield" "<" positive_int_const ">" { @d.declare_bitfield(nil, val[2], nil) }
721
+ | "bitfield" "<" positive_int_const "," bitfield_destination_type ">" { @d.declare_bitfield(nil, val[2], val[4]) }
722
+
723
+ bitfield_destination_type : boolean_type
724
+ | octet_type
725
+ | integer_type
726
+
727
+ enum_type : _enum_header _enum_body { @d.end_enum(val[0]) }
677
728
 
678
729
  _enum_header : "enum" identifier { @d.define_enum(val[1]) }
679
730
  _enum_body : "{" _enumerator_list "}"
680
731
 
681
732
  _enumerator_list : enumerator
682
- | _enumerator_list "," enumerator
733
+ | _enumerator_list "," enumerator
683
734
 
684
735
  enumerator : identifier
685
736
  {
@@ -691,6 +742,11 @@ rule
691
742
  | "sequence" "<" simple_type_spec ">"
692
743
  { ::IDL::Type::Sequence.new(val[2], nil) }
693
744
 
745
+ map_type : "map" "<" simple_type_spec "," simple_type_spec "," positive_int_const ">"
746
+ { if @idlversion < 4 then raise "int8 is only supported with IDL4 or newer" else ::IDL::Type::Map.new(val[2], val[4], val[6]) end }
747
+ | "map" "<" simple_type_spec "," simple_type_spec ">"
748
+ { if @idlversion < 4 then raise "int8 is only supported with IDL4 or newer" else ::IDL::Type::Map.new(val[2], val[4], nil) end }
749
+
694
750
  string_type : "string" "<" positive_int_const ">"
695
751
  { ::IDL::Type::String.new(val[2]) }
696
752
  | "string"
@@ -849,6 +905,7 @@ attr_accessor :yydebug
849
905
  def initialize(params = {})
850
906
  @d = ::IDL::Delegator.new(params)
851
907
  @params = params
908
+ @idlversion = params[:idlversion]
852
909
  end
853
910
 
854
911
  alias on_error0 on_error
data/lib/ridl/runner.rb CHANGED
@@ -18,23 +18,22 @@ require 'ridl/options'
18
18
  # -----------------------------------------------------------------------
19
19
 
20
20
  module IDL
21
-
22
21
  OPTIONS = Options.new({
23
- :outputdir => nil,
24
- :includepaths => [],
25
- :xincludepaths => [],
26
- :verbose => (ENV['RIDL_VERBOSE'] || 0).to_i,
27
- :debug => false,
28
- :namespace => nil,
29
- :search_incpath => false,
30
- :backend => nil,
31
- :macros => {
32
- }
22
+ outputdir: nil,
23
+ includepaths: [],
24
+ xincludepaths: [],
25
+ verbose: (ENV['RIDL_VERBOSE'] || 0).to_i,
26
+ debug: false,
27
+ namespace: nil,
28
+ search_incpath: false,
29
+ backend: nil,
30
+ macros: {
31
+ },
32
+ idlversion: 3
33
33
  })
34
34
  CORE_OPTIONS = OPTIONS.keys
35
35
 
36
36
  class Engine
37
-
38
37
  class ProductionStack
39
38
  def initialize
40
39
  @stack = []
@@ -56,6 +55,7 @@ module IDL
56
55
 
57
56
  def pop
58
57
  return nil if empty?
58
+
59
59
  id, prod = @stack.shift
60
60
  @index.delete(id)
61
61
  prod
@@ -63,12 +63,14 @@ module IDL
63
63
 
64
64
  def peek
65
65
  return nil if empty?
66
+
66
67
  id, _ = @stack.first
67
68
  id
68
69
  end
69
70
 
70
71
  def remove(id)
71
72
  return nil unless has?(id)
73
+
72
74
  i = @index.delete(id.to_sym)
73
75
  _, producer = @productionstack.delete(i)
74
76
  producer
@@ -90,7 +92,8 @@ module IDL
90
92
  macros: options[:macros].merge({
91
93
  __RIDL__: "#{RIDL_VERSION}",
92
94
  __RIDLBE__: @backend.name.to_s,
93
- __RIDLBE_VER__: @backend.version
95
+ __RIDLBE_VER__: @backend.version,
96
+ __RIDL_IDL_VERSION__: options[:idlversion].to_s
94
97
  })
95
98
  })
96
99
  @optparser = init_optparser
@@ -129,6 +132,7 @@ module IDL
129
132
 
130
133
  def push_production(id, producer)
131
134
  raise "Producer #{id} already queued" if @productionstack.has?(id)
135
+
132
136
  @productionstack.push(id, producer)
133
137
  end
134
138
 
@@ -183,9 +187,9 @@ module IDL
183
187
  # parse arguments
184
188
  begin
185
189
  @optparser.parse!(argv)
186
- rescue ArgumentError => ex
187
- IDL.error(ex.inspect)
188
- IDL.error(ex.backtrace.join("\n")) if IDL.verbose_level > 0
190
+ rescue ArgumentError => e
191
+ IDL.error(e.inspect)
192
+ IDL.error(e.backtrace.join("\n")) if IDL.verbose_level.positive?
189
193
  return false
190
194
  end
191
195
 
@@ -231,7 +235,7 @@ module IDL
231
235
  # process parse result -> code generation
232
236
  IDL.log(2, 'RIDL - processing input')
233
237
 
234
- GenFile.transaction do
238
+ GenFile.transaction do
235
239
  begin
236
240
 
237
241
  backend.process_input(_parser, _opts)
@@ -250,9 +254,9 @@ module IDL
250
254
  rescue Backend::ProcessStop
251
255
  IDL.log(2, "RIDL - processing #{IO === _idlfile ? 'from STDIN' : (StringIO === _idlfile ? 'from string' : _idlfile)} stopped with \"#{$!.message}\"")
252
256
 
253
- rescue => ex
254
- IDL.error(ex)
255
- IDL.error(ex.backtrace.join("\n")) unless ex.is_a? IDL::ParseError
257
+ rescue => e
258
+ IDL.error(e)
259
+ IDL.error(e.backtrace.join("\n")) unless e.is_a? IDL::ParseError
256
260
  return false
257
261
  end
258
262
  end
@@ -272,9 +276,9 @@ module IDL
272
276
 
273
277
  begin
274
278
  _parser.parse(io)
275
- rescue => ex
276
- IDL.error(ex.inspect)
277
- IDL.error(ex.backtrace.join("\n")) unless ex.is_a? IDL::ParseError
279
+ rescue => e
280
+ IDL.error(e.inspect)
281
+ IDL.error(e.backtrace.join("\n")) unless e.is_a? IDL::ParseError
278
282
  return nil
279
283
  ensure
280
284
  io.close unless String === io || io == $stdin
@@ -328,7 +332,7 @@ module IDL
328
332
 
329
333
  def init_optparser
330
334
  script_name = File.basename($0, '.*')
331
- if not script_name =~ /ridlc/
335
+ unless script_name =~ /ridlc/
332
336
  script_name = 'ruby ' + $0
333
337
  end
334
338
 
@@ -363,6 +367,11 @@ module IDL
363
367
  'Default: off') { |_|
364
368
  self.options[:debug] = true
365
369
  }
370
+ opts.on('--idl-version=VERSION', Integer,
371
+ 'Set IDL version (3|4)',
372
+ 'Default: 3') { |v|
373
+ self.options[:idlversion] = v
374
+ }
366
375
  opts.on('--search-includepath',
367
376
  'Use include paths to find main IDL source.',
368
377
  'Default: off') { |_|
@@ -398,11 +407,12 @@ module IDL
398
407
  opts.separator ""
399
408
 
400
409
  opts.on('-h', '--help',
401
- 'Show this help message.') { puts opts; puts; exit }
410
+ 'Show this help message.') { puts opts
411
+ puts
412
+ exit }
402
413
 
403
414
  opts
404
415
  end
405
-
406
416
  end
407
417
 
408
418
  def IDL.engine?
@@ -419,11 +429,13 @@ module IDL
419
429
 
420
430
  def IDL.pop_input
421
431
  return nil unless engine?
432
+
422
433
  Thread.current[:ridl_engine].pop_input
423
434
  end
424
435
 
425
436
  def IDL.peek_input
426
437
  return nil unless engine?
438
+
427
439
  Thread.current[:ridl_engine].peek_input
428
440
  end
429
441
 
@@ -437,11 +449,13 @@ module IDL
437
449
 
438
450
  def IDL.pop_production
439
451
  return nil unless engine?
452
+
440
453
  Thread.current[:ridl_engine].pop_production
441
454
  end
442
455
 
443
456
  def IDL.remove_production(id)
444
457
  return nil unless engine?
458
+
445
459
  Thread.current[:ridl_engine].remove_production(id)
446
460
  end
447
461
 
@@ -455,6 +469,7 @@ module IDL
455
469
 
456
470
  def IDL.production(id)
457
471
  return nil unless engine?
472
+
458
473
  Thread.current[:ridl_engine].production(id)
459
474
  end
460
475
 
@@ -503,7 +518,7 @@ module IDL
503
518
  # add optional search paths for RIDL backends
504
519
  options[:be_path] ||= []
505
520
  options[:be_path].unshift(*ENV['RIDL_BE_PATH'].split(/#{File::PATH_SEPARATOR}/)) if ENV['RIDL_BE_PATH']
506
- options[:be_path].collect! {|p| p.gsub('\\', '/') } # cleanup to prevent mixed path separators
521
+ options[:be_path].collect! { |p| p.gsub('\\', '/') } # cleanup to prevent mixed path separators
507
522
  $:.concat(options[:be_path]) unless options[:be_path].empty?
508
523
 
509
524
  # check for special bootstrapping switches
@@ -527,5 +542,4 @@ module IDL
527
542
  exit(1) unless Thread.current[:ridl_engine].run(argv)
528
543
  end
529
544
  end # IDL.run
530
-
531
545
  end