Search in sources :

Example 6 with HasErrorException

use of org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon by eclipse.

the class ExpressionTransformer method transformSuperInvocation.

// 
// Invocations
public void transformSuperInvocation(Tree.ExtendedType extendedType, ClassDefinitionBuilder classBuilder) {
    HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(extendedType);
    if (error != null) {
        classBuilder.getInitBuilder().delegateCall(this.makeThrowUnresolvedCompilationError(error));
        return;
    }
    if (extendedType.getInvocationExpression() != null && extendedType.getInvocationExpression().getPositionalArgumentList() != null) {
        Declaration primaryDeclaration = ((Tree.MemberOrTypeExpression) extendedType.getInvocationExpression().getPrimary()).getDeclaration();
        java.util.List<ParameterList> paramLists = ((Functional) primaryDeclaration).getParameterLists();
        if (paramLists.isEmpty()) {
            classBuilder.getInitBuilder().delegateCall(at(extendedType).Exec(makeErroneous(extendedType, "compiler bug: missing parameter list in extends clause: " + primaryDeclaration.getName() + " must be invoked")));
        } else {
            boolean prevFnCall = withinInvocation(true);
            try {
                JCStatement superExpr = transformConstructorDelegation(extendedType, new CtorDelegation(null, primaryDeclaration), extendedType.getInvocationExpression(), classBuilder, false);
                classBuilder.getInitBuilder().delegateCall(superExpr);
            } finally {
                withinInvocation(prevFnCall);
            }
        }
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)

Example 7 with HasErrorException

use of org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon by eclipse.

the class ExpressionTransformer method transform.

public JCStatement transform(Tree.SpecifierStatement op) {
    // SpecifierStatement do not return any value, therefore we don't care about the type of the expressions.
    inStatement = true;
    JCStatement result;
    HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(op.getBaseMemberExpression());
    if (error != null) {
        result = this.makeThrowUnresolvedCompilationError(error);
    } else if ((error = errors().getFirstExpressionErrorAndMarkBrokenness(op.getSpecifierExpression().getExpression())) != null) {
        result = this.makeThrowUnresolvedCompilationError(error);
    } else {
        result = at(op).Exec(transformAssignment(op, op.getBaseMemberExpression(), op.getSpecifierExpression().getExpression()));
    }
    inStatement = false;
    return result;
}
Also used : HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)

Example 8 with HasErrorException

use of org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon by eclipse.

the class StatementTransformer method transform.

// FIXME There is a similar implementation in ClassGen!
public List<JCStatement> transform(Tree.AttributeDeclaration decl) {
    ListBuffer<JCStatement> result = new ListBuffer<JCStatement>();
    // If the attribute is really from a parameter then don't generate a local variable
    Parameter parameter = CodegenUtil.findParamForDecl(decl);
    if (parameter == null) {
        final Name attrName = names().fromString(naming.substitute(decl.getDeclarationModel()));
        Type t = decl.getDeclarationModel().getType();
        JCExpression initialValue = null;
        SpecifierOrInitializerExpression initOrSpec = decl.getSpecifierOrInitializerExpression();
        if (initOrSpec != null) {
            HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(initOrSpec.getExpression().getTerm());
            if (error != null) {
                return List.<JCStatement>of(this.makeThrowUnresolvedCompilationError(error));
            }
            int flags = CodegenUtil.downcastForSmall(initOrSpec.getExpression(), decl.getDeclarationModel()) ? ExpressionTransformer.EXPR_UNSAFE_PRIMITIVE_TYPECAST_OK : 0;
            flags |= decl.getDeclarationModel().hasUncheckedNullType() ? ExpressionTransformer.EXPR_TARGET_ACCEPTS_NULL : 0;
            initialValue = expressionGen().transformExpression(initOrSpec.getExpression(), CodegenUtil.getBoxingStrategy(decl.getDeclarationModel()), decl.getDeclarationModel().getType(), flags);
        } else if (decl.getDeclarationModel().isVariable()) {
            // Java's definite initialization doesn't always work
            // so give variable attribute declarations without
            // initializers a default value. See #1153.
            initialValue = makeDefaultExprForType(t);
            if (CodegenUtil.getBoxingStrategy(decl.getDeclarationModel()) == BoxingStrategy.BOXED && canUnbox(t)) {
                initialValue = boxType(initialValue, t);
            }
        }
        List<JCAnnotation> annots = List.<JCAnnotation>nil();
        int modifiers = transformLocalFieldDeclFlags(decl);
        JCExpression typeExpr = makeJavaType(decl.getDeclarationModel(), t, modifiers);
        result.append(at(decl.getIdentifier()).VarDef(at(decl.getIdentifier()).Modifiers(modifiers, annots), attrName, typeExpr, initialValue));
        JCStatement outerSubs = openOuterSubstitutionIfNeeded(decl.getDeclarationModel(), t, modifiers);
        if (outerSubs != null) {
            result.append(outerSubs);
        }
    }
    return result.toList();
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) SpecifierOrInitializerExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SpecifierOrInitializerExpression) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name) CName(org.eclipse.ceylon.compiler.java.codegen.Naming.CName) SyntheticName(org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)

