Class ExpressionCompiler

  • Direct Known Subclasses:
    CompiledExpressionCompiler, ErrorExpressionCompiler, LiteralCompiler, ToBooleanCompiler, ToItemCompiler, ToIteratorCompiler

    public abstract class ExpressionCompiler
    extends java.lang.Object
    This abstract class represents the compiler (that is, Java bytecode generator) for a particular kind of expression on the expression tree. The expression compiler is called by the CompilerService working its way down the expression tree in a top down fashion: there is a one-to-one correspondence between the classes implementing the expression on the expression tree and the compiler object used to generate Java code fragments. Various methods are supplied to compile expressions; exactly one of them is called, depending on the context in which the expression appears.
    • Constructor Detail

      • ExpressionCompiler

        public ExpressionCompiler()
    • Method Detail

      • compileToItem

        public abstract void compileToItem​(CompilerService compiler,
                                           Expression expression)
                                    throws CannotCompileException
        Generate bytecode to evaluate the expression as an Item Precondition: none. Postcondition: at execution time, the stack contains either an item (the result of the expression), or null (representing an empty sequence).
        Parameters:
        compiler - the compiler service
        expression - the expression to be compiled
        Throws:
        CannotCompileException - if the expression cannot be compiled to bytecode
      • compileToIterator

        public abstract void compileToIterator​(CompilerService compiler,
                                               Expression expression)
                                        throws CannotCompileException
        Generate bytecode to evaluate the expression as a SequenceIterator Precondition: none. Postcondition: at execution time, the stack contains a SequenceIterator representing the result of the expression
        Parameters:
        compiler - the compiler service
        expression - the expression to be compiled
        Throws:
        CannotCompileException - if the expression cannot be compiled to bytecode
      • compileToBoolean

        public abstract void compileToBoolean​(CompilerService compiler,
                                              Expression expression)
                                       throws CannotCompileException
        Generate bytecode to evaluate the expression as a boolean Precondition: none. Postcondition: at execution time, the stack contains an integer (0=false, 1=true) representing the result of the expression
        Parameters:
        compiler - the compiler service
        expression - the expression to be compiled
        Throws:
        CannotCompileException - if the expression cannot be compiled to bytecode
      • compileToPrimitive

        public void compileToPrimitive​(CompilerService compiler,
                                       Expression expression,
                                       java.lang.Class requiredClass,
                                       OnEmpty onEmpty)
                                throws CannotCompileException
        Generate bytecode to evaluate the expression leaving a plain Java value on the stack. This method must only be called if the static type of the expressionis such that the value is known to be representable by a value of the specified class; the cardinality must be either exactly-one or zero-or-one.
        Parameters:
        compiler - the compiler service
        expression - the expression to be compiled
        requiredClass - the class of the Java value that is to be left on the stack if the generated code exits normally. This must be one of Integer.TYPE, Double.TYPE, Float.TYPE, BigDecimal.class, CharSequence.class.
        onEmpty - defines the action to be taken if the expression evaluates to the empty sequence. May be null if the expression is known statically not to evaluate to an empty sequence. If the return class is a primitive type (double, float, etc) this must be an instance of OnEmpty.UnwindAndJump
        Throws:
        CannotCompileException - if the expression cannot be compiled to bytecode
      • compileToPush

        public abstract void compileToPush​(CompilerService compiler,
                                           Expression expression)
                                    throws CannotCompileException
        Generate bytecode to evaluate the expression in push mode Precondition: none. Postcondition: at execution time, the stack is unchanged, and the value of the expression has been written to the current receiver
        Parameters:
        compiler - the compiler service
        expression - the expression to be compiled
        Throws:
        CannotCompileException - if the expression cannot be compiled to bytecode
      • compileItemFromInt

        protected final void compileItemFromInt​(CompilerService compiler,
                                                Expression expression)
                                         throws CannotCompileException
        Helper method to implement compileFromItem when the class implements compileToPrimitive returning an integer
        Parameters:
        compiler - the compiler service
        expression - the expression to be compiled
        Throws:
        CannotCompileException - if the expression cannot be compiled to bytecode
      • visitAnnotation

        public static void visitAnnotation​(CompilerService compiler,
                                           java.lang.String message)
        Generate annotations in the bytecode, for diagnostic purposes
        Parameters:
        compiler - the compiler service
        message - the message to be inserted in the bytecode
      • printStackTop

        public static void printStackTop​(CompilerService compiler)
        Print the top entry on the bytecode value stack, for diagnostic purposes
        Parameters:
        compiler - the bytecode compiler service to use
      • allocateStatic

        public static void allocateStatic​(CompilerService compiler,
                                          java.lang.Object value)
        Generate code to allocate static field in widget and to push field on stack
        Parameters:
        compiler - the compiler service
        value - the Object of the field
      • verify

        public static void verify​(org.objectweb.asm.ClassWriter cw,
                                  java.lang.String objectName,
                                  boolean debug)
        Verify the generated bytecode, for diagnostic purposes
        Parameters:
        cw - the ClassWriter
        objectName -
        debug - true if bytecode tracing is required
      • visitLineNumber

        public static void visitLineNumber​(CompilerService compiler,
                                           Generator ga,
                                           Expression expr)
        Generate line number of expression in byte-code
        Parameters:
        compiler - the compiler service
        ga - the generator adapter
        expr - Expression
      • generateMethod

        public void generateMethod​(CompilerService compiler,
                                   Expression expression,
                                   org.objectweb.asm.ClassVisitor cv)