Changeset 32b8144


Ignore:
Timestamp:
Feb 17, 2017, 2:20:25 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
11f95ee
Parents:
e6512c8
Message:

resolve case labels and case ranges

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    re6512c8 r32b8144  
    10441044
    10451045        void AlternativeFinder::visit( ConditionalExpr *conditionalExpr ) {
     1046                // find alternatives for condition
    10461047                AlternativeFinder firstFinder( indexer, env );
    10471048                firstFinder.findWithAdjustment( conditionalExpr->get_arg1() );
    10481049                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
     1050                        // find alternatives for true expression
    10491051                        AlternativeFinder secondFinder( indexer, first->env );
    10501052                        secondFinder.findWithAdjustment( conditionalExpr->get_arg2() );
    10511053                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
     1054                                // find alterantives for false expression
    10521055                                AlternativeFinder thirdFinder( indexer, second->env );
    10531056                                thirdFinder.findWithAdjustment( conditionalExpr->get_arg3() );
    10541057                                for ( AltList::const_iterator third = thirdFinder.alternatives.begin(); third != thirdFinder.alternatives.end(); ++third ) {
     1058                                        // unify true and false types, then infer parameters to produce new alternatives
    10551059                                        OpenVarSet openVars;
    10561060                                        AssertionSet needAssertions, haveAssertions;
     
    10791083        }
    10801084
     1085        void AlternativeFinder::visit( RangeExpr * rangeExpr ) {
     1086                // resolve low and high, accept alternatives whose low and high types unify
     1087                AlternativeFinder firstFinder( indexer, env );
     1088                firstFinder.findWithAdjustment( rangeExpr->get_low() );
     1089                for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first ) {
     1090                        AlternativeFinder secondFinder( indexer, first->env );
     1091                        secondFinder.findWithAdjustment( rangeExpr->get_high() );
     1092                        for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second ) {
     1093                                OpenVarSet openVars;
     1094                                AssertionSet needAssertions, haveAssertions;
     1095                                Alternative newAlt( 0, second->env, first->cost + second->cost );
     1096                                Type* commonType = nullptr;
     1097                                if ( unify( first->expr->get_result(), second->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
     1098                                        RangeExpr *newExpr = new RangeExpr( first->expr->clone(), second->expr->clone() );
     1099                                        newExpr->set_result( commonType ? commonType : first->expr->get_result()->clone() );
     1100                                        newAlt.expr = newExpr;
     1101                                        inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( alternatives ) );
     1102                                } // if
     1103                        } // for
     1104                } // for
     1105        }
     1106
    10811107        void AlternativeFinder::visit( UntypedTupleExpr *tupleExpr ) {
    10821108                std::list< AlternativeFinder > subExprAlternatives;
  • src/ResolvExpr/Resolver.cc

    re6512c8 r32b8144  
    302302        }
    303303
    304         template< typename SwitchClass >
    305         void handleSwitchStmt( SwitchClass *switchStmt, SymTab::Indexer &visitor ) {
     304        void Resolver::visit( SwitchStmt *switchStmt ) {
     305                ValueGuard< Type * > oldInitContext( initContext );
    306306                Expression *newExpr;
    307                 newExpr = findIntegralExpression( switchStmt->get_condition(), visitor );
     307                newExpr = findIntegralExpression( switchStmt->get_condition(), *this );
    308308                delete switchStmt->get_condition();
    309309                switchStmt->set_condition( newExpr );
    310310
    311                 visitor.Visitor::visit( switchStmt );
    312         }
    313 
    314         void Resolver::visit( SwitchStmt *switchStmt ) {
    315                 handleSwitchStmt( switchStmt, *this );
     311                initContext = newExpr->get_result();
     312                Parent::visit( switchStmt );
    316313        }
    317314
    318315        void Resolver::visit( CaseStmt *caseStmt ) {
     316                if ( caseStmt->get_condition() ) {
     317                        assert( initContext );
     318                        CastExpr * castExpr = new CastExpr( caseStmt->get_condition(), initContext->clone() );
     319                        Expression * newExpr = findSingleExpression( castExpr, *this );
     320                        castExpr = safe_dynamic_cast< CastExpr * >( newExpr );
     321                        caseStmt->set_condition( castExpr->get_arg() );
     322                        castExpr->set_arg( nullptr );
     323                        delete castExpr;
     324                }
    319325                Parent::visit( caseStmt );
    320326        }
  • src/tests/dtor-early-exit.c

    re6512c8 r32b8144  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // dtor-early-exit.c -- 
    8 // 
     6//
     7// dtor-early-exit.c --
     8//
    99// Author           : Rob Schluntz
    1010// Created On       : Wed Aug 17 08:26:25 2016
     
    1212// Last Modified On : Wed Aug 17 08:29:37 2016
    1313// Update Count     : 2
    14 // 
     14//
    1515
    1616#include <fstream>
     
    213213                // S_G-S_L = {}
    214214        }
     215#ifdef ERR2
    215216        // S_G = {}
    216 #ifdef ERR2
    217217        if (i == 5) goto L2; // this is an error in g++ because it skips initialization of y, x
    218218        // S_L-S_G = { y, x } => non-empty, so error
Note: See TracChangeset for help on using the changeset viewer.