Example 9 with HasErrorException

use of org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon by eclipse.

the class StatementTransformer method transformBlock.

public List<JCStatement> transformBlock(Tree.Block block, boolean revertRet) {
    if (block == null) {
        return List.<JCStatement>nil();
    }
    at(block);
    CeylonVisitor v = gen().visitor;
    final ListBuffer<JCTree> prevDefs = v.defs;
    final boolean prevInInitializer = v.inInitializer;
    final ClassDefinitionBuilder prevClassBuilder = v.classBuilder;
    Tree.Block oldBlock = block;
    currentBlock = block;
    List<JCStatement> result;
    try {
        v.defs = new ListBuffer<JCTree>();
        v.inInitializer = false;
        v.classBuilder = current();
        pushBlockImports(block);
        java.util.Iterator<Statement> statements = block.getStatements().iterator();
        while (statements.hasNext()) {
            Tree.Statement stmt = statements.next();
            Transformer<JCStatement, Return> returnTransformer;
            if (revertRet && stmt instanceof Tree.Declaration) {
                returnTransformer = returnTransformer(defaultReturnTransformer);
            } else {
                returnTransformer = this.returnTransformer;
            }
            try {
                HasErrorException error = errors().getFirstErrorBlock(stmt);
                if (error == null) {
                    stmt.visit(v);
                } else {
                    v.append(this.makeThrowUnresolvedCompilationError(error));
                    break;
                }
            } finally {
                returnTransformer(returnTransformer);
            }
        }
        popBlockImports(block);
        result = (List<JCStatement>) v.getResult().toList();
        Runnable r = onEndBlock.get(block);
        if (r != null) {
            r.run();
        }
    } finally {
        v.classBuilder = prevClassBuilder;
        v.inInitializer = prevInInitializer;
        v.defs = prevDefs;
        // Close Substitutions which were scoped to this block
        Scope scope = block.getScope();
        while (scope instanceof ConditionScope) {
            scope = scope.getScope();
        }
        naming.closeScopedSubstitutions(scope);
        currentBlock = oldBlock;
    }
    return result;
}
Also used : Return(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Return) JCExpressionStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpressionStatement) Statement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement) ForStatement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ForStatement) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement) Statement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 10 with HasErrorException

use of org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException in project ceylon by eclipse.

the class ExpressionTransformer method transform.

// Statement expressions
public JCStatement transform(Tree.ExpressionStatement tree) {
    // ExpressionStatements do not return any value, therefore we don't care about the type of the expressions.
    inStatement = true;
    JCStatement result;
    HasErrorException error = errors().getFirstExpressionErrorAndMarkBrokenness(tree.getExpression());
    if (error != null) {
        result = this.makeThrowUnresolvedCompilationError(error);
    } else {
        result = at(tree).Exec(transformExpression(tree.getExpression(), BoxingStrategy.INDIFFERENT, null));
    }
    inStatement = false;
    return result;
}
Also used : HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)

Aggregations

HasErrorException (org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException)15 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)12 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)8 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)8 Type (org.eclipse.ceylon.model.typechecker.model.Type)7 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)6 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)6 JCPrimitiveTypeTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree)5 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)4 JCBlock (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock)4 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)4 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)4 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)4 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)3 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)3 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)3 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)3 Value (org.eclipse.ceylon.model.typechecker.model.Value)3 Substitution (org.eclipse.ceylon.compiler.java.codegen.Naming.Substitution)2 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)2