Search in sources :

Example 1 with TagCIObject

use of lucee.transformer.bytecode.statement.tag.TagCIObject in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method writeGetSubPages.

private void writeGetSubPages(ClassWriter cw, String name, List<TagCIObject> subs, int dialect) {
    // pageSource.getFullClassName().replace('.', '/');
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_SUB_PAGES, null, null, cw);
    Label endIF = new Label();
    // adapter.visitVarInsn(Opcodes.ALOAD, 0);
    // adapter.visitFieldInsn(Opcodes.GETFIELD, name, "subs", "[Llucee/runtime/CIPage;");
    // adapter.visitJumpInsn(Opcodes.IFNONNULL, endIF);
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    ArrayVisitor av = new ArrayVisitor();
    av.visitBegin(adapter, Types.CI_PAGE, subs.size());
    Iterator<TagCIObject> it = subs.iterator();
    String className;
    int index = 0;
    while (it.hasNext()) {
        TagCIObject ci = it.next();
        av.visitBeginItem(adapter, index++);
        className = createSubClass(name, ci.getName(), dialect);
        // ASMConstants.NULL(adapter);
        adapter.visitTypeInsn(Opcodes.NEW, className);
        adapter.visitInsn(Opcodes.DUP);
        adapter.visitVarInsn(Opcodes.ALOAD, 0);
        adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, "getPageSource", "()Llucee/runtime/PageSource;");
        adapter.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", "(Llucee/runtime/PageSource;)V");
        av.visitEndItem(adapter);
    }
    av.visitEnd();
    adapter.visitFieldInsn(Opcodes.PUTFIELD, name, "subs", "[Llucee/runtime/CIPage;");
    // adapter.visitLabel(endIF);
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitFieldInsn(Opcodes.GETFIELD, name, "subs", "[Llucee/runtime/CIPage;");
    adapter.returnValue();
    adapter.endMethod();
}
Also used : Label(org.objectweb.asm.Label) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) ArrayVisitor(lucee.transformer.bytecode.visitor.ArrayVisitor) LitString(lucee.transformer.expression.literal.LitString) TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject)

Example 2 with TagCIObject

use of lucee.transformer.bytecode.statement.tag.TagCIObject in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method getSubs.

private List<TagCIObject> getSubs(TagCIObject[] defaultValue) {
    Iterator<Statement> it = getStatements().iterator();
    Statement s;
    TagCIObject t;
    List<TagCIObject> subs = null;
    while (it.hasNext()) {
        s = it.next();
        if (s instanceof TagCIObject) {
            t = (TagCIObject) s;
            if (!t.isMain()) {
                if (subs == null)
                    subs = new ArrayList<TagCIObject>();
                subs.add(t);
            }
        }
    }
    return subs;
}
Also used : ArrayList(java.util.ArrayList) TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject)

Example 3 with TagCIObject

use of lucee.transformer.bytecode.statement.tag.TagCIObject in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method getTagCFObject.

/**
 * get the main component/interface from the Page
 * @return
 * @throws TransformerException
 */
private TagCIObject getTagCFObject(TagCIObject defaultValue) {
    if (_comp != null)
        return _comp;
    // first look for main
    Iterator<Statement> it = getStatements().iterator();
    Statement s;
    TagCIObject t, sub = null;
    while (it.hasNext()) {
        s = it.next();
        if (s instanceof TagCIObject) {
            t = (TagCIObject) s;
            if (t.isMain())
                return _comp = t;
            else if (sub == null)
                sub = t;
        }
    }
    if (sub != null)
        return _comp = sub;
    return defaultValue;
}
Also used : TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject)

Example 4 with TagCIObject

use of lucee.transformer.bytecode.statement.tag.TagCIObject in project Lucee by lucee.

the class SourceLastModifiedClassAdapter method execute.

/**
 * convert the Page Object to java bytecode
 * @param className name of the genrated class (only necessary when Page object has no PageSource reference)
 * @return
 * @throws TransformerException
 */
