Changeset f0121d7 for src/InitTweak
- Timestamp:
- Oct 26, 2016, 10:56:46 AM (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:
- a1e67dd
- Parents:
- bf32bb8
- Location:
- src/InitTweak
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
rbf32bb8 rf0121d7 35 35 #include "GenPoly/DeclMutator.h" 36 36 #include "SynTree/AddStmtVisitor.h" 37 #include "CodeGen/GenType.h" // for warning s38 39 bool ctordtorp = false; 40 bool ctorp = false; 41 bool cpctorp = false; 42 bool dtorp = false; 37 #include "CodeGen/GenType.h" // for warning/error messages 38 39 bool ctordtorp = false; // print all debug 40 bool ctorp = false; // print ctor debug 41 bool cpctorp = false; // print copy ctor debug 42 bool dtorp = false; // print dtor debug 43 43 #define PRINT( text ) if ( ctordtorp ) { text } 44 44 #define CP_CTOR_PRINT( text ) if ( ctordtorp || cpctorp ) { text } … … 47 47 namespace InitTweak { 48 48 namespace { 49 const std::list<Label> noLabels;50 const std::list<Expression*> noDesignators;51 52 49 class InsertImplicitCalls : public GenPoly::PolyMutator { 53 50 public: … … 957 954 Expression * FixCtorExprs::mutate( ConstructorExpr * ctorExpr ) { 958 955 static UniqueName tempNamer( "_tmp_ctor_expr" ); 956 // xxx - is the size check necessary? 959 957 assert( ctorExpr->has_result() && ctorExpr->get_result()->size() == 1 ); 960 958 ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, ctorExpr->get_result()->clone(), nullptr ); -
src/InitTweak/GenInit.cc
rbf32bb8 rf0121d7 265 265 } 266 266 267 ConstructorInit * genCtorInit( ObjectDecl * objDecl ) { 268 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor 269 // for each constructable object 270 std::list< Statement * > ctor; 271 std::list< Statement * > dtor; 272 273 InitExpander srcParam( objDecl->get_init() ); 274 InitExpander nullParam( (Initializer *)NULL ); 275 SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl ); 276 SymTab::genImplicitCall( nullParam, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false ); 277 278 // Currently genImplicitCall produces a single Statement - a CompoundStmt 279 // which wraps everything that needs to happen. As such, it's technically 280 // possible to use a Statement ** in the above calls, but this is inherently 281 // unsafe, so instead we take the slightly less efficient route, but will be 282 // immediately informed if somehow the above assumption is broken. In this case, 283 // we could always wrap the list of statements at this point with a CompoundStmt, 284 // but it seems reasonable at the moment for this to be done by genImplicitCall 285 // itself. It is possible that genImplicitCall produces no statements (e.g. if 286 // an array type does not have a dimension). In this case, it's fine to ignore 287 // the object for the purposes of construction. 288 assert( ctor.size() == dtor.size() && ctor.size() <= 1 ); 289 if ( ctor.size() == 1 ) { 290 // need to remember init expression, in case no ctors exist 291 // if ctor does exist, want to use ctor expression instead of init 292 // push this decision to the resolver 293 assert( dynamic_cast< ImplicitCtorDtorStmt * > ( ctor.front() ) && dynamic_cast< ImplicitCtorDtorStmt * > ( dtor.front() ) ); 294 return new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ); 295 } 296 return nullptr; 297 } 298 267 299 DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) { 268 300 handleDWT( objDecl ); … … 275 307 if ( ! checkInitDepth( objDecl ) ) throw SemanticError( "Managed object's initializer is too deep ", objDecl ); 276 308 277 // call into genImplicitCall from Autogen.h to generate calls to ctor/dtor 278 // for each constructable object 279 std::list< Statement * > ctor; 280 std::list< Statement * > dtor; 281 282 InitExpander srcParam( objDecl->get_init() ); 283 InitExpander nullParam( (Initializer *)NULL ); 284 SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl ); 285 SymTab::genImplicitCall( nullParam, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false ); 286 287 // Currently genImplicitCall produces a single Statement - a CompoundStmt 288 // which wraps everything that needs to happen. As such, it's technically 289 // possible to use a Statement ** in the above calls, but this is inherently 290 // unsafe, so instead we take the slightly less efficient route, but will be 291 // immediately informed if somehow the above assumption is broken. In this case, 292 // we could always wrap the list of statements at this point with a CompoundStmt, 293 // but it seems reasonable at the moment for this to be done by genImplicitCall 294 // itself. It is possible that genImplicitCall produces no statements (e.g. if 295 // an array type does not have a dimension). In this case, it's fine to ignore 296 // the object for the purposes of construction. 297 assert( ctor.size() == dtor.size() && ctor.size() <= 1 ); 298 if ( ctor.size() == 1 ) { 299 // need to remember init expression, in case no ctors exist 300 // if ctor does exist, want to use ctor expression instead of init 301 // push this decision to the resolver 302 assert( dynamic_cast< ImplicitCtorDtorStmt * > ( ctor.front() ) && dynamic_cast< ImplicitCtorDtorStmt * > ( dtor.front() ) ); 303 objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ) ); 304 } 309 objDecl->set_init( genCtorInit( objDecl ) ); 305 310 } 306 311 return Parent::mutate( objDecl ); -
src/InitTweak/GenInit.h
rbf32bb8 rf0121d7 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // RemoveInit.h --7 // GenInit.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves … … 27 27 /// Adds return value temporaries and wraps Initializers in ConstructorInit nodes 28 28 void genInit( std::list< Declaration * > & translationUnit ); 29 30 /// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer 31 ConstructorInit * genCtorInit( ObjectDecl * objDecl ); 29 32 } // namespace 30 33
Note: See TracChangeset
for help on using the changeset viewer.