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/node.rb CHANGED
@@ -10,7 +10,6 @@
10
10
  # Copyright (c) Remedy IT Expertise BV
11
11
  #--------------------------------------------------------------------
12
12
  module IDL::AST
13
-
14
13
  REPO_ID_XCHARS = ['.', '-', '_']
15
14
  REPO_ID_RE = /^[#{('a'..'z').to_a.join}#{('A'..'Z').to_a.join}#{('0'..'9').to_a.join}\.\-_\/]+$/
16
15
 
@@ -75,16 +74,13 @@ module IDL::AST
75
74
  end
76
75
 
77
76
  def concat(anns)
78
- anns.each {|_ann| self << _ann } if anns
77
+ anns.each { |_ann| self << _ann } if anns
79
78
  end
80
79
  end
81
80
 
82
81
  class Leaf
83
- attr_reader :name, :intern
82
+ attr_reader :name, :intern, :scopes, :prefix, :annotations
84
83
  attr_accessor :enclosure
85
- attr_reader :scopes
86
- attr_reader :prefix
87
- attr_reader :annotations
88
84
 
89
85
  def typename
90
86
  self.class.name
@@ -117,7 +113,7 @@ module IDL::AST
117
113
  end
118
114
 
119
115
  def scoped_name
120
- @scoped_name ||= @scopes.collect{|s| s.name}.join("::").freeze
116
+ @scoped_name ||= @scopes.collect { |s| s.name }.join("::").freeze
121
117
  end
122
118
 
123
119
  def scoped_lm_name
@@ -200,7 +196,7 @@ module IDL::AST
200
196
  @repo_ver = "1.0" unless @repo_ver
201
197
  format("IDL:%s%s:%s",
202
198
  if @prefix.empty? then "" else @prefix + "/" end,
203
- self.scopes.collect{|s| s.name}.join("/"),
199
+ self.scopes.collect { |s| s.name }.join("/"),
204
200
  @repo_ver)
205
201
  else
206
202
  @repo_id
@@ -237,7 +233,7 @@ module IDL::AST
237
233
  class Node < Leaf
238
234
  def initialize(name, enclosure)
239
235
  super
240
- @introduced = Hash.new
236
+ @introduced = {}
241
237
  @children = []
242
238
  introduce(self)
243
239
  end
@@ -261,7 +257,7 @@ module IDL::AST
261
257
  @introduced.delete(node.intern)
262
258
  end
263
259
 
264
- def redefine(node, params)
260
+ def redefine(node, _params)
265
261
  raise "\"#{node.name}\" is already defined."
266
262
  end
267
263
 
@@ -271,10 +267,11 @@ module IDL::AST
271
267
  end
272
268
  end
273
269
 
274
- def define(_type, _name, params = Hash.new)
275
- if not is_definable?(_type)
276
- raise "#{_type.to_s} is not definable in #{self.typename}."
270
+ def define(_type, _name, params = {})
271
+ unless is_definable?(_type)
272
+ raise "#{_type} is not definable in #{self.typename}."
277
273
  end
274
+
278
275
  node = search_self(_name)
279
276
  if node.nil?
280
277
  node = _type.new(_name, self, params)
@@ -286,6 +283,7 @@ module IDL::AST
286
283
  if _type != node.class
287
284
  raise "#{_name} is already defined as a type of #{node.typename}"
288
285
  end
286
+
289
287
  node = redefine(node, params)
290
288
  end
291
289
  node
@@ -325,6 +323,7 @@ module IDL::AST
325
323
  if not node.nil? and node.name != _name
326
324
  raise "\"#{_name}\" clashed with \"#{node.name}\"."
327
325
  end
326
+
328
327
  node
329
328
  end
330
329
 
@@ -383,14 +382,20 @@ module IDL::AST
383
382
  class UnionMember < Member; end
384
383
  class Enum < Leaf; end
385
384
  class Enumerator < Leaf; end
385
+ class BitMask < Node; end
386
+ class BitValue < Leaf; end
387
+ class BitSet < Node; end
388
+ class BitField < Leaf; end
386
389
 
387
390
  class Module < Node
388
391
  DEFINABLE = [
389
392
  IDL::AST::Module, IDL::AST::Interface, IDL::AST::Valuebox, IDL::AST::Valuetype, IDL::AST::Const, IDL::AST::Struct,
390
393
  IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator, IDL::AST::Typedef, IDL::AST::Include,
391
- IDL::AST::Home, IDL::AST::Porttype, IDL::AST::Component, IDL::AST::Connector
394
+ IDL::AST::Home, IDL::AST::Porttype, IDL::AST::Component, IDL::AST::Connector, IDL::AST::BitMask, IDL::AST::BitValue,
395
+ IDL::AST::BitSet, IDL::AST::BitField
392
396
  ]
393
397
  attr_reader :anchor, :next, :template, :template_params
398
+
394
399
  def initialize(_name, _enclosure, params)
395
400
  super(_name, _enclosure)
396
401
  @anchor = params[:anchor]
@@ -410,6 +415,7 @@ module IDL::AST
410
415
 
411
416
  def template_param(param)
412
417
  return nil unless @template
418
+
413
419
  param = param.to_s if ::Symbol === param
414
420
  if ::String === param
415
421
  @template.params.each_with_index do |tp, ix|
@@ -455,7 +461,7 @@ module IDL::AST
455
461
  _anchor = node.has_anchor? ? node.anchor : node
456
462
  _anchor.annotations.concat(params.delete(:annotations))
457
463
  _last = _anchor.find_last
458
- _params = params.merge({ :anchor => _anchor, :prefix => node.prefix })
464
+ _params = params.merge({ anchor: _anchor, prefix: node.prefix })
459
465
  _next = IDL::AST::Module.new(node.name, self, _params)
460
466
  _last.set_next(_next)
461
467
  @children << _next
@@ -548,7 +554,7 @@ module IDL::AST
548
554
  end
549
555
 
550
556
  def replace_prefix(pfx)
551
- self.prefix = pfx # handles validation
557
+ self.prefix = pfx # handles validation
552
558
  if @anchor.nil?
553
559
  self.replace_prefix_i(pfx)
554
560
  else
@@ -578,6 +584,7 @@ module IDL::AST
578
584
  cp = IDL::AST::TemplateParam.concrete_param(instantiation_context, _template.anchor)
579
585
  # concrete param must be a IDL::Type::NodeType and it's node a Module (should never fail)
580
586
  raise "Invalid concrete anchor found" unless cp.is_a?(IDL::Type::NodeType) && cp.node.is_a?(IDL::AST::Module)
587
+
581
588
  @anchor = cp.node
582
589
  # link our self into module chain
583
590
  @anchor.find_last.set_next(self)
@@ -608,6 +615,7 @@ module IDL::AST
608
615
  if not node.nil? and node.name != _name
609
616
  raise "\"#{_name}\" clashed with \"#{node.name}\"."
610
617
  end
618
+
611
619
  if node.nil? && @next
612
620
  node = @next.search_links(_name)
613
621
  end
@@ -633,6 +641,7 @@ module IDL::AST
633
641
 
634
642
  class TemplateParam < Leaf
635
643
  attr_reader :idltype, :concrete
644
+
636
645
  def initialize(_name, _enclosure, params)
637
646
  super(_name, _enclosure)
638
647
  @idltype = params[:type]
@@ -667,7 +676,7 @@ module IDL::AST
667
676
  def self.concrete_param(instantiation_context, tpl_elem)
668
677
  # is this an element from the template's scope
669
678
  if tpl_elem.is_template?
670
- celem = if tpl_elem.is_a?(IDL::AST::TemplateParam) # an actual template parameter?
679
+ celem = if tpl_elem.is_a?(IDL::AST::TemplateParam) # an actual template parameter?
671
680
  tpl_elem.concrete # get the template parameter's concrete (instantiation argument) value
672
681
  else
673
682
  # referenced template elements should have been instantiated already and available through context
@@ -677,6 +686,7 @@ module IDL::AST
677
686
  ctxelem.is_a?(IDL::AST::Const) ? ctxelem.expression : ctxelem.idltype
678
687
  end
679
688
  raise "cannot resolve concrete node for template #{tpl_elem.typename} #{tpl_elem.scoped_lm_name}" unless celem
689
+
680
690
  celem
681
691
  else
682
692
  tpl_elem.idltype # just return the element's idltype if not from the template scope
@@ -692,6 +702,7 @@ module IDL::AST
692
702
  IDL::AST::TemplateParam, IDL::AST::TemplateModuleReference
693
703
  ]
694
704
  attr_reader :idltype
705
+
695
706
  def initialize(_name, _enclosure, _params)
696
707
  super(_name, _enclosure, {})
697
708
  @idltype = IDL::Type::TemplateModule.new(self)
@@ -716,6 +727,7 @@ module IDL::AST
716
727
  # process concrete parameters
717
728
  @template_params.each_with_index do |_tp, _ix|
718
729
  raise "missing template parameter for #{typename} #{scoped_lm_name}: #{_tp.name}" unless _ix < _module_instance.template_params.size
730
+
719
731
  _cp = _module_instance.template_params[_ix]
720
732
  if _cp.is_a?(IDL::Type)
721
733
  raise "anonymous type definitions are not allowed!" if _cp.is_anonymous?
@@ -723,6 +735,7 @@ module IDL::AST
723
735
  unless _tp.idltype.is_a?(IDL::Type::Any) || _tp.idltype.class === _cp.resolved_type
724
736
  raise "mismatched instantiation parameter \##{_ix} #{_cp.typename} for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}"
725
737
  end
738
+
726
739
  # verify concrete parameter
727
740
  case _tp.idltype
728
741
  when IDL::Type::Any # 'typename'
@@ -734,10 +747,12 @@ module IDL::AST
734
747
  IDL::Type::Union, # 'union'
735
748
  IDL::Type::Exception, # 'exception'
736
749
  IDL::Type::Enum # 'enum'
750
+ IDL::Type::BitMask# 'bitmask'
751
+ IDL::Type::BitSet# 'bitset'
737
752
  # no further checks
738
753
  when IDL::Type::Sequence # 'sequence' or 'sequence<...>'
739
754
  _tptype = _tp.idltype
740
- unless _tptype.basetype.is_a?(IDL::Type::Void) # 'sequence'
755
+ unless _tptype.basetype.is_a?(IDL::Type::Void) # 'sequence'
741
756
  # check basetype
742
757
  unless _tptype.basetype.is_a?(IDL::Type::ScopedName) &&
743
758
  _tptype.basetype.is_node?(IDL::AST::TemplateParam) &&
@@ -751,6 +766,7 @@ module IDL::AST
751
766
  unless _tp.idltype.is_a?(IDL::Type::Const)
752
767
  raise "unexpected expression as instantiation parameter for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}"
753
768
  end
769
+
754
770
  # match constant type
755
771
  _tp.idltype.narrow(_cp.value)
