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, #select_members, #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, #unescaped_name
Constructor Details
#initialize(_name, _enclosure, params) ⇒ ComponentBase
Returns a new instance of ComponentBase.
1161
1162
1163
1164
1165
1166
1167
1168
1169
|
# File 'lib/ridl/node.rb', line 1161
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.
1157
1158
1159
|
# File 'lib/ridl/node.rb', line 1157
def base
@base
end
|
#idltype ⇒ Object
Returns the value of attribute idltype.
1159
1160
1161
|
# File 'lib/ridl/node.rb', line 1159
def idltype
@idltype
end
|
#interfaces ⇒ Object
Returns the value of attribute interfaces.
1158
1159
1160
|
# File 'lib/ridl/node.rb', line 1158
def interfaces
@interfaces
end
|
Instance Method Details
#add_interfaces(intfs) ⇒ Object
1216
1217
1218
1219
1220
1221
1222
1223
1224
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 1216
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
1212
1213
1214
|
# File 'lib/ridl/node.rb', line 1212
def ancestors
resolved_bases
end
|
#has_base?(n) ⇒ Boolean
1208
1209
1210
|
# File 'lib/ridl/node.rb', line 1208
def has_base?(n)
@resolved_base && (@resolved_base == n.idltype.resolved_type.node) end
|
#has_support?(intf) ⇒ Boolean
1265
1266
1267
|
# File 'lib/ridl/node.rb', line 1265
def has_support?(intf)
@resolved_interfaces.any? { |b| b == intf.idltype.resolved_type.node }
end
|
#instantiate(_context, _enclosure, _params = {}) ⇒ Object
1184
1185
1186
1187
1188
1189
1190
1191
|
# File 'lib/ridl/node.rb', line 1184
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
1171
1172
1173
|
# File 'lib/ridl/node.rb', line 1171
def marshal_dump
super() << @base << @resolved_base << @interfaces << @resolved_interfaces << @idltype
end
|
#marshal_load(vars) ⇒ Object
1175
1176
1177
1178
1179
1180
1181
1182
|
# File 'lib/ridl/node.rb', line 1175
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
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
|
# File 'lib/ridl/node.rb', line 1273
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
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
|
# File 'lib/ridl/node.rb', line 1193
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
1269
1270
1271
|
# File 'lib/ridl/node.rb', line 1269
def supports?(intf)
self.has_support?(intf) || (@resolved_base && @resolved_base.supports?(intf)) || @resolved_interfaces.any? { |base_i| i.has_ancestor?(intf) }
end
|