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
#anchor, #next, #template, #template_params
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, _context = {}) ⇒ Object
- #is_template? ⇒ Boolean
- #params ⇒ Object
Methods inherited from Module
#_set_prefix, #annotations, #has_anchor?, #is_templated?, #marshal_dump, #marshal_load, #redefine, #replace_prefix, #repo_scopes, #template_param, #undo_introduction
Methods inherited from Node
#introduce, #is_definable?, #marshal_dump, #marshal_load, #match_members, #redefine, #replace_prefix, #resolve, #select_members, #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, #unescaped_name
Constructor Details
#initialize(_name, _enclosure, _params) ⇒ TemplateModule
Returns a new instance of TemplateModule.
716 717 718 719 720 |
# File 'lib/ridl/node.rb', line 716 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.
715 716 717 |
# File 'lib/ridl/node.rb', line 715 def idltype @idltype end |
Instance Method Details
#define(*args) ⇒ Object
722 723 724 725 726 |
# File 'lib/ridl/node.rb', line 722 def define(*args) child = super(*args) @template_params << child if child.is_a?(IDL::AST::TemplateParam) child end |
#instantiate(_module_instance, _context = {}) ⇒ Object
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 |
# File 'lib/ridl/node.rb', line 736 def instantiate(_module_instance, _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 < _module_instance.template_params.size _cp = _module_instance.template_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_matches?(_cp.resolved_type.basetype) 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
728 729 730 |
# File 'lib/ridl/node.rb', line 728 def is_template? true end |
#params ⇒ Object
732 733 734 |
# File 'lib/ridl/node.rb', line 732 def params @template_params end |