Ignore:
Timestamp:
Feb 1, 2018, 5:40:01 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
0188a0b
Parents:
d0a045c7 (diff), 33c0ce8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Expression.cc

    rd0a045c7 r85521c7  
    597597
    598598StmtExpr::StmtExpr( CompoundStmt *statements ) : statements( statements ) {
    599         assert( statements );
    600         std::list< Statement * > & body = statements->get_kids();
    601         if ( ! body.empty() ) {
    602                 if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
    603                         result = maybeClone( exprStmt->expr->result );
    604                 }
    605         }
    606         // ensure that StmtExpr has a result type
    607         if ( ! result ) {
    608                 result = new VoidType( Type::Qualifiers() );
    609         }
     599        computeResult();
    610600}
    611601StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {
     
    617607        deleteAll( dtors );
    618608        deleteAll( returnDecls );
     609}
     610void StmtExpr::computeResult() {
     611        assert( statements );
     612        std::list< Statement * > & body = statements->kids;
     613        delete result;
     614        result = nullptr;
     615        if ( ! returnDecls.empty() ) {
     616                // prioritize return decl for result type, since if a return decl exists, then
     617                // the StmtExpr is currently in an intermediate state where the body will always
     618                // give a void result type.
     619                result = returnDecls.front()->get_type()->clone();
     620        } else if ( ! body.empty() ) {
     621                if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( body.back() ) ) {
     622                        result = maybeClone( exprStmt->expr->result );
     623                }
     624        }
     625        // ensure that StmtExpr has a result type
     626        if ( ! result ) {
     627                result = new VoidType( Type::Qualifiers() );
     628        }
    619629}
    620630void StmtExpr::print( std::ostream &os, Indenter indent ) const {
Note: See TracChangeset for help on using the changeset viewer.