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 Detail

      • 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.
    • Method Detail

      • 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
      • calculateDatumValue

        protected Object calculateDatumValue​(Expression datum)
        Given the expression generated from a datum returns the value of the datum as an Object.
      • 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.