- File:
-
- 1 edited
-
src/ControlStruct/ExceptTranslate.cc (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
r7862059 rbfc7811 34 34 #include "SynTree/Statement.h" // for CompoundStmt, CatchStmt, ThrowStmt 35 35 #include "SynTree/Type.h" // for FunctionType, Type, noQualifiers 36 #include "SynTree/ DeclReplacer.h" // for DeclReplacer36 #include "SynTree/VarExprReplacer.h" // for VarExprReplacer, VarExprReplace... 37 37 #include "SynTree/Visitor.h" // for acceptAll 38 38 … … 104 104 // Types used in translation, make sure to use clone. 105 105 // void (*function)(); 106 FunctionType try_func_t;106 FunctionType * try_func_t; 107 107 // void (*function)(int, exception); 108 FunctionType catch_func_t;108 FunctionType * catch_func_t; 109 109 // int (*function)(exception); 110 FunctionType match_func_t;110 FunctionType * match_func_t; 111 111 // bool (*function)(exception); 112 FunctionType handle_func_t;112 FunctionType * handle_func_t; 113 113 // void (*function)(__attribute__((unused)) void *); 114 FunctionType finally_func_t;114 FunctionType * finally_func_t; 115 115 116 116 StructInstType * create_except_type() { … … 125 125 handler_except_decl( nullptr ), 126 126 except_decl( nullptr ), node_decl( nullptr ), hook_decl( nullptr ), 127 try_func_t( n oQualifiers, false),128 catch_func_t( n oQualifiers, false),129 match_func_t( n oQualifiers, false),130 handle_func_t( n oQualifiers, false),131 finally_func_t( n oQualifiers, false)127 try_func_t( new FunctionType(noQualifiers, false) ), 128 catch_func_t( new FunctionType(noQualifiers, false) ), 129 match_func_t( new FunctionType(noQualifiers, false) ), 130 handle_func_t( new FunctionType(noQualifiers, false) ), 131 finally_func_t( new FunctionType(noQualifiers, false) ) 132 132 {} 133 133 … … 141 141 assert( except_decl ); 142 142 143 ObjectDecl index_obj(143 auto index_obj = new ObjectDecl( 144 144 "__handler_index", 145 145 Type::StorageClasses(), … … 149 149 /*init*/ NULL 150 150 ); 151 ObjectDecl exception_obj(151 auto exception_obj = new ObjectDecl( 152 152 "__exception_inst", 153 153 Type::StorageClasses(), … … 160 160 /*init*/ NULL 161 161 ); 162 ObjectDecl bool_obj(162 auto bool_obj = new ObjectDecl( 163 163 "__ret_bool", 164 164 Type::StorageClasses(), … … 169 169 std::list<Attribute *>{ new Attribute( "unused" ) } 170 170 ); 171 ObjectDecl voidptr_obj(171 auto voidptr_obj = new ObjectDecl( 172 172 "__hook", 173 173 Type::StorageClasses(), … … 184 184 ); 185 185 186 ObjectDecl * unused_index_obj = index_obj .clone();186 ObjectDecl * unused_index_obj = index_obj->clone(); 187 187 unused_index_obj->attributes.push_back( new Attribute( "unused" ) ); 188 188 189 catch_func_t .get_parameters().push_back( index_obj.clone());190 catch_func_t .get_parameters().push_back( exception_obj.clone() );191 match_func_t .get_returnVals().push_back( unused_index_obj );192 match_func_t .get_parameters().push_back( exception_obj.clone() );193 handle_func_t .get_returnVals().push_back( bool_obj.clone());194 handle_func_t .get_parameters().push_back( exception_obj.clone());195 finally_func_t .get_parameters().push_back( voidptr_obj.clone());189 catch_func_t->get_parameters().push_back( index_obj ); 190 catch_func_t->get_parameters().push_back( exception_obj->clone() ); 191 match_func_t->get_returnVals().push_back( unused_index_obj ); 192 match_func_t->get_parameters().push_back( exception_obj->clone() ); 193 handle_func_t->get_returnVals().push_back( bool_obj ); 194 handle_func_t->get_parameters().push_back( exception_obj ); 195 finally_func_t->get_parameters().push_back( voidptr_obj ); 196 196 } 197 197 … … 204 204 call->get_args().push_back( throwStmt->get_expr() ); 205 205 throwStmt->set_expr( nullptr ); 206 delete throwStmt;207 206 return new ExprStmt( call ); 208 207 } … … 234 233 new UntypedExpr( new NameExpr( "__cfaabi_ehm__rethrow_terminate" ) ) 235 234 ) ); 236 delete throwStmt;237 235 return result; 238 236 } … … 251 249 ); 252 250 result->labels = throwStmt->labels; 253 delete throwStmt;254 251 return result; 255 252 } … … 267 264 268 265 return new FunctionDecl( "try", Type::StorageClasses(), 269 LinkageSpec::Cforall, try_func_t .clone(), body );266 LinkageSpec::Cforall, try_func_t->clone(), body ); 270 267 } 271 268 … … 274 271 std::list<CaseStmt *> handler_wrappers; 275 272 276 FunctionType *func_type = catch_func_t .clone();273 FunctionType *func_type = catch_func_t->clone(); 277 274 DeclarationWithType * index_obj = func_type->get_parameters().front(); 278 275 DeclarationWithType * except_obj = func_type->get_parameters().back(); … … 314 311 // Update variables in the body to point to this local copy. 315 312 { 316 DeclReplacer::DeclMap mapping;313 VarExprReplacer::DeclMap mapping; 317 314 mapping[ handler_decl ] = local_except; 318 DeclReplacer::replace( handler->body, mapping );315 VarExprReplacer::replace( handler->body, mapping ); 319 316 } 320 317 … … 384 381 modded_handler->set_cond( nullptr ); 385 382 modded_handler->set_body( nullptr ); 386 delete modded_handler;387 383 return block; 388 384 } … … 396 392 CompoundStmt * body = new CompoundStmt(); 397 393 398 FunctionType * func_type = match_func_t .clone();394 FunctionType * func_type = match_func_t->clone(); 399 395 DeclarationWithType * except_obj = func_type->get_parameters().back(); 400 396 … … 450 446 CompoundStmt * body = new CompoundStmt(); 451 447 452 FunctionType * func_type = handle_func_t .clone();448 FunctionType * func_type = handle_func_t->clone(); 453 449 DeclarationWithType * except_obj = func_type->get_parameters().back(); 454 450 … … 530 526 CompoundStmt * body = finally->get_block(); 531 527 finally->set_block( nullptr ); 532 delete finally;533 528 tryStmt->set_finally( nullptr ); 534 529 535 530 return new FunctionDecl("finally", Type::StorageClasses(), 536 LinkageSpec::Cforall, finally_func_t .clone(), body);531 LinkageSpec::Cforall, finally_func_t->clone(), body); 537 532 } 538 533
Note:
See TracChangeset
for help on using the changeset viewer.