Class: IDL::AST::Port

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

Overview

Porttype

Constant Summary collapse

PORTTYPES =
[:facet, :receptacle, :emitter, :publisher, :consumer, :port, :mirrorport]
PORT_MIRRORS =
{facet: :receptacle, receptacle: :facet}
EXTPORTDEF_ANNOTATION =
'ExtendedPortDef'

Instance Attribute Summary collapse

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, #marshal_dump, #marshal_load, #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) ⇒ Port

Returns a new instance of Port.



1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
# File 'lib/ridl/node.rb', line 1598

def initialize(_name, _enclosure, params)
  super(_name, _enclosure)
  @idltype  = params[:type]
  @porttype = params[:porttype]
  raise "unknown porttype for  #{typename} #{scoped_lm_name}: #{@porttype}" unless PORTTYPES.include?(@porttype)

  case @porttype
  when :facet, :receptacle
    unless @idltype.is_a?(IDL::Type::Object) ||
          (@idltype.is_a?(IDL::Type::NodeType) && (@idltype.is_node?(IDL::AST::Interface) || @idltype.is_node?(IDL::AST::TemplateParam)))
      raise "invalid type for #{typename} #{scoped_lm_name}:  #{@idltype.typename}"
    end
  when :port, :mirrorport
    unless @idltype.is_a?(IDL::Type::NodeType) && (@idltype.is_node?(IDL::AST::Porttype) || @idltype.is_node?(IDL::AST::TemplateParam))
      raise "invalid type for #{typename} #{scoped_lm_name}:  #{@idltype.typename}"
    end
  else
    unless @idltype.is_a?(IDL::Type::NodeType) && (@idltype.is_node?(IDL::AST::Eventtype) || @idltype.is_node?(IDL::AST::TemplateParam))
      raise "invalid type for #{typename} #{scoped_lm_name}:  #{@idltype.typename}"
    end
  end
  @multiple = params[:multiple] ? true : false
end

Instance Attribute Details

#idltypeObject (readonly)

Returns the value of attribute idltype.



1596
1597
1598
# File 'lib/ridl/node.rb', line 1596

def idltype
  @idltype
end

#porttypeObject (readonly)

Returns the value of attribute porttype.



1596
1597
1598
# File 'lib/ridl/node.rb', line 1596

def porttype
  @porttype
end

Instance Method Details

#attributesObject



1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
# File 'lib/ridl/node.rb', line 1658

def attributes
  case @porttype
  when :port, :mirrorport
    @idltype.resolved_type.node.attributes.collect { |att|
      exp_a = att.expanded_copy(self.name, self.enclosure)
      exp_a.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: self.name, base_name: att.name, mirror: (@porttype == :mirrorport) })
      exp_a # return expanded copy
    }
  else
    []
  end
end

#expanded_copy(name_pfx, enc) ⇒ Object



1635
1636
1637
1638
1639
# File 'lib/ridl/node.rb', line 1635

def expanded_copy(name_pfx, enc)
  p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, porttype: @porttype})
  p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: name_pfx, base_name: self.name, mirror: false })
  p # return expanded copy
end

#expanded_mirror_copy(name_pfx, enc) ⇒ Object



1641
1642
1643
1644
1645
# File 'lib/ridl/node.rb', line 1641

def expanded_mirror_copy(name_pfx, enc)
  p = IDL::AST::Port.new("#{name_pfx}_#{self.name}", enc, {type: @idltype, porttype: PORT_MIRRORS[@porttype]})
  p.annotations << Annotation.new(EXTPORTDEF_ANNOTATION, { extended_port_name: name_pfx, base_name: self.name, mirror: true })
  p # return expanded copy
end

#instantiate(instantiation_context, _enclosure) ⇒ Object



1622
1623
1624
1625
1626
1627
1628
1629
# File 'lib/ridl/node.rb', line 1622

def instantiate(instantiation_context, _enclosure)
  _params = {
    type: @idltype.instantiate(instantiation_context),
    porttype: @porttype,
    multiple: @multiple
  }
  super(instantiation_context, _enclosure, _params)
end

#multiple?Boolean

Returns:

  • (Boolean)


1631
1632
1633
# File 'lib/ridl/node.rb', line 1631

def multiple?
  @multiple
end

#portsObject



1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
# File 'lib/ridl/node.rb', line 1647

def ports
  case @porttype
  when :port
    @idltype.resolved_type.node.ports.collect { |p| p.expanded_copy(self.name, self.enclosure) }
  when :mirrorport
    @idltype.resolved_type.node.ports.collect { |p| p.expanded_mirror_copy(self.name, self.enclosure) }
  else
    [self]
  end
end