Search in sources :

Example 16 with ExprString

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

the class AbstrCFMLExprTransformer method string.

/*private Expression variable(Data data) throws TemplateException {
		Expression expr=null;
		
		// Dynamic
		if((expr=dynamic(data))!=null) {
			expr = subDynamic(data,expr);
			data.mode=DYNAMIC;
			return expr;
		} 
		return null;
	}*/
/**
 * Transfomiert einen lierale Zeichenkette.
 * <br />
 * EBNF:<br />
 * <code>("'" {"##"|"''"|"#" impOp "#"| ?-"#"-"'" } "'") |
 *	                 (""" {"##"|""""|"#" impOp "#"| ?-"#"-""" } """);</code>
 * @param data
 * @return CFXD Element
 * @throws TemplateException
 */
protected Expression string(ExprData data) throws TemplateException {
    // check starting character for a string literal
    if (!data.srcCode.isCurrent('"') && !data.srcCode.isCurrent('\''))
        return null;
    Position line = data.srcCode.getPosition();
    // Init Parameter
    char quoter = data.srcCode.getCurrentLower();
    StringBuilder str = new StringBuilder();
    Expression expr = null;
    while (data.srcCode.hasNext()) {
        data.srcCode.next();
        // check sharp
        if (data.srcCode.isCurrent('#')) {
            // Ecaped sharp
            if (data.srcCode.isNext('#')) {
                data.srcCode.next();
                str.append('#');
            } else // get Content of sharp
            {
                data.srcCode.next();
                comments(data);
                Expression inner = assignOp(data);
                comments(data);
                if (!data.srcCode.isCurrent('#'))
                    throw new TemplateException(data.srcCode, "Invalid Syntax Closing [#] not found");
                ExprString exprStr = null;
                if (str.length() != 0) {
                    exprStr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
                    if (expr != null) {
                        expr = data.factory.opString(expr, exprStr);
                    } else
                        expr = exprStr;
                    str = new StringBuilder();
                }
                if (expr == null) {
                    expr = inner;
                } else {
                    expr = data.factory.opString(expr, inner);
                }
            }
        } else // check quoter
        if (data.srcCode.isCurrent(quoter)) {
            // Ecaped sharp
            if (data.srcCode.isNext(quoter)) {
                data.srcCode.next();
                str.append(quoter);
            } else // finsish
            {
                break;
            }
        } else // all other character
        {
            str.append(data.srcCode.getCurrent());
        }
    }
    if (!data.srcCode.forwardIfCurrent(quoter))
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + quoter + "] not found");
    if (expr == null)
        expr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
    else if (str.length() != 0) {
        expr = data.factory.opString(expr, data.factory.createLitString(str.toString(), line, data.srcCode.getPosition()));
    }
    comments(data);
    if (expr instanceof Variable) {
        Variable var = (Variable) expr;
        var.fromHash(true);
    }
    return expr;
}
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) TemplateException(lucee.runtime.exp.TemplateException) ExprString(lucee.transformer.expression.ExprString)

Example 17 with ExprString

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

the class TryCatchFinally method addCatch.

/**
 * @param type
 * @param name
 * @param b
 * @param line
 * @throws TransformerException
 */
public void addCatch(Expression type, Expression name, Body b, Position line) throws TransformerException {
    // type
    if (type == null || type instanceof ExprString)
        ;
    else if (type instanceof Variable) {
        type = VariableString.toExprString(type);
    } else
        throw new TransformerException("type from catch statement is invalid", type.getStart());
    // name
    if (name instanceof LitString) {
        Variable v = getFactory().createVariable(Scope.SCOPE_UNDEFINED, name.getStart(), name.getEnd());
        v.addMember(getFactory().createDataMember(getFactory().toExprString(name)));
        name = new VariableRef(v, true);
    } else if (name instanceof Variable)
        name = new VariableRef((Variable) name, true);
    else
        throw new TransformerException("name from catch statement is invalid", name.getStart());
    addCatch((ExprString) type, (VariableRef) name, b, line);
}
Also used : LitString(lucee.transformer.expression.literal.LitString) VariableRef(lucee.transformer.bytecode.expression.var.VariableRef) Variable(lucee.transformer.expression.var.Variable) ExprString(lucee.transformer.expression.ExprString) TransformerException(lucee.transformer.TransformerException)

