Changeset ba3706f for src/InitTweak
- Timestamp:
- Nov 30, 2017, 4:43:59 PM (7 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:
- c50d54d
- Parents:
- 4429b04
- Location:
- src/InitTweak
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r4429b04 rba3706f 29 29 #include "SynTree/Expression.h" // for ConstantExpr, Expression (ptr only) 30 30 #include "SynTree/Initializer.h" // for ConstructorInit, Initializer 31 #include "SynTree/Label.h" // for Label , noLabels31 #include "SynTree/Label.h" // for Label 32 32 #include "SynTree/Statement.h" // for CompoundStmt, Statement (ptr only) 33 33 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Functi... … … 92 92 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 93 93 } 94 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels) );94 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 95 95 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 96 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels) );96 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 97 97 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 98 98 } -
src/InitTweak/FixInit.cc
r4429b04 rba3706f 49 49 #include "SynTree/Expression.h" // for UniqueExpr, VariableExpr, Unty... 50 50 #include "SynTree/Initializer.h" // for ConstructorInit, SingleInit 51 #include "SynTree/Label.h" // for Label, noLabels,operator<51 #include "SynTree/Label.h" // for Label, operator< 52 52 #include "SynTree/Mutator.h" // for mutateAll, Mutator, maybeMutate 53 53 #include "SynTree/Statement.h" // for ExprStmt, CompoundStmt, Branch... … … 544 544 // add all temporary declarations and their constructors 545 545 for ( ObjectDecl * obj : tempDecls ) { 546 stmtsToAddBefore.push_back( new DeclStmt( noLabels,obj ) );546 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 547 547 } // for 548 548 for ( ObjectDecl * obj : returnDecls ) { 549 stmtsToAddBefore.push_back( new DeclStmt( noLabels,obj ) );549 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 550 550 } // for 551 551 552 552 // add destructors after current statement 553 553 for ( Expression * dtor : dtors ) { 554 stmtsToAddAfter.push_back( new ExprStmt( noLabels,dtor ) );554 stmtsToAddAfter.push_back( new ExprStmt( dtor ) ); 555 555 } // for 556 556 … … 598 598 if ( ! result->isVoid() ) { 599 599 for ( ObjectDecl * obj : stmtExpr->get_returnDecls() ) { 600 stmtsToAddBefore.push_back( new DeclStmt( noLabels,obj ) );600 stmtsToAddBefore.push_back( new DeclStmt( obj ) ); 601 601 } // for 602 602 // add destructors after current statement 603 603 for ( Expression * dtor : stmtExpr->get_dtors() ) { 604 stmtsToAddAfter.push_back( new ExprStmt( noLabels,dtor ) );604 stmtsToAddAfter.push_back( new ExprStmt( dtor ) ); 605 605 } // for 606 606 // must have a non-empty body, otherwise it wouldn't have a result 607 607 assert( ! stmts.empty() ); 608 608 assert( ! stmtExpr->get_returnDecls().empty() ); 609 stmts.push_back( new ExprStmt( n oLabels, new VariableExpr( stmtExpr->get_returnDecls().front() ) ) );609 stmts.push_back( new ExprStmt( new VariableExpr( stmtExpr->get_returnDecls().front() ) ) ); 610 610 stmtExpr->get_returnDecls().clear(); 611 611 stmtExpr->get_dtors().clear(); … … 685 685 686 686 // generate body of if 687 CompoundStmt * initStmts = new CompoundStmt( noLabels);687 CompoundStmt * initStmts = new CompoundStmt(); 688 688 std::list< Statement * > & body = initStmts->get_kids(); 689 689 body.push_back( ctor ); 690 body.push_back( new ExprStmt( noLabels,setTrue ) );690 body.push_back( new ExprStmt( setTrue ) ); 691 691 692 692 // put it all together 693 IfStmt * ifStmt = new IfStmt( n oLabels, new VariableExpr( isUninitializedVar ), initStmts, 0 );694 stmtsToAddAfter.push_back( new DeclStmt( noLabels,isUninitializedVar ) );693 IfStmt * ifStmt = new IfStmt( new VariableExpr( isUninitializedVar ), initStmts, 0 ); 694 stmtsToAddAfter.push_back( new DeclStmt( isUninitializedVar ) ); 695 695 stmtsToAddAfter.push_back( ifStmt ); 696 696 … … 707 707 708 708 // void __objName_dtor_atexitN(...) {...} 709 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels) );709 FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() ); 710 710 dtorCaller->fixUniqueId(); 711 711 dtorCaller->get_statements()->push_back( dtorStmt ); … … 715 715 callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) ); 716 716 717 body.push_back( new ExprStmt( noLabels,callAtexit ) );717 body.push_back( new ExprStmt( callAtexit ) ); 718 718 719 719 // hoist variable and dtor caller decls to list of decls that will be added into global scope -
src/InitTweak/InitTweak.cc
r4429b04 rba3706f 19 19 #include "SynTree/Expression.h" // for Expression, UntypedExpr, Applicati... 20 20 #include "SynTree/Initializer.h" // for Initializer, ListInit, Designation 21 #include "SynTree/Label.h" // for Label , noLabels21 #include "SynTree/Label.h" // for Label 22 22 #include "SynTree/Statement.h" // for CompoundStmt, ExprStmt, BranchStmt 23 23 #include "SynTree/Type.h" // for FunctionType, ArrayType, PointerType … … 195 195 callExpr->get_args().splice( callExpr->get_args().end(), args ); 196 196 197 *out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels,callExpr ), nullptr );197 *out++ = new IfStmt( cond, new ExprStmt( callExpr ), nullptr ); 198 198 199 199 UntypedExpr * increment = new UntypedExpr( new NameExpr( "++?" ) ); 200 200 increment->get_args().push_back( index->clone() ); 201 *out++ = new ExprStmt( noLabels,increment );201 *out++ = new ExprStmt( increment ); 202 202 } 203 203 … … 244 244 std::list< Statement * > stmts; 245 245 build( callExpr, idx, idxEnd, init, back_inserter( stmts ) ); 246 stmts.push_back( new BranchStmt( noLabels,switchLabel, BranchStmt::Break ) );247 CaseStmt * caseStmt = new CaseStmt( noLabels,condition, stmts );246 stmts.push_back( new BranchStmt( switchLabel, BranchStmt::Break ) ); 247 CaseStmt * caseStmt = new CaseStmt( condition, stmts ); 248 248 branches.push_back( caseStmt ); 249 249 } 250 *out++ = new SwitchStmt( noLabels,index->clone(), branches );251 *out++ = new NullStmt( std::list<Label>{ switchLabel } );250 *out++ = new SwitchStmt( index->clone(), branches ); 251 *out++ = new NullStmt( { switchLabel } ); 252 252 } 253 253 } … … 262 262 Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) { 263 263 if ( ! init ) return nullptr; 264 CompoundStmt * block = new CompoundStmt( noLabels);264 CompoundStmt * block = new CompoundStmt(); 265 265 build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) ); 266 266 if ( block->get_kids().empty() ) {
Note: See TracChangeset
for help on using the changeset viewer.