- 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
- Files:
-
- 6 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 -
src/SynTree/Initializer.h
rbf32bb8 rf0121d7 23 23 24 24 #include <cassert> 25 26 const std::list<Expression*> noDesignators; 25 27 26 28 // Initializer: base class for object initializers (provide default values) -
src/Tuples/TupleExpansion.cc
rbf32bb8 rf0121d7 28 28 #include "Common/ScopedMap.h" 29 29 #include "ResolvExpr/typeops.h" 30 #include "InitTweak/GenInit.h" 30 31 31 32 namespace Tuples { … … 133 134 return tupleExpr; 134 135 } else { 135 return memberExpr; 136 // there may be a tuple expr buried in the aggregate 137 // xxx - this is a memory leak 138 return new UntypedMemberExpr( memberExpr->get_member()->clone(), memberExpr->get_aggregate()->acceptMutator( *this ) ); 136 139 } 137 140 } … … 142 145 if ( ! decls.count( unqExpr->get_id() ) ) { 143 146 // xxx - it's possible (likely?) that expressions can appear in the wrong order because of this. Need to ensure they're placed in the correct location. 144 // xxx - is it possible to make the decl's type const? 145 ObjectDecl * decl = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, unqExpr->get_result()->clone(), new SingleInit( unqExpr->get_expr()->clone() ) ); 146 decls[unqExpr->get_id()] = decl; 147 addDeclaration( decl ); 147 148 // xxx - this doesn't work, because it would need to be placed after fixInit, but fixInit doesn't know (and shouldn't have to know) about the existance of UniqueExprs - i.e. it will visit them twice 149 // need to construct/destruct unique exprs in general - maybe it's not worth it and fixInit should handle UniqueExpr explicitly? 150 // currently, tmp is being destructed before unqExpr is used, which suggests there should be a separate lifetime for unqExpr from the tmp_ret 151 152 // if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( unqExpr->get_expr() ) ) { 153 // if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( commaExpr->get_arg2() ) ) { 154 // // steal existing decl from expr 155 // if ( ObjectDecl * decl = dynamic_cast< ObjectDecl * >( varExpr->get_var() ) ) { 156 // decls[unqExpr->get_id()] = decl; 157 // return unqExpr->get_expr()->clone(); 158 // } 159 // } 160 // } 161 162 // xxx - attach a resolved ConstructorInit node? 163 // xxx - is it possible to make the objDecl's type const? 164 ObjectDecl * objDecl = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, unqExpr->get_result()->clone(), nullptr ); 165 // must be done on two lines because genCtorInit accesses objDecl's fields 166 objDecl->set_init( InitTweak::genCtorInit( objDecl ) ); 167 168 decls[unqExpr->get_id()] = objDecl; 169 addDeclaration( objDecl ); 148 170 } 149 171 return new VariableExpr( decls[unqExpr->get_id()] ); -
src/main.cc
rbf32bb8 rf0121d7 251 251 } // if 252 252 253 OPTPRINT( "expandUniqueExpr" ); // xxx - is this the right place for this? 253 OPTPRINT( "expandUniqueExpr" ); // xxx - is this the right place for this? want to expand ASAP so that subsequent passes don't need to worry about double-visiting a unique expr 254 254 Tuples::expandUniqueExpr( translationUnit ); 255 255
Note: See TracChangeset
for help on using the changeset viewer.