Class: IDL::AST::Interface
Overview
Constant Summary
collapse
- NAMETYPE =
:class
- DEFINABLE =
[IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute,
IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
Instance Attribute Summary collapse
Attributes inherited from Leaf
#annotations, #enclosure, #intern, #lm_name, #name, #prefix, #scopes
Instance Method Summary
collapse
Methods inherited from Derivable
#has_ancestor?, #search_self, #search_self_before_derived
Methods inherited from Node
#define, #introduce, #is_definable?, #match_members, #replace_prefix, #resolve, #undo_introduction, #walk_members
Methods inherited from Leaf
#_set_prefix, #has_annotations?, #is_template?, #lm_name_for_scope, #parsed_name_scope, #replace_prefix, #repo_scopes, #repository_id, #resolve, #scoped_lm_name, #scoped_name, #set_repo_id, #set_repo_version, #typename
Constructor Details
#initialize(_name, _enclosure, params) ⇒ Interface
Returns a new instance of Interface.
931
932
933
934
935
936
937
938
939
940
941
|
# File 'lib/ridl/node.rb', line 931
def initialize(_name, _enclosure, params)
super(_name, _enclosure)
@bases = []
@resolved_bases = []
@defined = !params[:forward]
@abstract = params[:abstract]
@pseudo = params[:pseudo]
@local = params[:local]
@idltype = IDL::Type::Interface.new(self)
add_bases(params[:inherits] || [])
end
|
Instance Attribute Details
#bases ⇒ Object
Returns the value of attribute bases.
928
929
930
|
# File 'lib/ridl/node.rb', line 928
def bases
@bases
end
|
#idltype ⇒ Object
Returns the value of attribute idltype.
929
930
931
|
# File 'lib/ridl/node.rb', line 929
def idltype
@idltype
end
|
Instance Method Details
#add_bases(inherits_) ⇒ Object
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
|
# File 'lib/ridl/node.rb', line 977
def add_bases(inherits_)
inherits_.each do |tc|
unless tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::TemplateParam)
unless (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Interface))
raise RuntimeError,
"invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
end
rtc = tc.resolved_type
if rtc.node.has_ancestor?(self)
raise RuntimeError,
"circular inheritance detected for #{typename} #{scoped_lm_name}: #{tc.node.scoped_lm_name} is descendant"
end
if not rtc.node.is_defined?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if rtc.node.is_local? and not self.is_local?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from 'local' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if rtc.node.is_pseudo? and not self.is_pseudo?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from 'pseudo' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if self.is_abstract? and not rtc.node.is_abstract?
raise RuntimeError,
"'abstract' #{typename} #{scoped_lm_name} cannot inherit from non-'abstract' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if self.is_local? and rtc.node.is_abstract?
raise RuntimeError,
"'local' #{typename} #{scoped_lm_name} cannot inherit from 'abstract' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if self.has_base?(rtc.node)
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
end
unless @resolved_bases.any? { |b| b.has_ancestor?(rtc.node) }
new_op_att_ = []
rtc.node.walk_members do |m|
new_op_att_ << m if m.is_a?(IDL::AST::Operation) || m.is_a?(IDL::AST::Attribute)
end
if new_op_att_.any? {|n| n_ = self.search_self(n.name); n_.is_a?(IDL::AST::Operation) || n_.is_a?(IDL::AST::Attribute) }
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} because of duplicated operations/attributes"
end
end
@resolved_bases << rtc.node
end
@bases << tc.node
end
end
|
#ancestors ⇒ Object
1036
1037
1038
|
# File 'lib/ridl/node.rb', line 1036
def ancestors
@resolved_bases
end
|
#attributes(include_bases = false, traversed = nil) ⇒ Object
1046
1047
1048
1049
1050
|
# File 'lib/ridl/node.rb', line 1046
def attributes(include_bases=false,traversed=nil)
atts = @children.find_all { |c| c.is_a?(IDL::AST::Attribute) }
atts.concat(base_attributes(traversed || [])) if include_bases
atts
end
|
#has_base?(_base) ⇒ Boolean
1032
1033
1034
|
# File 'lib/ridl/node.rb', line 1032
def has_base?(_base)
@resolved_bases.any? { |b| b == _base.idltype.resolved_type.node }
end
|
#instantiate(_context, _enclosure) ⇒ Object
958
959
960
961
962
963
964
965
966
967
968
969
|
# File 'lib/ridl/node.rb', line 958
def instantiate(_context, _enclosure)
_params = {
:forward => self.is_forward?,
:abstract => self.is_abstract?,
:pseudo => self.is_pseudo?,
:local => self.is_local?,
:inherits => self.concrete_bases(_context)
}
super(_context, _enclosure, _params)
end
|
#is_abstract? ⇒ Boolean
971
|
# File 'lib/ridl/node.rb', line 971
def is_abstract?; @abstract; end
|
#is_defined? ⇒ Boolean
974
|
# File 'lib/ridl/node.rb', line 974
def is_defined?; @defined; end
|
#is_forward? ⇒ Boolean
975
|
# File 'lib/ridl/node.rb', line 975
def is_forward?; not @defined; end
|
#is_local? ⇒ Boolean
972
|
# File 'lib/ridl/node.rb', line 972
def is_local?; @local; end
|
#is_pseudo? ⇒ Boolean
973
|
# File 'lib/ridl/node.rb', line 973
def is_pseudo?; @pseudo; end
|
#marshal_dump ⇒ Object
943
944
945
|
# File 'lib/ridl/node.rb', line 943
def marshal_dump
super() << @bases << @resolved_bases << @defined << @abstract << @local << @pseudo << @idltype
end
|
#marshal_load(vars) ⇒ Object
947
948
949
950
951
952
953
954
955
956
|
# File 'lib/ridl/node.rb', line 947
def marshal_load(vars)
@idltype = vars.pop
@pseudo = vars.pop
@local = vars.pop
@abstract = vars.pop
@defined = vars.pop
@resolved_bases = vars.pop
@bases = vars.pop
super(vars)
end
|
#operations(include_bases = false, traversed = nil) ⇒ Object
1040
1041
1042
1043
1044
|
# File 'lib/ridl/node.rb', line 1040
def operations(include_bases=false,traversed=nil)
ops = @children.find_all { |c| c.is_a?(IDL::AST::Operation) }
ops.concat(base_operations(traversed || [])) if include_bases
ops
end
|
#redefine(node, params) ⇒ Object
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
|
# File 'lib/ridl/node.rb', line 1052
def redefine(node, params)
if node.enclosure == self
case node
when IDL::AST::Struct, IDL::AST::Union
if node.is_defined?
raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
end
node.annotations.concat(params[:annotations])
_new_node = node.class.new(node.name, self, params)
_new_node.annotations.concat(node.annotations)
_new_node.prefix = node.prefix
_new_node.instance_variable_set(:@repo_ver, node.instance_variable_get(:@repo_ver))
_new_node.instance_variable_set(:@repo_id, node.instance_variable_get(:@repo_id))
node.switchtype = params[:switchtype] if node.is_a?(IDL::AST::Union)
@children << _new_node
node.enclosure.undo_introduction(node)
introduce(_new_node)
return _new_node
else
raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
end
end
case node
when IDL::AST::Operation, IDL::AST::Attribute
raise RuntimeError, "#{node.typename} '#{node.scoped_lm_name}' cannot be overridden."
else
newnode = node.class.new(node.name, self, params)
newnode.annotations.concat(params[:annotations])
introduce(newnode)
@children << newnode return newnode
end
end
|