ridl 2.8.1 → 2.9.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.
- checksums.yaml +4 -4
- data/README.rdoc +9 -3
- data/lib/ridl/backend.rb +11 -12
- data/lib/ridl/delegate.rb +89 -59
- data/lib/ridl/expression.rb +65 -27
- data/lib/ridl/genfile.rb +22 -16
- data/lib/ridl/node.rb +328 -189
- data/lib/ridl/options.rb +9 -11
- data/lib/ridl/optparse_ext.rb +32 -34
- data/lib/ridl/parser.rb +456 -236
- data/lib/ridl/runner.rb +33 -26
- data/lib/ridl/scanner.rb +171 -141
- data/lib/ridl/type.rb +113 -13
- data/lib/ridl/version.rb +2 -4
- metadata +4 -4
data/lib/ridl/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 =
|
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,
|
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 =
|
275
|
-
|
270
|
+
def define(_type, _name, params = {})
|
271
|
+
unless is_definable?(_type)
|
276
272
|
raise "#{_type.to_s} 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
|
|
@@ -391,6 +390,7 @@ module IDL::AST
|
|
391
390
|
IDL::AST::Home, IDL::AST::Porttype, IDL::AST::Component, IDL::AST::Connector
|
392
391
|
]
|
393
392
|
attr_reader :anchor, :next, :template, :template_params
|
393
|
+
|
394
394
|
def initialize(_name, _enclosure, params)
|
395
395
|
super(_name, _enclosure)
|
396
396
|
@anchor = params[:anchor]
|
@@ -410,6 +410,7 @@ module IDL::AST
|
|
410
410
|
|
411
411
|
def template_param(param)
|
412
412
|
return nil unless @template
|
413
|
+
|
413
414
|
param = param.to_s if ::Symbol === param
|
414
415
|
if ::String === param
|
415
416
|
@template.params.each_with_index do |tp, ix|
|
@@ -455,7 +456,7 @@ module IDL::AST
|
|
455
456
|
_anchor = node.has_anchor? ? node.anchor : node
|
456
457
|
_anchor.annotations.concat(params.delete(:annotations))
|
457
458
|
_last = _anchor.find_last
|
458
|
-
_params = params.merge({ :
|
459
|
+
_params = params.merge({ anchor: _anchor, prefix: node.prefix })
|
459
460
|
_next = IDL::AST::Module.new(node.name, self, _params)
|
460
461
|
_last.set_next(_next)
|
461
462
|
@children << _next
|
@@ -548,7 +549,7 @@ module IDL::AST
|
|
548
549
|
end
|
549
550
|
|
550
551
|
def replace_prefix(pfx)
|
551
|
-
self.prefix = pfx
|
552
|
+
self.prefix = pfx # handles validation
|
552
553
|
if @anchor.nil?
|
553
554
|
self.replace_prefix_i(pfx)
|
554
555
|
else
|
@@ -578,6 +579,7 @@ module IDL::AST
|
|
578
579
|
cp = IDL::AST::TemplateParam.concrete_param(instantiation_context, _template.anchor)
|
579
580
|
# concrete param must be a IDL::Type::NodeType and it's node a Module (should never fail)
|
580
581
|
raise "Invalid concrete anchor found" unless cp.is_a?(IDL::Type::NodeType) && cp.node.is_a?(IDL::AST::Module)
|
582
|
+
|
581
583
|
@anchor = cp.node
|
582
584
|
# link our self into module chain
|
583
585
|
@anchor.find_last.set_next(self)
|
@@ -608,6 +610,7 @@ module IDL::AST
|
|
608
610
|
if not node.nil? and node.name != _name
|
609
611
|
raise "\"#{_name}\" clashed with \"#{node.name}\"."
|
610
612
|
end
|
613
|
+
|
611
614
|
if node.nil? && @next
|
612
615
|
node = @next.search_links(_name)
|
613
616
|
end
|
@@ -633,6 +636,7 @@ module IDL::AST
|
|
633
636
|
|
634
637
|
class TemplateParam < Leaf
|
635
638
|
attr_reader :idltype, :concrete
|
639
|
+
|
636
640
|
def initialize(_name, _enclosure, params)
|
637
641
|
super(_name, _enclosure)
|
638
642
|
@idltype = params[:type]
|
@@ -667,7 +671,7 @@ module IDL::AST
|
|
667
671
|
def self.concrete_param(instantiation_context, tpl_elem)
|
668
672
|
# is this an element from the template's scope
|
669
673
|
if tpl_elem.is_template?
|
670
|
-
celem = if tpl_elem.is_a?(IDL::AST::TemplateParam)
|
674
|
+
celem = if tpl_elem.is_a?(IDL::AST::TemplateParam) # an actual template parameter?
|
671
675
|
tpl_elem.concrete # get the template parameter's concrete (instantiation argument) value
|
672
676
|
else
|
673
677
|
# referenced template elements should have been instantiated already and available through context
|
@@ -677,6 +681,7 @@ module IDL::AST
|
|
677
681
|
ctxelem.is_a?(IDL::AST::Const) ? ctxelem.expression : ctxelem.idltype
|
678
682
|
end
|
679
683
|
raise "cannot resolve concrete node for template #{tpl_elem.typename} #{tpl_elem.scoped_lm_name}" unless celem
|
684
|
+
|
680
685
|
celem
|
681
686
|
else
|
682
687
|
tpl_elem.idltype # just return the element's idltype if not from the template scope
|
@@ -692,6 +697,7 @@ module IDL::AST
|
|
692
697
|
IDL::AST::TemplateParam, IDL::AST::TemplateModuleReference
|
693
698
|
]
|
694
699
|
attr_reader :idltype
|
700
|
+
|
695
701
|
def initialize(_name, _enclosure, _params)
|
696
702
|
super(_name, _enclosure, {})
|
697
703
|
@idltype = IDL::Type::TemplateModule.new(self)
|
@@ -716,6 +722,7 @@ module IDL::AST
|
|
716
722
|
# process concrete parameters
|
717
723
|
@template_params.each_with_index do |_tp, _ix|
|
718
724
|
raise "missing template parameter for #{typename} #{scoped_lm_name}: #{_tp.name}" unless _ix < _module_instance.template_params.size
|
725
|
+
|
719
726
|
_cp = _module_instance.template_params[_ix]
|
720
727
|
if _cp.is_a?(IDL::Type)
|
721
728
|
raise "anonymous type definitions are not allowed!" if _cp.is_anonymous?
|
@@ -723,6 +730,7 @@ module IDL::AST
|
|
723
730
|
unless _tp.idltype.is_a?(IDL::Type::Any) || _tp.idltype.class === _cp.resolved_type
|
724
731
|
raise "mismatched instantiation parameter \##{_ix} #{_cp.typename} for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}"
|
725
732
|
end
|
733
|
+
|
726
734
|
# verify concrete parameter
|
727
735
|
case _tp.idltype
|
728
736
|
when IDL::Type::Any # 'typename'
|
@@ -737,7 +745,7 @@ module IDL::AST
|
|
737
745
|
# no further checks
|
738
746
|
when IDL::Type::Sequence # 'sequence' or 'sequence<...>'
|
739
747
|
_tptype = _tp.idltype
|
740
|
-
unless _tptype.basetype.is_a?(IDL::Type::Void)
|
748
|
+
unless _tptype.basetype.is_a?(IDL::Type::Void) # 'sequence'
|
741
749
|
# check basetype
|
742
750
|
unless _tptype.basetype.is_a?(IDL::Type::ScopedName) &&
|
743
751
|
_tptype.basetype.is_node?(IDL::AST::TemplateParam) &&
|
@@ -751,6 +759,7 @@ module IDL::AST
|
|
751
759
|
unless _tp.idltype.is_a?(IDL::Type::Const)
|
752
760
|
raise "unexpected expression as instantiation parameter for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}"
|
753
761
|
end
|
762
|
+
|
754
763
|
# match constant type
|
755
764
|
_tp.idltype.narrow(_cp.value)
|
756
765
|
else
|
@@ -765,7 +774,7 @@ module IDL::AST
|
|
765
774
|
|
766
775
|
protected
|
767
776
|
|
768
|
-
def walk_members_for_copy
|
777
|
+
def walk_members_for_copy
|
769
778
|
@children.each { |c| yield(c) unless c.is_a?(IDL::AST::TemplateParam) }
|
770
779
|
end
|
771
780
|
end # TemplateModule
|
@@ -776,6 +785,7 @@ module IDL::AST
|
|
776
785
|
unless _params[:tpl_type].is_a?(IDL::Type::ScopedName) && _params[:tpl_type].is_node?(IDL::AST::TemplateModule)
|
777
786
|
raise "templated module reference type required for #{typename} #{scoped_lm_name}: got #{_params[:tpl_type].typename}"
|
778
787
|
end
|
788
|
+
|
779
789
|
@template = _params[:tpl_type].resolved_type.node
|
780
790
|
_params[:tpl_params].each do |p|
|
781
791
|
unless (p.is_a?(IDL::Type::ScopedName) || p.is_a?(IDL::Expression::ScopedName)) && p.is_node?(IDL::AST::TemplateParam)
|
@@ -800,7 +810,7 @@ module IDL::AST
|
|
800
810
|
# concrete objects are either Expression or Type
|
801
811
|
tp.concrete
|
802
812
|
end
|
803
|
-
mod_inst = IDL::AST::Module.new(self.name, _enclosure, { :
|
813
|
+
mod_inst = IDL::AST::Module.new(self.name, _enclosure, { template: @template, template_params: inst_params })
|
804
814
|
@template.instantiate(mod_inst, instantiation_context)
|
805
815
|
mod_inst
|
806
816
|
end
|
@@ -812,15 +822,16 @@ module IDL::AST
|
|
812
822
|
|
813
823
|
class Include < Module
|
814
824
|
attr_reader :filename, :fullpath
|
825
|
+
|
815
826
|
def initialize(_name, _enclosure, params)
|
816
827
|
super(_name, _enclosure, params)
|
817
828
|
@filename = params[:filename]
|
818
829
|
@fullpath = params[:fullpath]
|
819
830
|
@defined = params[:defined] || false
|
820
831
|
@preprocessed = params[:preprocessed] || false
|
821
|
-
#overrule
|
832
|
+
# overrule
|
822
833
|
@scopes = @enclosure.scopes
|
823
|
-
@scoped_name = @scopes.collect{|s| s.name}.join("::")
|
834
|
+
@scoped_name = @scopes.collect { |s| s.name }.join("::")
|
824
835
|
end
|
825
836
|
|
826
837
|
def lm_scopes
|
@@ -836,13 +847,18 @@ module IDL::AST
|
|
836
847
|
@defined = vars.pop
|
837
848
|
@filename = vars.pop
|
838
849
|
super(vars)
|
839
|
-
#overrule
|
850
|
+
# overrule
|
840
851
|
@scopes = @enclosure.scopes || []
|
841
|
-
@scoped_name = @scopes.collect{|s| s.name}.join("::")
|
852
|
+
@scoped_name = @scopes.collect { |s| s.name }.join("::")
|
842
853
|
end
|
843
854
|
|
844
|
-
def is_defined
|
845
|
-
|
855
|
+
def is_defined?
|
856
|
+
@defined
|
857
|
+
end
|
858
|
+
|
859
|
+
def is_preprocessed?
|
860
|
+
@preprocessed
|
861
|
+
end
|
846
862
|
|
847
863
|
def introduce(node)
|
848
864
|
@enclosure.introduce(node) unless node == self
|
@@ -862,9 +878,9 @@ module IDL::AST
|
|
862
878
|
@filename = _template.filename
|
863
879
|
@defined = _template.is_defined?
|
864
880
|
@preprocessed = _template.is_preprocessed?
|
865
|
-
#overrule
|
881
|
+
# overrule
|
866
882
|
@scopes = @enclosure.scopes
|
867
|
-
@scoped_name = @scopes.collect{|s| s.name}.join("::")
|
883
|
+
@scoped_name = @scopes.collect { |s| s.name }.join("::")
|
868
884
|
self
|
869
885
|
end
|
870
886
|
|
@@ -874,7 +890,6 @@ module IDL::AST
|
|
874
890
|
end # Include
|
875
891
|
|
876
892
|
class Derivable < Node
|
877
|
-
|
878
893
|
alias :search_self_before_derived :search_self
|
879
894
|
def search_self(_name)
|
880
895
|
node = search_self_before_derived(_name)
|
@@ -895,6 +910,7 @@ module IDL::AST
|
|
895
910
|
def each_ancestors(visited = [], &block)
|
896
911
|
resolved_bases.each do |p|
|
897
912
|
next if visited.include? p
|
913
|
+
|
898
914
|
yield(p)
|
899
915
|
visited.push p
|
900
916
|
p.each_ancestors(visited, &block)
|
@@ -911,8 +927,9 @@ module IDL::AST
|
|
911
927
|
if results.size > 1
|
912
928
|
# check if the matched name resulted in multiple different nodes or all the same
|
913
929
|
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)
|
930
|
+
unless results.all? { |r| r_one == r || (r_one.class == r.class && r_one.scoped_name == r.scoped_name) }
|
931
|
+
s = results.inject([r_one]) { |l, r| l << r unless l.include?(r)
|
932
|
+
l }.collect { |n| n.scoped_name }.join(", ")
|
916
933
|
raise "\"#{_name}\" is ambiguous. " + s
|
917
934
|
end
|
918
935
|
end
|
@@ -945,8 +962,7 @@ module IDL::AST
|
|
945
962
|
class Interface < Derivable
|
946
963
|
DEFINABLE = [IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute,
|
947
964
|
IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
|
948
|
-
attr_reader :bases
|
949
|
-
attr_reader :idltype
|
965
|
+
attr_reader :bases, :idltype
|
950
966
|
|
951
967
|
def initialize(_name, _enclosure, params)
|
952
968
|
super(_name, _enclosure)
|
@@ -977,22 +993,36 @@ module IDL::AST
|
|
977
993
|
|
978
994
|
def instantiate(instantiation_context, _enclosure)
|
979
995
|
_params = {
|
980
|
-
:
|
981
|
-
:
|
982
|
-
:
|
983
|
-
:
|
984
|
-
:
|
996
|
+
forward: self.is_forward?,
|
997
|
+
abstract: self.is_abstract?,
|
998
|
+
pseudo: self.is_pseudo?,
|
999
|
+
local: self.is_local?,
|
1000
|
+
inherits: self.concrete_bases(instantiation_context)
|
985
1001
|
}
|
986
1002
|
# instantiate concrete interface def and validate
|
987
1003
|
# concrete bases
|
988
1004
|
super(instantiation_context, _enclosure, _params)
|
989
1005
|
end
|
990
1006
|
|
991
|
-
def is_abstract
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
def
|
1007
|
+
def is_abstract?
|
1008
|
+
@abstract
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
def is_local?
|
1012
|
+
@local
|
1013
|
+
end
|
1014
|
+
|
1015
|
+
def is_pseudo?
|
1016
|
+
@pseudo
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
def is_defined?
|
1020
|
+
@defined
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
def is_forward?
|
1024
|
+
not @defined
|
1025
|
+
end
|
996
1026
|
|
997
1027
|
def add_bases(inherits_)
|
998
1028
|
inherits_.each do |tc|
|
@@ -1000,11 +1030,12 @@ module IDL::AST
|
|
1000
1030
|
unless (tc.is_a?(IDL::Type::NodeType) && tc.is_node?(IDL::AST::Interface))
|
1001
1031
|
raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
|
1002
1032
|
end
|
1033
|
+
|
1003
1034
|
rtc = tc.resolved_type
|
1004
1035
|
if rtc.node.has_ancestor?(self)
|
1005
1036
|
raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{tc.node.scoped_lm_name} is descendant"
|
1006
1037
|
end
|
1007
|
-
|
1038
|
+
unless rtc.node.is_defined?
|
1008
1039
|
raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
|
1009
1040
|
end
|
1010
1041
|
if rtc.node.is_local? and not self.is_local?
|
@@ -1022,6 +1053,7 @@ module IDL::AST
|
|
1022
1053
|
if self.has_base?(rtc.node)
|
1023
1054
|
raise "#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
|
1024
1055
|
end
|
1056
|
+
|
1025
1057
|
# check if we indirectly derive from this base multiple times (which is ok; no further need to check)
|
1026
1058
|
unless @resolved_bases.any? { |b| b.has_ancestor?(rtc.node) }
|
1027
1059
|
# this is a new base so we need to check for member redefinition/ambiguity
|
@@ -1029,7 +1061,8 @@ module IDL::AST
|
|
1029
1061
|
rtc.node.walk_members do |m|
|
1030
1062
|
new_op_att_ << m if m.is_a?(IDL::AST::Operation) || m.is_a?(IDL::AST::Attribute)
|
1031
1063
|
end
|
1032
|
-
if new_op_att_.any? {|n| n_ = self.search_self(n.name)
|
1064
|
+
if new_op_att_.any? { |n| n_ = self.search_self(n.name)
|
1065
|
+
n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
|
1033
1066
|
raise "#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} because of duplicated operations/attributes"
|
1034
1067
|
end
|
1035
1068
|
# no need to check for duplicate member names; this inheritance is ok
|
@@ -1048,13 +1081,13 @@ module IDL::AST
|
|
1048
1081
|
@resolved_bases
|
1049
1082
|
end
|
1050
1083
|
|
1051
|
-
def operations(include_bases=false, traversed=nil)
|
1084
|
+
def operations(include_bases = false, traversed = nil)
|
1052
1085
|
ops = @children.find_all { |c| c.is_a?(IDL::AST::Operation) }
|
1053
1086
|
ops.concat(base_operations(traversed || [])) if include_bases
|
1054
1087
|
ops
|
1055
1088
|
end
|
1056
1089
|
|
1057
|
-
def attributes(include_bases=false, traversed=nil)
|
1090
|
+
def attributes(include_bases = false, traversed = nil)
|
1058
1091
|
atts = @children.find_all { |c| c.is_a?(IDL::AST::Attribute) }
|
1059
1092
|
atts.concat(base_attributes(traversed || [])) if include_bases
|
1060
1093
|
atts
|
@@ -1067,6 +1100,7 @@ module IDL::AST
|
|
1067
1100
|
if node.is_defined?
|
1068
1101
|
raise "#{node.typename} \"#{node.name}\" is already defined."
|
1069
1102
|
end
|
1103
|
+
|
1070
1104
|
node.annotations.concat(params[:annotations])
|
1071
1105
|
|
1072
1106
|
_new_node = node.class.new(node.name, self, params)
|
@@ -1095,7 +1129,7 @@ module IDL::AST
|
|
1095
1129
|
newnode = node.class.new(node.name, self, params)
|
1096
1130
|
newnode.annotations.concat(params[:annotations])
|
1097
1131
|
introduce(newnode)
|
1098
|
-
@children << newnode
|
1132
|
+
@children << newnode # add overriding child
|
1099
1133
|
return newnode
|
1100
1134
|
end
|
1101
1135
|
end
|
@@ -1116,9 +1150,7 @@ module IDL::AST
|
|
1116
1150
|
|
1117
1151
|
class ComponentBase < Derivable
|
1118
1152
|
DEFINABLE = []
|
1119
|
-
attr_reader :base
|
1120
|
-
attr_reader :interfaces
|
1121
|
-
attr_reader :idltype
|
1153
|
+
attr_reader :base, :interfaces, :idltype
|
1122
1154
|
|
1123
1155
|
def initialize(_name, _enclosure, params)
|
1124
1156
|
super(_name, _enclosure)
|
@@ -1145,8 +1177,8 @@ module IDL::AST
|
|
1145
1177
|
|
1146
1178
|
def instantiate(instantiation_context, _enclosure, _params = {})
|
1147
1179
|
_params.merge!({
|
1148
|
-
:
|
1149
|
-
:
|
1180
|
+
base: @base ? IDL::AST::TemplateParam.concrete_param(instantiation_context, @base) : @base,
|
1181
|
+
supports: self.concrete_interfaces(instantiation_context)
|
1150
1182
|
})
|
1151
1183
|
# instantiate concrete def and validate
|
1152
1184
|
super(instantiation_context, _enclosure, _params)
|
@@ -1160,6 +1192,7 @@ module IDL::AST
|
|
1160
1192
|
if parent.resolved_type.node.has_base?(self)
|
1161
1193
|
raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{parent.node.scoped_lm_name} is descendant"
|
1162
1194
|
end
|
1195
|
+
|
1163
1196
|
@resolved_base = parent.resolved_type.node
|
1164
1197
|
end
|
1165
1198
|
@base = parent.node
|
@@ -1179,8 +1212,9 @@ module IDL::AST
|
|
1179
1212
|
unless (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Interface))
|
1180
1213
|
raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
|
1181
1214
|
end
|
1215
|
+
|
1182
1216
|
rtc = tc.resolved_type
|
1183
|
-
|
1217
|
+
unless rtc.node.is_defined?
|
1184
1218
|
raise "#{typename} #{scoped_lm_name} cannot support forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
|
1185
1219
|
end
|
1186
1220
|
## TODO : is this legal?
|
@@ -1191,13 +1225,14 @@ module IDL::AST
|
|
1191
1225
|
raise "#{typename} #{scoped_lm_name} cannot support 'pseudo' #{tc.node.typename} #{tc.node.scoped_lm_name}"
|
1192
1226
|
end
|
1193
1227
|
## TODO : is this legal?
|
1194
|
-
#if tc.node.is_abstract?
|
1228
|
+
# if tc.node.is_abstract?
|
1195
1229
|
# raise RuntimeError,
|
1196
1230
|
# "'abstract' #{typename} #{scoped_lm_name} cannot support 'abstract' #{tc.node.typename} #{tc.node.scoped_lm_name}"
|
1197
|
-
#end
|
1231
|
+
# end
|
1198
1232
|
if self.has_support?(rtc.node)
|
1199
1233
|
raise "#{typename} #{scoped_lm_name} cannot support #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
|
1200
1234
|
end
|
1235
|
+
|
1201
1236
|
# check if we indirectly support this base multiple times (which is ok; no further need to check)
|
1202
1237
|
unless @resolved_interfaces.any? { |b| b.has_ancestor?(rtc.node) }
|
1203
1238
|
# this is a new support interface so we need to check for member redefinition/ambiguity
|
@@ -1205,7 +1240,8 @@ module IDL::AST
|
|
1205
1240
|
rtc.node.walk_members do |m|
|
1206
1241
|
new_op_att_ << m if m.is_a?(IDL::AST::Operation) || m.is_a?(IDL::AST::Attribute)
|
1207
1242
|
end
|
1208
|
-
if new_op_att_.any? {|n| n_ = self.search_self(n.name)
|
1243
|
+
if new_op_att_.any? { |n| n_ = self.search_self(n.name)
|
1244
|
+
n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
|
1209
1245
|
raise "#{typename} #{scoped_lm_name} cannot support #{tc.node.typename} #{tc.node.scoped_lm_name} because of duplicated operations/attributes"
|
1210
1246
|
end
|
1211
1247
|
# no need to check for duplicate member names; this support is ok
|
@@ -1231,6 +1267,7 @@ module IDL::AST
|
|
1231
1267
|
if node.is_defined?
|
1232
1268
|
raise "#{node.typename} \"#{node.name}\" is already defined."
|
1233
1269
|
end
|
1270
|
+
|
1234
1271
|
node.annotations.concat(params[:annotations])
|
1235
1272
|
|
1236
1273
|
_new_node = node.class.new(node.name, self, params)
|
@@ -1259,7 +1296,7 @@ module IDL::AST
|
|
1259
1296
|
newnode = node.class.new(node.name, self, params)
|
1260
1297
|
newnode.annotations.concat(params[:annotations])
|
1261
1298
|
introduce(newnode)
|
1262
|
-
@children << newnode
|
1299
|
+
@children << newnode # add overriding child
|
1263
1300
|
return newnode
|
1264
1301
|
end
|
1265
1302
|
end
|
@@ -1281,8 +1318,7 @@ module IDL::AST
|
|
1281
1318
|
class Home < ComponentBase
|
1282
1319
|
DEFINABLE = [IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::Initializer, IDL::AST::Finder,
|
1283
1320
|
IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
|
1284
|
-
attr_reader :component
|
1285
|
-
attr_reader :primarykey
|
1321
|
+
attr_reader :component, :primarykey
|
1286
1322
|
|
1287
1323
|
def initialize(_name, _enclosure, params)
|
1288
1324
|
@component = nil
|
@@ -1307,17 +1343,17 @@ module IDL::AST
|
|
1307
1343
|
end
|
1308
1344
|
|
1309
1345
|
def instantiate(instantiation_context, _enclosure)
|
1310
|
-
_params
|
1311
|
-
:
|
1312
|
-
:
|
1346
|
+
_params = {
|
1347
|
+
component: IDL::AST::TemplateParam.concrete_param(instantiation_context, @component),
|
1348
|
+
primarykey: @primarykey ? IDL::AST::TemplateParam.concrete_param(instantiation_context, @primarykey) : @primarykey
|
1313
1349
|
}
|
1314
1350
|
# instantiate concrete home def and validate
|
1315
1351
|
super(instantiation_context, _enclosure, _params)
|
1316
1352
|
end
|
1317
1353
|
|
1318
1354
|
def set_component_and_key(comp, key)
|
1319
|
-
unless comp
|
1320
|
-
unless comp
|
1355
|
+
unless comp&.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::TemplateParam)
|
1356
|
+
unless comp&.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::Component)
|
1321
1357
|
raise (comp ?
|
1322
1358
|
"invalid managed component for #{typename} #{scoped_lm_name}: #{comp.typename}" :
|
1323
1359
|
"missing managed component specification for #{typename} #{scoped_lm_name}")
|
@@ -1325,31 +1361,32 @@ module IDL::AST
|
|
1325
1361
|
unless comp.resolved_type.node.is_defined?
|
1326
1362
|
raise "#{scoped_lm_name}: #{comp.typename} cannot manage forward declared component #{comp.node.scoped_lm_name}"
|
1327
1363
|
end
|
1364
|
+
|
1328
1365
|
@resolved_comp = comp.resolved_type.node
|
1329
1366
|
end
|
1330
|
-
unless key
|
1367
|
+
unless key&.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::TemplateParam)
|
1331
1368
|
## TODO : add check for Components::PrimaryKeyBase base type
|
1332
1369
|
unless key.nil? || (key.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::Valuetype))
|
1333
1370
|
raise "invalid primary key for #{typename} #{scoped_lm_name}: #{key.typename}"
|
1334
1371
|
end
|
1372
|
+
|
1335
1373
|
@resolved_pk = key.resolved_type.node if key
|
1336
1374
|
end
|
1337
1375
|
@component = comp.node
|
1338
1376
|
@primarykey = key.node if key
|
1339
1377
|
end
|
1340
1378
|
|
1341
|
-
def operations(include_bases=false, traversed=nil)
|
1379
|
+
def operations(include_bases = false, traversed = nil)
|
1342
1380
|
ops = @children.find_all { |c| c.is_a?(IDL::AST::Operation) }
|
1343
1381
|
ops.concat(base_operations(traversed || [])) if include_bases
|
1344
1382
|
ops
|
1345
1383
|
end
|
1346
1384
|
|
1347
|
-
def attributes(include_bases=false, traversed=nil)
|
1385
|
+
def attributes(include_bases = false, traversed = nil)
|
1348
1386
|
atts = @children.find_all { |c| c.is_a?(IDL::AST::Attribute) }
|
1349
1387
|
atts.concat(base_attributes(traversed || [])) if include_bases
|
1350
1388
|
atts
|
1351
1389
|
end
|
1352
|
-
|
1353
1390
|
end # Home
|
1354
1391
|
|
1355
1392
|
class Connector < ComponentBase
|
@@ -1373,8 +1410,13 @@ module IDL::AST
|
|
1373
1410
|
super(instantiation_context, _enclosure, {})
|
1374
1411
|
end
|
1375
1412
|
|
1376
|
-
def is_defined
|
1377
|
-
|
1413
|
+
def is_defined?
|
1414
|
+
true
|
1415
|
+
end
|
1416
|
+
|
1417
|
+
def is_forward?
|
1418
|
+
false
|
1419
|
+
end
|
1378
1420
|
|
1379
1421
|
def add_interfaces(intfs)
|
1380
1422
|
raise "interface support not allowed for #{typename} #{scoped_lm_name}" if intfs && !intfs.empty?
|
@@ -1385,6 +1427,7 @@ module IDL::AST
|
|
1385
1427
|
unless (parent.is_a?(IDL::Type::NodeType) && parent.is_node?(self.class))
|
1386
1428
|
raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{parent.typename}"
|
1387
1429
|
end
|
1430
|
+
|
1388
1431
|
@resolved_base = parent.resolved_type.node
|
1389
1432
|
if @resolved_base.has_base?(self)
|
1390
1433
|
raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{parent.node.scoped_lm_name} is descendant"
|
@@ -1393,7 +1436,7 @@ module IDL::AST
|
|
1393
1436
|
@base = parent.node
|
1394
1437
|
end
|
1395
1438
|
|
1396
|
-
def ports(include_bases=false, traversed=nil)
|
1439
|
+
def ports(include_bases = false, traversed = nil)
|
1397
1440
|
ports = @children.inject([]) do |lst, c|
|
1398
1441
|
lst.concat(c.ports) if IDL::AST::Port === c
|
1399
1442
|
lst
|
@@ -1402,7 +1445,7 @@ module IDL::AST
|
|
1402
1445
|
ports
|
1403
1446
|
end
|
1404
1447
|
|
1405
|
-
def attributes(include_bases=false, traversed=nil)
|
1448
|
+
def attributes(include_bases = false, traversed = nil)
|
1406
1449
|
atts = @children.inject([]) do |lst, c|
|
1407
1450
|
if IDL::AST::Port === c
|
1408
1451
|
lst.concat(c.attributes)
|
@@ -1427,7 +1470,6 @@ module IDL::AST
|
|
1427
1470
|
end
|
1428
1471
|
ports
|
1429
1472
|
end
|
1430
|
-
|
1431
1473
|
end # Connector
|
1432
1474
|
|
1433
1475
|
class Component < ComponentBase
|
@@ -1450,19 +1492,25 @@ module IDL::AST
|
|
1450
1492
|
|
1451
1493
|
def instantiate(instantiation_context, _enclosure)
|
1452
1494
|
# instantiate concrete component def and validate
|
1453
|
-
super(instantiation_context, _enclosure, { :
|
1495
|
+
super(instantiation_context, _enclosure, { forward: self.is_forward? })
|
1454
1496
|
end
|
1455
1497
|
|
1456
|
-
def is_defined
|
1457
|
-
|
1498
|
+
def is_defined?
|
1499
|
+
@defined
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
def is_forward?
|
1503
|
+
not @defined
|
1504
|
+
end
|
1458
1505
|
|
1459
1506
|
def set_base(parent)
|
1460
1507
|
unless parent.is_a?(IDL::Type::ScopedName) && parent.is_node?(IDL::AST::TemplateParam)
|
1461
1508
|
unless (parent.is_a?(IDL::Type::NodeType) && parent.is_node?(self.class))
|
1462
1509
|
raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{parent.typename}"
|
1463
1510
|
end
|
1511
|
+
|
1464
1512
|
@resolved_base = parent.resolved_type.node
|
1465
|
-
|
1513
|
+
unless @resolved_base.is_defined?
|
1466
1514
|
raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{parent.node.typename} #{parent.node.scoped_lm_name}"
|
1467
1515
|
end
|
1468
1516
|
if @resolved_base.has_base?(self)
|
@@ -1472,7 +1520,7 @@ module IDL::AST
|
|
1472
1520
|
@base = parent.node
|
1473
1521
|
end
|
1474
1522
|
|
1475
|
-
def ports(include_bases=false, traversed=nil)
|
1523
|
+
def ports(include_bases = false, traversed = nil)
|
1476
1524
|
ports = @children.inject([]) do |lst, c|
|
1477
1525
|
lst.concat(c.ports) if IDL::AST::Port === c
|
1478
1526
|
lst
|
@@ -1481,11 +1529,11 @@ module IDL::AST
|
|
1481
1529
|
ports
|
1482
1530
|
end
|
1483
1531
|
|
1484
|
-
def operations(include_bases=false, traversed=nil)
|
1532
|
+
def operations(include_bases = false, traversed = nil)
|
1485
1533
|
include_bases ? base_operations(traversed || []) : []
|
1486
1534
|
end
|
1487
1535
|
|
1488
|
-
def attributes(include_bases=false, traversed=nil)
|
1536
|
+
def attributes(include_bases = false, traversed = nil)
|
1489
1537
|
atts = @children.inject([]) do |lst, c|
|
1490
1538
|
if IDL::AST::Port === c
|
1491
1539
|
lst.concat(c.attributes)
|
@@ -1510,23 +1558,23 @@ module IDL::AST
|
|
1510
1558
|
end
|
1511
1559
|
ports
|
1512
1560
|
end
|
1513
|
-
|
1514
1561
|
end # Component
|
1515
1562
|
|
1516
1563
|
class Porttype < Node
|
1517
1564
|
DEFINABLE = [IDL::AST::Attribute, IDL::AST::Port]
|
1518
1565
|
attr_reader :idltype
|
1519
|
-
|
1566
|
+
|
1567
|
+
def initialize(_name, _enclosure, _params)
|
1520
1568
|
super(_name, _enclosure)
|
1521
1569
|
@idltype = IDL::Type::Porttype.new(self)
|
1522
1570
|
end
|
1523
1571
|
|
1524
1572
|
def ports
|
1525
|
-
@children.select {|c| IDL::AST::Port === c}
|
1573
|
+
@children.select { |c| IDL::AST::Port === c }
|
1526
1574
|
end
|
1527
1575
|
|
1528
1576
|
def attributes
|
1529
|
-
@children.select {|c| IDL::AST::Attribute === c}
|
1577
|
+
@children.select { |c| IDL::AST::Attribute === c }
|
1530
1578
|
end
|
1531
1579
|
|
1532
1580
|
def instantiate(instantiation_context, _enclosure)
|
@@ -1536,15 +1584,16 @@ module IDL::AST
|
|
1536
1584
|
|
1537
1585
|
class Port < Leaf
|
1538
1586
|
PORTTYPES = [:facet, :receptacle, :emitter, :publisher, :consumer, :port, :mirrorport]
|
1539
|
-
PORT_MIRRORS = {:
|
1587
|
+
PORT_MIRRORS = {facet: :receptacle, receptacle: :facet}
|
1540
1588
|
EXTPORTDEF_ANNOTATION = 'ExtendedPortDef'
|
1541
|
-
attr_reader :idltype
|
1542
|
-
|
1589
|
+
attr_reader :idltype, :porttype
|
1590
|
+
|
1543
1591
|
def initialize(_name, _enclosure, params)
|
1544
1592
|
super(_name, _enclosure)
|
1545
1593
|
@idltype = params[:type]
|
1546
1594
|
@porttype = params[:porttype]
|
1547
1595
|
raise "unknown porttype for #{typename} #{scoped_lm_name}: #{@porttype}" unless PORTTYPES.include?(@porttype)
|
1596
|
+
|
1548
1597
|
case @porttype
|
1549
1598
|
when :facet, :receptacle
|
1550
1599
|
unless @idltype.is_a?(IDL::Type::Object) ||
|
@@ -1565,9 +1614,9 @@ module IDL::AST
|
|
1565
1614
|
|
1566
1615
|
def instantiate(instantiation_context, _enclosure)
|
1567
1616
|
_params = {
|
1568
|
-
:
|
1569
|
-
:
|
1570
|
-
:
|
1617
|
+
type: @idltype.instantiate(instantiation_context),
|
1618
|
+
porttype: @porttype,
|
1619
|
+
multiple: @multiple
|
1571
1620
|
}
|
1572
1621
|
super(instantiation_context, _enclosure, _params)
|
1573
1622
|
end
|
@@ -1577,23 +1626,23 @@ module IDL::AST
|
|
1577
1626
|
end
|
1578
1627
|
|
1579
1628
|
def expanded_copy(name_pfx, enc)
|
1580
|
-
p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {:
|
1581
|
-
p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { :
|
1629
|
+
p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, porttype: @porttype})
|
1630
|
+
p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: name_pfx, base_name: self.name, mirror: false })
|
1582
1631
|
p # return expanded copy
|
1583
1632
|
end
|
1584
1633
|
|
1585
1634
|
def expanded_mirror_copy(name_pfx, enc)
|
1586
|
-
p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {:
|
1587
|
-
p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { :
|
1635
|
+
p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, porttype: PORT_MIRRORS[@porttype]})
|
1636
|
+
p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: name_pfx, base_name: self.name, mirror: true })
|
1588
1637
|
p # return expanded copy
|
1589
1638
|
end
|
1590
1639
|
|
1591
1640
|
def ports
|
1592
1641
|
case @porttype
|
1593
1642
|
when :port
|
1594
|
-
@idltype.resolved_type.node.ports.collect {|p| p.expanded_copy(self.name, self.enclosure) }
|
1643
|
+
@idltype.resolved_type.node.ports.collect { |p| p.expanded_copy(self.name, self.enclosure) }
|
1595
1644
|
when :mirrorport
|
1596
|
-
@idltype.resolved_type.node.ports.collect {|p| p.expanded_mirror_copy(self.name, self.enclosure) }
|
1645
|
+
@idltype.resolved_type.node.ports.collect { |p| p.expanded_mirror_copy(self.name, self.enclosure) }
|
1597
1646
|
else
|
1598
1647
|
[self]
|
1599
1648
|
end
|
@@ -1602,9 +1651,9 @@ module IDL::AST
|
|
1602
1651
|
def attributes
|
1603
1652
|
case @porttype
|
1604
1653
|
when :port, :mirrorport
|
1605
|
-
@idltype.resolved_type.node.attributes.collect {|att|
|
1654
|
+
@idltype.resolved_type.node.attributes.collect { |att|
|
1606
1655
|
exp_a = att.expanded_copy(self.name, self.enclosure)
|
1607
|
-
exp_a.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { :
|
1656
|
+
exp_a.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: self.name, base_name: att.name, mirror: (@porttype == :mirrorport) })
|
1608
1657
|
exp_a # return expanded copy
|
1609
1658
|
}
|
1610
1659
|
else
|
@@ -1615,10 +1664,11 @@ module IDL::AST
|
|
1615
1664
|
|
1616
1665
|
class Valuebox < Leaf
|
1617
1666
|
attr_reader :idltype, :boxed_type
|
1667
|
+
|
1618
1668
|
def initialize(_name, _enclosure, params)
|
1619
1669
|
super(_name, _enclosure)
|
1620
1670
|
@idltype = IDL::Type::Valuebox.new(self)
|
1621
|
-
@boxed_type
|
1671
|
+
@boxed_type = params[:type]
|
1622
1672
|
unless @boxed_type.is_a?(IDL::Type::ScopedName) && @boxed_type.is_node?(IDL::AST::TemplateParam)
|
1623
1673
|
if @boxed_type.resolved_type.is_a?(IDL::Type::Valuetype)
|
1624
1674
|
raise "boxing valuetype #{@boxed_type.scoped_lm_name} in Valuebox #{scoped_lm_name} not allowed"
|
@@ -1642,7 +1692,7 @@ module IDL::AST
|
|
1642
1692
|
|
1643
1693
|
def instantiate(instantiation_context, _enclosure)
|
1644
1694
|
_params = {
|
1645
|
-
:
|
1695
|
+
type: @boxed_type.instantiate(instantiation_context)
|
1646
1696
|
}
|
1647
1697
|
super(instantiation_context, _enclosure, _params)
|
1648
1698
|
end
|
@@ -1651,8 +1701,7 @@ module IDL::AST
|
|
1651
1701
|
class Valuetype < Derivable
|
1652
1702
|
DEFINABLE = [IDL::AST::Include, IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::StateMember, IDL::AST::Initializer,
|
1653
1703
|
IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
|
1654
|
-
attr_reader :bases, :interfaces
|
1655
|
-
attr_reader :idltype
|
1704
|
+
attr_reader :bases, :interfaces, :idltype
|
1656
1705
|
|
1657
1706
|
def initialize(_name, _enclosure, params)
|
1658
1707
|
super(_name, _enclosure)
|
@@ -1677,6 +1726,7 @@ module IDL::AST
|
|
1677
1726
|
if @custom && @truncatable
|
1678
1727
|
raise "'truncatable' attribute *not* allowed for 'custom' #{typename} #{scoped_lm_name}"
|
1679
1728
|
end
|
1729
|
+
|
1680
1730
|
add_bases(_base[:list] || [])
|
1681
1731
|
add_interfaces(_inherits[:supports] || [])
|
1682
1732
|
end
|
@@ -1707,15 +1757,15 @@ module IDL::AST
|
|
1707
1757
|
|
1708
1758
|
def instantiate(instantiation_context, _enclosure)
|
1709
1759
|
_params = {
|
1710
|
-
:
|
1711
|
-
:
|
1712
|
-
:
|
1713
|
-
:
|
1714
|
-
:
|
1715
|
-
:
|
1716
|
-
:
|
1760
|
+
forward: self.is_forward?,
|
1761
|
+
abstract: self.is_abstract?,
|
1762
|
+
custom: self.is_custom?,
|
1763
|
+
inherits: {
|
1764
|
+
base: {
|
1765
|
+
truncatable: self.is_truncatable?,
|
1766
|
+
list: self.concrete_bases(instantiation_context)
|
1717
1767
|
},
|
1718
|
-
:
|
1768
|
+
supports: self.concrete_interfaces(instantiation_context)
|
1719
1769
|
}
|
1720
1770
|
}
|
1721
1771
|
inst = super(instantiation_context, _enclosure, _params)
|
@@ -1723,19 +1773,43 @@ module IDL::AST
|
|
1723
1773
|
inst
|
1724
1774
|
end
|
1725
1775
|
|
1726
|
-
def is_abstract
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
def
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1776
|
+
def is_abstract?
|
1777
|
+
@abstract
|
1778
|
+
end
|
1779
|
+
|
1780
|
+
def is_custom?
|
1781
|
+
@custom
|
1782
|
+
end
|
1783
|
+
|
1784
|
+
def is_truncatable?
|
1785
|
+
@truncatable
|
1786
|
+
end
|
1787
|
+
|
1788
|
+
def is_defined?
|
1789
|
+
@defined
|
1790
|
+
end
|
1791
|
+
|
1792
|
+
def defined=(f)
|
1793
|
+
@defined = f
|
1794
|
+
end
|
1795
|
+
|
1796
|
+
def is_forward?
|
1797
|
+
@forward
|
1798
|
+
end
|
1799
|
+
|
1800
|
+
def is_recursive?
|
1801
|
+
@recursive
|
1802
|
+
end
|
1803
|
+
|
1804
|
+
def recursive=(f)
|
1805
|
+
@recursive = f
|
1806
|
+
end
|
1734
1807
|
|
1735
1808
|
def is_local?(recurstk = [])
|
1736
1809
|
# not local if forward decl or recursion detected
|
1737
1810
|
return false if is_forward? || recurstk.include?(self)
|
1738
|
-
|
1811
|
+
|
1812
|
+
recurstk.push self # track root node to detect recursion
|
1739
1813
|
ret = state_members.any? { |m| m.is_local?(recurstk) }
|
1740
1814
|
recurstk.pop
|
1741
1815
|
ret
|
@@ -1766,22 +1840,23 @@ module IDL::AST
|
|
1766
1840
|
end
|
1767
1841
|
|
1768
1842
|
def truncatable_ids
|
1769
|
-
ids = [self.repository_id
|
1770
|
-
ids.concat(@resolved_bases.first
|
1843
|
+
ids = [self.repository_id]
|
1844
|
+
ids.concat(@resolved_bases.first.truncatable_ids) if self.has_concrete_base? && self.is_truncatable?
|
1771
1845
|
ids
|
1772
1846
|
end
|
1773
1847
|
|
1774
1848
|
def add_bases(inherits_)
|
1775
1849
|
inherits_.each do |tc|
|
1776
1850
|
unless tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::TemplateParam)
|
1777
|
-
|
1851
|
+
unless (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Valuetype))
|
1778
1852
|
raise "invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
|
1779
1853
|
end
|
1854
|
+
|
1780
1855
|
rtc = tc.resolved_type
|
1781
1856
|
if rtc.node.has_ancestor?(self)
|
1782
1857
|
raise "circular inheritance detected for #{typename} #{scoped_lm_name}: #{tc.node.scoped_lm_name} is descendant"
|
1783
1858
|
end
|
1784
|
-
|
1859
|
+
unless rtc.node.is_defined?
|
1785
1860
|
raise "#{typename} #{scoped_lm_name} cannot inherit from forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
|
1786
1861
|
end
|
1787
1862
|
if self.is_abstract? and not rtc.node.is_abstract?
|
@@ -1793,7 +1868,8 @@ module IDL::AST
|
|
1793
1868
|
if @resolved_bases.include?(rtc.node)
|
1794
1869
|
raise "#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
|
1795
1870
|
end
|
1796
|
-
|
1871
|
+
|
1872
|
+
if (not rtc.node.is_abstract?) and !@bases.empty?
|
1797
1873
|
raise "concrete basevalue #{tc.node.typename} #{tc.node.scoped_lm_name} MUST " +
|
1798
1874
|
"be first and only non-abstract in inheritance list for #{typename} #{scoped_lm_name}"
|
1799
1875
|
end
|
@@ -1806,17 +1882,19 @@ module IDL::AST
|
|
1806
1882
|
def add_interfaces(iflist_)
|
1807
1883
|
iflist_.each do |if_|
|
1808
1884
|
unless if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::TemplateParam)
|
1809
|
-
|
1885
|
+
unless (if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::Interface))
|
1810
1886
|
raise "invalid support identifier for #{typename} #{scoped_lm_name}: #{if_.typename}"
|
1811
1887
|
end
|
1888
|
+
|
1812
1889
|
rif_ = if_.resolved_type
|
1813
1890
|
### @@TODO@@ further validation
|
1814
|
-
if (not rif_.node.is_abstract?) and
|
1891
|
+
if (not rif_.node.is_abstract?) and !@interfaces.empty?
|
1815
1892
|
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
1893
|
end
|
1817
1894
|
if (not rif_.node.is_abstract?) && (not is_interface_compatible?(rif_.node))
|
1818
1895
|
raise "#{typename} #{scoped_lm_name} cannot support concrete interface #{rif_.node.scoped_lm_name} because it does not derive from inherited concrete interfaces"
|
1819
1896
|
end
|
1897
|
+
|
1820
1898
|
@resolved_interfaces << rif_.node
|
1821
1899
|
end
|
1822
1900
|
@interfaces << if_.node
|
@@ -1839,10 +1917,11 @@ module IDL::AST
|
|
1839
1917
|
if self.is_abstract? && [IDL::AST::StateMember, IDL::AST::Initializer].include?(_type)
|
1840
1918
|
raise "cannot define statemember #{_name} on abstract #{typename} #{scoped_lm_name}"
|
1841
1919
|
end
|
1920
|
+
|
1842
1921
|
super(_type, _name, *args)
|
1843
1922
|
end
|
1844
1923
|
|
1845
|
-
def walk_members
|
1924
|
+
def walk_members
|
1846
1925
|
@children.each { |c| yield(c) unless c.is_a?(IDL::AST::StateMember) or
|
1847
1926
|
c.is_a?(IDL::AST::Operation) or
|
1848
1927
|
c.is_a?(IDL::AST::Attribute) or
|
@@ -1876,6 +1955,7 @@ module IDL::AST
|
|
1876
1955
|
if node.is_defined?
|
1877
1956
|
raise "#{node.typename} \"#{node.name}\" is already defined."
|
1878
1957
|
end
|
1958
|
+
|
1879
1959
|
node.annotations.concat(params[:annotations])
|
1880
1960
|
|
1881
1961
|
_new_node = node.class.new(node.name, self, params)
|
@@ -1910,7 +1990,7 @@ module IDL::AST
|
|
1910
1990
|
|
1911
1991
|
protected
|
1912
1992
|
|
1913
|
-
def walk_members_for_copy
|
1993
|
+
def walk_members_for_copy
|
1914
1994
|
@children.each { |c| yield(c) }
|
1915
1995
|
end
|
1916
1996
|
|
@@ -1942,6 +2022,7 @@ module IDL::AST
|
|
1942
2022
|
|
1943
2023
|
class StateMember < Leaf
|
1944
2024
|
attr_reader :idltype, :visibility
|
2025
|
+
|
1945
2026
|
def initialize(_name, _enclosure, params)
|
1946
2027
|
@is_recursive = false
|
1947
2028
|
@has_incomplete_type = false
|
@@ -1950,8 +2031,9 @@ module IDL::AST
|
|
1950
2031
|
@visibility = (params[:visibility] == :public ? :public : :private)
|
1951
2032
|
unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
|
1952
2033
|
raise "Anonymous type definitions are not allowed!" if params[:type].is_anonymous?
|
2034
|
+
|
1953
2035
|
## check for use of incomplete types
|
1954
|
-
|
2036
|
+
unless @idltype.is_complete?
|
1955
2037
|
## verify type is used in sequence
|
1956
2038
|
if @idltype.resolved_type.is_a?(IDL::Type::Sequence)
|
1957
2039
|
## find the (non-sequence) elementtype
|
@@ -1965,7 +2047,7 @@ module IDL::AST
|
|
1965
2047
|
if mtype.is_a? IDL::Type::ScopedName
|
1966
2048
|
case mtype.resolved_type
|
1967
2049
|
when IDL::Type::Struct, IDL::Type::Union, IDL::Type::Valuetype
|
1968
|
-
|
2050
|
+
unless mtype.node.is_defined?
|
1969
2051
|
## check if incomplete struct/union/valuetype is contained within definition of self
|
1970
2052
|
enc = _enclosure
|
1971
2053
|
while enc.is_a?(IDL::AST::Struct) || enc.is_a?(IDL::AST::Union) || enc.is_a?(IDL::AST::Valuetype)
|
@@ -2024,8 +2106,8 @@ module IDL::AST
|
|
2024
2106
|
|
2025
2107
|
def instantiate(instantiation_context, _enclosure)
|
2026
2108
|
_params = {
|
2027
|
-
:
|
2028
|
-
:
|
2109
|
+
type: @idltype.instantiate(instantiation_context),
|
2110
|
+
visibility: self.visibility
|
2029
2111
|
}
|
2030
2112
|
super(instantiation_context, _enclosure, _params)
|
2031
2113
|
end
|
@@ -2049,10 +2131,11 @@ module IDL::AST
|
|
2049
2131
|
|
2050
2132
|
class Initializer < Leaf
|
2051
2133
|
attr_reader :raises, :params
|
2134
|
+
|
2052
2135
|
def initialize(_name, _enclosure, params)
|
2053
2136
|
super(_name, _enclosure)
|
2054
2137
|
@params = (params[:params] || []).collect do |(ptype, pname)|
|
2055
|
-
IDL::AST::Parameter.new(pname, self, {:
|
2138
|
+
IDL::AST::Parameter.new(pname, self, {attribute: :in, type: ptype})
|
2056
2139
|
end
|
2057
2140
|
@raises = []
|
2058
2141
|
self.raises = params[:raises]
|
@@ -2064,6 +2147,7 @@ module IDL::AST
|
|
2064
2147
|
(extype.is_node?(IDL::AST::Exception) || extype.is_node?(IDL::AST::TemplateParam) || extype.resolved_type.is_a?(IDL::Type::Native))
|
2065
2148
|
raise 'Only IDL Exception types allowed in raises declaration.'
|
2066
2149
|
end
|
2150
|
+
|
2067
2151
|
@raises << extype
|
2068
2152
|
end
|
2069
2153
|
end
|
@@ -2080,7 +2164,7 @@ module IDL::AST
|
|
2080
2164
|
|
2081
2165
|
def instantiate(instantiation_context, _enclosure)
|
2082
2166
|
_params = {
|
2083
|
-
:
|
2167
|
+
raises: self.concrete_raises(instantiation_context)
|
2084
2168
|
}
|
2085
2169
|
_init = super(instantiation_context, _enclosure, _params)
|
2086
2170
|
_init.set_concrete_parameters(instantiation_context, @params)
|
@@ -2098,11 +2182,10 @@ module IDL::AST
|
|
2098
2182
|
def set_concrete_parameters(instantiation_context, parms)
|
2099
2183
|
@params = parms.collect do |parm|
|
2100
2184
|
IDL::AST::Parameter.new(parm.name, self,
|
2101
|
-
{ :
|
2102
|
-
:
|
2185
|
+
{ attribute: :in,
|
2186
|
+
type: parm.idltype.instantiate(instantiation_context) })
|
2103
2187
|
end
|
2104
2188
|
end
|
2105
|
-
|
2106
2189
|
end # Initializer
|
2107
2190
|
|
2108
2191
|
class Finder < Initializer
|
@@ -2110,6 +2193,7 @@ module IDL::AST
|
|
2110
2193
|
|
2111
2194
|
class Const < Leaf
|
2112
2195
|
attr_reader :idltype, :expression, :value
|
2196
|
+
|
2113
2197
|
def initialize(_name, _enclosure, params)
|
2114
2198
|
super(_name, _enclosure)
|
2115
2199
|
@idltype = params[:type]
|
@@ -2117,7 +2201,8 @@ module IDL::AST
|
|
2117
2201
|
@value = nil
|
2118
2202
|
unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
|
2119
2203
|
raise "Anonymous type definitions are not allowed!" if @idltype.is_anonymous?
|
2120
|
-
raise "Incomplete type #{@idltype.typename} not allowed here!"
|
2204
|
+
raise "Incomplete type #{@idltype.typename} not allowed here!" unless @idltype.is_complete?
|
2205
|
+
|
2121
2206
|
unless @expression.is_a?(IDL::Expression::ScopedName) && @expression.is_node?(IDL::AST::TemplateParam)
|
2122
2207
|
@value = @idltype.narrow(@expression.value)
|
2123
2208
|
end
|
@@ -2141,21 +2226,24 @@ module IDL::AST
|
|
2141
2226
|
|
2142
2227
|
def instantiate(instantiation_context, _enclosure)
|
2143
2228
|
_params = {
|
2144
|
-
:
|
2145
|
-
:
|
2229
|
+
type: @idltype.instantiate(instantiation_context),
|
2230
|
+
expression: @expression.instantiate(instantiation_context)
|
2146
2231
|
}
|
2147
2232
|
super(instantiation_context, _enclosure, _params)
|
2148
2233
|
end
|
2149
2234
|
end # Const
|
2150
2235
|
|
2151
2236
|
class Parameter < Leaf
|
2152
|
-
IN
|
2237
|
+
IN = 0
|
2238
|
+
OUT = 1
|
2239
|
+
INOUT = 2
|
2153
2240
|
ATTRIBUTE_MAP = {
|
2154
|
-
:
|
2155
|
-
:
|
2156
|
-
:
|
2241
|
+
in: IN,
|
2242
|
+
out: OUT,
|
2243
|
+
inout: INOUT
|
2157
2244
|
}
|
2158
2245
|
attr_reader :idltype
|
2246
|
+
|
2159
2247
|
def initialize(_name, _enclosure, params)
|
2160
2248
|
super(_name, _enclosure)
|
2161
2249
|
@idltype = params[:type]
|
@@ -2163,15 +2251,18 @@ module IDL::AST
|
|
2163
2251
|
unless ATTRIBUTE_MAP.has_key?(@attribute)
|
2164
2252
|
raise "invalid attribute for parameter: #{params[:attribute]}"
|
2165
2253
|
end
|
2254
|
+
|
2166
2255
|
unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
|
2167
2256
|
raise "Anonymous type definitions are not allowed!" if params[:type].is_anonymous?
|
2257
|
+
raise "Exception #{@idltype.typename} is not allowed in an argument of an operation!" if @idltype.is_node?(IDL::AST::Exception)
|
2258
|
+
|
2168
2259
|
if @idltype.is_local?
|
2169
2260
|
if _enclosure.enclosure.is_a?(IDL::AST::Interface) && !_enclosure.enclosure.is_local?
|
2170
2261
|
raise "Local type #{@idltype.typename} not allowed for operation on unrestricted interface"
|
2171
2262
|
end
|
2172
2263
|
## IDL_Valuetype: no problem as valuetype operations are local
|
2173
2264
|
end
|
2174
|
-
|
2265
|
+
unless @idltype.is_complete?
|
2175
2266
|
if _enclosure.enclosure.is_a?(IDL::AST::Interface)
|
2176
2267
|
raise "Incomplete type #{@idltype.typename} not allowed here!"
|
2177
2268
|
end
|
@@ -2196,8 +2287,8 @@ module IDL::AST
|
|
2196
2287
|
|
2197
2288
|
def instantiate(instantiation_context, _enclosure)
|
2198
2289
|
_params = {
|
2199
|
-
:
|
2200
|
-
:
|
2290
|
+
type: @idltype.instantiate(instantiation_context),
|
2291
|
+
attribute: @attribute
|
2201
2292
|
}
|
2202
2293
|
super(instantiation_context, _enclosure, _params)
|
2203
2294
|
end
|
@@ -2218,13 +2309,14 @@ module IDL::AST
|
|
2218
2309
|
@context = nil
|
2219
2310
|
unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
|
2220
2311
|
raise "Anonymous type definitions are not allowed!" if params[:type].is_anonymous?
|
2312
|
+
|
2221
2313
|
if @idltype.is_local?
|
2222
2314
|
if _enclosure.is_a?(IDL::AST::Interface) && !_enclosure.is_local?
|
2223
2315
|
raise "Local type #{@idltype.typename} not allowed for operation on unrestricted interface"
|
2224
2316
|
end
|
2225
2317
|
## IDL_Valuetype: no problem as valuetype operations are local
|
2226
2318
|
end
|
2227
|
-
|
2319
|
+
unless @idltype.is_complete?
|
2228
2320
|
if _enclosure.is_a?(IDL::AST::Interface)
|
2229
2321
|
raise "Incomplete type #{@idltype.typename} not allowed here!"
|
2230
2322
|
end
|
@@ -2249,8 +2341,8 @@ module IDL::AST
|
|
2249
2341
|
|
2250
2342
|
def instantiate(instantiation_context, _enclosure)
|
2251
2343
|
_params = {
|
2252
|
-
:
|
2253
|
-
:
|
2344
|
+
type: @idltype.instantiate(instantiation_context),
|
2345
|
+
oneway: @oneway
|
2254
2346
|
}
|
2255
2347
|
_op = super(instantiation_context, _enclosure, _params)
|
2256
2348
|
_op.raises = self.concrete_raises(instantiation_context)
|
@@ -2264,6 +2356,7 @@ module IDL::AST
|
|
2264
2356
|
(extype.is_node?(IDL::AST::Exception) || extype.is_node?(IDL::AST::TemplateParam) || extype.resolved_type.is_a?(IDL::Type::Native))
|
2265
2357
|
raise 'Only IDL Exception or Native types allowed in raises declaration.'
|
2266
2358
|
end
|
2359
|
+
|
2267
2360
|
@raises << extype
|
2268
2361
|
end
|
2269
2362
|
end
|
@@ -2285,9 +2378,11 @@ module IDL::AST
|
|
2285
2378
|
def in_params
|
2286
2379
|
@in
|
2287
2380
|
end
|
2381
|
+
|
2288
2382
|
def out_params
|
2289
2383
|
@out
|
2290
2384
|
end
|
2385
|
+
|
2291
2386
|
def params
|
2292
2387
|
self.children
|
2293
2388
|
end
|
@@ -2318,8 +2413,8 @@ module IDL::AST
|
|
2318
2413
|
end # Operation
|
2319
2414
|
|
2320
2415
|
class Attribute < Leaf
|
2321
|
-
attr_reader :idltype, :readonly
|
2322
|
-
|
2416
|
+
attr_reader :idltype, :readonly, :get_raises, :set_raises
|
2417
|
+
|
2323
2418
|
def initialize(_name, _enclosure, params)
|
2324
2419
|
super(_name, _enclosure)
|
2325
2420
|
@idltype = params[:type]
|
@@ -2327,13 +2422,15 @@ module IDL::AST
|
|
2327
2422
|
@set_raises = []
|
2328
2423
|
unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
|
2329
2424
|
raise "Anonymous type definitions are not allowed!" if @idltype.is_anonymous?
|
2425
|
+
raise "Exception #{@idltype.typename} is not allowed as an attribute!" if @idltype.is_node?(IDL::AST::Exception)
|
2426
|
+
|
2330
2427
|
if @idltype.is_local?
|
2331
2428
|
if _enclosure.is_a?(IDL::AST::Interface) && !_enclosure.is_local?
|
2332
2429
|
raise "Local type #{@idltype.typename} not allowed for operation on unrestricted interface"
|
2333
2430
|
end
|
2334
2431
|
## IDL_Valuetype: no problem as valuetype operations are local
|
2335
2432
|
end
|
2336
|
-
|
2433
|
+
unless @idltype.is_complete?
|
2337
2434
|
if _enclosure.is_a?(IDL::AST::Interface)
|
2338
2435
|
raise "Incomplete type #{@idltype.typename} not allowed here!"
|
2339
2436
|
end
|
@@ -2357,8 +2454,8 @@ module IDL::AST
|
|
2357
2454
|
|
2358
2455
|
def instantiate(instantiation_context, _enclosure)
|
2359
2456
|
_params = {
|
2360
|
-
:
|
2361
|
-
:
|
2457
|
+
type: @idltype.instantiate(instantiation_context),
|
2458
|
+
readonly: @readonly
|
2362
2459
|
}
|
2363
2460
|
_att = super(instantiation_context, _enclosure, _params)
|
2364
2461
|
_att.get_raises = self.concrete_get_raises(instantiation_context)
|
@@ -2387,7 +2484,7 @@ module IDL::AST
|
|
2387
2484
|
end
|
2388
2485
|
|
2389
2486
|
def expanded_copy(name_pfx, enc)
|
2390
|
-
att = IDL::AST::Attribute.new("#{name_pfx}_#{self.name}", enc, {:
|
2487
|
+
att = IDL::AST::Attribute.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, readonly: @readonly})
|
2391
2488
|
att.get_raises = @get_raises unless @get_raises.empty?
|
2392
2489
|
att.set_raises = @set_raises unless @set_raises.empty?
|
2393
2490
|
att
|
@@ -2411,6 +2508,7 @@ module IDL::AST
|
|
2411
2508
|
class Struct < Node
|
2412
2509
|
DEFINABLE = [IDL::AST::Member, IDL::AST::Struct, IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator]
|
2413
2510
|
attr_reader :idltype
|
2511
|
+
|
2414
2512
|
def initialize(_name, _enclosure, params)
|
2415
2513
|
@defined = false
|
2416
2514
|
@recursive = false
|
@@ -2419,14 +2517,28 @@ module IDL::AST
|
|
2419
2517
|
@idltype = IDL::Type::Struct.new(self)
|
2420
2518
|
end
|
2421
2519
|
|
2422
|
-
def is_defined
|
2423
|
-
|
2424
|
-
|
2425
|
-
def is_recursive?; @recursive end
|
2426
|
-
def recursive=(f); @recursive = f end
|
2520
|
+
def is_defined?
|
2521
|
+
@defined
|
2522
|
+
end
|
2427
2523
|
|
2428
|
-
def
|
2429
|
-
@
|
2524
|
+
def defined=(f)
|
2525
|
+
@defined = f
|
2526
|
+
end
|
2527
|
+
|
2528
|
+
def is_forward?
|
2529
|
+
@forward
|
2530
|
+
end
|
2531
|
+
|
2532
|
+
def is_recursive?
|
2533
|
+
@recursive
|
2534
|
+
end
|
2535
|
+
|
2536
|
+
def recursive=(f)
|
2537
|
+
@recursive = f
|
2538
|
+
end
|
2539
|
+
|
2540
|
+
def walk_members
|
2541
|
+
@children.each { |m| yield(m) unless m.is_a? IDL::AST::Member }
|
2430
2542
|
end
|
2431
2543
|
|
2432
2544
|
def members
|
@@ -2436,7 +2548,8 @@ module IDL::AST
|
|
2436
2548
|
def is_local?(recurstk = [])
|
2437
2549
|
# not local if forward decl or recursion detected
|
2438
2550
|
return false if is_forward? || recurstk.include?(self)
|
2439
|
-
|
2551
|
+
|
2552
|
+
recurstk.push self # track root node to detect recursion
|
2440
2553
|
ret = members.any? { |m| m.is_local?(recurstk) }
|
2441
2554
|
recurstk.pop
|
2442
2555
|
ret
|
@@ -2456,7 +2569,7 @@ module IDL::AST
|
|
2456
2569
|
|
2457
2570
|
def instantiate(instantiation_context, _enclosure)
|
2458
2571
|
_params = {
|
2459
|
-
:
|
2572
|
+
forward: @forward
|
2460
2573
|
}
|
2461
2574
|
_s = super(instantiation_context, _enclosure, _params)
|
2462
2575
|
_s.defined = self.is_defined?
|
@@ -2465,7 +2578,7 @@ module IDL::AST
|
|
2465
2578
|
|
2466
2579
|
protected
|
2467
2580
|
|
2468
|
-
def walk_members_for_copy
|
2581
|
+
def walk_members_for_copy
|
2469
2582
|
@children.each { |c| yield(c) }
|
2470
2583
|
end
|
2471
2584
|
end # Struct
|
@@ -2480,13 +2593,16 @@ module IDL::AST
|
|
2480
2593
|
|
2481
2594
|
class Member < Leaf
|
2482
2595
|
attr_reader :idltype
|
2596
|
+
|
2483
2597
|
def initialize(_name, _enclosure, params)
|
2484
2598
|
super(_name, _enclosure)
|
2485
|
-
@idltype
|
2599
|
+
@idltype = params[:type]
|
2486
2600
|
unless @idltype.is_a?(IDL::Type::ScopedName) && @idltype.is_node?(IDL::AST::TemplateParam)
|
2487
2601
|
raise "Anonymous type definitions are not allowed!" if @idltype.is_anonymous?
|
2602
|
+
raise "Exception #{@idltype.typename} is not allowed as member!" if @idltype.is_node?(IDL::AST::Exception)
|
2603
|
+
|
2488
2604
|
## check for use of incomplete types
|
2489
|
-
|
2605
|
+
unless @idltype.is_complete?
|
2490
2606
|
## verify type is used in sequence
|
2491
2607
|
if @idltype.resolved_type.is_a? IDL::Type::Sequence
|
2492
2608
|
## find the (non-sequence) elementtype
|
@@ -2500,7 +2616,7 @@ module IDL::AST
|
|
2500
2616
|
if mtype.is_a? IDL::Type::ScopedName
|
2501
2617
|
case mtype.resolved_type
|
2502
2618
|
when IDL::Type::Struct, IDL::Type::Union, IDL::Type::Valuetype
|
2503
|
-
|
2619
|
+
unless mtype.node.is_defined?
|
2504
2620
|
## check if incomplete struct/union is contained within definition of self
|
2505
2621
|
enc = _enclosure
|
2506
2622
|
while enc.is_a?(IDL::AST::Struct) || enc.is_a?(IDL::AST::Union) || enc.is_a?(IDL::AST::Valuetype)
|
@@ -2538,7 +2654,7 @@ module IDL::AST
|
|
2538
2654
|
|
2539
2655
|
def instantiate(instantiation_context, _enclosure, _params = {})
|
2540
2656
|
_params.merge!({
|
2541
|
-
:
|
2657
|
+
type: @idltype.instantiate(instantiation_context)
|
2542
2658
|
})
|
2543
2659
|
super(instantiation_context, _enclosure, _params)
|
2544
2660
|
end
|
@@ -2548,6 +2664,7 @@ module IDL::AST
|
|
2548
2664
|
DEFINABLE = [IDL::AST::UnionMember, IDL::AST::Struct, IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator]
|
2549
2665
|
attr_reader :idltype
|
2550
2666
|
attr_accessor :switchtype
|
2667
|
+
|
2551
2668
|
def initialize(_name, _enclosure, params)
|
2552
2669
|
@defined = false
|
2553
2670
|
@recursive = false
|
@@ -2561,14 +2678,28 @@ module IDL::AST
|
|
2561
2678
|
@switchtype = _switchtype
|
2562
2679
|
end
|
2563
2680
|
|
2564
|
-
def is_defined
|
2565
|
-
|
2566
|
-
|
2567
|
-
def is_recursive?; @recursive end
|
2568
|
-
def recursive=(f); @recursive = f end
|
2681
|
+
def is_defined?
|
2682
|
+
@defined
|
2683
|
+
end
|
2569
2684
|
|
2570
|
-
def
|
2571
|
-
@
|
2685
|
+
def defined=(f)
|
2686
|
+
@defined = f
|
2687
|
+
end
|
2688
|
+
|
2689
|
+
def is_forward?
|
2690
|
+
@forward
|
2691
|
+
end
|
2692
|
+
|
2693
|
+
def is_recursive?
|
2694
|
+
@recursive
|
2695
|
+
end
|
2696
|
+
|
2697
|
+
def recursive=(f)
|
2698
|
+
@recursive = f
|
2699
|
+
end
|
2700
|
+
|
2701
|
+
def walk_members
|
2702
|
+
@children.each { |m| yield(m) unless m.is_a? IDL::AST::UnionMember }
|
2572
2703
|
end
|
2573
2704
|
|
2574
2705
|
def members
|
@@ -2578,7 +2709,8 @@ module IDL::AST
|
|
2578
2709
|
def is_local?(recurstk = [])
|
2579
2710
|
# not local if forward decl or recursion detected
|
2580
2711
|
return false if is_forward? || recurstk.include?(self)
|
2581
|
-
|
2712
|
+
|
2713
|
+
recurstk.push self # track root node to detect recursion
|
2582
2714
|
ret = members.any? { |m| m.is_local?(recurstk) }
|
2583
2715
|
recurstk.pop
|
2584
2716
|
ret
|
@@ -2596,6 +2728,7 @@ module IDL::AST
|
|
2596
2728
|
while swtype.in_range?(def_lbl)
|
2597
2729
|
return IDL::Expression::Value.new(@switchtype, def_lbl) unless lbls.include?(def_lbl)
|
2598
2730
|
return nil if def_lbl == swtype.max
|
2731
|
+
|
2599
2732
|
def_lbl = swtype.next(def_lbl)
|
2600
2733
|
end
|
2601
2734
|
nil
|
@@ -2603,6 +2736,7 @@ module IDL::AST
|
|
2603
2736
|
|
2604
2737
|
def validate_labels
|
2605
2738
|
return if self.is_template?
|
2739
|
+
|
2606
2740
|
labelvals = []
|
2607
2741
|
default_ = false
|
2608
2742
|
members.each { |m|
|
@@ -2610,14 +2744,16 @@ module IDL::AST
|
|
2610
2744
|
m.labels.each { |lbl|
|
2611
2745
|
if lbl == :default
|
2612
2746
|
raise "duplicate case label 'default' for #{typename} #{lm_name}" if default_
|
2747
|
+
|
2613
2748
|
default_ = true
|
2614
2749
|
else
|
2615
2750
|
# correct type
|
2616
2751
|
lv = @switchtype.resolved_type.narrow(lbl.value)
|
2617
2752
|
# doubles
|
2618
2753
|
if labelvals.include? lv
|
2619
|
-
raise "duplicate case label #{lv
|
2754
|
+
raise "duplicate case label #{lv} for #{typename} #{lm_name}"
|
2620
2755
|
end
|
2756
|
+
|
2621
2757
|
labelvals << lv
|
2622
2758
|
end
|
2623
2759
|
}
|
@@ -2645,7 +2781,7 @@ module IDL::AST
|
|
2645
2781
|
|
2646
2782
|
def instantiate(instantiation_context, _enclosure)
|
2647
2783
|
_params = {
|
2648
|
-
:
|
2784
|
+
forward: @forward
|
2649
2785
|
}
|
2650
2786
|
_u = super(instantiation_context, _enclosure, _params)
|
2651
2787
|
_u.set_switchtype(@switchtype.instantiate(instantiation_context))
|
@@ -2656,20 +2792,21 @@ module IDL::AST
|
|
2656
2792
|
|
2657
2793
|
protected
|
2658
2794
|
|
2659
|
-
def walk_members_for_copy
|
2795
|
+
def walk_members_for_copy
|
2660
2796
|
@children.each { |c| yield(c) }
|
2661
2797
|
end
|
2662
2798
|
end # Union
|
2663
2799
|
|
2664
2800
|
class UnionMember < Member
|
2665
2801
|
attr_reader :labels
|
2802
|
+
|
2666
2803
|
def initialize(_name, _enclosure, params)
|
2667
2804
|
super(_name, _enclosure, params)
|
2668
2805
|
## if any of the labels is 'default' forget about the others
|
2669
2806
|
if params[:labels].include?(:default)
|
2670
|
-
@labels = [
|
2807
|
+
@labels = [:default]
|
2671
2808
|
else
|
2672
|
-
@labels
|
2809
|
+
@labels = params[:labels]
|
2673
2810
|
end
|
2674
2811
|
end
|
2675
2812
|
|
@@ -2684,7 +2821,7 @@ module IDL::AST
|
|
2684
2821
|
|
2685
2822
|
def instantiate(instantiation_context, _enclosure)
|
2686
2823
|
_params = {
|
2687
|
-
:
|
2824
|
+
labels: @labels.collect { |l| l == :default ? l : l.instantiate(instantiation_context) }
|
2688
2825
|
}
|
2689
2826
|
super(instantiation_context, _enclosure, _params)
|
2690
2827
|
end
|
@@ -2692,7 +2829,8 @@ module IDL::AST
|
|
2692
2829
|
|
2693
2830
|
class Enum < Leaf
|
2694
2831
|
attr_reader :idltype
|
2695
|
-
|
2832
|
+
|
2833
|
+
def initialize(_name, _enclosure, _params)
|
2696
2834
|
super(_name, _enclosure)
|
2697
2835
|
@enums = []
|
2698
2836
|
@idltype = IDL::Type::Enum.new(self)
|
@@ -2719,11 +2857,11 @@ module IDL::AST
|
|
2719
2857
|
def instantiate(instantiation_context, _enclosure)
|
2720
2858
|
super(instantiation_context, _enclosure, {})
|
2721
2859
|
end
|
2722
|
-
|
2723
2860
|
end # Enum
|
2724
2861
|
|
2725
2862
|
class Enumerator < Leaf
|
2726
2863
|
attr_reader :idltype, :enum, :value
|
2864
|
+
|
2727
2865
|
def initialize(_name, _enclosure, params)
|
2728
2866
|
super(_name, _enclosure)
|
2729
2867
|
@idltype = IDL::Type::ULong.new
|
@@ -2747,15 +2885,17 @@ module IDL::AST
|
|
2747
2885
|
# find already instantiated Enum parent
|
2748
2886
|
_enum = _enclosure.resolve(@enum.name)
|
2749
2887
|
raise "Unable to resolve instantiated Enum scope for enumerator #{@enum.name}::#{name} instantiation" unless _enum
|
2750
|
-
|
2888
|
+
|
2889
|
+
super(instantiation_context, _enclosure, { enum: _enum, value: @value })
|
2751
2890
|
end
|
2752
2891
|
end # Enumerator
|
2753
2892
|
|
2754
2893
|
class Typedef < Leaf
|
2755
2894
|
attr_reader :idltype
|
2895
|
+
|
2756
2896
|
def initialize(_name, _enclosure, params)
|
2757
2897
|
super(_name, _enclosure)
|
2758
|
-
@idltype
|
2898
|
+
@idltype = params[:type]
|
2759
2899
|
end
|
2760
2900
|
|
2761
2901
|
def is_local?(recurstk = [])
|
@@ -2772,8 +2912,7 @@ module IDL::AST
|
|
2772
2912
|
end
|
2773
2913
|
|
2774
2914
|
def instantiate(instantiation_context, _enclosure)
|
2775
|
-
super(instantiation_context, _enclosure, { :
|
2915
|
+
super(instantiation_context, _enclosure, { type: @idltype.instantiate(instantiation_context) })
|
2776
2916
|
end
|
2777
2917
|
end # Typedef
|
2778
2918
|
end
|
2779
|
-
|