Search in sources :

Example 16 with Variable

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

the class AbstrCFMLExprTransformer method scope.

/**
 * Liest einen CFML Scope aus,
 * falls der folgende identifier keinem Scope entspricht,
 * gibt die Variable null zurueck.
 * <br />
 * EBNF:<br />
 * <code>"variable" | "cgi" | "url" | "form" | "session" | "application" | "arguments" | "cookie" | " client";</code>
 * @param id String identifier,
 * wird aus Optimierungszwechen nicht innerhalb dieser Funktion ausgelsen.
 * @return CFXD Variable Element oder null
 * @throws TemplateException
 */
private Variable scope(ExprData data, Identifier id, Position line) throws TemplateException {
    String idStr = id.getUpper();
    if (idStr.equals("ARGUMENTS"))
        return data.factory.createVariable(Scope.SCOPE_ARGUMENTS, line, data.srcCode.getPosition());
    else if (idStr.equals("LOCAL"))
        return data.factory.createVariable(Scope.SCOPE_LOCAL, line, data.srcCode.getPosition());
    else if (idStr.equals("VAR")) {
        Identifier _id = identifier(data, false, true);
        if (_id != null) {
            comments(data);
            Variable local = data.factory.createVariable(ScopeSupport.SCOPE_VAR, line, data.srcCode.getPosition());
            if (!"LOCAL".equalsIgnoreCase(_id.getString()))
                local.addMember(data.factory.createDataMember(_id));
            else {
                local.ignoredFirstMember(true);
            }
            return local;
        }
    } else if (idStr.equals("VARIABLES"))
        return data.factory.createVariable(Scope.SCOPE_VARIABLES, line, data.srcCode.getPosition());
    else if (idStr.equals("REQUEST"))
        return data.factory.createVariable(Scope.SCOPE_REQUEST, line, data.srcCode.getPosition());
    else if (idStr.equals("SERVER"))
        return data.factory.createVariable(Scope.SCOPE_SERVER, line, data.srcCode.getPosition());
    if (data.settings.ignoreScopes)
        return null;
    if (idStr.equals("CGI"))
        return data.factory.createVariable(Scope.SCOPE_CGI, line, data.srcCode.getPosition());
    else if (idStr.equals("SESSION"))
        return data.factory.createVariable(Scope.SCOPE_SESSION, line, data.srcCode.getPosition());
    else if (idStr.equals("APPLICATION"))
        return data.factory.createVariable(Scope.SCOPE_APPLICATION, line, data.srcCode.getPosition());
    else if (idStr.equals("FORM"))
        return data.factory.createVariable(Scope.SCOPE_FORM, line, data.srcCode.getPosition());
    else if (idStr.equals("URL"))
        return data.factory.createVariable(Scope.SCOPE_URL, line, data.srcCode.getPosition());
    else if (idStr.equals("CLIENT"))
        return data.factory.createVariable(Scope.SCOPE_CLIENT, line, data.srcCode.getPosition());
    else if (idStr.equals("COOKIE"))
        return data.factory.createVariable(Scope.SCOPE_COOKIE, line, data.srcCode.getPosition());
    else if (idStr.equals("CLUSTER"))
        return data.factory.createVariable(Scope.SCOPE_CLUSTER, line, data.srcCode.getPosition());
    return null;
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) OpVariable(lucee.transformer.bytecode.op.OpVariable) Variable(lucee.transformer.expression.var.Variable) LitString(lucee.transformer.expression.literal.LitString) ExprString(lucee.transformer.expression.ExprString)

Example 17 with Variable

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

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

the class QueryExecute method evaluate.

@Override
public void evaluate(BIF bif, FunctionLibFunction flf) throws EvaluatorException {
    Variable var = bif.getParent();
    if (var != null) {
        Assign ass = var.assign();
        if (ass != null) {
            try {
                String str = VariableString.variableToString(ass.getVariable(), false);
                addArgument(bif, str);
            } catch (TransformerException e) {
                SystemOut.printDate(e);
            }
        }
    }
}
Also used : Variable(lucee.transformer.expression.var.Variable) Assign(lucee.transformer.bytecode.expression.var.Assign) VariableString(lucee.transformer.bytecode.expression.var.VariableString) TransformerException(lucee.transformer.TransformerException)

