Search in sources :

Example 1 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(final Tree.AttributeSetterDefinition decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    TransformationPlan getterPlan = gen.errors().hasDeclarationAndMarkBrokenness(getterSetterPairing.getGetter(decl));
    if (getterPlan instanceof Drop) {
        // because there's little chance we'll be able to generate a correct setter
        return;
    }
    if (!acceptDeclaration(decl))
        return;
    int annots = gen.checkCompilerAnnotations(decl, defs);
    Setter dec = decl.getDeclarationModel();
    if (dec.isClassMember() && !ModelUtil.isLocalToInitializer(dec) || dec.getGetter().isStatic()) {
        classBuilder.attribute(gen.classGen().transform(decl, false));
    } else if (dec.isInterfaceMember()) {
        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 : Setter(org.eclipse.ceylon.model.typechecker.model.Setter) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 2 with Drop

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

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()) {
            FunctionOrValue model = param.getModel();
            if (Naming.aliasConstructorParameterName(model)) {
                gen.naming.addVariableSubst(model, Naming.suffixName(Suffix.$param$, param.getName()));
            }
        }
    }
    final CtorDelegation delegation = delegates.get(ctorModel);
    ListBuffer<JCStatement> stmts = new ListBuffer<JCStatement>();
    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 = new ListBuffer<JCExpression>();
            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().modifierTransformation().constructor(ctorModel), false, ctorName, stmts.toList(), DeclNameFlag.QUALIFIED));
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Return(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Return) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name) SyntheticName(org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) 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) Class(org.eclipse.ceylon.model.typechecker.model.Class) JCNewClass(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 3 with Drop

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

the class CeylonVisitor method visit.

/*
     * Compilation Unit
     */
public void visit(Tree.TypeAliasDeclaration decl) {
    TransformationPlan plan = gen.errors().hasDeclarationAndMarkBrokenness(decl);
    if (plan instanceof Drop) {
        return;
    }
    int annots = gen.checkCompilerAnnotations(decl, defs);
    TypeAlias dec = decl.getDeclarationModel();
    if (dec.isClassOrInterfaceMember()) {
        if (dec.isInterfaceMember()) {
            classBuilder.getCompanionBuilder((Interface) dec.getContainer()).defs(gen.classGen().transform(decl));
        } else {
            classBuilder.defs(gen.classGen().transform(decl));
        }
    } else {
        appendList(gen.classGen().transform(decl));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) 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 4 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.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.getDeclarationModel().isClassMember()) {
        classBuilder.defs(gen.classGen().transformObjectDefinition(decl, classBuilder));
    } else {
        appendList(gen.classGen().transformObjectDefinition(decl, null));
    }
    gen.resetCompilerAnnotations(annots);
}
Also used : TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) Drop(org.eclipse.ceylon.compiler.java.codegen.recovery.Drop)

Example 5 with Drop

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

the class ClassTransformer method addAtMembers.

private void addAtMembers(ClassDefinitionBuilder classBuilder, ClassOrInterface model, Tree.ClassOrInterface def) {
    List<JCExpression> members = List.nil();
    for (Declaration member : model.getMembers()) {
        if (member instanceof ClassOrInterface == false && member instanceof TypeAlias == false) {
            continue;
        }
        TypeDeclaration innerType = (TypeDeclaration) member;
        Tree.Declaration innerTypeTree = findInnerType(def, innerType.getName());
        if (innerTypeTree != null) {
            TransformationPlan plan = errors().hasDeclarationAndMarkBrokenness(innerTypeTree);
            if (plan instanceof Drop) {
                continue;
            }
        }
        if (innerType.isAlias() && innerTypeTree != null && Decl.isAncestorLocal(innerTypeTree.getDeclarationModel()))
            // for the same reason we do not generate aliases in transform(ClassOrInterface def) let's not list them
            continue;
        JCAnnotation atMember;
        // interfaces are moved to toplevel so they can lose visibility of member types if they are local
        if (Decl.isLocal(model) && model instanceof Interface)
            atMember = makeAtMember(innerType.getName());
        else
            atMember = makeAtMember(innerType.getType());
        members = members.prepend(atMember);
    }
    classBuilder.annotations(makeAtMembers(members));
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCPrimitiveTypeTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) MethodDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) TransformationPlan(org.eclipse.ceylon.compiler.java.codegen.recovery.TransformationPlan) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface) 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