Package gnu.expr

Class CaseExp

All Implemented Interfaces:
gnu.kawa.format.Printable, Named, SourceLocator, SourceLocator, Locator

public class CaseExp extends Expression
This class represents a case expression
 case case-key case-clause+
 case case-key case-clause* case-else-clause
     case-key ::= expression
     case-clause ::= ((datum*) expression+)
        | ((datum*) => expression)
     case-else-clause ::= (else  expression+)
        | (else => expression)
 
  • Constructor Details

    • CaseExp

      public CaseExp(Expression key, CaseExp.CaseClause[] clauses)
      Constructor for a case expression with no else clause. Arguments must be non null. clauses parameter must contain at least one CaseClause.
    • CaseExp

      public CaseExp(Expression key, CaseExp.CaseClause[] clauses, CaseExp.CaseClause elseClause)
      Constructor for a case expression with an else clause. Arguments must be non null.
  • Method Details

    • mustCompile

      protected boolean mustCompile()
      Specified by:
      mustCompile in class Expression
    • apply

      public void apply(CallContext ctx) throws Throwable
      Description copied from class: Expression
      Evaluate the expression. This is named apply rather than eval so it is compatible with the full-tail-call calling convention, and we can stash an Expression in CallContext's proc field. FIXME - are we making use of this?
      Overrides:
      apply in class Expression
      Throws:
      Throwable
    • print

      public void print(gnu.kawa.io.OutPort out)
      Specified by:
      print in class Expression
    • compile

      public void compile(Compilation comp, Target target)
      Specified by:
      compile in class Expression
    • visit

      protected <R, D> R visit(ExpVisitor<R,D> visitor, D d)
      Overrides:
      visit in class Expression
    • visitChildren

      protected <R, D> void visitChildren(ExpVisitor<R,D> visitor, D d)
      Overrides:
      visitChildren in class Expression
    • calculateDatumValue

      protected Object calculateDatumValue(Expression datum)
      Given the expression generated from a datum returns the value of the datum as an Object.
    • calculateType

      protected Type calculateType()
      Overrides:
      calculateType in class Expression
    • calculateDatumsType

      protected Type calculateDatumsType()
      Computes the union type of the case expression datums. Useful to know if the datums are all integer values.
    • searchValue

      public boolean searchValue(Object keyValue)
      Search a clause containing the specified key. If the clause is found returns true, false otherwise.
    • selectCase

      public Expression selectCase(Object keyValue)
      Search for a clause containing the specified key. If the clause is found returns the corresponding expression.