use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class ASMUtil method remove.
/**
* remove this tag from his parent body
* @param tag
*/
public static void remove(Tag tag) {
Body body = (Body) tag.getParent();
body.getStatements().remove(tag);
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class ASMUtil method replace.
/**
* replace src with trg
* @param src
* @param trg
*/
public static void replace(Tag src, Tag trg, boolean moveBody) {
trg.setParent(src.getParent());
Body p = (Body) src.getParent();
List<Statement> stats = p.getStatements();
Iterator<Statement> it = stats.iterator();
Statement stat;
int count = 0;
while (it.hasNext()) {
stat = it.next();
if (stat == src) {
if (moveBody && src.getBody() != null)
src.getBody().setParent(trg);
stats.set(count, trg);
break;
}
count++;
}
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class ASMUtil method move.
public static void move(Tag src, Body dest) {
// switch children
Body srcBody = (Body) src.getParent();
Iterator<Statement> it = srcBody.getStatements().iterator();
Statement stat;
while (it.hasNext()) {
stat = it.next();
if (stat == src) {
it.remove();
dest.addStatement(stat);
}
}
// switch parent
src.setParent(dest);
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method tryStatement.
/**
* Liest eine try Block ein
* <br />
* EBNF:<br />
* <code>;</code>
* @return Try Block
* @throws TemplateException
*/
private final TryCatchFinally tryStatement(ExprData data) throws TemplateException {
if (!data.srcCode.forwardIfCurrent("try", '{') && !data.srcCode.forwardIfCurrent("try ") && !data.srcCode.forwardIfCurrent("try", '/'))
return null;
data.srcCode.previous();
Body body = new BodyBase(data.factory);
TryCatchFinally tryCatchFinally = new TryCatchFinally(data.factory, body, data.srcCode.getPosition(), null);
statement(data, body, CTX_TRY);
comments(data);
// catches
short catchCount = 0;
while (data.srcCode.forwardIfCurrent("catch", '(')) {
catchCount++;
comments(data);
// type
int pos = data.srcCode.getPos();
Position line = data.srcCode.getPosition();
Expression name = null, type = null;
StringBuffer sbType = new StringBuffer();
String id;
while (true) {
id = identifier(data, false);
if (id == null)
break;
sbType.append(id);
data.srcCode.removeSpace();
if (!data.srcCode.forwardIfCurrent('.'))
break;
sbType.append('.');
data.srcCode.removeSpace();
}
if (sbType.length() == 0) {
type = string(data);
if (type == null)
throw new TemplateException(data.srcCode, "a catch statement must begin with the throwing type (query, application ...).");
} else {
type = data.factory.createLitString(sbType.toString());
}
// name = expression();
comments(data);
// name
if (!data.srcCode.isCurrent(')')) {
name = expression(data);
} else {
data.srcCode.setPos(pos);
name = expression(data);
type = data.factory.createLitString("any");
}
comments(data);
Body b = new BodyBase(data.factory);
try {
tryCatchFinally.addCatch(type, name, b, line);
} catch (TransformerException e) {
throw new TemplateException(data.srcCode, e.getMessage());
}
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid catch statement, missing closing )");
statement(data, b, CTX_CATCH);
comments(data);
}
// finally
if (finallyStatement(data, tryCatchFinally)) {
comments(data);
} else if (catchCount == 0)
throw new TemplateException(data.srcCode, "a try statement must have at least one catch statement");
// if(body.isEmpty()) return null;
tryCatchFinally.setEnd(data.srcCode.getPosition());
return tryCatchFinally;
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method caseStatement.
/**
* Liest ein Case Statement ein
* @return case Statement
* @throws TemplateException
*/
private final boolean caseStatement(ExprData data, Switch swit) throws TemplateException {
if (!data.srcCode.forwardIfCurrentAndNoWordAfter("case"))
return false;
// int line=data.srcCode.getLine();
comments(data);
Expression expr = super.expression(data);
comments(data);
if (!data.srcCode.forwardIfCurrent(':'))
throw new TemplateException(data.srcCode, "case body must start with [:]");
Body body = new BodyBase(data.factory);
switchBlock(data, body);
swit.addCase(expr, body);
return true;
}
Aggregations