756
772
  else
@@ -765,7 +781,7 @@ module IDL::AST
765
781
 
766
782
  protected
767
783
 
768
- def walk_members_for_copy(&block)
784
+ def walk_members_for_copy
769
785
  @children.each { |c| yield(c) unless c.is_a?(IDL::AST::TemplateParam) }
770
786
  end
771
787
  end # TemplateModule
@@ -776,6 +792,7 @@ module IDL::AST
776
792
  unless _params[:tpl_type].is_a?(IDL::Type::ScopedName) && _params[:tpl_type].is_node?(IDL::AST::TemplateModule)
777
793
  raise "templated module reference type required for #{typename} #{scoped_lm_name}: got #{_params[:tpl_type].typename}"
778
794
  end
795
+
779
796
  @template = _params[:tpl_type].resolved_type.node
780
797
  _params[:tpl_params].each do |p|
781
798
  unless (p.is_a?(IDL::Type::ScopedName) || p.is_a?(IDL::Expression::ScopedName)) && p.is_node?(IDL::AST::TemplateParam)
@@ -800,7 +817,7 @@ module IDL::AST
800
817
  # concrete objects are either Expression or Type
801
818
  tp.concrete
802
819
  end
803
- mod_inst = IDL::AST::Module.new(self.name, _enclosure, { :template => @template, :template_params => inst_params })
820
+ mod_inst = IDL::AST::Module.new(self.name, _enclosure, { template: @template, template_params: inst_params })
804
821
  @template.instantiate(mod_inst, instantiation_context)
805
822
  mod_inst
806
823
  end
@@ -812,15 +829,16 @@ module IDL::AST
812
829
 
813
830
  class Include < Module
814
831
  attr_reader :filename, :fullpath
832
+
815
833
  def initialize(_name, _enclosure, params)
816
834
  super(_name, _enclosure, params)
817
835
  @filename = params[:filename]
818
836
  @fullpath = params[:fullpath]
819
837
  @defined = params[:defined] || false
820
838
  @preprocessed = params[:preprocessed] || false
821
- #overrule
839
+ # overrule
822
840
  @scopes = @enclosure.scopes
823
- @scoped_name = @scopes.collect{|s| s.name}.join("::")
841
+ @scoped_name = @scopes.collect { |s| s.name }.join("::")
824
842
  end
825
843
 
826
844
  def lm_scopes
@@ -836,13 +854,18 @@ module IDL::AST
836
854
  @defined = vars.pop
837
855
  @filename = vars.pop
838
856
  super(vars)
839
- #overrule
857
+ # overrule
840
858
  @scopes = @enclosure.scopes || []
841
- @scoped_name = @scopes.collect{|s| s.name}.join("::")
859
+ @scoped_name = @scopes.collect { |s| s.name }.join("::")
842
860
  end
843
861
 
844
- def is_defined?; @defined; end
845
- def is_preprocessed?; @preprocessed; end
862
+ def is_defined?
863
+ @defined
864
+ end
865
+
866
+ def is_preprocessed?
867
+ @preprocessed
868
+ end
846
869
 
847
870
  def introduce(node)
848
871
  @enclosure.introduce(node) unless node == self
@@ -862,9 +885,9 @@ module IDL::AST
862
885
  @filename = _template.filename
863
886
  @defined = _template.is_defined?
864
887
  @preprocessed = _template.is_preprocessed?
865
- #overrule
888
+ # overrule
866
889
  @scopes = @enclosure.scopes
867
- @scoped_name = @scopes.collect{|s| s.name}.join("::")
890
+ @scoped_name = @scopes.collect { |s| s.name }.join("::")
868
891
  self
869
892
  end
870
893
 
@@ -874,7 +897,6 @@ module IDL::AST
874
897
  end # Include
875
898
 
876
899
  class Derivable < Node
877
-
878
900
  alias :search_self_before_derived :search_self
879
901
  def search_self(_name)
880
902
  node = search_self_before_derived(_name)
@@ -895,6 +917,7 @@ module IDL::AST
895
917
  def each_ancestors(visited = [], &block)
896
918
  resolved_bases.each do |p|
897
919
  next if visited.include? p
920
+
898
921
  yield(p)
899
922
  visited.push p
900
923
  p.each_ancestors(visited, &block)
@@ -911,8 +934,9 @@ module IDL::AST
911
934
  if results.size > 1
912
935
  # check if the matched name resulted in multiple different nodes or all the same
913
936
  r_one = results.shift
914
- unless results.all? {|r| r_one == r || (r_one.class == r.class && r_one.scoped_name == r.scoped_name) }
915
- s = results.inject([r_one]) {|l, r| l << r unless l.include?(r); l }.collect{ |n| n.scoped_name }.join(", ")
937
+ unless results.all? { |r| r_one == r || (r_one.class == r.class && r_one.scoped_name == r.scoped_name) }
938
+ s = results.inject([r_one]) { |l, r| l << r unless l.include?(r)
939
+ l }.collect { |n| n.scoped_name }.join(", ")
916
940
  raise "\"#{_name}\" is ambiguous. " + s
917
941
  end
918
942
  end
@@ -945,8 +969,7 @@ module IDL::AST
945
969
  class Interface < Derivable
