Search in sources :

Example 21 with Variable

use of lucee.transformer.expression.var.Variable in project Lucee by lucee.

the class AbstrCFMLExprTransformer method _plusMinusOp.

private Expression _plusMinusOp(ExprData data, Expression expr, int opr) throws TemplateException {
    // plus|Minus Assignment
    if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
        data.srcCode.next();
        comments(data);
        Expression value = assignOp(data);
        // if(opr==OpDouble.MINUS) value=OpNegateNumber.toExprDouble(value, null, null);
        expr = new OPUnary((Variable) expr, value, OPUnary.PRE, opr, expr.getStart(), data.srcCode.getPosition());
    // ExprDouble res = OpDouble.toExprDouble(expr, right,opr);
    // expr=new OpVariable((Variable)expr,res,data.cfml.getPosition());
    } else {
        comments(data);
        expr = OpDouble.toExprDouble(expr, modOp(data), opr);
    }
    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) OPUnary(lucee.transformer.bytecode.op.OPUnary)

Example 22 with Variable

use of lucee.transformer.expression.var.Variable in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method expressionStatement.

/**
 * List mithilfe des data.CFMLExprTransformer einen Ausruck ein.
 * <br />
 * EBNF:<br />
 * <code>expression ";";</code>
 * @param parent
 * @return Ausdruck
 * @throws TemplateException
 */
private Statement expressionStatement(ExprData data, Body parent) throws TemplateException {
    // first we check if we have a access modifier
    int pos = data.srcCode.getPos();
    int access = -1;
    boolean _final = false;
    if (data.context == CTX_CFC || data.context == CTX_STATIC) {
        if (data.srcCode.forwardIfCurrent("final ")) {
            _final = true;
            comments(data);
        }
        if (data.srcCode.forwardIfCurrent("private ")) {
            access = Component.ACCESS_PRIVATE;
            comments(data);
        } else if (data.srcCode.forwardIfCurrent("package ")) {
            access = Component.ACCESS_PACKAGE;
            comments(data);
        } else if (data.srcCode.forwardIfCurrent("public ")) {
            access = Component.ACCESS_PUBLIC;
            comments(data);
        } else if (data.srcCode.forwardIfCurrent("remote ")) {
            access = Component.ACCESS_REMOTE;
            // comments(data);
            throw new TemplateException(data.srcCode, "access modifier [remote] not supported in this context");
        }
        if (!_final && data.srcCode.forwardIfCurrent("final ")) {
            _final = true;
            comments(data);
        }
    }
    Expression expr = expression(data);
    checkSemiColonLineFeed(data, true, true, false);
    // variable declaration (variable in body)
    if (expr instanceof Variable) {
        Variable v = (Variable) expr;
        if (ASMUtil.isOnlyDataMember(v)) {
            expr = new Assign(v, data.srcCode.getDialect() == CFMLEngine.DIALECT_LUCEE || data.config.getFullNullSupport() ? data.factory.createNull() : data.factory.EMPTY(), data.srcCode.getPosition());
        }
    }
    // if a specific access was defined
    if (access > -1 || _final) {
        if (!(expr instanceof Assign)) {
            data.srcCode.setPos(pos);
            throw new TemplateException(data.srcCode, "invalid syntax, access modifier cannot be used in this context");
        }
        if (access > -1) {
            // this is only supported with the Lucee dialect
            // if(data.srcCode.getDialect()==CFMLEngine.DIALECT_CFML)
            // throw new TemplateException(data.srcCode,
            // "invalid syntax, access modifier cannot be used in this context");
            ((Assign) expr).setAccess(access);
        }
        if (_final)
            ((Assign) expr).setModifier(Member.MODIFIER_FINAL);
    }
    if (expr instanceof FunctionAsExpression)
        return ((FunctionAsExpression) expr).getFunction();
    return new ExpressionAsStatement(expr);
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Variable(lucee.transformer.expression.var.Variable) TemplateException(lucee.runtime.exp.TemplateException) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) Assign(lucee.transformer.bytecode.expression.var.Assign) ExpressionAsStatement(lucee.transformer.bytecode.statement.ExpressionAsStatement)

Example 23 with Variable

use of lucee.transformer.expression.var.Variable in project Lucee by lucee.

the class AbstrCFMLScriptTransformer method forStatement.

/**
 * Liest ein for Statement ein.
 * <br />
 * EBNF:<br />
 * <code>expression spaces ";" spaces condition spaces ";" spaces expression spaces ")" spaces block;</code>
 * @return for Statement
 * @throws TemplateException
 */
