Search in sources :

Example 16 with Literal

use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeOutNewComponent.

private void writeOutNewComponent(ConstrBytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component, String name) throws TransformerException {
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
    BytecodeContext bc = new BytecodeContext(null, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output, returnValue);
    Label methodBegin = new Label();
    Label methodEnd = new Label();
    adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0);
    ExpressionUtil.visitLine(bc, component.getStart());
    adapter.visitLabel(methodBegin);
    int comp = adapter.newLocal(Types.COMPONENT_IMPL);
    adapter.newInstance(Types.COMPONENT_IMPL);
    adapter.dup();
    Attribute attr;
    // ComponentPage
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.checkCast(Types.COMPONENT_PAGE_IMPL);
    // !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!!
    // Output
    attr = component.removeAttribute("output");
    if (attr != null) {
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    } else
        ASMConstants.NULL(adapter);
    // synchronized
    attr = component.removeAttribute("synchronized");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE);
    else
        adapter.push(false);
    // extends
    attr = component.removeAttribute("extends");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // implements
    attr = component.removeAttribute("implements");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // hint
    attr = component.removeAttribute("hint");
    if (attr != null) {
        Expression value = attr.getValue();
        if (!(value instanceof Literal)) {
            value = bc.getFactory().createLitString("[runtime expression]");
        }
        ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF);
    } else
        adapter.push("");
    // dspName
    attr = component.removeAttribute("displayname");
    if (attr == null)
        attr = component.getAttribute("display");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // callpath
    adapter.visitVarInsn(Opcodes.ALOAD, 2);
    // realpath
    adapter.visitVarInsn(Opcodes.ILOAD, 3);
    // style
    attr = component.removeAttribute("style");
    if (attr != null)
        ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF);
    else
        adapter.push("");
    // persistent
    attr = component.removeAttribute("persistent");
    boolean persistent = false;
    if (attr != null) {
        persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
    }
    // accessors
    attr = component.removeAttribute("accessors");
    boolean accessors = false;
    if (attr != null) {
        accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue();
    }
    // modifier
    attr = component.removeAttribute("modifier");
    int modifiers = Component.MODIFIER_NONE;
    if (attr != null) {
        // type already evaluated in evaluator
        LitString ls = (LitString) component.getFactory().toExprString(attr.getValue());
        modifiers = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, lucee.runtime.Component.MODIFIER_NONE);
    }
    adapter.push(persistent);
    adapter.push(accessors);
    adapter.push(modifiers);
    adapter.visitVarInsn(Opcodes.ILOAD, 4);
    // adapter.visitVarInsn(Opcodes.ALOAD, 4);
    createMetaDataStruct(bc, component.getAttributes(), component.getMetaData());
    adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL15);
    adapter.storeLocal(comp);
    // Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName)
    // initComponent(pc,c);
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.loadArg(0);
    adapter.loadLocal(comp);
    adapter.loadArg(4);
    adapter.invokeVirtual(Types.COMPONENT_PAGE_IMPL, INIT_COMPONENT3);
    adapter.visitLabel(methodEnd);
    // return component;
    adapter.loadLocal(comp);
    adapter.returnValue();
    // ExpressionUtil.visitLine(adapter, component.getEndLine());
    adapter.endMethod();
}
Also used : LitString(lucee.transformer.expression.literal.LitString) Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) Label(org.objectweb.asm.Label) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter)

Example 17 with Literal

use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.

the class VariableString method variableToStringArray.

public static String[] variableToStringArray(Variable var, boolean rawIfPossible) throws TransformerException {
    List<Member> members = var.getMembers();
    List<String> arr = new ArrayList<String>();
    if (var.getScope() != Scope.SCOPE_UNDEFINED)
        arr.add(ScopeFactory.toStringScope(var.getScope(), "undefined"));
    Iterator<Member> it = members.iterator();
    DataMember dm;
    Expression n;
    while (it.hasNext()) {
        Object o = it.next();
        if (!(o instanceof DataMember))
            throw new TransformerException("can't translate Variable to a String", var.getStart());
        dm = (DataMember) o;
        n = dm.getName();
        if (n instanceof Literal) {
            if (rawIfPossible && n instanceof Identifier) {
                arr.add(((Identifier) n).getRaw());
            } else {
                arr.add(((Literal) n).getString());
            }
        } else
            throw new TransformerException("argument name must be a constant value", var.getStart());
    }
    return arr.toArray(new String[arr.size()]);
}
Also used : Identifier(lucee.transformer.bytecode.literal.Identifier) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) ArrayList(java.util.ArrayList) DataMember(lucee.transformer.expression.var.DataMember) ExprString(lucee.transformer.expression.ExprString) DataMember(lucee.transformer.expression.var.DataMember) Member(lucee.transformer.expression.var.Member) TransformerException(lucee.transformer.TransformerException)

Example 18 with Literal

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

use of lucee.transformer.expression.literal.Literal in project Lucee by lucee.

the class DocComment method getHint.

/**
 * @return the hint
 */
public String getHint() {
    if (hint == null) {
        Attribute attr = params.remove("hint");
        if (attr != null) {
            Literal lit = (Literal) attr.getValue();
            hint = lit.getString().trim();
        } else {
            hint = StringUtil.unwrap(tmpHint.toString());
        }
    }
    return hint;
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Literal(lucee.transformer.expression.literal.Literal)

Aggregations

Literal (lucee.transformer.expression.literal.Literal)19 Expression (lucee.transformer.expression.Expression)8 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)6 ExprString (lucee.transformer.expression.ExprString)6 LitString (lucee.transformer.expression.literal.LitString)6 Member (lucee.transformer.expression.var.Member)5 TransformerException (lucee.transformer.TransformerException)4 Body (lucee.transformer.bytecode.Body)4 BIF (lucee.transformer.bytecode.expression.var.BIF)4 ArrayList (java.util.ArrayList)3 Statement (lucee.transformer.bytecode.Statement)3 PrintOut (lucee.transformer.bytecode.statement.PrintOut)3 Tag (lucee.transformer.bytecode.statement.tag.Tag)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 DataMember (lucee.transformer.expression.var.DataMember)3 Variable (lucee.transformer.expression.var.Variable)3 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 TemplateException (lucee.runtime.exp.TemplateException)2