946
970
  DEFINABLE = [IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute,
947
971
  IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
948
- attr_reader :bases
949
- attr_reader :idltype
972
+ attr_reader :bases, :idltype
950
973
 
951
974
  def initialize(_name, _enclosure, params)
952
975
  super(_name, _enclosure)
@@ -977,22 +1000,36 @@ module IDL::AST
977
1000
 
978
1001
  def instantiate(instantiation_context, _enclosure)
979
1002
  _params = {
980
- :forward => self.is_forward?,
981
- :abstract => self.is_abstract?,
982
- :pseudo => self.is_pseudo?,
983
- :local => self.is_local?,
984
- :inherits => self.concrete_bases(instantiation_context)
1003
+ forward: self.is_forward?,
1004
+ abstract: self.is_abstract?,
1005
+ pseudo: self.is_pseudo?,
1006
+ local: self.is_local?,
1007
+ inherits: self.concrete_bases(instantiation_context)
985
1008
  }
986
1009
  # instantiate concrete interface def and validate
987
1010
  # concrete bases
988
1011
  super(instantiation_context, _enclosure, _params)
989
1012
  end
990
1013
 
991
- def is_abstract?; @abstract; end
992
- def is_local?; @local; end
993
- def is_pseudo?; @pseudo; end
994
- def is_defined?; @defined; end
995
- def is_forward?; not @defined; end
1014
+ def is_abstract?
1015
+ @abstract
1016
+ end
1017
+
1018
+ def is_local?
1019
+ @local
1020
+ end
1021
+
1022
+ def is_pseudo?
1023
+ @pseudo
1024
+ end
1025
+
1026
+ def is_defined?
1027
+ @defined
1028
+ end
1029
+
1030
+ def is_forward?
1031
+ not @defined
1032
+ end
996
1033
 
997
1034
  def add_bases(inherits_)
998
1035
  inherits_.each do |tc|
@@ -1000,11 +1037,12 @@ module IDL::AST
1000
1037
  unless (tc.is_a?(IDL::Type::NodeType) && tc.is_node?(IDL::AST::Interface))
1001
1038
  raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
1002
1039
  end
1040
+
1003
1041
  rtc = tc.resolved_type
1004
1042
  if rtc.node.has_ancestor?(self)
1005
1043
  raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{tc.node.scoped_lm_name} is descendant"
1006
1044
  end
1007
- if not rtc.node.is_defined?
1045
+ unless rtc.node.is_defined?
1008
1046
  raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
1009
1047
  end
1010
1048
  if rtc.node.is_local? and not self.is_local?
@@ -1022,6 +1060,7 @@ module IDL::AST
1022
1060
  if self.has_base?(rtc.node)
1023
1061
  raise "#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
1024
1062
  end
1063
+
1025
1064
  # check if we indirectly derive from this base multiple times (which is ok; no further need to check)
1026
1065
  unless @resolved_bases.any? { |b| b.has_ancestor?(rtc.node) }
1027
1066
  # this is a new base so we need to check for member redefinition/ambiguity
@@ -1029,7 +1068,8 @@ module IDL::AST
1029
1068
  rtc.node.walk_members do |m|
1030
1069
  new_op_att_ << m if m.is_a?(IDL::AST::Operation) || m.is_a?(IDL::AST::Attribute)
1031
1070
  end
1032
- if new_op_att_.any? {|n| n_ = self.search_self(n.name); n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
1071
+ if new_op_att_.any? { |n| n_ = self.search_self(n.name)
1072
+ n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
1033
1073
  raise "#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} because of duplicated operations/attributes"
1034
1074
  end
1035
1075
  # no need to check for duplicate member names; this inheritance is ok
@@ -1048,13 +1088,13 @@ module IDL::AST
1048
1088
  @resolved_bases
1049
1089
  end
1050
1090
 
1051
- def operations(include_bases=false, traversed=nil)
1091
+ def operations(include_bases = false, traversed = nil)
1052
1092
  ops = @children.find_all { |c| c.is_a?(IDL::AST::Operation) }
1053
1093
  ops.concat(base_operations(traversed || [])) if include_bases
1054
1094
  ops
1055
1095
  end
1056
1096
 
1057
- def attributes(include_bases=false, traversed=nil)
1097
+ def attributes(include_bases = false, traversed = nil)
1058
1098
  atts = @children.find_all { |c| c.is_a?(IDL::AST::Attribute) }
1059
1099
  atts.concat(base_attributes(traversed || [])) if include_bases
1060
1100
  atts
@@ -1067,6 +1107,7 @@ module IDL::AST
1067
1107
  if node.is_defined?
1068
1108
  raise "#{node.typename} \"#{node.name}\" is already defined."
1069
1109
  end
1110
+
1070
1111
  node.annotations.concat(params[:annotations])
1071
1112
 
1072
1113
  _new_node = node.class.new(node.name, self, params)
@@ -1095,7 +1136,7 @@ module IDL::AST
1095
1136
  newnode = node.class.new(node.name, self, params)
1096
1137
  newnode.annotations.concat(params[:annotations])
1097
1138
  introduce(newnode)
1098
- @children << newnode # add overriding child
1139
+ @children << newnode # add overriding child
1099
1140
  return newnode
1100
1141
  end
1101
1142
  end
@@ -1116,9 +1157,7 @@ module IDL::AST
1116
1157
 
1117
1158
  class ComponentBase < Derivable
1118
1159
  DEFINABLE = []
1119
- attr_reader :base
1120
- attr_reader :interfaces
1121
- attr_reader :idltype
1160
+ attr_reader :base, :interfaces, :idltype
1122
1161
 
1123
1162
  def initialize(_name, _enclosure, params)
1124
1163
  super(_name, _enclosure)
@@ -1145,8 +1184,8 @@ module IDL::AST
1145
1184
 
1146
1185
  def instantiate(instantiation_context, _enclosure, _params = {})
1147
1186
  _params.merge!({
1148
- :base => @base ? IDL::AST::TemplateParam.concrete_param(instantiation_context, @base) : @base,
1149
- :supports => self.concrete_interfaces(instantiation_context)
1187
+ base: @base ? IDL::AST::TemplateParam.concrete_param(instantiation_context, @base) : @base,
1188
+ supports: self.concrete_interfaces(instantiation_context)
1150
1189
  })
1151
1190
  # instantiate concrete def and validate
1152
1191
  super(instantiation_context, _enclosure, _params)
@@ -1160,6 +1199,7 @@ module IDL::AST
1160
1199
  if parent.resolved_type.node.has_base?(self)
1161
1200
  raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{parent.node.scoped_lm_name} is descendant"
1162
1201
  end
1202
+
1163
1203
  @resolved_base = parent.resolved_type.node
1164
1204
  end
1165
1205
  @base = parent.node
@@ -1179,8 +1219,9 @@ module IDL::AST
1179
1219
  unless (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Interface))
1180
1220
  raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
1181
1221
  end
1222
+
1182
1223
  rtc = tc.resolved_type
1183
- if not rtc.node.is_defined?
1224
+ unless rtc.node.is_defined?
1184
1225
  raise "#{typename} #{scoped_lm_name} cannot support forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
1185
1226
  end
1186
1227
  ## TODO : is this legal?
@@ -1191,13 +1232,14 @@ module IDL::AST
1191
1232
  raise "#{typename} #{scoped_lm_name} cannot support 'pseudo' #{tc.node.typename} #{tc.node.scoped_lm_name}"
1192
1233
  end
1193
1234
  ## TODO : is this legal?
1194
- #if tc.node.is_abstract?
1235
+ # if tc.node.is_abstract?
1195
1236
  # raise RuntimeError,
1196
1237
  # "'abstract' #{typename} #{scoped_lm_name} cannot support 'abstract' #{tc.node.typename} #{tc.node.scoped_lm_name}"
1197
- #end
1238
+ # end
1198
1239
  if self.has_support?(rtc.node)
1199
1240
  raise "#{typename} #{scoped_lm_name} cannot support #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
1200
1241
  end
1242
+
1201
1243
  # check if we indirectly support this base multiple times (which is ok; no further need to check)
1202
1244
  unless @resolved_interfaces.any? { |b| b.has_ancestor?(rtc.node) }
1203
1245
  # this is a new support interface so we need to check for member redefinition/ambiguity
@@ -1205,7 +1247,8 @@ module IDL::AST
1205
1247
  rtc.node.walk_members do |m|
1206
1248
  new_op_att_ << m if m.is_a?(IDL::AST::Operation) || m.is_a?(IDL::AST::Attribute)
1207
1249
  end
1208
- if new_op_att_.any? {|n| n_ = self.search_self(n.name); n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
1250
+ if new_op_att_.any? { |n| n_ = self.search_self(n.name)
1251
+ n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
1209
1252
  raise "#{typename} #{scoped_lm_name} cannot support #{tc.node.typename} #{tc.node.scoped_lm_name} because of duplicated operations/attributes"
1210
1253
  end
1211
1254
  # no need to check for duplicate member names; this support is ok
@@ -1231,6 +1274,7 @@ module IDL::AST
1231
1274
  if node.is_defined?
1232
1275
  raise "#{node.typename} \"#{node.name}\" is already defined."
1233
1276
  end
1277
+
1234
1278
  node.annotations.concat(params[:annotations])
1235
1279
 
1236
1280
  _new_node = node.class.new(node.name, self, params)
@@ -1259,7 +1303,7 @@ module IDL::AST
1259
1303
  newnode = node.class.new(node.name, self, params)
1260
1304
  newnode.annotations.concat(params[:annotations])
1261
1305
  introduce(newnode)
1262
- @children << newnode # add overriding child
1306
+ @children << newnode # add overriding child
1263
1307
  return newnode
1264
1308
  end
1265
1309
  end
@@ -1281,8 +1325,7 @@ module IDL::AST
1281
1325
  class Home < ComponentBase
1282
1326
  DEFINABLE = [IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::Initializer, IDL::AST::Finder,
1283
1327
  IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
1284
- attr_reader :component
1285
- attr_reader :primarykey
1328
+ attr_reader :component, :primarykey
1286
1329
 
1287
1330
  def initialize(_name, _enclosure, params)
1288
1331
  @component = nil
@@ -1307,9 +1350,9 @@ module IDL::AST
1307
1350
  end
1308
1351
 
1309
1352
  def instantiate(instantiation_context, _enclosure)
1310
- _params = {
1311
- :component => IDL::AST::TemplateParam.concrete_param(instantiation_context, @component),
1312
- :primarykey => @primarykey ? IDL::AST::TemplateParam.concrete_param(instantiation_context, @primarykey) : @primarykey
1353
+ _params = {
1354
+ component: IDL::AST::TemplateParam.concrete_param(instantiation_context, @component),
1355
+ primarykey: @primarykey ? IDL::AST::TemplateParam.concrete_param(instantiation_context, @primarykey) : @primarykey
1313
1356
  }
1314
1357
  # instantiate concrete home def and validate
1315
1358
  super(instantiation_context, _enclosure, _params)
@@ -1325,6 +1368,7 @@ module IDL::AST
1325
1368
  unless comp.resolved_type.node.is_defined?
1326
1369
  raise "#{scoped_lm_name}: #{comp.typename} cannot manage forward declared component #{comp.node.scoped_lm_name}"
1327
1370
  end
1371
+
1328
1372
  @resolved_comp = comp.resolved_type.node
1329
1373
  end
1330
1374
  unless key&.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::TemplateParam)
@@ -1332,24 +1376,24 @@ module IDL::AST
1332
1376
  unless key.nil? || (key.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::Valuetype))
1333
1377
  raise "invalid primary key for #{typename} #{scoped_lm_name}: #{key.typename}"
1334
1378
  end
1379
+
1335
1380
  @resolved_pk = key.resolved_type.node if key
1336
1381
  end
1337
1382
  @component = comp.node
1338
1383
  @primarykey = key.node if key
1339
1384
  end
1340
1385
 
1341
- def operations(include_bases=false, traversed=nil)
1386
+ def operations(include_bases = false, traversed = nil)
1342
1387
  ops = @children.find_all { |c| c.is_a?(IDL::AST::Operation) }
1343
1388
  ops.concat(base_operations(traversed || [])) if include_bases
1344
1389
  ops
1345
1390
  end
1346
1391
 
1347
- def attributes(include_bases=false, traversed=nil)
1392
+ def attributes(include_bases = false, traversed = nil)
1348
1393
  atts = @children.find_all { |c| c.is_a?(IDL::AST::Attribute) }
1349
1394
  atts.concat(base_attributes(traversed || [])) if include_bases
1350
1395
  atts
1351
1396
  end
1352
-
1353
1397
  end # Home
1354
1398
 
1355
1399
  class Connector < ComponentBase
@@ -1373,8 +1417,13 @@ module IDL::AST
1373
1417
  super(instantiation_context, _enclosure, {})
1374
1418
  end
1375
1419
 
1376
- def is_defined?; true; end
1377
- def is_forward?; false; end
1420
+ def is_defined?
1421
+ true
1422
+ end
1423
+
1424
+ def is_forward?
1425
+ false
1426
+ end
1378
1427
 
1379
1428
  def add_interfaces(intfs)
1380
1429
  raise "interface support not allowed for #{typename} #{scoped_lm_name}" if intfs && !intfs.empty?
@@ -1385,6 +1434,7 @@ module IDL::AST
1385
1434
  unless (parent.is_a?(IDL::Type::NodeType) && parent.is_node?(self.class))
1386
1435
  raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{parent.typename}"
1387
1436
  end
1437
+
1388
1438
  @resolved_base = parent.resolved_type.node
1389
1439
  if @resolved_base.has_base?(self)
1390
1440
  raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{parent.node.scoped_lm_name} is descendant"
@@ -1393,7 +1443,7 @@ module IDL::AST
1393
1443
  @base = parent.node
1394
1444
  end
1395
1445
 
1396
- def ports(include_bases=false, traversed=nil)
1446
+ def ports(include_bases = false, traversed = nil)
1397
1447
  ports = @children.inject([]) do |lst, c|
1398
1448
  lst.concat(c.ports) if IDL::AST::Port === c
1399
1449
  lst
@@ -1402,7 +1452,7 @@ module IDL::AST
1402
1452
  ports
1403
1453
  end
1404
1454
 
1405
- def attributes(include_bases=false, traversed=nil)
1455
+ def attributes(include_bases = false, traversed = nil)
1406
1456
  atts = @children.inject([]) do |lst, c|
1407
1457
  if IDL::AST::Port === c
1408
1458
  lst.concat(c.attributes)
@@ -1427,7 +1477,6 @@ module IDL::AST
1427
1477
  end
1428
1478
  ports
1429
1479
  end
1430
-
1431
1480
  end # Connector
1432
1481
 
1433
1482
  class Component < ComponentBase
@@ -1450,19 +1499,25 @@ module IDL::AST
1450
1499
 
1451
1500
  def instantiate(instantiation_context, _enclosure)
1452
1501
  # instantiate concrete component def and validate
1453
- super(instantiation_context, _enclosure, { :forward => self.is_forward? })
1502
+ super(instantiation_context, _enclosure, { forward: self.is_forward? })
1454
1503
  end
1455
1504
 
1456
- def is_defined?; @defined; end
1457
- def is_forward?; not @defined; end
1505
+ def is_defined?
1506
+ @defined
1507
+ end
1508
+
1509
+ def is_forward?
1510
+ not @defined
1511
+ end
1458
1512
 
1459
1513
  def set_base(parent)
1460
1514
  unless parent.is_a?(IDL::Type::ScopedName) && parent.is_node?(IDL::AST::TemplateParam)
1461
1515
  unless (parent.is_a?(IDL::Type::NodeType) && parent.is_node?(self.class))
1462
1516
  raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{parent.typename}"
1463
1517
  end
1518
+
1464
1519
  @resolved_base = parent.resolved_type.node
1465
- if not @resolved_base.is_defined?
1520
+ unless @resolved_base.is_defined?
1466
1521
  raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{parent.node.typename} #{parent.node.scoped_lm_name}"
1467
1522
  end
1468
1523
  if @resolved_base.has_base?(self)
@@ -1472,7 +1527,7 @@ module IDL::AST
1472
1527
  @base = parent.node
1473
1528
  end
1474
1529
 
1475
- def ports(include_bases=false, traversed=nil)
1530
+ def ports(include_bases = false, traversed = nil)
1476
1531
  ports = @children.inject([]) do |lst, c|
1477
1532
  lst.concat(c.ports) if IDL::AST::Port === c
1478
1533
  lst
@@ -1481,11 +1536,11 @@ module IDL::AST
1481
1536
  ports
1482
1537
  end
1483
1538
 
1484
- def operations(include_bases=false, traversed=nil)
1539
+ def operations(include_bases = false, traversed = nil)
1485
1540
  include_bases ? base_operations(traversed || []) : []
1486
1541
  end
1487
1542
 
1488
- def attributes(include_bases=false, traversed=nil)
1543
+ def attributes(include_bases = false, traversed = nil)
1489
1544
  atts = @children.inject([]) do |lst, c|
1490
1545
  if IDL::AST::Port === c
1491
1546
  lst.concat(c.attributes)
@@ -1510,23 +1565,23 @@ module IDL::AST
1510
1565
  end
1511
1566
  ports
1512
1567
  end
1513
-
1514
1568
  end # Component
1515
1569
 
1516
1570
  class Porttype < Node
1517
1571
  DEFINABLE = [IDL::AST::Attribute, IDL::AST::Port]
1518
1572
  attr_reader :idltype
1519
- def initialize(_name, _enclosure, params)
1573
+
1574
+ def initialize(_name, _enclosure, _params)
1520
1575
  super(_name, _enclosure)
1521
1576
  @idltype = IDL::Type::Porttype.new(self)
1522
1577
  end
1523
1578
 
1524
1579
  def ports
1525
- @children.select {|c| IDL::AST::Port === c}
1580
+ @children.select { |c| IDL::AST::Port === c }
1526
1581
  end
1527
1582
 
1528
1583
  def attributes
1529
- @children.select {|c| IDL::AST::Attribute === c}
1584
+ @children.select { |c| IDL::AST::Attribute === c }
1530
1585
  end
1531
1586
 
1532
1587
  def instantiate(instantiation_context, _enclosure)
@@ -1536,15 +1591,16 @@ module IDL::AST
1536
1591
 
1537
1592
  class Port < Leaf
1538
1593
  PORTTYPES = [:facet, :receptacle, :emitter, :publisher, :consumer, :port, :mirrorport]
1539
- PORT_MIRRORS = {:facet => :receptacle, :receptacle => :facet}
1594
+ PORT_MIRRORS = {facet: :receptacle, receptacle: :facet}
1540
1595
  EXTPORTDEF_ANNOTATION = 'ExtendedPortDef'
1541
- attr_reader :idltype
1542
- attr_reader :porttype
1596
+ attr_reader :idltype, :porttype
1597
+
1543
1598
  def initialize(_name, _enclosure, params)
1544
1599
  super(_name, _enclosure)
1545
1600
  @idltype = params[:type]
1546
1601
  @porttype = params[:porttype]
1547
1602
  raise "unknown porttype for #{typename} #{scoped_lm_name}: #{@porttype}" unless PORTTYPES.include?(@porttype)
1603
+
1548
1604
  case @porttype
1549
1605
  when :facet, :receptacle
1550
1606
  unless @idltype.is_a?(IDL::Type::Object) ||
@@ -1565,9 +1621,9 @@ module IDL::AST
1565
1621
 
1566
1622
  def instantiate(instantiation_context, _enclosure)
1567
1623
  _params = {
1568
- :type => @idltype.instantiate(instantiation_context),
1569
- :porttype => @porttype,
1570
- :multiple => @multiple
1624
+ type: @idltype.instantiate(instantiation_context),
1625
+ porttype: @porttype,
1626
+ multiple: @multiple
1571
1627
  }
1572
1628
  super(instantiation_context, _enclosure, _params)
1573
1629
  end
@@ -1577,23 +1633,23 @@ module IDL::AST
1577
1633
  end
1578
1634
 
1579
1635
  def expanded_copy(name_pfx, enc)
1580
- p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {:type => @idltype, :porttype => @porttype})
1581
- p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { :extended_port_name => name_pfx, :base_name => self.name, :mirror => false })
1636
+ p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, porttype: @porttype})
1637
+ p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: name_pfx, base_name: self.name, mirror: false })
1582
1638
  p # return expanded copy