private final Statement forStatement(ExprData data) throws TemplateException {
    int pos = data.srcCode.getPos();
    // id
    String id = variableDec(data, false);
    if (id == null) {
        data.srcCode.setPos(pos);
        return null;
    }
    if (id.equalsIgnoreCase("for")) {
        id = null;
        data.srcCode.removeSpace();
        if (!data.srcCode.forwardIfCurrent('(')) {
            data.srcCode.setPos(pos);
            return null;
        }
    } else {
        data.srcCode.removeSpace();
        if (!data.srcCode.forwardIfCurrent(':')) {
            data.srcCode.setPos(pos);
            return null;
        }
        data.srcCode.removeSpace();
        if (!data.srcCode.forwardIfCurrent("for", '(')) {
            data.srcCode.setPos(pos);
            return null;
        }
    }
    // if(!data.srcCode.forwardIfCurrent("for",'('))
    // return null;
    Expression left = null;
    Body body = new BodyBase(data.factory);
    Position line = data.srcCode.getPosition();
    comments(data);
    if (!data.srcCode.isCurrent(';')) {
        // left
        left = expression(data);
        comments(data);
    }
    // middle for
    if (data.srcCode.forwardIfCurrent(';')) {
        Expression cont = null;
        Expression update = null;
        // condition
        comments(data);
        if (!data.srcCode.isCurrent(';')) {
            cont = condition(data);
            comments(data);
        }
        // middle
        if (!data.srcCode.forwardIfCurrent(';'))
            throw new TemplateException(data.srcCode, "invalid syntax in for statement");
        // update
        comments(data);
        if (!data.srcCode.isCurrent(')')) {
            update = expression(data);
            comments(data);
        }
        // start )
        if (!data.srcCode.forwardIfCurrent(')'))
            throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
        // ex block
        statement(data, body, CTX_FOR);
        return new For(data.factory, left, cont, update, body, line, data.srcCode.getPosition(), id);
    } else // middle foreach
    if (data.srcCode.forwardIfCurrent("in")) {
        // condition
        comments(data);
        Expression value = expression(data);
        comments(data);
        if (!data.srcCode.forwardIfCurrent(')'))
            throw new TemplateException(data.srcCode, "invalid syntax in for statement, for statement must end with a [)]");
        // ex block
        statement(data, body, CTX_FOR);
        if (!(left instanceof Variable))
            throw new TemplateException(data.srcCode, "invalid syntax in for statement, left value is invalid");
        // throw new TemplateException(data.srcCode,"invalid syntax in for statement, right value is invalid");
        return new ForEach((Variable) left, value, body, line, data.srcCode.getPosition(), id);
    } else
        throw new TemplateException(data.srcCode, "invalid syntax in for statement");
}
Also used : Variable(lucee.transformer.expression.var.Variable) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) For(lucee.transformer.bytecode.statement.For) Body(lucee.transformer.bytecode.Body) ScriptBody(lucee.transformer.bytecode.ScriptBody) FunctionBody(lucee.transformer.bytecode.FunctionBody) BodyBase(lucee.transformer.bytecode.BodyBase) ForEach(lucee.transformer.bytecode.statement.ForEach)

Example 24 with Variable

use of lucee.transformer.expression.var.Variable in project Lucee by lucee.

the class AbstrCFMLExprTransformer method _divMultiOp.

private Expression _divMultiOp(ExprData data, Expression expr, int iOp) throws TemplateException {
    if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
        data.srcCode.next();
        comments(data);
        Expression value = assignOp(data);
        return new OPUnary((Variable) expr, value, OPUnary.PRE, iOp, expr.getStart(), data.srcCode.getPosition());
    // ExprDouble res = OpDouble.toExprDouble(expr, right,iOp);
    // return new OpVariable((Variable)expr,res,data.cfml.getPosition());
    }
    comments(data);
    return OpDouble.toExprDouble(expr, expoOp(data), iOp);
}
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) OPUnary(lucee.transformer.bytecode.op.OPUnary)

Example 25 with Variable

use of lucee.transformer.expression.var.Variable in project Lucee by lucee.

the class AbstrCFMLExprTransformer method negatePlusMinusOp.

/**
 * Negate Numbers
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression negatePlusMinusOp(ExprData data) throws TemplateException {
    // And Operation
    Position line = data.srcCode.getPosition();
    if (data.srcCode.forwardIfCurrent('-')) {
        // pre increment
        if (data.srcCode.forwardIfCurrent('-')) {
            comments(data);
            Expression expr = clip(data);
            return new OPUnary((Variable) expr, data.factory.DOUBLE_ONE(), OPUnary.PRE, OpDouble.MINUS, line, data.srcCode.getPosition());
        // ExprDouble res = OpDouble.toExprDouble(expr, LitDouble.toExprDouble(1D),OpDouble.MINUS);
        // return new OpVariable((Variable)expr,res,data.cfml.getPosition());
        }
        comments(data);
        return OpNegateNumber.toExprDouble(clip(data), OpNegateNumber.MINUS, line, data.srcCode.getPosition());
    } else if (data.srcCode.forwardIfCurrent('+')) {
        if (data.srcCode.forwardIfCurrent('+')) {
            comments(data);
            Expression expr = clip(data);
            return new OPUnary((Variable) expr, data.factory.DOUBLE_ONE(), OPUnary.PRE, OpDouble.PLUS, line, data.srcCode.getPosition());
        }
        comments(data);
        // OpNegateNumber.toExprDouble(clip(),OpNegateNumber.PLUS,line);
        return data.factory.toExprDouble(clip(data));
    }
    return clip(data);
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) OPUnary(lucee.transformer.bytecode.op.OPUnary)

Aggregations

Variable (lucee.transformer.expression.var.Variable)26 Expression (lucee.transformer.expression.Expression)16 OpVariable (lucee.transformer.bytecode.op.OpVariable)14 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)12 TemplateException (lucee.runtime.exp.TemplateException)8 Position (lucee.transformer.Position)5 Argument (lucee.transformer.bytecode.expression.var.Argument)5 BIF (lucee.transformer.bytecode.expression.var.BIF)5 ExprString (lucee.transformer.expression.ExprString)5 OPUnary (lucee.transformer.bytecode.op.OPUnary)4 LitString (lucee.transformer.expression.literal.LitString)4 Member (lucee.transformer.expression.var.Member)4 Body (lucee.transformer.bytecode.Body)3 Assign (lucee.transformer.bytecode.expression.var.Assign)3 Literal (lucee.transformer.expression.literal.Literal)3 TransformerException (lucee.transformer.TransformerException)2 Statement (lucee.transformer.bytecode.Statement)2 FunctionMember (lucee.transformer.bytecode.expression.var.FunctionMember)2 NamedArgument (lucee.transformer.bytecode.expression.var.NamedArgument)2 Identifier (lucee.transformer.bytecode.literal.Identifier)2