Search in sources :

Example 11 with Variable

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

the class AbstrCFMLExprTransformer method concatOp.

/**
 * Transfomiert eine  Konkatinations-Operator (&) Operation. Im Gegensatz zu CFMX ,
 * wird das "!" Zeichen auch als Not Operator anerkannt.
 * <br />
 * EBNF:<br />
 * <code>plusMinusOp {"&" spaces concatOp};</code>
 * @return CFXD Element
 * @throws TemplateException
 */
private Expression concatOp(ExprData data) throws TemplateException {
    Expression expr = plusMinusOp(data);
    while (data.srcCode.isCurrent('&') && !data.srcCode.isCurrent("&&")) {
        data.srcCode.next();
        // &=
        if (data.srcCode.isCurrent('=') && expr instanceof Variable) {
            data.srcCode.next();
            comments(data);
            Expression value = assignOp(data);
            expr = new OPUnary((Variable) expr, value, OPUnary.PRE, OPUnary.CONCAT, expr.getStart(), data.srcCode.getPosition());
        // ExprString res = OpString.toExprString(expr, right);
        // expr=new OpVariable((Variable)expr,res,data.cfml.getPosition());
        } else {
            comments(data);
            expr = data.factory.opString(expr, plusMinusOp(data));
        }
    }
    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 12 with Variable

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

the class AbstrCFMLExprTransformer method startElement.

/**
 * Extrahiert den Start Element einer Variale,
 * dies ist entweder eine Funktion, eine Scope Definition oder eine undefinierte Variable.
 * <br />
 * EBNF:<br />
 * <code>identifier "(" functionArg ")" | scope | identifier;</code>
 * @param name Einstiegsname
 * @return CFXD Element
 * @throws TemplateException
 */
private Variable startElement(ExprData data, Identifier name, Position line) throws TemplateException {
    // check function
    if (data.srcCode.isCurrent('(')) {
        FunctionMember func = getFunctionMember(data, name, true);
        Variable var = name.getFactory().createVariable(line, data.srcCode.getPosition());
        var.addMember(func);
        comments(data);
        return var;
    }
    // check scope
    Variable var = scope(data, name, line);
    if (var != null)
        return var;
    // undefined variable
    var = name.getFactory().createVariable(line, data.srcCode.getPosition());
    var.addMember(data.factory.createDataMember(name));
    comments(data);
    return var;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) FunctionMember(lucee.transformer.bytecode.expression.var.FunctionMember)

Example 13 with Variable

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

the class AbstrCFMLExprTransformer method staticScope.

private Expression staticScope(ExprData data, Expression expr) throws TemplateException {
    if (data.srcCode.forwardIfCurrent("::")) {
        if (!(expr instanceof Variable))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]");
        Variable old = (Variable) expr;
        // set back to read again as a component path
        data.srcCode.setPos(old.getStart().pos);
        // now we read the component path
        ExprString componentPath = readComponentPath(data);
        if (!data.srcCode.forwardIfCurrent("::"))
            throw new TemplateException(data.srcCode, "invalid syntax before [::]" + data.srcCode.getCurrent());
        comments(data);
        BIF bif = null;
        if (componentPath instanceof LitString) {
            LitString ls = (LitString) componentPath;
            if ("super".equalsIgnoreCase(ls.getString())) {
                bif = ASMUtil.createBif(data, GET_SUPER_STATIC_SCOPE);
            }
        }
        // now we generate a _getStaticScope function call with that path
        if (bif == null) {
            bif = ASMUtil.createBif(data, GET_STATIC_SCOPE);
            bif.addArgument(new Argument(componentPath, "string"));
        }
        Variable var = data.factory.createVariable(old.getStart(), data.srcCode.getPosition());
        var.addMember(bif);
        // now we are reading what is coming after ":::"
        Expression sd = subDynamic(data, var, false, true);
        return sd;
    }
    return null;
}
Also used : LitString(lucee.transformer.expression.literal.LitString) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) NamedArgument(lucee.transformer.bytecode.expression.var.NamedArgument) Argument(lucee.transformer.bytecode.expression.var.Argument) TemplateException(lucee.runtime.exp.TemplateException) ExprString(lucee.transformer.expression.ExprString) FunctionAsExpression(lucee.transformer.bytecode.expression.FunctionAsExpression) Expression(lucee.transformer.expression.Expression) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 14 with Variable

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

the class AbstrCFMLExprTransformer method json.

protected Expression json(ExprData data, FunctionLibFunction flf, char start, char end) throws TemplateException {
    if (!data.srcCode.forwardIfCurrent(start))
        return null;
    Position line = data.srcCode.getPosition();
    data.srcCode.removeSpace();
    // [:|=]
    if (data.srcCode.forwardIfCurrent(':', ']') || data.srcCode.forwardIfCurrent('=', ']')) {
        flf = flf.getFunctionLib().getFunction("_literalOrderedStruct");
        BIF bif = new BIF(data.factory, data.settings, flf);
        bif.setArgType(flf.getArgType());
        try {
            bif.setClassDefinition(flf.getFunctionClassDefinition());
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
            throw new PageRuntimeException(t);
        }
        bif.setReturnType(flf.getReturnTypeAsString());
        data.ep.add(flf, bif, data.srcCode);
        Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
        var.addMember(bif);
        return var;
    }
    BIF bif = new BIF(data.factory, data.settings, flf);
    bif.setArgType(flf.getArgType());
    try {
        bif.setClassDefinition(flf.getFunctionClassDefinition());
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw new PageRuntimeException(t);
    }
    bif.setReturnType(flf.getReturnTypeAsString());
    do {
        comments(data);
        if (data.srcCode.isCurrent(end))
            break;
        bif.addArgument(functionArgument(data, data.settings.dotNotationUpper));
        comments(data);
    } while (data.srcCode.forwardIfCurrent(','));
    comments(data);
    if (!data.srcCode.forwardIfCurrent(end))
        throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + end + "] not found");
    comments(data);
    if (flf.hasTteClass()) {
        FunctionLibFunction tmp = flf.getEvaluator().pre(bif, flf);
        if (tmp != null && tmp != flf) {
            bif.setFlf(flf = tmp);
            bif.setArgType(flf.getArgType());
            try {
                bif.setClassDefinition(flf.getFunctionClassDefinition());
            } catch (Throwable t) {
                ExceptionUtil.rethrowIfNecessary(t);
                throw new PageRuntimeException(t);
            }
            bif.setReturnType(flf.getReturnTypeAsString());
        }
    }
    data.ep.add(flf, bif, data.srcCode);
    Variable var = data.factory.createVariable(line, data.srcCode.getPosition());
    var.addMember(bif);
    return var;
}
Also used : OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) Position(lucee.transformer.Position) TemplateException(lucee.runtime.exp.TemplateException) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 15 with Variable

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

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