public byte[] execute(String className) throws TransformerException {
    // not exists in any case, so every usage must have a plan b for not existence
    PageSource optionalPS = sourceCode instanceof PageSourceCode ? ((PageSourceCode) sourceCode).getPageSource() : null;
    List<LitString> keys = new ArrayList<LitString>();
    ClassWriter cw = ASMUtil.getClassWriter();
    ArrayList<String> imports = new ArrayList<String>();
    getImports(imports, this);
    // look for component if necessary
    TagCIObject comp = getTagCFObject(null);
    // in case we have a sub component
    if (className == null) {
        if (optionalPS == null)
            throw new IllegalArgumentException("when Page object has no PageSource, a className is necessary");
        className = optionalPS.getClassName();
    }
    if (comp != null)
        className = createSubClass(className, comp.getName(), sourceCode.getDialect());
    className = className.replace('.', '/');
    this.className = className;
    // parent
    // "lucee/runtime/Page";
    String parent = PageImpl.class.getName();
    if (// "lucee/runtime/ComponentPage";
    isComponent(comp))
        // "lucee/runtime/ComponentPage";
        parent = ComponentPageImpl.class.getName();
    else // "lucee/runtime/InterfacePage";
    if (isInterface(comp))
        parent = InterfacePageImpl.class.getName();
    parent = parent.replace('.', '/');
    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, className, null, parent, null);
    if (optionalPS != null) {
        // we use full path  when FD is enabled
        String path = config.allowRequestTimeout() ? optionalPS.getRealpathWithVirtual() : optionalPS.getPhyscalFile().getAbsolutePath();
        // when adding more use ; as delimiter
        cw.visitSource(path, null);
    // cw.visitSource(optionalPS.getPhyscalFile().getAbsolutePath(),
    // "rel:"+optionalPS.getRealpathWithVirtual()); // when adding more use ; as delimiter
    } else {
    // cw.visitSource("","rel:");
    }
    // static constructor
    // GeneratorAdapter statConstrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,STATIC_CONSTRUCTOR,null,null,cw);
    // StaticConstrBytecodeContext statConstr = null;//new BytecodeContext(null,null,this,externalizer,keys,cw,name,statConstrAdapter,STATIC_CONSTRUCTOR,writeLog(),suppressWSbeforeArg);
    // constructor
    GeneratorAdapter constrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_PS, null, null, cw);
    ConstrBytecodeContext constr = new ConstrBytecodeContext(optionalPS, this, keys, cw, className, constrAdapter, CONSTRUCTOR_PS, writeLog(), suppressWSbeforeArg, output, returnValue);
    constrAdapter.loadThis();
    Type t;
    if (isComponent(comp)) {
        t = Types.COMPONENT_PAGE_IMPL;
        // extends
        // Attribute attr = comp.getAttribute("extends");
        // if(attr!=null) ExpressionUtil.writeOutSilent(attr.getValue(),constr, Expression.MODE_REF);
        // else constrAdapter.push("");
        constrAdapter.invokeConstructor(t, CONSTRUCTOR);
    } else if (isInterface(comp)) {
        t = Types.INTERFACE_PAGE_IMPL;
        constrAdapter.invokeConstructor(t, CONSTRUCTOR);
    } else {
        t = Types.PAGE_IMPL;
        constrAdapter.invokeConstructor(t, CONSTRUCTOR);
    }
    // call _init()
    constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
    constrAdapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, constr.getClassName(), "initKeys", "()V");
    // private static  ImportDefintion[] test=new ImportDefintion[]{...};
    {
        FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "imports", "[Llucee/runtime/component/ImportDefintion;", null, null);
        fv.visitEnd();
        constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
        ArrayVisitor av = new ArrayVisitor();
        av.visitBegin(constrAdapter, Types.IMPORT_DEFINITIONS, imports.size());
        int index = 0;
        Iterator<String> it = imports.iterator();
        while (it.hasNext()) {
            av.visitBeginItem(constrAdapter, index++);
            constrAdapter.push(it.next());
            ASMConstants.NULL(constrAdapter);
            constrAdapter.invokeStatic(Types.IMPORT_DEFINITIONS_IMPL, ID_GET_INSTANCE);
            av.visitEndItem(constrAdapter);
        }
        av.visitEnd();
        constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, className, "imports", "[Llucee/runtime/component/ImportDefintion;");
    }
    // getVersion
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, VERSION, null, null, cw);
    adapter.push(version);
    adapter.returnValue();
    adapter.endMethod();
    // public ImportDefintion[] getImportDefintions()
    if (imports.size() > 0) {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw);
        adapter.visitVarInsn(Opcodes.ALOAD, 0);
        adapter.visitFieldInsn(Opcodes.GETFIELD, className, "imports", "[Llucee/runtime/component/ImportDefintion;");
        adapter.returnValue();
        adapter.endMethod();
    } else {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw);
        adapter.visitInsn(Opcodes.ICONST_0);
        adapter.visitTypeInsn(Opcodes.ANEWARRAY, "lucee/runtime/component/ImportDefintion");
        adapter.returnValue();
        adapter.endMethod();
    }
    // getSourceLastModified
    adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LAST_MOD, null, null, cw);
    adapter.push(lastModifed);
    adapter.returnValue();
    adapter.endMethod();
    // getSourceLength
    adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LENGTH, null, null, cw);
    adapter.push(length);
    adapter.returnValue();
    adapter.endMethod();
    // getCompileTime
    adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, COMPILE_TIME, null, null, cw);
    adapter.push(System.currentTimeMillis());
    adapter.returnValue();
    adapter.endMethod();
    // getHash
    adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, HASH, null, null, cw);
    adapter.push(hash);
    adapter.returnValue();
    adapter.endMethod();
    if (comp != null) {
        writeOutStaticConstructor(constr, keys, cw, comp, className);
    }
    // newInstance/initComponent/call
    if (isComponent()) {
        writeOutNewComponent(constr, keys, cw, comp, className);
        writeOutInitComponent(constr, keys, cw, comp, className);
    } else if (isInterface()) {
        writeOutNewInterface(constr, keys, cw, comp, className);
        writeOutInitInterface(constr, keys, cw, comp, className);
    } else {
        writeOutCall(constr, keys, cw, className);
    }
    // write UDFProperties to constructor
    // writeUDFProperties(bc,funcs,pageType);
    // udfCall
    Function[] functions = getFunctions();
    ConditionVisitor cv;
    DecisionIntVisitor div;
    // less/equal than 10 functions
    if (isInterface()) {
    } else if (functions.length <= 10) {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw);
        BytecodeContext bc = new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output, returnValue);
        if (functions.length == 0) {
        } else if (functions.length == 1) {
            ExpressionUtil.visitLine(bc, functions[0].getStart());
            functions[0].getBody().writeOut(bc);
            ExpressionUtil.visitLine(bc, functions[0].getEnd());
        } else
            writeOutUdfCallInner(bc, functions, 0, functions.length);
        adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        adapter.endMethod();
    } else // more than 10 functions
    {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw);
        BytecodeContext bc = new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output, returnValue);
        cv = new ConditionVisitor();
        cv.visitBefore();
        int count = 0;
        for (int i = 0; i < functions.length; i += 10) {
            cv.visitWhenBeforeExpr();
            div = new DecisionIntVisitor();
            div.visitBegin();
            adapter.loadArg(2);
            div.visitLT();
            adapter.push(i + 10);
            div.visitEnd(bc);
            cv.visitWhenAfterExprBeforeBody(bc);
            adapter.visitVarInsn(Opcodes.ALOAD, 0);
            adapter.visitVarInsn(Opcodes.ALOAD, 1);
            adapter.visitVarInsn(Opcodes.ALOAD, 2);
            adapter.visitVarInsn(Opcodes.ILOAD, 3);
            adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, createFunctionName(++count), "(Llucee/runtime/PageContext;Llucee/runtime/type/UDF;I)Ljava/lang/Object;");
            // adapter.returnValue();
            adapter.visitInsn(Opcodes.ARETURN);
            cv.visitWhenAfterBody(bc);
        }
        cv.visitAfter(bc);
        adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        adapter.endMethod();
        count = 0;
        Method innerCall;
        for (int i = 0; i < functions.length; i += 10) {
            innerCall = new Method(createFunctionName(++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, USER_DEFINED_FUNCTION, Types.INT_VALUE });
            adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerCall, null, new Type[] { Types.THROWABLE }, cw);
            writeOutUdfCallInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, innerCall, writeLog(), suppressWSbeforeArg, output, returnValue), functions, i, i + 10 > functions.length ? functions.length : i + 10);
            adapter.visitInsn(Opcodes.ACONST_NULL);
            adapter.returnValue();
            adapter.endMethod();
        }
    }
    // threadCall
    TagThread[] threads = getThreads();
    if (true) {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, THREAD_CALL, null, new Type[] { Types.THROWABLE }, cw);
        if (threads.length > 0)
            writeOutThreadCallInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, THREAD_CALL, writeLog(), suppressWSbeforeArg, output, returnValue), threads, 0, threads.length);
        // adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        adapter.endMethod();
    }
    // less/equal than 10 functions
    if (isInterface()) {
    } else if (functions.length <= 10) {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
        if (functions.length > 0)
            writeUdfDefaultValueInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output, returnValue), functions, 0, functions.length);
        adapter.loadArg(DEFAULT_VALUE);
        adapter.returnValue();
        adapter.endMethod();
    } else {
        adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
        BytecodeContext bc = new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output, returnValue);
        cv = new ConditionVisitor();
        cv.visitBefore();
        int count = 0;
        for (int i = 0; i < functions.length; i += 10) {
            cv.visitWhenBeforeExpr();
            div = new DecisionIntVisitor();
            div.visitBegin();
            adapter.loadArg(1);
            div.visitLT();
            adapter.push(i + 10);
            div.visitEnd(bc);
            cv.visitWhenAfterExprBeforeBody(bc);
            adapter.visitVarInsn(Opcodes.ALOAD, 0);
            adapter.visitVarInsn(Opcodes.ALOAD, 1);
            adapter.visitVarInsn(Opcodes.ILOAD, 2);
            adapter.visitVarInsn(Opcodes.ILOAD, 3);
            adapter.visitVarInsn(Opcodes.ALOAD, 4);
            adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, "udfDefaultValue" + (++count), "(Llucee/runtime/PageContext;IILjava/lang/Object;)Ljava/lang/Object;");
            // adapter.returnValue();
            adapter.visitInsn(Opcodes.ARETURN);
            cv.visitWhenAfterBody(bc);
        }
        cv.visitAfter(bc);
        adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        adapter.endMethod();
        count = 0;
        Method innerDefaultValue;
        for (int i = 0; i < functions.length; i += 10) {
            innerDefaultValue = new Method("udfDefaultValue" + (++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.INT_VALUE, Types.INT_VALUE, Types.OBJECT });
            adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerDefaultValue, null, new Type[] { Types.PAGE_EXCEPTION }, cw);
            writeUdfDefaultValueInner(new BytecodeContext(optionalPS, constr, this, keys, cw, className, adapter, innerDefaultValue, writeLog(), suppressWSbeforeArg, output, returnValue), functions, i, i + 10 > functions.length ? functions.length : i + 10);
            adapter.loadArg(DEFAULT_VALUE);
            // adapter.visitInsn(Opcodes.ACONST_NULL);
            adapter.returnValue();
            adapter.endMethod();
        }
    }
    // CONSTRUCTOR
    List<Data> udfProperties = constr.getUDFProperties();
    Iterator<Data> it = udfProperties.iterator();
    String udfpropsClassName = Types.UDF_PROPERTIES_ARRAY.toString();
    // new UDFProperties Array
    constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
    constrAdapter.push(udfProperties.size());
    constrAdapter.newArray(Types.UDF_PROPERTIES);
    constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, getClassName(), "udfs", udfpropsClassName);
    // set item
    Data data;
    while (it.hasNext()) {
        data = it.next();
        constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
        constrAdapter.visitFieldInsn(Opcodes.GETFIELD, constr.getClassName(), "udfs", Types.UDF_PROPERTIES_ARRAY.toString());
        constrAdapter.push(data.arrayIndex);
        data.function.createUDFProperties(constr, data.valueIndex, data.type);
        constrAdapter.visitInsn(Opcodes.AASTORE);
    }
    // setPageSource(pageSource);
    constrAdapter.visitVarInsn(Opcodes.ALOAD, 0);
    constrAdapter.visitVarInsn(Opcodes.ALOAD, 1);
    constrAdapter.invokeVirtual(t, SET_PAGE_SOURCE);
    constrAdapter.returnValue();
    constrAdapter.endMethod();
    // INIT KEYS
    {
        GeneratorAdapter aInit = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, INIT_KEYS, null, null, cw);
        BytecodeContext bcInit = new BytecodeContext(optionalPS, constr, this, keys, cw, className, aInit, INIT_KEYS, writeLog(), suppressWSbeforeArg, output, returnValue);
        registerFields(bcInit, keys);
        aInit.returnValue();
        aInit.endMethod();
    }
    // set field subs
    FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "subs", "[Llucee/runtime/CIPage;", null, null);
    fv.visitEnd();
    // create sub components/interfaces
    if (comp != null && comp.isMain()) {
        List<TagCIObject> subs = getSubs(null);
        if (!ArrayUtil.isEmpty(subs)) {
            Iterator<TagCIObject> _it = subs.iterator();
            TagCIObject tc;
            while (_it.hasNext()) {
                tc = _it.next();
                tc.writeOut(this);
            }
            writeGetSubPages(cw, className, subs, sourceCode.getDialect());
        }
    }
    return cw.toByteArray();
}
Also used : InterfacePageImpl(lucee.runtime.InterfacePageImpl) PageSourceCode(lucee.transformer.util.PageSourceCode) ArrayList(java.util.ArrayList) TagThread(lucee.transformer.bytecode.statement.tag.TagThread) LitString(lucee.transformer.expression.literal.LitString) FieldVisitor(org.objectweb.asm.FieldVisitor) LitString(lucee.transformer.expression.literal.LitString) Function(lucee.transformer.bytecode.statement.udf.Function) IFunction(lucee.transformer.bytecode.statement.IFunction) ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) Iterator(java.util.Iterator) DecisionIntVisitor(lucee.transformer.bytecode.visitor.DecisionIntVisitor) TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject) Data(lucee.transformer.bytecode.ConstrBytecodeContext.Data) Method(org.objectweb.asm.commons.Method) ClassWriter(org.objectweb.asm.ClassWriter) PageSource(lucee.runtime.PageSource) Type(org.objectweb.asm.Type) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) ArrayVisitor(lucee.transformer.bytecode.visitor.ArrayVisitor)

