Class: IDL::AST::TemplateModuleReference

Inherits:
Leaf
  • Object
show all
Defined in:
lib/ridl/node.rb,
lib/ridl/node.rb

Overview

TemplateModule

Instance Attribute Summary

Attributes inherited from Leaf

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

Instance Method Summary collapse

Methods inherited from Leaf

#has_annotations?, #is_local?, #is_template?, #lm_name, #lm_scopes, #replace_prefix, #repository_id, #scoped_lm_name, #scoped_name, #set_repo_id, #set_repo_version, #typename, #unescaped_name

Constructor Details

#initialize(_name, _enclosure, _params) ⇒ TemplateModuleReference

Returns a new instance of TemplateModuleReference.



790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/ridl/node.rb', line 790

def initialize(_name, _enclosure, _params)
  super(_name, _enclosure)
  unless _params[:tpl_type].is_a?(IDL::Type::ScopedName) && _params[:tpl_type].is_node?(IDL::AST::TemplateModule)
    raise "templated module reference type required for #{typename} #{scoped_lm_name}: got #{_params[:tpl_type].typename}"
  end

  @template = _params[:tpl_type].resolved_type.node
  _params[:tpl_params].each do |p|
    unless (p.is_a?(IDL::Type::ScopedName) || p.is_a?(IDL::Expression::ScopedName)) && p.is_node?(IDL::AST::TemplateParam)
      raise "invalid template module parameter for template module reference #{typename} #{scoped_lm_name}: #{p.typename}"
    end
  end
  @params = _params[:tpl_params].collect { |p| p.resolved_node }
end

Instance Method Details

#instantiate(instantiation_context, _enclosure) ⇒ Object



815
816
817
818
819
820
821
822
823
# File 'lib/ridl/node.rb', line 815

def instantiate(instantiation_context, _enclosure)
  inst_params = @params.collect do |tp|
    # concrete objects are either Expression or Type
    tp.concrete
  end
  mod_inst = IDL::AST::Module.new(self.name, _enclosure, { template: @template, template_params: inst_params })
  @template.instantiate(mod_inst, instantiation_context)
  mod_inst
end

#marshal_dumpObject



805
806
807
# File 'lib/ridl/node.rb', line 805

def marshal_dump
  super() << @template << @params
end

#marshal_load(vars) ⇒ Object



809
810
811
812
813
# File 'lib/ridl/node.rb', line 809

def marshal_load(vars)
  @params = vars.pop
  @template = vars.pop
  super(vars)
end

#resolve(_name) ⇒ Object



825
826
827
# File 'lib/ridl/node.rb', line 825

def resolve(_name)
  @template.resolve(_name)
end