class IDL::AST::Union

Constants

DEFINABLE

Attributes

idltype[R]
switchtype[RW]

Public Class Methods

new(_name, _enclosure, params) click to toggle source
Calls superclass method IDL::AST::Node::new
# File lib/ridl/node.rb, line 2668
def initialize(_name, _enclosure, params)
  @defined = false
  @recursive = false
  @forward = params[:forward] ? true : false
  @switchtype = nil
  super(_name, _enclosure)
  @idltype = IDL::Type::Union.new(self)
end

Public Instance Methods

default_label() click to toggle source
# File lib/ridl/node.rb, line 2723
def default_label
  swtype = @switchtype.resolved_type
  lbls = members.collect { |m| m.labels.include?(:default) ? [] : m.labels.collect { |l| l.value } }.flatten
  lbls = lbls.sort unless IDL::Type::Boolean === swtype ## work around bug in Ruby 1.9.2
  def_lbl = swtype.min
  while swtype.in_range?(def_lbl)
    return IDL::Expression::Value.new(@switchtype, def_lbl) unless lbls.include?(def_lbl)
    return nil if def_lbl == swtype.max

    def_lbl = swtype.next(def_lbl)
  end
  nil
end
defined=(f) click to toggle source
# File lib/ridl/node.rb, line 2685
def defined=(f)
  @defined = f
end
has_default?() click to toggle source
# File lib/ridl/node.rb, line 2719
def has_default?
  members.any? { |m| m.labels.include?(:default) }
end
instantiate(instantiation_context, _enclosure) click to toggle source
Calls superclass method IDL::AST::Leaf#instantiate
# File lib/ridl/node.rb, line 2782
def instantiate(instantiation_context, _enclosure)
  _params = {
    forward: @forward
  }
  _u = super(instantiation_context, _enclosure, _params)
  _u.set_switchtype(@switchtype.instantiate(instantiation_context))
  _u.validate_labels
  _u.defined = self.is_defined?
  _u
end
is_defined?() click to toggle source
# File lib/ridl/node.rb, line 2681
def is_defined?
  @defined
end
is_forward?() click to toggle source
# File lib/ridl/node.rb, line 2689
def is_forward?
  @forward
end
is_local?(recurstk = []) click to toggle source
# File lib/ridl/node.rb, line 2709
def is_local?(recurstk = [])
  # not local if forward decl or recursion detected
  return false if is_forward? || recurstk.include?(self)

  recurstk.push self # track root node to detect recursion
  ret = members.any? { |m| m.is_local?(recurstk) }
  recurstk.pop
  ret
end
is_recursive?() click to toggle source
# File lib/ridl/node.rb, line 2693
def is_recursive?
  @recursive
end
marshal_dump() click to toggle source
Calls superclass method IDL::AST::Node#marshal_dump
# File lib/ridl/node.rb, line 2769
def marshal_dump
  super() << @defined << @recursive << @forward << @idltype << @switchtype
end
marshal_load(vars) click to toggle source
Calls superclass method IDL::AST::Node#marshal_load
# File lib/ridl/node.rb, line 2773
def marshal_load(vars)
  @switchtype = vars.pop
  @idltype = vars.pop
  @forward = vars.pop
  @recursive = vars.pop
  @defined = vars.pop
  super(vars)
end
members() click to toggle source
# File lib/ridl/node.rb, line 2705
def members
  @children.find_all { |c| c.is_a? IDL::AST::UnionMember }
end
recursive=(f) click to toggle source
# File lib/ridl/node.rb, line 2697
def recursive=(f)
  @recursive = f
end
set_switchtype(_switchtype) click to toggle source
# File lib/ridl/node.rb, line 2677
def set_switchtype(_switchtype)
  @switchtype = _switchtype
end
validate_labels() click to toggle source
# File lib/ridl/node.rb, line 2737
def validate_labels
  return if self.is_template?

  labelvals = []
  default_ = false
  members.each { |m|
    ## check union case labels for validity
    m.labels.each { |lbl|
      if lbl == :default
        raise "duplicate case label 'default' for #{typename} #{lm_name}" if default_

        default_ = true
      else
        # correct type
        lv = @switchtype.resolved_type.narrow(lbl.value)
        # doubles
        if labelvals.include? lv
          raise "duplicate case label #{lv} for #{typename} #{lm_name}"
        end

        labelvals << lv
      end
    }
  }
  ## check if default allowed if defined
  if default_
    if @switchtype.resolved_type.range_length == labelvals.size
      raise "'default' case label superfluous for #{typename} #{lm_name}"
    end
  end
end
walk_members() { |m| ... } click to toggle source
# File lib/ridl/node.rb, line 2701
def walk_members
  @children.each { |m| yield(m) unless m.is_a? IDL::AST::UnionMember }
end

Protected Instance Methods

walk_members_for_copy() { |c| ... } click to toggle source
# File lib/ridl/node.rb, line 2795
def walk_members_for_copy
  @children.each { |c| yield(c) }
end