1583
1639
  end
1584
1640
 
1585
1641
  def expanded_mirror_copy(name_pfx, enc)
1586
- p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {:type => @idltype, :porttype => PORT_MIRRORS[@porttype]})
1587
- p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { :extended_port_name => name_pfx, :base_name => self.name, :mirror => true })
1642
+ p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, porttype: PORT_MIRRORS[@porttype]})
1643
+ p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: name_pfx, base_name: self.name, mirror: true })
1588
1644
  p # return expanded copy
1589
1645
  end
1590
1646
 
1591
1647
  def ports
1592
1648
  case @porttype
1593
1649
  when :port
1594
- @idltype.resolved_type.node.ports.collect {|p| p.expanded_copy(self.name, self.enclosure) }
1650
+ @idltype.resolved_type.node.ports.collect { |p| p.expanded_copy(self.name, self.enclosure) }
1595
1651
  when :mirrorport
1596
- @idltype.resolved_type.node.ports.collect {|p| p.expanded_mirror_copy(self.name, self.enclosure) }
1652
+ @idltype.resolved_type.node.ports.collect { |p| p.expanded_mirror_copy(self.name, self.enclosure) }
1597
1653
  else
1598
1654
  [self]
1599
1655
  end
@@ -1602,9 +1658,9 @@ module IDL::AST
1602
1658
  def attributes
1603
1659
  case @porttype
1604
1660
  when :port, :mirrorport
1605
- @idltype.resolved_type.node.attributes.collect {|att|
1661
+ @idltype.resolved_type.node.attributes.collect { |att|
1606
1662
  exp_a = att.expanded_copy(self.name, self.enclosure)
1607
- exp_a.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { :extended_port_name => self.name, :base_name => att.name, :mirror => (@porttype == :mirrorport) })
1663
+ exp_a.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: self.name, base_name: att.name, mirror: (@porttype == :mirrorport) })
1608
1664
  exp_a # return expanded copy
1609
1665
  }
1610
1666
  else
@@ -1615,10 +1671,11 @@ module IDL::AST
1615
1671
 
1616
1672
  class Valuebox < Leaf
1617
1673
  attr_reader :idltype, :boxed_type
1674
+
1618
1675
  def initialize(_name, _enclosure, params)
1619
1676
  super(_name, _enclosure)
1620
1677
  @idltype = IDL::Type::Valuebox.new(self)
1621
- @boxed_type = params[:type]
1678
+ @boxed_type = params[:type]
1622
1679
  unless @boxed_type.is_a?(IDL::Type::ScopedName) && @boxed_type.is_node?(IDL::AST::TemplateParam)
1623
1680
  if @boxed_type.resolved_type.is_a?(IDL::Type::Valuetype)
1624
1681
  raise "boxing valuetype #{@boxed_type.scoped_lm_name} in Valuebox #{scoped_lm_name} not allowed"
@@ -1642,7 +1699,7 @@ module IDL::AST
1642
1699
 
1643
1700
  def instantiate(instantiation_context, _enclosure)
1644
1701
  _params = {
1645
- :type => @boxed_type.instantiate(instantiation_context)
1702
+ type: @boxed_type.instantiate(instantiation_context)
1646
1703
  }
1647
1704
  super(instantiation_context, _enclosure, _params)
1648
1705
  end
@@ -1651,8 +1708,7 @@ module IDL::AST
1651
1708
  class Valuetype < Derivable
1652
1709
  DEFINABLE = [IDL::AST::Include, IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::StateMember, IDL::AST::Initializer,
1653
1710
  IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
1654
- attr_reader :bases, :interfaces
1655
- attr_reader :idltype
1711
+ attr_reader :bases, :interfaces, :idltype
1656
1712
 
1657
1713
  def initialize(_name, _enclosure, params)
1658
1714
  super(_name, _enclosure)
@@ -1677,6 +1733,7 @@ module IDL::AST
1677
1733
  if @custom && @truncatable
1678
1734
  raise "'truncatable' attribute *not* allowed for 'custom' #{typename} #{scoped_lm_name}"
1679
1735
  end
1736
+
1680
1737
  add_bases(_base[:list] || [])
1681
1738
  add_interfaces(_inherits[:supports] || [])
1682
1739
  end
@@ -1707,15 +1764,15 @@ module IDL::AST
1707
1764
 
1708
1765
  def instantiate(instantiation_context, _enclosure)
1709
1766
  _params = {
1710
- :forward => self.is_forward?,
1711
- :abstract => self.is_abstract?,
1712
- :custom => self.is_custom?,
1713
- :inherits => {
1714
- :base => {
1715
- :truncatable => self.is_truncatable?,
1716
- :list => self.concrete_bases(instantiation_context)
1767
+ forward: self.is_forward?,
1768
+ abstract: self.is_abstract?,
1769
+ custom: self.is_custom?,
1770
+ inherits: {
1771
+ base: {
1772
+ truncatable: self.is_truncatable?,
1773
+ list: self.concrete_bases(instantiation_context)
1717
1774
  },
1718
- :supports => self.concrete_interfaces(instantiation_context)
1775
+ supports: self.concrete_interfaces(instantiation_context)
1719
1776
  }
1720
1777
  }
1721
1778
  inst = super(instantiation_context, _enclosure, _params)
@@ -1723,19 +1780,43 @@ module IDL::AST
1723
1780
  inst
1724
1781
  end
1725
1782
 
1726
- def is_abstract?; @abstract; end
1727
- def is_custom?; @custom; end
1728
- def is_truncatable?; @truncatable; end
1729
- def is_defined?; @defined; end
1730
- def defined=(f); @defined = f; end
1731
- def is_forward?; @forward; end
1732
- def is_recursive?; @recursive end
1733
- def recursive=(f); @recursive = f end
1783
+ def is_abstract?
1784
+ @abstract
1785
+ end
1786
+
1787
+ def is_custom?
1788
+ @custom
1789
+ end
1790
+
1791
+ def is_truncatable?
1792
+ @truncatable
1793
+ end
1794
+
1795
+ def is_defined?
1796
+ @defined
1797
+ end
1798
+
1799
+ def defined=(f)
1800
+ @defined = f
1801
+ end
1802
+
1803
+ def is_forward?
1804
+ @forward
1805
+ end
1806
+
1807
+ def is_recursive?
1808
+ @recursive
1809
+ end
1810
+
1811
+ def recursive=(f)
1812
+ @recursive = f
1813
+ end
1734
1814
 
1735
1815
  def is_local?(recurstk = [])
1736
1816
  # not local if forward decl or recursion detected
1737
1817
  return false if is_forward? || recurstk.include?(self)
1738
- recurstk.push self # track root node to detect recursion
1818
+
1819
+ recurstk.push self # track root node to detect recursion
1739
1820
  ret = state_members.any? { |m| m.is_local?(recurstk) }
1740
1821
  recurstk.pop
1741
1822
  ret
@@ -1766,22 +1847,23 @@ module IDL::AST
1766
1847
  end
1767
1848
 
1768
1849
  def truncatable_ids
1769
- ids = [self.repository_id()]
1770
- ids.concat(@resolved_bases.first().truncatable_ids()) if self.has_concrete_base?() && self.is_truncatable?()
1850
+ ids = [self.repository_id]
1851
+ ids.concat(@resolved_bases.first.truncatable_ids) if self.has_concrete_base? && self.is_truncatable?
1771
1852
  ids
1772
1853
  end
1773
1854
 
1774
1855
  def add_bases(inherits_)
1775
1856
  inherits_.each do |tc|
1776
1857
  unless tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::TemplateParam)
1777
- if not (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Valuetype))
1858
+ unless (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Valuetype))
1778
1859
  raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
