Search in sources :

Example 6 with TransformationPlan

use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.

the class CeylonVisitor method visit.

public void visit(Tree.AttributeDeclaration decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    // To accept this method it is either not native, native for this
    // backend or it's a native header with an implementation and there
    // is no native implementation specifically for this backend
    boolean accept = acceptDeclaration(decl);
    if (!accept)
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    if (Decl.withinClassOrInterface(decl) && !Decl.isLocalToInitializer(decl)) {
        // Class attributes
        gen.classGen().transform(decl, classBuilder);
    } else if (Decl.isToplevel(decl)) {
        topattrBuilder.add(decl);
    } else if ((Decl.isLocal(decl)) && ((Decl.isCaptured(decl) && Decl.isVariable(decl)) || Decl.isTransient(decl) || Decl.hasSetter(decl))) {
        // Captured local attributes get turned into an inner getter/setter class
        appendList(gen.transform(decl));
    } else {
        // All other local attributes
        appendList(gen.statementGen().transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(com.redhat.ceylon.compiler.java.codegen.recovery.Drop)

Example 7 with TransformationPlan

use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.

the class CeylonVisitor method visit.

public void visit(Tree.ObjectDefinition decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (skipHeaderMergeLater(decl)) {
        return;
    }
    // To accept this object it is either not native or native for this backend
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    if (Decl.withinClass(decl)) {
        classBuilder.defs(gen.classGen().transformObjectDefinition(decl, classBuilder));
    } else {
        appendList(gen.classGen().transformObjectDefinition(decl, null));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(com.redhat.ceylon.compiler.java.codegen.recovery.Drop)

Example 8 with TransformationPlan

use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.

the class CeylonVisitor method visit.

public void visit(Tree.AttributeGetterDefinition decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    if (Decl.withinClass(decl) && !Decl.isLocalToInitializer(decl)) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
    } else if (Decl.withinInterface(decl) && !Decl.isLocalToInitializer(decl)) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
        AttributeDefinitionBuilder adb = gen.classGen().transform(decl, true);
        if (decl.getDeclarationModel().isShared()) {
            adb.ignoreAnnotations();
        }
        classBuilder.getCompanionBuilder((Interface) decl.getDeclarationModel().getContainer()).attribute(adb);
    } else if (Decl.isToplevel(decl)) {
        topattrBuilder.add(decl);
    } else {
        appendList(gen.transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(com.redhat.ceylon.compiler.java.codegen.recovery.Drop)

Example 9 with TransformationPlan

use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.

the class CeylonVisitor method visit.

public void visit(Tree.AnyMethod decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    if (Decl.withinClassOrInterface(decl) && (!Decl.isDeferred(decl) || Decl.isCaptured(decl))) {
        classBuilder.method(decl, plan);
    } else {
        appendList(gen.classGen().transformWrappedMethod(decl, plan));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(com.redhat.ceylon.compiler.java.codegen.recovery.Drop)

Example 10 with TransformationPlan

use of com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan in project ceylon-compiler by ceylon.

the class CeylonVisitor method transformConstructor.

private void transformConstructor(Tree.Declaration ctor, Tree.ParameterList parameterList, Tree.DelegatedConstructor delegatedCtor, Tree.Block block, Constructor ctorModel, Map<Constructor, CtorDelegation> delegates) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(ctor);
    if (plan instanceof Drop) {
        return;
    }
    if (parameterList != null) {
        for (Parameter param : parameterList.getModel().getParameters()) {
            if (Naming.aliasConstructorParameterName(param.getModel())) {
                gen.naming.addVariableSubst(param.getModel(), gen.naming.suffixName(Suffix.$param$, param.getName()));
            }
        }
    }
    final CtorDelegation delegation = delegates.get(ctorModel);
    ListBuffer<JCStatement> stmts = ListBuffer.lb();
    boolean delegatedTo = CtorDelegation.isDelegatedTo(delegates, ctorModel);
    if (delegatedTo && !ctorModel.isAbstract()) {
        Tree.InvocationExpression chainedCtorInvocation;
        if (delegatedCtor != null) {
            chainedCtorInvocation = delegatedCtor.getInvocationExpression();
        } else {
            chainedCtorInvocation = null;
        }
        // We need to generate $delegation$ delegation constructor
        makeDelegationConstructor(ctor, parameterList, delegatedCtor, block, ctorModel, delegation, chainedCtorInvocation);
        JCStatement delegateExpr;
        if (chainedCtorInvocation != null) {
            delegateExpr = gen.expressionGen().transformConstructorDelegation(chainedCtorInvocation, delegation.isSelfDelegation() ? delegation : new CtorDelegation(ctorModel, ctorModel), chainedCtorInvocation, classBuilder, !delegation.isSelfDelegation());
        } else {
            // In this case there is no extends clause in the source code
            // so we have to construct the argument list "by hand".
            ListBuffer<JCExpression> arguments = ListBuffer.<JCExpression>lb();
            for (TypeParameter tp : ((Class) delegation.getConstructor().getContainer()).getTypeParameters()) {
                arguments.add(gen.makeReifiedTypeArgument(tp.getType()));
            }
            arguments.add(gen.naming.makeNamedConstructorName(delegation.getConstructor(), true));
            for (Parameter p : delegation.getConstructor().getFirstParameterList().getParameters()) {
                arguments.add(gen.naming.makeName(p.getModel(), Naming.NA_IDENT));
            }
            delegateExpr = gen.make().Exec(gen.make().Apply(null, gen.naming.makeThis(), arguments.toList()));
        }
        stmts.add(delegateExpr);
    } else if (delegatedCtor != null) {
        stmts.add(gen.expressionGen().transformConstructorDelegation(delegatedCtor, delegation, delegatedCtor.getInvocationExpression(), classBuilder, false));
    } else {
    // no explicit extends clause
    }
    final boolean addBody;
    if (delegatedTo && (delegation.isAbstractSelfOrSuperDelegation())) {
        if (delegation.getConstructor().isAbstract()) {
            stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(null, ctorModel));
            addBody = true;
        } else if (delegation.getExtendingConstructor() != null && delegation.getExtendingConstructor().isAbstract()) {
            stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(delegation.getExtendingConstructor(), ctorModel));
            addBody = true;
        } else {
            addBody = false;
        }
    } else if (delegation.isAbstractSelfDelegation()) {
        // delegating to abstract
        stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(delegation.getExtendingConstructor(), ctorModel));
        addBody = true;
    } else if (delegation.isConcreteSelfDelegation()) {
        stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(delegation.getExtendingConstructor(), ctorModel));
        addBody = true;
    } else {
        // super delegation
        stmts.addAll(classBuilder.getInitBuilder().copyStatementsBetween(null, ctorModel));
        addBody = true;
    }
    if (ctorModel.isAbstract() && !delegatedTo) {
        stmts.add(gen.make().Throw(gen.make().NewClass(null, List.<JCExpression>nil(), gen.make().QualIdent(gen.syms().ceylonUninvokableErrorType.tsym), List.<JCExpression>nil(), null)));
    }
    List<JCStatement> following = ctorModel.isAbstract() ? List.<JCStatement>nil() : classBuilder.getInitBuilder().copyStatementsBetween(ctorModel, null);
    if (addBody) {
        if (following.isEmpty()) {
            stmts.addAll(gen.statementGen().transformBlock(block));
        } else {
            Name label = gen.naming.aliasName(Naming.Unfix.$return$.toString());
            Transformer<JCStatement, Return> prev = gen.statementGen().returnTransformer(gen.statementGen().new ConstructorReturnTransformer(label));
            try {
                stmts.add(gen.make().Labelled(label, gen.make().DoLoop(gen.make().Block(0, gen.statementGen().transformBlock(block, true)), gen.make().Literal(false))));
            } finally {
                gen.statementGen().returnTransformer(prev);
            }
        }
    }
    ThrowVisitor visitor = new ThrowVisitor();
    block.visit(visitor);
    if (!visitor.getDefinitelyReturnsViaThrow()) {
        stmts.addAll(following);
    }
    String ctorName = !Decl.isDefaultConstructor(ctorModel) ? gen.naming.makeTypeDeclarationName(ctorModel) : null;
    classBuilder.defs(gen.classGen().makeNamedConstructor(ctor, parameterList, ctorModel, classBuilder, Strategy.generateInstantiator(ctorModel), gen.classGen().transformConstructorDeclFlags(ctorModel), false, ctorName, stmts.toList(), DeclNameFlag.QUALIFIED));
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Return(com.redhat.ceylon.compiler.typechecker.tree.Tree.Return) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) Drop(com.redhat.ceylon.compiler.java.codegen.recovery.Drop) SyntheticName(com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName) Name(com.sun.tools.javac.util.Name) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) CustomTree(com.redhat.ceylon.compiler.typechecker.tree.CustomTree) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) Class(com.redhat.ceylon.model.typechecker.model.Class) TransformationPlan(com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan)

Aggregations

TransformationPlan (com.redhat.ceylon.compiler.java.codegen.recovery.TransformationPlan)11 Drop (com.redhat.ceylon.compiler.java.codegen.recovery.Drop)9 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)4 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)4 Interface (com.redhat.ceylon.model.typechecker.model.Interface)4 JCTree (com.sun.tools.javac.tree.JCTree)4 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)3 ThrowerCatchallConstructor (com.redhat.ceylon.compiler.java.codegen.recovery.ThrowerCatchallConstructor)2 LazyInterface (com.redhat.ceylon.model.loader.model.LazyInterface)2 Class (com.redhat.ceylon.model.typechecker.model.Class)2 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)2 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)2 SyntheticName (com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName)1 CustomTree (com.redhat.ceylon.compiler.typechecker.tree.CustomTree)1 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)1 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)1 Return (com.redhat.ceylon.compiler.typechecker.tree.Tree.Return)1 ClassAlias (com.redhat.ceylon.model.typechecker.model.ClassAlias)1 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)1 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)1