use of lucee.transformer.bytecode.statement.PrintOut 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.PrintOut 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.PrintOut 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);
}
use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.
the class BodyBase method concatPrintouts.
private boolean concatPrintouts(String str) {
if (last instanceof PrintOut) {
PrintOut po = (PrintOut) last;
Expression expr = po.getExpr();
if (expr instanceof LitString) {
LitString lit = (LitString) expr;
if (lit.getString().length() < 1024) {
po.setExpr(lit.getFactory().createLitString(lit.getString().concat(str), lit.getStart(), lit.getEnd()));
return true;
}
}
}
return false;
}
use of lucee.transformer.bytecode.statement.PrintOut in project Lucee by lucee.
the class ASMUtil method removeLiterlChildren.
public static void removeLiterlChildren(Tag tag, boolean recursive) {
Body body = tag.getBody();
if (body != null) {
List<Statement> list = body.getStatements();
Statement[] stats = list.toArray(new Statement[list.size()]);
PrintOut po;
Tag t;
for (int i = 0; i < stats.length; i++) {
if (stats[i] instanceof PrintOut) {
po = (PrintOut) stats[i];
if (po.getExpr() instanceof Literal) {
body.getStatements().remove(po);
}
} else if (recursive && stats[i] instanceof Tag) {
t = (Tag) stats[i];
if (t.getTagLibTag().isAllowRemovingLiteral()) {
removeLiterlChildren(t, recursive);
}
}
}
}
}
Aggregations