Class: IDL::AST::TemplateModule
- Defined in:
- lib/ridl/node.rb,
lib/ridl/node.rb
Constant Summary collapse
- NAMETYPE =
:class- DEFINABLE =
[ IDL::AST::Include, IDL::AST::Module, IDL::AST::Interface, IDL::AST::Valuebox, IDL::AST::Valuetype, IDL::AST::Const, IDL::AST::Struct, IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator, IDL::AST::Typedef, IDL::AST::Home, IDL::AST::Porttype, IDL::AST::Component, IDL::AST::Connector, IDL::AST::TemplateParam, IDL::AST::TemplateModuleReference ]
Instance Attribute Summary collapse
-
#idltype ⇒ Object
readonly
Returns the value of attribute idltype.
Attributes inherited from Module
Attributes inherited from Leaf
#annotations, #enclosure, #intern, #lm_name, #name, #prefix, #scopes
Instance Method Summary collapse
- #define(*args) ⇒ Object
-
#initialize(_name, _enclosure, _params) ⇒ TemplateModule
constructor
A new instance of TemplateModule.
- #instantiate(_module_instance, _concrete_params, _context = {}) ⇒ Object
- #is_template? ⇒ Boolean
Methods inherited from Module
#_set_prefix, #annotations, #has_anchor?, #marshal_dump, #marshal_load, #redefine, #replace_prefix, #repo_scopes, #undo_introduction
Methods inherited from Node
#introduce, #is_definable?, #marshal_dump, #marshal_load, #match_members, #redefine, #replace_prefix, #resolve, #undo_introduction, #walk_members
Methods inherited from Leaf
#_set_prefix, #has_annotations?, #is_local?, #lm_name_for_scope, #marshal_dump, #marshal_load, #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) ⇒ TemplateModule
Returns a new instance of TemplateModule.
672 673 674 675 676 |
# File 'lib/ridl/node.rb', line 672 def initialize(_name, _enclosure, _params) super(_name, _enclosure, {}) @idltype = IDL::Type::TemplateModule.new(self) @template_params = [] end |
Instance Attribute Details
#idltype ⇒ Object (readonly)
Returns the value of attribute idltype.
671 672 673 |
# File 'lib/ridl/node.rb', line 671 def idltype @idltype end |
Instance Method Details
#define(*args) ⇒ Object
678 679 680 681 682 |
# File 'lib/ridl/node.rb', line 678 def define(*args) child = super(*args) @template_params << child if child.is_a?(IDL::AST::TemplateParam) child end |
#instantiate(_module_instance, _concrete_params, _context = {}) ⇒ Object
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/ridl/node.rb', line 688 def instantiate(_module_instance, _concrete_params, _context = {}) # process concrete parameters @template_params.each_with_index do |_tp, _ix| raise RuntimeError, "missing template parameter for #{typename} #{scoped_lm_name}: #{_tp.name}" unless _ix < _concrete_params.size _cp = _concrete_params[_ix] if _cp.is_a?(IDL::Type) raise RuntimeError, "anonymous type definitions are not allowed!" if _cp.is_anonymous? # parameter should be a matching IDL::Type unless _tp.idltype.is_a?(IDL::Type::Any) || _tp.idltype.class === _cp.resolved_type raise RuntimeError, "mismatched instantiation parameter \##{_ix} #{_cp.typename} for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}" end # verify concrete parameter case _tp.idltype when IDL::Type::Any # 'typename' # no further checks when IDL::Type::Interface, # 'interface' IDL::Type::Eventtype, # 'eventtype' IDL::Type::Valuetype, # 'valuetype' IDL::Type::Struct, # 'struct' IDL::Type::Union, # 'union' IDL::Type::Exception, # 'exception' IDL::Type::Enum # 'enum' # no further checks when IDL::Type::Sequence # 'sequence' or 'sequence<...>' _tptype = _tp.idltype unless _tptype.basetype.is_a?(IDL::Type::Void) # 'sequence' # check basetype unless _tptype.basetype.is_a?(IDL::Type::ScopedName) && _tptype.basetype.is_node?(IDL::AST::TemplateParam) && _tptype.basetype.node.concrete && _tptype.basetype.node.concrete.idltype.resolved_type == _cp.resolved_type.basetype.resolved_type raise RuntimeError, "invalid sequence type as instantiation parameter for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}" end end end elsif _cp.is_a?(IDL::Expression) # template param should be 'const <const_type>' unless _tp.idltype.is_a?(IDL::Type::Const) raise RuntimeError, "unexpected expression as instantiation parameter for #{typename} #{scoped_lm_name}: expected #{_tp.idltype.typename} for #{_tp.name}" end # match constant type _tp.idltype.narrow(_cp.value) else raise RuntimeError, "invalid instantiation parameter for #{typename} #{scoped_lm_name}: #{_cp.class.name}" end # if we get here all is well -> store concrete param _tp.set_concrete_param(_cp.is_a?(IDL::Type::ScopedName) ? _cp.node : _cp) end # instantiate template by copying template module state to module instance _module_instance.copy_from(self, _context) end |
#is_template? ⇒ Boolean
684 685 686 |
# File 'lib/ridl/node.rb', line 684 def is_template? true end |