Search in sources :

Example 1 with SwitchCaseList

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.SwitchCaseList 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)1 BaseMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)1 Expression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression)1 IndexExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.IndexExpression)1 InvocationExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.InvocationExpression)1 MemberOrTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MemberOrTypeExpression)1 ParameterizedExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.ParameterizedExpression)1 PostfixOperatorExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.PostfixOperatorExpression)1 PrefixOperatorExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.PrefixOperatorExpression)1 QualifiedMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.QualifiedMemberExpression)1 StaticMemberOrTypeExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.StaticMemberOrTypeExpression)1 SwitchCaseList (org.eclipse.ceylon.compiler.typechecker.tree.Tree.SwitchCaseList)1