1779
1860
  end
1861
+
1780
1862
  rtc = tc.resolved_type
1781
1863
  if rtc.node.has_ancestor?(self)
1782
1864
  raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{tc.node.scoped_lm_name} is descendant"
1783
1865
  end
1784
- if not rtc.node.is_defined?
1866
+ unless rtc.node.is_defined?
1785
1867
  raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
1786
1868
  end
1787
1869
  if self.is_abstract? and not rtc.node.is_abstract?
@@ -1793,7 +1875,8 @@ module IDL::AST
1793
1875
  if @resolved_bases.include?(rtc.node)
1794
1876
  raise "#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
1795
1877
  end
1796
- if (not rtc.node.is_abstract?) and @bases.size > 0
1878
+
1879
+ if (not rtc.node.is_abstract?) and !@bases.empty?
1797
1880
  raise "concrete basevalue #{tc.node.typename} #{tc.node.scoped_lm_name} MUST " +
1798
1881
  "be first and only non-abstract in inheritance list for #{typename} #{scoped_lm_name}"
1799
1882
  end
@@ -1806,17 +1889,19 @@ module IDL::AST
1806
1889
  def add_interfaces(iflist_)
1807
1890
  iflist_.each do |if_|
1808
1891
  unless if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::TemplateParam)
1809
- if not (if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::Interface))
1892
+ unless (if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::Interface))
1810
1893
  raise "invalid support identifier for #{typename} #{scoped_lm_name}: #{if_.typename}"
1811
1894
  end
1895
+
1812
1896
  rif_ = if_.resolved_type
1813
1897
  ### @@TODO@@ further validation
1814
- if (not rif_.node.is_abstract?) and @interfaces.size > 0
1898
+ if (not rif_.node.is_abstract?) and !@interfaces.empty?
1815
1899
  raise "concrete interface '#{rif_.node.scoped_lm_name}' inheritance not allowed for #{typename} #{scoped_lm_name}. Valuetypes can only inherit (support) a single concrete interface."
1816
1900
  end
1817
1901
  if (not rif_.node.is_abstract?) && (not is_interface_compatible?(rif_.node))
1818
1902
  raise "#{typename} #{scoped_lm_name} cannot support concrete interface #{rif_.node.scoped_lm_name} because it does not derive from inherited concrete interfaces"
1819
1903
  end
1904
+
1820
1905
  @resolved_interfaces << rif_.node
1821
1906
  end
1822
1907
  @interfaces << if_.node
@@ -1839,10 +1924,11 @@ module IDL::AST
1839
1924
  if self.is_abstract? && [IDL::AST::StateMember, IDL::AST::Initializer].include?(_type)
1840
1925
  raise "cannot define statemember #{_name} on abstract #{typename} #{scoped_lm_name}"
1841
1926
  end
1927
+
1842
1928
  super(_type, _name, *args)
1843
1929
  end
1844
1930
 
1845
- def walk_members(&block)
1931
+ def walk_members
1846
1932
  @children.each { |c| yield(c) unless c.is_a?(IDL::AST::StateMember) or
1847
1933
  c.is_a?(IDL::AST::Operation) or
1848
1934
  c.is_a?(IDL::AST::Attribute) or
@@ -1876,6 +1962,7 @@ module IDL::AST
1876
1962
  if node.is_defined?
1877
1963
  raise "#{node.typename} \"#{node.name}\" is already defined."
1878
1964
  end
1965
+
1879
1966
  node.annotations.concat(params[:annotations])
1880
1967
 
1881
1968
  _new_node = node.class.new(node.name, self, params)
@@ -1910,7 +1997,7 @@ module IDL::AST
1910
1997
 
1911
1998
  protected
1912
1999
 
1913
- def walk_members_for_copy(&block)
2000
+ def walk_members_for_copy
1914
2001
  @children.each { |c| yield(c) }
1915
2002
  end
1916
2003
 
@@ -1942,6 +2029,7 @@ module IDL::AST
1942
2029
 
1943
2030
  class StateMember < Leaf
1944
2031
  attr_reader :idltype, :visibility
2032
+
1945
2033
  def initialize(_name, _enclosure, params)
1946
2034
  @is_recursive = false
1947
2035
  @has_incomplete_type = false
@@ -1950,8 +2038,9 @@ module IDL::AST
1950
2038
  @visibility = (params[:visibility] == :public ? :public : :private)
1951
2039
  unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
1952
2040
  raise "Anonymous type definitions are not allowed!" if params[:type].is_anonymous?
2041
+
1953
2042
  ## check for use of incomplete types
1954
- if !@idltype.is_complete?
2043
+ unless @idltype.is_complete?
1955
2044
  ## verify type is used in sequence
1956
2045
  if @idltype.resolved_type.is_a?(IDL::Type::Sequence)
1957
2046
  ## find the (non-sequence) elementtype
@@ -1965,7 +2054,7 @@ module IDL::AST
1965
2054
  if mtype.is_a? IDL::Type::ScopedName
1966
2055
  case mtype.resolved_type
1967
2056
  when IDL::Type::Struct, IDL::Type::Union, IDL::Type::Valuetype
1968
- if !mtype.node.is_defined?
2057
+ unless mtype.node.is_defined?
1969
2058
  ## check if incomplete struct/union/valuetype is contained within definition of self
1970
2059
  enc = _enclosure
1971
2060
  while enc.is_a?(IDL::AST::Struct) || enc.is_a?(IDL::AST::Union) || enc.is_a?(IDL::AST::Valuetype)
@@ -2024,8 +2113,8 @@ module IDL::AST
2024
2113
 
2025
2114
  def instantiate(instantiation_context, _enclosure)
2026
2115
  _params = {
2027
- :type => @idltype.instantiate(instantiation_context),
2028
- :visibility => self.visibility
2116
+ type: @idltype.instantiate(instantiation_context),
2117
+ visibility: self.visibility
2029
2118
  }
2030
2119
  super(instantiation_context, _enclosure, _params)
2031
2120
  end
@@ -2049,10 +2138,11 @@ module IDL::AST
2049
2138
 
2050
2139
  class Initializer < Leaf
2051
2140
  attr_reader :raises, :params
2141
+
2052
2142
  def initialize(_name, _enclosure, params)
2053
2143
  super(_name, _enclosure)
2054
2144
  @params = (params[:params] || []).collect do |(ptype, pname)|
2055
- IDL::AST::Parameter.new(pname, self, {:attribute => :in, :type => ptype})
2145
+ IDL::AST::Parameter.new(pname, self, {attribute: :in, type: ptype})
2056
2146
  end
2057
2147
  @raises = []
2058
2148
  self.raises = params[:raises]
@@ -2064,6 +2154,7 @@ module IDL::AST
2064
2154
  (extype.is_node?(IDL::AST::Exception) || extype.is_node?(IDL::AST::TemplateParam) || extype.resolved_type.is_a?(IDL::Type::Native))
2065
2155
  raise 'Only IDL Exception types allowed in raises declaration.'
2066
2156
  end
2157
+
2067
2158
  @raises << extype
2068
2159
  end
2069
2160
  end
@@ -2080,7 +2171,7 @@ module IDL::AST
2080
2171
 
2081
2172
  def instantiate(instantiation_context, _enclosure)
2082
2173
  _params = {
2083
- :raises => self.concrete_raises(instantiation_context)
2174
+ raises: self.concrete_raises(instantiation_context)
2084
2175
  }
2085
2176
  _init = super(instantiation_context, _enclosure, _params)
2086
2177
  _init.set_concrete_parameters(instantiation_context, @params)
@@ -2098,11 +2189,10 @@ module IDL::AST
2098
2189
  def set_concrete_parameters(instantiation_context, parms)
2099
2190
  @params = parms.collect do |parm|
2100
2191
  IDL::AST::Parameter.new(parm.name, self,
2101
- { :attribute => :in,
2102
- :type => parm.idltype.instantiate(instantiation_context) })
2192
+ { attribute: :in,
2193
+ type: parm.idltype.instantiate(instantiation_context) })
2103
2194
  end
2104
2195
  end
2105
-
2106
2196
  end # Initializer
2107
2197
 
2108
2198
  class Finder < Initializer
@@ -2110,6 +2200,7 @@ module IDL::AST
2110
2200
 
2111
2201
  class Const < Leaf
2112
2202
  attr_reader :idltype, :expression, :value
2203
+
2113
2204
  def initialize(_name, _enclosure, params)
2114
2205
  super(_name, _enclosure)
2115
2206
  @idltype = params[:type]
@@ -2117,7 +2208,8 @@ module IDL::AST
2117
2208
  @value = nil
2118
2209
  unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
2119
2210
  raise "Anonymous type definitions are not allowed!" if @idltype.is_anonymous?
2120
- raise "Incomplete type #{@idltype.typename} not allowed here!" if !@idltype.is_complete?
2211
+ raise "Incomplete type #{@idltype.typename} not allowed here!" unless @idltype.is_complete?
2212
+
2121
2213
  unless @expression.is_a?(IDL::Expression::ScopedName) && @expression.is_node?(IDL::AST::TemplateParam)
2122
2214
  @value = @idltype.narrow(@expression.value)
2123
2215
  end
@@ -2141,21 +2233,24 @@ module IDL::AST
2141
2233
 
2142
2234
  def instantiate(instantiation_context, _enclosure)
2143
2235
  _params = {
2144
- :type => @idltype.instantiate(instantiation_context),
2145
- :expression => @expression.instantiate(instantiation_context)
2236
+ type: @idltype.instantiate(instantiation_context),
2237
+ expression: @expression.instantiate(instantiation_context)
2146
2238
  }
2147
2239
  super(instantiation_context, _enclosure, _params)
2148
2240
  end
2149
2241
  end # Const
2150
2242
 
2151
2243
  class Parameter < Leaf
2152
- IN, OUT, INOUT = 0, 1, 2
2244
+ IN = 0
2245
+ OUT = 1
2246
+ INOUT = 2
2153
2247
  ATTRIBUTE_MAP = {
2154
- :in => IN,
2155
- :out => OUT,
2156
- :inout => INOUT
2248
+ in: IN,
2249
+ out: OUT,
2250
+ inout: INOUT
2157
2251
  }
