Search in sources :

Example 41 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class Function method createArguments.

private final void createArguments(BytecodeContext bc) throws TransformerException {
    GeneratorAdapter ga = bc.getAdapter();
    ga.push(arguments.size());
    ga.newArray(FUNCTION_ARGUMENT);
    Argument arg;
    for (int i = 0; i < arguments.size(); i++) {
        arg = arguments.get(i);
        boolean canHaveKey = Factory.canRegisterKey(arg.getName());
        // CHECK if default values
        // type
        ExprString _strType = arg.getType();
        short _type = CFTypes.TYPE_UNKNOW;
        if (_strType instanceof LitString) {
            _type = CFTypes.toShortStrict(((LitString) _strType).getString(), CFTypes.TYPE_UNKNOW);
        }
        boolean useType = !canHaveKey || _type != CFTypes.TYPE_ANY;
        // boolean useStrType=useType && (_type==CFTypes.TYPE_UNDEFINED || _type==CFTypes.TYPE_UNKNOW || CFTypes.toString(_type, null)==null);
        // required
        ExprBoolean _req = arg.getRequired();
        boolean useReq = !canHaveKey || toBoolean(_req, null) != Boolean.FALSE;
        // default-type
        Expression _def = arg.getDefaultValueType(bc.getFactory());
        boolean useDef = !canHaveKey || toInt(_def, -1) != FunctionArgument.DEFAULT_TYPE_NULL;
        // pass by reference
        ExprBoolean _pass = arg.isPassByReference();
        boolean usePass = !canHaveKey || toBoolean(_pass, null) != Boolean.TRUE;
        // display-hint
        ExprString _dsp = arg.getDisplayName();
        boolean useDsp = !canHaveKey || !isLiteralEmptyString(_dsp);
        // hint
        ExprString _hint = arg.getHint();
        boolean useHint = !canHaveKey || !isLiteralEmptyString(_hint);
        // meta
        Map _meta = arg.getMetaData();
        boolean useMeta = !canHaveKey || (_meta != null && !_meta.isEmpty());
        int functionIndex = 7;
        if (!useMeta) {
            functionIndex--;
            if (!useHint) {
                functionIndex--;
                if (!useDsp) {
                    functionIndex--;
                    if (!usePass) {
                        functionIndex--;
                        if (!useDef) {
                            functionIndex--;
                            if (!useReq) {
                                functionIndex--;
                                if (!useType) {
                                    functionIndex--;
                                }
                            }
                        }
                    }
                }
            }
        }
        // write out arguments
        ga.dup();
        ga.push(i);
        // new FunctionArgument(...)
        ga.newInstance(canHaveKey && functionIndex < INIT_FAI_KEY_LIGHT.length ? FUNCTION_ARGUMENT_LIGHT : FUNCTION_ARGUMENT_IMPL);
        ga.dup();
        // name
        bc.getFactory().registerKey(bc, arg.getName(), false);
        // type
        if (functionIndex >= INIT_FAI_KEY.length - 7) {
            _strType.writeOut(bc, Expression.MODE_REF);
            bc.getAdapter().push(_type);
        }
        // required
        if (functionIndex >= INIT_FAI_KEY.length - 6)
            _req.writeOut(bc, Expression.MODE_VALUE);
        // default value
        if (functionIndex >= INIT_FAI_KEY.length - 5)
            _def.writeOut(bc, Expression.MODE_VALUE);
        // pass by reference
        if (functionIndex >= INIT_FAI_KEY.length - 4)
            _pass.writeOut(bc, Expression.MODE_VALUE);
        // display-name
        if (functionIndex >= INIT_FAI_KEY.length - 3)
            _dsp.writeOut(bc, Expression.MODE_REF);
        // hint
        if (functionIndex >= INIT_FAI_KEY.length - 2)
            _hint.writeOut(bc, Expression.MODE_REF);
        // meta
        if (functionIndex == INIT_FAI_KEY.length - 1)
            Page.createMetaDataStruct(bc, _meta, null);
        if (functionIndex < INIT_FAI_KEY_LIGHT.length)
            ga.invokeConstructor(FUNCTION_ARGUMENT_LIGHT, INIT_FAI_KEY[functionIndex]);
        else
            ga.invokeConstructor(FUNCTION_ARGUMENT_IMPL, INIT_FAI_KEY[functionIndex]);
        ga.visitInsn(Opcodes.AASTORE);
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Argument(lucee.transformer.bytecode.statement.Argument) FunctionArgument(lucee.runtime.type.FunctionArgument) ExprString(lucee.transformer.expression.ExprString) Expression(lucee.transformer.expression.Expression) ExprBoolean(lucee.transformer.expression.ExprBoolean) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 42 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class BodyBase method addStatement.

/**
 * @see lucee.transformer.bytecode.Body#addStatement(lucee.transformer.bytecode.Statement)
 */
@Override
public void addStatement(Statement statement) {
    if (statement instanceof PrintOut) {
        Expression expr = ((PrintOut) statement).getExpr();
        if (expr instanceof LitString && concatPrintouts(((LitString) expr).getString()))
            return;
    }
    statement.setParent(this);
    this.statements.add(statement);
    last = statement;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression)

Example 43 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeOutFunctionDefaultValueInnerInner.

private void writeOutFunctionDefaultValueInnerInner(BytecodeContext bc, Function function) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    List<Argument> args = function.getArguments();
    if (args.size() == 0) {
        adapter.loadArg(DEFAULT_VALUE);
        adapter.returnValue();
        return;
    }
    Iterator<Argument> it = args.iterator();
    Argument arg;
    ConditionVisitor cv = new ConditionVisitor();
    DecisionIntVisitor div;
    cv.visitBefore();
    int count = 0;
    while (it.hasNext()) {
        arg = it.next();
        cv.visitWhenBeforeExpr();
        div = new DecisionIntVisitor();
        div.visitBegin();
        adapter.loadArg(2);
        div.visitEQ();
        adapter.push(count++);
        div.visitEnd(bc);
        cv.visitWhenAfterExprBeforeBody(bc);
        Expression defaultValue = arg.getDefaultValue();
        if (defaultValue != null) {
            /*if(defaultValue instanceof Null) {
						adapter.invokeStatic(NULL, GET_INSTANCE);
					}
					else*/
            defaultValue.writeOut(bc, Expression.MODE_REF);
        } else
            adapter.loadArg(DEFAULT_VALUE);
        // adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        cv.visitWhenAfterBody(bc);
    }
    cv.visitOtherviseBeforeBody();
    // adapter.visitInsn(ACONST_NULL);
    // adapter.returnValue();
    cv.visitOtherviseAfterBody();
    cv.visitAfter(bc);
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) Argument(lucee.transformer.bytecode.statement.Argument) Expression(lucee.transformer.expression.Expression) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) DecisionIntVisitor(lucee.transformer.bytecode.visitor.DecisionIntVisitor)

