use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class ASMUtil method getAncestorTag.
/**
* Gibt ein uebergeordnetes Tag mit dem uebergebenen Full-Name (Namespace und Name) zurueck,
* falls ein solches existiert, andernfalls wird null zurueckgegeben.
* @param el Startelement, von wo aus gesucht werden soll.
* @param fullName Name des gesuchten Tags.
* @return uebergeornetes Element oder null.
*/
public static Tag getAncestorTag(Statement stat, String fullName) {
Statement parent = stat;
Tag tag;
while (true) {
parent = parent.getParent();
if (parent == null)
return null;
if (parent instanceof Tag) {
tag = (Tag) parent;
if (tag.getFullname().equalsIgnoreCase(fullName))
return tag;
}
}
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method statement.
private boolean statement(ExprData data, Body parent, short context) throws TemplateException {
short prior = data.context;
data.context = context;
comments(data);
Statement child = null;
if (data.srcCode.forwardIfCurrent(';')) {
return true;
} else if ((child = ifStatement(data)) != null)
parent.addStatement(child);
else if ((child = propertyStatement(data, parent)) != null)
parent.addStatement(child);
else if ((child = paramStatement(data, parent)) != null)
parent.addStatement(child);
else // else if(funcStatement(data,parent)); // do nothing, happen already inside the method
if ((child = funcStatement(data, parent)) != null)
parent.addStatement(child);
else if ((child = whileStatement(data)) != null)
parent.addStatement(child);
else if ((child = doStatement(data)) != null)
parent.addStatement(child);
else if ((child = forStatement(data)) != null)
parent.addStatement(child);
else if ((child = returnStatement(data)) != null)
parent.addStatement(child);
else if ((child = switchStatement(data)) != null)
parent.addStatement(child);
else if ((child = tryStatement(data)) != null)
parent.addStatement(child);
else // else if(staticStatement(data,parent)) ; // do nothing, happen already inside the method
if ((child = staticStatement(data, parent)) != null)
parent.addStatement(child);
else if ((child = componentStatement(data, parent)) != null)
parent.addStatement(child);
else if ((child = tagStatement(data, parent)) != null)
parent.addStatement(child);
else if ((child = cftagStatement(data, parent)) != null)
parent.addStatement(child);
else if (block(data, parent)) {
} else
parent.addStatement(expressionStatement(data, parent));
data.docComment = null;
data.context = prior;
return false;
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class TagIf method _writeOut.
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
Label end = new Label();
List<Statement> tmp = new ArrayList<Statement>();
Iterator<Statement> it = getBody().getStatements().iterator();
Tag t;
Label endIf = writeOutElseIfStart(bc, this);
boolean hasElse = false;
while (it.hasNext()) {
Statement stat = it.next();
if (!hasElse && stat instanceof Tag) {
t = (Tag) stat;
if (t.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.ElseIf")) {
__writeOut(bc, tmp);
writeOutElseIfEnd(adapter, endIf, end);
endIf = writeOutElseIfStart(bc, t);
continue;
} else if (t.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Else")) {
__writeOut(bc, tmp);
ExpressionUtil.visitLine(bc, t.getStart());
hasElse = true;
writeOutElseIfEnd(adapter, endIf, end);
continue;
}
}
tmp.add(stat);
// ExpressionUtil.writeOut(stat, bc);
}
__writeOut(bc, tmp);
if (!hasElse)
writeOutElseIfEnd(adapter, endIf, end);
adapter.visitLabel(end);
}
use of lucee.transformer.bytecode.Statement 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);
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class TagTry method _writeOut.
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
final GeneratorAdapter adapter = bc.getAdapter();
adapter.visitLabel(begin);
Body tryBody = new BodyBase(getFactory());
List<Tag> catches = new ArrayList<Tag>();
Tag tmpFinal = null;
tryBody.setParent(getBody().getParent());
List<Statement> statements = getBody().getStatements();
Statement stat;
Tag tag;
{
Iterator<Statement> it = statements.iterator();
while (it.hasNext()) {
stat = it.next();
if (stat instanceof Tag) {
tag = (Tag) stat;
if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Catch")) {
catches.add(tag);
continue;
} else if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Finally")) {
tmpFinal = tag;
continue;
}
}
tryBody.addStatement(stat);
}
;
}
final Tag _finally = tmpFinal;
// has no try body, if there is no try body, no catches are executed, only finally
if (!tryBody.hasStatements()) {
if (_finally != null && _finally.getBody() != null) {
BodyBase.writeOut(bc, _finally.getBody());
// ExpressionUtil.writeOut(_finally.getBody(), bc);
}
return;
}
final int old = adapter.newLocal(Types.PAGE_EXCEPTION);
adapter.loadArg(0);
adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_CATCH);
adapter.storeLocal(old);
TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(new OnFinally() {
@Override
public void _writeOut(BytecodeContext bc) throws TransformerException {
adapter.loadArg(0);
adapter.loadLocal(old);
adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH_PE);
if (_finally != null) {
ExpressionUtil.visitLine(bc, _finally.getStart());
BodyBase.writeOut(bc, _finally.getBody());
// ExpressionUtil.writeOut(_finally.getBody(), bc);
}
}
}, getFlowControlFinal());
// Try
tcfv.visitTryBegin(bc);
BodyBase.writeOut(bc, tryBody);
// ExpressionUtil.writeOut(tryBody, bc);
int e = tcfv.visitTryEndCatchBeging(bc);
// if(e instanceof lucee.runtime.exp.Abort) throw e;
Label abortEnd = new Label();
adapter.loadLocal(e);
// Abort.isAbort(t);
adapter.invokeStatic(Types.ABORT, TryCatchFinally.IS_ABORT);
// adapter.instanceOf(Types.ABORT);
adapter.ifZCmp(Opcodes.IFEQ, abortEnd);
adapter.loadLocal(e);
adapter.throwException();
adapter.visitLabel(abortEnd);
// PageExceptionImpl old=pc.getCatch();
// PageException pe=Caster.toPageEception(e);
int pe = adapter.newLocal(Types.PAGE_EXCEPTION);
adapter.loadLocal(e);
adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION);
adapter.storeLocal(pe);
Iterator<Tag> it = catches.iterator();
Attribute attrType;
Expression type;
Label endAllIfs = new Label();
Tag tagElse = null;
while (it.hasNext()) {
tag = it.next();
Label endIf = new Label();
attrType = tag.getAttribute("type");
type = bc.getFactory().createLitString("any");
if (attrType != null)
type = attrType.getValue();
if (type instanceof LitString && ((LitString) type).getString().equalsIgnoreCase("any")) {
tagElse = tag;
continue;
}
ExpressionUtil.visitLine(bc, tag.getStart());
// if(pe.typeEqual(@type)
adapter.loadLocal(pe);
type.writeOut(bc, Expression.MODE_REF);
adapter.invokeVirtual(Types.PAGE_EXCEPTION, TYPE_EQUAL);
adapter.ifZCmp(Opcodes.IFEQ, endIf);
catchBody(bc, adapter, tag, pe, true, true);
adapter.visitJumpInsn(Opcodes.GOTO, endAllIfs);
adapter.visitLabel(endIf);
}
// else
if (tagElse != null) {
catchBody(bc, adapter, tagElse, pe, true, true);
} else {
// pc.setCatch(pe,true);
adapter.loadArg(0);
adapter.loadLocal(pe);
adapter.push(false);
adapter.push(true);
adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH3);
// throw pe;
adapter.loadLocal(pe);
adapter.throwException();
}
adapter.visitLabel(endAllIfs);
// PageExceptionImpl old=pc.getCatch();
tcfv.visitCatchEnd(bc);
}
Aggregations