use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class Interface method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
super.evaluate(tag, libTag);
Body body = tag.getBody();
List<Statement> statments = body.getStatements();
Statement stat;
Iterator<Statement> it = statments.iterator();
Tag t;
while (it.hasNext()) {
stat = it.next();
if (stat instanceof PrintOut) {
// body.remove(stat);
} else if (stat instanceof Tag) {
t = (Tag) stat;
if (stat instanceof TagImport) {
// ignore
} else if (stat instanceof TagFunction) {
Function.throwIfNotEmpty(t);
Attribute attr = t.getAttribute("access");
if (attr != null) {
ExprString expr = t.getFactory().toExprString(attr.getValue());
if (!(expr instanceof LitString))
throw new EvaluatorException("the attribute access of the Tag function inside an interface must contain a constant value");
String access = ((LitString) expr).getString().trim();
if (!"public".equalsIgnoreCase(access))
throw new EvaluatorException("the attribute access of the tag function inside an interface definition can only have the value [public] not [" + access + "]");
} else
t.addAttribute(new Attribute(false, "access", stat.getFactory().createLitString("public"), "string"));
} else
throw new EvaluatorException("tag " + libTag.getFullName() + " can only contain function definitions.");
}
}
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class Output method addEncodeToChildren.
private void addEncodeToChildren(Iterator it, Expression encodeForValue, FunctionLibFunction encodeForBIF) {
Statement stat;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof PrintOut) {
PrintOut printOut = ((PrintOut) stat);
Expression e = removeCastString(printOut.getExpr());
if (!(e instanceof Literal)) {
if (e instanceof Variable) {
Member member = ((Variable) e).getFirstMember();
if (member instanceof BIF) {
BIF bif = (BIF) member;
String cn = bif.getClassDefinition().getClassName();
if (cn.startsWith(ENCODE_FOR) || cn.equals(ESAPIEncode.class.getName())) {
continue;
}
}
}
printOut.setEncodeFor(encodeForValue);
}
} else if (stat instanceof Tag) {
Body b = ((Tag) stat).getBody();
if (b != null)
addEncodeToChildren(b.getStatements().iterator(), encodeForValue, encodeForBIF);
} else if (stat instanceof Body) {
addEncodeToChildren(((Body) stat).getStatements().iterator(), encodeForValue, encodeForBIF);
}
}
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class Static method getStaticBody.
static StaticBody getStaticBody(Body body) {
Iterator<Statement> it = body.getStatements().iterator();
Statement s;
while (it.hasNext()) {
s = it.next();
if (s instanceof StaticBody)
return (StaticBody) s;
}
StaticBody sb = new StaticBody(body.getFactory());
body.addStatement(sb);
return sb;
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class TagCIObject method getStaticBodies.
public List<StaticBody> getStaticBodies() {
Body b = getBody();
List<StaticBody> list = null;
if (!ASMUtil.isEmpty(b)) {
Statement stat;
Iterator<Statement> it = b.getStatements().iterator();
while (it.hasNext()) {
stat = it.next();
// StaticBody
if (stat instanceof StaticBody) {
it.remove();
if (list == null)
list = new ArrayList<StaticBody>();
list.add((StaticBody) stat);
// return (StaticBody) stat;
}
}
}
return list;
}
use of lucee.transformer.bytecode.Statement in project Lucee by lucee.
the class TagFunction method _writeOut.
public void _writeOut(BytecodeContext bc, int type) throws TransformerException {
// private static final Expression EMPTY = LitString.toExprString("");
Body functionBody = new BodyBase(bc.getFactory());
RefBoolean isStatic = new RefBooleanImpl();
Function func = createFunction(bc.getPage(), functionBody, isStatic, bc.getOutput());
// ScriptBody sb=new ScriptBody(bc.getFactory());
func.setParent(getParent());
List<Statement> statements = getBody().getStatements();
Statement stat;
Tag tag;
// suppress WS between cffunction and the last cfargument
Tag last = null;
if (bc.getSupressWSbeforeArg()) {
// check if there is a cfargument at all
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.Argument")) {
last = tag;
}
}
}
// check if there are only literal WS printouts
if (last != null) {
it = statements.iterator();
while (it.hasNext()) {
stat = it.next();
if (stat == last)
break;
if (stat instanceof PrintOut) {
PrintOut po = (PrintOut) stat;
Expression expr = po.getExpr();
if (!(expr instanceof LitString) || !StringUtil.isWhiteSpace(((LitString) expr).getString())) {
last = null;
break;
}
}
}
}
}
Iterator<Statement> it = statements.iterator();
boolean beforeLastArgument = last != null;
while (it.hasNext()) {
stat = it.next();
if (beforeLastArgument) {
if (stat == last) {
beforeLastArgument = false;
} else if (stat instanceof PrintOut) {
PrintOut po = (PrintOut) stat;
Expression expr = po.getExpr();
if (expr instanceof LitString) {
LitString ls = (LitString) expr;
if (StringUtil.isWhiteSpace(ls.getString()))
continue;
}
}
}
if (stat instanceof Tag) {
tag = (Tag) stat;
if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument")) {
addArgument(func, tag);
continue;
}
}
functionBody.addStatement(stat);
}
func._writeOut(bc, type);
}
Aggregations