2158
2252
  attr_reader :idltype
2253
+
2159
2254
  def initialize(_name, _enclosure, params)
2160
2255
  super(_name, _enclosure)
2161
2256
  @idltype = params[:type]
@@ -2163,15 +2258,18 @@ module IDL::AST
2163
2258
  unless ATTRIBUTE_MAP.has_key?(@attribute)
2164
2259
  raise "invalid attribute for parameter: #{params[:attribute]}"
2165
2260
  end
2261
+
2166
2262
  unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
2167
2263
  raise "Anonymous type definitions are not allowed!" if params[:type].is_anonymous?
2264
+ raise "Exception #{@idltype.typename} is not allowed in an argument of an operation!" if @idltype.is_node?(IDL::AST::Exception)
2265
+
2168
2266
  if @idltype.is_local?
2169
2267
  if _enclosure.enclosure.is_a?(IDL::AST::Interface) && !_enclosure.enclosure.is_local?
2170
2268
  raise "Local type #{@idltype.typename} not allowed for operation on unrestricted interface"
2171
2269
  end
2172
2270
  ## IDL_Valuetype: no problem as valuetype operations are local
2173
2271
  end
2174
- if !@idltype.is_complete?
2272
+ unless @idltype.is_complete?
2175
2273
  if _enclosure.enclosure.is_a?(IDL::AST::Interface)
2176
2274
  raise "Incomplete type #{@idltype.typename} not allowed here!"
2177
2275
  end
@@ -2196,8 +2294,8 @@ module IDL::AST
2196
2294
 
2197
2295
  def instantiate(instantiation_context, _enclosure)
2198
2296
  _params = {
2199
- :type => @idltype.instantiate(instantiation_context),
2200
- :attribute => @attribute
2297
+ type: @idltype.instantiate(instantiation_context),
2298
+ attribute: @attribute
2201
2299
  }
2202
2300
  super(instantiation_context, _enclosure, _params)
2203
2301
  end
@@ -2218,13 +2316,14 @@ module IDL::AST
2218
2316
  @context = nil
2219
2317
  unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
2220
2318
  raise "Anonymous type definitions are not allowed!" if params[:type].is_anonymous?
2319
+
2221
2320
  if @idltype.is_local?
2222
2321
  if _enclosure.is_a?(IDL::AST::Interface) && !_enclosure.is_local?
2223
2322
  raise "Local type #{@idltype.typename} not allowed for operation on unrestricted interface"
2224
2323
  end
2225
2324
  ## IDL_Valuetype: no problem as valuetype operations are local
2226
2325
  end
2227
- if !@idltype.is_complete?
2326
+ unless @idltype.is_complete?
2228
2327
  if _enclosure.is_a?(IDL::AST::Interface)
2229
2328
  raise "Incomplete type #{@idltype.typename} not allowed here!"
2230
2329
  end
@@ -2249,8 +2348,8 @@ module IDL::AST
2249
2348
 
2250
2349
  def instantiate(instantiation_context, _enclosure)
2251
2350
  _params = {
2252
- :type => @idltype.instantiate(instantiation_context),
2253
- :oneway => @oneway,
2351
+ type: @idltype.instantiate(instantiation_context),
2352
+ oneway: @oneway
2254
2353
  }
2255
2354
  _op = super(instantiation_context, _enclosure, _params)
2256
2355
  _op.raises = self.concrete_raises(instantiation_context)
@@ -2264,6 +2363,7 @@ module IDL::AST
2264
2363
  (extype.is_node?(IDL::AST::Exception) || extype.is_node?(IDL::AST::TemplateParam) || extype.resolved_type.is_a?(IDL::Type::Native))
2265
2364
  raise 'Only IDL Exception or Native types allowed in raises declaration.'
2266
2365
  end
2366
+
2267
2367
  @raises << extype
2268
2368
  end
2269
2369
  end
@@ -2285,9 +2385,11 @@ module IDL::AST
2285
2385
  def in_params
2286
2386
  @in
2287
2387
  end
2388
+
2288
2389
  def out_params
2289
2390
  @out
2290
2391
  end
2392
+
2291
2393
  def params
2292
2394
  self.children
2293
2395
  end
@@ -2318,8 +2420,8 @@ module IDL::AST
2318
2420
  end # Operation
2319
2421
 
2320
2422
  class Attribute < Leaf
2321
- attr_reader :idltype, :readonly
2322
- attr_reader :get_raises, :set_raises
2423
+ attr_reader :idltype, :readonly, :get_raises, :set_raises
2424
+
2323
2425
  def initialize(_name, _enclosure, params)
2324
2426
  super(_name, _enclosure)
2325
2427
  @idltype = params[:type]
@@ -2327,13 +2429,15 @@ module IDL::AST
2327
2429
  @set_raises = []
2328
2430
  unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
2329
2431
  raise "Anonymous type definitions are not allowed!" if @idltype.is_anonymous?
2432
+ raise "Exception #{@idltype.typename} is not allowed as an attribute!" if @idltype.is_node?(IDL::AST::Exception)
2433
+
2330
2434
  if @idltype.is_local?
2331
2435
  if _enclosure.is_a?(IDL::AST::Interface) && !_enclosure.is_local?
2332
2436
  raise "Local type #{@idltype.typename} not allowed for operation on unrestricted interface"
2333
2437
  end
2334
2438
  ## IDL_Valuetype: no problem as valuetype operations are local
2335
2439
  end
2336
- if !@idltype.is_complete?
2440
+ unless @idltype.is_complete?
2337
2441
  if _enclosure.is_a?(IDL::AST::Interface)
2338
2442
  raise "Incomplete type #{@idltype.typename} not allowed here!"
2339
2443
  end
@@ -2357,8 +2461,8 @@ module IDL::AST
2357
2461
 
2358
2462
  def instantiate(instantiation_context, _enclosure)
2359
2463
  _params = {
2360
- :type => @idltype.instantiate(instantiation_context),
2361
- :readonly => @readonly
2464
+ type: @idltype.instantiate(instantiation_context),
2465
+ readonly: @readonly
2362
2466
  }
2363
2467
  _att = super(instantiation_context, _enclosure, _params)
2364
2468
  _att.get_raises = self.concrete_get_raises(instantiation_context)
@@ -2387,7 +2491,7 @@ module IDL::AST
2387
2491
  end
2388
2492
 
2389
2493
  def expanded_copy(name_pfx, enc)
2390
- att = IDL::AST::Attribute.new("#{name_pfx}_#{self.name}", enc, {:type => @idltype, :readonly => @readonly})
2494
+ att = IDL::AST::Attribute.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, readonly: @readonly})
2391
2495
  att.get_raises = @get_raises unless @get_raises.empty?
2392
2496
  att.set_raises = @set_raises unless @set_raises.empty?
2393
2497
  att
@@ -2411,42 +2515,81 @@ module IDL::AST
2411
2515
  class Struct < Node
2412
2516
  DEFINABLE = [IDL::AST::Member, IDL::AST::Struct, IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator]
2413
2517
  attr_reader :idltype
2518
+
2414
2519
  def initialize(_name, _enclosure, params)
2415
2520
  @defined = false
2416
2521
  @recursive = false
2417
2522
  @forward = params[:forward] ? true : false
2418
2523
  super(_name, _enclosure)
2419
2524
  @idltype = IDL::Type::Struct.new(self)
2525
+ @base = set_base(params[:inherits])
2526
+ end
2527
+
2528
+ def set_base(inherits)
2529
+ unless inherits.nil?
2530
+ rtc = inherits.resolved_type
2531
+ unless rtc.node.is_defined?
2532
+ raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{rtc.node.typename} #{rtc.node.scoped_lm_name}"
2533
+ end
2534
+ unless rtc.node.is_a?(IDL::AST::Struct)
2535
+ raise "#{typename} #{scoped_lm_name} cannot inherit from non structure #{rtc.node.typename} #{rtc.node.scoped_lm_name}"
2536
+ end
2537
+ inherits.node
2538
+ end
2420
2539
  end
2421
2540
 
2422
- def is_defined?; @defined end
2423
- def defined=(f); @defined = f end
2424
- def is_forward?; @forward end
2425
- def is_recursive?; @recursive end
2426
- def recursive=(f); @recursive = f end
2541
+ def base
2542
+ @base
2543
+ end
2427
2544
 
2428
- def walk_members(&block)
2429
- @children.each { |m| yield(m) if not m.is_a? IDL::AST::Member }
2545
+ def is_defined?
2546
+ @defined
2547
+ end
2548
+
2549
+ def defined=(f)
2550
+ @defined = f
2551
+ end
2552
+
2553
+ def is_forward?
2554
+ @forward
2555
+ end
2556
+
2557
+ def is_recursive?
2558
+ @recursive
2559
+ end
2560
+
2561
+ def recursive=(f)
2562
+ @recursive = f
2563
+ end
2564
+
2565
+ def walk_members
2566
+ @children.each { |m| yield(m) unless m.is_a? IDL::AST::Member }
2430
2567
  end
2431
2568
 
2432
2569
  def members
2433
2570
  @children.find_all { |c| c.is_a? IDL::AST::Member }
2434
2571
  end
2435
2572
 
2573
+ def types
2574
+ @children.reject { |c| c.is_a? IDL::AST::Member }
2575
+ end
2576
+
2436
2577
  def is_local?(recurstk = [])
2437
2578
  # not local if forward decl or recursion detected
2438
2579
  return false if is_forward? || recurstk.include?(self)
2439
- recurstk.push self # track root node to detect recursion
2580
+
2581
+ recurstk.push self # track root node to detect recursion
2440
2582
  ret = members.any? { |m| m.is_local?(recurstk) }
2441
2583
  recurstk.pop
2442
2584
  ret
2443
2585
  end
2444
2586
 
2445
2587
  def marshal_dump
2446
- super() << @idltype << @defined << @recursive << @forward
2588
+ super() << @idltype << @defined << @recursive << @forward << @base
2447
2589
  end
2448
2590
 
2449
2591
  def marshal_load(vars)
2592
+ @base = vars.pop
2450
2593
  @forward = vars.pop
2451
2594
  @recursive = vars.pop
2452
2595
  @defined = vars.pop
@@ -2456,7 +2599,7 @@ module IDL::AST
2456
2599
 
2457
2600
  def instantiate(instantiation_context, _enclosure)
2458
2601
  _params = {
2459
- :forward => @forward
2602
+ forward: @forward
2460
2603
  }
2461
2604
  _s = super(instantiation_context, _enclosure, _params)
2462
2605
  _s.defined = self.is_defined?
@@ -2465,7 +2608,7 @@ module IDL::AST
2465
2608
 
2466
2609
  protected
2467
2610
 
2468
- def walk_members_for_copy(&block)
2611
+ def walk_members_for_copy
2469
2612
  @children.each { |c| yield(c) }
