use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class Continue method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag) throws EvaluatorException {
String ns = libTag.getTagLib().getNameSpaceAndSeparator();
String loopName = ns + "loop";
String whileName = ns + "while";
// label
String label = null;
Attribute attrLabel = tag.getAttribute("label");
if (attrLabel != null) {
TagContinue tc = (TagContinue) tag;
label = Break.variableToString(tag, attrLabel, null);
if (label != null) {
tc.setLabel(label = label.trim());
tag.removeAttribute("label");
} else if (ASMUtil.isLiteralAttribute(tag, attrLabel, ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
label = ls.getString();
if (!StringUtil.isEmpty(label, true)) {
tc.setLabel(label = label.trim());
tag.removeAttribute("label");
} else
label = null;
}
}
if (ASMUtil.isLiteralAttribute(tag, "label", ASMUtil.TYPE_STRING, false, true)) {
LitString ls = (LitString) tag.getFactory().toExprString(tag.getAttribute("label").getValue());
TagContinue tc = (TagContinue) tag;
label = ls.getString();
if (!StringUtil.isEmpty(label, true)) {
tc.setLabel(label = label.trim());
tag.removeAttribute("label");
} else
label = null;
}
if (!ASMUtil.hasAncestorContinueFCStatement(tag, label)) {
if (tag.isScriptBase()) {
if (StringUtil.isEmpty(label))
throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...)");
throw new EvaluatorException("Wrong Context, " + libTag.getName() + " must be inside a loop (for,while,loop ...) with the label [" + label + "]");
}
if (StringUtil.isEmpty(label))
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag");
throw new EvaluatorException("Wrong Context, tag " + libTag.getFullName() + " must be inside a " + loopName + " or " + whileName + " tag with the label [" + label + "]");
}
}
use of lucee.transformer.bytecode.statement.tag.Attribute 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.statement.tag.Attribute in project Lucee by lucee.
the class Sprite method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag tagLibTag, FunctionLib[] flibs) throws EvaluatorException {
String id = "sprite_" + IDGenerator.intId();
try {
Page page = ASMUtil.getAncestorPage(tag);
SourceCode sc = page.getSourceCode();
String key = sc.id();
key = HashUtil.create64BitHashAsString(Thread.currentThread().getId() + ":" + key);
Expression src = tag.getAttribute("src").getValue();
// get data from previous sprites
Previous previous = sprites.get(key);
if (previous != null) {
previous.tag.removeAttribute("_ids");
previous.tag.removeAttribute("_srcs");
previous.tag = tag;
} else {
sprites.put(key, previous = new Previous(tag));
}
previous.ids.add(id);
if (previous.src == null)
previous.src = src;
else {
previous.src = tag.getFactory().opString(previous.src, tag.getFactory().createLitString(","));
previous.src = tag.getFactory().opString(previous.src, src);
}
tag.addAttribute(new Attribute(false, "_id", tag.getFactory().createLitString(id), "string"));
tag.addAttribute(new Attribute(false, "_ids", tag.getFactory().createLitString(lucee.runtime.type.util.ListUtil.listToList(previous.ids, ",")), "string"));
tag.addAttribute(new Attribute(false, "_srcs", previous.src, "string"));
} catch (Throwable e) {
// TODO handle Excpetion much more precise
ExceptionUtil.rethrowIfNecessary(e);
throw new PageRuntimeException(Caster.toPageException(e));
}
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method __multiAttrStatement.
private final Tag __multiAttrStatement(Body parent, ExprData data, TagLibTag tlt) throws TemplateException {
if (data.ep == null)
return null;
String type = tlt.getName();
if (data.srcCode.forwardIfCurrent(type) || // lucee dialect support component as alias for class
(data.srcCode.getDialect() == CFMLEngine.DIALECT_LUCEE && type.equalsIgnoreCase(Constants.LUCEE_COMPONENT_TAG_NAME) && data.srcCode.forwardIfCurrent(Constants.CFML_COMPONENT_TAG_NAME))) {
boolean isValid = (data.srcCode.isCurrent(' ') || (tlt.getHasBody() && data.srcCode.isCurrent('{')));
if (!isValid) {
data.srcCode.setPos(data.srcCode.getPos() - type.length());
return null;
}
} else
return null;
Position line = data.srcCode.getPosition();
TagLibTagScript script = tlt.getScript();
// TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,type);
if (script.getContext() == CTX_CFC)
data.isCFC = true;
else if (script.getContext() == CTX_INTERFACE)
data.isInterface = true;
// Tag tag=new TagComponent(line);
Tag tag = getTag(data, parent, tlt, line, null);
tag.setTagLibTag(tlt);
tag.setScriptBase(true);
// add component meta data
if (data.isCFC) {
addMetaData(data, tag, IGNORE_LIST_COMPONENT);
}
if (data.isInterface) {
addMetaData(data, tag, IGNORE_LIST_INTERFACE);
}
// EvaluatorPool.getPool();
comments(data);
// attributes
// attributes(func,data);
Attribute[] attrs = attributes(tag, tlt, data, SEMI_BLOCK, data.factory.EMPTY(), script.getRtexpr() ? Boolean.TRUE : Boolean.FALSE, null, false, ',', false);
for (int i = 0; i < attrs.length; i++) {
tag.addAttribute(attrs[i]);
}
comments(data);
// body
if (tlt.getHasBody()) {
Body body = new BodyBase(data.factory);
boolean wasSemiColon = statement(data, body, script.getContext());
if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
tag.setBody(body);
} else
checkSemiColonLineFeed(data, true, true, true);
tag.setEnd(data.srcCode.getPosition());
eval(tlt, data, tag);
return tag;
}
use of lucee.transformer.bytecode.statement.tag.Attribute in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method closurePart.
@Override
protected final Function closurePart(ExprData data, String id, int access, int modifier, String rtnType, Position line, boolean closure) throws TemplateException {
Body body = new FunctionBody(data.factory);
Function func = closure ? new Closure(data.root, id, access, modifier, rtnType, body, line, null) : new FunctionImpl(data.root, id, access, modifier, rtnType, body, line, null);
comments(data);
if (!data.srcCode.forwardIfCurrent('('))
throw new TemplateException(data.srcCode, "invalid syntax in function head, missing begin [(]");
// arguments
ArrayList<Argument> args = getScriptFunctionArguments(data);
for (Argument arg : args) {
func.addArgument(arg.getName(), arg.getType(), arg.getRequired(), arg.getDefaultValue(), arg.isPassByReference(), arg.getDisplayName(), arg.getHint(), arg.getMetaData());
}
// end )
comments(data);
if (!data.srcCode.forwardIfCurrent(')'))
throw new TemplateException(data.srcCode, "invalid syntax in function head, missing ending [)]");
// doc comment
if (data.docComment != null) {
func.setHint(data.factory, data.docComment.getHint());
// params
/*Map<String, Attribute> params = data.docComment.getParams();
Iterator<Attribute> it = params.values().iterator();
Attribute attr;
String name;
while(it.hasNext()){
attr=it.next();
name=attr.getName();
}*/
func.setMetaData(data.docComment.getParams());
data.docComment = null;
}
comments(data);
// attributes
Attribute[] attrs = attributes(null, null, data, SEMI_BLOCK, data.factory.EMPTY(), Boolean.TRUE, null, false, NO_ATTR_SEP, true);
for (int i = 0; i < attrs.length; i++) {
func.addAttribute(attrs[i]);
}
// body
boolean oldInsideFunction = data.insideFunction;
data.insideFunction = true;
try {
// ex block
statement(data, body, CTX_FUNCTION);
} finally {
data.insideFunction = oldInsideFunction;
}
func.setEnd(data.srcCode.getPosition());
if (closure)
comments(data);
return func;
}
Aggregations