Example 44 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeOutNewComponent.

private void writeOutNewComponent(ConstrBytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component, String name) throws TransformerException {
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
    BytecodeContext bc = new BytecodeContext(null, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output, returnValue);
    Label methodBegin = new Label();
    Label methodEnd = new Label();
    adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0);
    ExpressionUtil.visitLine(bc, component.getStart());
    adapter.visitLabel(methodBegin);
    int comp = adapter.newLocal(Types.COMPONENT_IMPL);
    adapter.newInstance(Types.COMPONENT_IMPL);
    adapter.dup();
    Attribute attr;
    // ComponentPage
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.checkCast(Types.COMPONENT_PAGE_IMPL);
    // !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!!
    // Output
    attr = component.removeAttribute("output");
    if (attr != null) {
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    } else
        ASMConstants.NULL(adapter);
    // synchronized
    attr = component.removeAttribute("synchronized");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE);
    else
        adapter.push(false);
    // extends
    attr = component.removeAttribute("extends");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // implements
    attr = component.removeAttribute("implements");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // hint
    attr = component.removeAttribute("hint");
    if (attr != null) {
        Expression value = attr.getValue();
        if (!(value instanceof Literal)) {
            value = bc.getFactory().createLitString("[runtime expression]");
        }
        ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF);
    } else
        adapter.push("");
    // dspName
    attr = component.removeAttribute("displayname");
    if (attr == null)
        attr = component.getAttribute("display");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // callpath
    adapter.visitVarInsn(Opcodes.ALOAD, 2);
    // realpath
    adapter.visitVarInsn(Opcodes.ILOAD, 3);
    // style
    attr = component.removeAttribute("style");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // persistent
    attr = component.removeAttribute("persistent");
    boolean persistent = false;
    if (attr != null) {
        persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
    }
    // accessors
    attr = component.removeAttribute("accessors");
    boolean accessors = false;
    if (attr != null) {
        accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
    }
    // modifier
    attr = component.removeAttribute("modifier");
    int modifiers = Component.MODIFIER_NONE;
    if (attr != null) {
        // type already evaluated in evaluator
        LitString ls = (LitString) component.getFactory().toExprString(attr.getValue());
        modifiers = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, lucee.runtime.Component.MODIFIER_NONE);
    }
    adapter.push(persistent);
    adapter.push(accessors);
    adapter.push(modifiers);
    adapter.visitVarInsn(Opcodes.ILOAD, 4);
    // adapter.visitVarInsn(Opcodes.ALOAD, 4);
    createMetaDataStruct(bc, component.getAttributes(), component.getMetaData());
    adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL15);
    adapter.storeLocal(comp);
    // Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName)
    // initComponent(pc,c);
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.loadArg(0);
    adapter.loadLocal(comp);
    adapter.loadArg(4);
    adapter.invokeVirtual(Types.COMPONENT_PAGE_IMPL, INIT_COMPONENT3);
    adapter.visitLabel(methodEnd);
    // return component;
    adapter.loadLocal(comp);
    adapter.returnValue();
    // ExpressionUtil.visitLine(adapter, component.getEndLine());
    adapter.endMethod();
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) Label(org.objectweb.asm.Label) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 45 with Expression

