use of lucee.transformer.expression.literal.LitString 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.expression.literal.LitString in project Lucee by lucee.
the class Loop method execute.
@Override
public TagLib execute(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, Data data) throws TemplateException {
TagLoop loop = (TagLoop) tag;
// label
try {
if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
String l = ls.getString();
if (!StringUtil.isEmpty(l, true)) {
loop.setLabel(l.trim());
tag.removeAttribute("label");
}
}
} catch (EvaluatorException e) {
throw new TemplateException(null, e);
}
return null;
}
use of lucee.transformer.expression.literal.LitString in project Lucee by lucee.
the class AbstrCFMLExprTransformer method newOp.
private Expression newOp(ExprData data, Expression expr) throws TemplateException {
if (!(expr instanceof Variable))
return expr;
Variable var = (Variable) expr;
Member m = var.getFirstMember();
if (!(m instanceof DataMember))
return expr;
ExprString n = ((DataMember) m).getName();
if (!(n instanceof LitString))
return expr;
LitString ls = (LitString) n;
if (!"new".equalsIgnoreCase(ls.getString()))
return expr;
int start = data.srcCode.getPos();
ExprString exprName = readComponentPath(data);
if (exprName == null) {
data.srcCode.setPos(start);
return expr;
}
comments(data);
if (data.srcCode.isCurrent('(')) {
FunctionMember func = getFunctionMember(data, Identifier.toIdentifier(data.factory, "_createComponent", Identifier.CASE_ORIGNAL, null, null), true);
func.addArgument(new Argument(exprName, "string"));
Variable v = expr.getFactory().createVariable(expr.getStart(), expr.getEnd());
v.addMember(func);
comments(data);
return v;
}
data.srcCode.setPos(start);
return expr;
}
use of lucee.transformer.expression.literal.LitString 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.expression.literal.LitString in project Lucee by lucee.
the class TagGroupUtil method writeOutTypeQuery.
public static void writeOutTypeQuery(final TagGroup tag, BytecodeContext bc) throws TransformerException {
final GeneratorAdapter adapter = bc.getAdapter();
tag.setNumberIterator(adapter.newLocal(NUMBER_ITERATOR));
boolean isOutput = tag.getType() == TagGroup.TAG_OUTPUT;
ParseBodyVisitor pbv = isOutput ? new ParseBodyVisitor() : null;
if (isOutput)
pbv.visitBegin(bc);
// Query query=pc.getQuery(@query);
tag.setQuery(adapter.newLocal(Types.QUERY));
adapter.loadArg(0);
Expression val = tag.getAttribute("query").getValue();
val.writeOut(bc, Expression.MODE_REF);
if (val instanceof LitString)
adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_QUERY_STRING);
else
adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_QUERY_OBJ);
adapter.storeLocal(tag.getQuery());
tag.setPID(adapter.newLocal(Types.INT_VALUE));
adapter.loadArg(0);
adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID);
adapter.storeLocal(tag.getPID());
// int startAt=query.getCurrentrow();
final int startAt = adapter.newLocal(Types.INT_VALUE);
adapter.loadLocal(tag.getQuery());
adapter.loadLocal(tag.getPID());
// adapter.loadArg(0);
// adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID);
adapter.invokeInterface(Types.QUERY, TagLoop.GET_CURRENTROW_1);
adapter.storeLocal(startAt);
// if(query.getRecordcount()>0) {
DecisionIntVisitor div = new DecisionIntVisitor();
div.visitBegin();
adapter.loadLocal(tag.getQuery());
adapter.invokeInterface(Types.QUERY, GET_RECORDCOUNT);
div.visitGT();
adapter.push(0);
div.visitEnd(bc);
Label ifRecCount = new Label();
adapter.ifZCmp(Opcodes.IFEQ, ifRecCount);
// startrow
int from = adapter.newLocal(Types.INT_VALUE);
Attribute attrStartRow = tag.getAttribute("startrow");
if (attrStartRow != null) {
// NumberRange.range(@startrow,1)
// attrStartRow.getValue().writeOut(bc, Expression.MODE_VALUE);
bc.getFactory().toExprInt(attrStartRow.getValue()).writeOut(bc, Expression.MODE_VALUE);
// adapter.visitInsn(Opcodes.D2I);
adapter.push(1);
adapter.invokeStatic(Types.NUMBER_RANGE, RANGE);
// adapter.visitInsn(Opcodes.D2I);
} else {
adapter.push(1);
}
adapter.storeLocal(from);
// numberIterator
adapter.loadLocal(from);
adapter.loadLocal(tag.getQuery());
adapter.invokeInterface(Types.QUERY, GET_RECORDCOUNT);
// adapter.visitInsn(Opcodes.I2D);
Attribute attrMaxRow = tag.getAttribute("maxrows");
Attribute attrEndRow = tag.getAttribute("endrow");
if (attrMaxRow != null) {
bc.getFactory().toExprInt(attrMaxRow.getValue()).writeOut(bc, Expression.MODE_VALUE);
adapter.invokeStatic(NUMBER_ITERATOR, LOAD_MAX);
} else if (attrEndRow != null) {
bc.getFactory().toExprInt(attrEndRow.getValue()).writeOut(bc, Expression.MODE_VALUE);
adapter.invokeStatic(NUMBER_ITERATOR, LOAD_END);
} else {
adapter.invokeStatic(NUMBER_ITERATOR, LOAD_2);
}
adapter.storeLocal(tag.getNumberIterator());
// Group
Attribute attrGroup = tag.getAttribute("group");
Attribute attrGroupCS = tag.getAttribute("groupcasesensitive");
tag.setGroup(adapter.newLocal(Types.STRING));
final int groupCaseSensitive = adapter.newLocal(Types.BOOLEAN_VALUE);
if (attrGroup != null) {
attrGroup.getValue().writeOut(bc, Expression.MODE_REF);
adapter.storeLocal(tag.getGroup());
if (attrGroupCS != null)
attrGroupCS.getValue().writeOut(bc, Expression.MODE_VALUE);
else
adapter.push(false);
adapter.storeLocal(groupCaseSensitive);
}
// pc.us().addQuery(query);
adapter.loadArg(0);
adapter.invokeVirtual(Types.PAGE_CONTEXT, US);
adapter.loadLocal(tag.getQuery());
adapter.invokeInterface(UNDEFINED, ADD_QUERY);
// current
final int current = adapter.newLocal(Types.INT_VALUE);
adapter.loadLocal(from);
adapter.push(1);
adapter.visitInsn(Opcodes.ISUB);
adapter.storeLocal(current);
// Try
TryFinallyVisitor tfv = new TryFinallyVisitor(new OnFinally() {
@Override
public void _writeOut(BytecodeContext bc) {
// query.reset();
// query.go(startAt);
adapter.loadLocal(tag.getQuery());
adapter.loadLocal(startAt);
adapter.loadLocal(tag.getPID());
// adapter.loadArg(0);
// adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID);
adapter.invokeInterface(Types.QUERY, TagLoop.GO);
adapter.pop();
// pc.us().removeQuery();
adapter.loadArg(0);
adapter.invokeVirtual(Types.PAGE_CONTEXT, US);
adapter.invokeInterface(UNDEFINED, REMOVE_QUERY);
// NumberIterator.release(ni);
adapter.loadLocal(tag.getNumberIterator());
adapter.invokeStatic(NUMBER_ITERATOR, REALEASE);
}
}, null);
tfv.visitTryBegin(bc);
WhileVisitor wv = new WhileVisitor();
if (tag instanceof TagLoop)
((TagLoop) tag).setLoopVisitor(wv);
wv.visitBeforeExpression(bc);
// while(ni.isValid()) {
adapter.loadLocal(tag.getNumberIterator());
adapter.loadLocal(current);
adapter.push(1);
adapter.visitInsn(Opcodes.IADD);
adapter.invokeVirtual(NUMBER_ITERATOR, IS_VALID_1);
wv.visitAfterExpressionBeforeBody(bc);
// if(!query.go(ni.current()))break;
adapter.loadLocal(tag.getQuery());
adapter.loadLocal(tag.getNumberIterator());
adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
adapter.loadLocal(tag.getPID());
adapter.invokeInterface(Types.QUERY, TagLoop.GO);
NotVisitor.visitNot(bc);
Label _if = new Label();
adapter.ifZCmp(Opcodes.IFEQ, _if);
wv.visitBreak(bc);
adapter.visitLabel(_if);
if (attrGroup != null) {
// NumberIterator oldNi=numberIterator;
int oldNi = adapter.newLocal(NUMBER_ITERATOR);
adapter.loadLocal(tag.getNumberIterator());
adapter.storeLocal(oldNi);
// numberIterator=NumberIterator.load(ni,query,group,grp_case);
adapter.loadArg(0);
adapter.loadLocal(tag.getNumberIterator());
adapter.loadLocal(tag.getQuery());
adapter.loadLocal(tag.getGroup());
adapter.loadLocal(groupCaseSensitive);
adapter.invokeStatic(NUMBER_ITERATOR, LOAD_5);
adapter.storeLocal(tag.getNumberIterator());
// current=oldNi.current();
adapter.loadLocal(oldNi);
adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
adapter.storeLocal(current);
tag.getBody().writeOut(bc);
// tmp(adapter,current);
// NumberIterator.release(ni);
adapter.loadLocal(tag.getNumberIterator());
adapter.invokeStatic(NUMBER_ITERATOR, REALEASE);
// numberIterator=oldNi;
adapter.loadLocal(oldNi);
adapter.storeLocal(tag.getNumberIterator());
} else {
// current=ni.current();
adapter.loadLocal(tag.getNumberIterator());
adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
adapter.storeLocal(current);
tag.getBody().writeOut(bc);
}
// ni.setCurrent(current+1);
/*adapter.loadLocal(tag.getNumberIterator());
adapter.loadLocal(current);
adapter.push(1);
adapter.visitInsn(Opcodes.IADD);
adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/
wv.visitAfterBody(bc, tag.getEnd());
tfv.visitTryEnd(bc);
adapter.visitLabel(ifRecCount);
if (isOutput)
pbv.visitEnd(bc);
}
Aggregations