Search in sources :

Example 6 with Argument

use of lucee.transformer.bytecode.expression.var.Argument in project Lucee by lucee.

the class GetTickCount method execute.

@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
    Argument[] args = bif.getArguments();
    if (ArrayUtil.isEmpty(args))
        return;
    Argument arg = args[0];
    Expression value = arg.getValue();
    if (value instanceof LitString) {
        String unit = ((LitString) value).getString();
        if ("nano".equalsIgnoreCase(unit))
            arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_NANO), "number");
        else if ("milli".equalsIgnoreCase(unit))
            arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_MILLI), "number");
        else if ("micro".equalsIgnoreCase(unit))
            arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_MICRO), "number");
        else if ("second".equalsIgnoreCase(unit))
            arg.setValue(bif.getFactory().createLitDouble(lucee.runtime.functions.other.GetTickCount.UNIT_SECOND), "number");
    }
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Argument(lucee.transformer.bytecode.expression.var.Argument) Expression(lucee.transformer.expression.Expression) LitString(lucee.transformer.expression.literal.LitString)

Example 7 with Argument

use of lucee.transformer.bytecode.expression.var.Argument in project Lucee by lucee.

the class IsDefined method execute.

@Override
public void execute(BIF bif, FunctionLibFunction flf) throws TemplateException {
    Argument arg = bif.getArguments()[0];
    Expression value = arg.getValue();
    if (value instanceof LitString) {
        String str = ((LitString) value).getString();
        StringList sl = VariableInterpreter.parse(str, false);
        if (sl != null) {
            // scope
            str = sl.next();
            int scope = VariableInterpreter.scopeString2Int(bif.ts.ignoreScopes, str);
            if (scope == Scope.SCOPE_UNDEFINED)
                sl.reset();
            // keys
            String[] arr = sl.toArray();
            ArrayUtil.trim(arr);
            // update first arg
            arg.setValue(bif.getFactory().createLitDouble(scope), "number");
            if (arr.length == 1) {
                // LitString.toExprString(str);
                Expression expr = new CollectionKey(bif.getFactory(), arr[0]);
                arg = new Argument(expr, Collection.Key.class.getName());
                bif.addArgument(arg);
            } else {
                CollectionKeyArray expr = new CollectionKeyArray(bif.getFactory(), arr);
                // LiteralStringArray expr = new LiteralStringArray(arr);
                arg = new Argument(expr, Collection.Key[].class.getName());
                bif.addArgument(arg);
            }
        }
    }
// print.out("bif:"+arg.getValue().getClass().getName());
}
Also used : LitString(lucee.transformer.expression.literal.LitString) CollectionKeyArray(lucee.transformer.bytecode.expression.type.CollectionKeyArray) Argument(lucee.transformer.bytecode.expression.var.Argument) Expression(lucee.transformer.expression.Expression) StringList(lucee.commons.lang.StringList) Collection(lucee.runtime.type.Collection) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey) LitString(lucee.transformer.expression.literal.LitString) CollectionKey(lucee.transformer.bytecode.expression.type.CollectionKey)

Example 8 with Argument

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

Aggregations

Argument (lucee.transformer.bytecode.expression.var.Argument)8 Expression (lucee.transformer.expression.Expression)7 LitString (lucee.transformer.expression.literal.LitString)5 Variable (lucee.transformer.expression.var.Variable)5 CollectionKey (lucee.transformer.bytecode.expression.type.CollectionKey)2 BIF (lucee.transformer.bytecode.expression.var.BIF)2 NamedArgument (lucee.transformer.bytecode.expression.var.NamedArgument)2 OpVariable (lucee.transformer.bytecode.op.OpVariable)2 ExprString (lucee.transformer.expression.ExprString)2 Member (lucee.transformer.expression.var.Member)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringList (lucee.commons.lang.StringList)1 TemplateException (lucee.runtime.exp.TemplateException)1 PreserveSingleQuotes (lucee.runtime.functions.other.PreserveSingleQuotes)1 QuotedValueList (lucee.runtime.functions.other.QuotedValueList)1 ValueList (lucee.runtime.functions.query.ValueList)1 Collection (lucee.runtime.type.Collection)1 Body (lucee.transformer.bytecode.Body)1 Statement (lucee.transformer.bytecode.Statement)1