Example 5 with TagCIObject

use of lucee.transformer.bytecode.statement.tag.TagCIObject in project Lucee by lucee.

the class Component method evaluate.

@Override
public void evaluate(Tag tag, TagLibTag tlt) throws EvaluatorException {
    /*if(tag instanceof TagOther) {
			print.e(((TagOther)tag).getFullname());
		}*/
    TagCIObject tc = (TagCIObject) tag;
    Statement pPage = tag.getParent();
    // String className=tag.getTagLibTag().getTagClassName();
    Page page;
    // move components inside script to root
    if (pPage instanceof Page) {
        page = (Page) pPage;
    } else {
        // is in script
        Tag p = ASMUtil.getParentTag(tag);
        if ((pPage = p.getParent()) instanceof Page && p.getTagLibTag().getName().equalsIgnoreCase(((Page) pPage).getSourceCode().getDialect() == CFMLEngine.DIALECT_CFML ? Constants.CFML_SCRIPT_TAG_NAME : Constants.LUCEE_SCRIPT_TAG_NAME)) {
            // chnaged order of the condition, not sure if this is ok
            page = (Page) pPage;
            // move imports from script to component body
            List<Statement> children = p.getBody().getStatements();
            Iterator<Statement> it = children.iterator();
            Statement stat;
            Tag t;
            while (it.hasNext()) {
                stat = it.next();
                if (!(stat instanceof Tag))
                    continue;
                t = (Tag) stat;
                if (t.getTagLibTag().getName().equals("import")) {
                    tag.getBody().addStatement(t);
                }
            }
            // move to page
            ASMUtil.move(tag, page);
        // if(!inline)ASMUtil.replace(p, tag, false);
        } else
            throw new EvaluatorException("Wrong Context, tag " + tlt.getFullName() + " can't be inside other tags, tag is inside tag " + p.getFullname());
    }
    // Page page=(Page) pPage;
    Boolean insideCITemplate = isInsideCITemplate(page);
    boolean main = isMainComponent(page, tc);
    // is a full grown component or a inline component
    if (insideCITemplate == Boolean.FALSE) {
        throw new EvaluatorException("Wrong Context, " + tlt.getFullName() + " tag must be inside a file with the extension " + Constants.getCFMLComponentExtension() + " or " + Constants.getLuceeComponentExtension());
    }
    // if(count>1)
    // throw new EvaluatorException("inside one cfc file only one tag "+tlt.getFullName()+" is allowed, now we have "+count);
    boolean isComponent = tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Component");
    /*boolean isInterface="lucee.runtime.tag.Interface".equals(tlt.getTagClassName());
		if(main) {
			if(isComponent)			page.setIsComponent(true);
			else if(isInterface)	page.setIsInterface(true);
		}*/
    tc.setMain(main);
    // Attributes
    // Name
    String name = null;
    if (!main) {
        Map<String, Attribute> attrs = tag.getAttributes();
        if (attrs.size() > 0) {
            Attribute first = attrs.values().iterator().next();
            if (first.isDefaultValue()) {
                name = first.getName();
            }
        }
        if (name == null) {
            Attribute attr = tag.getAttribute("name");
            if (attr != null) {
                Expression expr = tag.getFactory().toExprString(attr.getValue());
                if (!(expr instanceof LitString))
                    throw new EvaluatorException("Name of the component " + tlt.getFullName() + ", must be a literal string value");
                name = ((LitString) expr).getString();
            } else
                throw new EvaluatorException("Missing name of the component " + tlt.getFullName() + "");
        }
        tc.setName(name);
    }
    // output
    // "output=true" is handled in "lucee.transformer.cfml.attributes.impl.Function"
    Attribute attr = tag.getAttribute("output");
    if (attr != null) {
        Expression expr = tag.getFactory().toExprBoolean(attr.getValue());
        if (!(expr instanceof LitBoolean))
            throw new EvaluatorException("Attribute output of the Tag " + tlt.getFullName() + ", must contain a static boolean value (true or false, yes or no)");
    // boolean output = ((LitBoolean)expr).getBooleanValue();
    // if(!output) ASMUtil.removeLiterlChildren(tag, true);
    }
    // extends
    attr = tag.getAttribute("extends");
    if (attr != null) {
        Expression expr = tag.getFactory().toExprString(attr.getValue());
        if (!(expr instanceof LitString))
            throw new EvaluatorException("Attribute extends of the Tag " + tlt.getFullName() + ", must contain a literal string value");
    }
    // implements
    if (isComponent) {
        attr = tag.getAttribute("implements");
        if (attr != null) {
            Expression expr = tag.getFactory().toExprString(attr.getValue());
            if (!(expr instanceof LitString))
                throw new EvaluatorException("Attribute implements of the Tag " + tlt.getFullName() + ", must contain a literal string value");
        }
    }
    // modifier
    if (isComponent) {
        attr = tag.getAttribute("modifier");
        if (attr != null) {
            Expression expr = tag.getFactory().toExprString(attr.getValue());
            if (!(expr instanceof LitString))
                throw new EvaluatorException("Attribute modifier of the Tag " + tlt.getFullName() + ", must contain a literal string value");
            LitString ls = (LitString) expr;
            int mod = ComponentUtil.toModifier(ls.getString(), lucee.runtime.Component.MODIFIER_NONE, -1);
            if (mod == -1)
                throw new EvaluatorException("Value [" + ls.getString() + "] from attribute modifier of the Tag " + tlt.getFullName() + " is invalid,valid values are [none,abstract,final]");
        }
    }
}
Also used : Attribute(lucee.transformer.bytecode.statement.tag.Attribute) Statement(lucee.transformer.bytecode.Statement) Page(lucee.transformer.bytecode.Page) LitBoolean(lucee.transformer.expression.literal.LitBoolean) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) EvaluatorException(lucee.transformer.cfml.evaluator.EvaluatorException) Expression(lucee.transformer.expression.Expression) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(lucee.transformer.bytecode.statement.tag.Tag) LitBoolean(lucee.transformer.expression.literal.LitBoolean) TagCIObject(lucee.transformer.bytecode.statement.tag.TagCIObject)

