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