Changeset 65660bd for src/InitTweak/GenInit.cc
- Timestamp:
- Sep 22, 2016, 8:14:56 AM (9 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:
- ac9ca96
- Parents:
- 1132b62
- git-author:
- Rob Schluntz <rschlunt@…> (09/21/16 23:43:37)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/22/16 08:14:56)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
r1132b62 r65660bd 29 29 #include "GenPoly/DeclMutator.h" 30 30 #include "GenPoly/ScopedSet.h" 31 #include "ResolvExpr/typeops.h" 31 32 32 33 namespace InitTweak { … … 50 51 51 52 protected: 52 std::list<DeclarationWithType*> returnVals;53 FunctionType * ftype; 53 54 UniqueName tempNamer; 54 55 std::string funcName; … … 86 87 87 88 bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed 89 bool isManaged( Type * type ) const; // determine if type is managed 88 90 void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor 89 91 GenPoly::ScopedSet< std::string > managedTypes; … … 134 136 135 137 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) { 136 // update for multiple return values138 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals(); 137 139 assert( returnVals.size() == 0 || returnVals.size() == 1 ); 138 140 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address … … 156 158 157 159 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 158 ValueGuard< std::list<DeclarationWithType*> > oldReturnVals( returnVals ); 160 // xxx - need to handle named return values - this pass may need to happen 161 // after resolution? the ordering is tricky because return statements must be 162 // constructed - the simplest way to do that (while also handling multiple 163 // returns) is to structure the returnVals into a tuple, as done here. 164 // however, if the tuple return value is structured before resolution, 165 // it's difficult to resolve named return values, since the name is lost 166 // in conversion to a tuple. this might be easiest to deal with 167 // after reference types are added, as it may then be possible to 168 // uniformly move named return values to the parameter list directly 169 ValueGuard< FunctionType * > oldFtype( ftype ); 159 170 ValueGuard< std::string > oldFuncName( funcName ); 160 171 161 FunctionType * type = functionDecl->get_functionType(); 162 returnVals = type->get_returnVals(); 172 ftype = functionDecl->get_functionType(); 173 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals(); 174 if ( retVals.size() > 1 ) { 175 TupleType * tupleType = safe_dynamic_cast< TupleType * >( ResolvExpr::extractResultType( ftype ) ); 176 ObjectDecl * newRet = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) ); 177 retVals.clear(); 178 retVals.push_back( newRet ); 179 } 163 180 funcName = functionDecl->get_name(); 164 181 DeclarationWithType * decl = Mutator::mutate( functionDecl ); … … 220 237 } 221 238 239 bool CtorDtor::isManaged( Type * type ) const { 240 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end(); 241 } 242 222 243 bool CtorDtor::isManaged( ObjectDecl * objDecl ) const { 223 244 Type * type = objDecl->get_type(); … … 225 246 type = at->get_base(); 226 247 } 227 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end(); 248 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( type ) ) { 249 return std::any_of( tupleType->get_types().begin(), tupleType->get_types().end(), [&](Type * type) { return isManaged( type ); }); 250 } 251 return isManaged( type ); 228 252 } 229 253
Note: See TracChangeset
for help on using the changeset viewer.