Class: IDL::AST::ComponentBase
Overview
Constant Summary
collapse
- NAMETYPE =
:class
- DEFINABLE =
[]
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_local?, #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) ⇒ ComponentBase
Returns a new instance of ComponentBase.
1113
1114
1115
1116
1117
1118
1119
1120
1121
|
# File 'lib/ridl/node.rb', line 1113
def initialize(_name, _enclosure, params)
super(_name, _enclosure)
@base = nil
@resolved_base = nil
@interfaces = []
@resolved_interfaces = []
set_base(params[:base]) if params[:base]
add_interfaces(params[:supports] || [])
end
|
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
1109
1110
1111
|
# File 'lib/ridl/node.rb', line 1109
def base
@base
end
|
#idltype ⇒ Object
Returns the value of attribute idltype.
1111
1112
1113
|
# File 'lib/ridl/node.rb', line 1111
def idltype
@idltype
end
|
#interfaces ⇒ Object
Returns the value of attribute interfaces.
1110
1111
1112
|
# File 'lib/ridl/node.rb', line 1110
def interfaces
@interfaces
end
|
Instance Method Details
#add_interfaces(intfs) ⇒ Object
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
|
# File 'lib/ridl/node.rb', line 1168
def add_interfaces(intfs)
intfs.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 not rtc.node.is_defined?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot support forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if rtc.node.is_local?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot support 'local' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if rtc.node.is_pseudo?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot support 'pseudo' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if self.has_support?(rtc.node)
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot support #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
end
unless @resolved_interfaces.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 support #{tc.node.typename} #{tc.node.scoped_lm_name} because of duplicated operations/attributes"
end
end
@resolved_interfaces << rtc.node
end
@interfaces << tc.node
end
end
|
#ancestors ⇒ Object
1164
1165
1166
|
# File 'lib/ridl/node.rb', line 1164
def ancestors
resolved_bases
end
|
#has_base?(n) ⇒ Boolean
1160
1161
1162
|
# File 'lib/ridl/node.rb', line 1160
def has_base?(n)
@resolved_base && (@resolved_base == n.idltype.resolved_type.node) end
|
#has_support?(intf) ⇒ Boolean
1217
1218
1219
|
# File 'lib/ridl/node.rb', line 1217
def has_support?(intf)
@resolved_interfaces.any? { |b| b == intf.idltype.resolved_type.node }
end
|
#instantiate(_context, _enclosure, _params = {}) ⇒ Object
1136
1137
1138
1139
1140
1141
1142
1143
|
# File 'lib/ridl/node.rb', line 1136
def instantiate(_context, _enclosure, _params = {})
_params.merge!({
:base => @base ? IDL::Type::ScopedName.new(IDL::AST::TemplateParam.concrete_param(_context, @base)) : @base,
:supports => self.concrete_interfaces(_context)
})
super(_context, _enclosure, _params)
end
|
#marshal_dump ⇒ Object
1123
1124
1125
|
# File 'lib/ridl/node.rb', line 1123
def marshal_dump
super() << @base << @resolved_base << @interfaces << @resolved_interfaces << @idltype
end
|
#marshal_load(vars) ⇒ Object
1127
1128
1129
1130
1131
1132
1133
1134
|
# File 'lib/ridl/node.rb', line 1127
def marshal_load(vars)
@idltype = vars.pop
@resolved_interfaces = vars.pop
@interfaces = vars.pop
@resolved_base = vars.pop
@base = vars.pop
super(vars)
end
|
#redefine(node, params) ⇒ Object
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
|
# File 'lib/ridl/node.rb', line 1225
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
|
#set_base(parent) ⇒ Object
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
|
# File 'lib/ridl/node.rb', line 1145
def set_base(parent)
unless parent.is_a?(IDL::Type::ScopedName) && parent.is_node?(IDL::AST::TemplateParam)
unless (parent.is_a?(IDL::Type::ScopedName) && parent.is_node?(self.class))
raise RuntimeError,
"invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{parent.typename}"
end
if parent.resolved_type.node.has_base?(self)
raise RuntimeError,
"circular inheritance detected for #{typename} #{scoped_lm_name}: #{parent.node.scoped_lm_name} is descendant"
end
@resolved_base = parent.resolved_type.node
end
@base = parent.node
end
|
#supports?(intf) ⇒ Boolean
1221
1222
1223
|
# File 'lib/ridl/node.rb', line 1221
def supports?(intf)
self.has_support?(intf) || (@resolved_base && @resolved_base.supports?(intf)) || @resolved_interfaces.any? { |base_i| i.has_ancestor?(intf) }
end
|