2470
2613
  end
2471
2614
  end # Struct
@@ -2480,13 +2623,16 @@ module IDL::AST
2480
2623
 
2481
2624
  class Member < Leaf
2482
2625
  attr_reader :idltype
2626
+
2483
2627
  def initialize(_name, _enclosure, params)
2484
2628
  super(_name, _enclosure)
2485
- @idltype = params[:type]
2629
+ @idltype = params[:type]
2486
2630
  unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
2487
2631
  raise "Anonymous type definitions are not allowed!" if @idltype.is_anonymous?
2632
+ raise "Exception #{@idltype.typename} is not allowed as member!" if @idltype.is_node?(IDL::AST::Exception)
2633
+
2488
2634
  ## check for use of incomplete types
2489
- if !@idltype.is_complete?
2635
+ unless @idltype.is_complete?
2490
2636
  ## verify type is used in sequence
2491
2637
  if @idltype.resolved_type.is_a? IDL::Type::Sequence
2492
2638
  ## find the (non-sequence) elementtype
@@ -2500,7 +2646,7 @@ module IDL::AST
2500
2646
  if mtype.is_a? IDL::Type::ScopedName
2501
2647
  case mtype.resolved_type
2502
2648
  when IDL::Type::Struct, IDL::Type::Union, IDL::Type::Valuetype
2503
- if !mtype.node.is_defined?
2649
+ unless mtype.node.is_defined?
2504
2650
  ## check if incomplete struct/union is contained within definition of self
2505
2651
  enc = _enclosure
2506
2652
  while enc.is_a?(IDL::AST::Struct) || enc.is_a?(IDL::AST::Union) || enc.is_a?(IDL::AST::Valuetype)
@@ -2538,7 +2684,7 @@ module IDL::AST
2538
2684
 
2539
2685
  def instantiate(instantiation_context, _enclosure, _params = {})
2540
2686
  _params.merge!({
2541
- :type => @idltype.instantiate(instantiation_context),
2687
+ type: @idltype.instantiate(instantiation_context)
2542
2688
  })
2543
2689
  super(instantiation_context, _enclosure, _params)
2544
2690
  end
@@ -2548,6 +2694,7 @@ module IDL::AST
2548
2694
  DEFINABLE = [IDL::AST::UnionMember, IDL::AST::Struct, IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator]
2549
2695
  attr_reader :idltype
2550
2696
  attr_accessor :switchtype
2697
+
2551
2698
  def initialize(_name, _enclosure, params)
2552
2699
  @defined = false
2553
2700
  @recursive = false
@@ -2561,24 +2708,43 @@ module IDL::AST
2561
2708
  @switchtype = _switchtype
2562
2709
  end
2563
2710
 
2564
- def is_defined?; @defined; end
2565
- def defined=(f); @defined = f; end
2566
- def is_forward?; @forward; end
2567
- def is_recursive?; @recursive end
2568
- def recursive=(f); @recursive = f end
2711
+ def is_defined?
2712
+ @defined
2713
+ end
2569
2714
 
2570
- def walk_members(&block)
2571
- @children.each { |m| yield(m) if not m.is_a? IDL::AST::UnionMember }
2715
+ def defined=(f)
2716
+ @defined = f
2717
+ end
2718
+
2719
+ def is_forward?
2720
+ @forward
2721
+ end
2722
+
2723
+ def is_recursive?
2724
+ @recursive
2725
+ end
2726
+
2727
+ def recursive=(f)
2728
+ @recursive = f
2729
+ end
2730
+
2731
+ def walk_members
2732
+ @children.each { |m| yield(m) unless m.is_a? IDL::AST::UnionMember }
2572
2733
  end
2573
2734
 
2574
2735
  def members
2575
2736
  @children.find_all { |c| c.is_a? IDL::AST::UnionMember }
2576
2737
  end
2577
2738
 
2739
+ def types
2740
+ @children.reject { |c| c.is_a? IDL::AST::UnionMember }
2741
+ end
2742
+
2578
2743
  def is_local?(recurstk = [])
2579
2744
  # not local if forward decl or recursion detected
2580
2745
  return false if is_forward? || recurstk.include?(self)
2581
- recurstk.push self # track root node to detect recursion
2746
+
2747
+ recurstk.push self # track root node to detect recursion
2582
2748
  ret = members.any? { |m| m.is_local?(recurstk) }
2583
2749
  recurstk.pop
2584
2750
  ret
@@ -2590,12 +2756,14 @@ module IDL::AST
2590
2756
 
2591
2757
  def default_label
2592
2758
  swtype = @switchtype.resolved_type
2759
+ return nil if IDL::Type::WChar === swtype # No default label detection for wchar
2593
2760
  lbls = members.collect { |m| m.labels.include?(:default) ? [] : m.labels.collect { |l| l.value } }.flatten
2594
2761
  lbls = lbls.sort unless IDL::Type::Boolean === swtype ## work around bug in Ruby 1.9.2
2595
2762
  def_lbl = swtype.min
2596
2763
  while swtype.in_range?(def_lbl)
2597
2764
  return IDL::Expression::Value.new(@switchtype, def_lbl) unless lbls.include?(def_lbl)
2598
2765
  return nil if def_lbl == swtype.max
2766
+
2599
2767
  def_lbl = swtype.next(def_lbl)
2600
2768
  end
2601
2769
  nil
@@ -2603,6 +2771,7 @@ module IDL::AST
2603
2771
 
2604
2772
  def validate_labels
2605
2773
  return if self.is_template?
2774
+
2606
2775
  labelvals = []
2607
2776
  default_ = false
