class ADSL::Parser::ASTEither

Public Instance Methods

list_entity_classes_written_to() click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 872
def list_entity_classes_written_to
  @blocks.map{ block.list_entity_classes_written_to }.flatten
end
optimize() click to toggle source
Calls superclass method ADSL::Parser::ASTNode#optimize
# File lib/adsl/parser/ast_nodes.rb, line 876
def optimize
  until_no_change super do |either|
    next either.optimize unless either.is_a?(ASTEither)
    next ASTDummyStmt.new if either.blocks.empty?
    next either.blocks.first if either.blocks.length == 1
    ASTEither.new(:blocks => either.blocks.map{ |block|
      if block.statements.length == 1 && block.statements.first.is_a?(ASTEither)
        block.statements.first.blocks
      else
        [block]
      end
    }.flatten(1).uniq)
  end
end
to_adsl() click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 891
def to_adsl
  "either #{ @blocks.map{ |b| "{\n#{ b.to_adsl.adsl_indent }}" }.join " or " }\n"
end
typecheck_and_resolve(context) click to toggle source
# File lib/adsl/parser/ast_nodes.rb, line 839
def typecheck_and_resolve(context)
  context.push_frame

  contexts = [context]
  (@blocks.length-1).times do
    contexts << context.dup
  end

  blocks = []
  @blocks.length.times do |i|
    blocks << @blocks[i].typecheck_and_resolve(contexts[i])
  end

  contexts.each do |c|
    c.pop_frame
  end

  either = ADSL::DS::DSEither.new :blocks => blocks

  lambdas = []

  ASTTypecheckResolveContext::context_vars_that_differ(*contexts).each do |var_name, vars|
    common_type = ADSL::DS::DSClass.common_supertype(vars.map(&:type))
    var = ADSL::DS::DSVariable.new :name => var_name, :type => common_type
    objset = ADSL::DS::DSEitherLambdaObjset.new :either => either, :vars => vars
    assignment = ADSL::DS::DSAssignment.new :var => var, :objset => objset
    context.redefine_var var, nil
    lambdas << assignment
  end

  return [ either, lambdas ]
end