use of com.sun.tools.javac.tree.JCTree.JCReturn in project ceylon-compiler by ceylon.
the class NamedArgumentInvocation method bindMethodArgument.
private void bindMethodArgument(Tree.MethodArgument methodArg, Parameter declaredParam, Naming.SyntheticName argName) {
ListBuffer<JCStatement> statements;
Function model = methodArg.getDeclarationModel();
List<JCStatement> body;
boolean prevNoExpressionlessReturn = gen.statementGen().noExpressionlessReturn;
boolean prevSyntheticClassBody = gen.expressionGen().withinSyntheticClassBody(Decl.isMpl(model) || gen.expressionGen().isWithinSyntheticClassBody());
try {
gen.statementGen().noExpressionlessReturn = gen.isAnything(model.getType());
if (methodArg.getBlock() != null) {
body = gen.statementGen().transformBlock(methodArg.getBlock());
if (!methodArg.getBlock().getDefinitelyReturns()) {
if (gen.isAnything(model.getType())) {
body = body.append(gen.make().Return(gen.makeNull()));
} else {
body = body.append(gen.make().Return(gen.makeErroneous(methodArg.getBlock(), "compiler bug: non-void method does not definitely return")));
}
}
} else {
Expression expr = methodArg.getSpecifierExpression().getExpression();
BoxingStrategy boxing = CodegenUtil.getBoxingStrategy(model);
Type type = model.getType();
JCExpression transExpr = gen.expressionGen().transformExpression(expr, boxing, type);
JCReturn returnStat = gen.make().Return(transExpr);
body = List.<JCStatement>of(returnStat);
}
} finally {
gen.expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
gen.statementGen().noExpressionlessReturn = prevNoExpressionlessReturn;
}
Type callableType = model.appliedReference(null, Collections.<Type>emptyList()).getFullType();
CallableBuilder callableBuilder = CallableBuilder.methodArgument(gen.gen(), methodArg, model, callableType, Collections.singletonList(methodArg.getParameterLists().get(0)), gen.classGen().transformMplBody(methodArg.getParameterLists(), model, body));
JCExpression callable = callableBuilder.build();
JCExpression typeExpr = gen.makeJavaType(callableType, JT_RAW);
JCVariableDecl varDecl = gen.makeVar(argName, typeExpr, callable);
statements = ListBuffer.<JCStatement>of(varDecl);
bind(declaredParam, argName, gen.makeJavaType(callableType), statements.toList());
}
use of com.sun.tools.javac.tree.JCTree.JCReturn in project ceylon-compiler by ceylon.
the class ClassTransformer method generateIndirectGetterBlock.
private JCTree.JCBlock generateIndirectGetterBlock(Value v) {
JCTree.JCExpression returnExpr;
returnExpr = naming.makeQualIdent(naming.makeName(v, Naming.NA_WRAPPER), "get_");
returnExpr = make().Apply(null, returnExpr, List.<JCExpression>nil());
JCReturn returnValue = make().Return(returnExpr);
List<JCStatement> stmts = List.<JCTree.JCStatement>of(returnValue);
JCTree.JCBlock block = make().Block(0L, stmts);
return block;
}
use of com.sun.tools.javac.tree.JCTree.JCReturn in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transform.
JCExpression transform(Tree.FunctionArgument functionArg, Type expectedType) {
Function model = functionArg.getDeclarationModel();
List<JCStatement> body;
boolean prevNoExpressionlessReturn = statementGen().noExpressionlessReturn;
boolean prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(true);
try {
statementGen().noExpressionlessReturn = isAnything(model.getType());
if (functionArg.getBlock() != null) {
body = statementGen().transformBlock(functionArg.getBlock());
if (!functionArg.getBlock().getDefinitelyReturns()) {
if (isAnything(model.getType())) {
body = body.append(make().Return(makeNull()));
} else {
body = body.append(make().Return(makeErroneous(functionArg.getBlock(), "compiler bug: non-void method does not definitely return")));
}
}
} else {
Tree.Expression expr = functionArg.getExpression();
JCExpression transExpr = expressionGen().transformExpression(expr);
JCReturn returnStat = make().Return(transExpr);
body = List.<JCStatement>of(returnStat);
}
} finally {
expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
statementGen().noExpressionlessReturn = prevNoExpressionlessReturn;
}
//functionArg.getTypeModel();
Type callableType = model.getTypedReference().getFullType();
CallableBuilder callableBuilder = CallableBuilder.methodArgument(gen(), functionArg, model, callableType, Collections.singletonList(functionArg.getParameterLists().get(0)), classGen().transformMplBody(functionArg.getParameterLists(), model, body));
JCExpression result = callableBuilder.build();
result = applyErasureAndBoxing(result, callableType, true, BoxingStrategy.BOXED, expectedType);
return result;
}
Aggregations