Example 19 with Variable

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

the class Query method translateChildren.

private void translateChildren(Iterator it) {
    Statement stat;
    while (it.hasNext()) {
        stat = (Statement) it.next();
        if (stat instanceof PrintOut) {
            PrintOut printOut = ((PrintOut) stat);
            Expression e = printOut.getExpr();
            if (!(e instanceof Literal)) {
                Expression expr = removeCastString(e);
                if (expr instanceof Variable) {
                    // do not preserve BIF PreserveSingleQuotes return value
                    Member member = ((Variable) expr).getFirstMember();
                    if (member instanceof BIF) {
                        BIF bif = (BIF) member;
                        if (bif.getClassDefinition().getClassName().equals(PreserveSingleQuotes.class.getName())) {
                            printOut.setExpr(bif.getArguments()[0].getValue());
                            continue;
                        } else if (bif.getClassDefinition().getClassName().equals(ListQualify.class.getName())) {
                            Argument[] args = bif.getArguments();
                            List<Argument> arr = new ArrayList<Argument>();
                            // first get existing arguments
                            arr.add(args[0]);
                            arr.add(args[1]);
                            if (args.length >= 3)
                                arr.add(args[2]);
                            else
                                arr.add(new Argument(expr.getFactory().createLitString(","), "string"));
                            if (args.length >= 4)
                                arr.add(args[3]);
                            else
                                arr.add(new Argument(expr.getFactory().createLitString("all"), "string"));
                            if (args.length >= 5)
                                arr.add(args[4]);
                            else
                                arr.add(new Argument(expr.getFactory().createLitBoolean(false), "boolean"));
                            // PSQ-BIF DO NOT REMOVE THIS COMMENT
                            arr.add(new Argument(expr.getFactory().createLitBoolean(true), "boolean"));
                            bif.setArguments(arr.toArray(new Argument[arr.size()]));
                            continue;
                        } else if (bif.getClassDefinition().getClassName().equals(QuotedValueList.class.getName()) || bif.getClassDefinition().getClassName().equals(ValueList.class.getName())) {
                            // printOut.setPreserveSingleQuote(false);
                            continue;
                        }
                    }
                    // do not preserve UDF return value
                    member = ((Variable) expr).getLastMember();
                    if (member instanceof UDF)
                        continue;
                }
                printOut.setCheckPSQ(true);
                if (e != expr)
                    printOut.setExpr(expr);
            }
        } else if (stat instanceof Tag) {
            Body b = ((Tag) stat).getBody();
            if (b != null)
                translateChildren(b.getStatements().iterator());
        } else if (stat instanceof Body) {
            translateChildren(((Body) stat).getStatements().iterator());
        }
    }
}
Also used : Variable(lucee.transformer.expression.var.Variable) Argument(lucee.transformer.bytecode.expression.var.Argument) Statement(lucee.transformer.bytecode.Statement) PreserveSingleQuotes(lucee.runtime.functions.other.PreserveSingleQuotes) PrintOut(lucee.transformer.bytecode.statement.PrintOut) Expression(lucee.transformer.expression.Expression) UDF(lucee.transformer.bytecode.expression.var.UDF) Literal(lucee.transformer.expression.literal.Literal) QuotedValueList(lucee.runtime.functions.other.QuotedValueList) ValueList(lucee.runtime.functions.query.ValueList) ArrayList(java.util.ArrayList) List(java.util.List) Tag(lucee.transformer.bytecode.statement.tag.Tag) Member(lucee.transformer.expression.var.Member) Body(lucee.transformer.bytecode.Body) BIF(lucee.transformer.bytecode.expression.var.BIF)

Example 20 with Variable

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

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