Class: IDL::AST::Port

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

Overview

Porttype

Constant Summary collapse

NAMETYPE =
:member
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, #lm_name, #name, #prefix, #scopes

Instance Method Summary collapse

Methods inherited from Leaf

#_set_prefix, #has_annotations?, #is_local?, #is_template?, #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) ⇒ Port

Returns a new instance of Port.

Raises:

  • (RuntimeError)


1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
# File 'lib/ridl/node.rb', line 1586

def initialize(_name, _enclosure, params)
  super(_name, _enclosure)
  @idltype  = params[:type]
  @porttype = params[:porttype]
  raise RuntimeError, "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::ScopedName) && (@idltype.is_node?(IDL::AST::Interface) || @idltype.is_node?(IDL::AST::TemplateParam)))
      raise RuntimeError, "invalid type for #{typename} #{scoped_lm_name}:  #{@idltype.typename}"
    end
  when :port, :mirrorport
    unless @idltype.is_a?(IDL::Type::ScopedName) && (@idltype.is_node?(IDL::AST::Porttype) || @idltype.is_node?(IDL::AST::TemplateParam))
      raise RuntimeError, "invalid type for #{typename} #{scoped_lm_name}:  #{@idltype.typename}"
    end
  else
    unless @idltype.is_a?(IDL::Type::ScopedName) && (@idltype.is_node?(IDL::AST::Eventtype) ||  @idltype.is_node?(IDL::AST::TemplateParam))
      raise RuntimeError, "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.



1584
1585
1586
# File 'lib/ridl/node.rb', line 1584

def idltype
  @idltype
end

#porttypeObject (readonly)

Returns the value of attribute porttype.



1585
1586
1587
# File 'lib/ridl/node.rb', line 1585

def porttype
  @porttype
end

Instance Method Details

#attributesObject



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

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



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

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



1628
1629
1630
1631
1632
# File 'lib/ridl/node.rb', line 1628

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(_context, _enclosure) ⇒ Object



1609
1610
1611
1612
1613
1614
1615
1616
# File 'lib/ridl/node.rb', line 1609

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

#multiple?Boolean

Returns:

  • (Boolean)


1618
1619
1620
# File 'lib/ridl/node.rb', line 1618

def multiple?
  @multiple
end

#portsObject



1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
# File 'lib/ridl/node.rb', line 1634

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