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, #select_members, #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, #unescaped_name
Constructor Details
#initialize(_name, _enclosure, params) ⇒ Interface
Returns a new instance of Interface.
979
980
981
982
983
984
985
986
987
988
989
|
# File 'lib/ridl/node.rb', line 979
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.
976
977
978
|
# File 'lib/ridl/node.rb', line 976
def bases
@bases
end
|
#idltype ⇒ Object
Returns the value of attribute idltype.
977
978
979
|
# File 'lib/ridl/node.rb', line 977
def idltype
@idltype
end
|
Instance Method Details
#add_bases(inherits_) ⇒ Object
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
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
|
# File 'lib/ridl/node.rb', line 1025
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
1084
1085
1086
|
# File 'lib/ridl/node.rb', line 1084
def ancestors
@resolved_bases
end
|
#attributes(include_bases = false, traversed = nil) ⇒ Object
1094
1095
1096
1097
1098
|
# File 'lib/ridl/node.rb', line 1094
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
1080
1081
1082
|
# File 'lib/ridl/node.rb', line 1080
def has_base?(_base)
@resolved_bases.any? { |b| b == _base.idltype.resolved_type.node }
end
|
#instantiate(_context, _enclosure) ⇒ Object
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
|
# File 'lib/ridl/node.rb', line 1006
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
1019
|
# File 'lib/ridl/node.rb', line 1019
def is_abstract?; @abstract; end
|
#is_defined? ⇒ Boolean
1022
|
# File 'lib/ridl/node.rb', line 1022
def is_defined?; @defined; end
|
#is_forward? ⇒ Boolean
1023
|
# File 'lib/ridl/node.rb', line 1023
def is_forward?; not @defined; end
|
#is_local? ⇒ Boolean
1020
|
# File 'lib/ridl/node.rb', line 1020
def is_local?; @local; end
|
#is_pseudo? ⇒ Boolean
1021
|
# File 'lib/ridl/node.rb', line 1021
def is_pseudo?; @pseudo; end
|
#marshal_dump ⇒ Object
991
992
993
|
# File 'lib/ridl/node.rb', line 991
def marshal_dump
super() << @bases << @resolved_bases << @defined << @abstract << @local << @pseudo << @idltype
end
|
#marshal_load(vars) ⇒ Object
995
996
997
998
999
1000
1001
1002
1003
1004
|
# File 'lib/ridl/node.rb', line 995
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
1088
1089
1090
1091
1092
|
# File 'lib/ridl/node.rb', line 1088
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
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
|
# File 'lib/ridl/node.rb', line 1100
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
|