Class: IDL::AST::Home

Inherits:
ComponentBase show all
Defined in:
lib/ridl/node.rb,
lib/ridl/node.rb

Overview

ComponentBase

Constant Summary collapse

NAMETYPE =
:class
DEFINABLE =
[IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::Initializer, IDL::AST::Finder,
IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]

Instance Attribute Summary collapse

Attributes inherited from ComponentBase

#base, #idltype, #interfaces

Attributes inherited from Leaf

#annotations, #enclosure, #intern, #lm_name, #name, #prefix, #scopes

Instance Method Summary collapse

Methods inherited from ComponentBase

#add_interfaces, #ancestors, #has_base?, #has_support?, #redefine, #set_base, #supports?

Methods inherited from Derivable

#has_ancestor?, #search_self, #search_self_before_derived

Methods inherited from Node

#define, #introduce, #is_definable?, #match_members, #redefine, #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) ⇒ Home

Returns a new instance of Home.



1286
1287
1288
1289
1290
1291
1292
1293
1294
# File 'lib/ridl/node.rb', line 1286

def initialize(_name, _enclosure, params)
  @component = nil
  @resolved_comp = nil
  @primarykey = nil
  @resolved_pk = nil
  @idltype = IDL::Type::Home.new(self)
  super(_name, _enclosure, params)
  set_component_and_key(params[:component], params[:primarykey])
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



1283
1284
1285
# File 'lib/ridl/node.rb', line 1283

def component
  @component
end

#primarykeyObject (readonly)

Returns the value of attribute primarykey.



1284
1285
1286
# File 'lib/ridl/node.rb', line 1284

def primarykey
  @primarykey
end

Instance Method Details

#attributes(include_bases = false, traversed = nil) ⇒ Object



1349
1350
1351
1352
1353
# File 'lib/ridl/node.rb', line 1349

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

#instantiate(_context, _enclosure) ⇒ Object



1308
1309
1310
1311
1312
1313
1314
1315
# File 'lib/ridl/node.rb', line 1308

def instantiate(_context, _enclosure)
  _params  = {
    :component => IDL::Type::ScopedName.new(IDL::AST::TemplateParam.concrete_param(_context, @component)),
    :primarykey => @primarykey ? IDL::Type::ScopedName.new(IDL::AST::TemplateParam.concrete_param(_context, @primarykey)) : @primarykey
  }
  # instantiate concrete home def and validate
  super(_context, _enclosure, _params)
end

#marshal_dumpObject



1296
1297
1298
# File 'lib/ridl/node.rb', line 1296

def marshal_dump
  super() << @component << @resolved_comp << @primarykey << @resolved_pk
end

#marshal_load(vars) ⇒ Object



1300
1301
1302
1303
1304
1305
1306
# File 'lib/ridl/node.rb', line 1300

def marshal_load(vars)
  @resolved_pk = vars.pop
  @primarykey = vars.pop
  @resolved_comp = vars.pop
  @component = vars.pop
  super(vars)
end

#operations(include_bases = false, traversed = nil) ⇒ Object



1343
1344
1345
1346
1347
# File 'lib/ridl/node.rb', line 1343

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

#set_component_and_key(comp, key) ⇒ Object



1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
# File 'lib/ridl/node.rb', line 1317

def set_component_and_key(comp, key)
  unless comp && comp.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::TemplateParam)
    unless comp && comp.is_a?(IDL::Type::ScopedName) && comp.is_node?(IDL::AST::Component)
      raise RuntimeError,
            (comp ?
              "invalid managed component for #{typename} #{scoped_lm_name}: #{comp.typename}" :
              "missing managed component specification for #{typename} #{scoped_lm_name}")
    end
    unless comp.resolved_type.node.is_defined?
      raise RuntimeError,
        "#{scoped_lm_name}: #{comp.typename} cannot manage forward declared component #{comp.node.scoped_lm_name}"
    end
    @resolved_comp = comp.resolved_type.node
  end
  unless key && key.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::TemplateParam)
    ## TODO : add check for Components::PrimaryKeyBase base type
    unless key.nil? || (key.is_a?(IDL::Type::ScopedName) && key.is_node?(IDL::AST::Valuetype))
      raise RuntimeError,
        "invalid primary key for #{typename} #{scoped_lm_name}: #{key.typename}"
    end
    @resolved_pk = key.resolved_type.node if key
  end
  @component = comp.node
  @primarykey = key.node if key
end