Changes in src/InitTweak/GenInit.cc [ac9ca967:dcd73d1]
- File:
-
- 1 edited
-
src/InitTweak/GenInit.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/GenInit.cc
rac9ca967 rdcd73d1 29 29 #include "GenPoly/DeclMutator.h" 30 30 #include "GenPoly/ScopedSet.h" 31 #include "ResolvExpr/typeops.h"32 31 33 32 namespace InitTweak { … … 51 50 52 51 protected: 53 FunctionType * ftype;52 std::list<DeclarationWithType*> returnVals; 54 53 UniqueName tempNamer; 55 54 std::string funcName; … … 87 86 88 87 bool isManaged( ObjectDecl * objDecl ) const ; // determine if object is managed 89 bool isManaged( Type * type ) const; // determine if type is managed90 88 void handleDWT( DeclarationWithType * dwt ); // add type to managed if ctor/dtor 91 89 GenPoly::ScopedSet< std::string > managedTypes; … … 136 134 137 135 Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) { 138 std::list< DeclarationWithType * > & returnVals = ftype->get_returnVals();136 // update for multiple return values 139 137 assert( returnVals.size() == 0 || returnVals.size() == 1 ); 140 138 // hands off if the function returns an lvalue - we don't want to allocate a temporary if a variable's address … … 158 156 159 157 DeclarationWithType* ReturnFixer::mutate( FunctionDecl *functionDecl ) { 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 ); 158 ValueGuard< std::list<DeclarationWithType*> > oldReturnVals( returnVals ); 170 159 ValueGuard< std::string > oldFuncName( funcName ); 171 160 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 } 161 FunctionType * type = functionDecl->get_functionType(); 162 returnVals = type->get_returnVals(); 180 163 funcName = functionDecl->get_name(); 181 164 DeclarationWithType * decl = Mutator::mutate( functionDecl ); … … 237 220 } 238 221 239 bool CtorDtor::isManaged( Type * type ) const {240 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( type ) ) {241 // tuple is also managed if any of its components are managed242 if ( std::any_of( tupleType->get_types().begin(), tupleType->get_types().end(), [&](Type * type) { return isManaged( type ); }) ) {243 return true;244 }245 }246 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end();247 }248 249 222 bool CtorDtor::isManaged( ObjectDecl * objDecl ) const { 250 223 Type * type = objDecl->get_type(); … … 252 225 type = at->get_base(); 253 226 } 254 return isManaged( type);227 return managedTypes.find( SymTab::Mangler::mangle( type ) ) != managedTypes.end(); 255 228 } 256 229 … … 315 288 managedTypes.beginScope(); 316 289 // go through assertions and recursively add seen ctor/dtors 317 for ( auto &tyDecl : functionDecl->get_functionType()->get_forall() ) {290 for ( TypeDecl * tyDecl : functionDecl->get_functionType()->get_forall() ) { 318 291 for ( DeclarationWithType *& assertion : tyDecl->get_assertions() ) { 319 292 assertion = assertion->acceptMutator( *this );
Note:
See TracChangeset
for help on using the changeset viewer.