Search in sources :

Example 6 with JCReturn

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());
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) JCReturn(com.sun.tools.javac.tree.JCTree.JCReturn) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) QualifiedTypeExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.QualifiedTypeExpression) Expression(com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) BoxingStrategy(com.redhat.ceylon.compiler.java.codegen.AbstractTransformer.BoxingStrategy) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl)

Example 7 with JCReturn

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;
}
Also used : JCReturn(com.sun.tools.javac.tree.JCTree.JCReturn) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCTree(com.sun.tools.javac.tree.JCTree) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement)

Example 8 with JCReturn

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;
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) JCReturn(com.sun.tools.javac.tree.JCTree.JCReturn) Type(com.redhat.ceylon.model.typechecker.model.Type) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Expression(com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement)

Aggregations

JCReturn (com.sun.tools.javac.tree.JCTree.JCReturn)8 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)7 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)6 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)6 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)5 JCTree (com.sun.tools.javac.tree.JCTree)4 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)4 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)3 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)3 ListBuffer (com.sun.tools.javac.util.ListBuffer)3 Name (com.sun.tools.javac.util.Name)3 Expression (com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression)2 Function (com.redhat.ceylon.model.typechecker.model.Function)2 Type (com.redhat.ceylon.model.typechecker.model.Type)2 JCAssign (com.sun.tools.javac.tree.JCTree.JCAssign)2 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)2 JCConditional (com.sun.tools.javac.tree.JCTree.JCConditional)2 JCIf (com.sun.tools.javac.tree.JCTree.JCIf)2 JavacNode (lombok.javac.JavacNode)2 BoxingStrategy (com.redhat.ceylon.compiler.java.codegen.AbstractTransformer.BoxingStrategy)1