use of lucee.transformer.expression.Expression in project Lucee by lucee.

the class Call method _writeOut.

@Override
public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter ga = bc.getAdapter();
    ga.loadArg(0);
    expr.writeOut(bc, MODE_REF);
    ExpressionUtil.writeOutExpressionArray(bc, Types.OBJECT, args.toArray(new Expression[args.size()]));
    ga.invokeStatic(Types.PAGE_CONTEXT_UTIL, namedArgs() ? GET_FUNCTION_WITH_NAMED_ARGS_KEY : GET_FUNCTION_KEY);
    return Types.OBJECT;
}
Also used : Expression(lucee.transformer.expression.Expression) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Aggregations

Expression (lucee.transformer.expression.Expression)74 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)34 LitString (lucee.transformer.expression.literal.LitString)25 TemplateException (lucee.runtime.exp.TemplateException)19 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)16 Variable (lucee.transformer.expression.var.Variable)16 Body (lucee.transformer.bytecode.Body)11 ExprString (lucee.transformer.expression.ExprString)11 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 Position (lucee.transformer.Position)10 OpVariable (lucee.transformer.bytecode.op.OpVariable)10 LitBoolean (lucee.transformer.expression.literal.LitBoolean)8 Literal (lucee.transformer.expression.literal.Literal)8 ArrayList (java.util.ArrayList)7 TransformerException (lucee.transformer.TransformerException)7 BodyBase (lucee.transformer.bytecode.BodyBase)7 Statement (lucee.transformer.bytecode.Statement)7 Argument (lucee.transformer.bytecode.expression.var.Argument)7 PrintOut (lucee.transformer.bytecode.statement.PrintOut)6 FunctionBody (lucee.transformer.bytecode.FunctionBody)5