Search in sources :

Example 1 with Invoker

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

Aggregations

TemplateException (lucee.runtime.exp.TemplateException)1 Position (lucee.transformer.Position)1 ExpressionInvoker (lucee.transformer.bytecode.expression.ExpressionInvoker)1 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)1 FunctionMember (lucee.transformer.bytecode.expression.var.FunctionMember)1 ExprString (lucee.transformer.expression.ExprString)1 Expression (lucee.transformer.expression.Expression)1 Invoker (lucee.transformer.expression.Invoker)1 LitString (lucee.transformer.expression.literal.LitString)1 DataMember (lucee.transformer.expression.var.DataMember)1 Member (lucee.transformer.expression.var.Member)1