Search in sources :

Example 6 with Tree

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree in project ceylon by eclipse.

the class LocalTypeVisitor method startFrom.

public void startFrom(Node tree) {
    int mpl = 0;
    String prefix = null;
    // make sure we start with the right number of anonymous classes for methods with MPL before we visit the children
    if (tree instanceof Tree.AnyMethod) {
        Function model = ((Tree.AnyMethod) tree).getDeclarationModel();
        mpl = model.getParameterLists().size();
        if (mpl > 1) {
            prefix = this.prefix;
            for (int i = 1; i < mpl; i++) enterAnonymousClass();
        }
    }
    if (tree instanceof Tree.ClassDefinition) {
        visitClassBody((Tree.ClassDefinition) tree);
    } else {
        tree.visitChildren(this);
    }
    if (mpl > 1) {
        for (int i = 1; i < mpl; i++) exitAnonymousClass();
        this.prefix = prefix;
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ClassDefinition(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ClassDefinition)

Example 7 with Tree

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree in project ceylon by eclipse.

the class BoxingVisitor method visit.

@Override
public void visit(Tree.SwitchExpression that) {
    super.visit(that);
    SwitchCaseList caseList = that.getSwitchCaseList();
    if (caseList == null || caseList.getCaseClauses() == null)
        return;
    boolean unboxed = true;
    for (Tree.CaseClause caseClause : caseList.getCaseClauses()) {
        Expression expr = caseClause.getExpression();
        if (expr == null)
            return;
        // a single boxed one makes the whole switch boxed
        if (!CodegenUtil.isUnBoxed(expr))
            unboxed = false;
    // A Switch expression can never be raw, type erased or untrusted because
    // it uses a Let with a new variable declaration, so the rawness,
    // erasedness and untrustedness of its branches cannot propagate further
    // up the tree.
    }
    if (caseList.getElseClause() != null) {
        Expression expr = caseList.getElseClause().getExpression();
        if (expr == null)
            return;
        // a single boxed one makes the whole switch boxed
        if (!CodegenUtil.isUnBoxed(expr))
            unboxed = false;
    // see comment about about why we don't propagate rawness etc here.
    }
    if (unboxed && !willEraseToObject(that.getUnit().denotableType(that.getTypeModel())))
        CodegenUtil.markUnBoxed(that);
    if (that.getTypeModel().isExactly(that.getUnit().getNullValueType())) {
        CodegenUtil.markTypeErased(that);
    }
}
Also used : PostfixOperatorExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PostfixOperatorExpression) BaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) IndexExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.IndexExpression) PrefixOperatorExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PrefixOperatorExpression) Expression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression) ParameterizedExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ParameterizedExpression) StaticMemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression) QualifiedMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression) MemberOrTypeExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression) InvocationExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.InvocationExpression) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) SwitchCaseList(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SwitchCaseList)

Aggregations

Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)3 Expression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression)3 Function (org.eclipse.ceylon.model.typechecker.model.Function)2 Type (org.eclipse.ceylon.model.typechecker.model.Type)2 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)2 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)2 HashMap (java.util.HashMap)1 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)1 AnalyzerUtil.checkCasesDisjoint (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint)1 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)1 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)1 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)1 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)1 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)1 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)1 BaseMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)1 ClassDefinition (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ClassDefinition)1 IndexExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.IndexExpression)1 InvocationExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.InvocationExpression)1