use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class Try method evaluate.
/**
* @see lucee.transformer.cfml.evaluator.EvaluatorSupport#evaluate(Element)
*/
@Override
public void evaluate(Tag tag) throws EvaluatorException {
Body body = tag.getBody();
int catchCount = 0;
int noCatchCount = 0;
int finallyCount = 0;
// count catch tag and other in body
if (body != null) {
List stats = body.getStatements();
Iterator it = stats.iterator();
Statement stat;
Tag t;
String name;
while (it.hasNext()) {
stat = (Statement) it.next();
if (stat instanceof Tag) {
t = (Tag) stat;
name = t.getTagLibTag().getName();
if (name.equals("finally")) {
finallyCount++;
noCatchCount++;
} else if (name.equals("catch"))
catchCount++;
else
noCatchCount++;
} else
noCatchCount++;
}
}
// check if has Content
if (catchCount == 0 && finallyCount == 0)
throw new EvaluatorException("Wrong Context, tag cftry must have at least one tag cfcatch inside or a cffinally tag.");
if (finallyCount > 1)
throw new EvaluatorException("Wrong Context, tag cftry can have only one tag cffinally inside.");
// check if no has Content
if (noCatchCount == 0) {
ASMUtil.remove(tag);
}
}
use of lucee.transformer.bytecode.Body 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.Body in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method lambdaPart.
@Override
protected final Function lambdaPart(ExprData data, String id, int access, int modifier, String rtnType, Position line, ArrayList<Argument> args) throws TemplateException {
Body body = new FunctionBody(data.factory);
Function func = new Lambda(data.root, id, access, modifier, rtnType, body, line, null);
// new FunctionImpl(data.page,id,access,rtnType,body,line,null);
comments(data);
// add arguments
for (Argument arg : args) {
func.addArgument(arg.getName(), arg.getType(), arg.getRequired(), arg.getDefaultValue(), arg.isPassByReference(), arg.getDisplayName(), arg.getHint(), arg.getMetaData());
}
comments(data);
// body
boolean oldInsideFunction = data.insideFunction;
data.insideFunction = true;
try {
if (data.srcCode.isCurrent('{')) {
statement(data, body, CTX_FUNCTION);
} else {
if (data.srcCode.forwardIfCurrent("return ")) {
comments(data);
}
// ex block
short prior = data.context;
data.context = CTX_FUNCTION;
comments(data);
Expression expr = expression(data);
// checkSemiColonLineFeed( data, true ,true );
Return rtn = new Return(expr, line, data.srcCode.getPosition());
body.addStatement(rtn);
data.docComment = null;
data.context = prior;
}
} finally {
data.insideFunction = oldInsideFunction;
}
/*try {
// ex block
statement(data,body,CTX_FUNCTION);
}
finally{
data.insideFunction=oldInsideFunction;
}*/
func.setEnd(data.srcCode.getPosition());
comments(data);
return func;
}
use of lucee.transformer.bytecode.Body 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;
}
use of lucee.transformer.bytecode.Body in project Lucee by lucee.
the class AbstrCFMLScriptTransformer method __singleAttrStatement.
private final Statement __singleAttrStatement(Body parent, ExprData data, TagLibTag tlt, boolean allowTwiceAttr) throws TemplateException {
String tagName = tlt.getName();
if (data.srcCode.forwardIfCurrent(tagName)) {
if (!data.srcCode.isCurrent(' ') && !data.srcCode.isCurrent(';')) {
data.srcCode.setPos(data.srcCode.getPos() - tagName.length());
return null;
}
} else
return null;
int pos = data.srcCode.getPos() - tagName.length();
Position line = data.srcCode.getPosition();
// TagLibTag tlt = CFMLTransformer.getTLT(data.srcCode,tagName.equals("pageencoding")?"processingdirective":tagName);
Tag tag = getTag(data, parent, tlt, line, null);
tag.setScriptBase(true);
tag.setTagLibTag(tlt);
comments(data);
// attribute
TagLibTagAttr attr = tlt.getScript().getSingleAttr();
String attrName = null;
Expression attrValue = null;
short attrType = ATTR_TYPE_NONE;
if (attr != null) {
attrType = attr.getScriptSupport();
char c = data.srcCode.getCurrent();
if (ATTR_TYPE_REQUIRED == attrType || (!data.srcCode.isCurrent(';') && ATTR_TYPE_OPTIONAL == attrType)) {
if (data.srcCode.isCurrent('{')) {
// this can be only a json string
int p = data.srcCode.getPos();
try {
attrValue = isSimpleValue(attr.getType()) ? null : json(data, JSON_STRUCT, '{', '}');
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
data.srcCode.setPos(p);
}
} else
attrValue = attributeValue(data, tlt.getScript().getRtexpr());
if (attrValue != null && isOperator(c)) {
data.srcCode.setPos(pos);
return null;
}
}
}
if (attrValue != null) {
attrName = attr.getName();
TagLibTagAttr tlta = tlt.getAttribute(attr.getName(), true);
tag.addAttribute(new Attribute(false, attrName, CastOther.toExpression(attrValue, tlta.getType()), tlta.getType()));
} else if (ATTR_TYPE_REQUIRED == attrType) {
data.srcCode.setPos(pos);
return null;
}
// body
if (tlt.getHasBody()) {
Body body = new BodyBase(data.factory);
boolean wasSemiColon = statement(data, body, tlt.getScript().getContext());
if (!wasSemiColon || !tlt.isBodyFree() || body.hasStatements())
tag.setBody(body);
} else
checkSemiColonLineFeed(data, true, true, true);
if (tlt.hasTTE())
data.ep.add(tlt, tag, data.flibs, data.srcCode);
if (!StringUtil.isEmpty(attrName))
validateAttributeName(attrName, data.srcCode, new ArrayList<String>(), tlt, new RefBooleanImpl(false), new StringBuffer(), allowTwiceAttr);
tag.setEnd(data.srcCode.getPosition());
eval(tlt, data, tag);
return tag;
}
Aggregations