Changeset 4c03e63 for src/Common
- Timestamp:
- Jun 23, 2017, 4:20:33 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
- Children:
- 74e58ea3, 7bbba76
- Parents:
- e1c1829 (diff), 88177cf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/Common
- Files:
-
- 3 edited
-
PassVisitor.h (modified) (10 diffs)
-
PassVisitor.impl.h (modified) (29 diffs)
-
PassVisitor.proto.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
re1c1829 r4c03e63 18 18 // Templated visitor type 19 19 // To use declare a PassVisitor< YOUR VISITOR TYPE > 20 // The visitor type should specify the previsit/postvisit for types that are desired. 20 // The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired. 21 // Note: previsit/postvisit/premutate/postmutate must be **public** members 22 // 23 // Several additional features are available through inheritance 24 // | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression 25 // | WithStmtsToAdd - provides the ability to insert statements before or after the current statement by adding new statements into 26 // stmtsToAddBefore or stmtsToAddAfter respectively. 27 // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children 28 // | WithScopes - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable 29 // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. 21 30 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 22 31 template< typename pass_type > … … 28 37 PassVisitor(Args &&... args) 29 38 : pass( std::forward<Args>( args )... ) 30 {} 39 { 40 typedef PassVisitor<pass_type> this_t; 41 this_t * const * visitor = visitor_impl(pass, 0); 42 if(visitor) { 43 *const_cast<this_t **>( visitor ) = this; 44 } 45 } 31 46 32 47 virtual ~PassVisitor() = default; … … 86 101 virtual void visit( ConstructorExpr * ctorExpr ) override final; 87 102 virtual void visit( CompoundLiteralExpr *compLitExpr ) override final; 88 virtual void visit( UntypedValofExpr *valofExpr ) override final;89 103 virtual void visit( RangeExpr *rangeExpr ) override final; 90 104 virtual void visit( UntypedTupleExpr *tupleExpr ) override final; … … 172 186 virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final; 173 187 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final; 174 virtual Expression* mutate( UntypedValofExpr *valofExpr ) override final;175 188 virtual Expression* mutate( RangeExpr *rangeExpr ) override final; 176 189 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final; … … 207 220 208 221 private: 222 template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 223 template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 224 209 225 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } 210 226 template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } … … 218 234 void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } 219 235 220 void visitStatementList( std::list< Statement* > &statements ); 236 template< typename func_t > 237 void handleStatementList( std::list< Statement * > & statements, func_t func ); 238 void visitStatementList ( std::list< Statement* > &statements ); 221 239 void mutateStatementList( std::list< Statement* > &statements ); 222 240 223 Statement * visitStatement( Statement * stmt ); 241 template< typename func_t > 242 Statement * handleStatement( Statement * stmt, func_t func ); 243 Statement * visitStatement ( Statement * stmt ); 224 244 Statement * mutateStatement( Statement * stmt ); 225 245 226 void visitExpression( Expression * expr ); 246 template< typename func_t > 247 Expression * handleExpression( Expression * expr, func_t func ); 248 Expression * visitExpression ( Expression * expr ); 227 249 Expression * mutateExpression( Expression * expr ); 228 250 … … 231 253 std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } 232 254 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } 233 bool visit_children() { bool* skip = skip_children_impl(pass, 0); return ! (skip && *skip); } 234 void reset_visit() { bool* skip = skip_children_impl(pass, 0); if(skip) *skip = false; } 255 std::list< Declaration* > * get_beforeDecls() { return declsToAddBefore_impl( pass, 0); } 256 std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); } 257 258 void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } 235 259 236 260 guard_value_impl init_guard() { … … 271 295 std::list< Statement* > stmtsToAddAfter; 272 296 }; 273 274 297 class WithShortCircuiting { 275 298 protected: … … 278 301 279 302 public: 280 bool skip_children;303 bool_ref visit_children; 281 304 }; 282 305 … … 297 320 }; 298 321 322 template<typename pass_type> 323 class WithVisitorRef { 324 protected: 325 WithVisitorRef() = default; 326 ~WithVisitorRef() = default; 327 328 public: 329 PassVisitor<pass_type> * const visitor; 330 }; 299 331 300 332 #include "PassVisitor.impl.h" -
src/Common/PassVisitor.impl.h
re1c1829 r4c03e63 4 4 __attribute__((unused)) \ 5 5 const auto & guard = init_guard(); \ 6 bool visit_children = true; \ 7 set_visit_children( visit_children ); \ 6 8 call_previsit( node ); \ 7 if( visit_children() ) { \ 8 reset_visit(); \ 9 if( visit_children ) { \ 9 10 10 11 #define VISIT_END( node ) \ … … 15 16 __attribute__((unused)) \ 16 17 const auto & guard = init_guard(); \ 18 bool visit_children = true; \ 19 set_visit_children( visit_children ); \ 17 20 call_premutate( node ); \ 18 if( visit_children() ) { \ 19 reset_visit(); \ 21 if( visit_children ) { \ 20 22 21 23 #define MUTATE_END( type, node ) \ … … 42 44 } 43 45 44 typedef std::list< Statement * > StmtList_t; 45 46 template< typename pass_type > 47 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 46 typedef std::list< Statement * > StmtList_t; 47 typedef std::list< Declaration * > DeclList_t; 48 49 template<typename iterator_t> 50 static inline void splice( iterator_t it, DeclList_t * decls ) { 51 std::transform( 52 decls->begin(), 53 decls->end(), 54 it, 55 [](Declaration * decl) -> auto { 56 return new DeclStmt( noLabels, decl ); 57 } 58 ); 59 decls->clear(); 60 } 61 62 template< typename pass_type > 63 static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) { 64 65 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 66 DeclList_t* afterDecls = visitor.get_afterDecls(); 67 68 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 69 // splice in new declarations after previous decl 70 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 71 72 if ( i == decls.end() ) break; 73 74 // run mutator on declaration 75 maybeAccept( *i, visitor ); 76 77 // splice in new declarations before current decl 78 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 79 } 80 } 81 82 template< typename pass_type > 83 static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { 84 85 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 86 DeclList_t* afterDecls = mutator.get_afterDecls(); 87 88 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { 89 // splice in new declarations after previous decl 90 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 91 92 if ( i == decls.end() ) break; 93 94 // run mutator on declaration 95 *i = maybeMutate( *i, mutator ); 96 97 // splice in new declarations before current decl 98 if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } 99 } 100 } 101 102 template< typename pass_type > 103 template< typename func_t > 104 void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { 48 105 SemanticError errors; 49 106 50 107 StmtList_t* beforeStmts = get_beforeStmts(); 51 108 StmtList_t* afterStmts = get_afterStmts(); 109 DeclList_t* beforeDecls = get_beforeDecls(); 110 DeclList_t* afterDecls = get_afterDecls(); 52 111 53 112 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 113 114 if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); } 54 115 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 116 55 117 try { 56 (*i)->accept( *this ); 118 func( *i ); 119 assert(( empty( beforeStmts ) && empty( afterStmts )) 120 || ( empty( beforeDecls ) && empty( afterDecls )) ); 121 57 122 } catch ( SemanticError &e ) { 58 123 errors.append( e ); 59 124 } 125 126 if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); } 60 127 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 61 128 } 62 129 130 if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); } 63 131 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 64 132 if ( !errors.isEmpty() ) { throw errors; } … … 66 134 67 135 template< typename pass_type > 136 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 137 handleStatementList( statements, [this]( Statement * stmt) { 138 stmt->accept( *this ); 139 }); 140 } 141 142 template< typename pass_type > 68 143 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 69 SemanticError errors; 144 handleStatementList( statements, [this]( Statement *& stmt) { 145 stmt = stmt->acceptMutator( *this ); 146 }); 147 } 148 149 150 template< typename pass_type > 151 template< typename func_t > 152 Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) { 153 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 154 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr () ); 155 ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); 156 ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); 157 ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); 158 ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); 159 160 Statement *newStmt = func( stmt ); 70 161 71 162 StmtList_t* beforeStmts = get_beforeStmts(); 72 163 StmtList_t* afterStmts = get_afterStmts(); 73 74 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 75 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 76 try { 77 *i = (*i)->acceptMutator( *this ); 78 } catch ( SemanticError &e ) { 79 errors.append( e ); 80 } 81 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 82 } 83 84 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 85 if ( !errors.isEmpty() ) { throw errors; } 86 } 87 88 template< typename pass_type > 89 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 90 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 91 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 92 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 93 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 94 95 maybeAccept( stmt, *this ); 96 97 StmtList_t* beforeStmts = get_beforeStmts(); 98 StmtList_t* afterStmts = get_afterStmts(); 99 100 if( empty(beforeStmts) && empty(afterStmts) ) { return stmt; } 164 DeclList_t* beforeDecls = get_beforeDecls(); 165 DeclList_t* afterDecls = get_afterDecls(); 166 167 if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; } 168 assert(( empty( beforeStmts ) && empty( afterStmts )) 169 || ( empty( beforeDecls ) && empty( afterDecls )) ); 101 170 102 171 CompoundStmt *compound = new CompoundStmt( noLabels ); 172 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } 103 173 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 104 compound->get_kids().push_back( stmt ); 174 compound->get_kids().push_back( newStmt ); 175 if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); } 105 176 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 106 177 return compound; … … 108 179 109 180 template< typename pass_type > 181 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 182 return handleStatement( stmt, [this]( Statement * stmt ) { 183 maybeAccept( stmt, *this ); 184 return stmt; 185 }); 186 } 187 188 template< typename pass_type > 110 189 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 111 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 112 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 113 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 114 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 115 116 Statement *newStmt = maybeMutate( stmt, *this ); 117 118 StmtList_t* beforeStmts = get_beforeStmts(); 119 StmtList_t* afterStmts = get_afterStmts(); 120 121 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 122 123 CompoundStmt *compound = new CompoundStmt( noLabels ); 124 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 125 compound->get_kids().push_back( newStmt ); 126 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 127 return compound; 128 } 129 130 131 132 template< typename pass_type > 133 void PassVisitor< pass_type >::visitExpression( Expression * expr ) { 134 if( !expr ) return; 190 return handleStatement( stmt, [this]( Statement * stmt ) { 191 return maybeMutate( stmt, *this ); 192 }); 193 } 194 195 template< typename pass_type > 196 template< typename func_t > 197 Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) { 198 if( !expr ) return nullptr; 135 199 136 200 auto env_ptr = get_env_ptr(); … … 138 202 *env_ptr = expr->get_env(); 139 203 } 140 // xxx - should env be cloned (or moved) onto the result of the mutate? 141 expr->accept( *this ); 204 205 // should env be cloned (or moved) onto the result of the mutate? 206 return func( expr ); 207 } 208 209 template< typename pass_type > 210 Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) { 211 return handleExpression(expr, [this]( Expression * expr ) { 212 expr->accept( *this ); 213 return expr; 214 }); 142 215 } 143 216 144 217 template< typename pass_type > 145 218 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 146 if( !expr ) return nullptr; 147 148 auto env_ptr = get_env_ptr(); 149 if ( env_ptr && expr->get_env() ) { 150 *env_ptr = expr->get_env(); 151 } 152 // xxx - should env be cloned (or moved) onto the result of the mutate? 153 return expr->acceptMutator( *this ); 154 } 155 219 return handleExpression(expr, [this]( Expression * expr ) { 220 return expr->acceptMutator( *this ); 221 }); 222 } 156 223 157 224 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ … … 159 226 template< typename pass_type > 160 227 void PassVisitor< pass_type >::visit( ObjectDecl * node ) { 161 VISIT_BODY( node ); 228 VISIT_BODY( node ); 162 229 } 163 230 164 231 template< typename pass_type > 165 232 void PassVisitor< pass_type >::visit( FunctionDecl * node ) { 166 VISIT_BODY( node ); 233 VISIT_BODY( node ); 167 234 } 168 235 169 236 template< typename pass_type > 170 237 void PassVisitor< pass_type >::visit( StructDecl * node ) { 171 VISIT_BODY( node ); 238 VISIT_BODY( node ); 172 239 } 173 240 174 241 template< typename pass_type > 175 242 void PassVisitor< pass_type >::visit( UnionDecl * node ) { 176 VISIT_BODY( node ); 243 VISIT_BODY( node ); 177 244 } 178 245 179 246 template< typename pass_type > 180 247 void PassVisitor< pass_type >::visit( EnumDecl * node ) { 181 VISIT_BODY( node ); 248 VISIT_BODY( node ); 182 249 } 183 250 184 251 template< typename pass_type > 185 252 void PassVisitor< pass_type >::visit( TraitDecl * node ) { 186 VISIT_BODY( node ); 253 VISIT_BODY( node ); 187 254 } 188 255 189 256 template< typename pass_type > 190 257 void PassVisitor< pass_type >::visit( TypeDecl * node ) { 191 VISIT_BODY( node ); 258 VISIT_BODY( node ); 192 259 } 193 260 194 261 template< typename pass_type > 195 262 void PassVisitor< pass_type >::visit( TypedefDecl * node ) { 196 VISIT_BODY( node ); 263 VISIT_BODY( node ); 197 264 } 198 265 199 266 template< typename pass_type > 200 267 void PassVisitor< pass_type >::visit( AsmDecl * node ) { 201 VISIT_BODY( node ); 268 VISIT_BODY( node ); 202 269 } 203 270 … … 231 298 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 232 299 VISIT_START( node ); 233 call_beginScope();234 300 235 301 visitExpression( node->get_expr() ); 236 302 237 call_endScope();238 303 VISIT_END( node ); 239 304 } … … 248 313 } 249 314 315 //-------------------------------------------------------------------------- 316 // AsmStmt 250 317 template< typename pass_type > 251 318 void PassVisitor< pass_type >::visit( AsmStmt * node ) { 252 VISIT_BODY( node ); 319 VISIT_BODY( node ); 320 } 321 322 template< typename pass_type > 323 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { 324 MUTATE_BODY( Statement, node ); 253 325 } 254 326 … … 257 329 template< typename pass_type > 258 330 void PassVisitor< pass_type >::visit( IfStmt * node ) { 259 VISIT_START( node ); 331 VISIT_START( node ); 260 332 261 333 visitExpression( node->get_condition() ); … … 268 340 template< typename pass_type > 269 341 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 270 MUTATE_START( node ); 342 MUTATE_START( node ); 271 343 272 344 node->set_condition( mutateExpression( node->get_condition() ) ); … … 281 353 template< typename pass_type > 282 354 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 283 VISIT_START( node ); 355 VISIT_START( node ); 284 356 285 357 visitExpression( node->get_condition() ); … … 291 363 template< typename pass_type > 292 364 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { 293 MUTATE_START( node ); 365 MUTATE_START( node ); 294 366 295 367 node->set_condition( mutateExpression( node->get_condition() ) ); … … 300 372 301 373 //-------------------------------------------------------------------------- 302 // WhileStmt374 // ForStmt 303 375 template< typename pass_type > 304 376 void PassVisitor< pass_type >::visit( ForStmt * node ) { 305 VISIT_START( node ); 377 VISIT_START( node ); 306 378 307 379 acceptAll( node->get_initialization(), *this ); … … 315 387 template< typename pass_type > 316 388 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { 317 MUTATE_START( node ); 389 MUTATE_START( node ); 318 390 319 391 mutateAll( node->get_initialization(), *this ); … … 329 401 template< typename pass_type > 330 402 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 331 VISIT_START( node ); 403 VISIT_START( node ); 332 404 333 405 visitExpression( node->get_condition() ); … … 339 411 template< typename pass_type > 340 412 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { 341 MUTATE_START( node ); 342 413 MUTATE_START( node ); 414 343 415 node->set_condition( mutateExpression( node->get_condition() ) ); 344 416 mutateStatementList( node->get_statements() ); 345 417 346 418 MUTATE_END( Statement, node ); 347 419 } 348 420 349 421 //-------------------------------------------------------------------------- 350 // SwitchStmt422 // CaseStmt 351 423 template< typename pass_type > 352 424 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 353 VISIT_START( node ); 354 425 VISIT_START( node ); 426 355 427 visitExpression( node->get_condition() ); 356 428 visitStatementList( node->get_statements() ); 357 429 358 430 VISIT_END( node ); 359 431 } … … 361 433 template< typename pass_type > 362 434 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { 363 MUTATE_START( node ); 364 435 MUTATE_START( node ); 436 365 437 node->set_condition( mutateExpression( node->get_condition() ) ); 366 438 mutateStatementList( node->get_statements() ); 367 439 368 440 MUTATE_END( Statement, node ); 369 441 } 370 442 443 //-------------------------------------------------------------------------- 444 // BranchStmt 371 445 template< typename pass_type > 372 446 void PassVisitor< pass_type >::visit( BranchStmt * node ) { 373 VISIT_BODY( node ); 447 VISIT_BODY( node ); 448 } 449 450 template< typename pass_type > 451 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { 452 MUTATE_BODY( Statement, node ); 374 453 } 375 454 … … 415 494 maybeAccept( node->get_block(), *this ); 416 495 acceptAll( node->get_catchers(), *this ); 496 maybeAccept( node->get_finally(), *this ); 417 497 418 498 VISIT_END( node ); … … 425 505 node->set_block( maybeMutate( node->get_block(), *this ) ); 426 506 mutateAll( node->get_catchers(), *this ); 427 507 node->set_finally( maybeMutate( node->get_finally(), *this ) ); 508 428 509 MUTATE_END( Statement, node ); 429 510 } … … 435 516 VISIT_START( node ); 436 517 518 maybeAccept( node->get_decl(), *this ); 519 node->set_cond( visitExpression( node->get_cond() ) ); 437 520 node->set_body( visitStatement( node->get_body() ) ); 438 maybeAccept( node->get_decl(), *this );439 521 440 522 VISIT_END( node ); … … 444 526 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { 445 527 MUTATE_START( node ); 446 447 node->set_body( mutateStatement( node->get_body() ) ); 448 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 449 528 529 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 530 node->set_cond( mutateExpression( node->get_cond() ) ); 531 node->set_body( mutateStatement( node->get_body() ) ); 532 450 533 MUTATE_END( Statement, node ); 451 534 } … … 453 536 template< typename pass_type > 454 537 void PassVisitor< pass_type >::visit( FinallyStmt * node ) { 455 VISIT_BODY( node ); 538 VISIT_BODY( node ); 456 539 } 457 540 458 541 template< typename pass_type > 459 542 void PassVisitor< pass_type >::visit( NullStmt * node ) { 460 VISIT_BODY( node ); 543 VISIT_BODY( node ); 461 544 } 462 545 463 546 template< typename pass_type > 464 547 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 465 VISIT_BODY( node ); 548 VISIT_BODY( node ); 466 549 } 467 550 468 551 template< typename pass_type > 469 552 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { 470 VISIT_BODY( node ); 553 VISIT_BODY( node ); 471 554 } 472 555 473 556 template< typename pass_type > 474 557 void PassVisitor< pass_type >::visit( ApplicationExpr * node ) { 475 VISIT_BODY( node ); 558 VISIT_BODY( node ); 476 559 } 477 560 … … 502 585 template< typename pass_type > 503 586 void PassVisitor< pass_type >::visit( NameExpr * node ) { 504 VISIT_BODY( node ); 587 VISIT_BODY( node ); 505 588 } 506 589 507 590 template< typename pass_type > 508 591 void PassVisitor< pass_type >::visit( CastExpr * node ) { 509 VISIT_BODY( node ); 592 VISIT_BODY( node ); 510 593 } 511 594 512 595 template< typename pass_type > 513 596 void PassVisitor< pass_type >::visit( AddressExpr * node ) { 514 VISIT_BODY( node ); 597 VISIT_BODY( node ); 515 598 } 516 599 517 600 template< typename pass_type > 518 601 void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) { 519 VISIT_BODY( node ); 602 VISIT_BODY( node ); 520 603 } 521 604 522 605 template< typename pass_type > 523 606 void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { 524 VISIT_BODY( node ); 607 VISIT_BODY( node ); 525 608 } 526 609 527 610 template< typename pass_type > 528 611 void PassVisitor< pass_type >::visit( MemberExpr * node ) { 529 VISIT_BODY( node ); 612 VISIT_BODY( node ); 530 613 } 531 614 532 615 template< typename pass_type > 533 616 void PassVisitor< pass_type >::visit( VariableExpr * node ) { 534 VISIT_BODY( node ); 617 VISIT_BODY( node ); 535 618 } 536 619 537 620 template< typename pass_type > 538 621 void PassVisitor< pass_type >::visit( ConstantExpr * node ) { 539 VISIT_BODY( node ); 622 VISIT_BODY( node ); 540 623 } 541 624 542 625 template< typename pass_type > 543 626 void PassVisitor< pass_type >::visit( SizeofExpr * node ) { 544 VISIT_BODY( node ); 627 VISIT_BODY( node ); 545 628 } 546 629 547 630 template< typename pass_type > 548 631 void PassVisitor< pass_type >::visit( AlignofExpr * node ) { 549 VISIT_BODY( node ); 632 VISIT_BODY( node ); 550 633 } 551 634 552 635 template< typename pass_type > 553 636 void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) { 554 VISIT_BODY( node ); 637 VISIT_BODY( node ); 555 638 } 556 639 557 640 template< typename pass_type > 558 641 void PassVisitor< pass_type >::visit( OffsetofExpr * node ) { 559 VISIT_BODY( node ); 642 VISIT_BODY( node ); 560 643 } 561 644 562 645 template< typename pass_type > 563 646 void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) { 564 VISIT_BODY( node ); 647 VISIT_BODY( node ); 565 648 } 566 649 567 650 template< typename pass_type > 568 651 void PassVisitor< pass_type >::visit( AttrExpr * node ) { 569 VISIT_BODY( node ); 652 VISIT_BODY( node ); 570 653 } 571 654 572 655 template< typename pass_type > 573 656 void PassVisitor< pass_type >::visit( LogicalExpr * node ) { 574 VISIT_BODY( node ); 657 VISIT_BODY( node ); 575 658 } 576 659 577 660 template< typename pass_type > 578 661 void PassVisitor< pass_type >::visit( ConditionalExpr * node ) { 579 VISIT_BODY( node ); 662 VISIT_BODY( node ); 580 663 } 581 664 582 665 template< typename pass_type > 583 666 void PassVisitor< pass_type >::visit( CommaExpr * node ) { 584 VISIT_BODY( node ); 667 VISIT_BODY( node ); 585 668 } 586 669 587 670 template< typename pass_type > 588 671 void PassVisitor< pass_type >::visit( TypeExpr * node ) { 589 VISIT_BODY( node ); 672 VISIT_BODY( node ); 590 673 } 591 674 592 675 template< typename pass_type > 593 676 void PassVisitor< pass_type >::visit( AsmExpr * node ) { 594 VISIT_BODY( node ); 677 VISIT_BODY( node ); 595 678 } 596 679 597 680 template< typename pass_type > 598 681 void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) { 599 VISIT_BODY( node ); 682 VISIT_BODY( node ); 600 683 } 601 684 602 685 template< typename pass_type > 603 686 void PassVisitor< pass_type >::visit( ConstructorExpr * node ) { 604 VISIT_BODY( node ); 687 VISIT_BODY( node ); 605 688 } 606 689 607 690 template< typename pass_type > 608 691 void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) { 609 VISIT_BODY( node ); 610 } 611 612 template< typename pass_type > 613 void PassVisitor< pass_type >::visit( UntypedValofExpr * node ) { 614 VISIT_BODY( node ); 692 VISIT_BODY( node ); 615 693 } 616 694 617 695 template< typename pass_type > 618 696 void PassVisitor< pass_type >::visit( RangeExpr * node ) { 619 VISIT_BODY( node ); 697 VISIT_BODY( node ); 620 698 } 621 699 622 700 template< typename pass_type > 623 701 void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) { 624 VISIT_BODY( node ); 702 VISIT_BODY( node ); 625 703 } 626 704 627 705 template< typename pass_type > 628 706 void PassVisitor< pass_type >::visit( TupleExpr * node ) { 629 VISIT_BODY( node ); 707 VISIT_BODY( node ); 630 708 } 631 709 632 710 template< typename pass_type > 633 711 void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) { 634 VISIT_BODY( node ); 712 VISIT_BODY( node ); 635 713 } 636 714 637 715 template< typename pass_type > 638 716 void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) { 639 VISIT_BODY( node ); 717 VISIT_BODY( node ); 640 718 } 641 719 … … 659 737 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { 660 738 MUTATE_START( node ); 661 739 662 740 // don't want statements from outer CompoundStmts to be added to this StmtExpr 663 741 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); … … 672 750 template< typename pass_type > 673 751 void PassVisitor< pass_type >::visit( UniqueExpr * node ) { 674 VISIT_BODY( node ); 752 VISIT_BODY( node ); 675 753 } 676 754 677 755 template< typename pass_type > 678 756 void PassVisitor< pass_type >::visit( VoidType * node ) { 679 VISIT_BODY( node ); 757 VISIT_BODY( node ); 680 758 } 681 759 682 760 template< typename pass_type > 683 761 void PassVisitor< pass_type >::visit( BasicType * node ) { 684 VISIT_BODY( node ); 762 VISIT_BODY( node ); 685 763 } 686 764 687 765 template< typename pass_type > 688 766 void PassVisitor< pass_type >::visit( PointerType * node ) { 689 VISIT_BODY( node ); 767 VISIT_BODY( node ); 690 768 } 691 769 692 770 template< typename pass_type > 693 771 void PassVisitor< pass_type >::visit( ArrayType * node ) { 694 VISIT_BODY( node ); 772 VISIT_BODY( node ); 695 773 } 696 774 697 775 template< typename pass_type > 698 776 void PassVisitor< pass_type >::visit( FunctionType * node ) { 699 VISIT_BODY( node ); 777 VISIT_BODY( node ); 700 778 } 701 779 702 780 template< typename pass_type > 703 781 void PassVisitor< pass_type >::visit( StructInstType * node ) { 704 VISIT_BODY( node ); 782 VISIT_BODY( node ); 705 783 } 706 784 707 785 template< typename pass_type > 708 786 void PassVisitor< pass_type >::visit( UnionInstType * node ) { 709 VISIT_BODY( node ); 787 VISIT_BODY( node ); 710 788 } 711 789 712 790 template< typename pass_type > 713 791 void PassVisitor< pass_type >::visit( EnumInstType * node ) { 714 VISIT_BODY( node ); 792 VISIT_BODY( node ); 715 793 } 716 794 717 795 template< typename pass_type > 718 796 void PassVisitor< pass_type >::visit( TraitInstType * node ) { 719 VISIT_BODY( node ); 797 VISIT_BODY( node ); 720 798 } 721 799 722 800 template< typename pass_type > 723 801 void PassVisitor< pass_type >::visit( TypeInstType * node ) { 724 VISIT_BODY( node ); 802 VISIT_BODY( node ); 725 803 } 726 804 727 805 template< typename pass_type > 728 806 void PassVisitor< pass_type >::visit( TupleType * node ) { 729 VISIT_BODY( node ); 807 VISIT_BODY( node ); 730 808 } 731 809 732 810 template< typename pass_type > 733 811 void PassVisitor< pass_type >::visit( TypeofType * node ) { 734 VISIT_BODY( node ); 812 VISIT_BODY( node ); 735 813 } 736 814 737 815 template< typename pass_type > 738 816 void PassVisitor< pass_type >::visit( AttrType * node ) { 739 VISIT_BODY( node ); 817 VISIT_BODY( node ); 740 818 } 741 819 742 820 template< typename pass_type > 743 821 void PassVisitor< pass_type >::visit( VarArgsType * node ) { 744 VISIT_BODY( node ); 822 VISIT_BODY( node ); 745 823 } 746 824 747 825 template< typename pass_type > 748 826 void PassVisitor< pass_type >::visit( ZeroType * node ) { 749 VISIT_BODY( node ); 827 VISIT_BODY( node ); 750 828 } 751 829 752 830 template< typename pass_type > 753 831 void PassVisitor< pass_type >::visit( OneType * node ) { 754 VISIT_BODY( node ); 832 VISIT_BODY( node ); 755 833 } 756 834 … … 777 855 template< typename pass_type > 778 856 void PassVisitor< pass_type >::visit( ListInit * node ) { 779 VISIT_BODY( node ); 857 VISIT_BODY( node ); 780 858 } 781 859 782 860 template< typename pass_type > 783 861 void PassVisitor< pass_type >::visit( ConstructorInit * node ) { 784 VISIT_BODY( node ); 862 VISIT_BODY( node ); 785 863 } 786 864 787 865 template< typename pass_type > 788 866 void PassVisitor< pass_type >::visit( Subrange * node ) { 789 VISIT_BODY( node ); 867 VISIT_BODY( node ); 790 868 } 791 869 792 870 template< typename pass_type > 793 871 void PassVisitor< pass_type >::visit( Constant * node ) { 794 VISIT_BODY( node ); 872 VISIT_BODY( node ); 795 873 } 796 874 … … 843 921 844 922 template< typename pass_type > 845 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) {846 MUTATE_BODY( Statement, node );847 }848 849 template< typename pass_type >850 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) {851 MUTATE_BODY( Statement, node );852 }853 854 template< typename pass_type >855 923 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 856 924 MUTATE_BODY( Statement, node ); … … 988 1056 989 1057 template< typename pass_type > 990 Expression * PassVisitor< pass_type >::mutate( UntypedValofExpr * node ) {991 MUTATE_BODY( Expression, node );992 }993 994 template< typename pass_type >995 1058 Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) { 996 1059 MUTATE_BODY( Expression, node ); -
src/Common/PassVisitor.proto.h
re1c1829 r4c03e63 1 1 #pragma once 2 3 template<typename pass_type> 4 class PassVisitor; 2 5 3 6 typedef std::function<void( void * )> cleanup_func_t; … … 31 34 32 35 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t; 36 37 class bool_ref { 38 public: 39 bool_ref() = default; 40 ~bool_ref() = default; 41 42 operator bool() { return *m_ref; } 43 bool operator=( bool val ) { return *m_ref = val; } 44 45 private: 46 47 template<typename pass> 48 friend class PassVisitor; 49 50 void set( bool & val ) { m_ref = &val; }; 51 52 bool * m_ref; 53 }; 33 54 34 55 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 112 133 FIELD_PTR( std::list< Statement* >, stmtsToAddBefore ) 113 134 FIELD_PTR( std::list< Statement* >, stmtsToAddAfter ) 114 FIELD_PTR( bool, skip_children ) 135 FIELD_PTR( std::list< Declaration* >, declsToAddBefore ) 136 FIELD_PTR( std::list< Declaration* >, declsToAddAfter ) 137 FIELD_PTR( bool_ref, visit_children ) 115 138 FIELD_PTR( at_cleanup_t, at_cleanup ) 139 FIELD_PTR( PassVisitor<pass_type> * const, visitor )
Note:
See TracChangeset
for help on using the changeset viewer.