Class: IDL::AST::TemplateParam

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

Overview

Module

Instance Attribute Summary collapse

Attributes inherited from Leaf

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Leaf

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

Constructor Details

#initialize(_name, _enclosure, params) ⇒ TemplateParam

Returns a new instance of TemplateParam.



645
646
647
648
649
# File 'lib/ridl/node.rb', line 645

def initialize(_name, _enclosure, params)
  super(_name, _enclosure)
  @idltype = params[:type]
  @concrete = nil
end

Instance Attribute Details

#concreteObject (readonly)

Returns the value of attribute concrete.



643
644
645
# File 'lib/ridl/node.rb', line 643

def concrete
  @concrete
end

#idltypeObject (readonly)

Returns the value of attribute idltype.



643
644
645
# File 'lib/ridl/node.rb', line 643

def idltype
  @idltype
end

Class Method Details

.concrete_param(instantiation_context, tpl_elem) ⇒ Object



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/ridl/node.rb', line 676

def self.concrete_param(instantiation_context, tpl_elem)
  # is this an element from the template's scope
  if tpl_elem.is_template?
    celem = if tpl_elem.is_a?(IDL::AST::TemplateParam) # an actual template parameter?
      tpl_elem.concrete # get the template parameter's concrete (instantiation argument) value
    else
      # referenced template elements should have been instantiated already and available through context
      ctxelem = instantiation_context[tpl_elem]
      # all items in the context are AST elements but for a concrete parameter value only constants and type
      # elements will be referenced; return accordingly
      ctxelem.is_a?(IDL::AST::Const) ? ctxelem.expression : ctxelem.idltype
    end
    raise "cannot resolve concrete node for template #{tpl_elem.typename} #{tpl_elem.scoped_lm_name}" unless celem

    celem
  else
    tpl_elem.idltype # just return the element's idltype if not from the template scope
  end
end

Instance Method Details

#concrete_matches?(idl_type) ⇒ Boolean

Returns:

  • (Boolean)


668
669
670
671
672
673
674
# File 'lib/ridl/node.rb', line 668

def concrete_matches?(idl_type)
  if @concrete
    concrete_type = (@concrete.is_a?(IDL::Type) ? @concrete : @concrete.idltype).resolved_type
    return concrete_type.matches?(idl_type.resolved_type)
  end
  false
end

#is_template?Boolean

Returns:

  • (Boolean)


660
661
662
# File 'lib/ridl/node.rb', line 660

def is_template?
  true
end

#marshal_dumpObject



651
652
653
# File 'lib/ridl/node.rb', line 651

def marshal_dump
  super() << @idltype
end

#marshal_load(vars) ⇒ Object



655
656
657
658
# File 'lib/ridl/node.rb', line 655

def marshal_load(vars)
  @idltype = vars.pop
  super(vars)
end

#set_concrete_param(_param) ⇒ Object



664
665
666
# File 'lib/ridl/node.rb', line 664

def set_concrete_param(_param)
  @concrete = _param
end