use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class ASMUtil method hasSisterTagAfter.
/**
* Prueft ob das das angegebene Tag in der gleichen Ebene nach dem angegebenen Tag vorkommt.
* @param tag Ausgangspunkt, nach diesem tag darf das angegebene nicht vorkommen.
* @param nameToFind Tag Name der nicht vorkommen darf
* @return kommt das Tag vor.
*/
public static boolean hasSisterTagAfter(Tag tag, String nameToFind) {
Body body = (Body) tag.getParent();
List<Statement> stats = body.getStatements();
Iterator<Statement> it = stats.iterator();
Statement other;
boolean isAfter = false;
while (it.hasNext()) {
other = it.next();
if (other instanceof Tag) {
if (isAfter) {
if (((Tag) other).getTagLibTag().getName().equals(nameToFind))
return true;
} else if (other == tag)
isAfter = true;
}
}
return false;
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class Function method throwIfNotEmpty.
public static void throwIfNotEmpty(Tag tag) throws EvaluatorException {
Body body = tag.getBody();
List<Statement> statments = body.getStatements();
Statement stat;
Iterator<Statement> it = statments.iterator();
TagLibTag tlt;
while (it.hasNext()) {
stat = it.next();
if (stat instanceof Tag) {
tlt = ((Tag) stat).getTagLibTag();
if (!tlt.getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Argument"))
throw new EvaluatorException("tag " + tlt.getFullName() + " is not allowed inside a function declaration");
}
/*else if(stat instanceof PrintOut) {
//body.remove(stat);
}*/
}
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class Mail method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
if (tag.containsAttribute("query")) {
TagLib lib = libTag.getTagLib();
TagLibTag outputTag = lib.getTag("output");
TagOutput output = new TagOutput(tag.getFactory(), tag.getStart(), null);
output.setFullname(outputTag.getFullName());
output.setTagLibTag(outputTag);
output.addAttribute(new Attribute(false, "output", tag.getFactory().TRUE(), "boolean"));
output.addAttribute(new Attribute(false, "formail", tag.getFactory().TRUE(), "boolean"));
// output.getBody();
Body body = new BodyBase(tag.getFactory());
output.setBody(body);
ASMUtil.replace(tag, output, false);
body.addStatement(tag);
output.addAttribute(tag.removeAttribute("query"));
if (tag.containsAttribute("group"))
output.addAttribute(tag.removeAttribute("group"));
if (tag.containsAttribute("groupcasesensitive"))
output.addAttribute(tag.removeAttribute("groupcasesensitive"));
if (tag.containsAttribute("startrow"))
output.addAttribute(tag.removeAttribute("startrow"));
if (tag.containsAttribute("maxrows"))
output.addAttribute(tag.removeAttribute("maxrows"));
new Output().evaluate(output, outputTag);
}
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class Query method translateChildren.
private void translateChildren(Iterator it) {
Statement stat;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof PrintOut) {
PrintOut printOut = ((PrintOut) stat);
Expression e = printOut.getExpr();
if (!(e instanceof Literal)) {
Expression expr = removeCastString(e);
if (expr instanceof Variable) {
// do not preserve BIF PreserveSingleQuotes return value
Member member = ((Variable) expr).getFirstMember();
if (member instanceof BIF) {
BIF bif = (BIF) member;
if (bif.getClassDefinition().getClassName().equals(PreserveSingleQuotes.class.getName())) {
printOut.setExpr(bif.getArguments()[0].getValue());
continue;
} else if (bif.getClassDefinition().getClassName().equals(ListQualify.class.getName())) {
Argument[] args = bif.getArguments();
List<Argument> arr = new ArrayList<Argument>();
// first get existing arguments
arr.add(args[0]);
arr.add(args[1]);
if (args.length >= 3)
arr.add(args[2]);
else
arr.add(new Argument(expr.getFactory().createLitString(","), "string"));
if (args.length >= 4)
arr.add(args[3]);
else
arr.add(new Argument(expr.getFactory().createLitString("all"), "string"));
if (args.length >= 5)
arr.add(args[4]);
else
arr.add(new Argument(expr.getFactory().createLitBoolean(false), "boolean"));
// PSQ-BIF DO NOT REMOVE THIS COMMENT
arr.add(new Argument(expr.getFactory().createLitBoolean(true), "boolean"));
bif.setArguments(arr.toArray(new Argument[arr.size()]));
continue;
} else if (bif.getClassDefinition().getClassName().equals(QuotedValueList.class.getName()) || bif.getClassDefinition().getClassName().equals(ValueList.class.getName())) {
// printOut.setPreserveSingleQuote(false);
continue;
}
}
// do not preserve UDF return value
member = ((Variable) expr).getLastMember();
if (member instanceof UDF)
continue;
}
printOut.setCheckPSQ(true);
if (e != expr)
printOut.setExpr(expr);
}
} else if (stat instanceof Tag) {
Body b = ((Tag) stat).getBody();
if (b != null)
translateChildren(b.getStatements().iterator());
} else if (stat instanceof Body) {
translateChildren(((Body) stat).getStatements().iterator());
}
}
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class Static method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
// check parent
Body body = null;
String compName = Property.getComponentName(tag);
boolean isCompChild = false;
Tag p = ASMUtil.getParentTag(tag);
if (p != null && (p instanceof TagComponent || getFullname(p, "").equalsIgnoreCase(compName))) {
isCompChild = true;
body = p.getBody();
}
Tag pp = p != null ? ASMUtil.getParentTag(p) : null;
if (!isCompChild && pp != null && (p instanceof TagComponent || getFullname(pp, "").equalsIgnoreCase(compName))) {
isCompChild = true;
body = pp.getBody();
}
if (!isCompChild) {
throw new EvaluatorException("Wrong Context for the the static constructor, " + "a static constructor must inside a component body.");
}
// Body body=(Body) tag.getParent();
List<Statement> children = tag.getBody().getStatements();
// remove that tag from parent
ASMUtil.remove(tag);
StaticBody sb = getStaticBody(body);
ASMUtil.addStatements(sb, children);
}
Aggregations