Changeset 85521c7 for src/SynTree


Ignore:
Timestamp:
Feb 1, 2018, 5:40:01 PM (8 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, stuck-waitfor-destruct, with_gc
Children:
0188a0bc
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

Location:
src/SynTree
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/Declaration.h

    rd0a045c7 r85521c7  
    151151        FunctionType *type;
    152152        CompoundStmt *statements;
     153        std::list< Expression * > withExprs;
    153154
    154155        FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
  • 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 {
  • src/SynTree/Expression.h

    rd0a045c7 r85521c7  
    728728        StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; }
    729729
     730        // call to set the result type of this StmtExpr based on its body
     731        void computeResult();
     732
    730733        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    731734        std::list< Expression * > & get_dtors() { return dtors; }
  • src/SynTree/FunctionDecl.cc

    rd0a045c7 r85521c7  
    5151                VarExprReplacer::replace( this, declMap );
    5252        }
     53        cloneAll( other.withExprs, withExprs );
    5354}
    5455
     
    5657        delete type;
    5758        delete statements;
     59        deleteAll( withExprs );
    5860}
    5961
Note: See TracChangeset for help on using the changeset viewer.