Example 18 with ExprString

use of lucee.transformer.expression.ExprString 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 19 with ExprString

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

the class VT method _writeOutFirstDataMember.

Type _writeOutFirstDataMember(BytecodeContext bc, DataMember member, int scope, boolean last, boolean doOnlyScope, Expression defaultValue, RefInteger startIndex) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    if (startIndex != null)
        startIndex.setValue(doOnlyScope ? 0 : 1);
    // this/static
    if (scope == Scope.SCOPE_UNDEFINED) {
        ExprString name = member.getName();
        if (ASMUtil.isDotKey(name)) {
            LitString ls = (LitString) name;
            // THIS
            if (ls.getString().equalsIgnoreCase("THIS")) {
                if (startIndex != null)
                    startIndex.setValue(1);
                adapter.loadArg(0);
                adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
                if (defaultValue != null) {
                    defaultValue.writeOut(bc, MODE_REF);
                    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? THIS_GET1 : THIS_TOUCH1);
                } else
                    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? THIS_GET0 : THIS_TOUCH0);
                return Types.OBJECT;
            }
            // STATIC
            if (ls.getString().equalsIgnoreCase("STATIC")) {
                if (startIndex != null)
                    startIndex.setValue(1);
                adapter.loadArg(0);
                adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
                if (defaultValue != null) {
                    defaultValue.writeOut(bc, MODE_REF);
                    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? STATIC_GET1 : STATIC_TOUCH1);
                } else
                    adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, (countFM + countDM) == 1 ? STATIC_GET0 : STATIC_TOUCH0);
                return Types.OBJECT;
            }
        }
    }
    if (member.getSafeNavigated())
        adapter.loadArg(0);
    // collection
    Type rtn;
    if (scope == Scope.SCOPE_LOCAL && defaultValue != null) {
        // local
        adapter.loadArg(0);
        adapter.checkCast(Types.PAGE_CONTEXT_IMPL);
        getFactory().FALSE().writeOut(bc, MODE_VALUE);
        defaultValue.writeOut(bc, MODE_VALUE);
        adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, TypeScope.METHOD_LOCAL_EL);
        rtn = Types.OBJECT;
    } else {
        // all other scopes
        adapter.loadArg(0);
        rtn = TypeScope.invokeScope(adapter, scope);
    }
    if (doOnlyScope)
        return rtn;
    getFactory().registerKey(bc, member.getName(), false);
    boolean _last = !last && scope == Scope.SCOPE_UNDEFINED;
    if (!member.getSafeNavigated()) {
        adapter.invokeInterface(TypeScope.SCOPES[scope], _last ? METHOD_SCOPE_GET_COLLECTION_KEY : METHOD_SCOPE_GET_KEY);
    } else {
        // LDEV-1201
        Expression val = member.getSafeNavigatedValue();
        if (val == null)
            ASMConstants.NULL(bc.getAdapter());
        else
            val.writeOut(bc, Expression.MODE_REF);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, _last ? GET_COLLECTION[THREE] : GET[THREE]);
    }
    return Types.OBJECT;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Type(org.objectweb.asm.Type) ExprString(lucee.transformer.expression.ExprString) Expression(lucee.transformer.expression.Expression) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 20 with ExprString

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

ExprString (lucee.transformer.expression.ExprString)22 LitString (lucee.transformer.expression.literal.LitString)15 Expression (lucee.transformer.expression.Expression)9 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)8 Type (org.objectweb.asm.Type)6 TemplateException (lucee.runtime.exp.TemplateException)4 FunctionAsExpression (lucee.transformer.bytecode.expression.FunctionAsExpression)4 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)4 Variable (lucee.transformer.expression.var.Variable)4 Method (org.objectweb.asm.commons.Method)4 OpVariable (lucee.transformer.bytecode.op.OpVariable)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 ExprBoolean (lucee.transformer.expression.ExprBoolean)3 ExprDouble (lucee.transformer.expression.ExprDouble)3 DataMember (lucee.transformer.expression.var.DataMember)3 Member (lucee.transformer.expression.var.Member)3 Position (lucee.transformer.Position)2 TransformerException (lucee.transformer.TransformerException)2 Body (lucee.transformer.bytecode.Body)2 Argument (lucee.transformer.bytecode.expression.var.Argument)2