gnu.kawa.reflect
Class TypeSwitch

java.lang.Object
  extended by gnu.mapping.PropertySet
      extended by gnu.mapping.Procedure
          extended by gnu.mapping.ProcedureN
              extended by gnu.mapping.MethodProc
                  extended by gnu.kawa.reflect.TypeSwitch
All Implemented Interfaces:
Inlineable, Named

public class TypeSwitch
extends MethodProc
implements Inlineable

Implement 'typeswitch' (as in XQuery) or 'typecase'. Usage: (typeswitch SELECTOR CASE-LAMBDA ... DEFAULT-LAMBDA) Each CASE-LAMBDA is a 1-argument MethodProc, while DEFAULT-LAMBDA is a 0-argument Procedure. Calls the first CASE-LAMBDA such that SELECTOR is a valid argument; if there is none, calls DEFAULT-LAMBDA. In the current implementation, all of CASE-LAMBDA and DEFAULT-LAMBDA must be LambdaExps, and the call must be inlined.


Field Summary
static TypeSwitch typeSwitch
           
 
Fields inherited from class gnu.mapping.MethodProc
argTypes, NO_MATCH, NO_MATCH_AMBIGUOUS, NO_MATCH_BAD_TYPE, NO_MATCH_TOO_FEW_ARGS, NO_MATCH_TOO_MANY_ARGS
 
Fields inherited from class gnu.mapping.ProcedureN
noArgs
 
Fields inherited from class gnu.mapping.Procedure
compilerKey, validateApplyKey
 
Fields inherited from class gnu.mapping.PropertySet
nameKey
 
Constructor Summary
TypeSwitch(java.lang.String name)
           
 
Method Summary
 void apply(CallContext ctx)
          Call this Procedure using the explicit-CallContext-convention.
 void compile(ApplyExp exp, Compilation comp, Target target)
           
 Type getReturnType(Expression[] args)
          Semi-deprecated - instead should be set at Inline time.
 int numArgs()
          Return minArgs()|(maxArgs<<12).
 
Methods inherited from class gnu.mapping.MethodProc
applyN, getParameterType, isApplicable, matchFailAsException, mostSpecific, mostSpecific, numParameters, resolveParameterTypes
 
Methods inherited from class gnu.mapping.ProcedureN
apply0, apply1, apply2, apply3, apply4
 
Methods inherited from class gnu.mapping.Procedure
apply, check0, check1, check2, check3, check4, checkArgCount, checkN, getSetter, getSourceLocation, isSideEffectFree, match0, match1, match2, match3, match4, matchN, maxArgs, maxArgs, minArgs, minArgs, set0, set1, setN, setSetter, setSourceLocation, toString
 
Methods inherited from class gnu.mapping.PropertySet
getName, getProperty, getSymbol, removeProperty, setName, setProperty, setProperty, setSymbol
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

typeSwitch

public static final TypeSwitch typeSwitch
Constructor Detail

TypeSwitch

public TypeSwitch(java.lang.String name)
Method Detail

numArgs

public int numArgs()
Description copied from class: Procedure
Return minArgs()|(maxArgs<<12). We use a single virtual function to reduce the number of methods in the system, as well as the number of virtual method table entries. We shift by 12 so the number can normally be represented using a sipush instruction, without requiring a constant pool entry.

Overrides:
numArgs in class Procedure

apply

public void apply(CallContext ctx)
           throws java.lang.Throwable
Description copied from class: Procedure
Call this Procedure using the explicit-CallContext-convention. The input arguments are (by default) in stack.args; the result is written to ctx.consumer.

Overrides:
apply in class Procedure
Throws:
java.lang.Throwable

compile

public void compile(ApplyExp exp,
                    Compilation comp,
                    Target target)
Specified by:
compile in interface Inlineable

getReturnType

public Type getReturnType(Expression[] args)
Description copied from class: Procedure
Semi-deprecated - instead should be set at Inline time. FIXME

Overrides:
getReturnType in class Procedure