Class: IDL::AST::Union
- Inherits:
-
Node
show all
- Defined in:
- lib/ridl/node.rb,
lib/ridl/node.rb
Overview
Constant Summary
collapse
- NAMETYPE =
:class
- DEFINABLE =
[IDL::AST::UnionMember, IDL::AST::Struct, IDL::AST::Union, IDL::AST::Enum, IDL::AST::Enumerator]
Instance Attribute Summary collapse
Attributes inherited from Leaf
#annotations, #enclosure, #intern, #lm_name, #name, #prefix, #scopes
Instance Method Summary
collapse
Methods inherited from Node
#define, #introduce, #is_definable?, #match_members, #redefine, #replace_prefix, #resolve, #select_members, #undo_introduction
Methods inherited from Leaf
#_set_prefix, #has_annotations?, #is_template?, #lm_name_for_scope, #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) ⇒ Union
Returns a new instance of Union.
2619
2620
2621
2622
2623
2624
2625
2626
|
# File 'lib/ridl/node.rb', line 2619
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
|
Instance Attribute Details
#idltype ⇒ Object
Returns the value of attribute idltype.
2617
2618
2619
|
# File 'lib/ridl/node.rb', line 2617
def idltype
@idltype
end
|
#switchtype ⇒ Object
Returns the value of attribute switchtype.
2618
2619
2620
|
# File 'lib/ridl/node.rb', line 2618
def switchtype
@switchtype
end
|
Instance Method Details
#default_label ⇒ Object
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
|
# File 'lib/ridl/node.rb', line 2659
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 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) ⇒ Object
2633
|
# File 'lib/ridl/node.rb', line 2633
def defined=(f); @defined = f; end
|
#has_default? ⇒ Boolean
2655
2656
2657
|
# File 'lib/ridl/node.rb', line 2655
def has_default?
members.any? { |m| m.labels.include?(:default) }
end
|
#instantiate(_context, _enclosure) ⇒ Object
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
|
# File 'lib/ridl/node.rb', line 2717
def instantiate(_context, _enclosure)
_params = {
:forward => @forward
}
_u = super(_context, _enclosure, _params)
_u.set_switchtype(@switchtype.instantiate(_context))
_u.validate_labels
_u.defined = self.is_defined?
_u
end
|
#is_defined? ⇒ Boolean
2632
|
# File 'lib/ridl/node.rb', line 2632
def is_defined?; @defined; end
|
#is_forward? ⇒ Boolean
2634
|
# File 'lib/ridl/node.rb', line 2634
def is_forward?; @forward; end
|
#is_local?(recurstk = []) ⇒ Boolean
2646
2647
2648
2649
2650
2651
2652
2653
|
# File 'lib/ridl/node.rb', line 2646
def is_local?(recurstk = [])
return false if is_forward? || recurstk.include?(self)
recurstk.push self ret = members.any? { |m| m.is_local?(recurstk) }
recurstk.pop
ret
end
|
#is_recursive? ⇒ Boolean
2635
|
# File 'lib/ridl/node.rb', line 2635
def is_recursive?; @recursive end
|
#marshal_dump ⇒ Object
2704
2705
2706
|
# File 'lib/ridl/node.rb', line 2704
def marshal_dump
super() << @defined << @recursive << @forward << @idltype << @switchtype
end
|
#marshal_load(vars) ⇒ Object
2708
2709
2710
2711
2712
2713
2714
2715
|
# File 'lib/ridl/node.rb', line 2708
def marshal_load(vars)
@switchtype = vars.pop
@idltype = vars.pop
@forward = vars.pop
@recursive = vars.pop
@defined = vars.pop
super(vars)
end
|
#members ⇒ Object
2642
2643
2644
|
# File 'lib/ridl/node.rb', line 2642
def members
@children.find_all { |c| c.is_a? IDL::AST::UnionMember }
end
|
#recursive=(f) ⇒ Object
2636
|
# File 'lib/ridl/node.rb', line 2636
def recursive=(f); @recursive = f end
|
#set_switchtype(_switchtype) ⇒ Object
2628
2629
2630
|
# File 'lib/ridl/node.rb', line 2628
def set_switchtype(_switchtype)
@switchtype = _switchtype
end
|
#validate_labels ⇒ Object
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
|
# File 'lib/ridl/node.rb', line 2672
def validate_labels
return if self.is_template?
labelvals = []
default_ = false
members.each { |m|
m.labels.each { |lbl|
if lbl == :default
raise RuntimeError,
"duplicate case label 'default' for #{typename} #{lm_name}" if default_
default_ = true
else
lv = @switchtype.resolved_type.narrow(lbl.value)
if labelvals.include? lv
raise RuntimeError,
"duplicate case label #{lv.to_s} for #{typename} #{lm_name}"
end
labelvals << lv
end
}
}
if default_
if @switchtype.resolved_type.range_length == labelvals.size
raise RuntimeError,
"'default' case label superfluous for #{typename} #{lm_name}"
end
end
end
|
#walk_members(&block) ⇒ Object
2638
2639
2640
|
# File 'lib/ridl/node.rb', line 2638
def walk_members(&block)
@children.each { |m| yield(m) if not m.is_a? IDL::AST::UnionMember }
end
|