Search in sources :

Example 6 with Drop

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

the class CeylonVisitor method visit.

public void visit(Tree.ClassOrInterface decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    if (skipHeaderMergeLater(decl)) {
        return;
    }
    // To accept this class it is either not native or native for this backend
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    if (decl.getDeclarationModel().isClassOrInterfaceMember()) {
        if (decl.getDeclarationModel().isInterfaceMember()) {
            classBuilder.getCompanionBuilder((Interface) decl.getDeclarationModel().getContainer()).defs(gen.classGen().transform(decl));
        } else {
            classBuilder.defs(gen.classGen().transform(decl));
        }
    } else {
        appendList(gen.classGen().transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 7 with Drop

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

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);
    Function dec = decl.getDeclarationModel();
    if (dec.isClassOrInterfaceMember() && (!Decl.isDeferred(dec) || ModelUtil.isCaptured(dec))) {
        classBuilder.method(decl, plan);
    } else {
        appendList(gen.classGen().transformWrappedMethod(decl, plan));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 8 with Drop

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

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);
    Value dec = decl.getDeclarationModel();
    if (dec.isClassMember() && !ModelUtil.isLocalToInitializer(dec) || dec.isStatic()) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
    } else if (dec.isInterfaceMember() && !ModelUtil.isLocalToInitializer(dec)) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
        AttributeDefinitionBuilder adb = gen.classGen().transform(decl, true);
        if (dec.isShared()) {
            adb.ignoreAnnotations();
        }
        classBuilder.getCompanionBuilder((Interface) dec.getContainer()).attribute(adb);
    } else if (dec.isToplevel()) {
        topattrBuilder.add(decl);
    } else {
        appendList(gen.transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 9 with Drop

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

the class CeylonVisitor method visit.

public void visit(Tree.ClassBody that) {
    // Transform executable statements and declarations in the body
    // except constructors. Record how constructors delegate.
    HashMap<Constructor, CtorDelegation> delegates = new HashMap<Constructor, CtorDelegation>();
    java.util.List<Statement> stmts = getBodyStatements(that);
    HashMap<Constructor, CtorDelegation> broken = new HashMap<Constructor, CtorDelegation>();
    for (Tree.Statement stmt : stmts) {
        if (stmt instanceof Tree.Constructor) {
            Tree.Constructor ctor = (Tree.Constructor) stmt;
            Constructor ctorModel = ctor.getConstructor();
            if (gen.errors().hasDeclarationAndMarkBrokenness(ctor) instanceof Drop) {
                broken.put(ctorModel, CtorDelegation.brokenDelegation(ctorModel));
                continue;
            }
            classBuilder.getInitBuilder().constructor(ctor);
            if (ctor.getDelegatedConstructor() != null) {
                // error recovery
                if (ctor.getDelegatedConstructor().getInvocationExpression() != null) {
                    Tree.ExtendedTypeExpression p = (Tree.ExtendedTypeExpression) ctor.getDelegatedConstructor().getInvocationExpression().getPrimary();
                    Declaration delegatedDecl = p.getDeclaration();
                    delegates.put(ctorModel, ctorDelegation(ctorModel, delegatedDecl, broken));
                }
            } else {
                // implicitly delegating to superclass initializer
                Type et = ModelUtil.getConstructedClass(ctorModel).getExtendedType();
                if (et != null) {
                    Declaration delegatedDecl = et.getDeclaration();
                    delegates.put(ctorModel, ctorDelegation(ctorModel, delegatedDecl, broken));
                }
            }
        } else if (stmt instanceof Tree.Enumerated) {
            Tree.Enumerated singleton = (Tree.Enumerated) stmt;
            Constructor ctorModel = singleton.getEnumerated();
            if (gen.errors().hasDeclarationAndMarkBrokenness(singleton) instanceof Drop) {
                broken.put(ctorModel, CtorDelegation.brokenDelegation(ctorModel));
                continue;
            }
            classBuilder.getInitBuilder().singleton(singleton);
            if (singleton.getDelegatedConstructor() != null) {
                Tree.ExtendedTypeExpression p = (Tree.ExtendedTypeExpression) singleton.getDelegatedConstructor().getInvocationExpression().getPrimary();
                Declaration delegatedDecl = p.getDeclaration();
                delegates.put(ctorModel, ctorDelegation(ctorModel, delegatedDecl, broken));
            } else {
                // implicitly delegating to superclass initializer
                Type et = ModelUtil.getConstructedClass(ctorModel).getExtendedType();
                if (et != null) {
                    Declaration delegatedDecl = et.getDeclaration();
                    delegates.put(ctorModel, ctorDelegation(ctorModel, delegatedDecl, broken));
                }
            }
        } else if (stmt instanceof Tree.SpecifierStatement && ((Tree.SpecifierStatement) stmt).getRefinement()) {
            HasErrorException error = gen.errors().getFirstErrorBlock(stmt);
            if (error != null) {
                classBuilder.broken();
            }
            stmt.visit(this);
        } else {
            HasErrorException error = gen.errors().getFirstErrorInitializer(stmt);
            if (error != null) {
                append(gen.makeThrowUnresolvedCompilationError(error));
            } else {
                stmt.visit(this);
            }
        }
    }
    // Now transform constructors
    for (Tree.Statement stmt : stmts) {
        if (stmt instanceof Tree.Constructor) {
            Tree.Constructor ctor = (Tree.Constructor) stmt;
            if (gen.errors().hasDeclarationError(ctor) instanceof Drop) {
                continue;
            }
            transformConstructor(ctor, ctor.getParameterList(), ctor.getDelegatedConstructor(), ctor.getBlock(), ctor.getConstructor(), delegates);
        } else if (stmt instanceof Tree.Enumerated) {
            Tree.Enumerated ctor = (Tree.Enumerated) stmt;
            if (gen.errors().hasDeclarationError(ctor) instanceof Drop) {
                continue;
            }
            transformSingletonConstructor(delegates, ctor);
        }
    }
}
Also used : HashMap(java.util.HashMap) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Statement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop) Type(org.eclipse.ceylon.model.typechecker.model.Type) Statement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement) HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 10 with Drop

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

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);
    Value dec = decl.getDeclarationModel();
    if (dec.isClassOrInterfaceMember() && !ModelUtil.isLocalToInitializer(dec) || dec.isStatic()) {
        // Class attributes
        gen.classGen().transform(decl, classBuilder);
    } else if (dec.isToplevel()) {
        topattrBuilder.add(decl);
    } else if (Decl.isLocal(dec) && (ModelUtil.isCaptured(dec) && Decl.isVariable(dec) || dec.isTransient() || Decl.hasSetter(dec))) {
        // 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 : FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Aggregations

Drop (org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)10 TransformationPlan (org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan)9 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)3 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)3 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)3 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)3 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)3 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)2 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)2 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)2 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)2 TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)2 Value (org.eclipse.ceylon.model.typechecker.model.Value)2 HashMap (java.util.HashMap)1 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)1 HasErrorException (org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException)1 MethodDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)1 Return (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Return)1 Statement (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement)1 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)1