Search in sources :

Example 1 with SwitchCaseList

use of com.redhat.ceylon.compiler.typechecker.tree.Tree.SwitchCaseList in project ceylon-compiler by ceylon.

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().getNullValueDeclaration().getType())) {
        CodegenUtil.markTypeErased(that);
    }
}
Also used : InvocationExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.InvocationExpression) MemberOrTypeExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression) PrefixOperatorExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.PrefixOperatorExpression) PostfixOperatorExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.PostfixOperatorExpression) StaticMemberOrTypeExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression) ParameterizedExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.ParameterizedExpression) IndexExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.IndexExpression) QualifiedMemberExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression) Expression(com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression) BaseMemberExpression(com.redhat.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) SwitchCaseList(com.redhat.ceylon.compiler.typechecker.tree.Tree.SwitchCaseList)

Aggregations

Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)1 BaseMemberExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)1 Expression (com.redhat.ceylon.compiler.typechecker.tree.Tree.Expression)1 IndexExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.IndexExpression)1 InvocationExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.InvocationExpression)1 MemberOrTypeExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression)1 ParameterizedExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.ParameterizedExpression)1 PostfixOperatorExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.PostfixOperatorExpression)1 PrefixOperatorExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.PrefixOperatorExpression)1 QualifiedMemberExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression)1 StaticMemberOrTypeExpression (com.redhat.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)1 SwitchCaseList (com.redhat.ceylon.compiler.typechecker.tree.Tree.SwitchCaseList)1