class ADSL::Parser::ASTUnion

Public Instance Methods

objset_has_side_effects?() click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 1033
def objset_has_side_effects?
  @objsets.nil? ? false : @objsets.map{ |o| o.objset_has_side_effects? }.include?(true)
end
optimize() click to toggle source
Calls superclass method ADSL::Parser::ASTNode#optimize
# File lib/adsl/parser/ast_nodes.rb, line 1051
def optimize
  until_no_change super do |union|
    next ASTEmptyObjset.new if union.objsets.empty?
    next union.objsets.first if union.objsets.length == 1
    ASTUnion.new(:objsets => union.objsets.map{ |objset|
      objset.is_a?(ASTUnion) ? objset.objsets : [objset]
    }.flatten(1).reject{ |o| o.is_a? ASTEmptyObjset })
  end
end
to_adsl() click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 1061
def to_adsl
  "union(#{ @objsets.map(&:to_adsl).join(', ') })"
end
typecheck_and_resolve(context) click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 1037
def typecheck_and_resolve(context)
  objsets = @objsets.map{ |o| o.typecheck_and_resolve context }
  objsets.reject!{ |o| o.type.nil? }

  return ADSL::DS::DSEmptyObjset.new if objsets.length == 0
  return objsets.first if objsets.length == 1

  types = objsets.map{ |o| o.type }
  # will raise an error if no single common supertype exists
  ADSL::DS::DSClass.common_supertype(types)

  return ADSL::DS::DSUnion.new :objsets => objsets
end