Changes in / [63238a4:28f3a19]
- Location:
- src
- Files:
-
- 4 added
- 90 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r63238a4 r28f3a19 1188 1188 unsigned Indenter::tabsize = 2; 1189 1189 1190 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {1191 if ( node ) {1192 node->print( out );1193 } else {1194 out << "nullptr";1195 }1196 return out;1197 }1198 1199 1190 // Local Variables: // 1200 1191 // tab-width: 4 // -
src/CodeGen/FixMain.cc
r63238a4 r28f3a19 29 29 namespace CodeGen { 30 30 bool FixMain::replace_main = false; 31 std::unique_ptr<FunctionDecl>FixMain::main_signature = nullptr;31 FunctionDecl* FixMain::main_signature = nullptr; 32 32 33 33 template<typename container> … … 41 41 SemanticError(functionDecl, "Multiple definition of main routine\n"); 42 42 } 43 main_signature .reset( functionDecl->clone() );43 main_signature = functionDecl; 44 44 } 45 45 -
src/CodeGen/FixMain.h
r63238a4 r28f3a19 40 40 private: 41 41 static bool replace_main; 42 static std::unique_ptr<FunctionDecl>main_signature;42 static FunctionDecl* main_signature; 43 43 }; 44 44 }; -
src/CodeGen/FixNames.cc
r63238a4 r28f3a19 16 16 #include "FixNames.h" 17 17 18 #include <memory> // for unique_ptr19 18 #include <string> // for string, operator!=, operator== 20 19 … … 47 46 std::string mangle_main() { 48 47 FunctionType* main_type; 49 std::unique_ptr<FunctionDecl> mainDecl { new FunctionDecl( "main", Type::StorageClasses(), LinkageSpec::Cforall,50 main_type = new FunctionType( Type::Qualifiers(), true ), nullptr )51 48 FunctionDecl* mainDecl = new FunctionDecl{ 49 "main", Type::StorageClasses(), LinkageSpec::Cforall, 50 main_type = new FunctionType{ Type::Qualifiers(), true }, nullptr }; 52 51 main_type->get_returnVals().push_back( 53 52 new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) 54 53 ); 55 54 56 auto && name = SymTab::Mangler::mangle( mainDecl .get());55 auto && name = SymTab::Mangler::mangle( mainDecl ); 57 56 // std::cerr << name << std::endl; 58 57 return std::move(name); … … 60 59 std::string mangle_main_args() { 61 60 FunctionType* main_type; 62 std::unique_ptr<FunctionDecl> mainDecl { new FunctionDecl( "main", Type::StorageClasses(), LinkageSpec::Cforall,63 main_type = new FunctionType( Type::Qualifiers(), false ), nullptr )64 61 FunctionDecl* mainDecl = new FunctionDecl{ 62 "main", Type::StorageClasses(), LinkageSpec::Cforall, 63 main_type = new FunctionType{ Type::Qualifiers(), false }, nullptr }; 65 64 main_type->get_returnVals().push_back( 66 65 new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) … … 77 76 ); 78 77 79 auto&& name = SymTab::Mangler::mangle( mainDecl .get());78 auto&& name = SymTab::Mangler::mangle( mainDecl ); 80 79 // std::cerr << name << std::endl; 81 80 return std::move(name); -
src/CodeGen/Generate.cc
r63238a4 r28f3a19 41 41 void cleanTree( std::list< Declaration * > & translationUnit ) { 42 42 PassVisitor<TreeCleaner> cleaner; 43 filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); } , false);43 filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); } ); 44 44 mutateAll( translationUnit, cleaner ); 45 45 } // cleanTree … … 79 79 } 80 80 return false; 81 } , false);81 } ); 82 82 } 83 83 … … 85 85 Statement * callStmt = nullptr; 86 86 std::swap( stmt->callStmt, callStmt ); 87 delete stmt;88 87 return callStmt; 89 88 } -
src/Common/PassVisitor.h
r63238a4 r28f3a19 153 153 virtual void visit( Subrange * subrange ) override final; 154 154 155 virtual void visit( Constant * constant ) overridefinal;155 virtual void visit( Constant * constant ) final; 156 156 157 157 virtual void visit( Attribute * attribute ) override final; 158 159 virtual void visit( TypeSubstitution * sub ) final; 158 160 159 161 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override final; … … 253 255 virtual Subrange * mutate( Subrange * subrange ) override final; 254 256 255 virtual Constant * mutate( Constant * constant ) overridefinal;257 virtual Constant * mutate( Constant * constant ) final; 256 258 257 259 virtual Attribute * mutate( Attribute * attribute ) override final; -
src/Common/PassVisitor.impl.h
r63238a4 r28f3a19 38 38 MUTATE_END( type, node ); \ 39 39 40 40 #include "Common/GC.h" 41 41 42 42 template<typename T> … … 397 397 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 398 398 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 399 static ObjectDecl func(399 static ObjectDecl* func = new_static_root<ObjectDecl>( 400 400 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 401 401 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 402 402 nullptr 403 403 ); 404 indexerAddId( &func );404 indexerAddId( func ); 405 405 maybeAccept_impl( node->type, *this ); 406 406 // function body needs to have the same scope as parameters - CompoundStmt will not enter … … 431 431 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 432 432 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 433 static ObjectDecl func(433 static ObjectDecl* func = new_static_root<ObjectDecl>( 434 434 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 435 435 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 436 436 nullptr 437 437 ); 438 indexerAddId( &func );438 indexerAddId( func ); 439 439 maybeMutate_impl( node->type, *this ); 440 440 // function body needs to have the same scope as parameters - CompoundStmt will not enter … … 1234 1234 indexerScopedAccept( node->result, *this ); 1235 1235 1236 // xxx - not quite sure why this doesn't visit( node->function ); 1236 1237 for ( auto expr : node->args ) { 1237 1238 visitExpression( expr ); … … 2694 2695 // TypeSubstitution 2695 2696 template< typename pass_type > 2697 void PassVisitor< pass_type >::visit( TypeSubstitution * node ) { 2698 VISIT_START( node ); 2699 2700 for ( auto & p : node->typeEnv ) { 2701 indexerScopedAccept( p.second, *this ); 2702 } 2703 for ( auto & p : node->varEnv ) { 2704 indexerScopedAccept( p.second, *this ); 2705 } 2706 2707 VISIT_END( node ); 2708 } 2709 2710 template< typename pass_type > 2696 2711 TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) { 2697 2712 MUTATE_START( node ); -
src/Common/module.mk
r63238a4 r28f3a19 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## module.mk -- 8 ## module.mk -- 9 9 ## 10 10 ## Author : Richard C. Bilson … … 18 18 Common/UniqueName.cc \ 19 19 Common/DebugMalloc.cc \ 20 Common/GC.cc \ 20 21 Common/Assert.cc \ 21 22 Common/Heap.cc -
src/Common/utility.h
r63238a4 r28f3a19 190 190 191 191 template <typename E, typename UnaryPredicate, template< typename, typename...> class Container, typename... Args > 192 void filter( Container< E *, Args... > & container, UnaryPredicate pred , bool doDelete) {192 void filter( Container< E *, Args... > & container, UnaryPredicate pred ) { 193 193 auto i = begin( container ); 194 194 while ( i != end( container ) ) { 195 195 auto it = next( i ); 196 196 if ( pred( *i ) ) { 197 if ( doDelete ) {198 delete *i;199 } // if200 197 container.erase( i ); 201 198 } // if -
src/Concurrency/Keywords.cc
r63238a4 r28f3a19 19 19 #include <string> // for string, operator== 20 20 21 #include "Common/GC.h" // for new_static_root 21 22 #include "Common/PassVisitor.h" // for PassVisitor 22 23 #include "Common/SemanticError.h" // for SemanticError … … 206 207 StructDecl* dtor_guard_decl = nullptr; 207 208 208 static std::unique_ptr< Type >generic_func;209 static Type* generic_func; 209 210 }; 210 211 211 std::unique_ptr< Type > MutexKeyword::generic_func = std::unique_ptr< Type >( 212 new FunctionType( 213 noQualifiers, 214 true 215 ) 216 ); 212 Type* MutexKeyword::generic_func = new_static_root<FunctionType>( noQualifiers, true ); 217 213 218 214 //----------------------------------------------------------------------------- … … 288 284 // convert (thread &)t to (thread_desc &)*get_thread(t), etc. 289 285 if( !type_decl ) SemanticError( cast, context_error ); 290 Expression * arg = cast->arg;291 cast->arg = nullptr;292 delete cast;293 286 return new CastExpr( 294 287 UntypedExpr::createDeref( 295 new UntypedExpr( new NameExpr( getter_name ), { arg } )288 new UntypedExpr( new NameExpr( getter_name ), { cast->arg } ) 296 289 ), 297 290 new ReferenceType( … … 318 311 StructDecl * forward = decl->clone(); 319 312 forward->set_body( false ); 320 deleteAll( forward->get_members() );321 313 forward->get_members().clear(); 322 314 … … 382 374 fixupGenerics(main_type, decl); 383 375 } 384 385 delete this_decl;386 376 387 377 declsToAddBefore.push_back( forward ); -
src/Concurrency/Waitfor.cc
r63238a4 r28f3a19 137 137 StructDecl * decl_acceptable = nullptr; 138 138 StructDecl * decl_monitor = nullptr; 139 140 static std::unique_ptr< Type > generic_func;141 139 142 140 UniqueName namer_acc = "__acceptables_"s; … … 476 474 } 477 475 478 delete setter;479 480 476 return new VariableExpr( timeout ); 481 477 } -
src/ControlStruct/ExceptTranslate.cc
r63238a4 r28f3a19 104 104 // Types used in translation, make sure to use clone. 105 105 // void (*function)(); 106 FunctionType try_func_t;106 FunctionType * try_func_t; 107 107 // void (*function)(int, exception); 108 FunctionType catch_func_t;108 FunctionType * catch_func_t; 109 109 // int (*function)(exception); 110 FunctionType match_func_t;110 FunctionType * match_func_t; 111 111 // bool (*function)(exception); 112 FunctionType handle_func_t;112 FunctionType * handle_func_t; 113 113 // void (*function)(__attribute__((unused)) void *); 114 FunctionType finally_func_t;114 FunctionType * finally_func_t; 115 115 116 116 StructInstType * create_except_type() { … … 125 125 handler_except_decl( nullptr ), 126 126 except_decl( nullptr ), node_decl( nullptr ), hook_decl( nullptr ), 127 try_func_t( n oQualifiers, false),128 catch_func_t( n oQualifiers, false),129 match_func_t( n oQualifiers, false),130 handle_func_t( n oQualifiers, false),131 finally_func_t( n oQualifiers, false)127 try_func_t( new FunctionType(noQualifiers, false) ), 128 catch_func_t( new FunctionType(noQualifiers, false) ), 129 match_func_t( new FunctionType(noQualifiers, false) ), 130 handle_func_t( new FunctionType(noQualifiers, false) ), 131 finally_func_t( new FunctionType(noQualifiers, false) ) 132 132 {} 133 133 … … 141 141 assert( except_decl ); 142 142 143 ObjectDecl index_obj(143 auto index_obj = new ObjectDecl( 144 144 "__handler_index", 145 145 Type::StorageClasses(), … … 149 149 /*init*/ NULL 150 150 ); 151 ObjectDecl exception_obj(151 auto exception_obj = new ObjectDecl( 152 152 "__exception_inst", 153 153 Type::StorageClasses(), … … 160 160 /*init*/ NULL 161 161 ); 162 ObjectDecl bool_obj(162 auto bool_obj = new ObjectDecl( 163 163 "__ret_bool", 164 164 Type::StorageClasses(), … … 169 169 std::list<Attribute *>{ new Attribute( "unused" ) } 170 170 ); 171 ObjectDecl voidptr_obj(171 auto voidptr_obj = new ObjectDecl( 172 172 "__hook", 173 173 Type::StorageClasses(), … … 184 184 ); 185 185 186 ObjectDecl * unused_index_obj = index_obj .clone();186 ObjectDecl * unused_index_obj = index_obj->clone(); 187 187 unused_index_obj->attributes.push_back( new Attribute( "unused" ) ); 188 188 189 catch_func_t .get_parameters().push_back( index_obj.clone());190 catch_func_t .get_parameters().push_back( exception_obj.clone() );191 match_func_t .get_returnVals().push_back( unused_index_obj );192 match_func_t .get_parameters().push_back( exception_obj.clone() );193 handle_func_t .get_returnVals().push_back( bool_obj.clone());194 handle_func_t .get_parameters().push_back( exception_obj.clone());195 finally_func_t .get_parameters().push_back( voidptr_obj.clone());189 catch_func_t->get_parameters().push_back( index_obj ); 190 catch_func_t->get_parameters().push_back( exception_obj->clone() ); 191 match_func_t->get_returnVals().push_back( unused_index_obj ); 192 match_func_t->get_parameters().push_back( exception_obj->clone() ); 193 handle_func_t->get_returnVals().push_back( bool_obj ); 194 handle_func_t->get_parameters().push_back( exception_obj ); 195 finally_func_t->get_parameters().push_back( voidptr_obj ); 196 196 } 197 197 … … 204 204 call->get_args().push_back( throwStmt->get_expr() ); 205 205 throwStmt->set_expr( nullptr ); 206 delete throwStmt;207 206 return new ExprStmt( call ); 208 207 } … … 234 233 new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) ) 235 234 ) ); 236 delete throwStmt;237 235 return result; 238 236 } … … 251 249 ); 252 250 result->labels = throwStmt->labels; 253 delete throwStmt;254 251 return result; 255 252 } … … 267 264 268 265 return new FunctionDecl( "try", Type::StorageClasses(), 269 LinkageSpec::Cforall, try_func_t .clone(), body );266 LinkageSpec::Cforall, try_func_t->clone(), body ); 270 267 } 271 268 … … 274 271 std::list<CaseStmt *> handler_wrappers; 275 272 276 FunctionType *func_type = catch_func_t .clone();273 FunctionType *func_type = catch_func_t->clone(); 277 274 DeclarationWithType * index_obj = func_type->get_parameters().front(); 278 275 DeclarationWithType * except_obj = func_type->get_parameters().back(); … … 384 381 modded_handler->set_cond( nullptr ); 385 382 modded_handler->set_body( nullptr ); 386 delete modded_handler;387 383 return block; 388 384 } … … 396 392 CompoundStmt * body = new CompoundStmt(); 397 393 398 FunctionType * func_type = match_func_t .clone();394 FunctionType * func_type = match_func_t->clone(); 399 395 DeclarationWithType * except_obj = func_type->get_parameters().back(); 400 396 … … 450 446 CompoundStmt * body = new CompoundStmt(); 451 447 452 FunctionType * func_type = handle_func_t .clone();448 FunctionType * func_type = handle_func_t->clone(); 453 449 DeclarationWithType * except_obj = func_type->get_parameters().back(); 454 450 … … 530 526 CompoundStmt * body = finally->get_block(); 531 527 finally->set_block( nullptr ); 532 delete finally;533 528 tryStmt->set_finally( nullptr ); 534 529 535 530 return new FunctionDecl("finally", Type::StorageClasses(), 536 LinkageSpec::Cforall, finally_func_t .clone(), body);531 LinkageSpec::Cforall, finally_func_t->clone(), body); 537 532 } 538 533 -
src/ControlStruct/MLEMutator.cc
r63238a4 r28f3a19 226 226 227 227 // transform break/continue statements into goto to simplify later handling of branches 228 delete branchStmt;229 228 return new BranchStmt( exitLabel, BranchStmt::Goto ); 230 229 } -
src/GenPoly/Box.cc
r63238a4 r28f3a19 281 281 /// Adds parameters for otype layout to a function type 282 282 void addOtypeParams( FunctionType *layoutFnType, std::list< TypeDecl* > &otypeParams ) { 283 BasicType sizeAlignType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 284 285 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); param != otypeParams.end(); ++param ) { 286 TypeInstType paramType( Type::Qualifiers(), (*param)->get_name(), *param ); 287 std::string paramName = mangleType( ¶mType ); 288 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 289 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType.clone(), 0 ) ); 283 auto sizeAlignType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 284 285 for ( std::list< TypeDecl* >::const_iterator param = otypeParams.begin(); 286 param != otypeParams.end(); ++param ) { 287 auto paramType = new TypeInstType( Type::Qualifiers(), (*param)->get_name(), *param ); 288 std::string paramName = mangleType( paramType ); 289 layoutFnType->get_parameters().push_back( new ObjectDecl( sizeofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) ); 290 layoutFnType->get_parameters().push_back( new ObjectDecl( alignofName( paramName ), Type::StorageClasses(), LinkageSpec::Cforall, 0, sizeAlignType->clone(), 0 ) ); 290 291 } 291 292 } … … 742 743 Type * newType = param->clone(); 743 744 if ( env ) env->apply( newType ); 744 ObjectDecl *newObj = ObjectDecl::newObject( tempNamer.newName(), newType, nullptr ); 745 ObjectDecl *newObj = ObjectDecl::newObject( 746 tempNamer.newName(), newType, nullptr ); 745 747 newObj->get_type()->get_qualifiers() = Type::Qualifiers(); // TODO: is this right??? 746 748 stmtsToAddBefore.push_back( new DeclStmt( newObj ) ); … … 862 864 // do not carry over attributes to real type parameters/return values 863 865 for ( DeclarationWithType * dwt : realType->parameters ) { 864 deleteAll( dwt->get_type()->attributes );865 866 dwt->get_type()->attributes.clear(); 866 867 } 867 868 for ( DeclarationWithType * dwt : realType->returnVals ) { 868 deleteAll( dwt->get_type()->attributes );869 869 dwt->get_type()->attributes.clear(); 870 870 } … … 987 987 } // if 988 988 appExpr->get_args().clear(); 989 delete appExpr;990 989 return addAssign; 991 990 } … … 1018 1017 } // if 1019 1018 if ( baseType1 || baseType2 ) { 1020 delete ret->get_result();1021 1019 ret->set_result( appExpr->get_result()->clone() ); 1022 1020 if ( appExpr->get_env() ) { … … 1025 1023 } // if 1026 1024 appExpr->get_args().clear(); 1027 delete appExpr;1028 1025 return ret; 1029 1026 } // if … … 1035 1032 Expression *ret = appExpr->get_args().front(); 1036 1033 // fix expr type to remove pointer 1037 delete ret->get_result();1038 1034 ret->set_result( appExpr->get_result()->clone() ); 1039 1035 if ( appExpr->get_env() ) { … … 1042 1038 } // if 1043 1039 appExpr->get_args().clear(); 1044 delete appExpr;1045 1040 return ret; 1046 1041 } // if … … 1182 1177 Expression *ret = expr->args.front(); 1183 1178 expr->args.clear(); 1184 delete expr;1185 1179 return ret; 1186 1180 } // if … … 1216 1210 if ( polytype || needs ) { 1217 1211 Expression *ret = addrExpr->arg; 1218 delete ret->result;1219 1212 ret->result = addrExpr->result->clone(); 1220 1213 addrExpr->arg = nullptr; 1221 delete addrExpr;1222 1214 return ret; 1223 1215 } else { … … 1229 1221 if ( retval && returnStmt->expr ) { 1230 1222 assert( returnStmt->expr->result && ! returnStmt->expr->result->isVoid() ); 1231 delete returnStmt->expr;1232 1223 returnStmt->expr = nullptr; 1233 1224 } // if … … 1272 1263 } 1273 1264 } 1274 // deleteAll( functions );1275 1265 } 1276 1266 … … 1292 1282 for ( Declaration * param : functionDecl->type->parameters ) { 1293 1283 if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( param ) ) { 1294 delete obj->init;1295 1284 obj->init = nullptr; 1296 1285 } … … 1340 1329 std::list< DeclarationWithType *> inferredParams; 1341 1330 // size/align/offset parameters may not be used in body, pass along with unused attribute. 1342 ObjectDecl newObj( "", Type::StorageClasses(), LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, 1343 { new Attribute( "unused" ) } ); 1344 ObjectDecl newPtr( "", Type::StorageClasses(), LinkageSpec::C, 0, 1345 new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); 1346 for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { 1331 auto newObj = new ObjectDecl( 1332 "", Type::StorageClasses(), LinkageSpec::C, 0, 1333 new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, 1334 { new Attribute( "unused" ) } ); 1335 auto newPtr = new ObjectDecl( 1336 "", Type::StorageClasses(), LinkageSpec::C, 0, 1337 new PointerType( Type::Qualifiers(), 1338 new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ), 0 ); 1339 for ( Type::ForallList::const_iterator tyParm = funcType->get_forall().begin(); 1340 tyParm != funcType->get_forall().end(); ++tyParm ) { 1347 1341 ObjectDecl *sizeParm, *alignParm; 1348 1342 // add all size and alignment parameters to parameter list 1349 1343 if ( (*tyParm)->isComplete() ) { 1350 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1351 std::string parmName = mangleType( &parmType ); 1352 1353 sizeParm = newObj.clone(); 1344 auto parmType = new TypeInstType( 1345 Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1346 std::string parmName = mangleType( parmType ); 1347 1348 sizeParm = newObj->clone(); 1354 1349 sizeParm->set_name( sizeofName( parmName ) ); 1355 1350 last = funcType->get_parameters().insert( last, sizeParm ); 1356 1351 ++last; 1357 1352 1358 alignParm = newObj .clone();1353 alignParm = newObj->clone(); 1359 1354 alignParm->set_name( alignofName( parmName ) ); 1360 1355 last = funcType->get_parameters().insert( last, alignParm ); … … 1379 1374 1380 1375 ObjectDecl *sizeParm, *alignParm, *offsetParm; 1381 sizeParm = newObj .clone();1376 sizeParm = newObj->clone(); 1382 1377 sizeParm->set_name( sizeofName( typeName ) ); 1383 1378 last = funcType->get_parameters().insert( last, sizeParm ); 1384 1379 ++last; 1385 1380 1386 alignParm = newObj .clone();1381 alignParm = newObj->clone(); 1387 1382 alignParm->set_name( alignofName( typeName ) ); 1388 1383 last = funcType->get_parameters().insert( last, alignParm ); … … 1392 1387 // NOTE zero-length arrays are illegal in C, so empty structs have no offset array 1393 1388 if ( ! polyBaseStruct->get_baseStruct()->get_members().empty() ) { 1394 offsetParm = newPtr .clone();1389 offsetParm = newPtr->clone(); 1395 1390 offsetParm->set_name( offsetofName( typeName ) ); 1396 1391 last = funcType->get_parameters().insert( last, offsetParm ); … … 1443 1438 if ( Type * base = typeDecl->base ) { 1444 1439 // add size/align variables for opaque type declarations 1445 TypeInstType inst( Type::Qualifiers(), typeDecl->name, typeDecl );1446 std::string typeName = mangleType( &inst );1440 auto inst = new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ); 1441 std::string typeName = mangleType( inst ); 1447 1442 Type *layoutType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 1448 1443 … … 1501 1496 // polymorphic aggregate members should be converted into monomorphic members. 1502 1497 // Using char[size_T] here respects the expected sizing rules of an aggregate type. 1503 Type * newType = polyToMonoType( field->type ); 1504 delete field->type; 1505 field->type = newType; 1498 field->type = polyToMonoType( field->type ); 1506 1499 } 1507 1500 } … … 1526 1519 stmtsToAddBefore.push_back( new DeclStmt( newBuf ) ); 1527 1520 1528 delete objectDecl->get_init();1529 1521 objectDecl->set_init( new SingleInit( new VariableExpr( newBuf ) ) ); 1530 1522 } … … 1605 1597 } 1606 1598 1607 delete memberType;1608 delete memberExpr;1609 1599 return newMemberExpr; 1610 1600 } … … 1626 1616 addrExpr->arg = nullptr; 1627 1617 std::swap( addrExpr->env, ret->env ); 1628 delete addrExpr;1629 1618 return ret; 1630 1619 } … … 1635 1624 1636 1625 ObjectDecl *PolyGenericCalculator::makeVar( const std::string &name, Type *type, Initializer *init ) { 1637 ObjectDecl *newObj = new ObjectDecl( name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init ); 1626 ObjectDecl *newObj = new ObjectDecl( 1627 name, Type::StorageClasses(), LinkageSpec::C, nullptr, type, init ); 1638 1628 stmtsToAddBefore.push_back( new DeclStmt( newObj ) ); 1639 1629 return newObj; … … 1768 1758 1769 1759 Expression * gen = genSizeof( ty ); 1770 if ( gen ) { 1771 delete sizeofExpr; 1772 return gen; 1773 } else return sizeofExpr; 1760 return gen ? gen : sizeofExpr; 1774 1761 } 1775 1762 … … 1777 1764 Type *ty = alignofExpr->get_isType() ? alignofExpr->get_type() : alignofExpr->get_expr()->get_result(); 1778 1765 if ( findGeneric( ty ) ) { 1779 Expression *ret = new NameExpr( alignofName( mangleType( ty ) ) ); 1780 delete alignofExpr; 1781 return ret; 1766 return new NameExpr( alignofName( mangleType( ty ) ) ); 1782 1767 } 1783 1768 return alignofExpr; … … 1794 1779 if ( i == -1 ) return offsetofExpr; 1795 1780 1796 Expression *offsetInd = makeOffsetIndex( ty, i ); 1797 delete offsetofExpr; 1798 return offsetInd; 1781 return makeOffsetIndex( ty, i ); 1799 1782 } else if ( dynamic_cast< UnionInstType* >( ty ) ) { 1800 1783 // all union members are at offset zero 1801 delete offsetofExpr;1802 1784 return new ConstantExpr( Constant::from_ulong( 0 ) ); 1803 1785 } else return offsetofExpr; … … 1839 1821 } 1840 1822 1841 delete offsetPackExpr;1842 1823 return ret; 1843 1824 } -
src/GenPoly/GenPoly.cc
r63238a4 r28f3a19 445 445 Type * newType = arg->clone(); 446 446 if ( env ) env->apply( newType ); 447 std::unique_ptr<Type> manager( newType );448 447 // if the argument's type is polymorphic, we don't need to box again! 449 448 return ! isPolyType( newType ); -
src/GenPoly/InstantiateGeneric.cc
r63238a4 r28f3a19 58 58 59 59 TypeList& operator= ( const TypeList &that ) { 60 deleteAll( params );61 62 60 params.clear(); 63 61 cloneAll( that.params, params ); … … 67 65 68 66 TypeList& operator= ( TypeList &&that ) { 69 deleteAll( params );70 71 67 params = std::move( that.params ); 72 68 … … 74 70 } 75 71 76 ~TypeList() { deleteAll( params );}72 ~TypeList() {} 77 73 78 74 bool operator== ( const TypeList& that ) const { … … 293 289 /// Strips the instances's type parameters 294 290 void stripInstParams( ReferenceToType *inst ) { 295 deleteAll( inst->get_parameters() );296 291 inst->get_parameters().clear(); 297 292 } … … 300 295 substituteMembers( base->get_members(), baseParams, typeSubs ); 301 296 302 // xxx - can't delete type parameters because they may have assertions that are used303 // deleteAll( baseParams );304 297 baseParams.clear(); 305 298 … … 380 373 newInst->set_baseStruct( concDecl ); 381 374 382 delete inst;383 375 inst = newInst; 384 376 break; … … 390 382 } 391 383 392 deleteAll( typeSubs );393 384 return inst; 394 385 } … … 430 421 newInst->set_baseUnion( concDecl ); 431 422 432 delete inst;433 423 inst = newInst; 434 424 break; … … 439 429 } 440 430 441 deleteAll( typeSubs );442 431 return inst; 443 432 } … … 477 466 ResolvExpr::adjustExprType( ret->result ); // pointer decay 478 467 std::swap( ret->env, memberExpr->env ); 479 delete memberExpr;480 468 return ret; 481 469 } -
src/GenPoly/Lvalue.cc
r63238a4 r28f3a19 51 51 assertf( base, "expected pointer type in dereference (type was %s)", toString( arg->result ).c_str() ); 52 52 ApplicationExpr * ret = new ApplicationExpr( deref, { arg } ); 53 delete ret->result;54 53 ret->result = base->clone(); 55 54 ret->result->set_lvalue( true ); … … 174 173 return ret; 175 174 } 176 delete result;177 175 } 178 176 return appExpr; … … 233 231 Type * baseType = InitTweak::getPointerBase( arg->result ); 234 232 assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg->result ).c_str() ); 235 PointerType * ptrType = new PointerType( Type::Qualifiers(), baseType->clone() ); 236 delete arg->result; 237 arg->result = ptrType; 233 arg->set_result( new PointerType( Type::Qualifiers(), baseType->clone() ) ); 238 234 arg = mkDeref( arg ); 239 235 // assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) ); … … 407 403 } 408 404 ret->env = castExpr->env; 409 delete ret->result;410 405 ret->result = castExpr->result; 411 406 castExpr->env = nullptr; 412 407 castExpr->arg = nullptr; 413 408 castExpr->result = nullptr; 414 delete castExpr;415 409 return ret; 416 410 } else if ( diff < 0 ) { … … 428 422 } 429 423 ret->env = castExpr->env; 430 delete ret->result;431 424 ret->result = castExpr->result; 432 425 ret->result->set_lvalue( true ); // ensure result is lvalue … … 434 427 castExpr->arg = nullptr; 435 428 castExpr->result = nullptr; 436 delete castExpr;437 429 return ret; 438 430 } else { … … 449 441 castExpr->arg = nullptr; 450 442 std::swap( castExpr->env, ret->env ); 451 delete castExpr;452 443 return ret; 453 444 } … … 460 451 Type::Qualifiers qualifiers = refType->get_qualifiers(); 461 452 refType->base = nullptr; 462 delete refType;463 453 return new PointerType( qualifiers, base ); 464 454 } … … 472 462 ret->env = expr->env; 473 463 expr->env = nullptr; 474 delete expr;475 464 return ret; 476 465 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) { … … 481 470 ret->env = expr->env; 482 471 expr->env = nullptr; 483 delete expr;484 472 485 473 // conditional expr type may not be either of the argument types, need to unify … … 514 502 arg0 = nullptr; 515 503 addrExpr->env = nullptr; 516 delete addrExpr;517 504 return ret; 518 505 } … … 544 531 addrExpr->arg = nullptr; 545 532 appExpr->env = nullptr; 546 delete appExpr;547 533 return ret; 548 534 } -
src/GenPoly/ScrubTyVars.cc
r63238a4 r28f3a19 28 28 if ( ! tyVars ) { 29 29 if ( typeInst->get_isFtype() ) { 30 delete typeInst; 31 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 30 return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) }; 32 31 } else { 33 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 34 delete typeInst; 35 return ret; 32 return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) }; 36 33 } 37 34 } … … 42 39 case TypeDecl::Dtype: 43 40 case TypeDecl::Ttype: 44 { 45 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) ); 46 delete typeInst; 47 return ret; 48 } 41 return new PointerType{ Type::Qualifiers(), new VoidType( typeInst->get_qualifiers() ) }; 49 42 case TypeDecl::Ftype: 50 delete typeInst; 51 return new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ); 43 return new PointerType{ Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) }; 52 44 } // switch 53 45 } // if … … 57 49 Type * ScrubTyVars::mutateAggregateType( Type * ty ) { 58 50 if ( shouldScrub( ty ) ) { 59 PointerType * ret = new PointerType( Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) ); 60 delete ty; 61 return ret; 51 return new PointerType{ Type::Qualifiers(), new VoidType( ty->get_qualifiers() ) }; 62 52 } 63 53 return ty; … … 104 94 Type * ret = dynType->acceptMutator( *visitor ); 105 95 ret->get_qualifiers() |= pointer->get_qualifiers(); 106 pointer->base = nullptr;107 delete pointer;108 96 return ret; 109 97 } -
src/GenPoly/Specialize.cc
r63238a4 r28f3a19 17 17 #include <iterator> // for back_insert_iterator, back_i... 18 18 #include <map> // for _Rb_tree_iterator, _Rb_tree_... 19 #include <memory> // for unique_ptr20 19 #include <string> // for string 21 20 #include <tuple> // for get … … 193 192 explodeSimple( new TupleIndexExpr( expr->clone(), i ), out ); 194 193 } 195 delete expr;196 194 } else { 197 195 // non-tuple type - output a clone of the expression … … 226 224 env->apply( actualType ); 227 225 } 228 std::unique_ptr< FunctionType > actualTypeManager( actualType ); // for RAII229 226 std::list< DeclarationWithType * >::iterator actualBegin = actualType->get_parameters().begin(); 230 227 std::list< DeclarationWithType * >::iterator actualEnd = actualType->get_parameters().end(); -
src/InitTweak/FixGlobalInit.cc
r63238a4 r28f3a19 57 57 GlobalFixer & fixer = visitor.pass; 58 58 // don't need to include function if it's empty 59 if ( fixer.initFunction->get_statements()->get_kids().empty() ) { 60 delete fixer.initFunction; 61 } else { 59 if ( ! fixer.initFunction->get_statements()->get_kids().empty() ) { 62 60 translationUnit.push_back( fixer.initFunction ); 63 61 } // if 64 62 65 if ( fixer.destroyFunction->get_statements()->get_kids().empty() ) { 66 delete fixer.destroyFunction; 67 } else { 63 if ( ! fixer.destroyFunction->get_statements()->get_kids().empty() ) { 68 64 translationUnit.push_back( fixer.destroyFunction ); 69 65 } // if … … 130 126 objDecl->set_init( NULL ); 131 127 } // if 132 delete ctorInit;133 128 } // if 134 129 } -
src/InitTweak/FixInit.cc
r63238a4 r28f3a19 454 454 resolved->env = nullptr; 455 455 } // if 456 delete stmt;457 456 if ( TupleAssignExpr * assign = dynamic_cast< TupleAssignExpr * >( resolved ) ) { 458 457 // fix newly generated StmtExpr … … 554 553 result = result->clone(); 555 554 env->apply( result ); 556 if ( ! InitTweak::isConstructable( result ) ) { 557 delete result; 558 return; 559 } 555 if ( ! InitTweak::isConstructable( result ) ) return; 560 556 561 557 // create variable that will hold the result of the stmt expr … … 652 648 std::swap( impCpCtorExpr->env, callExpr->env ); 653 649 assert( impCpCtorExpr->env == nullptr ); 654 delete impCpCtorExpr;655 650 656 651 if ( returnDecl ) { … … 711 706 if ( unqMap.count( unqExpr->get_id() ) ) { 712 707 // take data from other UniqueExpr to ensure consistency 713 delete unqExpr->get_expr();714 708 unqExpr->set_expr( unqMap[unqExpr->get_id()]->get_expr()->clone() ); 715 delete unqExpr->get_result();716 709 unqExpr->set_result( maybeClone( unqExpr->get_expr()->get_result() ) ); 717 710 if ( unqCount[ unqExpr->get_id() ] == 0 ) { // insert destructor after the last use of the unique expression … … 824 817 // create a new object which is never used 825 818 static UniqueName dummyNamer( "_dummy" ); 826 ObjectDecl * dummy = new ObjectDecl( dummyNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ), 0, std::list< Attribute * >{ new Attribute("unused") } ); 827 delete ctorInit; 828 return dummy; 819 return new ObjectDecl{ 820 dummyNamer.newName(), Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, 821 new PointerType{ Type::Qualifiers(), new VoidType( Type::Qualifiers() ) }, 822 0, std::list< Attribute * >{ new Attribute("unused") } }; 829 823 } 830 824 } else { … … 852 846 objDecl->init = nullptr; 853 847 } // if 854 delete ctorInit;855 848 } // if 856 849 return objDecl; … … 1228 1221 ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr ); 1229 1222 declsToAddBefore.push_back( tmp ); 1230 delete ctorExpr;1231 1223 1232 1224 // build assignment and replace constructor's first argument with new temporary … … 1237 1229 // resolve assignment and dispose of new env 1238 1230 ResolvExpr::findVoidExpression( assign, indexer ); 1239 delete assign->env;1240 1231 assign->env = nullptr; 1241 1232 -
src/InitTweak/GenInit.cc
r63238a4 r28f3a19 258 258 // generic parameters should not play a role in determining whether a generic type is constructed - construct all generic types, so that 259 259 // polymorphic constructors make generic types managed types 260 StructInstType inst( Type::Qualifiers(), aggregateDecl );261 managedTypes.insert( SymTab::Mangler::mangleConcrete( &inst ) );260 auto inst = new StructInstType( Type::Qualifiers(), aggregateDecl ); 261 managedTypes.insert( SymTab::Mangler::mangleConcrete( inst ) ); 262 262 break; 263 263 } -
src/InitTweak/InitTweak.cc
r63238a4 r28f3a19 5 5 #include <memory> // for __shared_ptr 6 6 7 #include "Common/GC.h" // for new_static_root 7 8 #include "Common/PassVisitor.h" 8 9 #include "Common/SemanticError.h" // for SemanticError … … 122 123 public: 123 124 ExprImpl( Expression * expr ) : arg( expr ) {} 124 virtual ~ExprImpl() { delete arg; }125 virtual ~ExprImpl() = default; 125 126 126 127 virtual std::list< Expression * > next( std::list< Expression * > & indices ) { … … 166 167 167 168 void InitExpander::clearArrayIndices() { 168 deleteAll( indices );169 169 indices.clear(); 170 170 } … … 263 263 build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) ); 264 264 if ( block->get_kids().empty() ) { 265 delete block;266 265 return nullptr; 267 266 } else { … … 525 524 // This operator could easily exist as a real function, but it's tricky because nothing should resolve to this function. 526 525 TypeDecl * td = new TypeDecl( "T", noStorageClasses, nullptr, TypeDecl::Dtype, true ); 527 assign = new FunctionDecl( "?=?", noStorageClasses, LinkageSpec::Intrinsic, SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr ); 526 assign = new_static_root<FunctionDecl>( 527 "?=?", noStorageClasses, LinkageSpec::Intrinsic, 528 SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr ); 528 529 } 529 530 if ( dynamic_cast< ReferenceType * >( dst->result ) ) { -
src/MakeLibCfa.cc
r63238a4 r28f3a19 65 65 struct ZeroOneReplacer { 66 66 ZeroOneReplacer( Type * t ) : type( t ) {} 67 ~ZeroOneReplacer() { delete type; }68 67 Type * type = nullptr; 69 68 70 69 Type * common( Type * t ) { 71 70 if ( ! type ) return t; 72 delete t;73 71 return type->clone(); 74 72 } -
src/Makefile.in
r63238a4 r28f3a19 163 163 Common/driver_cfa_cpp-UniqueName.$(OBJEXT) \ 164 164 Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT) \ 165 Common/driver_cfa_cpp-GC.$(OBJEXT) \ 165 166 Common/driver_cfa_cpp-Assert.$(OBJEXT) \ 166 167 Common/driver_cfa_cpp-Heap.$(OBJEXT) \ … … 250 251 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \ 251 252 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \ 253 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT) \ 252 254 SynTree/driver_cfa_cpp-DeclReplacer.$(OBJEXT) \ 253 255 Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT) \ … … 486 488 CodeTools/TrackLoc.cc Concurrency/Keywords.cc \ 487 489 Concurrency/Waitfor.cc Common/SemanticError.cc \ 488 Common/UniqueName.cc Common/DebugMalloc.cc Common/Assert.cc \ 489 Common/Heap.cc ControlStruct/LabelGenerator.cc \ 490 ControlStruct/LabelFixer.cc ControlStruct/MLEMutator.cc \ 491 ControlStruct/Mutate.cc ControlStruct/ForExprMutator.cc \ 490 Common/UniqueName.cc Common/DebugMalloc.cc Common/GC.cc \ 491 Common/Assert.cc Common/Heap.cc \ 492 ControlStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \ 493 ControlStruct/MLEMutator.cc ControlStruct/Mutate.cc \ 494 ControlStruct/ForExprMutator.cc \ 492 495 ControlStruct/ExceptTranslate.cc GenPoly/Box.cc \ 493 496 GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc \ … … 527 530 SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \ 528 531 SynTree/Initializer.cc SynTree/TypeSubstitution.cc \ 529 SynTree/Attribute.cc SynTree/DeclReplacer.cc \ 530 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 531 Tuples/Explode.cc Virtual/ExpandCasts.cc 532 SynTree/Attribute.cc SynTree/BaseSyntaxNode.cc \ 533 SynTree/DeclReplacer.cc Tuples/TupleAssignment.cc \ 534 Tuples/TupleExpansion.cc Tuples/Explode.cc \ 535 Virtual/ExpandCasts.cc 532 536 MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \ 533 537 ${cfa_cpplib_PROGRAMS}} … … 671 675 Common/$(DEPDIR)/$(am__dirstamp) 672 676 Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT): Common/$(am__dirstamp) \ 677 Common/$(DEPDIR)/$(am__dirstamp) 678 Common/driver_cfa_cpp-GC.$(OBJEXT): Common/$(am__dirstamp) \ 673 679 Common/$(DEPDIR)/$(am__dirstamp) 674 680 Common/driver_cfa_cpp-Assert.$(OBJEXT): Common/$(am__dirstamp) \ … … 915 921 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \ 916 922 SynTree/$(DEPDIR)/$(am__dirstamp) 923 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT): \ 924 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) 917 925 SynTree/driver_cfa_cpp-DeclReplacer.$(OBJEXT): \ 918 926 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) … … 976 984 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Assert.Po@am__quote@ 977 985 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-DebugMalloc.Po@am__quote@ 986 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-GC.Po@am__quote@ 978 987 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Heap.Po@am__quote@ 979 988 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-SemanticError.Po@am__quote@ … … 1039 1048 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@ 1040 1049 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@ 1050 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po@am__quote@ 1041 1051 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@ 1042 1052 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@ … … 1298 1308 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Common/driver_cfa_cpp-DebugMalloc.obj `if test -f 'Common/DebugMalloc.cc'; then $(CYGPATH_W) 'Common/DebugMalloc.cc'; else $(CYGPATH_W) '$(srcdir)/Common/DebugMalloc.cc'; fi` 1299 1309 1310 Common/driver_cfa_cpp-GC.o: Common/GC.cc 1311 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Common/driver_cfa_cpp-GC.o -MD -MP -MF Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo -c -o Common/driver_cfa_cpp-GC.o `test -f 'Common/GC.cc' || echo '$(srcdir)/'`Common/GC.cc 1312 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo Common/$(DEPDIR)/driver_cfa_cpp-GC.Po 1313 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='Common/GC.cc' object='Common/driver_cfa_cpp-GC.o' libtool=no @AMDEPBACKSLASH@ 1314 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1315 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Common/driver_cfa_cpp-GC.o `test -f 'Common/GC.cc' || echo '$(srcdir)/'`Common/GC.cc 1316 1317 Common/driver_cfa_cpp-GC.obj: Common/GC.cc 1318 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Common/driver_cfa_cpp-GC.obj -MD -MP -MF Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo -c -o Common/driver_cfa_cpp-GC.obj `if test -f 'Common/GC.cc'; then $(CYGPATH_W) 'Common/GC.cc'; else $(CYGPATH_W) '$(srcdir)/Common/GC.cc'; fi` 1319 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo Common/$(DEPDIR)/driver_cfa_cpp-GC.Po 1320 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='Common/GC.cc' object='Common/driver_cfa_cpp-GC.obj' libtool=no @AMDEPBACKSLASH@ 1321 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1322 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o Common/driver_cfa_cpp-GC.obj `if test -f 'Common/GC.cc'; then $(CYGPATH_W) 'Common/GC.cc'; else $(CYGPATH_W) '$(srcdir)/Common/GC.cc'; fi` 1323 1300 1324 Common/driver_cfa_cpp-Assert.o: Common/Assert.cc 1301 1325 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT Common/driver_cfa_cpp-Assert.o -MD -MP -MF Common/$(DEPDIR)/driver_cfa_cpp-Assert.Tpo -c -o Common/driver_cfa_cpp-Assert.o `test -f 'Common/Assert.cc' || echo '$(srcdir)/'`Common/Assert.cc … … 2515 2539 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2516 2540 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi` 2541 2542 SynTree/driver_cfa_cpp-BaseSyntaxNode.o: SynTree/BaseSyntaxNode.cc 2543 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc 2544 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po 2545 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.o' libtool=no @AMDEPBACKSLASH@ 2546 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2547 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.o `test -f 'SynTree/BaseSyntaxNode.cc' || echo '$(srcdir)/'`SynTree/BaseSyntaxNode.cc 2548 2549 SynTree/driver_cfa_cpp-BaseSyntaxNode.obj: SynTree/BaseSyntaxNode.cc 2550 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-BaseSyntaxNode.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi` 2551 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po 2552 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.obj' libtool=no @AMDEPBACKSLASH@ 2553 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2554 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-BaseSyntaxNode.obj `if test -f 'SynTree/BaseSyntaxNode.cc'; then $(CYGPATH_W) 'SynTree/BaseSyntaxNode.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/BaseSyntaxNode.cc'; fi` 2517 2555 2518 2556 SynTree/driver_cfa_cpp-DeclReplacer.o: SynTree/DeclReplacer.cc -
src/Parser/DeclarationNode.cc
r63238a4 r28f3a19 94 94 95 95 delete assert.condition; 96 delete assert.message;97 96 } 98 97 … … 1002 1001 obj->location = cur->location; 1003 1002 * out++ = obj; 1004 delete agg;1005 1003 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 1006 1004 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); -
src/Parser/ExpressionNode.cc
r63238a4 r28f3a19 408 408 Type * targetType = maybeMoveBuildType( decl_node ); 409 409 if ( dynamic_cast< VoidType * >( targetType ) ) { 410 delete targetType;411 410 return new CastExpr( maybeMoveBuild< Expression >(expr_node), false ); 412 411 } else { … … 436 435 437 436 Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) { 438 Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() ); 439 delete member; 440 return ret; 437 return new UntypedOffsetofExpr{ maybeMoveBuildType( decl_node ), member->get_name() }; 441 438 } // build_offsetOf 442 439 -
src/Parser/ParseNode.h
r63238a4 r28f3a19 128 128 129 129 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 130 os << expr .get()<< std::endl;130 os << expr << std::endl; 131 131 } 132 132 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 133 133 134 134 template<typename T> 135 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr .get()); }136 137 Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }135 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr); } 136 137 Expression * build() const { return expr; } 138 138 private: 139 139 bool extension = false; 140 std::unique_ptr<Expression>expr;140 Expression* expr; 141 141 }; // ExpressionNode 142 142 … … 364 364 365 365 virtual StatementNode * clone() const final { assert( false ); return nullptr; } 366 Statement * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }366 Statement * build() const { return stmt; } 367 367 368 368 virtual StatementNode * add_label( const std::string * name, DeclarationNode * attr = nullptr ) { … … 376 376 377 377 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 378 os << stmt .get()<< std::endl;378 os << stmt << std::endl; 379 379 } 380 380 private: 381 std::unique_ptr<Statement>stmt;381 Statement* stmt; 382 382 }; // StatementNode 383 383 -
src/Parser/StatementNode.cc
r63238a4 r28f3a19 50 50 agg = decl; 51 51 } // if 52 stmt .reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );52 stmt = new DeclStmt{ maybeMoveBuild< Declaration >(agg) }; 53 53 } // StatementNode::StatementNode 54 54 … … 58 58 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 59 59 StatementNode * node = strict_dynamic_cast< StatementNode * >(curr); 60 assert( dynamic_cast< CaseStmt * >(node->stmt .get()) );60 assert( dynamic_cast< CaseStmt * >(node->stmt) ); 61 61 prev = curr; 62 62 } // for … … 66 66 buildMoveList( stmt, stmts ); 67 67 // splice any new Statements to end of current Statements 68 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt .get());68 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt); 69 69 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 70 70 return this; -
src/ResolvExpr/AdjustExprType.cc
r63238a4 r28f3a19 66 66 67 67 Type * AdjustExprType::postmutate( ArrayType * arrayType ) { 68 PointerType *pointerType = new PointerType{ arrayType->get_qualifiers(), arrayType->base }; 69 arrayType->base = nullptr; 70 delete arrayType; 71 return pointerType; 68 return new PointerType{ arrayType->get_qualifiers(), arrayType->base }; 72 69 } 73 70 -
src/ResolvExpr/Alternative.cc
r63238a4 r28f3a19 20 20 #include <utility> // for move 21 21 22 #include "Common/GC.h" 23 #include "Common/PassVisitor.h" 22 24 #include "Common/utility.h" // for maybeClone 23 25 #include "ResolvExpr/Cost.h" // for Cost, Cost::zero, operator<< 24 26 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 25 27 #include "SynTree/Expression.h" // for Expression 28 #include "SynTree/GcTracer.h" 26 29 #include "SynTree/Type.h" // for Type 27 30 … … 34 37 Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost, const Cost &cvtCost ) 35 38 : cost( cost ), cvtCost( cvtCost ), expr( expr ), env( env ) {} 36 37 Alternative::Alternative( const Alternative &other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( maybeClone( other.expr ) ), env( other.env ) { 38 } 39 40 Alternative &Alternative::operator=( const Alternative &other ) { 41 if ( &other == this ) return *this; 42 delete expr; 43 cost = other.cost; 44 cvtCost = other.cvtCost; 45 expr = maybeClone( other.expr ); 46 env = other.env; 39 40 Alternative::Alternative( const Alternative& o ) 41 : cost( o.cost ), cvtCost( o.cvtCost ), expr( maybeClone( o.expr ) ), env( o.env ) {} 42 43 Alternative & Alternative::operator= ( const Alternative& o ) { 44 if ( &o == this ) return *this; 45 cost = o.cost; 46 cvtCost = o.cvtCost; 47 expr = maybeClone( o.expr ); 48 env = o.env; 47 49 return *this; 48 }49 50 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( std::move( other.env ) ) {51 other.expr = nullptr;52 }53 54 Alternative & Alternative::operator=( Alternative && other ) {55 if ( &other == this ) return *this;56 delete expr;57 cost = other.cost;58 cvtCost = other.cvtCost;59 expr = other.expr;60 env = std::move( other.env );61 other.expr = nullptr;62 return *this;63 }64 65 Alternative::~Alternative() {66 delete expr;67 50 } 68 51 … … 96 79 } 97 80 81 const GC& operator<< ( const GC& gc, const Alternative& alt ) { 82 PassVisitor<GcTracer> tracer{ gc }; 83 maybeAccept( alt.expr, tracer ); 84 tracer << alt.env; 85 return gc; 86 } 87 98 88 } // namespace ResolvExpr 99 89 -
src/ResolvExpr/Alternative.h
r63238a4 r28f3a19 24 24 class Expression; 25 25 26 class GC; 27 26 28 namespace ResolvExpr { 27 29 struct Alternative { … … 30 32 Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost, const Cost &cvtCost ); 31 33 Alternative( const Alternative &other ); 32 Alternative &operator=( const Alternative &other ); 33 Alternative( Alternative && other ); 34 Alternative &operator=( Alternative && other ); 35 ~Alternative(); 34 Alternative & operator= ( const Alternative &other ); 35 Alternative( Alternative&& other ) = default; 36 Alternative & operator= ( Alternative&& other ) = default; 36 37 37 38 void print( std::ostream &os, Indenter indent = {} ) const; 38 39 39 /// Returns the stored expression, but released from management of this Alternative40 Expression* release_expr() {41 Expression* tmp = expr;42 expr = nullptr;43 return tmp;44 }45 46 40 Cost cost; 47 41 Cost cvtCost; 48 Expression * expr;42 Expression * expr; 49 43 TypeEnvironment env; 50 44 }; … … 62 56 return os; 63 57 } 58 59 const GC& operator<< ( const GC&, const Alternative& ); 64 60 } // namespace ResolvExpr 65 61 -
src/ResolvExpr/AlternativeFinder.cc
r63238a4 r28f3a19 21 21 #include <list> // for _List_iterator, list, _List_const_... 22 22 #include <map> // for _Rb_tree_iterator, map, _Rb_tree_c... 23 #include <memory> // for allocator_traits<>::value_type , unique_ptr23 #include <memory> // for allocator_traits<>::value_type 24 24 #include <utility> // for pair 25 25 #include <vector> // for vector … … 35 35 #include "ResolveTypeof.h" // for resolveTypeof 36 36 #include "Resolver.h" // for resolveStmtExpr 37 #include "Common/GC.h" // for new_static_root 37 38 #include "SymTab/Indexer.h" // for Indexer 38 39 #include "SymTab/Mangler.h" // for Mangler … … 166 167 candidate->env.apply( newType ); 167 168 mangleName = SymTab::Mangler::mangle( newType ); 168 delete newType;169 169 } 170 170 std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName ); … … 308 308 // adds anonymous member interpretations whenever an aggregate value type is seen. 309 309 // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value 310 std::unique_ptr<Expression> aggrExpr( alt.expr->clone());310 Expression* aggrExpr = alt.expr->clone(); 311 311 alt.env.apply( aggrExpr->result ); 312 312 Type * aggrType = aggrExpr->result; 313 313 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 314 314 aggrType = aggrType->stripReferences(); 315 aggrExpr .reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );315 aggrExpr = new CastExpr{ aggrExpr, aggrType->clone() }; 316 316 } 317 317 318 318 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->result ) ) { 319 addAggMembers( structInst, aggrExpr .get(), alt.cost+Cost::safe, alt.env, "" );319 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 320 320 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->result ) ) { 321 addAggMembers( unionInst, aggrExpr .get(), alt.cost+Cost::safe, alt.env, "" );321 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 322 322 } // if 323 323 } … … 354 354 355 355 void AlternativeFinder::Finder::postvisit( ApplicationExpr *applicationExpr ) { 356 alternatives.push_back( Alternative( applicationExpr ->clone(), env, Cost::zero ) );356 alternatives.push_back( Alternative( applicationExpr, env, Cost::zero ) ); 357 357 } 358 358 … … 560 560 561 561 Expression *varExpr = data.combine( newerAlt.cvtCost ); 562 delete varExpr->get_result();563 562 varExpr->set_result( adjType->clone() ); 564 563 PRINT( … … 574 573 inferParameters = (*inferParameters)[ id ].inferParams.get(); 575 574 } 576 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions577 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType ->clone(), curDecl->get_type()->clone(), varExpr );575 576 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType, curDecl->get_type(), varExpr ); 578 577 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out ); 579 } else {580 delete adjType;581 578 } 582 579 } … … 627 624 struct ArgPack { 628 625 std::size_t parent; ///< Index of parent pack 629 std::unique_ptr<Expression> expr;///< The argument stored here626 Expression* expr; ///< The argument stored here 630 627 Cost cost; ///< The cost of this argument 631 628 TypeEnvironment env; ///< Environment for this pack … … 639 636 640 637 ArgPack() 641 : parent(0), expr( ), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0),642 tupleStart(0), nextExpl(0), explAlt(0) {}638 : parent(0), expr(nullptr), cost(Cost::zero), env(), need(), have(), openVars(), 639 nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {} 643 640 644 641 ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have, 645 642 const OpenVarSet& openVars) 646 : parent(0), expr( ), cost(Cost::zero), env(env), need(need), have(have),643 : parent(0), expr(nullptr), cost(Cost::zero), env(env), need(need), have(have), 647 644 openVars(openVars), nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {} 648 645 … … 651 648 unsigned tupleStart = 0, Cost cost = Cost::zero, unsigned nextExpl = 0, 652 649 unsigned explAlt = 0 ) 653 : parent(parent), expr(expr ->clone()), cost(cost), env(move(env)), need(move(need)),650 : parent(parent), expr(expr), cost(cost), env(move(env)), need(move(need)), 654 651 have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart), 655 652 nextExpl(nextExpl), explAlt(explAlt) {} … … 657 654 ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have, 658 655 OpenVarSet&& openVars, unsigned nextArg, Cost added ) 659 : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added),660 env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)),661 nextArg(nextArg),tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {}656 : parent(o.parent), expr(o.expr), cost(o.cost + added), env(move(env)), 657 need(move(need)), have(move(have)), openVars(move(openVars)), nextArg(nextArg), 658 tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {} 662 659 663 660 /// true iff this pack is in the middle of an exploded argument … … 674 671 std::list<Expression*> exprs; 675 672 const ArgPack* pack = this; 676 if ( expr ) { exprs.push_front( expr .release()); }673 if ( expr ) { exprs.push_front( expr ); } 677 674 while ( pack->tupleStart == 0 ) { 678 675 pack = &packs[pack->parent]; 679 exprs.push_front( pack->expr ->clone());676 exprs.push_front( pack->expr ); 680 677 cost += pack->cost; 681 678 } 682 679 // reset pack to appropriate tuple 683 expr .reset( new TupleExpr( exprs ) );680 expr = new TupleExpr{ exprs }; 684 681 tupleStart = pack->tupleStart - 1; 685 682 parent = pack->parent; … … 734 731 735 732 results.emplace_back( 736 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),733 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 737 734 copy(results[i].need), copy(results[i].have), 738 735 copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl, … … 755 752 newResult.parent = i; 756 753 std::list<Expression*> emptyList; 757 newResult.expr .reset( new TupleExpr( emptyList ) );754 newResult.expr = new TupleExpr{ emptyList }; 758 755 argType = newResult.expr->get_result(); 759 756 } else { … … 762 759 newResult.cost = results[i].cost; 763 760 newResult.tupleStart = results[i].tupleStart; 764 newResult.expr .reset( results[i].expr->clone() );761 newResult.expr = results[i].expr; 765 762 argType = newResult.expr->get_result(); 766 763 … … 812 809 // add new result 813 810 results.emplace_back( 814 i, expl.exprs.front() .get(), move(env), copy(results[i].need),811 i, expl.exprs.front(), move(env), copy(results[i].need), 815 812 copy(results[i].have), move(openVars), nextArg + 1, 816 813 nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 838 835 if ( results[i].hasExpl() ) { 839 836 const ExplodedActual& expl = results[i].getExpl( args ); 840 Expression* expr = expl.exprs[results[i].nextExpl] .get();837 Expression* expr = expl.exprs[results[i].nextExpl]; 841 838 842 839 TypeEnvironment env = results[i].env; … … 909 906 910 907 // consider only first exploded actual 911 Expression* expr = expl.exprs.front() .get();908 Expression* expr = expl.exprs.front(); 912 909 Type* actualType = expr->result->clone(); 913 910 … … 937 934 938 935 template<typename OutputIterator> 939 void AlternativeFinder::Finder::validateFunctionAlternative( const Alternative &func, ArgPack& result,940 const std::vector<ArgPack>& results, OutputIterator out ) {941 ApplicationExpr *appExpr = new ApplicationExpr( func.expr ->clone());936 void AlternativeFinder::Finder::validateFunctionAlternative( const Alternative &func, 937 ArgPack& result, const std::vector<ArgPack>& results, OutputIterator out ) { 938 ApplicationExpr *appExpr = new ApplicationExpr( func.expr ); 942 939 // sum cost and accumulate actuals 943 940 std::list<Expression*>& args = appExpr->args; … … 945 942 const ArgPack* pack = &result; 946 943 while ( pack->expr ) { 947 args.push_front( pack->expr ->clone());944 args.push_front( pack->expr ); 948 945 cost += pack->cost; 949 946 pack = &results[pack->parent]; … … 1012 1009 1013 1010 results.emplace_back( 1014 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),1011 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 1015 1012 copy(results[i].need), copy(results[i].have), 1016 1013 copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl, … … 1048 1045 // add new result 1049 1046 results.emplace_back( 1050 i, expl.exprs.front() .get(), move(env), copy(results[i].need),1047 i, expl.exprs.front(), move(env), copy(results[i].need), 1051 1048 copy(results[i].have), move(openVars), nextArg + 1, 0, 1052 1049 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 1083 1080 1084 1081 // find function operators 1085 static NameExpr *opExpr = new NameExpr( "?()" );1082 static auto *opExpr = new_static_root<NameExpr>( "?()" ); 1086 1083 AlternativeFinder funcOpFinder( indexer, env ); 1087 1084 // it's ok if there aren't any defined function ops … … 1115 1112 ) 1116 1113 // check if the type is pointer to function 1117 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr-> result->stripReferences() ) ) {1118 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer-> base) ) {1114 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) { 1115 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 1119 1116 Alternative newFunc( *func ); 1120 1117 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1152 1149 // check if type is a pointer to function 1153 1150 if ( PointerType* pointer = dynamic_cast<PointerType*>( 1154 funcOp->expr-> result->stripReferences() ) ) {1151 funcOp->expr->get_result()->stripReferences() ) ) { 1155 1152 if ( FunctionType* function = 1156 dynamic_cast<FunctionType*>( pointer-> base) ) {1153 dynamic_cast<FunctionType*>( pointer->get_base() ) ) { 1157 1154 Alternative newFunc( *funcOp ); 1158 1155 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1176 1173 PRINT( 1177 1174 ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr ); 1178 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr-> function->result);1179 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer-> base);1180 std::cerr << "Case +++++++++++++ " << appExpr-> function<< std::endl;1175 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() ); 1176 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() ); 1177 std::cerr << "Case +++++++++++++ " << appExpr->get_function() << std::endl; 1181 1178 std::cerr << "formals are:" << std::endl; 1182 printAll( function-> parameters, std::cerr, 8 );1179 printAll( function->get_parameters(), std::cerr, 8 ); 1183 1180 std::cerr << "actuals are:" << std::endl; 1184 printAll( appExpr-> args, std::cerr, 8 );1181 printAll( appExpr->get_args(), std::cerr, 8 ); 1185 1182 std::cerr << "bindings are:" << std::endl; 1186 1183 withFunc.env.print( std::cerr, 8 ); … … 1223 1220 bool isLvalue( Expression *expr ) { 1224 1221 // xxx - recurse into tuples? 1225 return expr->result && ( expr-> result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result) );1222 return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) ); 1226 1223 } 1227 1224 … … 1232 1229 if ( isLvalue( alt.expr ) ) { 1233 1230 alternatives.push_back( 1234 Alternative{ new AddressExpr( alt.expr ->clone()), alt.env, alt.cost } );1231 Alternative{ new AddressExpr( alt.expr ), alt.env, alt.cost } ); 1235 1232 } // if 1236 1233 } // for … … 1238 1235 1239 1236 void AlternativeFinder::Finder::postvisit( LabelAddressExpr * expr ) { 1240 alternatives.push_back( Alternative{ expr ->clone(), env, Cost::zero } );1237 alternatives.push_back( Alternative{ expr, env, Cost::zero } ); 1241 1238 } 1242 1239 … … 1258 1255 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 1259 1256 } 1260 delete argExpr;1261 1257 assert( componentExprs.size() > 0 ); 1262 1258 // produce the tuple of casts … … 1334 1330 for ( Alternative & alt : finder.alternatives ) { 1335 1331 alternatives.push_back( Alternative( 1336 new VirtualCastExpr( alt.expr ->clone(), castExpr->get_result()->clone() ),1332 new VirtualCastExpr( alt.expr, castExpr->get_result()->clone() ), 1337 1333 alt.env, alt.cost ) ); 1338 1334 } … … 1356 1352 Expression * aggrExpr = agg->expr->clone(); 1357 1353 referenceToRvalueConversion( aggrExpr, cost ); 1358 std::unique_ptr<Expression> guard( aggrExpr );1359 1354 1360 1355 // find member of the given type … … 1370 1365 1371 1366 void AlternativeFinder::Finder::postvisit( MemberExpr *memberExpr ) { 1372 alternatives.push_back( Alternative( memberExpr ->clone(), env, Cost::zero ) );1367 alternatives.push_back( Alternative( memberExpr, env, Cost::zero ) ); 1373 1368 } 1374 1369 … … 1405 1400 1406 1401 void AlternativeFinder::Finder::postvisit( ConstantExpr *constantExpr ) { 1407 alternatives.push_back( Alternative( constantExpr ->clone(), env, Cost::zero ) );1402 alternatives.push_back( Alternative( constantExpr, env, Cost::zero ) ); 1408 1403 } 1409 1404 … … 1425 1420 Alternative &choice = winners.front(); 1426 1421 referenceToRvalueConversion( choice.expr, choice.cost ); 1427 alternatives.push_back( Alternative( new SizeofExpr( choice.expr ->clone()), choice.env, Cost::zero ) );1422 alternatives.push_back( Alternative( new SizeofExpr( choice.expr ), choice.env, Cost::zero ) ); 1428 1423 } // if 1429 1424 } … … 1446 1441 Alternative &choice = winners.front(); 1447 1442 referenceToRvalueConversion( choice.expr, choice.cost ); 1448 alternatives.push_back( Alternative( new AlignofExpr( choice.expr ->clone()), choice.env, Cost::zero ) );1443 alternatives.push_back( Alternative( new AlignofExpr( choice.expr ), choice.env, Cost::zero ) ); 1449 1444 } // if 1450 1445 } … … 1475 1470 1476 1471 void AlternativeFinder::Finder::postvisit( OffsetofExpr *offsetofExpr ) { 1477 alternatives.push_back( Alternative( offsetofExpr ->clone(), env, Cost::zero ) );1472 alternatives.push_back( Alternative( offsetofExpr, env, Cost::zero ) ); 1478 1473 } 1479 1474 1480 1475 void AlternativeFinder::Finder::postvisit( OffsetPackExpr *offsetPackExpr ) { 1481 alternatives.push_back( Alternative( offsetPackExpr ->clone(), env, Cost::zero ) );1476 alternatives.push_back( Alternative( offsetPackExpr, env, Cost::zero ) ); 1482 1477 } 1483 1478 … … 1557 1552 compositeEnv.simpleCombine( second.env ); 1558 1553 1559 LogicalExpr *newExpr = new LogicalExpr( first.expr ->clone(), second.expr->clone(), logicalExpr->get_isAnd() );1554 LogicalExpr *newExpr = new LogicalExpr( first.expr, second.expr, logicalExpr->get_isAnd() ); 1560 1555 alternatives.push_back( Alternative( newExpr, compositeEnv, first.cost + second.cost ) ); 1561 1556 } … … 1590 1585 Type* commonType = nullptr; 1591 1586 if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { 1592 ConditionalExpr *newExpr = new ConditionalExpr( first.expr ->clone(), second.expr->clone(), third.expr->clone());1587 ConditionalExpr *newExpr = new ConditionalExpr( first.expr, second.expr, third.expr ); 1593 1588 newExpr->result = commonType ? commonType : second.expr->result->clone(); 1594 1589 // convert both options to the conditional result type … … 1609 1604 secondFinder.findWithAdjustment( commaExpr->get_arg2() ); 1610 1605 for ( const Alternative & alt : secondFinder.alternatives ) { 1611 alternatives.push_back( Alternative( new CommaExpr( newFirstArg ->clone(), alt.expr->clone()), alt.env, alt.cost ) );1606 alternatives.push_back( Alternative( new CommaExpr( newFirstArg, alt.expr ), alt.env, alt.cost ) ); 1612 1607 } // for 1613 delete newFirstArg;1614 1608 } 1615 1609 … … 1632 1626 Type* commonType = nullptr; 1633 1627 if ( unify( first.expr->result, second.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { 1634 RangeExpr * newExpr = new RangeExpr( first.expr ->clone(), second.expr->clone());1628 RangeExpr * newExpr = new RangeExpr( first.expr, second.expr ); 1635 1629 newExpr->result = commonType ? commonType : first.expr->result->clone(); 1636 1630 newAlt.expr = newExpr; … … 1660 1654 1661 1655 void AlternativeFinder::Finder::postvisit( TupleExpr *tupleExpr ) { 1662 alternatives.push_back( Alternative( tupleExpr ->clone(), env, Cost::zero ) );1656 alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) ); 1663 1657 } 1664 1658 1665 1659 void AlternativeFinder::Finder::postvisit( ImplicitCopyCtorExpr * impCpCtorExpr ) { 1666 alternatives.push_back( Alternative( impCpCtorExpr ->clone(), env, Cost::zero ) );1660 alternatives.push_back( Alternative( impCpCtorExpr, env, Cost::zero ) ); 1667 1661 } 1668 1662 … … 1673 1667 finder.findWithoutPrune( ctorExpr->get_callExpr() ); 1674 1668 for ( Alternative & alt : finder.alternatives ) { 1675 alternatives.push_back( Alternative( new ConstructorExpr( alt.expr ->clone()), alt.env, alt.cost ) );1669 alternatives.push_back( Alternative( new ConstructorExpr( alt.expr ), alt.env, alt.cost ) ); 1676 1670 } 1677 1671 } 1678 1672 1679 1673 void AlternativeFinder::Finder::postvisit( TupleIndexExpr *tupleExpr ) { 1680 alternatives.push_back( Alternative( tupleExpr ->clone(), env, Cost::zero ) );1674 alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) ); 1681 1675 } 1682 1676 1683 1677 void AlternativeFinder::Finder::postvisit( TupleAssignExpr *tupleAssignExpr ) { 1684 alternatives.push_back( Alternative( tupleAssignExpr ->clone(), env, Cost::zero ) );1678 alternatives.push_back( Alternative( tupleAssignExpr, env, Cost::zero ) ); 1685 1679 } 1686 1680 … … 1690 1684 for ( Alternative & alt : finder.alternatives ) { 1691 1685 // ensure that the id is passed on to the UniqueExpr alternative so that the expressions are "linked" 1692 UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr ->clone(), unqExpr->get_id() );1686 UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr, unqExpr->get_id() ); 1693 1687 alternatives.push_back( Alternative( newUnqExpr, alt.env, alt.cost ) ); 1694 1688 } … … 1741 1735 // count one safe conversion for each value that is thrown away 1742 1736 thisCost.incSafe( discardedValues ); 1743 Alternative newAlt( new InitExpr( restructureCast( alt.expr ->clone(), toType, true ), initAlt.designation->clone()), newEnv, alt.cost, thisCost );1737 Alternative newAlt( new InitExpr( restructureCast( alt.expr, toType, true ), initAlt.designation ), newEnv, alt.cost, thisCost ); 1744 1738 inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) ); 1745 1739 } -
src/ResolvExpr/ConversionCost.cc
r63238a4 r28f3a19 20 20 #include <string> // for operator==, string 21 21 22 #include "Common/GC.h" // for new_static_root 22 23 #include "ResolvExpr/Cost.h" // for Cost 23 24 #include "ResolvExpr/TypeEnvironment.h" // for EqvClass, TypeEnvironment … … 357 358 void ConversionCost::postvisit( EnumInstType * ) { 358 359 static Type::Qualifiers q; 359 static BasicType integer( q, BasicType::SignedInt );360 cost = costFunc( &integer, dest, indexer, env ); // safe if dest >= int360 static BasicType* integer = new_static_root<BasicType>( q, BasicType::SignedInt ); 361 cost = costFunc( integer, dest, indexer, env ); // safe if dest >= int 361 362 if ( cost < Cost::unsafe ) { 362 363 cost.incSafe(); -
src/ResolvExpr/ExplodedActual.h
r63238a4 r28f3a19 16 16 #pragma once 17 17 18 #include <memory>19 18 #include <vector> 20 19 … … 29 28 TypeEnvironment env; 30 29 Cost cost; 31 std::vector< std::unique_ptr<Expression>> exprs;30 std::vector< Expression* > exprs; 32 31 33 32 ExplodedActual() : env(), cost(Cost::zero), exprs() {} -
src/ResolvExpr/ResolveTypeof.cc
r63238a4 r28f3a19 70 70 Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer ); 71 71 assert( newExpr->result && ! newExpr->result->isVoid() ); 72 Type * newType = newExpr->result; 73 newExpr->result = nullptr; 74 delete typeofType; 75 delete newExpr; 76 return newType; 72 return newExpr->result; 77 73 } // if 78 74 return typeofType; -
src/ResolvExpr/Resolver.cc
r63238a4 r28f3a19 22 22 #include "Alternative.h" // for Alternative, AltList 23 23 #include "AlternativeFinder.h" // for AlternativeFinder, resolveIn... 24 #include "Common/GC.h" // for new_generation, collect_young 24 25 #include "Common/PassVisitor.h" // for PassVisitor 25 26 #include "Common/SemanticError.h" // for SemanticError … … 158 159 castExpr->arg = nullptr; 159 160 std::swap( expr->env, castExpr->env ); 160 delete castExpr;161 161 } 162 162 } … … 167 167 void findUnfinishedKindExpression(Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) { 168 168 assertf( untyped, "expected a non-null expression." ); 169 170 auto guard = new_generation(); // set up GC generation for this top-level expression 171 169 172 TypeEnvironment env; 170 173 AlternativeFinder finder( indexer, env ); … … 207 210 Alternative & choice = winners.front(); 208 211 if ( findDeletedExpr( choice.expr ) ) { 212 trace( choice.expr ); 209 213 SemanticError( untyped->location, choice.expr, "Unique best alternative includes deleted identifier in " ); 210 214 } 211 215 alt = std::move( choice ); 216 trace( alt ); 212 217 } 213 218 … … 218 223 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast ); 219 224 finishExpr( choice.expr, choice.env, untyped->env ); 220 delete untyped;221 225 untyped = choice.expr; 222 226 choice.expr = nullptr; … … 241 245 assertf( expr, "expected a non-null expression." ); 242 246 243 static CastExpr untyped( nullptr ); // cast to void244 untyped .location = expr->location;247 auto untyped = new CastExpr{ expr }; // cast to void 248 untyped->location = expr->location; 245 249 246 250 // set up and resolve expression cast to void 247 untyped.arg = expr;248 251 Alternative choice; 249 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );252 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true ); 250 253 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 251 254 env = std::move( choice.env ); 252 255 253 256 // clean up resolved expression 254 Expression * ret = castExpr->arg; 255 castExpr->arg = nullptr; 256 257 // unlink the arg so that it isn't deleted twice at the end of the program 258 untyped.arg = nullptr; 259 return ret; 257 return castExpr->arg; 260 258 } 261 259 … … 265 263 Expression * newExpr = resolveInVoidContext( untyped, indexer, env ); 266 264 finishExpr( newExpr, env, untyped->env ); 267 delete untyped;268 265 untyped = newExpr; 269 266 } … … 449 446 castExpr->arg = nullptr; 450 447 std::swap( newExpr->env, castExpr->env ); 451 delete castExpr;452 448 } 453 449 caseStmt->condition = newExpr; … … 747 743 // and newExpr may already have inferParams of its own, so a simple swap is not sufficient. 748 744 newExpr->spliceInferParams( initExpr ); 749 delete initExpr;750 745 751 746 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) … … 765 760 ce->set_arg( nullptr ); 766 761 std::swap( ce->env, newExpr->env ); 767 delete ce;768 762 } 769 763 } … … 816 810 // could not find valid constructor, or found an intrinsic constructor 817 811 // fall back on C-style initializer 818 delete ctorInit->get_ctor(); 819 ctorInit->set_ctor( NULL ); 820 delete ctorInit->get_dtor(); 821 ctorInit->set_dtor( NULL ); 812 ctorInit->set_ctor( nullptr ); 813 ctorInit->set_dtor( nullptr ); 822 814 maybeAccept( ctorInit->get_init(), *visitor ); 823 815 } … … 845 837 846 838 // found a constructor - can get rid of C-style initializer 847 delete ctorInit->init;848 839 ctorInit->init = nullptr; 849 840 … … 852 843 // to clean up generated code. 853 844 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) { 854 delete ctorInit->ctor;855 845 ctorInit->ctor = nullptr; 856 846 } 857 847 858 848 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) { 859 delete ctorInit->dtor;860 849 ctorInit->dtor = nullptr; 861 850 } -
src/ResolvExpr/TypeEnvironment.cc
r63238a4 r28f3a19 17 17 #include <algorithm> // for copy, set_intersection 18 18 #include <iterator> // for ostream_iterator, insert_iterator 19 #include <memory> // for unique_ptr20 19 #include <utility> // for pair, move 21 20 21 #include "Common/PassVisitor.h" // for PassVisitor<GcTracer> 22 22 #include "Common/utility.h" // for maybeClone 23 #include "SynTree/GcTracer.h" // for PassVisitor<GcTracer> 23 24 #include "SynTree/Type.h" // for Type, FunctionType, Type::Fora... 24 25 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution … … 77 78 EqvClass &EqvClass::operator=( const EqvClass &other ) { 78 79 if ( this == &other ) return *this; 79 delete type;80 80 initialize( other, *this ); 81 81 return *this; … … 84 84 EqvClass &EqvClass::operator=( EqvClass &&other ) { 85 85 if ( this == &other ) return *this; 86 delete type;87 86 88 87 vars = std::move(other.vars); 89 88 type = other.type; 90 other.type = nullptr;91 89 allowWidening = std::move(other.allowWidening); 92 90 data = std::move(other.data); … … 95 93 } 96 94 97 EqvClass::~EqvClass() { 98 delete type; 99 } 100 101 void EqvClass::set_type( Type* ty ) { 102 if ( ty == type ) return; 103 delete type; 104 type = ty; 105 } 95 void EqvClass::set_type( Type* ty ) { type = ty; } 106 96 107 97 void EqvClass::print( std::ostream &os, Indenter indent ) const { … … 175 165 TypeInstType *newTypeInst = new TypeInstType( Type::Qualifiers(), *theClass->vars.begin(), theClass->data.kind == TypeDecl::Ftype ); 176 166 sub.add( *theVar, newTypeInst ); 177 delete newTypeInst;178 167 } // if 179 168 } // for … … 261 250 Type *common = 0; 262 251 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 263 std::unique_ptr< Type > newType( curClass->type->clone());252 Type *newType = curClass->type->clone(); 264 253 newType->get_qualifiers() = typeInst->get_qualifiers(); 265 if ( unifyInexact( newType .get(), bindTo, *this, need, have, openVars, widenMode & WidenMode( curClass->allowWidening, true ), indexer, common ) ) {254 if ( unifyInexact( newType, bindTo, *this, need, have, openVars, widenMode & WidenMode( curClass->allowWidening, true ), indexer, common ) ) { 266 255 if ( common ) { 267 256 common->get_qualifiers() = Type::Qualifiers{}; … … 319 308 if ( type1 && type2 ) { 320 309 // both classes bound, merge if bound types can be unified 321 std::unique_ptr<Type> newType1{ type1->clone() }, newType2{ type2->clone() };310 Type *newType1 = type1->clone(), *newType2 = type2->clone(); 322 311 WidenMode newWidenMode{ widen1, widen2 }; 323 312 Type *common = 0; 324 if ( unifyInexact( newType1 .get(), newType2.get(), *this, need, have, openVars, newWidenMode, indexer, common ) ) {313 if ( unifyInexact( newType1, newType2, *this, need, have, openVars, newWidenMode, indexer, common ) ) { 325 314 class1->vars.insert( class2->vars.begin(), class2->vars.end() ); 326 315 class1->allowWidening = widen1 && widen2; … … 370 359 return out; 371 360 } 361 362 PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ) { 363 for ( const EqvClass & c : env ) { 364 maybeAccept( c.type, gc ); 365 } 366 return gc; 367 } 372 368 } // namespace ResolvExpr 373 369 -
src/ResolvExpr/TypeEnvironment.h
r63238a4 r28f3a19 29 29 #include "SynTree/Type.h" // for Type, Type::ForallList 30 30 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 31 32 template< typename Pass > 33 class PassVisitor; 34 class GcTracer; 31 35 32 36 namespace ResolvExpr { … … 83 87 EqvClass &operator=( const EqvClass &other ); 84 88 EqvClass &operator=( EqvClass &&other ); 85 ~EqvClass();86 89 void print( std::ostream &os, Indenter indent = {} ) const; 87 90 … … 148 151 149 152 std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ); 153 154 PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ); 150 155 } // namespace ResolvExpr 151 156 -
src/ResolvExpr/Unify.cc
r63238a4 r28f3a19 17 17 #include <iterator> // for back_insert_iterator, back_inserter 18 18 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_i... 19 #include <memory> // for unique_ptr20 19 #include <set> // for set 21 20 #include <string> // for string, operator==, operator!=, bas... … … 99 98 findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true ); 100 99 101 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 102 delete newFirst; 103 delete newSecond; 104 return result; 100 return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 105 101 } 106 102 … … 123 119 /// newSecond->print( std::cerr ); 124 120 /// std::cerr << std::endl; 125 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 126 delete newFirst; 127 delete newSecond; 128 return result; 121 return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 129 122 } 130 123 … … 134 127 findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true ); 135 128 Type *commonType = 0; 136 if ( unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) { 137 if ( commonType ) { 138 delete commonType; 139 } // if 140 return true; 141 } else { 142 return false; 143 } // if 129 return unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ); 144 130 } 145 131 … … 335 321 336 322 template< typename Iterator, typename Func > 337 std::unique_ptr<Type>combineTypes( Iterator begin, Iterator end, Func & toType ) {323 Type* combineTypes( Iterator begin, Iterator end, Func & toType ) { 338 324 std::list< Type * > types; 339 325 for ( ; begin != end; ++begin ) { … … 341 327 flatten( toType( *begin ), back_inserter( types ) ); 342 328 } 343 return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );329 return new TupleType{ Type::Qualifiers(), types }; 344 330 } 345 331 … … 356 342 if ( isTtype1 && ! isTtype2 ) { 357 343 // combine all of the things in list2, then unify 358 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );344 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 359 345 } else if ( isTtype2 && ! isTtype1 ) { 360 346 // combine all of the things in list1, then unify 361 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );347 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 362 348 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 363 349 return false; … … 369 355 Type * t1 = (*list1Begin)->get_type(); 370 356 if ( Tuples::isTtype( t1 ) ) { 371 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );357 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 372 358 } else return false; 373 359 } else if ( list2Begin != list2End ) { … … 375 361 Type * t2 = (*list2Begin)->get_type(); 376 362 if ( Tuples::isTtype( t2 ) ) { 377 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );363 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 378 364 } else return false; 379 365 } else { … … 394 380 // expand ttype parameter into its actual type 395 381 if ( eqvClass->data.kind == TypeDecl::Ttype && eqvClass->type ) { 396 delete typeInst;397 382 return eqvClass->type->clone(); 398 383 } … … 418 403 dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) ); 419 404 } 420 delete dcl;421 405 } 422 406 } … … 427 411 // flatten the parameter lists for both functions so that tuple structure 428 412 // doesn't affect unification. Must be a clone so that the types don't change. 429 std::unique_ptr<FunctionType> flatFunc( functionType->clone());430 std::unique_ptr<FunctionType> flatOther( otherFunction->clone());413 FunctionType* flatFunc = functionType->clone(); 414 FunctionType* flatOther = otherFunction->clone(); 431 415 flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env ); 432 416 flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env ); … … 569 553 if ( isTtype1 && ! isTtype2 ) { 570 554 // combine all of the things in list2, then unify 571 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );555 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 572 556 } else if ( isTtype2 && ! isTtype1 ) { 573 557 // combine all of the things in list1, then unify 574 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );558 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 575 559 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 576 560 return false; … … 582 566 Type * t1 = *list1Begin; 583 567 if ( Tuples::isTtype( t1 ) ) { 584 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );568 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 585 569 } else return false; 586 570 } else if ( list2Begin != list2End ) { … … 588 572 Type * t2 = *list2Begin; 589 573 if ( Tuples::isTtype( t2 ) ) { 590 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );574 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 591 575 } else return false; 592 576 } else { … … 597 581 void Unify::postvisit(TupleType *tupleType) { 598 582 if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) { 599 std::unique_ptr<TupleType> flat1( tupleType->clone());600 std::unique_ptr<TupleType> flat2( otherTuple->clone());583 TupleType* flat1 = tupleType->clone(); 584 TupleType* flat2 = otherTuple->clone(); 601 585 std::list<Type *> types1, types2; 602 586 … … 605 589 flat2->acceptMutator( expander ); 606 590 607 flatten( flat1 .get(), back_inserter( types1 ) );608 flatten( flat2 .get(), back_inserter( types2 ) );591 flatten( flat1, back_inserter( types1 ) ); 592 flatten( flat2, back_inserter( types2 ) ); 609 593 610 594 result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, indexer ); -
src/ResolvExpr/Unify.h
r63238a4 r28f3a19 54 54 bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 55 55 std::list< Type* > commonTypes; 56 if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) { 57 deleteAll( commonTypes ); 58 return true; 59 } else { 60 return false; 61 } // if 56 return unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ); 62 57 } 63 58 -
src/SymTab/Autogen.cc
r63238a4 r28f3a19 214 214 void addForwardDecl( FunctionDecl * functionDecl, std::list< Declaration * > & declsToAdd ) { 215 215 FunctionDecl * decl = functionDecl->clone(); 216 delete decl->statements;217 216 decl->statements = nullptr; 218 217 declsToAdd.push_back( decl ); … … 333 332 } catch ( SemanticErrorException & ) { 334 333 // okay if decl does not resolve - that means the function should not be generated 335 delete dcl;336 334 } 337 335 } … … 373 371 // do not carry over field's attributes to parameter type 374 372 Type * paramType = field->get_type()->clone(); 375 deleteAll( paramType->attributes );376 373 paramType->attributes.clear(); 377 374 // add a parameter corresponding to this field … … 383 380 resolve( ctor ); 384 381 } 385 delete memCtorType;386 382 } 387 383 … … 511 507 // do not carry over field's attributes to parameter type 512 508 Type * paramType = field->get_type()->clone(); 513 deleteAll( paramType->attributes );514 509 paramType->attributes.clear(); 515 510 // add a parameter corresponding to this field … … 524 519 break; 525 520 } 526 delete memCtorType;527 521 } 528 522 … … 594 588 // must visit children (enum constants) to add them to the indexer 595 589 if ( enumDecl->has_body() ) { 596 EnumInstType enumInst( Type::Qualifiers(), enumDecl->get_name() );597 enumInst .set_baseEnum( enumDecl );598 EnumFuncGenerator gen( &enumInst, data, functionNesting, indexer );590 auto enumInst = new EnumInstType{ Type::Qualifiers(), enumDecl->get_name() }; 591 enumInst->set_baseEnum( enumDecl ); 592 EnumFuncGenerator gen( enumInst, data, functionNesting, indexer ); 599 593 generateFunctions( gen, declsToAddAfter ); 600 594 } … … 604 598 visit_children = false; 605 599 if ( structDecl->has_body() ) { 606 StructInstType structInst( Type::Qualifiers(), structDecl->name );607 structInst .set_baseStruct( structDecl );600 auto structInst = new StructInstType{ Type::Qualifiers(), structDecl->name }; 601 structInst->set_baseStruct( structDecl ); 608 602 for ( TypeDecl * typeDecl : structDecl->parameters ) { 609 structInst .parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) );610 } 611 StructFuncGenerator gen( structDecl, &structInst, data, functionNesting, indexer );603 structInst->parameters.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->name, typeDecl ) ) ); 604 } 605 StructFuncGenerator gen( structDecl, structInst, data, functionNesting, indexer ); 612 606 generateFunctions( gen, declsToAddAfter ); 613 607 } // if … … 617 611 visit_children = false; 618 612 if ( unionDecl->has_body() ) { 619 UnionInstType unionInst( Type::Qualifiers(), unionDecl->get_name() );620 unionInst .set_baseUnion( unionDecl );613 auto unionInst = new UnionInstType{ Type::Qualifiers(), unionDecl->get_name() }; 614 unionInst->set_baseUnion( unionDecl ); 621 615 for ( TypeDecl * typeDecl : unionDecl->get_parameters() ) { 622 unionInst .get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );623 } 624 UnionFuncGenerator gen( unionDecl, &unionInst, data, functionNesting, indexer );616 unionInst->get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) ); 617 } 618 UnionFuncGenerator gen( unionDecl, unionInst, data, functionNesting, indexer ); 625 619 generateFunctions( gen, declsToAddAfter ); 626 620 } // if … … 631 625 if ( ! typeDecl->base ) return; 632 626 633 TypeInstType refType( Type::Qualifiers(), typeDecl->name, typeDecl );634 TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer );627 auto refType = new TypeInstType{ Type::Qualifiers(), typeDecl->name, typeDecl }; 628 TypeFuncGenerator gen( typeDecl, refType, data, functionNesting, indexer ); 635 629 generateFunctions( gen, declsToAddAfter ); 636 630 -
src/SymTab/Autogen.h
r63238a4 r28f3a19 97 97 // return if adding reference fails - will happen on default constructor and destructor 98 98 if ( isReferenceCtorDtor && ! srcParam.addReference() ) { 99 delete fExpr;100 99 return listInit; 101 100 } -
src/SymTab/FixFunction.cc
r63238a4 r28f3a19 28 28 29 29 DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) { 30 // can't delete function type because it may contain assertions, so transfer ownership to new object 31 ObjectDecl *pointer = new ObjectDecl( functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, new PointerType( Type::Qualifiers(), functionDecl->type ), nullptr, functionDecl->attributes ); 32 functionDecl->attributes.clear(); 33 functionDecl->type = nullptr; 34 delete functionDecl; 35 return pointer; 30 return new ObjectDecl{ 31 functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, 32 new PointerType{ Type::Qualifiers(), functionDecl->type }, 33 nullptr, functionDecl->attributes }; 36 34 } 37 35 … … 42 40 Type * FixFunction::postmutate(ArrayType *arrayType) { 43 41 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 44 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic ); 45 arrayType->base = nullptr; 46 arrayType->dimension = nullptr; 47 delete arrayType; 48 return pointerType; 42 return new PointerType{ arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic }; 49 43 } 50 44 -
src/SymTab/Validate.cc
r63238a4 r28f3a19 48 48 #include "CodeGen/CodeGenerator.h" // for genName 49 49 #include "CodeGen/OperatorTable.h" // for isCtorDtor, isCtorDtorAssign 50 #include "Common/GC.h" // for new_static_root, register_static_root 50 51 #include "ControlStruct/Mutate.h" // for ForExprMutator 51 52 #include "Common/PassVisitor.h" // for PassVisitor, WithDeclsToAdd … … 199 200 void addImplicitTypedef( AggDecl * aggDecl ); 200 201 201 typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr; 202 typedef ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap; 202 typedef ScopedMap< std::string, std::pair< TypedefDecl*, int > > TypedefMap; 203 203 typedef std::map< std::string, TypeDecl * > TypeDeclMap; 204 204 TypedefMap typedefNames; … … 313 313 } // if 314 314 // Always remove the hoisted aggregate from the inner structure. 315 GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist , false); } );315 GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist ); } ); 316 316 } 317 317 … … 374 374 // one void is the only thing in the list; remove it. 375 375 if ( containsVoid ) { 376 delete dwts.front();377 376 dwts.clear(); 378 377 } … … 501 500 } 502 501 } 503 deleteAll( td->assertions );504 502 td->assertions.clear(); 505 503 } // for … … 617 615 // expand trait instance into all of its members 618 616 expandAssertions( traitInst, back_inserter( type->assertions ) ); 619 delete traitInst;620 617 } else { 621 618 // pass other assertions through … … 689 686 // grab and remember declaration of size_t 690 687 SizeType = eliminator.pass.typedefNames["size_t"].first->get_base()->clone(); 688 GC::get().register_static_root( SizeType ); 691 689 } else { 692 690 // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong 693 691 // eventually should have a warning for this case. 694 SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 695 } 696 filter( translationUnit, isTypedef, true ); 692 SizeType = 693 new_static_root<BasicType>( Type::Qualifiers(), BasicType::LongUnsignedInt ); 694 } 695 filter( translationUnit, isTypedef ); 697 696 } 698 697 … … 708 707 ret->attributes.splice( ret->attributes.end(), typeInst->attributes ); 709 708 } else { 710 deleteAll( ret->attributes );711 709 ret->attributes.clear(); 712 710 } … … 721 719 mutateAll( rtt->parameters, *visitor ); // recursively fix typedefs on parameters 722 720 } // if 723 delete typeInst;724 721 return ret; 725 722 } else { … … 763 760 } 764 761 } else { 765 typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );762 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 766 763 } // if 767 764 … … 807 804 if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->get_type() ) ) { // function type? 808 805 // replace the current object declaration with a function declaration 809 FunctionDecl * newDecl = new FunctionDecl( objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() ); 810 objDecl->get_attributes().clear(); 811 objDecl->set_type( nullptr ); 812 delete objDecl; 813 return newDecl; 806 return new FunctionDecl{ 807 objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), 808 funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() }; 814 809 } // if 815 810 return objDecl; … … 835 830 } // if 836 831 return false; 837 } , true);832 } ); 838 833 return compoundStmt; 839 834 } … … 843 838 template<typename AggDecl> 844 839 AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) { 845 filter( aggDecl->members, isTypedef , true);840 filter( aggDecl->members, isTypedef ); 846 841 return aggDecl; 847 842 } … … 858 853 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 859 854 } // if 860 TypedefDecl Ptr tyDecl( new TypedefDecl( aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() ) );861 typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );855 TypedefDecl* tyDecl = new TypedefDecl{ aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() }; 856 typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 862 857 } // if 863 858 } … … 973 968 static UniqueName indexName( "_compLit" ); 974 969 975 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() ); 976 compLitExpr->set_result( nullptr ); 977 compLitExpr->set_initializer( nullptr ); 978 delete compLitExpr; 970 ObjectDecl * tempvar = new ObjectDecl{ 971 indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() }; 979 972 declsToAddBefore.push_back( tempvar ); // add modified temporary to current block 980 973 return new VariableExpr( tempvar ); … … 1012 1005 // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false. 1013 1006 ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) ); 1014 deleteAll( retVals );1015 1007 retVals.clear(); 1016 1008 retVals.push_back( newRet ); … … 1053 1045 if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) { 1054 1046 if ( labels.count( nameExpr->name ) ) { 1055 Label name = nameExpr->name; 1056 delete addrExpr; 1057 return new LabelAddressExpr( name ); 1047 return new LabelAddressExpr{ nameExpr->name }; 1058 1048 } 1059 1049 } -
src/SynTree/AddressExpr.cc
r63238a4 r28f3a19 58 58 } 59 59 60 AddressExpr::~AddressExpr() {61 delete arg;62 }63 64 60 void AddressExpr::print( std::ostream &os, Indenter indent ) const { 65 61 os << "Address of:" << std::endl; … … 75 71 } 76 72 LabelAddressExpr::LabelAddressExpr( const LabelAddressExpr & other ) : Expression( other ), arg( other.arg ) {} 77 LabelAddressExpr::~LabelAddressExpr() {}78 73 79 74 void LabelAddressExpr::print( std::ostream & os, Indenter ) const { -
src/SynTree/AggregateDecl.cc
r63238a4 r28f3a19 33 33 cloneAll( other.attributes, attributes ); 34 34 body = other.body; 35 }36 37 AggregateDecl::~AggregateDecl() {38 deleteAll( attributes );39 deleteAll( parameters );40 deleteAll( members );41 35 } 42 36 -
src/SynTree/ApplicationExpr.cc
r63238a4 r28f3a19 17 17 #include <list> // for list 18 18 #include <map> // for _Rb_tree_const_iterator, map, map<>:... 19 #include <memory> // for unique_ptr20 19 #include <ostream> // for operator<<, ostream, basic_ostream 21 20 #include <string> // for operator<<, string, char_traits … … 43 42 } 44 43 45 ParamEntry::~ParamEntry() {46 delete actualType;47 delete formalType;48 delete expr;49 }50 51 44 ParamEntry::ParamEntry( ParamEntry && other ) : 52 45 decl( other.decl ), actualType( other.actualType ), formalType( other.formalType ), expr( other.expr ), inferParams( std::move( other.inferParams ) ) { … … 58 51 ParamEntry & ParamEntry::operator=( ParamEntry && other ) { 59 52 if ( &other == this ) return *this; 60 delete actualType;61 delete formalType;62 delete expr;63 53 decl = other.decl; 64 54 actualType = other.actualType; … … 86 76 } 87 77 88 ApplicationExpr::~ApplicationExpr() {89 delete function;90 deleteAll( args );91 }92 93 78 void ApplicationExpr::print( std::ostream &os, Indenter indent ) const { 94 79 os << "Application of" << std::endl << indent+1; -
src/SynTree/ArrayType.cc
r63238a4 r28f3a19 34 34 } 35 35 36 ArrayType::~ArrayType() {37 delete base;38 delete dimension;39 }40 41 36 void ArrayType::print( std::ostream &os, Indenter indent ) const { 42 37 Type::print( os, indent ); -
src/SynTree/AttrType.cc
r63238a4 r28f3a19 37 37 } 38 38 39 AttrType::~AttrType() {40 delete expr;41 delete type;42 }43 44 39 void AttrType::print( std::ostream &os, Indenter indent ) const { 45 40 Type::print( os, indent ); -
src/SynTree/Attribute.cc
r63238a4 r28f3a19 23 23 Attribute::Attribute( const Attribute &other ) : name( other.name ) { 24 24 cloneAll( other.parameters, parameters ); 25 }26 27 Attribute::~Attribute() {28 deleteAll( parameters );29 25 } 30 26 -
src/SynTree/Attribute.h
r63238a4 r28f3a19 36 36 Attribute( std::string name = "", const std::list< Expression * > & parameters = std::list< Expression * >() ) : name( name ), parameters( parameters ) {} 37 37 Attribute( const Attribute &other ); 38 virtual ~Attribute();39 38 40 39 std::string get_name() const { return name; } -
src/SynTree/BaseSyntaxNode.h
r63238a4 r28f3a19 17 17 18 18 #include "Common/CodeLocation.h" 19 #include "Common/GC.h" 19 20 #include "Common/Indenter.h" 21 20 22 class Visitor; 21 23 class Mutator; 22 24 23 class BaseSyntaxNode { 24 public: 25 class BaseSyntaxNode : public GC_Object { 26 friend class GcTracer; 27 public: 25 28 CodeLocation location; 26 27 virtual ~BaseSyntaxNode() {}28 29 29 30 virtual BaseSyntaxNode * clone() const = 0; -
src/SynTree/CommaExpr.cc
r63238a4 r28f3a19 34 34 } 35 35 36 CommaExpr::~CommaExpr() {37 delete arg1;38 delete arg2;39 }40 41 36 void CommaExpr::print( std::ostream &os, Indenter indent ) const { 42 37 os << "Comma Expression:" << std::endl; -
src/SynTree/CompoundStmt.cc
r63238a4 r28f3a19 68 68 } 69 69 70 CompoundStmt::~CompoundStmt() {71 deleteAll( kids );72 }73 74 70 void CompoundStmt::print( std::ostream &os, Indenter indent ) const { 75 71 os << "CompoundStmt" << endl; -
src/SynTree/Constant.cc
r63238a4 r28f3a19 27 27 type = other.type->clone(); 28 28 } 29 30 Constant::~Constant() { delete type; }31 29 32 30 Constant Constant::from_bool( bool b ) { -
src/SynTree/Constant.h
r63238a4 r28f3a19 19 19 #include <string> // for string 20 20 21 #include "BaseSyntaxNode.h"22 21 #include "Mutator.h" // for Mutator 23 22 #include "Visitor.h" // for Visitor 24 23 24 #include "Common/Indenter.h" // for Indenter 25 25 26 class Type; 26 27 27 class Constant : public BaseSyntaxNode{28 class Constant { 28 29 public: 29 30 Constant( Type * type, std::string rep, unsigned long long val ); 30 31 Constant( Type * type, std::string rep, double val ); 31 32 Constant( const Constant & other ); 32 virtual ~Constant(); 33 33 34 34 virtual Constant * clone() const { return new Constant( *this ); } 35 35 -
src/SynTree/DeclStmt.cc
r63238a4 r28f3a19 29 29 } 30 30 31 DeclStmt::~DeclStmt() {32 delete decl;33 }34 35 31 void DeclStmt::print( std::ostream &os, Indenter indent ) const { 36 32 assert( decl != 0 ); -
src/SynTree/Declaration.cc
r63238a4 r28f3a19 38 38 } 39 39 40 Declaration::~Declaration() {41 }42 43 40 void Declaration::fixUniqueId() { 44 41 // don't need to set unique ID twice … … 68 65 } 69 66 70 AsmDecl::~AsmDecl() {71 delete stmt;72 }73 74 67 void AsmDecl::print( std::ostream &os, Indenter indent ) const { 75 68 stmt->print( os, indent ); … … 85 78 86 79 StaticAssertDecl::StaticAssertDecl( const StaticAssertDecl & other ) : Declaration( other ), condition( maybeClone( other.condition ) ), message( maybeClone( other.message ) ) { 87 }88 89 StaticAssertDecl::~StaticAssertDecl() {90 delete condition;91 delete message;92 80 } 93 81 -
src/SynTree/Declaration.h
r63238a4 r28f3a19 45 45 Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ); 46 46 Declaration( const Declaration &other ); 47 virtual ~Declaration();48 47 49 48 const std::string &get_name() const { return name; } … … 88 87 DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs ); 89 88 DeclarationWithType( const DeclarationWithType &other ); 90 virtual ~DeclarationWithType(); 91 89 92 90 std::string get_mangleName() const { return mangleName; } 93 91 DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; } … … 127 125 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); 128 126 ObjectDecl( const ObjectDecl &other ); 129 virtual ~ObjectDecl();130 127 131 128 virtual Type * get_type() const override { return type; } … … 157 154 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); 158 155 FunctionDecl( const FunctionDecl &other ); 159 virtual ~FunctionDecl();160 156 161 157 virtual Type * get_type() const override { return type; } … … 185 181 NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type ); 186 182 NamedTypeDecl( const NamedTypeDecl &other ); 187 virtual ~NamedTypeDecl();188 183 189 184 Type *get_base() const { return base; } … … 220 215 TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init = nullptr ); 221 216 TypeDecl( const TypeDecl &other ); 222 virtual ~TypeDecl();223 217 224 218 Kind get_kind() const { return kind; } … … 269 263 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ); 270 264 AggregateDecl( const AggregateDecl &other ); 271 virtual ~AggregateDecl(); 272 265 273 266 std::list<Declaration*>& get_members() { return members; } 274 267 std::list<TypeDecl*>& get_parameters() { return parameters; } … … 354 347 AsmDecl( AsmStmt *stmt ); 355 348 AsmDecl( const AsmDecl &other ); 356 virtual ~AsmDecl();357 349 358 350 AsmStmt *get_stmt() { return stmt; } … … 373 365 StaticAssertDecl( Expression * condition, ConstantExpr * message ); 374 366 StaticAssertDecl( const StaticAssertDecl & other ); 375 virtual ~StaticAssertDecl();376 367 377 368 virtual StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } -
src/SynTree/DeclarationWithType.cc
r63238a4 r28f3a19 34 34 } 35 35 36 DeclarationWithType::~DeclarationWithType() {37 deleteAll( attributes );38 delete asmName;39 }40 41 36 // Local Variables: // 42 37 // tab-width: 4 // -
src/SynTree/Expression.cc
r63238a4 r28f3a19 59 59 Expression::~Expression() { 60 60 delete env; 61 delete result;62 61 } 63 62 … … 81 80 ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { 82 81 } 83 84 ConstantExpr::~ConstantExpr() {}85 82 86 83 void ConstantExpr::print( std::ostream &os, Indenter indent ) const { … … 127 124 } 128 125 129 VariableExpr::~VariableExpr() {130 // don't delete the declaration, since it points somewhere else in the tree131 }132 133 126 VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) { 134 127 VariableExpr * funcExpr = new VariableExpr( func ); … … 157 150 } 158 151 159 SizeofExpr::~SizeofExpr() {160 delete expr;161 delete type;162 }163 164 152 void SizeofExpr::print( std::ostream &os, Indenter indent) const { 165 153 os << "Sizeof Expression on: "; … … 183 171 } 184 172 185 AlignofExpr::~AlignofExpr() {186 delete expr;187 delete type;188 }189 190 173 void AlignofExpr::print( std::ostream &os, Indenter indent) const { 191 174 os << "Alignof Expression on: "; … … 203 186 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) : 204 187 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 205 206 UntypedOffsetofExpr::~UntypedOffsetofExpr() {207 delete type;208 }209 188 210 189 void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const { … … 224 203 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 225 204 226 OffsetofExpr::~OffsetofExpr() {227 delete type;228 }229 230 205 void OffsetofExpr::print( std::ostream &os, Indenter indent) const { 231 206 os << "Offsetof Expression on member " << member->name << " of "; … … 241 216 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {} 242 217 243 OffsetPackExpr::~OffsetPackExpr() { delete type; }244 245 218 void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const { 246 219 os << "Offset pack expression on "; … … 259 232 AttrExpr::AttrExpr( const AttrExpr &other ) : 260 233 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 261 }262 263 AttrExpr::~AttrExpr() {264 delete attr;265 delete expr;266 delete type;267 234 } 268 235 … … 287 254 288 255 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) { 289 }290 291 CastExpr::~CastExpr() {292 delete arg;293 256 } 294 257 … … 312 275 } 313 276 314 KeywordCastExpr::~KeywordCastExpr() {315 delete arg;316 }317 318 277 const std::string & KeywordCastExpr::targetString() const { 319 278 static const std::string targetStrs[] = { … … 340 299 341 300 VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 342 }343 344 VirtualCastExpr::~VirtualCastExpr() {345 delete arg;346 301 } 347 302 … … 368 323 } 369 324 370 UntypedMemberExpr::~UntypedMemberExpr() {371 delete aggregate;372 delete member;373 }374 375 325 void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const { 376 326 os << "Untyped Member Expression, with field: " << std::endl << indent+1; … … 399 349 } 400 350 401 MemberExpr::~MemberExpr() {402 // don't delete the member declaration, since it points somewhere else in the tree403 delete aggregate;404 }405 406 351 void MemberExpr::print( std::ostream &os, Indenter indent ) const { 407 352 os << "Member Expression, with field: " << std::endl; … … 419 364 Expression( other ), function( maybeClone( other.function ) ) { 420 365 cloneAll( other.args, args ); 421 }422 423 UntypedExpr::~UntypedExpr() {424 delete function;425 deleteAll( args );426 366 } 427 367 … … 472 412 } 473 413 474 NameExpr::~NameExpr() {}475 476 414 void NameExpr::print( std::ostream &os, Indenter indent ) const { 477 415 os << "Name: " << get_name(); … … 486 424 LogicalExpr::LogicalExpr( const LogicalExpr &other ) : 487 425 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { 488 }489 490 LogicalExpr::~LogicalExpr() {491 delete arg1;492 delete arg2;493 426 } 494 427 … … 506 439 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : 507 440 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { 508 }509 510 ConditionalExpr::~ConditionalExpr() {511 delete arg1;512 delete arg2;513 delete arg3;514 441 } 515 442 … … 549 476 ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() { 550 477 set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment 551 delete callExpr;552 deleteAll( tempDecls );553 deleteAll( returnDecls );554 deleteAll( dtors );555 478 } 556 479 … … 577 500 } 578 501 579 ConstructorExpr::~ConstructorExpr() {580 delete callExpr;581 }582 583 502 void ConstructorExpr::print( std::ostream &os, Indenter indent ) const { 584 503 os << "Constructor Expression: " << std::endl << indent+1; … … 595 514 596 515 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {} 597 598 CompoundLiteralExpr::~CompoundLiteralExpr() {599 delete initializer;600 }601 516 602 517 void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const { … … 625 540 cloneAll( other.dtors, dtors ); 626 541 } 627 StmtExpr::~StmtExpr() {628 delete statements;629 deleteAll( dtors );630 deleteAll( returnDecls );631 }632 542 void StmtExpr::computeResult() { 633 543 assert( statements ); 634 544 std::list< Statement * > & body = statements->kids; 635 delete result;636 545 result = nullptr; 637 546 if ( ! returnDecls.empty() ) { … … 676 585 UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { 677 586 } 678 UniqueExpr::~UniqueExpr() { 679 delete expr; 680 delete object; 681 delete var; 682 } 587 683 588 void UniqueExpr::print( std::ostream &os, Indenter indent ) const { 684 589 os << "Unique Expression with id:" << id << std::endl << indent+1; … … 693 598 InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {} 694 599 InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {} 695 InitAlternative::~InitAlternative() {696 delete type;697 delete designation;698 }699 600 700 601 UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {} 701 602 UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {} 702 UntypedInitExpr::~UntypedInitExpr() {703 delete expr;704 }705 603 706 604 void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const { … … 720 618 } 721 619 InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {} 722 InitExpr::~InitExpr() {723 delete expr;724 delete designation;725 }726 620 727 621 void InitExpr::print( std::ostream & os, Indenter indent ) const { … … 737 631 } 738 632 DeletedExpr::DeletedExpr( const DeletedExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), deleteStmt( other.deleteStmt ) {} 739 DeletedExpr::~DeletedExpr() {740 delete expr;741 }742 633 743 634 void DeletedExpr::print( std::ostream & os, Indenter indent ) const { … … 754 645 } 755 646 DefaultArgExpr::DefaultArgExpr( const DefaultArgExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ) {} 756 DefaultArgExpr::~DefaultArgExpr() {757 delete expr;758 }759 647 760 648 void DefaultArgExpr::print( std::ostream & os, Indenter indent ) const { … … 766 654 GenericExpr::Association::Association( Expression * expr ) : type( nullptr ), expr( expr ), isDefault( true ) {} 767 655 GenericExpr::Association::Association( const Association & other ) : type( maybeClone( other.type ) ), expr( maybeClone( other.expr ) ), isDefault( other.isDefault ) {} 768 GenericExpr::Association::~Association() {769 delete type;770 delete expr;771 }772 656 773 657 GenericExpr::GenericExpr( Expression * control, const std::list<Association> & assoc ) : Expression(), control( control ), associations( assoc ) {} 774 GenericExpr::GenericExpr( const GenericExpr & other ) : Expression(other), control( maybeClone( other.control ) ), associations( other.associations ) { 775 } 776 GenericExpr::~GenericExpr() { 777 delete control; 778 } 658 GenericExpr::GenericExpr( const GenericExpr & other ) : Expression(other), control( maybeClone( other.control ) ), associations( other.associations ) {} 659 GenericExpr::~GenericExpr() {} 779 660 780 661 void GenericExpr::print( std::ostream & os, Indenter indent ) const { -
src/SynTree/Expression.h
r63238a4 r28f3a19 41 41 ParamEntry( UniqueId decl, Type * actualType, Type * formalType, Expression* expr ): decl( decl ), actualType( actualType ), formalType( formalType ), expr( expr ), inferParams( new InferredParams ) {} 42 42 ParamEntry( const ParamEntry & other ); 43 ParamEntry( ParamEntry && other ); 44 ~ParamEntry(); 43 ParamEntry( ParamEntry&& other ); 45 44 ParamEntry & operator=( const ParamEntry & other ); 46 45 ParamEntry & operator=( ParamEntry && other ); … … 55 54 /// Expression is the root type for all expressions 56 55 class Expression : public BaseSyntaxNode { 56 protected: 57 virtual ~Expression(); 58 57 59 public: 58 60 Type * result; … … 63 65 Expression(); 64 66 Expression( const Expression & other ); 65 virtual ~Expression();66 67 67 68 Type *& get_result() { return result; } … … 94 95 ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 95 96 ApplicationExpr( const ApplicationExpr & other ); 96 virtual ~ApplicationExpr();97 97 98 98 Expression * get_function() const { return function; } … … 116 116 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 117 117 UntypedExpr( const UntypedExpr & other ); 118 virtual ~UntypedExpr();119 118 120 119 Expression * get_function() const { return function; } … … 141 140 NameExpr( std::string name ); 142 141 NameExpr( const NameExpr & other ); 143 virtual ~NameExpr();144 142 145 143 const std::string & get_name() const { return name; } … … 162 160 AddressExpr( Expression * arg ); 163 161 AddressExpr( const AddressExpr & other ); 164 virtual ~AddressExpr();165 162 166 163 Expression * get_arg() const { return arg; } … … 181 178 LabelAddressExpr( const Label &arg ); 182 179 LabelAddressExpr( const LabelAddressExpr & other ); 183 virtual ~LabelAddressExpr();184 180 185 181 virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); } … … 199 195 CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor 200 196 CastExpr( const CastExpr & other ); 201 virtual ~CastExpr();202 197 203 198 Expression * get_arg() const { return arg; } … … 220 215 KeywordCastExpr( Expression * arg, Target target ); 221 216 KeywordCastExpr( const KeywordCastExpr & other ); 222 virtual ~KeywordCastExpr();223 217 224 218 const std::string & targetString() const; … … 237 231 VirtualCastExpr( Expression * arg, Type * toType ); 238 232 VirtualCastExpr( const VirtualCastExpr & other ); 239 virtual ~VirtualCastExpr();240 233 241 234 Expression * get_arg() const { return arg; } … … 256 249 UntypedMemberExpr( Expression * member, Expression * aggregate ); 257 250 UntypedMemberExpr( const UntypedMemberExpr & other ); 258 virtual ~UntypedMemberExpr();259 251 260 252 Expression * get_member() const { return member; } … … 278 270 MemberExpr( DeclarationWithType * member, Expression * aggregate ); 279 271 MemberExpr( const MemberExpr & other ); 280 virtual ~MemberExpr();281 272 282 273 DeclarationWithType * get_member() const { return member; } … … 299 290 VariableExpr( DeclarationWithType * var ); 300 291 VariableExpr( const VariableExpr & other ); 301 virtual ~VariableExpr();302 292 303 293 DeclarationWithType * get_var() const { return var; } … … 319 309 ConstantExpr( Constant constant ); 320 310 ConstantExpr( const ConstantExpr & other ); 321 virtual ~ConstantExpr();322 311 323 312 Constant * get_constant() { return & constant; } … … 343 332 SizeofExpr( const SizeofExpr & other ); 344 333 SizeofExpr( Type * type ); 345 virtual ~SizeofExpr();346 334 347 335 Expression * get_expr() const { return expr; } … … 368 356 AlignofExpr( const AlignofExpr & other ); 369 357 AlignofExpr( Type * type ); 370 virtual ~AlignofExpr();371 358 372 359 Expression * get_expr() const { return expr; } … … 391 378 UntypedOffsetofExpr( Type * type, const std::string & member ); 392 379 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); 393 virtual ~UntypedOffsetofExpr();394 380 395 381 std::string get_member() const { return member; } … … 412 398 OffsetofExpr( Type * type, DeclarationWithType * member ); 413 399 OffsetofExpr( const OffsetofExpr & other ); 414 virtual ~OffsetofExpr();415 400 416 401 Type * get_type() const { return type; } … … 432 417 OffsetPackExpr( StructInstType * type ); 433 418 OffsetPackExpr( const OffsetPackExpr & other ); 434 virtual ~OffsetPackExpr();435 419 436 420 StructInstType * get_type() const { return type; } … … 454 438 AttrExpr( const AttrExpr & other ); 455 439 AttrExpr( Expression * attr, Type * type ); 456 virtual ~AttrExpr();457 440 458 441 Expression * get_attr() const { return attr; } … … 479 462 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true ); 480 463 LogicalExpr( const LogicalExpr & other ); 481 virtual ~LogicalExpr();482 464 483 465 bool get_isAnd() const { return isAnd; } … … 505 487 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ); 506 488 ConditionalExpr( const ConditionalExpr & other ); 507 virtual ~ConditionalExpr();508 489 509 490 Expression * get_arg1() const { return arg1; } … … 528 509 CommaExpr( Expression * arg1, Expression * arg2 ); 529 510 CommaExpr( const CommaExpr & other ); 530 virtual ~CommaExpr();531 511 532 512 Expression * get_arg1() const { return arg1; } … … 548 528 TypeExpr( Type * type ); 549 529 TypeExpr( const TypeExpr & other ); 550 virtual ~TypeExpr();551 530 552 531 Type * get_type() const { return type; } … … 568 547 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 569 548 AsmExpr( const AsmExpr & other ); 570 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };571 549 572 550 Expression * get_inout() const { return inout; } … … 590 568 /// along with a set of copy constructor calls, one for each argument. 591 569 class ImplicitCopyCtorExpr : public Expression { 570 protected: 571 virtual ~ImplicitCopyCtorExpr(); 572 592 573 public: 593 574 ApplicationExpr * callExpr; … … 598 579 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 599 580 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 600 virtual ~ImplicitCopyCtorExpr();601 581 602 582 ApplicationExpr * get_callExpr() const { return callExpr; } … … 620 600 ConstructorExpr( Expression * callExpr ); 621 601 ConstructorExpr( const ConstructorExpr & other ); 622 ~ConstructorExpr();623 602 624 603 Expression * get_callExpr() const { return callExpr; } … … 638 617 CompoundLiteralExpr( Type * type, Initializer * initializer ); 639 618 CompoundLiteralExpr( const CompoundLiteralExpr & other ); 640 virtual ~CompoundLiteralExpr();641 619 642 620 Initializer * get_initializer() const { return initializer; } … … 675 653 UntypedTupleExpr( const std::list< Expression * > & exprs ); 676 654 UntypedTupleExpr( const UntypedTupleExpr & other ); 677 virtual ~UntypedTupleExpr();678 655 679 656 std::list<Expression*>& get_exprs() { return exprs; } … … 692 669 TupleExpr( const std::list< Expression * > & exprs ); 693 670 TupleExpr( const TupleExpr & other ); 694 virtual ~TupleExpr();695 671 696 672 std::list<Expression*>& get_exprs() { return exprs; } … … 710 686 TupleIndexExpr( Expression * tuple, unsigned int index ); 711 687 TupleIndexExpr( const TupleIndexExpr & other ); 712 virtual ~TupleIndexExpr();713 688 714 689 Expression * get_tuple() const { return tuple; } … … 730 705 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ); 731 706 TupleAssignExpr( const TupleAssignExpr & other ); 732 virtual ~TupleAssignExpr();733 707 734 708 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; } … … 750 724 StmtExpr( CompoundStmt * statements ); 751 725 StmtExpr( const StmtExpr & other ); 752 virtual ~StmtExpr();753 726 754 727 CompoundStmt * get_statements() const { return statements; } … … 775 748 UniqueExpr( Expression * expr, long long idVal = -1 ); 776 749 UniqueExpr( const UniqueExpr & other ); 777 ~UniqueExpr();778 750 779 751 Expression * get_expr() const { return expr; } … … 805 777 InitAlternative( const InitAlternative & other ); 806 778 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it 807 ~InitAlternative();808 779 }; 809 780 … … 815 786 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); 816 787 UntypedInitExpr( const UntypedInitExpr & other ); 817 ~UntypedInitExpr();818 788 819 789 Expression * get_expr() const { return expr; } … … 835 805 InitExpr( Expression * expr, Designation * designation ); 836 806 InitExpr( const InitExpr & other ); 837 ~InitExpr();838 807 839 808 Expression * get_expr() const { return expr; } … … 857 826 DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt ); 858 827 DeletedExpr( const DeletedExpr & other ); 859 ~DeletedExpr();860 828 861 829 virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); } … … 872 840 DefaultArgExpr( Expression * expr ); 873 841 DefaultArgExpr( const DefaultArgExpr & other ); 874 ~DefaultArgExpr();875 842 876 843 virtual DefaultArgExpr * clone() const { return new DefaultArgExpr( * this ); } … … 892 859 Association( const Association & other ); 893 860 Association & operator=( const Association & other ) = delete; // at the moment this isn't used, and I don't want to implement it 894 ~Association();895 861 }; 896 862 … … 900 866 GenericExpr( Expression * control, const std::list<Association> & assoc ); 901 867 GenericExpr( const GenericExpr & other ); 902 virtual~GenericExpr();868 ~GenericExpr(); 903 869 904 870 virtual GenericExpr * clone() const { return new GenericExpr( * this ); } -
src/SynTree/FunctionDecl.cc
r63238a4 r28f3a19 52 52 } 53 53 cloneAll( other.withExprs, withExprs ); 54 }55 56 FunctionDecl::~FunctionDecl() {57 delete type;58 delete statements;59 deleteAll( withExprs );60 54 } 61 55 -
src/SynTree/FunctionType.cc
r63238a4 r28f3a19 31 31 cloneAll( other.returnVals, returnVals ); 32 32 cloneAll( other.parameters, parameters ); 33 }34 35 FunctionType::~FunctionType() {36 deleteAll( returnVals );37 deleteAll( parameters );38 33 } 39 34 -
src/SynTree/Initializer.cc
r63238a4 r28f3a19 32 32 } 33 33 34 Designation::~Designation() {35 // std::cerr << "destroying designation" << std::endl;36 deleteAll( designators );37 // std::cerr << "finished destroying designation" << std::endl;38 }39 40 34 void Designation::print( std::ostream &os, Indenter indent ) const { 41 35 if ( ! designators.empty() ) { … … 52 46 Initializer::Initializer( const Initializer & other ) : BaseSyntaxNode( other ), maybeConstructed( other.maybeConstructed ) { 53 47 } 54 Initializer::~Initializer() {}55 48 56 49 SingleInit::SingleInit( Expression *v, bool maybeConstructed ) : Initializer( maybeConstructed ), value ( v ) { … … 58 51 59 52 SingleInit::SingleInit( const SingleInit &other ) : Initializer(other), value ( maybeClone( other.value ) ) { 60 }61 62 SingleInit::~SingleInit() {63 delete value;64 53 } 65 54 … … 87 76 } 88 77 89 ListInit::~ListInit() {90 deleteAll( initializers );91 deleteAll( designations );92 }93 94 78 void ListInit::print( std::ostream &os, Indenter indent ) const { 95 79 os << "Compound initializer: " << std::endl; … … 110 94 ConstructorInit::ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ) : Initializer( true ), ctor( ctor ), dtor( dtor ), init( init ) {} 111 95 ConstructorInit::ConstructorInit( const ConstructorInit &other ) : Initializer( other ), ctor( maybeClone( other.ctor ) ), dtor( maybeClone( other.dtor ) ), init( maybeClone( other.init ) ) { 112 }113 114 ConstructorInit::~ConstructorInit() {115 delete ctor;116 delete dtor;117 delete init;118 96 } 119 97 -
src/SynTree/Initializer.h
r63238a4 r28f3a19 33 33 Designation( const std::list< Expression * > & designators ); 34 34 Designation( const Designation & other ); 35 virtual ~Designation();36 35 37 36 std::list< Expression * > & get_designators() { return designators; } … … 50 49 Initializer( bool maybeConstructed ); 51 50 Initializer( const Initializer & other ); 52 virtual ~Initializer();53 51 54 52 bool get_maybeConstructed() { return maybeConstructed; } … … 70 68 SingleInit( Expression *value, bool maybeConstructed = false ); 71 69 SingleInit( const SingleInit &other ); 72 virtual ~SingleInit();73 70 74 71 Expression *get_value() { return value; } … … 91 88 const std::list<Designation *> &designators = {}, bool maybeConstructed = false ); 92 89 ListInit( const ListInit & other ); 93 virtual ~ListInit();94 90 95 91 std::list<Designation *> & get_designations() { return designations; } … … 123 119 ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ); 124 120 ConstructorInit( const ConstructorInit &other ); 125 virtual ~ConstructorInit();126 121 127 122 void set_ctor( Statement * newValue ) { ctor = newValue; } -
src/SynTree/NamedTypeDecl.cc
r63238a4 r28f3a19 30 30 cloneAll( other.parameters, parameters ); 31 31 cloneAll( other.assertions, assertions ); 32 }33 34 NamedTypeDecl::~NamedTypeDecl() {35 delete base;36 deleteAll( parameters );37 deleteAll( assertions );38 32 } 39 33 -
src/SynTree/ObjectDecl.cc
r63238a4 r28f3a19 32 32 ObjectDecl::ObjectDecl( const ObjectDecl &other ) 33 33 : Parent( other ), type( maybeClone( other.type ) ), init( maybeClone( other.init ) ), bitfieldWidth( maybeClone( other.bitfieldWidth ) ) { 34 }35 36 ObjectDecl::~ObjectDecl() {37 delete type;38 delete init;39 delete bitfieldWidth;40 34 } 41 35 -
src/SynTree/PointerType.cc
r63238a4 r28f3a19 36 36 } 37 37 38 PointerType::~PointerType() {39 delete base;40 delete dimension;41 }42 43 38 void PointerType::print( std::ostream &os, Indenter indent ) const { 44 39 Type::print( os, indent ); -
src/SynTree/ReferenceToType.cc
r63238a4 r28f3a19 32 32 ReferenceToType::ReferenceToType( const ReferenceToType &other ) : Type( other ), name( other.name ), hoistType( other.hoistType ) { 33 33 cloneAll( other.parameters, parameters ); 34 }35 36 ReferenceToType::~ReferenceToType() {37 deleteAll( parameters );38 34 } 39 35 … … 170 166 } 171 167 172 TraitInstType::~TraitInstType() {173 }174 175 168 bool TraitInstType::isComplete() const { assert( false ); } 176 169 … … 183 176 184 177 TypeInstType::TypeInstType( const TypeInstType &other ) : Parent( other ), baseType( other.baseType ), isFtype( other.isFtype ) { 185 }186 187 188 TypeInstType::~TypeInstType() {189 // delete baseType; //This is shared and should not be deleted190 178 } 191 179 -
src/SynTree/ReferenceType.cc
r63238a4 r28f3a19 28 28 } 29 29 30 ReferenceType::~ReferenceType() {31 delete base;32 }33 34 30 int ReferenceType::referenceDepth() const { 35 31 return base->referenceDepth()+1; -
src/SynTree/Statement.cc
r63238a4 r28f3a19 44 44 } 45 45 46 Statement::~Statement() {}47 48 46 ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {} 49 47 50 48 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 51 52 ExprStmt::~ExprStmt() {53 delete expr;54 }55 49 56 50 void ExprStmt::print( std::ostream &os, Indenter indent ) const { … … 66 60 cloneAll( other.input, input ); 67 61 cloneAll( other.clobber, clobber ); 68 }69 70 AsmStmt::~AsmStmt() {71 delete instruction;72 deleteAll( output );73 deleteAll( input );74 deleteAll( clobber );75 62 } 76 63 … … 129 116 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 130 117 131 ReturnStmt::~ReturnStmt() {132 delete expr;133 }134 135 118 void ReturnStmt::print( std::ostream &os, Indenter indent ) const { 136 119 os << "Return Statement, returning: "; … … 148 131 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { 149 132 cloneAll( other.initialization, initialization ); 150 }151 152 IfStmt::~IfStmt() {153 deleteAll( initialization );154 delete condition;155 delete thenPart;156 delete elsePart;157 133 } 158 134 … … 192 168 } 193 169 194 SwitchStmt::~SwitchStmt() {195 delete condition;196 // destroy statements197 deleteAll( statements );198 }199 200 170 void SwitchStmt::print( std::ostream &os, Indenter indent ) const { 201 171 os << "Switch on condition: "; … … 216 186 Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { 217 187 cloneAll( other.stmts, stmts ); 218 }219 220 CaseStmt::~CaseStmt() {221 delete condition;222 deleteAll( stmts );223 188 } 224 189 … … 251 216 } 252 217 253 WhileStmt::~WhileStmt() {254 delete body;255 delete condition;256 }257 258 218 void WhileStmt::print( std::ostream &os, Indenter indent ) const { 259 219 os << "While on condition: " << endl ; … … 273 233 cloneAll( other.initialization, initialization ); 274 234 275 }276 277 ForStmt::~ForStmt() {278 deleteAll( initialization );279 delete condition;280 delete increment;281 delete body;282 235 } 283 236 … … 319 272 ThrowStmt::ThrowStmt( const ThrowStmt &other ) : 320 273 Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { 321 }322 323 ThrowStmt::~ThrowStmt() {324 delete expr;325 delete target;326 274 } 327 275 … … 344 292 } 345 293 346 TryStmt::~TryStmt() {347 delete block;348 deleteAll( handlers );349 delete finallyBlock;350 }351 352 294 void TryStmt::print( std::ostream &os, Indenter indent ) const { 353 295 os << "Try Statement" << endl; … … 378 320 } 379 321 380 CatchStmt::~CatchStmt() {381 delete decl;382 delete body;383 }384 385 322 void CatchStmt::print( std::ostream &os, Indenter indent ) const { 386 323 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; … … 405 342 406 343 FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { 407 }408 409 FinallyStmt::~FinallyStmt() {410 delete block;411 344 } 412 345 … … 440 373 orelse .statement = other.orelse .statement->clone(); 441 374 orelse .condition = other.orelse .condition->clone(); 442 }443 444 WaitForStmt::~WaitForStmt() {445 for( auto & clause : clauses ) {446 delete clause.target.function;447 deleteAll( clause.target.arguments );448 delete clause.statement;449 delete clause.condition;450 }451 452 delete timeout.time;453 delete timeout.statement;454 delete timeout.condition;455 456 delete orelse.statement;457 delete orelse.condition;458 375 } 459 376 … … 497 414 cloneAll( other.exprs, exprs ); 498 415 } 499 WithStmt::~WithStmt() {500 deleteAll( exprs );501 delete stmt;502 }503 416 504 417 void WithStmt::print( std::ostream & os, Indenter indent ) const { … … 526 439 } 527 440 528 ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {529 delete callStmt;530 }531 532 441 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const { 533 442 os << "Implicit Ctor Dtor Statement" << endl; -
src/SynTree/Statement.h
r63238a4 r28f3a19 38 38 39 39 Statement( const std::list<Label> & labels = {} ); 40 virtual ~Statement();41 40 42 41 std::list<Label> & get_labels() { return labels; } … … 56 55 CompoundStmt( std::list<Statement *> stmts ); 57 56 CompoundStmt( const CompoundStmt &other ); 58 virtual ~CompoundStmt();59 57 60 58 std::list<Statement*>& get_kids() { return kids; } … … 84 82 ExprStmt( Expression *expr ); 85 83 ExprStmt( const ExprStmt &other ); 86 virtual ~ExprStmt();87 84 88 85 Expression *get_expr() { return expr; } … … 105 102 AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); 106 103 AsmStmt( const AsmStmt &other ); 107 virtual ~AsmStmt();108 104 109 105 bool get_voltile() { return voltile; } … … 149 145 std::list<Statement *> initialization = std::list<Statement *>() ); 150 146 IfStmt( const IfStmt &other ); 151 virtual ~IfStmt();152 147 153 148 std::list<Statement *> &get_initialization() { return initialization; } … … 172 167 SwitchStmt( Expression *condition, const std::list<Statement *> &statements ); 173 168 SwitchStmt( const SwitchStmt &other ); 174 virtual ~SwitchStmt();175 169 176 170 Expression *get_condition() { return condition; } … … 194 188 CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException); 195 189 CaseStmt( const CaseStmt &other ); 196 virtual ~CaseStmt();197 190 198 191 static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() ); … … 226 219 Statement *body, std::list<Statement *> & initialization, bool isDoWhile = false ); 227 220 WhileStmt( const WhileStmt &other ); 228 virtual ~WhileStmt();229 221 230 222 Expression *get_condition() { return condition; } … … 251 243 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 252 244 ForStmt( const ForStmt &other ); 253 virtual ~ForStmt();254 245 255 246 std::list<Statement *> &get_initialization() { return initialization; } … … 304 295 ReturnStmt( Expression *expr ); 305 296 ReturnStmt( const ReturnStmt &other ); 306 virtual ~ReturnStmt();307 297 308 298 Expression *get_expr() { return expr; } … … 325 315 ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr ); 326 316 ThrowStmt( const ThrowStmt &other ); 327 virtual ~ThrowStmt();328 317 329 318 Kind get_kind() { return kind; } … … 347 336 TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 348 337 TryStmt( const TryStmt &other ); 349 virtual ~TryStmt();350 338 351 339 CompoundStmt *get_block() const { return block; } … … 374 362 Expression *cond, Statement *body ); 375 363 CatchStmt( const CatchStmt &other ); 376 virtual ~CatchStmt();377 364 378 365 Kind get_kind() { return kind; } … … 396 383 FinallyStmt( CompoundStmt *block ); 397 384 FinallyStmt( const FinallyStmt &other ); 398 virtual ~FinallyStmt();399 385 400 386 CompoundStmt *get_block() const { return block; } … … 423 409 WaitForStmt(); 424 410 WaitForStmt( const WaitForStmt & ); 425 virtual ~WaitForStmt();426 411 427 412 std::vector<Clause> clauses; … … 452 437 WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 453 438 WithStmt( const WithStmt & other ); 454 virtual ~WithStmt();455 439 456 440 virtual WithStmt * clone() const override { return new WithStmt( *this ); } … … 468 452 DeclStmt( Declaration *decl ); 469 453 DeclStmt( const DeclStmt &other ); 470 virtual ~DeclStmt();471 454 472 455 Declaration *get_decl() const { return decl; } … … 490 473 ImplicitCtorDtorStmt( Statement * callStmt ); 491 474 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ); 492 virtual ~ImplicitCtorDtorStmt();493 475 494 476 Statement *get_callStmt() const { return callStmt; } -
src/SynTree/TupleExpr.cc
r63238a4 r28f3a19 35 35 } 36 36 37 UntypedTupleExpr::~UntypedTupleExpr() {38 deleteAll( exprs );39 }40 41 37 void UntypedTupleExpr::print( std::ostream &os, Indenter indent ) const { 42 38 os << "Untyped Tuple:" << std::endl; … … 51 47 TupleExpr::TupleExpr( const TupleExpr &other ) : Expression( other ) { 52 48 cloneAll( other.exprs, exprs ); 53 }54 55 TupleExpr::~TupleExpr() {56 deleteAll( exprs );57 49 } 58 50 … … 72 64 73 65 TupleIndexExpr::TupleIndexExpr( const TupleIndexExpr &other ) : Expression( other ), tuple( other.tuple->clone() ), index( other.index ) { 74 }75 76 TupleIndexExpr::~TupleIndexExpr() {77 delete tuple;78 66 } 79 67 … … 105 93 } 106 94 107 TupleAssignExpr::~TupleAssignExpr() {108 delete stmtExpr;109 }110 111 95 void TupleAssignExpr::print( std::ostream &os, Indenter indent ) const { 112 96 os << "Tuple Assignment Expression, with stmt expr:" << std::endl; -
src/SynTree/TupleType.cc
r63238a4 r28f3a19 43 43 } 44 44 45 TupleType::~TupleType() {46 deleteAll( types );47 deleteAll( members );48 }49 50 45 void TupleType::print( std::ostream &os, Indenter indent ) const { 51 46 Type::print( os, indent ); -
src/SynTree/Type.cc
r63238a4 r28f3a19 63 63 } 64 64 65 Type::~Type() {66 deleteAll( forall );67 deleteAll( attributes );68 }69 70 65 // These must remain in the same order as the corresponding bit fields. 71 66 const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" }; -
src/SynTree/Type.h
r63238a4 r28f3a19 141 141 Type( const Qualifiers & tq, const std::list< Attribute * > & attributes ); 142 142 Type( const Type & other ); 143 virtual ~Type();144 143 145 144 Qualifiers & get_qualifiers() { return tq; } … … 263 262 PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 264 263 PointerType( const PointerType& ); 265 virtual ~PointerType();266 264 267 265 Type *get_base() { return base; } … … 293 291 ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 294 292 ArrayType( const ArrayType& ); 295 virtual ~ArrayType();296 293 297 294 Type *get_base() { return base; } … … 321 318 ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 322 319 ReferenceType( const ReferenceType & ); 323 virtual ~ReferenceType();324 320 325 321 Type *get_base() { return base; } … … 354 350 FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 355 351 FunctionType( const FunctionType& ); 356 virtual ~FunctionType();357 352 358 353 std::list<DeclarationWithType*> & get_returnVals() { return returnVals; } … … 378 373 ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes ); 379 374 ReferenceToType( const ReferenceToType & other ); 380 virtual ~ReferenceToType();381 375 382 376 const std::string & get_name() const { return name; } … … 505 499 TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 506 500 TraitInstType( const TraitInstType & other ); 507 ~TraitInstType();508 501 509 502 virtual bool isComplete() const override; … … 527 520 TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 528 521 TypeInstType( const TypeInstType & other ); 529 ~TypeInstType();530 522 531 523 TypeDecl *get_baseType() const { return baseType; } … … 551 543 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 552 544 TupleType( const TupleType& ); 553 virtual ~TupleType();554 545 555 546 typedef std::list<Type*> value_type; … … 585 576 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 586 577 TypeofType( const TypeofType& ); 587 virtual ~TypeofType();588 578 589 579 Expression *get_expr() const { return expr; } … … 608 598 AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 609 599 AttrType( const AttrType& ); 610 virtual ~AttrType();611 600 612 601 const std::string & get_name() const { return name; } -
src/SynTree/TypeDecl.cc
r63238a4 r28f3a19 25 25 26 26 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) { 27 }28 29 TypeDecl::~TypeDecl() {30 delete init;31 27 } 32 28 -
src/SynTree/TypeExpr.cc
r63238a4 r28f3a19 26 26 } 27 27 28 TypeExpr::~TypeExpr() {29 delete type;30 }31 32 28 void TypeExpr::print( std::ostream &os, Indenter indent ) const { 33 29 if ( type ) type->print( os, indent ); -
src/SynTree/TypeSubstitution.cc
r63238a4 r28f3a19 26 26 } 27 27 28 TypeSubstitution::~TypeSubstitution() {29 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {30 delete( i->second );31 }32 for ( VarEnvType::iterator i = varEnv.begin(); i != varEnv.end(); ++i ) {33 delete( i->second );34 }35 }36 37 28 TypeSubstitution &TypeSubstitution::operator=( const TypeSubstitution &other ) { 38 29 if ( this == &other ) return *this; … … 57 48 58 49 void TypeSubstitution::add( std::string formalType, Type *actualType ) { 59 TypeEnvType::iterator i = typeEnv.find( formalType );60 if ( i != typeEnv.end() ) {61 delete i->second;62 } // if63 50 typeEnv[ formalType ] = actualType->clone(); 64 51 } 65 52 66 53 void TypeSubstitution::remove( std::string formalType ) { 67 TypeEnvType::iterator i = typeEnv.find( formalType ); 68 if ( i != typeEnv.end() ) { 69 delete i->second; 70 typeEnv.erase( formalType ); 71 } // if 54 typeEnv.erase( formalType ); 72 55 } 73 56 … … 161 144 Type * newtype = i->second->clone(); 162 145 newtype->get_qualifiers() |= inst->get_qualifiers(); 163 delete inst;164 146 // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode. 165 147 return newtype->acceptMutator( *visitor ); … … 173 155 } else { 174 156 subCount++; 175 delete nameExpr;176 157 return i->second->clone(); 177 158 } // if -
src/SynTree/TypeSubstitution.h
r63238a4 r28f3a19 35 35 TypeSubstitution( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); 36 36 TypeSubstitution( const TypeSubstitution &other ); 37 virtual ~TypeSubstitution();38 37 39 38 TypeSubstitution &operator=( const TypeSubstitution &other ); … … 60 59 void normalize(); 61 60 61 void accept( Visitor& v ) { v.visit( this ); } 62 62 TypeSubstitution * acceptMutator( Mutator & m ) { return m.mutate( this ); } 63 63 … … 101 101 if ( TypeExpr *actual = dynamic_cast< TypeExpr* >( *actualIt ) ) { 102 102 if ( formal->get_name() != "" ) { 103 TypeEnvType::iterator i = typeEnv.find( formal->get_name() );104 if ( i != typeEnv.end() ) {105 delete i->second;106 } // if107 103 typeEnv[ formal->get_name() ] = actual->get_type()->clone(); 108 104 } // if -
src/SynTree/TypeofType.cc
r63238a4 r28f3a19 29 29 } 30 30 31 TypeofType::~TypeofType() {32 delete expr;33 }34 35 31 void TypeofType::print( std::ostream &os, Indenter indent ) const { 36 32 Type::print( os, indent ); -
src/SynTree/Visitor.h
r63238a4 r28f3a19 126 126 127 127 virtual void visit( Attribute * attribute ) = 0; 128 129 virtual void visit( TypeSubstitution * sub ) = 0; 128 130 }; 129 131 -
src/SynTree/module.mk
r63238a4 r28f3a19 48 48 SynTree/TypeSubstitution.cc \ 49 49 SynTree/Attribute.cc \ 50 SynTree/BaseSyntaxNode.cc \ 50 51 SynTree/DeclReplacer.cc 51 52 -
src/Tuples/Explode.cc
r63238a4 r28f3a19 70 70 // should now be a tuple of references rather than a reference to a tuple. 71 71 // Still, this code is a bit awkward, and could use some improvement. 72 UniqueExpr * newUniqueExpr = new UniqueExpr( applyCast( uniqueExpr->get_expr() ), uniqueExpr->get_id() ); 73 delete uniqueExpr; 72 UniqueExpr * newUniqueExpr = new UniqueExpr{ applyCast( uniqueExpr->get_expr() ), uniqueExpr->get_id() }; 74 73 if ( castAdded ) { 75 74 // if a cast was added by applyCast, then unique expr now has one more layer of reference … … 88 87 // field is consistent with the type of the tuple expr, since the field 89 88 // may have changed from type T to T&. 90 Expression * expr = tupleExpr->get_tuple(); 91 tupleExpr->set_tuple( nullptr ); 92 TupleIndexExpr * ret = new TupleIndexExpr( expr, tupleExpr->get_index() ); 93 delete tupleExpr; 94 return ret; 89 return new TupleIndexExpr( tupleExpr->get_tuple(), tupleExpr->get_index() ); 95 90 } 96 91 }; -
src/Tuples/Explode.h
r63238a4 r28f3a19 27 27 namespace SymTab { 28 28 class Indexer; 29 } // namespace SymTab 29 } // namespace SymTabf 30 30 31 31 namespace Tuples { … … 67 67 for ( ResolvExpr::Alternative & alt : alts ) { 68 68 // distribute reference cast over all components 69 append( std::forward<Output>(out), distributeReference( alt. release_expr()),69 append( std::forward<Output>(out), distributeReference( alt.expr ), 70 70 alt.env, alt.cost, alt.cvtCost ); 71 71 } … … 84 84 // tuple type, but not tuple expr - recursively index into its components. 85 85 // if expr type is reference, convert to value type 86 Expression * arg = expr ->clone();86 Expression * arg = expr; 87 87 if ( Tuples::maybeImpureIgnoreUnique( arg ) ) { 88 88 // expressions which may contain side effects require a single unique instance of the expression. … … 94 94 } 95 95 for ( unsigned int i = 0; i < tupleType->size(); i++ ) { 96 TupleIndexExpr * idx = new TupleIndexExpr( arg ->clone(), i );96 TupleIndexExpr * idx = new TupleIndexExpr( arg, i ); 97 97 explodeUnique( idx, alt, indexer, std::forward<Output>(out), isTupleAssign ); 98 delete idx;99 98 } 100 delete arg;101 99 } 102 100 } else { 103 // atomic (non-tuple) type - output a clone ofthe expression in a new alternative104 append( std::forward<Output>(out), expr ->clone(), alt.env, alt.cost, alt.cvtCost );101 // atomic (non-tuple) type - output the expression in a new alternative 102 append( std::forward<Output>(out), expr, alt.env, alt.cost, alt.cvtCost ); 105 103 } 106 104 } -
src/Tuples/TupleExpansion.cc
r63238a4 r28f3a19 46 46 47 47 std::map< int, Expression * > decls; // not vector, because order added may not be increasing order 48 49 ~UniqueExprExpander() {50 for ( std::pair<const int, Expression *> & p : decls ) {51 delete p.second;52 }53 }54 48 }; 55 49 … … 112 106 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->member, inner ); 113 107 inner->location = newMemberExpr->location = loc; 114 memberExpr->member = nullptr;115 memberExpr->aggregate = nullptr;116 delete memberExpr;117 108 return newMemberExpr->acceptMutator( expander ); 118 109 } else { … … 134 125 expr->location = memberExpr->location; 135 126 } 136 delete aggr;137 127 tupleExpr->location = memberExpr->location; 138 128 return tupleExpr; … … 180 170 decls[id] = condExpr; 181 171 } 182 delete unqExpr;183 172 return decls[id]->clone(); 184 173 } … … 190 179 ret->set_env( assnExpr->get_env() ); 191 180 assnExpr->set_env( nullptr ); 192 delete assnExpr;193 181 return ret; 194 182 } … … 221 209 newType->get_parameters().push_back( new TypeExpr( t->clone() ) ); 222 210 } 223 delete tupleType;224 211 return newType; 225 212 } … … 232 219 TypeSubstitution * env = tupleExpr->env; 233 220 tupleExpr->env = nullptr; 234 delete tupleExpr;235 221 236 222 if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * > ( tuple ) ) { … … 242 228 ret->env = env; 243 229 expr = nullptr; // remove from list so it can safely be deleted 244 delete tupleExpr;245 230 return ret; 246 231 } … … 287 272 TypeSubstitution * env = tupleExpr->get_env(); 288 273 289 // remove data from shell and delete it274 // remove data from shell 290 275 tupleExpr->set_result( nullptr ); 291 276 tupleExpr->get_exprs().clear(); 292 277 tupleExpr->set_env( nullptr ); 293 delete tupleExpr;294 278 295 279 return replaceTupleExpr( result, exprs, env ); -
src/Virtual/ExpandCasts.cc
r63238a4 r28f3a19 139 139 ObjectDecl * table = found->second; 140 140 141 Expression * result = new CastExpr(141 return new CastExpr{ 142 142 //new ApplicationExpr( 143 143 //new AddressExpr( new VariableExpr( vcast_decl ) ), … … 158 158 } ), 159 159 castExpr->get_result()->clone() 160 ); 161 162 castExpr->set_arg( nullptr ); 163 castExpr->set_result( nullptr ); 164 delete castExpr; 165 return result; 160 }; 166 161 } 167 162 -
src/main.cc
r63238a4 r28f3a19 1 1 2 // 2 3 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo … … 35 36 #include "CodeTools/TrackLoc.h" // for fillLocations 36 37 #include "Common/CompilerError.h" // for CompilerError 38 #include "Common/GC.h" // for GC 37 39 #include "Common/Heap.h" 38 40 #include "Common/PassVisitor.h" … … 57 59 #include "SymTab/Validate.h" // for validate 58 60 #include "SynTree/Declaration.h" // for Declaration 61 #include "SynTree/GcTracer.h" // for GC << TranslationUnit 59 62 #include "SynTree/Visitor.h" // for acceptAll 60 63 #include "Tuples/Tuples.h" // for expandMemberTuples, expan... … … 178 181 signal( SIGABRT, sigAbortHandler ); 179 182 180 // std::cout << "main" << std::endl;181 // for ( int i = 0; i < argc; i += 1 ) {182 // std::cout << '\t' << argv[i] << std::endl;183 // } // for184 185 183 parse_cmdline( argc, argv, filename ); // process command-line arguments 186 184 CodeGen::FixMain::setReplaceMain( !nomainp ); … … 241 239 delete parseTree; 242 240 parseTree = nullptr; 241 collect( translationUnit ); 243 242 244 243 if ( astp ) { … … 249 248 // add the assignment statement after the initialization of a type parameter 250 249 PASS( "validate", SymTab::validate( translationUnit, symtabp ) ); 251 if ( symtabp ) { 252 deleteAll( translationUnit ); 253 return 0; 254 } // if 250 if ( symtabp ) return 0; 251 collect( translationUnit ); 255 252 256 253 if ( expraltp ) { … … 269 266 PASS( "genInit", InitTweak::genInit( translationUnit ) ); 270 267 PASS( "expandMemberTuples" , Tuples::expandMemberTuples( translationUnit ) ); 268 collect( translationUnit ); 271 269 if ( libcfap ) { 272 270 // generate the bodies of cfa library functions … … 276 274 if ( declstatsp ) { 277 275 CodeTools::printDeclStats( translationUnit ); 278 deleteAll( translationUnit );279 276 return 0; 280 277 } … … 288 285 289 286 PASS( "resolve", ResolvExpr::resolve( translationUnit ) ); 287 collect( translationUnit ); 290 288 if ( exprp ) { 291 289 dump( translationUnit ); … … 295 293 // fix ObjectDecl - replaces ConstructorInit nodes 296 294 PASS( "fixInit", InitTweak::fix( translationUnit, filename, libcfap || treep ) ); 295 collect( translationUnit ); 297 296 if ( ctorinitp ) { 298 297 dump ( translationUnit ); … … 309 308 310 309 PASS( "expandTuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this? 311 310 collect( translationUnit ); 312 311 if ( tuplep ) { 313 312 dump( translationUnit ); … … 318 317 319 318 PASS( "instantiateGenerics", GenPoly::instantiateGeneric( translationUnit ) ); 319 collect( translationUnit ); 320 320 if ( genericsp ) { 321 321 dump( translationUnit ); … … 323 323 } 324 324 PASS( "convertLvalue", GenPoly::convertLvalue( translationUnit ) ); 325 326 325 collect( translationUnit ); 327 326 if ( bboxp ) { 328 327 dump( translationUnit ); … … 330 329 } // if 331 330 PASS( "box", GenPoly::box( translationUnit ) ); 332 331 collect( translationUnit ); 333 332 if ( bcodegenp ) { 334 333 dump( translationUnit ); … … 386 385 }// try 387 386 388 deleteAll( translationUnit );389 387 if(!libcfap && !treep) HeapStats::printStats(); 390 388 return 0; … … 601 599 printAll( decls, out ); 602 600 } 603 deleteAll( translationUnit );604 601 } // dump 605 602
Note: See TracChangeset
for help on using the changeset viewer.