2608
2777
  members.each { |m|
@@ -2610,14 +2779,16 @@ module IDL::AST
2610
2779
  m.labels.each { |lbl|
2611
2780
  if lbl == :default
2612
2781
  raise "duplicate case label 'default' for #{typename} #{lm_name}" if default_
2782
+
2613
2783
  default_ = true
2614
2784
  else
2615
2785
  # correct type
2616
2786
  lv = @switchtype.resolved_type.narrow(lbl.value)
2617
2787
  # doubles
2618
2788
  if labelvals.include? lv
2619
- raise "duplicate case label #{lv.to_s} for #{typename} #{lm_name}"
2789
+ raise "duplicate case label #{lv} for #{typename} #{lm_name}"
2620
2790
  end
2791
+
2621
2792
  labelvals << lv
2622
2793
  end
2623
2794
  }
@@ -2645,7 +2816,7 @@ module IDL::AST
2645
2816
 
2646
2817
  def instantiate(instantiation_context, _enclosure)
2647
2818
  _params = {
2648
- :forward => @forward
2819
+ forward: @forward
2649
2820
  }
2650
2821
  _u = super(instantiation_context, _enclosure, _params)
2651
2822
  _u.set_switchtype(@switchtype.instantiate(instantiation_context))
@@ -2656,20 +2827,21 @@ module IDL::AST
2656
2827
 
2657
2828
  protected
2658
2829
 
2659
- def walk_members_for_copy(&block)
2830
+ def walk_members_for_copy
2660
2831
  @children.each { |c| yield(c) }
2661
2832
  end
2662
2833
  end # Union
2663
2834
 
2664
2835
  class UnionMember < Member
2665
2836
  attr_reader :labels
2837
+
2666
2838
  def initialize(_name, _enclosure, params)
2667
2839
  super(_name, _enclosure, params)
2668
2840
  ## if any of the labels is 'default' forget about the others
2669
2841
  if params[:labels].include?(:default)
2670
- @labels = [ :default ]
2842
+ @labels = [:default]
2671
2843
  else
2672
- @labels = params[:labels]
2844
+ @labels = params[:labels]
2673
2845
  end
2674
2846
  end
2675
2847
 
@@ -2684,26 +2856,32 @@ module IDL::AST
2684
2856
 
2685
2857
  def instantiate(instantiation_context, _enclosure)
2686
2858
  _params = {
2687
- :labels => @labels.collect { |l| l == :default ? l : l.instantiate(instantiation_context) },
2859
+ labels: @labels.collect { |l| l == :default ? l : l.instantiate(instantiation_context) }
2688
2860
  }
2689
2861
  super(instantiation_context, _enclosure, _params)
2690
2862
  end
2691
2863
  end # UnionMember
2692
2864
 
2693
2865
  class Enum < Leaf
2694
- attr_reader :idltype
2695
- def initialize(_name, _enclosure, params)
2696
- super(_name, _enclosure)
2866
+ attr_reader :idltype, :bitbound, :bitbound_bits
2867
+
2868
+ def initialize(_name, enclosure, params)
2869
+ super(_name, enclosure)
2697
2870
  @enums = []
2698
2871
  @idltype = IDL::Type::Enum.new(self)
2872
+ @bitbound = IDL::Type::ULong.new
2873
+ @bitbound_bits = 32
2874
+ annotations.concat(params[:annotations])
2699
2875
  end
2700
2876
 
2701
2877
  def marshal_dump
2702
- super() << @idltype << @enums
2878
+ super() << @idltype << @bitbound << @bitbound_bits << @enums
2703
2879
  end
2704
2880
 
2705
2881
  def marshal_load(vars)
2706
2882
  @enums = vars.pop
2883
+ @bitbound = vars.pop
2884
+ @bitbound_bits = vars.pop
2707
2885
  @idltype = vars.pop
2708
2886
  super(vars)
2709
2887
  end
@@ -2716,14 +2894,27 @@ module IDL::AST
2716
2894
  @enums << n
2717
2895
  end
2718
2896
 
2897
+ def determine_bitbound
2898
+ bitbound = annotations[:bit_bound].first
2899
+ unless bitbound.nil?
2900
+ @bitbound_bits = bitbound.fields[:value]
2901
+ raise "Missing number of bits for bit_bound annotation for #{name}" if @bitbound_bits.nil?
2902
+ raise "Illegal negative bit_bound #{bits} value for #{name}" if @bitbound_bits.negative?
2903
+ raise "Illegal zero bit_bound value for #{name}, not #{bits}" if @bitbound_bits.zero?
2904
+ raise "Bitbound for #{name} must be <= 32" unless @bitbound_bits <= 32
2905
+ end
2906
+ @bitbound = IDL::Type::UTinyShort.new if @bitbound_bits.between?(1,8)
2907
+ @bitbound = IDL::Type::UShort.new if @bitbound_bits.between?(9,16)
2908
+ end
2909
+
2719
2910
  def instantiate(instantiation_context, _enclosure)
2720
2911
  super(instantiation_context, _enclosure, {})
2721
2912
  end
2722
-
2723
2913
  end # Enum
2724
2914
 
2725
2915
  class Enumerator < Leaf
2726
2916
  attr_reader :idltype, :enum, :value
2917
+
2727
2918
  def initialize(_name, _enclosure, params)
2728
2919
  super(_name, _enclosure)
2729
2920
  @idltype = IDL::Type::ULong.new
@@ -2747,15 +2938,241 @@ module IDL::AST
2747
2938
  # find already instantiated Enum parent
2748
2939
  _enum = _enclosure.resolve(@enum.name)
2749
2940
  raise "Unable to resolve instantiated Enum scope for enumerator #{@enum.name}::#{name} instantiation" unless _enum
2750
- super(instantiation_context, _enclosure, { :enum => _enum, :value => @value })
2941
+
2942
+ super(instantiation_context, _enclosure, { enum: _enum, value: @value })
2751
2943
  end
2752
2944
  end # Enumerator
2753
2945
 
2754
- class Typedef < Leaf
2946
+ class BitMask < Node
2947
+ DEFINABLE = [IDL::AST::BitValue]
2948
+ attr_reader :idltype, :bitbound, :bitbound_bits
2949
+
2950
+ def initialize(name, enclosure, params)
2951
+ super(name, enclosure)
2952
+ @bitvalues = []
2953
+ @idltype = IDL::Type::BitMask.new(self)
2954
+ annotations.concat(params[:annotations])
2955
+ end
2956
+
2957
+ def marshal_dump
2958
+ super() << @idltype << @bitbound << @bitbound_bits << @bitvalues
2959
+ end
2960
+
2961
+ def marshal_load(vars)
2962
+ @bitvalues = vars.pop
2963
+ @bitbound_bits = vars.pop
2964
+ @bitbound = vars.pop
2965
+ @idltype = vars.pop
2966
+ super(vars)
2967
+ end
2968
+
2969
+ def bitvalues
2970
+ @bitvalues
2971
+ end
2972
+
2973
+ def add_bitvalue(n)
2974
+ @bitvalues << n
2975
+ end
2976
+
2977
+ def determine_bitbound
2978
+ bitbound = annotations[:bit_bound].first
2979
+ @bitbound_bits = @bitvalues.size
2980
+ unless bitbound.nil?
2981
+ @bitbound_bits = bitbound.fields[:value]
2982
+ raise "Missing number of bits for bit_bound annotation for #{name}" if @bitbound_bits.nil?
2983
+ raise "Illegal negative bit_bound #{bits} value for #{name}" if @bitbound_bits.negative?
2984
+ raise "Illegal zero bit_bound value for #{name}, not #{bits}" if @bitbound_bits.zero?
2985
+ raise "Bitbound for #{name} must be <= 64" unless @bitbound_bits <= 64
2986
+ end
2987
+ @bitbound = IDL::Type::UTinyShort.new if @bitbound_bits.between?(1,8)
2988
+ @bitbound = IDL::Type::UShort.new if @bitbound_bits.between?(9,16)
2989
+ @bitbound = IDL::Type::ULong.new if @bitbound_bits.between?(17,32)
2990
+ @bitbound = IDL::Type::ULongLong.new if @bitbound_bits.between?(33,64)
2991
+ end
2992
+
2993
+ def instantiate(instantiation_context, _enclosure)
2994
+ super(instantiation_context, _enclosure, {})
2995
+ end
2996
+ end # BitMask
2997
+
2998
+ class BitValue < Leaf
2999
+ attr_reader :idltype, :bitmask, :position
3000
+
3001
+ def initialize(name, enclosure, params)
3002
+ super(name, enclosure)
3003
+ @idltype = IDL::Type::ULong.new
3004
+ @bitmask = params[:bitmask]
3005
+ @position = params[:position]
3006
+ annotations.concat(params[:annotations])
3007
+ position_annotation = annotations[:position].first
3008
+ unless position_annotation.nil?
3009
+ @position = position_annotation.fields[:value]
3010
+ end
3011
+ @bitmask.add_bitvalue(self)
3012
+ end
3013
+
3014
+ def marshal_dump
3015
+ super() << @idltype << @bitmask << @position
3016
+ end
3017
+
3018
+ def marshal_load(vars)
3019
+ @position = vars.pop
3020
+ @bitmask = vars.pop
3021
+ @idltype = vars.pop
3022
+ super(vars)
3023
+ end
3024
+
3025
+ def instantiate(instantiation_context, _enclosure)
3026
+ # find already instantiated BitMask parent
3027
+ _bitmask = _enclosure.resolve(@bitmask.name)
3028
+ raise "Unable to resolve instantiated BitMask scope for bitvalue #{@bitmask.name}::#{name} instantiation" unless _bitmask
3029
+
3030
+ super(instantiation_context, _enclosure, { bitmask: _bitmask, position: @position })
3031
+ end
3032
+ end # BitValue
3033
+
3034
+ class BitSet < Node
3035
+ DEFINABLE = [IDL::AST::BitField]
2755
3036
  attr_reader :idltype
3037
+
3038
+ def initialize(_name, enclosure, params)
3039
+ super(_name, enclosure)
3040
+ @bitfields = []
3041
+ @bitset_bits = 0
3042
+ @idltype = IDL::Type::BitSet.new(self)
3043
+ @base = set_base(params[:inherits])
3044
+ end
3045
+
3046
+ def set_base(inherits)
3047
+ unless inherits.nil?
3048
+ rtc = inherits.resolved_type
3049
+ unless rtc.node.is_a?(IDL::AST::BitSet)
3050
+ raise "#{typename} #{scoped_lm_name} cannot inherit from non bitset #{rtc.node.typename} #{rtc.node.scoped_lm_name}"
3051
+ end
3052
+ inherits.node
3053
+ end
3054
+ end
3055
+
3056
+ def base
3057
+ @base
3058
+ end
3059
+
3060
+ # Override from Node base to handle anonymous bitfields
3061
+ def define(_type, _name, params = {})
3062
+ unless is_definable?(_type)
3063
+ raise "#{_type} is not definable in #{self.typename}."
3064
+ end
3065
+
3066
+ # All IDL definables have a name except a bitfield, that has an optional name and can
3067
+ # be anonymous
3068
+ node = search_self(_name) unless _name.nil?
3069
+ if node.nil?
3070
+ node = _type.new(_name, self, params)
3071
+ node.annotations.concat(params[:annotations])
3072
+ node.prefix = @prefix
3073
+ introduce(node) unless _name.nil? # If there is no name don't introduce it in our scope
3074
+ @children << node
3075
+ else
3076
+ if _type != node.class
3077
+ raise "#{_name} is already defined as a type of #{node.typename}"
3078
+ end
3079
+
3080
+ node = redefine(node, params)
3081
+ end
3082
+ node
3083
+ end
3084
+
3085
+ def marshal_dump
3086
+ super() << @idltype << @bitset_bits << @bitfields << @base
3087
+ end
3088
+
3089
+ def marshal_load(vars)
3090
+ @base = vars.pop
3091
+ @bitfields = vars.pop
3092
+ @bitset_bits = vars.pop
3093
+ @idltype = vars.pop
3094
+ super(vars)
3095
+ end
3096
+
3097
+ # Total number of bits in this bitset including the optional base
3098
+ def bitset_bits
3099
+ base.nil? ? @bitset_bits : @bitset_bits + base.bitset_bits
3100
+ end
3101
+
3102
+ # Underlying type which is large enough to contain the full bitset
3103
+ # including its base
3104
+ def underlying_type
3105
+ return IDL::Type::UTinyShort.new if bitset_bits.between?(1,8)
3106
+ return IDL::Type::UShort.new if bitset_bits.between?(9,16)
3107
+ return IDL::Type::ULong.new if bitset_bits.between?(17,32)
3108
+ return IDL::Type::ULongLong.new if bitset_bits.between?(33,64)
3109
+ end
3110
+
3111
+ def bitfields
3112
+ @bitfields
3113
+ end
3114
+
3115
+ def add_bitfield(n)
3116
+ @bitfields << n
3117
+ @bitset_bits += n.bits
3118
+ raise "Bitset size #{bitset_bits} must be between 1 and 64" unless bitset_bits.between?(1, 64)
3119
+ end
3120
+
3121
+ def instantiate(instantiation_context, _enclosure)
3122
+ super(instantiation_context, _enclosure, {})
3123
+ end
3124
+ end # BitSet
3125
+
3126
+ class BitField < Leaf
3127
+ attr_reader :idltype, :bitset, :bits
3128
+
2756
3129
  def initialize(_name, _enclosure, params)
2757
3130
  super(_name, _enclosure)
2758
- @idltype = params[:type]
3131
+ @idltype = params[:idltype]
3132
+ @bitset = params[:bitset]
3133
+ @bits = params[:bits]
3134
+
3135
+ raise "Amount of bits for bitfield #{_name} must <= 64, not #{bits}" if bits > 64
3136
+
3137
+ # When no IDL type has been specified for the bitfield in IDL we need to determine
3138
+ # the underlying type based on the number of bits
3139
+ if @idltype.nil?
3140
+ @idltype = IDL::Type::Boolean.new if bits == 1
3141
+ @idltype = IDL::Type::TinyShort.new if bits.between?(2,8)
3142
+ @idltype = IDL::Type::Short.new if bits.between?(9,16)
3143
+ @idltype = IDL::Type::Long.new if bits.between?(17,32)
3144
+ @idltype = IDL::Type::LongLong.new if bits.between?(33,64)
3145
+ end
3146
+ @bitset.add_bitfield(self)
3147
+ end
3148
+
3149
+ def marshal_dump
3150
+ super() << @idltype << @bits << @bitset << @value
3151
+ end
3152
+
3153
+ def marshal_load(vars)
3154
+ @value = vars.pop
3155
+ @bitset = vars.pop
3156
+ @bits = vars.pop
3157
+ @idltype = vars.pop
3158
+ super(vars)
3159
+ end
3160
+
3161
+ def instantiate(instantiation_context, _enclosure)
3162
+ # find already instantiated BitSet parent
3163
+ _bitmask = _enclosure.resolve(@bitset.name)
3164
+ raise "Unable to resolve instantiated BitSet scope for bitfield #{@bitset.name}::#{name} instantiation" unless _bitset
3165
+
3166
+ super(instantiation_context, _enclosure, { bitset: _bitset, bits: @bits })
3167
+ end
3168
+ end # BitField
3169
+
3170
+ class Typedef < Leaf
3171
+ attr_reader :idltype
3172
+
3173
+ def initialize(_name, enclosure, params)
3174
+ super(_name, enclosure)
3175
+ @idltype = params[:type]
2759
3176
  end
2760
3177
 
2761
3178
  def is_local?(recurstk = [])
@@ -2772,7 +3189,7 @@ module IDL::AST
2772
3189
  end
2773
3190
 
2774
3191
  def instantiate(instantiation_context, _enclosure)
2775
- super(instantiation_context, _enclosure, { :type => @idltype.instantiate(instantiation_context) })
3192
+ super(instantiation_context, _enclosure, { type: @idltype.instantiate(instantiation_context) })
2776
3193
  end
2777
3194
  end # Typedef
2778
3195
  end