Changes in / [9d5fb67:1cdfa82]
- Location:
- src
- Files:
-
- 4 added
- 90 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r9d5fb67 r1cdfa82 1145 1145 unsigned Indenter::tabsize = 2; 1146 1146 1147 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {1148 if ( node ) {1149 node->print( out );1150 } else {1151 out << "nullptr";1152 }1153 return out;1154 }1155 1156 1147 // Local Variables: // 1157 1148 // tab-width: 4 // -
src/CodeGen/FixMain.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 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 name; -
src/CodeGen/Generate.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 150 150 virtual void visit( Subrange * subrange ) override final; 151 151 152 virtual void visit( Constant * constant ) overridefinal;152 virtual void visit( Constant * constant ) final; 153 153 154 154 virtual void visit( Attribute * attribute ) override final; 155 156 virtual void visit( TypeSubstitution * sub ) final; 155 157 156 158 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override final; … … 247 249 virtual Subrange * mutate( Subrange * subrange ) override final; 248 250 249 virtual Constant * mutate( Constant * constant ) overridefinal;251 virtual Constant * mutate( Constant * constant ) final; 250 252 251 253 virtual Attribute * mutate( Attribute * attribute ) override final; -
src/Common/PassVisitor.impl.h
r9d5fb67 r1cdfa82 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 maybeAccept_impl( node->statements, *this ); … … 427 427 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 428 428 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 429 static ObjectDecl func(429 static ObjectDecl* func = new_static_root<ObjectDecl>( 430 430 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 431 431 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 432 432 nullptr 433 433 ); 434 indexerAddId( &func );434 indexerAddId( func ); 435 435 maybeMutate_impl( node->type, *this ); 436 436 maybeMutate_impl( node->statements, *this ); … … 1193 1193 indexerScopedAccept( node->result, *this ); 1194 1194 1195 // xxx - not quite sure why this doesn't visit( node->function ); 1195 1196 for ( auto expr : node->args ) { 1196 1197 visitExpression( expr ); … … 2599 2600 // TypeSubstitution 2600 2601 template< typename pass_type > 2602 void PassVisitor< pass_type >::visit( TypeSubstitution * node ) { 2603 VISIT_START( node ); 2604 2605 for ( auto & p : node->typeEnv ) { 2606 indexerScopedAccept( p.second, *this ); 2607 } 2608 for ( auto & p : node->varEnv ) { 2609 indexerScopedAccept( p.second, *this ); 2610 } 2611 2612 VISIT_END( node ); 2613 } 2614 2615 template< typename pass_type > 2601 2616 TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) { 2602 2617 MUTATE_START( node ); -
src/Common/module.mk
r9d5fb67 r1cdfa82 18 18 Common/UniqueName.cc \ 19 19 Common/DebugMalloc.cc \ 20 Common/GC.cc \ 20 21 Common/Assert.cc -
src/Common/utility.h
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 //----------------------------------------------------------------------------- … … 318 314 StructDecl * forward = decl->clone(); 319 315 forward->set_body( false ); 320 deleteAll( forward->get_members() );321 316 forward->get_members().clear(); 322 317 … … 382 377 fixupGenerics(main_type, decl); 383 378 } 384 385 delete this_decl;386 379 387 380 declsToAddBefore.push_back( forward ); -
src/Concurrency/Waitfor.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 441 441 Type * newType = arg->clone(); 442 442 if ( env ) env->apply( newType ); 443 std::unique_ptr<Type> manager( newType );444 443 // if the argument's type is polymorphic, we don't need to box again! 445 444 return ! isPolyType( newType ); -
src/GenPoly/InstantiateGeneric.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 ); … … 176 175 return ret; 177 176 } 178 delete result;179 177 } 180 178 return appExpr; … … 235 233 Type * baseType = InitTweak::getPointerBase( arg->result ); 236 234 assertf( baseType, "parameter is reference, arg must be pointer or reference: %s", toString( arg->result ).c_str() ); 237 PointerType * ptrType = new PointerType( Type::Qualifiers(), baseType->clone() ); 238 delete arg->result; 239 arg->result = ptrType; 235 arg->set_result( new PointerType( Type::Qualifiers(), baseType->clone() ) ); 240 236 arg = mkDeref( arg ); 241 237 // assertf( arg->result->referenceDepth() == 0, "Reference types should have been eliminated from intrinsic function calls, but weren't: %s", toCString( arg->result ) ); … … 409 405 } 410 406 ret->env = castExpr->env; 411 delete ret->result;412 407 ret->result = castExpr->result; 413 408 castExpr->env = nullptr; 414 409 castExpr->arg = nullptr; 415 410 castExpr->result = nullptr; 416 delete castExpr;417 411 return ret; 418 412 } else if ( diff < 0 ) { … … 430 424 } 431 425 ret->env = castExpr->env; 432 delete ret->result;433 426 ret->result = castExpr->result; 434 427 ret->result->set_lvalue( true ); // ensure result is lvalue … … 436 429 castExpr->arg = nullptr; 437 430 castExpr->result = nullptr; 438 delete castExpr;439 431 return ret; 440 432 } else { … … 451 443 castExpr->arg = nullptr; 452 444 std::swap( castExpr->env, ret->env ); 453 delete castExpr;454 445 return ret; 455 446 } … … 462 453 Type::Qualifiers qualifiers = refType->get_qualifiers(); 463 454 refType->base = nullptr; 464 delete refType;465 455 return new PointerType( qualifiers, base ); 466 456 } … … 474 464 ret->env = expr->env; 475 465 expr->env = nullptr; 476 delete expr;477 466 return ret; 478 467 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) { … … 483 472 ret->env = expr->env; 484 473 expr->env = nullptr; 485 delete expr;486 474 487 475 // conditional expr type may not be either of the argument types, need to unify … … 516 504 arg0 = nullptr; 517 505 addrExpr->env = nullptr; 518 delete addrExpr;519 506 return ret; 520 507 } … … 546 533 addrExpr->arg = nullptr; 547 534 appExpr->env = nullptr; 548 delete appExpr;549 535 return ret; 550 536 } -
src/GenPoly/ScrubTyVars.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 ControlStruct/driver_cfa_cpp-LabelGenerator.$(OBJEXT) \ … … 249 250 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \ 250 251 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \ 252 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT) \ 251 253 SynTree/driver_cfa_cpp-DeclReplacer.$(OBJEXT) \ 252 254 Tuples/driver_cfa_cpp-TupleAssignment.$(OBJEXT) \ … … 485 487 CodeTools/TrackLoc.cc Concurrency/Keywords.cc \ 486 488 Concurrency/Waitfor.cc Common/SemanticError.cc \ 487 Common/UniqueName.cc Common/DebugMalloc.cc Common/ Assert.cc \488 Co ntrolStruct/LabelGenerator.cc ControlStruct/LabelFixer.cc \489 ControlStruct/ MLEMutator.cc ControlStruct/Mutate.cc \490 ControlStruct/ ForExprMutator.cc \489 Common/UniqueName.cc Common/DebugMalloc.cc Common/GC.cc \ 490 Common/Assert.cc ControlStruct/LabelGenerator.cc \ 491 ControlStruct/LabelFixer.cc ControlStruct/MLEMutator.cc \ 492 ControlStruct/Mutate.cc ControlStruct/ForExprMutator.cc \ 491 493 ControlStruct/ExceptTranslate.cc GenPoly/Box.cc \ 492 494 GenPoly/GenPoly.cc GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc \ … … 526 528 SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \ 527 529 SynTree/Initializer.cc SynTree/TypeSubstitution.cc \ 528 SynTree/Attribute.cc SynTree/DeclReplacer.cc \ 529 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 530 Tuples/Explode.cc Virtual/ExpandCasts.cc 530 SynTree/Attribute.cc SynTree/BaseSyntaxNode.cc \ 531 SynTree/DeclReplacer.cc Tuples/TupleAssignment.cc \ 532 Tuples/TupleExpansion.cc Tuples/Explode.cc \ 533 Virtual/ExpandCasts.cc 531 534 MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \ 532 535 ${cfa_cpplib_PROGRAMS}} … … 670 673 Common/$(DEPDIR)/$(am__dirstamp) 671 674 Common/driver_cfa_cpp-DebugMalloc.$(OBJEXT): Common/$(am__dirstamp) \ 675 Common/$(DEPDIR)/$(am__dirstamp) 676 Common/driver_cfa_cpp-GC.$(OBJEXT): Common/$(am__dirstamp) \ 672 677 Common/$(DEPDIR)/$(am__dirstamp) 673 678 Common/driver_cfa_cpp-Assert.$(OBJEXT): Common/$(am__dirstamp) \ … … 912 917 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \ 913 918 SynTree/$(DEPDIR)/$(am__dirstamp) 919 SynTree/driver_cfa_cpp-BaseSyntaxNode.$(OBJEXT): \ 920 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) 914 921 SynTree/driver_cfa_cpp-DeclReplacer.$(OBJEXT): \ 915 922 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) … … 973 980 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-Assert.Po@am__quote@ 974 981 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-DebugMalloc.Po@am__quote@ 982 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-GC.Po@am__quote@ 975 983 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-SemanticError.Po@am__quote@ 976 984 @AMDEP_TRUE@@am__include@ @am__quote@Common/$(DEPDIR)/driver_cfa_cpp-UniqueName.Po@am__quote@ … … 1035 1043 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@ 1036 1044 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@ 1045 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po@am__quote@ 1037 1046 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@ 1038 1047 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@ … … 1294 1303 @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` 1295 1304 1305 Common/driver_cfa_cpp-GC.o: Common/GC.cc 1306 @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 1307 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo Common/$(DEPDIR)/driver_cfa_cpp-GC.Po 1308 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='Common/GC.cc' object='Common/driver_cfa_cpp-GC.o' libtool=no @AMDEPBACKSLASH@ 1309 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1310 @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 1311 1312 Common/driver_cfa_cpp-GC.obj: Common/GC.cc 1313 @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` 1314 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) Common/$(DEPDIR)/driver_cfa_cpp-GC.Tpo Common/$(DEPDIR)/driver_cfa_cpp-GC.Po 1315 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='Common/GC.cc' object='Common/driver_cfa_cpp-GC.obj' libtool=no @AMDEPBACKSLASH@ 1316 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1317 @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` 1318 1296 1319 Common/driver_cfa_cpp-Assert.o: Common/Assert.cc 1297 1320 @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 … … 2497 2520 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2498 2521 @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` 2522 2523 SynTree/driver_cfa_cpp-BaseSyntaxNode.o: SynTree/BaseSyntaxNode.cc 2524 @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 2525 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po 2526 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.o' libtool=no @AMDEPBACKSLASH@ 2527 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2528 @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 2529 2530 SynTree/driver_cfa_cpp-BaseSyntaxNode.obj: SynTree/BaseSyntaxNode.cc 2531 @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` 2532 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-BaseSyntaxNode.Po 2533 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='SynTree/BaseSyntaxNode.cc' object='SynTree/driver_cfa_cpp-BaseSyntaxNode.obj' libtool=no @AMDEPBACKSLASH@ 2534 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2535 @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` 2499 2536 2500 2537 SynTree/driver_cfa_cpp-DeclReplacer.o: SynTree/DeclReplacer.cc -
src/Parser/DeclarationNode.cc
r9d5fb67 r1cdfa82 1009 1009 obj->location = cur->location; 1010 1010 * out++ = obj; 1011 delete agg;1012 1011 } else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) { 1013 1012 UnionInstType * inst = new UnionInstType( Type::Qualifiers(), agg->get_name() ); -
src/Parser/ExpressionNode.cc
r9d5fb67 r1cdfa82 407 407 Type * targetType = maybeMoveBuildType( decl_node ); 408 408 if ( dynamic_cast< VoidType * >( targetType ) ) { 409 delete targetType;410 409 return new CastExpr( maybeMoveBuild< Expression >(expr_node), false ); 411 410 } else { … … 435 434 436 435 Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) { 437 Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() ); 438 delete member; 439 return ret; 436 return new UntypedOffsetofExpr{ maybeMoveBuildType( decl_node ), member->get_name() }; 440 437 } // build_offsetOf 441 438 -
src/Parser/ParseNode.h
r9d5fb67 r1cdfa82 124 124 125 125 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 126 os << expr .get()<< std::endl;126 os << expr << std::endl; 127 127 } 128 128 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 129 129 130 130 template<typename T> 131 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr .get()); }132 133 Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }131 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr); } 132 133 Expression * build() const { return expr; } 134 134 private: 135 135 bool extension = false; 136 std::unique_ptr<Expression>expr;136 Expression* expr; 137 137 }; // ExpressionNode 138 138 … … 360 360 361 361 virtual StatementNode * clone() const final { assert( false ); return nullptr; } 362 Statement * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }362 Statement * build() const { return stmt; } 363 363 364 364 virtual StatementNode * add_label( const std::string * name, DeclarationNode * attr = nullptr ) { … … 372 372 373 373 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 374 os << stmt .get()<< std::endl;374 os << stmt << std::endl; 375 375 } 376 376 private: 377 std::unique_ptr<Statement>stmt;377 Statement* stmt; 378 378 }; // StatementNode 379 379 -
src/Parser/StatementNode.cc
r9d5fb67 r1cdfa82 16 16 #include <cassert> // for assert, strict_dynamic_cast, assertf 17 17 #include <list> // for list 18 #include <memory> // for unique_ptr19 18 #include <string> // for string 20 19 … … 50 49 agg = decl; 51 50 } // if 52 stmt .reset( new DeclStmt( maybeMoveBuild< Declaration >(agg) ) );51 stmt = new DeclStmt{ maybeMoveBuild< Declaration >(agg) }; 53 52 } // StatementNode::StatementNode 54 53 … … 58 57 for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) { 59 58 StatementNode *node = strict_dynamic_cast< StatementNode * >(curr); 60 assert( dynamic_cast< CaseStmt * >(node->stmt .get()) );59 assert( dynamic_cast< CaseStmt * >(node->stmt) ); 61 60 prev = curr; 62 61 } // for … … 66 65 buildMoveList( stmt, stmts ); 67 66 // splice any new Statements to end of current Statements 68 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt .get());67 CaseStmt * caseStmt = dynamic_cast< CaseStmt * >(node->stmt); 69 68 caseStmt->get_statements().splice( caseStmt->get_statements().end(), stmts ); 70 69 return this; -
src/ResolvExpr/AdjustExprType.cc
r9d5fb67 r1cdfa82 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 74 71 Type * AdjustExprType::postmutate( FunctionType * functionType ) { 75 return new PointerType ( Type::Qualifiers(), functionType );72 return new PointerType{ Type::Qualifiers(), functionType }; 76 73 } 77 74 … … 80 77 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { 81 78 if ( eqvClass.data.kind == TypeDecl::Ftype ) { 82 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 83 return pointerType; 79 return new PointerType{ Type::Qualifiers(), typeInst }; 84 80 } 85 81 } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 86 82 if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { 87 83 if ( tyDecl->get_kind() == TypeDecl::Ftype ) { 88 PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); 89 return pointerType; 84 return new PointerType{ Type::Qualifiers(), typeInst }; 90 85 } // if 91 86 } // if -
src/ResolvExpr/Alternative.cc
r9d5fb67 r1cdfa82 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;47 return *this;48 }49 50 Alternative::Alternative( Alternative && other ) : cost( other.cost ), cvtCost( other.cvtCost ), expr( other.expr ), env( 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 = other.env;61 other.expr = nullptr;62 return *this;63 }64 65 Alternative::~Alternative() {66 delete expr;67 }68 39 69 40 void Alternative::print( std::ostream &os, Indenter indent ) const { … … 96 67 } 97 68 69 const GC& operator<< ( const GC& gc, const Alternative& alt ) { 70 PassVisitor<GcTracer> tracer{ gc }; 71 maybeAccept( alt.expr, tracer ); 72 tracer << alt.env; 73 return gc; 74 } 75 98 76 } // namespace ResolvExpr 99 77 -
src/ResolvExpr/Alternative.h
r9d5fb67 r1cdfa82 24 24 class Expression; 25 25 26 class GC; 27 26 28 namespace ResolvExpr { 27 29 struct Alternative { … … 29 31 Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost ); 30 32 Alternative( Expression *expr, const TypeEnvironment &env, const Cost &cost, const Cost &cvtCost ); 31 Alternative( const Alternative &other ); 32 Alternative &operator=( const Alternative &other ); 33 Alternative( Alternative && other ); 34 Alternative &operator=( Alternative && other ); 35 ~Alternative(); 33 Alternative( const Alternative &other ) = default; 34 Alternative &operator=( const Alternative &other ) = default; 36 35 37 36 void print( std::ostream &os, Indenter indent = {} ) const; 38 37 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 38 Cost cost; 47 39 Cost cvtCost; 48 Expression * expr;40 Expression * expr; 49 41 TypeEnvironment env; 50 42 }; … … 62 54 return os; 63 55 } 56 57 const GC& operator<< ( const GC&, const Alternative& ); 64 58 } // namespace ResolvExpr 65 59 -
src/ResolvExpr/AlternativeFinder.cc
r9d5fb67 r1cdfa82 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 … … 101 102 void addAnonConversions( const Alternative & alt ); 102 103 /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member 103 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member);104 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ); 104 105 /// Adds alternatives for member expressions where the left side has tuple type 105 106 void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ); … … 165 166 candidate->env.apply( newType ); 166 167 mangleName = SymTab::Mangler::mangle( newType ); 167 delete newType;168 168 } 169 169 std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName ); … … 297 297 // adds anonymous member interpretations whenever an aggregate value type is seen. 298 298 // 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 299 std::unique_ptr<Expression> aggrExpr( alt.expr->clone());299 Expression* aggrExpr = alt.expr->clone(); 300 300 alt.env.apply( aggrExpr->get_result() ); 301 301 Type * aggrType = aggrExpr->get_result(); 302 302 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 303 303 aggrType = aggrType->stripReferences(); 304 aggrExpr .reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );304 aggrExpr = new CastExpr{ aggrExpr, aggrType->clone() }; 305 305 } 306 306 307 307 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 308 NameExpr nameExpr( "" ); 309 addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 308 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 310 309 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 311 NameExpr nameExpr( "" ); 312 addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 310 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 313 311 } // if 314 312 } 315 313 316 314 template< typename StructOrUnionType > 317 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) { 318 // by this point, member must be a name expr 319 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ); 320 if ( ! nameExpr ) return; 321 const std::string & name = nameExpr->get_name(); 315 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ) { 322 316 std::list< Declaration* > members; 323 317 aggInst->lookup( name, members ); … … 568 562 569 563 Expression *varExpr = data.combine( newerAlt.cvtCost ); 570 delete varExpr->get_result();571 564 varExpr->set_result( adjType->clone() ); 572 565 PRINT( … … 585 578 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 586 579 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out ); 587 } else {588 delete adjType;589 580 } 590 581 } … … 634 625 struct ArgPack { 635 626 std::size_t parent; ///< Index of parent pack 636 std::unique_ptr<Expression> expr;///< The argument stored here627 Expression* expr; ///< The argument stored here 637 628 Cost cost; ///< The cost of this argument 638 629 TypeEnvironment env; ///< Environment for this pack … … 681 672 std::list<Expression*> exprs; 682 673 const ArgPack* pack = this; 683 if ( expr ) { exprs.push_front( expr .release()); }674 if ( expr ) { exprs.push_front( expr ); } 684 675 while ( pack->tupleStart == 0 ) { 685 676 pack = &packs[pack->parent]; … … 688 679 } 689 680 // reset pack to appropriate tuple 690 expr .reset( new TupleExpr( exprs ) );681 expr = new TupleExpr{ exprs }; 691 682 tupleStart = pack->tupleStart - 1; 692 683 parent = pack->parent; … … 740 731 741 732 results.emplace_back( 742 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),733 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 743 734 copy(results[i].need), copy(results[i].have), 744 735 copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl, … … 761 752 newResult.parent = i; 762 753 std::list<Expression*> emptyList; 763 newResult.expr .reset( new TupleExpr( emptyList ) );754 newResult.expr = new TupleExpr{ emptyList }; 764 755 argType = newResult.expr->get_result(); 765 756 } else { … … 768 759 newResult.cost = results[i].cost; 769 760 newResult.tupleStart = results[i].tupleStart; 770 newResult.expr .reset( results[i].expr->clone());761 newResult.expr = results[i].expr->clone(); 771 762 argType = newResult.expr->get_result(); 772 763 … … 818 809 // add new result 819 810 results.emplace_back( 820 i, expl.exprs.front() .get(), move(env), copy(results[i].need),811 i, expl.exprs.front(), move(env), copy(results[i].need), 821 812 copy(results[i].have), move(openVars), nextArg + 1, 822 813 nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 844 835 if ( results[i].hasExpl() ) { 845 836 const ExplodedActual& expl = results[i].getExpl( args ); 846 Expression* expr = expl.exprs[results[i].nextExpl] .get();837 Expression* expr = expl.exprs[results[i].nextExpl]; 847 838 848 839 TypeEnvironment env = results[i].env; … … 915 906 916 907 // consider only first exploded actual 917 Expression* expr = expl.exprs.front() .get();908 Expression* expr = expl.exprs.front(); 918 909 Type* actualType = expr->get_result()->clone(); 919 910 … … 1018 1009 1019 1010 results.emplace_back( 1020 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),1011 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 1021 1012 copy(results[i].need), copy(results[i].have), 1022 1013 copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl, … … 1054 1045 // add new result 1055 1046 results.emplace_back( 1056 i, expl.exprs.front() .get(), move(env), copy(results[i].need),1047 i, expl.exprs.front(), move(env), copy(results[i].need), 1057 1048 copy(results[i].have), move(openVars), nextArg + 1, 0, 1058 1049 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 1088 1079 1089 1080 // find function operators 1090 static NameExpr *opExpr = new NameExpr( "?()" );1081 static auto *opExpr = new_static_root<NameExpr>( "?()" ); 1091 1082 AlternativeFinder funcOpFinder( indexer, env ); 1092 1083 // it's ok if there aren't any defined function ops 1093 funcOpFinder.maybeFind( opExpr );1084 funcOpFinder.maybeFind( opExpr ); 1094 1085 PRINT( 1095 1086 std::cerr << "known function ops:" << std::endl; … … 1264 1255 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 1265 1256 } 1266 delete argExpr;1267 1257 assert( componentExprs.size() > 0 ); 1268 1258 // produce the tuple of casts … … 1343 1333 } 1344 1334 1335 namespace { 1336 /// Gets name from untyped member expression (member must be NameExpr) 1337 const std::string& get_member_name( UntypedMemberExpr *memberExpr ) { 1338 NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() ); 1339 assert( nameExpr ); 1340 return nameExpr->get_name(); 1341 } 1342 } 1343 1345 1344 void AlternativeFinder::Finder::postvisit( UntypedMemberExpr *memberExpr ) { 1346 1345 AlternativeFinder funcFinder( indexer, env ); … … 1351 1350 Expression * aggrExpr = agg->expr->clone(); 1352 1351 referenceToRvalueConversion( aggrExpr, cost ); 1353 std::unique_ptr<Expression> guard( aggrExpr );1354 1352 1355 1353 // find member of the given type 1356 1354 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 1357 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1355 addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1358 1356 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 1359 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1357 addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1360 1358 } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) { 1361 1359 addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() ); … … 1602 1600 alternatives.push_back( Alternative( new CommaExpr( newFirstArg->clone(), alt.expr->clone() ), alt.env, alt.cost ) ); 1603 1601 } // for 1604 delete newFirstArg;1605 1602 } 1606 1603 -
src/ResolvExpr/ConversionCost.cc
r9d5fb67 r1cdfa82 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 … … 351 352 void ConversionCost::postvisit( EnumInstType * ) { 352 353 static Type::Qualifiers q; 353 static BasicType integer( q, BasicType::SignedInt );354 cost = costFunc( &integer, dest, indexer, env ); // safe if dest >= int354 static BasicType* integer = new_static_root<BasicType>( q, BasicType::SignedInt ); 355 cost = costFunc( integer, dest, indexer, env ); // safe if dest >= int 355 356 if ( cost < Cost::unsafe ) { 356 357 cost.incSafe(); -
src/ResolvExpr/ExplodedActual.h
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 … … 139 140 castExpr->arg = nullptr; 140 141 std::swap( expr->env, castExpr->env ); 141 delete castExpr;142 142 } 143 143 } … … 148 148 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) { 149 149 assertf( untyped, "expected a non-null expression." ); 150 151 auto guard = new_generation(); // set up GC generation for this top-level expression 152 150 153 TypeEnvironment env; 151 154 AlternativeFinder finder( indexer, env ); … … 175 178 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 176 179 if ( winners.size() == 0 ) { 177 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") ); 180 SemanticError( untyped, toString( 181 "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), 182 "expression: ") ); 178 183 } else if ( winners.size() != 1 ) { 179 184 std::ostringstream stream; 180 stream << "Cannot choose between " << winners.size() << " alternatives for " << kindStr << (kindStr != "" ? " " : "") << "expression\n"; 185 stream << "Cannot choose between " << winners.size() << " alternatives for " 186 << kindStr << (kindStr != "" ? " " : "") << "expression\n"; 181 187 untyped->print( stream ); 182 188 stream << " Alternatives are:\n"; 183 189 printAlts( winners, stream, 1 ); 190 184 191 SemanticError( untyped->location, stream.str() ); 185 192 } … … 188 195 Alternative & choice = winners.front(); 189 196 if ( findDeletedExpr( choice.expr ) ) { 190 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 197 trace( choice.expr ); 198 SemanticError( choice.expr, 199 "Unique best alternative includes deleted identifier in " ); 191 200 } 192 201 alt = std::move( choice ); 202 trace( alt ); 193 203 } 194 204 … … 199 209 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast ); 200 210 finishExpr( choice.expr, choice.env, untyped->env ); 201 delete untyped;202 211 untyped = choice.expr; 203 212 choice.expr = nullptr; … … 222 231 assertf( expr, "expected a non-null expression." ); 223 232 224 static CastExpr untyped( nullptr ); // cast to void233 auto untyped = new CastExpr{ expr }; // cast to void 225 234 226 235 // set up and resolve expression cast to void 227 untyped.arg = expr;228 236 Alternative choice; 229 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, true );237 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true ); 230 238 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 231 239 env = std::move( choice.env ); 232 240 233 241 // clean up resolved expression 234 Expression * ret = castExpr->arg; 235 castExpr->arg = nullptr; 236 237 // unlink the arg so that it isn't deleted twice at the end of the program 238 untyped.arg = nullptr; 239 return ret; 242 return castExpr->arg; 240 243 } 241 244 … … 245 248 Expression * newExpr = resolveInVoidContext( untyped, indexer, env ); 246 249 finishExpr( newExpr, env, untyped->env ); 247 delete untyped;248 250 untyped = newExpr; 249 251 } … … 423 425 caseStmt->condition = castExpr->arg; 424 426 castExpr->arg = nullptr; 425 delete castExpr;426 427 } 427 428 } … … 705 706 std::swap( initExpr->env, newExpr->env ); 706 707 std::swap( initExpr->inferParams, newExpr->inferParams ) ; 707 delete initExpr;708 708 709 709 // get the actual object's type (may not exactly match what comes back from the resolver due to conversions) … … 723 723 ce->set_arg( nullptr ); 724 724 std::swap( ce->env, newExpr->env ); 725 delete ce;726 725 } 727 726 } … … 774 773 // could not find valid constructor, or found an intrinsic constructor 775 774 // fall back on C-style initializer 776 delete ctorInit->get_ctor(); 777 ctorInit->set_ctor( NULL ); 778 delete ctorInit->get_dtor(); 779 ctorInit->set_dtor( NULL ); 775 ctorInit->set_ctor( nullptr ); 776 ctorInit->set_dtor( nullptr ); 780 777 maybeAccept( ctorInit->get_init(), *visitor ); 781 778 } … … 803 800 804 801 // found a constructor - can get rid of C-style initializer 805 delete ctorInit->init;806 802 ctorInit->init = nullptr; 807 803 … … 810 806 // to clean up generated code. 811 807 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) { 812 delete ctorInit->ctor;813 808 ctorInit->ctor = nullptr; 814 809 } 815 810 816 811 if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) { 817 delete ctorInit->dtor;818 812 ctorInit->dtor = nullptr; 819 813 } -
src/ResolvExpr/TypeEnvironment.cc
r9d5fb67 r1cdfa82 19 19 #include <utility> // for pair 20 20 21 #include "Common/PassVisitor.h" // for PassVisitor<GcTracer> 21 22 #include "Common/utility.h" // for maybeClone 23 #include "SynTree/GcTracer.h" // for PassVisitor<GcTracer> 22 24 #include "SynTree/Type.h" // for Type, FunctionType, Type::Fora... 23 25 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution … … 59 61 EqvClass &EqvClass::operator=( const EqvClass &other ) { 60 62 if ( this == &other ) return *this; 61 delete type;62 63 initialize( other, *this ); 63 64 return *this; 64 }65 66 EqvClass::~EqvClass() {67 delete type;68 65 } 69 66 … … 147 144 /// std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl; 148 145 sub.add( *theVar, newTypeInst ); 149 delete newTypeInst;150 146 } // if 151 147 } // for … … 188 184 if ( secondClass->type ) { 189 185 if ( newClass.type ) { 190 Type *newType = combineFunc( newClass.type, secondClass->type ); 191 delete newClass.type; 192 newClass.type = newType; 186 newClass.type = combineFunc( newClass.type, secondClass->type ); 193 187 newClass.allowWidening = newClass.allowWidening && secondClass->allowWidening; 194 188 } else { … … 230 224 return out; 231 225 } 226 227 PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ) { 228 for ( const EqvClass & c : env ) { 229 maybeAccept( c.type, gc ); 230 } 231 return gc; 232 } 232 233 } // namespace ResolvExpr 233 234 -
src/ResolvExpr/TypeEnvironment.h
r9d5fb67 r1cdfa82 26 26 #include "SynTree/Type.h" // for Type, Type::ForallList 27 27 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 28 29 template< typename Pass > 30 class PassVisitor; 31 class GcTracer; 28 32 29 33 namespace ResolvExpr { … … 67 71 EqvClass( const EqvClass &other ); 68 72 EqvClass &operator=( const EqvClass &other ); 69 ~EqvClass();70 73 void print( std::ostream &os, Indenter indent = {} ) const; 71 74 }; … … 117 120 118 121 std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ); 122 123 PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ); 119 124 } // namespace ResolvExpr 120 125 -
src/ResolvExpr/Unify.cc
r9d5fb67 r1cdfa82 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 … … 171 164 Type *common = 0; 172 165 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 173 std::unique_ptr< Type > newType( curClass.type->clone());166 Type* newType = curClass.type->clone(); 174 167 newType->get_qualifiers() = typeInst->get_qualifiers(); 175 if ( unifyInexact( newType .get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) {168 if ( unifyInexact( newType, other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) { 176 169 if ( common ) { 177 170 common->get_qualifiers() = Type::Qualifiers(); 178 delete curClass.type;179 171 curClass.type = common; 180 172 env.add( curClass ); … … 239 231 if ( common ) { 240 232 common->get_qualifiers() = Type::Qualifiers(); 241 delete class1.type;242 233 class1.type = common; 243 234 } // if … … 272 263 env.add( newClass ); 273 264 } // if 274 delete type1;275 delete type2;276 265 return result; 277 266 } … … 282 271 findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true ); 283 272 Type *commonType = 0; 284 if ( unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) { 285 if ( commonType ) { 286 delete commonType; 287 } // if 288 return true; 289 } else { 290 return false; 291 } // if 273 return unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ); 292 274 } 293 275 … … 483 465 484 466 template< typename Iterator, typename Func > 485 std::unique_ptr<Type>combineTypes( Iterator begin, Iterator end, Func & toType ) {467 Type* combineTypes( Iterator begin, Iterator end, Func & toType ) { 486 468 std::list< Type * > types; 487 469 for ( ; begin != end; ++begin ) { … … 489 471 flatten( toType( *begin ), back_inserter( types ) ); 490 472 } 491 return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );473 return new TupleType{ Type::Qualifiers(), types }; 492 474 } 493 475 … … 504 486 if ( isTtype1 && ! isTtype2 ) { 505 487 // combine all of the things in list2, then unify 506 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );488 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 507 489 } else if ( isTtype2 && ! isTtype1 ) { 508 490 // combine all of the things in list1, then unify 509 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );491 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 510 492 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 511 493 return false; … … 517 499 Type * t1 = (*list1Begin)->get_type(); 518 500 if ( Tuples::isTtype( t1 ) ) { 519 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );501 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 520 502 } else return false; 521 503 } else if ( list2Begin != list2End ) { … … 523 505 Type * t2 = (*list2Begin)->get_type(); 524 506 if ( Tuples::isTtype( t2 ) ) { 525 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );507 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 526 508 } else return false; 527 509 } else { … … 544 526 // expand ttype parameter into its actual type 545 527 if ( eqvClass.type ) { 546 delete typeInst;547 528 return eqvClass.type->clone(); 548 529 } … … 569 550 dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) ); 570 551 } 571 delete dcl;572 552 } 573 553 } … … 578 558 // flatten the parameter lists for both functions so that tuple structure 579 559 // doesn't affect unification. Must be a clone so that the types don't change. 580 std::unique_ptr<FunctionType> flatFunc( functionType->clone());581 std::unique_ptr<FunctionType> flatOther( otherFunction->clone());560 FunctionType* flatFunc = functionType->clone(); 561 FunctionType* flatOther = otherFunction->clone(); 582 562 flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env ); 583 563 flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env ); … … 720 700 if ( isTtype1 && ! isTtype2 ) { 721 701 // combine all of the things in list2, then unify 722 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );702 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 723 703 } else if ( isTtype2 && ! isTtype1 ) { 724 704 // combine all of the things in list1, then unify 725 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );705 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 726 706 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 727 707 return false; … … 733 713 Type * t1 = *list1Begin; 734 714 if ( Tuples::isTtype( t1 ) ) { 735 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );715 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 736 716 } else return false; 737 717 } else if ( list2Begin != list2End ) { … … 739 719 Type * t2 = *list2Begin; 740 720 if ( Tuples::isTtype( t2 ) ) { 741 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );721 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 742 722 } else return false; 743 723 } else { … … 748 728 void Unify::postvisit(TupleType *tupleType) { 749 729 if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) { 750 std::unique_ptr<TupleType> flat1( tupleType->clone());751 std::unique_ptr<TupleType> flat2( otherTuple->clone());730 TupleType* flat1 = tupleType->clone(); 731 TupleType* flat2 = otherTuple->clone(); 752 732 std::list<Type *> types1, types2; 753 733 … … 756 736 flat2->acceptMutator( expander ); 757 737 758 flatten( flat1 .get(), back_inserter( types1 ) );759 flatten( flat2 .get(), back_inserter( types2 ) );738 flatten( flat1, back_inserter( types1 ) ); 739 flatten( flat2, back_inserter( types2 ) ); 760 740 761 741 result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, indexer ); -
src/ResolvExpr/Unify.h
r9d5fb67 r1cdfa82 64 64 bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 65 65 std::list< Type* > commonTypes; 66 if ( unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ) ) { 67 deleteAll( commonTypes ); 68 return true; 69 } else { 70 return false; 71 } // if 66 return unifyList( list1Begin, list1End, list2Begin, list2End, env, needAssertions, haveAssertions, openVars, indexer, commonTypes ); 72 67 } 73 68 -
src/SymTab/Autogen.cc
r9d5fb67 r1cdfa82 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 err ) { 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 "Common/PassVisitor.h" // for PassVisitor, WithDeclsToAdd 51 52 #include "Common/ScopedMap.h" // for ScopedMap … … 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; … … 373 373 // one void is the only thing in the list; remove it. 374 374 if ( containsVoid ) { 375 delete dwts.front();376 375 dwts.clear(); 377 376 } … … 500 499 } 501 500 } 502 deleteAll( td->assertions );503 501 td->assertions.clear(); 504 502 } // for … … 616 614 // expand trait instance into all of its members 617 615 expandAssertions( traitInst, back_inserter( type->assertions ) ); 618 delete traitInst;619 616 } else { 620 617 // pass other assertions through … … 688 685 // grab and remember declaration of size_t 689 686 SizeType = eliminator.pass.typedefNames["size_t"].first->get_base()->clone(); 687 GC::get().register_static_root( SizeType ); 690 688 } else { 691 689 // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong 692 690 // eventually should have a warning for this case. 693 SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 691 SizeType = 692 new_static_root<BasicType>( Type::Qualifiers(), BasicType::LongUnsignedInt ); 694 693 } 695 694 filter( translationUnit, isTypedef, true ); … … 707 706 ret->attributes.splice( ret->attributes.end(), typeInst->attributes ); 708 707 } else { 709 deleteAll( ret->attributes );710 708 ret->attributes.clear(); 711 709 } … … 720 718 mutateAll( rtt->parameters, *visitor ); // recursively fix typedefs on parameters 721 719 } // if 722 delete typeInst;723 720 return ret; 724 721 } else { … … 762 759 } 763 760 } else { 764 typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );761 typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 765 762 } // if 766 763 … … 806 803 if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->get_type() ) ) { // function type? 807 804 // replace the current object declaration with a function declaration 808 FunctionDecl * newDecl = new FunctionDecl( objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() ); 809 objDecl->get_attributes().clear(); 810 objDecl->set_type( nullptr ); 811 delete objDecl; 812 return newDecl; 805 return new FunctionDecl{ 806 objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), 807 funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() }; 813 808 } // if 814 809 return objDecl; … … 857 852 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 858 853 } // if 859 TypedefDecl Ptr tyDecl( new TypedefDecl( aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() ) );860 typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );854 TypedefDecl* tyDecl = new TypedefDecl{ aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() }; 855 typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel ); 861 856 } // if 862 857 } … … 972 967 static UniqueName indexName( "_compLit" ); 973 968 974 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() ); 975 compLitExpr->set_result( nullptr ); 976 compLitExpr->set_initializer( nullptr ); 977 delete compLitExpr; 969 ObjectDecl * tempvar = new ObjectDecl{ 970 indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() }; 978 971 declsToAddBefore.push_back( tempvar ); // add modified temporary to current block 979 972 return new VariableExpr( tempvar ); … … 1011 1004 // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false. 1012 1005 ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) ); 1013 deleteAll( retVals );1014 1006 retVals.clear(); 1015 1007 retVals.push_back( newRet ); … … 1052 1044 if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) { 1053 1045 if ( labels.count( nameExpr->name ) ) { 1054 Label name = nameExpr->name; 1055 delete addrExpr; 1056 return new LabelAddressExpr( name ); 1046 return new LabelAddressExpr{ nameExpr->name }; 1057 1047 } 1058 1048 } -
src/SynTree/AddressExpr.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 ApplicationExpr::ApplicationExpr( Expression *funcExpr, const std::list<Expression *> & args ) : function( funcExpr ), args( args ) { 52 45 PointerType *pointer = strict_dynamic_cast< PointerType* >( funcExpr->get_result() ); … … 61 54 Expression( other ), function( maybeClone( other.function ) ) { 62 55 cloneAll( other.args, args ); 63 }64 65 ApplicationExpr::~ApplicationExpr() {66 delete function;67 deleteAll( args );68 56 } 69 57 -
src/SynTree/ArrayType.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 38 38 } 39 39 40 Declaration::~Declaration() {41 }42 43 40 void Declaration::fixUniqueId() { 44 41 // don't need to set unique ID twice … … 66 63 67 64 AsmDecl::AsmDecl( const AsmDecl &other ) : Declaration( other ), stmt( maybeClone( other.stmt ) ) { 68 }69 70 AsmDecl::~AsmDecl() {71 delete stmt;72 65 } 73 66 -
src/SynTree/Declaration.h
r9d5fb67 r1cdfa82 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; } … … 87 86 DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs ); 88 87 DeclarationWithType( const DeclarationWithType &other ); 89 virtual ~DeclarationWithType(); 90 88 91 89 std::string get_mangleName() const { return mangleName; } 92 90 DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; } … … 126 124 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); 127 125 ObjectDecl( const ObjectDecl &other ); 128 virtual ~ObjectDecl();129 126 130 127 virtual Type * get_type() const override { return type; } … … 156 153 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); 157 154 FunctionDecl( const FunctionDecl &other ); 158 virtual ~FunctionDecl();159 155 160 156 virtual Type * get_type() const override { return type; } … … 184 180 NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type ); 185 181 NamedTypeDecl( const NamedTypeDecl &other ); 186 virtual ~NamedTypeDecl();187 182 188 183 Type *get_base() const { return base; } … … 219 214 TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init = nullptr ); 220 215 TypeDecl( const TypeDecl &other ); 221 virtual ~TypeDecl();222 216 223 217 Kind get_kind() const { return kind; } … … 268 262 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ); 269 263 AggregateDecl( const AggregateDecl &other ); 270 virtual ~AggregateDecl(); 271 264 272 265 std::list<Declaration*>& get_members() { return members; } 273 266 std::list<TypeDecl*>& get_parameters() { return parameters; } … … 353 346 AsmDecl( AsmStmt *stmt ); 354 347 AsmDecl( const AsmDecl &other ); 355 virtual ~AsmDecl();356 348 357 349 AsmStmt *get_stmt() { return stmt; } -
src/SynTree/DeclarationWithType.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 52 52 Expression::~Expression() { 53 53 delete env; 54 delete result;55 54 } 56 55 … … 74 73 ConstantExpr::ConstantExpr( const ConstantExpr &other) : Expression( other ), constant( other.constant ) { 75 74 } 76 77 ConstantExpr::~ConstantExpr() {}78 75 79 76 void ConstantExpr::print( std::ostream &os, Indenter indent ) const { … … 120 117 } 121 118 122 VariableExpr::~VariableExpr() {123 // don't delete the declaration, since it points somewhere else in the tree124 }125 126 119 VariableExpr * VariableExpr::functionPointer( FunctionDecl * func ) { 127 120 VariableExpr * funcExpr = new VariableExpr( func ); … … 150 143 } 151 144 152 SizeofExpr::~SizeofExpr() {153 delete expr;154 delete type;155 }156 157 145 void SizeofExpr::print( std::ostream &os, Indenter indent) const { 158 146 os << "Sizeof Expression on: "; … … 176 164 } 177 165 178 AlignofExpr::~AlignofExpr() {179 delete expr;180 delete type;181 }182 183 166 void AlignofExpr::print( std::ostream &os, Indenter indent) const { 184 167 os << "Alignof Expression on: "; … … 196 179 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr &other ) : 197 180 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 198 199 UntypedOffsetofExpr::~UntypedOffsetofExpr() {200 delete type;201 }202 181 203 182 void UntypedOffsetofExpr::print( std::ostream &os, Indenter indent) const { … … 217 196 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 218 197 219 OffsetofExpr::~OffsetofExpr() {220 delete type;221 }222 223 198 void OffsetofExpr::print( std::ostream &os, Indenter indent) const { 224 199 os << "Offsetof Expression on member " << member->name << " of "; … … 234 209 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {} 235 210 236 OffsetPackExpr::~OffsetPackExpr() { delete type; }237 238 211 void OffsetPackExpr::print( std::ostream &os, Indenter indent ) const { 239 212 os << "Offset pack expression on "; … … 252 225 AttrExpr::AttrExpr( const AttrExpr &other ) : 253 226 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 254 }255 256 AttrExpr::~AttrExpr() {257 delete attr;258 delete expr;259 delete type;260 227 } 261 228 … … 280 247 281 248 CastExpr::CastExpr( const CastExpr &other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) { 282 }283 284 CastExpr::~CastExpr() {285 delete arg;286 249 } 287 250 … … 335 298 } 336 299 337 VirtualCastExpr::~VirtualCastExpr() {338 delete arg;339 }340 341 300 void VirtualCastExpr::print( std::ostream &os, Indenter indent ) const { 342 301 os << "Virtual Cast of:" << std::endl << indent+1; … … 361 320 } 362 321 363 UntypedMemberExpr::~UntypedMemberExpr() {364 delete aggregate;365 delete member;366 }367 368 322 void UntypedMemberExpr::print( std::ostream &os, Indenter indent ) const { 369 323 os << "Untyped Member Expression, with field: " << std::endl << indent+1; … … 392 346 } 393 347 394 MemberExpr::~MemberExpr() {395 // don't delete the member declaration, since it points somewhere else in the tree396 delete aggregate;397 }398 399 348 void MemberExpr::print( std::ostream &os, Indenter indent ) const { 400 349 os << "Member Expression, with field: " << std::endl; … … 412 361 Expression( other ), function( maybeClone( other.function ) ) { 413 362 cloneAll( other.args, args ); 414 }415 416 UntypedExpr::~UntypedExpr() {417 delete function;418 deleteAll( args );419 363 } 420 364 … … 465 409 } 466 410 467 NameExpr::~NameExpr() {}468 469 411 void NameExpr::print( std::ostream &os, Indenter indent ) const { 470 412 os << "Name: " << get_name(); … … 479 421 LogicalExpr::LogicalExpr( const LogicalExpr &other ) : 480 422 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { 481 }482 483 LogicalExpr::~LogicalExpr() {484 delete arg1;485 delete arg2;486 423 } 487 424 … … 499 436 ConditionalExpr::ConditionalExpr( const ConditionalExpr &other ) : 500 437 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { 501 }502 503 ConditionalExpr::~ConditionalExpr() {504 delete arg1;505 delete arg2;506 delete arg3;507 438 } 508 439 … … 542 473 ImplicitCopyCtorExpr::~ImplicitCopyCtorExpr() { 543 474 set_env( nullptr ); // ImplicitCopyCtorExpr does not take ownership of an environment 544 delete callExpr;545 deleteAll( tempDecls );546 deleteAll( returnDecls );547 deleteAll( dtors );548 475 } 549 476 … … 570 497 } 571 498 572 ConstructorExpr::~ConstructorExpr() {573 delete callExpr;574 }575 576 499 void ConstructorExpr::print( std::ostream &os, Indenter indent ) const { 577 500 os << "Constructor Expression: " << std::endl << indent+1; … … 588 511 589 512 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr &other ) : Expression( other ), initializer( other.initializer->clone() ) {} 590 591 CompoundLiteralExpr::~CompoundLiteralExpr() {592 delete initializer;593 }594 513 595 514 void CompoundLiteralExpr::print( std::ostream &os, Indenter indent ) const { … … 618 537 cloneAll( other.dtors, dtors ); 619 538 } 620 StmtExpr::~StmtExpr() {621 delete statements;622 deleteAll( dtors );623 deleteAll( returnDecls );624 }625 539 void StmtExpr::computeResult() { 626 540 assert( statements ); 627 541 std::list< Statement * > & body = statements->kids; 628 delete result;629 542 result = nullptr; 630 543 if ( ! returnDecls.empty() ) { … … 669 582 UniqueExpr::UniqueExpr( const UniqueExpr &other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { 670 583 } 671 UniqueExpr::~UniqueExpr() { 672 delete expr; 673 delete object; 674 delete var; 675 } 584 676 585 void UniqueExpr::print( std::ostream &os, Indenter indent ) const { 677 586 os << "Unique Expression with id:" << id << std::endl << indent+1; … … 686 595 InitAlternative::InitAlternative( Type * type, Designation * designation ) : type( type ), designation( designation ) {} 687 596 InitAlternative::InitAlternative( const InitAlternative & other ) : type( maybeClone( other.type ) ), designation( maybeClone( other.designation ) ) {} 688 InitAlternative::~InitAlternative() {689 delete type;690 delete designation;691 }692 597 693 598 UntypedInitExpr::UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ) : expr( expr ), initAlts( initAlts ) {} 694 599 UntypedInitExpr::UntypedInitExpr( const UntypedInitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), initAlts( other.initAlts ) {} 695 UntypedInitExpr::~UntypedInitExpr() {696 delete expr;697 }698 600 699 601 void UntypedInitExpr::print( std::ostream & os, Indenter indent ) const { … … 713 615 } 714 616 InitExpr::InitExpr( const InitExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), designation( maybeClone( other.designation) ) {} 715 InitExpr::~InitExpr() {716 delete expr;717 delete designation;718 }719 617 720 618 void InitExpr::print( std::ostream & os, Indenter indent ) const { … … 730 628 } 731 629 DeletedExpr::DeletedExpr( const DeletedExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), deleteStmt( other.deleteStmt ) {} 732 DeletedExpr::~DeletedExpr() {733 delete expr;734 }735 630 736 631 void DeletedExpr::print( std::ostream & os, Indenter indent ) const { -
src/SynTree/Expression.h
r9d5fb67 r1cdfa82 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();44 43 ParamEntry & operator=( const ParamEntry & other ); 45 44 … … 53 52 /// Expression is the root type for all expressions 54 53 class Expression : public BaseSyntaxNode { 54 protected: 55 virtual ~Expression(); 56 55 57 public: 56 58 Type * result; … … 61 63 Expression(); 62 64 Expression( const Expression & other ); 63 virtual ~Expression();64 65 65 66 Type *& get_result() { return result; } … … 89 90 ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 90 91 ApplicationExpr( const ApplicationExpr & other ); 91 virtual ~ApplicationExpr();92 92 93 93 Expression * get_function() const { return function; } … … 111 111 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 112 112 UntypedExpr( const UntypedExpr & other ); 113 virtual ~UntypedExpr();114 113 115 114 Expression * get_function() const { return function; } … … 136 135 NameExpr( std::string name ); 137 136 NameExpr( const NameExpr & other ); 138 virtual ~NameExpr();139 137 140 138 const std::string & get_name() const { return name; } … … 157 155 AddressExpr( Expression * arg ); 158 156 AddressExpr( const AddressExpr & other ); 159 virtual ~AddressExpr();160 157 161 158 Expression * get_arg() const { return arg; } … … 176 173 LabelAddressExpr( const Label &arg ); 177 174 LabelAddressExpr( const LabelAddressExpr & other ); 178 virtual ~LabelAddressExpr();179 175 180 176 virtual LabelAddressExpr * clone() const { return new LabelAddressExpr( * this ); } … … 194 190 CastExpr( Expression * arg, void * ) = delete; // prevent accidentally passing pointers for isGenerated in the first constructor 195 191 CastExpr( const CastExpr & other ); 196 virtual ~CastExpr();197 192 198 193 Expression * get_arg() const { return arg; } … … 232 227 VirtualCastExpr( Expression * arg, Type * toType ); 233 228 VirtualCastExpr( const VirtualCastExpr & other ); 234 virtual ~VirtualCastExpr();235 229 236 230 Expression * get_arg() const { return arg; } … … 251 245 UntypedMemberExpr( Expression * member, Expression * aggregate ); 252 246 UntypedMemberExpr( const UntypedMemberExpr & other ); 253 virtual ~UntypedMemberExpr();254 247 255 248 Expression * get_member() const { return member; } … … 273 266 MemberExpr( DeclarationWithType * member, Expression * aggregate ); 274 267 MemberExpr( const MemberExpr & other ); 275 virtual ~MemberExpr();276 268 277 269 DeclarationWithType * get_member() const { return member; } … … 294 286 VariableExpr( DeclarationWithType * var ); 295 287 VariableExpr( const VariableExpr & other ); 296 virtual ~VariableExpr();297 288 298 289 DeclarationWithType * get_var() const { return var; } … … 314 305 ConstantExpr( Constant constant ); 315 306 ConstantExpr( const ConstantExpr & other ); 316 virtual ~ConstantExpr();317 307 318 308 Constant * get_constant() { return & constant; } … … 338 328 SizeofExpr( const SizeofExpr & other ); 339 329 SizeofExpr( Type * type ); 340 virtual ~SizeofExpr();341 330 342 331 Expression * get_expr() const { return expr; } … … 363 352 AlignofExpr( const AlignofExpr & other ); 364 353 AlignofExpr( Type * type ); 365 virtual ~AlignofExpr();366 354 367 355 Expression * get_expr() const { return expr; } … … 386 374 UntypedOffsetofExpr( Type * type, const std::string & member ); 387 375 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); 388 virtual ~UntypedOffsetofExpr();389 376 390 377 std::string get_member() const { return member; } … … 407 394 OffsetofExpr( Type * type, DeclarationWithType * member ); 408 395 OffsetofExpr( const OffsetofExpr & other ); 409 virtual ~OffsetofExpr();410 396 411 397 Type * get_type() const { return type; } … … 427 413 OffsetPackExpr( StructInstType * type ); 428 414 OffsetPackExpr( const OffsetPackExpr & other ); 429 virtual ~OffsetPackExpr();430 415 431 416 StructInstType * get_type() const { return type; } … … 449 434 AttrExpr( const AttrExpr & other ); 450 435 AttrExpr( Expression * attr, Type * type ); 451 virtual ~AttrExpr();452 436 453 437 Expression * get_attr() const { return attr; } … … 474 458 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true ); 475 459 LogicalExpr( const LogicalExpr & other ); 476 virtual ~LogicalExpr();477 460 478 461 bool get_isAnd() const { return isAnd; } … … 500 483 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3 ); 501 484 ConditionalExpr( const ConditionalExpr & other ); 502 virtual ~ConditionalExpr();503 485 504 486 Expression * get_arg1() const { return arg1; } … … 523 505 CommaExpr( Expression * arg1, Expression * arg2 ); 524 506 CommaExpr( const CommaExpr & other ); 525 virtual ~CommaExpr();526 507 527 508 Expression * get_arg1() const { return arg1; } … … 543 524 TypeExpr( Type * type ); 544 525 TypeExpr( const TypeExpr & other ); 545 virtual ~TypeExpr();546 526 547 527 Type * get_type() const { return type; } … … 563 543 AsmExpr( Expression * inout, Expression * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 564 544 AsmExpr( const AsmExpr & other ); 565 virtual ~AsmExpr() { delete inout; delete constraint; delete operand; };566 545 567 546 Expression * get_inout() const { return inout; } … … 585 564 /// along with a set of copy constructor calls, one for each argument. 586 565 class ImplicitCopyCtorExpr : public Expression { 566 protected: 567 virtual ~ImplicitCopyCtorExpr(); 568 587 569 public: 588 570 ApplicationExpr * callExpr; … … 593 575 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 594 576 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 595 virtual ~ImplicitCopyCtorExpr();596 577 597 578 ApplicationExpr * get_callExpr() const { return callExpr; } … … 615 596 ConstructorExpr( Expression * callExpr ); 616 597 ConstructorExpr( const ConstructorExpr & other ); 617 ~ConstructorExpr();618 598 619 599 Expression * get_callExpr() const { return callExpr; } … … 633 613 CompoundLiteralExpr( Type * type, Initializer * initializer ); 634 614 CompoundLiteralExpr( const CompoundLiteralExpr & other ); 635 virtual ~CompoundLiteralExpr();636 615 637 616 Initializer * get_initializer() const { return initializer; } … … 670 649 UntypedTupleExpr( const std::list< Expression * > & exprs ); 671 650 UntypedTupleExpr( const UntypedTupleExpr & other ); 672 virtual ~UntypedTupleExpr();673 651 674 652 std::list<Expression*>& get_exprs() { return exprs; } … … 687 665 TupleExpr( const std::list< Expression * > & exprs ); 688 666 TupleExpr( const TupleExpr & other ); 689 virtual ~TupleExpr();690 667 691 668 std::list<Expression*>& get_exprs() { return exprs; } … … 705 682 TupleIndexExpr( Expression * tuple, unsigned int index ); 706 683 TupleIndexExpr( const TupleIndexExpr & other ); 707 virtual ~TupleIndexExpr();708 684 709 685 Expression * get_tuple() const { return tuple; } … … 725 701 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls ); 726 702 TupleAssignExpr( const TupleAssignExpr & other ); 727 virtual ~TupleAssignExpr();728 703 729 704 TupleAssignExpr * set_stmtExpr( StmtExpr * newValue ) { stmtExpr = newValue; return this; } … … 745 720 StmtExpr( CompoundStmt * statements ); 746 721 StmtExpr( const StmtExpr & other ); 747 virtual ~StmtExpr();748 722 749 723 CompoundStmt * get_statements() const { return statements; } … … 770 744 UniqueExpr( Expression * expr, long long idVal = -1 ); 771 745 UniqueExpr( const UniqueExpr & other ); 772 ~UniqueExpr();773 746 774 747 Expression * get_expr() const { return expr; } … … 800 773 InitAlternative( const InitAlternative & other ); 801 774 InitAlternative & operator=( const Initializer & other ) = delete; // at the moment this isn't used, and I don't want to implement it 802 ~InitAlternative();803 775 }; 804 776 … … 810 782 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); 811 783 UntypedInitExpr( const UntypedInitExpr & other ); 812 ~UntypedInitExpr();813 784 814 785 Expression * get_expr() const { return expr; } … … 830 801 InitExpr( Expression * expr, Designation * designation ); 831 802 InitExpr( const InitExpr & other ); 832 ~InitExpr();833 803 834 804 Expression * get_expr() const { return expr; } … … 852 822 DeletedExpr( Expression * expr, BaseSyntaxNode * deleteStmt ); 853 823 DeletedExpr( const DeletedExpr & other ); 854 ~DeletedExpr();855 824 856 825 virtual DeletedExpr * clone() const { return new DeletedExpr( * this ); } -
src/SynTree/FunctionDecl.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 … … 122 109 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 123 110 124 ReturnStmt::~ReturnStmt() {125 delete expr;126 }127 128 111 void ReturnStmt::print( std::ostream &os, Indenter indent ) const { 129 112 os << "Return Statement, returning: "; … … 141 124 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { 142 125 cloneAll( other.initialization, initialization ); 143 }144 145 IfStmt::~IfStmt() {146 deleteAll( initialization );147 delete condition;148 delete thenPart;149 delete elsePart;150 126 } 151 127 … … 185 161 } 186 162 187 SwitchStmt::~SwitchStmt() {188 delete condition;189 // destroy statements190 deleteAll( statements );191 }192 193 163 void SwitchStmt::print( std::ostream &os, Indenter indent ) const { 194 164 os << "Switch on condition: "; … … 209 179 Statement( other ), condition( maybeClone(other.condition ) ), _isDefault( other._isDefault ) { 210 180 cloneAll( other.stmts, stmts ); 211 }212 213 CaseStmt::~CaseStmt() {214 delete condition;215 deleteAll( stmts );216 181 } 217 182 … … 244 209 } 245 210 246 WhileStmt::~WhileStmt() {247 delete body;248 delete condition;249 }250 251 211 void WhileStmt::print( std::ostream &os, Indenter indent ) const { 252 212 os << "While on condition: " << endl ; … … 266 226 cloneAll( other.initialization, initialization ); 267 227 268 }269 270 ForStmt::~ForStmt() {271 deleteAll( initialization );272 delete condition;273 delete increment;274 delete body;275 228 } 276 229 … … 312 265 ThrowStmt::ThrowStmt( const ThrowStmt &other ) : 313 266 Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { 314 }315 316 ThrowStmt::~ThrowStmt() {317 delete expr;318 delete target;319 267 } 320 268 … … 337 285 } 338 286 339 TryStmt::~TryStmt() {340 delete block;341 deleteAll( handlers );342 delete finallyBlock;343 }344 345 287 void TryStmt::print( std::ostream &os, Indenter indent ) const { 346 288 os << "Try Statement" << endl; … … 371 313 } 372 314 373 CatchStmt::~CatchStmt() {374 delete decl;375 delete body;376 }377 378 315 void CatchStmt::print( std::ostream &os, Indenter indent ) const { 379 316 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; … … 398 335 399 336 FinallyStmt::FinallyStmt( const FinallyStmt & other ) : Statement( other ), block( maybeClone( other.block ) ) { 400 }401 402 FinallyStmt::~FinallyStmt() {403 delete block;404 337 } 405 338 … … 435 368 } 436 369 437 WaitForStmt::~WaitForStmt() {438 for( auto & clause : clauses ) {439 delete clause.target.function;440 deleteAll( clause.target.arguments );441 delete clause.statement;442 delete clause.condition;443 }444 445 delete timeout.time;446 delete timeout.statement;447 delete timeout.condition;448 449 delete orelse.statement;450 delete orelse.condition;451 }452 453 370 void WaitForStmt::print( std::ostream &os, Indenter indent ) const { 454 371 os << "Waitfor Statement" << endl; … … 461 378 WithStmt::WithStmt( const WithStmt & other ) : Statement( other ), stmt( maybeClone( other.stmt ) ) { 462 379 cloneAll( other.exprs, exprs ); 463 }464 WithStmt::~WithStmt() {465 deleteAll( exprs );466 delete stmt;467 380 } 468 381 … … 491 404 } 492 405 493 ImplicitCtorDtorStmt::~ImplicitCtorDtorStmt() {494 delete callStmt;495 }496 497 406 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const { 498 407 os << "Implicit Ctor Dtor Statement" << endl; -
src/SynTree/Statement.h
r9d5fb67 r1cdfa82 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; } … … 136 132 std::list<Statement *> initialization = std::list<Statement *>() ); 137 133 IfStmt( const IfStmt &other ); 138 virtual ~IfStmt();139 134 140 135 std::list<Statement *> &get_initialization() { return initialization; } … … 159 154 SwitchStmt( Expression *condition, const std::list<Statement *> &statements ); 160 155 SwitchStmt( const SwitchStmt &other ); 161 virtual ~SwitchStmt();162 156 163 157 Expression *get_condition() { return condition; } … … 181 175 CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException); 182 176 CaseStmt( const CaseStmt &other ); 183 virtual ~CaseStmt();184 177 185 178 static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() ); … … 212 205 Statement *body, bool isDoWhile = false ); 213 206 WhileStmt( const WhileStmt &other ); 214 virtual ~WhileStmt();215 207 216 208 Expression *get_condition() { return condition; } … … 237 229 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 238 230 ForStmt( const ForStmt &other ); 239 virtual ~ForStmt();240 231 241 232 std::list<Statement *> &get_initialization() { return initialization; } … … 290 281 ReturnStmt( Expression *expr ); 291 282 ReturnStmt( const ReturnStmt &other ); 292 virtual ~ReturnStmt();293 283 294 284 Expression *get_expr() { return expr; } … … 311 301 ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr ); 312 302 ThrowStmt( const ThrowStmt &other ); 313 virtual ~ThrowStmt();314 303 315 304 Kind get_kind() { return kind; } … … 333 322 TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 334 323 TryStmt( const TryStmt &other ); 335 virtual ~TryStmt();336 324 337 325 CompoundStmt *get_block() const { return block; } … … 360 348 Expression *cond, Statement *body ); 361 349 CatchStmt( const CatchStmt &other ); 362 virtual ~CatchStmt();363 350 364 351 Kind get_kind() { return kind; } … … 382 369 FinallyStmt( CompoundStmt *block ); 383 370 FinallyStmt( const FinallyStmt &other ); 384 virtual ~FinallyStmt();385 371 386 372 CompoundStmt *get_block() const { return block; } … … 409 395 WaitForStmt(); 410 396 WaitForStmt( const WaitForStmt & ); 411 virtual ~WaitForStmt();412 397 413 398 std::vector<Clause> clauses; … … 438 423 WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); 439 424 WithStmt( const WithStmt & other ); 440 virtual ~WithStmt();441 425 442 426 virtual WithStmt * clone() const override { return new WithStmt( *this ); } … … 454 438 DeclStmt( Declaration *decl ); 455 439 DeclStmt( const DeclStmt &other ); 456 virtual ~DeclStmt();457 440 458 441 Declaration *get_decl() const { return decl; } … … 476 459 ImplicitCtorDtorStmt( Statement * callStmt ); 477 460 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ); 478 virtual ~ImplicitCtorDtorStmt();479 461 480 462 Statement *get_callStmt() const { return callStmt; } -
src/SynTree/TupleExpr.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 57 57 } 58 58 59 Type::~Type() {60 deleteAll( forall );61 deleteAll( attributes );62 }63 64 59 // These must remain in the same order as the corresponding bit fields. 65 60 const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" }; -
src/SynTree/Type.h
r9d5fb67 r1cdfa82 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; } … … 261 260 PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 262 261 PointerType( const PointerType& ); 263 virtual ~PointerType();264 262 265 263 Type *get_base() { return base; } … … 291 289 ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 292 290 ArrayType( const ArrayType& ); 293 virtual ~ArrayType();294 291 295 292 Type *get_base() { return base; } … … 319 316 ReferenceType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 320 317 ReferenceType( const ReferenceType & ); 321 virtual ~ReferenceType();322 318 323 319 Type *get_base() { return base; } … … 352 348 FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 353 349 FunctionType( const FunctionType& ); 354 virtual ~FunctionType();355 350 356 351 std::list<DeclarationWithType*> & get_returnVals() { return returnVals; } … … 376 371 ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes ); 377 372 ReferenceToType( const ReferenceToType & other ); 378 virtual ~ReferenceToType();379 373 380 374 const std::string & get_name() const { return name; } … … 503 497 TraitInstType( const Type::Qualifiers & tq, TraitDecl * baseTrait, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 504 498 TraitInstType( const TraitInstType & other ); 505 ~TraitInstType();506 499 507 500 virtual bool isComplete() const override; … … 525 518 TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 526 519 TypeInstType( const TypeInstType & other ); 527 ~TypeInstType();528 520 529 521 TypeDecl *get_baseType() const { return baseType; } … … 549 541 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 550 542 TupleType( const TupleType& ); 551 virtual ~TupleType();552 543 553 544 typedef std::list<Type*> value_type; … … 583 574 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 584 575 TypeofType( const TypeofType& ); 585 virtual ~TypeofType();586 576 587 577 Expression *get_expr() const { return expr; } … … 606 596 AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 607 597 AttrType( const AttrType& ); 608 virtual ~AttrType();609 598 610 599 const std::string & get_name() const { return name; } -
src/SynTree/TypeDecl.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 123 123 124 124 virtual void visit( Attribute * attribute ) = 0; 125 126 virtual void visit( TypeSubstitution * sub ) = 0; 125 127 }; 126 128 -
src/SynTree/module.mk
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 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 } … … 96 96 TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), 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 { -
src/Tuples/TupleExpansion.cc
r9d5fb67 r1cdfa82 45 45 46 46 std::map< int, Expression * > decls; // not vector, because order added may not be increasing order 47 48 ~UniqueExprExpander() {49 for ( std::pair<const int, Expression *> & p : decls ) {50 delete p.second;51 }52 }53 47 }; 54 48 … … 111 105 UntypedMemberExpr * newMemberExpr = new UntypedMemberExpr( memberExpr->member, inner ); 112 106 inner->location = newMemberExpr->location = loc; 113 memberExpr->member = nullptr;114 memberExpr->aggregate = nullptr;115 delete memberExpr;116 107 return newMemberExpr->acceptMutator( expander ); 117 108 } else { … … 135 126 expr->location = memberExpr->location; 136 127 } 137 delete aggr;138 128 tupleExpr->location = memberExpr->location; 139 129 return tupleExpr; … … 181 171 decls[id] = condExpr; 182 172 } 183 delete unqExpr;184 173 return decls[id]->clone(); 185 174 } … … 191 180 ret->set_env( assnExpr->get_env() ); 192 181 assnExpr->set_env( nullptr ); 193 delete assnExpr;194 182 return ret; 195 183 } … … 222 210 newType->get_parameters().push_back( new TypeExpr( t->clone() ) ); 223 211 } 224 delete tupleType;225 212 return newType; 226 213 } … … 233 220 TypeSubstitution * env = tupleExpr->get_env(); 234 221 tupleExpr->set_env( nullptr ); 235 delete tupleExpr;236 222 237 223 StructInstType * type = strict_dynamic_cast< StructInstType * >( tuple->get_result() ); … … 275 261 TypeSubstitution * env = tupleExpr->get_env(); 276 262 277 // remove data from shell and delete it 278 tupleExpr->set_result( nullptr ); 279 tupleExpr->get_exprs().clear(); 263 // remove data from shell 280 264 tupleExpr->set_env( nullptr ); 281 delete tupleExpr;282 265 283 266 return replaceTupleExpr( result, exprs, env ); -
src/Virtual/ExpandCasts.cc
r9d5fb67 r1cdfa82 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
r9d5fb67 r1cdfa82 37 37 #include "Common/PassVisitor.h" 38 38 #include "Common/CompilerError.h" // for CompilerError 39 #include "Common/GC.h" // for GC 39 40 #include "Common/SemanticError.h" // for SemanticError 40 41 #include "Common/UnimplementedError.h" // for UnimplementedError … … 57 58 #include "SymTab/Validate.h" // for validate 58 59 #include "SynTree/Declaration.h" // for Declaration 60 #include "SynTree/GcTracer.h" // for GC << TranslationUnit 59 61 #include "SynTree/Visitor.h" // for acceptAll 60 62 #include "Tuples/Tuples.h" // for expandMemberTuples, expan... … … 64 66 65 67 #define OPTPRINT(x) if ( errorp ) cerr << x << endl; 66 67 68 68 69 LinkageSpec::Spec linkage = LinkageSpec::Cforall; … … 233 234 delete parseTree; 234 235 parseTree = nullptr; 236 collect( translationUnit ); 235 237 236 238 if ( astp ) { … … 242 244 OPTPRINT( "validate" ) 243 245 SymTab::validate( translationUnit, symtabp ); 244 if ( symtabp ) { 245 deleteAll( translationUnit ); 246 return 0; 247 } // if 246 if ( symtabp ) return 0; 247 collect( translationUnit ); 248 248 249 249 if ( expraltp ) { … … 266 266 OPTPRINT( "expandMemberTuples" ); 267 267 Tuples::expandMemberTuples( translationUnit ); 268 collect( translationUnit ); 268 269 if ( libcfap ) { 269 270 // generate the bodies of cfa library functions … … 273 274 if ( declstatsp ) { 274 275 CodeTools::printDeclStats( translationUnit ); 275 deleteAll( translationUnit );276 276 return 0; 277 277 } … … 286 286 OPTPRINT( "resolve" ) 287 287 ResolvExpr::resolve( translationUnit ); 288 collect( translationUnit ); 288 289 if ( exprp ) { 289 290 dump( translationUnit ); … … 294 295 OPTPRINT( "fixInit" ) 295 296 InitTweak::fix( translationUnit, filename, libcfap || treep ); 297 collect( translationUnit ); 296 298 if ( ctorinitp ) { 297 299 dump ( translationUnit ); … … 313 315 OPTPRINT( "expandTuples" ); // xxx - is this the right place for this? 314 316 Tuples::expandTuples( translationUnit ); 317 collect( translationUnit ); 315 318 if ( tuplep ) { 316 319 dump( translationUnit ); … … 323 326 OPTPRINT("instantiateGenerics") 324 327 GenPoly::instantiateGeneric( translationUnit ); 328 collect( translationUnit ); 325 329 if ( genericsp ) { 326 330 dump( translationUnit ); 327 331 return 0; 328 332 } 333 329 334 OPTPRINT( "convertLvalue" ) 330 335 GenPoly::convertLvalue( translationUnit ); 331 332 336 collect( translationUnit ); 333 337 if ( bboxp ) { 334 338 dump( translationUnit ); 335 339 return 0; 336 340 } // if 341 337 342 OPTPRINT( "box" ) 338 343 GenPoly::box( translationUnit ); 339 344 collect( translationUnit ); 340 345 if ( bcodegenp ) { 341 346 dump( translationUnit ); … … 383 388 } // try 384 389 385 deleteAll( translationUnit );386 390 return 0; 387 391 } // main … … 568 572 printAll( decls, out ); 569 573 } 570 deleteAll( translationUnit );571 574 } // dump 572 575
Note:
See TracChangeset
for help on using the changeset viewer.