use of lucee.transformer.bytecode.FunctionBody 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.FunctionBody 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