Search in sources :

Example 16 with TransformerException

use of lucee.transformer.TransformerException 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 17 with TransformerException

use of lucee.transformer.TransformerException in project Lucee by lucee.

the class TagCIObject method writeOut.

public void writeOut(Page p) throws TransformerException {
    Page page = new Page(p.getFactory(), p.getConfig(), p.getSourceCode(), this, CFMLEngineFactory.getInstance().getInfo().getFullVersionInfo(), p.getLastModifed(), p.writeLog(), p.getSupressWSbeforeArg(), p.getOutput(), p.returnValue(), p.ignoreScopes);
    // page.setIsComponent(true); // MUST can be a interface as well
    page.addStatement(this);
    byte[] barr = page.execute(p.getClassName());
    // ps.getMapping().getClassRootDirectory().getRealResource(page.getClassName()+".class");
    Resource classFile = null;
    try {
        IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
    } catch (IOException e) {
        new TransformerException(ExceptionUtil.getMessage(e), getStart());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(lucee.commons.io.res.Resource) Page(lucee.transformer.bytecode.Page) IOException(java.io.IOException) TransformerException(lucee.transformer.TransformerException)

Example 18 with TransformerException

use of lucee.transformer.TransformerException in project Lucee by lucee.

the class TagFunction method createFunction.

private Function createFunction(Page page, Body body, RefBoolean isStatic, boolean defaultOutput) throws TransformerException {
    Attribute attr;
    LitString ANY = page.getFactory().createLitString("any");
    LitString PUBLIC = page.getFactory().createLitString("public");
    // name
    Expression name = removeAttribute("name").getValue();
    /*if(name instanceof LitString) {
			((LitString)name).upperCase();
		}*/
    // return
    attr = removeAttribute("returntype");
    // if(attr==null) attr = getAttribute("return");
    // if(attr==null) attr = getAttribute("type");
    Expression returnType = (attr == null) ? ANY : attr.getValue();
    // output
    attr = removeAttribute("output");
    Expression output = (attr == null) ? (defaultOutput ? page.getFactory().TRUE() : page.getFactory().TRUE()) : attr.getValue();
    // bufferOutput
    attr = removeAttribute("bufferoutput");
    Expression bufferOutput = (attr == null) ? null : attr.getValue();
    // modifier
    isStatic.setValue(false);
    int modifier = Component.MODIFIER_NONE;
    attr = removeAttribute("modifier");
    if (attr != null) {
        Expression val = attr.getValue();
        if (val instanceof Literal) {
            Literal l = (Literal) val;
            String str = StringUtil.emptyIfNull(l.getString()).trim();
            if ("abstract".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_ABSTRACT;
            else if ("final".equalsIgnoreCase(str))
                modifier = Component.MODIFIER_FINAL;
            else if ("static".equalsIgnoreCase(str))
                isStatic.setValue(true);
        }
    }
    // access
    attr = removeAttribute("access");
    Expression access = (attr == null) ? PUBLIC : attr.getValue();
    // dspLabel
    attr = removeAttribute("displayname");
    Expression displayname = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
    // hint
    attr = removeAttribute("hint");
    Expression hint = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
    // description
    attr = removeAttribute("description");
    Expression description = (attr == null) ? page.getFactory().EMPTY() : attr.getValue();
    // returnformat
    attr = removeAttribute("returnformat");
    Expression returnFormat = (attr == null) ? null : attr.getValue();
    // secureJson
    attr = removeAttribute("securejson");
    Expression secureJson = (attr == null) ? null : attr.getValue();
    // verifyClient
    attr = removeAttribute("verifyclient");
    Expression verifyClient = (attr == null) ? null : attr.getValue();
    // localMode
    attr = removeAttribute("localmode");
    Expression localMode = (attr == null) ? null : attr.getValue();
    // cachedWithin
    Literal cachedWithin = null;
    attr = removeAttribute("cachedwithin");
    if (attr != null) {
        Expression val = attr.getValue();
        if (val instanceof Literal)
            cachedWithin = ((Literal) val);
    }
    String strAccess = ((LitString) access).getString();
    int acc = ComponentUtil.toIntAccess(strAccess, -1);
    if (acc == -1)
        throw new TransformerException("invalid access type [" + strAccess + "], access types are remote, public, package, private", getStart());
    Function func = new FunctionImpl(page, name, returnType, returnFormat, output, bufferOutput, acc, displayname, description, hint, secureJson, verifyClient, localMode, cachedWithin, modifier, body, getStart(), getEnd());
    // %**%
    Map attrs = getAttributes();
    Iterator it = attrs.entrySet().iterator();
    HashMap<String, Attribute> metadatas = new HashMap<String, Attribute>();
    while (it.hasNext()) {
        attr = (Attribute) ((Map.Entry) it.next()).getValue();
        metadatas.put(attr.getName(), attr);
    }
    func.setMetaData(metadatas);
    return func;
}
Also used : HashMap(java.util.HashMap) LitString(lucee.transformer.expression.literal.LitString) LitString(lucee.transformer.expression.literal.LitString) Function(lucee.transformer.bytecode.statement.udf.Function) IFunction(lucee.transformer.bytecode.statement.IFunction) Expression(lucee.transformer.expression.Expression) Literal(lucee.transformer.expression.literal.Literal) FunctionImpl(lucee.transformer.bytecode.statement.udf.FunctionImpl) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) TransformerException(lucee.transformer.TransformerException)

Example 19 with TransformerException

use of lucee.transformer.TransformerException in project Lucee by lucee.

the class TagLoop method _writeOut.

/**
 * @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    boolean old;
    switch(type) {
        case TYPE_STRUCT:
        case TYPE_COLLECTION:
            writeOutTypeCollection(bc);
            break;
        case TYPE_CONDITION:
            writeOutTypeCondition(bc);
            break;
        case TYPE_FILE:
            writeOutTypeFile(bc);
            break;
        case TYPE_FROM_TO:
            writeOutTypeFromTo(bc);
            break;
        case TYPE_LIST:
            writeOutTypeListArray(bc, false);
            break;
        case TYPE_ARRAY:
            writeOutTypeListArray(bc, true);
            break;
        case TYPE_QUERY:
            old = bc.changeDoSubFunctions(false);
            TagGroupUtil.writeOutTypeQuery(this, bc);
            bc.changeDoSubFunctions(old);
            // writeOutTypeQuery(bc);
            break;
        case TYPE_GROUP:
            old = bc.changeDoSubFunctions(false);
            TagGroupUtil.writeOutTypeGroup(this, bc);
            bc.changeDoSubFunctions(old);
            // writeOutTypeQuery(bc);
            break;
        case TYPE_INNER_GROUP:
            old = bc.changeDoSubFunctions(false);
            TagGroupUtil.writeOutTypeInnerGroup(this, bc);
            bc.changeDoSubFunctions(old);
            break;
        case TYPE_INNER_QUERY:
            old = bc.changeDoSubFunctions(false);
            TagGroupUtil.writeOutTypeInnerQuery(this, bc);
            bc.changeDoSubFunctions(old);
            break;
        case TYPE_TIMES:
            writeOutTypeTimes(bc);
            break;
        case TYPE_NOTHING:
            GeneratorAdapter a = bc.getAdapter();
            DoWhileVisitor dwv = new DoWhileVisitor();
            setLoopVisitor(dwv);
            dwv.visitBeginBody(a);
            getBody().writeOut(bc);
            dwv.visitEndBodyBeginExpr(a);
            a.push(false);
            dwv.visitEndExpr(a);
            break;
        default:
            throw new TransformerException("invalid type", getStart());
    }
}
Also used : DoWhileVisitor(lucee.transformer.bytecode.visitor.DoWhileVisitor) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) TransformerException(lucee.transformer.TransformerException)

Example 20 with TransformerException

use of lucee.transformer.TransformerException in project Lucee by lucee.

the class TagSwitch method _writeOut.

/**
 * @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
 */
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    // expression
    int expression = adapter.newLocal(Types.STRING);
    getAttribute("expression").getValue().writeOut(bc, Expression.MODE_REF);
    adapter.storeLocal(expression);
    List statements = getBody().getStatements();
    Statement stat;
    Tag tag;
    ConditionVisitor cv = new ConditionVisitor();
    cv.visitBefore();
    // cases
    Iterator it = statements.iterator();
    Tag def = null;
    while (it.hasNext()) {
        stat = (Statement) it.next();
        if (stat instanceof Tag) {
            tag = (Tag) stat;
            if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Case")) {
                addCase(bc, cv, tag, expression);
                continue;
            } else if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Defaultcase")) {
                if (def != null)
                    throw new TransformerException("multiple defaultcases are not allowed", getStart());
                def = tag;
            // setDefaultCase(bc,cv,tag);
            // break;
            }
        }
    }
    // default
    if (def != null)
        setDefaultCase(bc, cv, def);
    cv.visitAfter(bc);
}
Also used : ConditionVisitor(lucee.transformer.bytecode.visitor.ConditionVisitor) Statement(lucee.transformer.bytecode.Statement) Iterator(java.util.Iterator) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) List(java.util.List) TransformerException(lucee.transformer.TransformerException)

Aggregations

TransformerException (lucee.transformer.TransformerException)24 GeneratorAdapter (org.objectweb.asm.commons.GeneratorAdapter)11 LitString (lucee.transformer.expression.literal.LitString)9 ExprString (lucee.transformer.expression.ExprString)7 Expression (lucee.transformer.expression.Expression)7 BytecodeContext (lucee.transformer.bytecode.BytecodeContext)5 OnFinally (lucee.transformer.bytecode.visitor.OnFinally)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 TemplateException (lucee.runtime.exp.TemplateException)4 Body (lucee.transformer.bytecode.Body)4 Page (lucee.transformer.bytecode.Page)4 TryCatchFinallyVisitor (lucee.transformer.bytecode.visitor.TryCatchFinallyVisitor)4 Literal (lucee.transformer.expression.literal.Literal)4 Label (org.objectweb.asm.Label)4 BodyBase (lucee.transformer.bytecode.BodyBase)3 Statement (lucee.transformer.bytecode.Statement)3 EvaluatorException (lucee.transformer.cfml.evaluator.EvaluatorException)3 DataMember (lucee.transformer.expression.var.DataMember)3 Member (lucee.transformer.expression.var.Member)3