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);
}
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());
}
}
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;
}
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());
}
}
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);
}
Aggregations