Aggregations

TagCIObject (lucee.transformer.bytecode.statement.tag.TagCIObject)5 LitString (lucee.transformer.expression.literal.LitString)3 ArrayList (java.util.ArrayList)2 ArrayVisitor (lucee.transformer.bytecode.visitor.ArrayVisitor)2 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)2 Iterator (java.util.Iterator)1 InterfacePageImpl (lucee.runtime.InterfacePageImpl)1 PageSource (lucee.runtime.PageSource)1 Data (lucee.transformer.bytecode.ConstrBytecodeContext.Data)1 Page (lucee.transformer.bytecode.Page)1 Statement (lucee.transformer.bytecode.Statement)1 IFunction (lucee.transformer.bytecode.statement.IFunction)1 Attribute (lucee.transformer.bytecode.statement.tag.Attribute)1 Tag (lucee.transformer.bytecode.statement.tag.Tag)1 TagThread (lucee.transformer.bytecode.statement.tag.TagThread)1 Function (lucee.transformer.bytecode.statement.udf.Function)1 ConditionVisitor (lucee.transformer.bytecode.visitor.ConditionVisitor)1 DecisionIntVisitor (lucee.transformer.bytecode.visitor.DecisionIntVisitor)1 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)1 Expression (lucee.transformer.expression.Expression)1