Search in sources :

Example 56 with Expression

use of lucee.transformer.expression.Expression 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)

Example 57 with Expression

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

the class AbstrCFMLExprTransformer method checker.

/**
 * Hier werden die verschiedenen Moeglichen Werte erkannt
 * und jenachdem wird mit der passenden Methode weitergefahren
 * <br />
 * EBNF:<br />
 * <code>string | number | dynamic | sharp;</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression checker(ExprData data) throws TemplateException {
    Expression expr = null;
    // String
    if ((expr = string(data)) != null) {
        expr = subDynamic(data, expr, false, false);
        // (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
        data.mode = STATIC;
        return expr;
    }
    // Number
    if ((expr = number(data)) != null) {
        expr = subDynamic(data, expr, false, false);
        // (expr instanceof Literal)?STATIC:DYNAMIC;// STATIC
        data.mode = STATIC;
        return expr;
    }
    // closure
    if ((expr = closure(data)) != null) {
        data.mode = DYNAMIC;
        return expr;
    }
    // lambda
    if ((expr = lambda(data)) != null) {
        data.mode = DYNAMIC;
        return expr;
    }
    // Dynamic
    if ((expr = dynamic(data)) != null) {
        expr = newOp(data, expr);
        expr = subDynamic(data, expr, true, false);
        data.mode = DYNAMIC;
        return expr;
    }
    // Sharp
    if ((expr = sharp(data)) != null) {
        data.mode = DYNAMIC;
        return expr;
    }
    // JSON
    if ((expr = json(data, JSON_ARRAY, '[', ']')) != null) {
        expr = subDynamic(data, expr, false, false);
        data.mode = DYNAMIC;
        return expr;
    }
    if ((expr = json(data, JSON_STRUCT, '{', '}')) != null) {
        expr = subDynamic(data, expr, false, false);
        data.mode = DYNAMIC;
        return expr;
    }
    // else Error
    throw new TemplateException(data.srcCode, "Syntax Error, Invalid Construct");
}
Also used : FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) TemplateException(lucee.runtime.exp.TemplateException)

Example 58 with Expression

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

the class AbstrCFMLExprTransformer method subDynamic.

private Expression subDynamic(ExprData data, Expression expr, boolean tryStatic, boolean isStaticChild) throws TemplateException {
    String name = null;
    Invoker invoker = null;
    // Loop over nested Variables
    boolean safeNavigation;
    while (data.srcCode.isValidIndex()) {
        safeNavigation = false;
        ExprString nameProp = null, namePropUC = null;
        // []
        if (data.srcCode.forwardIfCurrent('[')) {
            isStaticChild = false;
            // get Next Var
            nameProp = structElement(data);
            namePropUC = nameProp;
            // Valid Syntax ???
            if (!data.srcCode.forwardIfCurrent(']'))
                throw new TemplateException(data.srcCode, "Invalid Syntax Closing []] not found");
        } else // .
        if (isStaticChild || data.srcCode.forwardIfCurrent('.') || (safeNavigation = data.srcCode.forwardIfCurrent('?', '.'))) {
            isStaticChild = false;
            // Extract next Var String
            comments(data);
            Position line = data.srcCode.getPosition();
            name = identifier(data, true);
            if (name == null)
                throw new TemplateException(data.srcCode, "Invalid identifier");
            comments(data);
            nameProp = Identifier.toIdentifier(data.factory, name, line, data.srcCode.getPosition());
            namePropUC = Identifier.toIdentifier(data.factory, name, data.settings.dotNotationUpper ? Identifier.CASE_UPPER : Identifier.CASE_ORIGNAL, line, data.srcCode.getPosition());
        } else // finish
        {
            break;
        }
        comments(data);
        if (expr instanceof Invoker) {
            invoker = (Invoker) expr;
        } else {
            invoker = new ExpressionInvoker(expr);
            expr = invoker;
        }
        // safe navigation
        Member member;
        if (safeNavigation) {
            List<Member> members = invoker.getMembers();
            if (members.size() > 0) {
                member = members.get(members.size() - 1);
                member.setSafeNavigated(true);
            }
        }
        // Method
        if (data.srcCode.isCurrent('(')) {
            // properly this is never used
            if (nameProp == null && name != null)
                nameProp = Identifier.toIdentifier(data.factory, name, Identifier.CASE_ORIGNAL, null, null);
            invoker.addMember(member = getFunctionMember(data, nameProp, false));
        } else
            // property
            invoker.addMember(member = data.factory.createDataMember(namePropUC));
        if (safeNavigation) {
            member.setSafeNavigated(true);
        }
    }
    // STATIC SCOPE CALL
    if (tryStatic) {
        comments(data);
        Expression staticCall = staticScope(data, expr);
        if (staticCall != null)
            return staticCall;
    }
    return expr;
}
Also used : ExpressionInvoker(lucee.transformer.bytecode.expression.ExpressionInvoker) Invoker(lucee.transformer.expression.Invoker) ExpressionInvoker(lucee.transformer.bytecode.expression.ExpressionInvoker) ExprString(lucee.transformer.expression.ExprString) TemplateException(lucee.runtime.exp.TemplateException) Position(lucee.transformer.Position) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member)

Example 59 with Expression

use of lucee.transformer.expression.Expression 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 60 with Expression

use of lucee.transformer.expression.Expression 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)

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