- Timestamp:
- Dec 13, 2016, 5:37:15 PM (8 years ago)
- 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:
- 31f379c
- Parents:
- 1d2b64f
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r1d2b64f rd5556a3 40 40 41 41 namespace SymTab { 42 struct NewScope { 43 NewScope( SymTab::Indexer & indexer ) : indexer( indexer ) { indexer.enterScope(); } 44 ~NewScope() { indexer.leaveScope(); } 45 SymTab::Indexer & indexer; 46 }; 47 42 48 template< typename TreeType, typename VisitorType > 43 49 inline void acceptNewScope( TreeType *tree, VisitorType &visitor ) { … … 454 460 void Indexer::visit( TupleAssignExpr *tupleExpr ) { 455 461 acceptNewScope( tupleExpr->get_result(), *this ); 456 enterScope(); 457 acceptAll( tupleExpr->get_tempDecls(), *this ); 458 acceptAll( tupleExpr->get_assigns(), *this ); 459 leaveScope(); 462 maybeAccept( tupleExpr->get_stmtExpr(), *this ); 460 463 } 461 464 -
src/SynTree/Expression.cc
r1d2b64f rd5556a3 524 524 525 525 ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() { 526 set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment 526 527 delete callExpr; 527 528 deleteAll( tempDecls ); … … 533 534 os << "Implicit Copy Constructor Expression: " << std::endl; 534 535 assert( callExpr ); 536 os << std::string( indent+2, ' ' ); 535 537 callExpr->print( os, indent + 2 ); 536 538 os << std::endl << std::string( indent, ' ' ) << "with temporaries:" << std::endl; … … 584 586 os << std::string( indent+2, ' ' ); 585 587 initializer->print( os, indent + 2 ); 588 Expression::print( os, indent ); 586 589 } 587 590 … … 603 606 os << " ... "; 604 607 high->print( os, indent ); 608 Expression::print( os, indent ); 605 609 } 606 610 … … 614 618 } 615 619 } 616 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) {} 620 StmtExpr::StmtExpr( const StmtExpr &other ) : Expression( other ), statements( other.statements->clone() ) { 621 cloneAll( other.returnDecls, returnDecls ); 622 cloneAll( other.dtors, dtors ); 623 } 617 624 StmtExpr::~StmtExpr() { 618 625 delete statements; 626 deleteAll( dtors ); 627 deleteAll( returnDecls ); 619 628 } 620 629 void StmtExpr::print( std::ostream &os, int indent ) const { 621 630 os << "Statement Expression: " << std::endl << std::string( indent, ' ' ); 622 631 statements->print( os, indent+2 ); 632 if ( ! returnDecls.empty() ) { 633 os << std::string( indent+2, ' ' ) << "with returnDecls: "; 634 printAll( returnDecls, os, indent+2 ); 635 } 636 if ( ! dtors.empty() ) { 637 os << std::string( indent+2, ' ' ) << "with dtors: "; 638 printAll( dtors, os, indent+2 ); 639 } 640 Expression::print( os, indent ); 623 641 } 624 642 … … 644 662 get_expr()->print( os, indent+2 ); 645 663 if ( get_object() ) { 646 os << "with decl: ";664 os << std::string( indent+2, ' ' ) << "with decl: "; 647 665 get_object()->printShort( os, indent+2 ); 648 666 } 667 Expression::print( os, indent ); 649 668 } 650 669 -
src/SynTree/Expression.h
r1d2b64f rd5556a3 543 543 544 544 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 545 void set_tempDecls( std::list< ObjectDecl * > newValue ) { tempDecls = newValue; }546 547 545 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 548 void set_returnDecls( std::list< ObjectDecl * > newValue ) { returnDecls = newValue; }549 550 546 std::list< Expression * > & get_dtors() { return dtors; } 551 void set_dtors( std::list< Expression * > newValue ) { dtors = newValue; }552 547 553 548 virtual ImplicitCopyCtorExpr *clone() const { return new ImplicitCopyCtorExpr( *this ); } … … 706 701 virtual ~TupleAssignExpr(); 707 702 708 std::list< Expression * > & get_assigns() { return assigns; }709 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }703 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; } 704 StmtExpr * get_stmtExpr() const { return stmtExpr; } 710 705 711 706 virtual TupleAssignExpr *clone() const { return new TupleAssignExpr( *this ); } … … 714 709 virtual void print( std::ostream &os, int indent = 0 ) const; 715 710 private: 716 std::list< Expression * > assigns; // assignment expressions that use tempDecls 717 std::list< ObjectDecl * > tempDecls; // temporaries for address of lhs exprs 711 StmtExpr * stmtExpr = nullptr; 718 712 }; 719 713 … … 728 722 StmtExpr * set_statements( CompoundStmt * newValue ) { statements = newValue; return this; } 729 723 724 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 725 std::list< Expression * > & get_dtors() { return dtors; } 726 730 727 virtual StmtExpr *clone() const { return new StmtExpr( *this ); } 731 728 virtual void accept( Visitor &v ) { v.visit( this ); } … … 734 731 private: 735 732 CompoundStmt * statements; 733 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression 734 std::list< Expression * > dtors; // destructor(s) for return variable(s) 736 735 }; 737 736 -
src/SynTree/Mutator.cc
r1d2b64f rd5556a3 325 325 mutateAll( impCpCtorExpr->get_tempDecls(), *this ); 326 326 mutateAll( impCpCtorExpr->get_returnDecls(), *this ); 327 mutateAll( impCpCtorExpr->get_dtors(), *this ); 327 328 return impCpCtorExpr; 328 329 } … … 373 374 Expression *Mutator::mutate( TupleAssignExpr *assignExpr ) { 374 375 assignExpr->set_result( maybeMutate( assignExpr->get_result(), *this ) ); 375 mutateAll( assignExpr->get_tempDecls(), *this ); 376 mutateAll( assignExpr->get_assigns(), *this ); 376 assignExpr->set_stmtExpr( maybeMutate( assignExpr->get_stmtExpr(), *this ) ); 377 377 return assignExpr; 378 378 } … … 381 381 stmtExpr->set_result( maybeMutate( stmtExpr->get_result(), *this ) ); 382 382 stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) ); 383 mutateAll( stmtExpr->get_returnDecls(), *this ); 384 mutateAll( stmtExpr->get_dtors(), *this ); 383 385 return stmtExpr; 384 386 } … … 503 505 Initializer *Mutator::mutate( ConstructorInit *ctorInit ) { 504 506 ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) ); 507 ctorInit->set_dtor( maybeMutate( ctorInit->get_dtor(), *this ) ); 505 508 ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) ); 506 509 return ctorInit; -
src/SynTree/TupleExpr.cc
r1d2b64f rd5556a3 87 87 } 88 88 89 90 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ), assigns( assigns ), tempDecls( tempDecls ) { 89 TupleAssignExpr::TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname ) : Expression( _aname ) { 90 // convert internally into a StmtExpr which contains the declarations and produces the tuple of the assignments 91 91 set_result( Tuples::makeTupleType( assigns ) ); 92 CompoundStmt * compoundStmt = new CompoundStmt( noLabels ); 93 std::list< Statement * > & stmts = compoundStmt->get_kids(); 94 for ( ObjectDecl * obj : tempDecls ) { 95 stmts.push_back( new DeclStmt( noLabels, obj ) ); 96 } 97 TupleExpr * tupleExpr = new TupleExpr( assigns ); 98 assert( tupleExpr->get_result() ); 99 stmts.push_back( new ExprStmt( noLabels, tupleExpr ) ); 100 stmtExpr = new StmtExpr( compoundStmt ); 92 101 } 93 102 94 103 TupleAssignExpr::TupleAssignExpr( const TupleAssignExpr &other ) : Expression( other ) { 95 cloneAll( other.assigns, assigns ); 96 cloneAll( other.tempDecls, tempDecls ); 97 98 // clone needs to go into assigns and replace tempDecls 99 VarExprReplacer::DeclMap declMap; 100 std::list< ObjectDecl * >::const_iterator origit = other.tempDecls.begin(); 101 for ( ObjectDecl * temp : tempDecls ) { 102 assert( origit != other.tempDecls.end() ); 103 ObjectDecl * origTemp = *origit++; 104 assert( origTemp ); 105 assert( temp->get_name() == origTemp->get_name() ); 106 declMap[ origTemp ] = temp; 107 } 108 if ( ! declMap.empty() ) { 109 VarExprReplacer replacer( declMap ); 110 for ( Expression * assn : assigns ) { 111 assn->accept( replacer ); 112 } 113 } 104 assert( other.stmtExpr ); 105 stmtExpr = other.stmtExpr->clone(); 114 106 } 115 107 116 108 TupleAssignExpr::~TupleAssignExpr() { 117 deleteAll( assigns ); 118 // deleteAll( tempDecls ); 109 delete stmtExpr; 119 110 } 120 111 121 112 void TupleAssignExpr::print( std::ostream &os, int indent ) const { 122 os << "Tuple Assignment Expression, with temporaries:" << std::endl; 123 printAll( tempDecls, os, indent+4 ); 124 os << std::string( indent+2, ' ' ) << "with assignments: " << std::endl; 125 printAll( assigns, os, indent+4 ); 113 os << "Tuple Assignment Expression, with stmt expr:" << std::endl; 114 os << std::string( indent+2, ' ' ); 115 stmtExpr->print( os, indent+4 ); 126 116 Expression::print( os, indent ); 127 117 } -
src/SynTree/Visitor.cc
r1d2b64f rd5556a3 276 276 acceptAll( impCpCtorExpr->get_tempDecls(), *this ); 277 277 acceptAll( impCpCtorExpr->get_returnDecls(), *this ); 278 acceptAll( impCpCtorExpr->get_dtors(), *this ); 278 279 } 279 280 … … 317 318 void Visitor::visit( TupleAssignExpr *assignExpr ) { 318 319 maybeAccept( assignExpr->get_result(), *this ); 319 acceptAll( assignExpr->get_tempDecls(), *this ); 320 acceptAll( assignExpr->get_assigns(), *this ); 320 maybeAccept( assignExpr->get_stmtExpr(), *this ); 321 321 } 322 322 … … 324 324 maybeAccept( stmtExpr->get_result(), *this ); 325 325 maybeAccept( stmtExpr->get_statements(), *this ); 326 acceptAll( stmtExpr->get_returnDecls(), *this ); 327 acceptAll( stmtExpr->get_dtors(), *this ); 326 328 } 327 329 … … 425 427 void Visitor::visit( ConstructorInit *ctorInit ) { 426 428 maybeAccept( ctorInit->get_ctor(), *this ); 429 maybeAccept( ctorInit->get_dtor(), *this ); 427 430 maybeAccept( ctorInit->get_init(), *this ); 428 431 } -
src/Tuples/TupleExpansion.cc
r1d2b64f rd5556a3 194 194 new CommaExpr( new CommaExpr( assignUnq, assignFinished ), var->clone() ) ); 195 195 condExpr->set_result( var->get_result()->clone() ); 196 condExpr->set_env( maybeClone( unqExpr->get_env() ) ); 196 197 decls[id] = condExpr; 197 198 } … … 202 203 Expression * TupleAssignExpander::mutate( TupleAssignExpr * assnExpr ) { 203 204 assnExpr = safe_dynamic_cast< TupleAssignExpr * >( Parent::mutate( assnExpr ) ); 204 CompoundStmt * compoundStmt = new CompoundStmt( noLabels ); 205 std::list< Statement * > & stmts = compoundStmt->get_kids(); 206 for ( ObjectDecl * obj : assnExpr->get_tempDecls() ) { 207 stmts.push_back( new DeclStmt( noLabels, obj ) ); 208 } 209 TupleExpr * tupleExpr = new TupleExpr( assnExpr->get_assigns() ); 210 assert( tupleExpr->get_result() ); 211 stmts.push_back( new ExprStmt( noLabels, tupleExpr ) ); 212 assnExpr->get_tempDecls().clear(); 213 assnExpr->get_assigns().clear(); 205 StmtExpr * ret = assnExpr->get_stmtExpr(); 206 assnExpr->set_stmtExpr( nullptr ); 207 // move env to StmtExpr 208 ret->set_env( assnExpr->get_env() ); 209 assnExpr->set_env( nullptr ); 214 210 delete assnExpr; 215 return new StmtExpr( compoundStmt );211 return ret; 216 212 } 217 213 … … 221 217 if ( ! typeMap.count( mangleName ) ) { 222 218 // generate struct type to replace tuple type 219 // xxx - should fix this to only generate one tuple struct for each number of type parameters 223 220 StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName ); 224 221 decl->set_body( true ); … … 247 244 tupleExpr->set_tuple( nullptr ); 248 245 unsigned int idx = tupleExpr->get_index(); 246 TypeSubstitution * env = tupleExpr->get_env(); 247 tupleExpr->set_env( nullptr ); 249 248 delete tupleExpr; 250 249 … … 253 252 assert( structDecl->get_members().size() > idx ); 254 253 Declaration * member = *std::next(structDecl->get_members().begin(), idx); 255 return new MemberExpr( safe_dynamic_cast< DeclarationWithType * >( member ), tuple ); 256 } 257 258 Expression * replaceTupleExpr( Type * result, const std::list< Expression * > & exprs ) { 254 MemberExpr * memExpr = new MemberExpr( safe_dynamic_cast< DeclarationWithType * >( member ), tuple ); 255 memExpr->set_env( env ); 256 return memExpr; 257 } 258 259 Expression * replaceTupleExpr( Type * result, const std::list< Expression * > & exprs, TypeSubstitution * env ) { 259 260 if ( result->isVoid() ) { 260 261 // void result - don't need to produce a value for cascading - just output a chain of comma exprs 261 262 assert( ! exprs.empty() ); 262 263 std::list< Expression * >::const_iterator iter = exprs.begin(); 263 Expression * expr = *iter++;264 Expression * expr = new CastExpr( *iter++ ); 264 265 for ( ; iter != exprs.end(); ++iter ) { 265 expr = new CommaExpr( expr, *iter ); 266 } 266 expr = new CommaExpr( expr, new CastExpr( *iter ) ); 267 } 268 expr->set_env( env ); 267 269 return expr; 268 270 } else { … … 274 276 inits.push_back( new SingleInit( expr ) ); 275 277 } 276 return new CompoundLiteralExpr( result, new ListInit( inits ) ); 278 Expression * expr = new CompoundLiteralExpr( result, new ListInit( inits ) ); 279 expr->set_env( env ); 280 return expr; 277 281 } 278 282 } … … 284 288 std::list< Expression * > exprs = tupleExpr->get_exprs(); 285 289 assert( result ); 290 TypeSubstitution * env = tupleExpr->get_env(); 286 291 287 292 // remove data from shell and delete it 288 293 tupleExpr->set_result( nullptr ); 289 294 tupleExpr->get_exprs().clear(); 295 tupleExpr->set_env( nullptr ); 290 296 delete tupleExpr; 291 297 292 return replaceTupleExpr( result, exprs );298 return replaceTupleExpr( result, exprs, env ); 293 299 } 294 300
Note: See TracChangeset
for help on using the changeset viewer.