Search in sources :

Example 6 with ExprBoolean

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

the class AbstrCFMLScriptTransformer method condition.

/**
 * Ruft die Methode expression der zu vererbenten Klasse auf
 * und prueft ob der Rueckgabewert einen boolschen Wert repraesentiert und castet den Wert allenfalls.
 * <br />
 * EBNF:<br />
 * <code>TemplateException::expression;</code>
 * @return condition
 * @throws TemplateException
 */
private final ExprBoolean condition(ExprData data) throws TemplateException {
    ExprBoolean condition = null;
    comments(data);
    condition = CastBoolean.toExprBoolean(super.expression(data));
    comments(data);
    return condition;
}
Also used : ExprBoolean(lucee.transformer.expression.ExprBoolean)

Example 7 with ExprBoolean

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

the class TagInclude method _writeOut.

/**
 * @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    Type type = Types.PAGE_CONTEXT;
    Method func = DO_INCLUDE_RUN_ONCE2;
    // cachedwithin
    Expression cachedwithin = null;
    Attribute attr = getAttribute("cachedwithin");
    if (attr != null && attr.getValue() != null) {
        cachedwithin = attr.getValue();
        type = Types.PAGE_CONTEXT_IMPL;
        func = DO_INCLUDE_RUN_ONCE3;
    }
    GeneratorAdapter adapter = bc.getAdapter();
    adapter.loadArg(0);
    if (cachedwithin != null)
        adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
    // template
    getAttribute("template").getValue().writeOut(bc, Expression.MODE_REF);
    // run Once
    attr = getAttribute("runonce");
    ExprBoolean expr = (attr == null) ? bc.getFactory().FALSE() : bc.getFactory().toExprBoolean(attr.getValue());
    expr.writeOut(bc, Expression.MODE_VALUE);
    // cachedwithin
    if (cachedwithin != null)
        cachedwithin.writeOut(bc, Expression.MODE_REF);
    adapter.invokeVirtual(type, func);
}
Also used : Type(org.objectweb.asm.Type) Expression(lucee.transformer.expression.Expression) ExprBoolean(lucee.transformer.expression.ExprBoolean) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) Method(org.objectweb.asm.commons.Method)

Example 8 with ExprBoolean

use of lucee.transformer.expression.ExprBoolean 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 9 with ExprBoolean

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

the class AbstrCFMLExprTransformer method conditionalOp.

private Expression conditionalOp(ExprData data) throws TemplateException {
    Expression expr = impOp(data);
    if (data.srcCode.forwardIfCurrent('?')) {
        comments(data);
        // Elvis
        if (data.srcCode.forwardIfCurrent(':')) {
            comments(data);
            Expression right = assignOp(data);
            if (expr instanceof ExprBoolean)
                return expr;
            if (!(expr instanceof Variable))
                throw new TemplateException(data.srcCode, "left operand of the Elvis operator has to be a variable or a function call");
            Variable left = (Variable) expr;
            /*List<Member> members = left.getMembers();
				Member last=null;
				for(Member m:members) {
					last=m;
					m.setSafeNavigated(true);
				}
				if(last!=null) {
					last.setSafeNavigatedValue(right);
				}
				return left;*/
            return OpElvis.toExpr(left, right);
        }
        Expression left = assignOp(data);
        comments(data);
        if (!data.srcCode.forwardIfCurrent(':'))
            throw new TemplateException(data.srcCode, "invalid conditional operator");
        comments(data);
        Expression right = assignOp(data);
        expr = OpContional.toExpr(expr, left, right);
    }
    return expr;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TemplateException(lucee.runtime.exp.TemplateException) ExprBoolean(lucee.transformer.expression.ExprBoolean)

Aggregations

ExprBoolean (lucee.transformer.expression.ExprBoolean)9 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)6 Type (org.objectweb.asm.Type)4 ExprDouble (lucee.transformer.expression.ExprDouble)3 ExprString (lucee.transformer.expression.ExprString)3 Expression (lucee.transformer.expression.Expression)3 Method (org.objectweb.asm.commons.Method)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TemplateException (lucee.runtime.exp.TemplateException)1 FunctionArgument (lucee.runtime.type.FunctionArgument)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 OpDouble (lucee.transformer.bytecode.op.OpDouble)1 OpVariable (lucee.transformer.bytecode.op.OpVariable)1 Argument (lucee.transformer.bytecode.statement.Argument)1 ExprFloat (lucee.transformer.expression.ExprFloat)1 LitString (lucee.transformer.expression.literal.LitString)1 Literal (lucee.transformer.expression.literal.Literal)1 Variable (lucee.transformer.expression.var.Variable)1 Label (org.objectweb.asm.Label)1