[13932f14] | 1 | #pragma once |
---|
[3268a58] | 2 | // IWYU pragma: private, include "PassVisitor.h" |
---|
[13932f14] | 3 | |
---|
[6e09f211] | 4 | #define VISIT_START( node ) \ |
---|
| 5 | __attribute__((unused)) \ |
---|
[62423350] | 6 | guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ |
---|
[b73bd70] | 7 | bool visit_children = true; \ |
---|
| 8 | set_visit_children( visit_children ); \ |
---|
[6e09f211] | 9 | call_previsit( node ); \ |
---|
[b73bd70] | 10 | if( visit_children ) { \ |
---|
[6e09f211] | 11 | |
---|
| 12 | #define VISIT_END( node ) \ |
---|
| 13 | } \ |
---|
| 14 | call_postvisit( node ); \ |
---|
[9c1600c] | 15 | |
---|
[6e09f211] | 16 | #define MUTATE_START( node ) \ |
---|
| 17 | __attribute__((unused)) \ |
---|
[62423350] | 18 | guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ |
---|
[b73bd70] | 19 | bool visit_children = true; \ |
---|
| 20 | set_visit_children( visit_children ); \ |
---|
[6e09f211] | 21 | call_premutate( node ); \ |
---|
[b73bd70] | 22 | if( visit_children ) { \ |
---|
[296b2be] | 23 | |
---|
| 24 | #define MUTATE_END( type, node ) \ |
---|
[7b13aeb] | 25 | } \ |
---|
[296b2be] | 26 | return call_postmutate< type * >( node ); \ |
---|
| 27 | |
---|
| 28 | |
---|
[6e09f211] | 29 | #define VISIT_BODY( node ) \ |
---|
| 30 | VISIT_START( node ); \ |
---|
| 31 | Visitor::visit( node ); \ |
---|
| 32 | VISIT_END( node ); \ |
---|
[13932f14] | 33 | |
---|
[ab904dc] | 34 | |
---|
[296b2be] | 35 | #define MUTATE_BODY( type, node ) \ |
---|
| 36 | MUTATE_START( node ); \ |
---|
| 37 | Mutator::mutate( node ); \ |
---|
| 38 | MUTATE_END( type, node ); \ |
---|
| 39 | |
---|
[134322e] | 40 | |
---|
| 41 | |
---|
| 42 | template<typename T> |
---|
| 43 | static inline bool empty( T * ptr ) { |
---|
| 44 | return !ptr || ptr->empty(); |
---|
| 45 | } |
---|
| 46 | |
---|
[6ca154b] | 47 | typedef std::list< Statement * > StmtList_t; |
---|
| 48 | typedef std::list< Declaration * > DeclList_t; |
---|
| 49 | |
---|
| 50 | template<typename iterator_t> |
---|
| 51 | static inline void splice( iterator_t it, DeclList_t * decls ) { |
---|
| 52 | std::transform( |
---|
| 53 | decls->begin(), |
---|
| 54 | decls->end(), |
---|
| 55 | it, |
---|
| 56 | [](Declaration * decl) -> auto { |
---|
| 57 | return new DeclStmt( noLabels, decl ); |
---|
| 58 | } |
---|
| 59 | ); |
---|
| 60 | decls->clear(); |
---|
| 61 | } |
---|
[134322e] | 62 | |
---|
| 63 | template< typename pass_type > |
---|
[6ca154b] | 64 | static inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) { |
---|
[134322e] | 65 | |
---|
[6ca154b] | 66 | DeclList_t* beforeDecls = visitor.get_beforeDecls(); |
---|
| 67 | DeclList_t* afterDecls = visitor.get_afterDecls(); |
---|
[522363e] | 68 | SemanticError errors; |
---|
[134322e] | 69 | |
---|
[6ca154b] | 70 | for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { |
---|
| 71 | // splice in new declarations after previous decl |
---|
[d24d4e1] | 72 | if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } |
---|
[6ca154b] | 73 | |
---|
| 74 | if ( i == decls.end() ) break; |
---|
| 75 | |
---|
[522363e] | 76 | try { |
---|
| 77 | // run visitor on declaration |
---|
| 78 | maybeAccept( *i, visitor ); |
---|
| 79 | } catch( SemanticError &e ) { |
---|
| 80 | e.set_location( (*i)->location ); |
---|
| 81 | errors.append( e ); |
---|
| 82 | } |
---|
[6ca154b] | 83 | |
---|
| 84 | // splice in new declarations before current decl |
---|
| 85 | if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } |
---|
[134322e] | 86 | } |
---|
[522363e] | 87 | if ( ! errors.isEmpty() ) { |
---|
| 88 | throw errors; |
---|
| 89 | } |
---|
[6ca154b] | 90 | } |
---|
[134322e] | 91 | |
---|
[6ca154b] | 92 | template< typename pass_type > |
---|
| 93 | static inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { |
---|
| 94 | |
---|
| 95 | DeclList_t* beforeDecls = mutator.get_beforeDecls(); |
---|
| 96 | DeclList_t* afterDecls = mutator.get_afterDecls(); |
---|
[522363e] | 97 | SemanticError errors; |
---|
[6ca154b] | 98 | |
---|
| 99 | for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { |
---|
| 100 | // splice in new declarations after previous decl |
---|
[d24d4e1] | 101 | if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } |
---|
[6ca154b] | 102 | |
---|
| 103 | if ( i == decls.end() ) break; |
---|
[522363e] | 104 | try { |
---|
| 105 | // run mutator on declaration |
---|
| 106 | *i = maybeMutate( *i, mutator ); |
---|
| 107 | } catch( SemanticError &e ) { |
---|
| 108 | e.set_location( (*i)->location ); |
---|
| 109 | errors.append( e ); |
---|
| 110 | } |
---|
[6ca154b] | 111 | |
---|
| 112 | // splice in new declarations before current decl |
---|
| 113 | if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } |
---|
| 114 | } |
---|
[522363e] | 115 | if ( ! errors.isEmpty() ) { |
---|
| 116 | throw errors; |
---|
| 117 | } |
---|
[134322e] | 118 | } |
---|
| 119 | |
---|
[e0886db] | 120 | template< typename Container, typename VisitorType > |
---|
| 121 | inline void maybeAccept( Container &container, VisitorType &visitor ) { |
---|
| 122 | SemanticError errors; |
---|
| 123 | for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { |
---|
| 124 | try { |
---|
| 125 | if ( *i ) { |
---|
| 126 | (*i)->accept( visitor ); |
---|
| 127 | } |
---|
| 128 | } catch( SemanticError &e ) { |
---|
| 129 | e.set_location( (*i)->location ); |
---|
| 130 | errors.append( e ); |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | if ( ! errors.isEmpty() ) { |
---|
| 134 | throw errors; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | template< typename Container, typename MutatorType > |
---|
| 139 | inline void maybeMutateRef( Container &container, MutatorType &mutator ) { |
---|
| 140 | SemanticError errors; |
---|
| 141 | for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { |
---|
| 142 | try { |
---|
| 143 | if ( *i ) { |
---|
| 144 | /// *i = (*i)->acceptMutator( mutator ); |
---|
| 145 | *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); |
---|
| 146 | assert( *i ); |
---|
| 147 | } // if |
---|
| 148 | } catch( SemanticError &e ) { |
---|
| 149 | e.set_location( (*i)->location ); |
---|
| 150 | errors.append( e ); |
---|
| 151 | } // try |
---|
| 152 | } // for |
---|
| 153 | if ( ! errors.isEmpty() ) { |
---|
| 154 | throw errors; |
---|
| 155 | } // if |
---|
| 156 | } |
---|
| 157 | |
---|
[296b2be] | 158 | template< typename pass_type > |
---|
[6ca154b] | 159 | template< typename func_t > |
---|
| 160 | void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { |
---|
[296b2be] | 161 | SemanticError errors; |
---|
| 162 | |
---|
[2a7b3ca] | 163 | // don't want statements from outer CompoundStmts to be added to this CompoundStmt |
---|
| 164 | ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); |
---|
| 165 | ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); |
---|
| 166 | ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); |
---|
| 167 | ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); |
---|
| 168 | |
---|
[134322e] | 169 | StmtList_t* beforeStmts = get_beforeStmts(); |
---|
| 170 | StmtList_t* afterStmts = get_afterStmts(); |
---|
[6ca154b] | 171 | DeclList_t* beforeDecls = get_beforeDecls(); |
---|
| 172 | DeclList_t* afterDecls = get_afterDecls(); |
---|
[134322e] | 173 | |
---|
[296b2be] | 174 | for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { |
---|
[6ca154b] | 175 | |
---|
| 176 | if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); } |
---|
[134322e] | 177 | if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } |
---|
[6ca154b] | 178 | |
---|
[296b2be] | 179 | try { |
---|
[6ca154b] | 180 | func( *i ); |
---|
| 181 | assert(( empty( beforeStmts ) && empty( afterStmts )) |
---|
| 182 | || ( empty( beforeDecls ) && empty( afterDecls )) ); |
---|
| 183 | |
---|
[296b2be] | 184 | } catch ( SemanticError &e ) { |
---|
[aa685db] | 185 | e.set_location( (*i)->location ); |
---|
[296b2be] | 186 | errors.append( e ); |
---|
[134322e] | 187 | } |
---|
[6ca154b] | 188 | |
---|
| 189 | if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); } |
---|
[134322e] | 190 | if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } |
---|
[296b2be] | 191 | } |
---|
[134322e] | 192 | |
---|
[6ca154b] | 193 | if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); } |
---|
[134322e] | 194 | if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } |
---|
| 195 | if ( !errors.isEmpty() ) { throw errors; } |
---|
[296b2be] | 196 | } |
---|
| 197 | |
---|
| 198 | template< typename pass_type > |
---|
[6ca154b] | 199 | void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { |
---|
| 200 | handleStatementList( statements, [this]( Statement * stmt) { |
---|
| 201 | stmt->accept( *this ); |
---|
| 202 | }); |
---|
| 203 | } |
---|
[134322e] | 204 | |
---|
[6ca154b] | 205 | template< typename pass_type > |
---|
| 206 | void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { |
---|
| 207 | handleStatementList( statements, [this]( Statement *& stmt) { |
---|
| 208 | stmt = stmt->acceptMutator( *this ); |
---|
| 209 | }); |
---|
[134322e] | 210 | } |
---|
| 211 | |
---|
[6ca154b] | 212 | |
---|
[134322e] | 213 | template< typename pass_type > |
---|
[6ca154b] | 214 | template< typename func_t > |
---|
| 215 | Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) { |
---|
[134322e] | 216 | // don't want statements from outer CompoundStmts to be added to this CompoundStmt |
---|
[6ca154b] | 217 | ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr () ); |
---|
| 218 | ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); |
---|
| 219 | ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); |
---|
| 220 | ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); |
---|
| 221 | ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); |
---|
[296b2be] | 222 | |
---|
[6ca154b] | 223 | Statement *newStmt = func( stmt ); |
---|
[134322e] | 224 | |
---|
| 225 | StmtList_t* beforeStmts = get_beforeStmts(); |
---|
| 226 | StmtList_t* afterStmts = get_afterStmts(); |
---|
[6ca154b] | 227 | DeclList_t* beforeDecls = get_beforeDecls(); |
---|
| 228 | DeclList_t* afterDecls = get_afterDecls(); |
---|
[134322e] | 229 | |
---|
[6ca154b] | 230 | if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; } |
---|
| 231 | assert(( empty( beforeStmts ) && empty( afterStmts )) |
---|
| 232 | || ( empty( beforeDecls ) && empty( afterDecls )) ); |
---|
[134322e] | 233 | |
---|
| 234 | CompoundStmt *compound = new CompoundStmt( noLabels ); |
---|
[6ca154b] | 235 | if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } |
---|
[134322e] | 236 | if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } |
---|
| 237 | compound->get_kids().push_back( newStmt ); |
---|
[6ca154b] | 238 | if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); } |
---|
[134322e] | 239 | if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } |
---|
| 240 | return compound; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | template< typename pass_type > |
---|
[6ca154b] | 244 | Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { |
---|
| 245 | return handleStatement( stmt, [this]( Statement * stmt ) { |
---|
[d24d4e1] | 246 | maybeAccept( stmt, *this ); |
---|
[6ca154b] | 247 | return stmt; |
---|
| 248 | }); |
---|
| 249 | } |
---|
[134322e] | 250 | |
---|
[6ca154b] | 251 | template< typename pass_type > |
---|
| 252 | Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { |
---|
| 253 | return handleStatement( stmt, [this]( Statement * stmt ) { |
---|
| 254 | return maybeMutate( stmt, *this ); |
---|
| 255 | }); |
---|
[296b2be] | 256 | } |
---|
| 257 | |
---|
| 258 | template< typename pass_type > |
---|
[6ca154b] | 259 | template< typename func_t > |
---|
| 260 | Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) { |
---|
[296b2be] | 261 | if( !expr ) return nullptr; |
---|
| 262 | |
---|
[134322e] | 263 | auto env_ptr = get_env_ptr(); |
---|
| 264 | if ( env_ptr && expr->get_env() ) { |
---|
| 265 | *env_ptr = expr->get_env(); |
---|
[296b2be] | 266 | } |
---|
[6ca154b] | 267 | |
---|
| 268 | // should env be cloned (or moved) onto the result of the mutate? |
---|
| 269 | return func( expr ); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | template< typename pass_type > |
---|
| 273 | Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) { |
---|
| 274 | return handleExpression(expr, [this]( Expression * expr ) { |
---|
| 275 | expr->accept( *this ); |
---|
| 276 | return expr; |
---|
[d24d4e1] | 277 | }); |
---|
[296b2be] | 278 | } |
---|
[ab904dc] | 279 | |
---|
[6ca154b] | 280 | template< typename pass_type > |
---|
| 281 | Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { |
---|
| 282 | return handleExpression(expr, [this]( Expression * expr ) { |
---|
| 283 | return expr->acceptMutator( *this ); |
---|
| 284 | }); |
---|
| 285 | } |
---|
[ab904dc] | 286 | |
---|
[296b2be] | 287 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
---|
[e0886db] | 288 | //======================================================================================================================================================================== |
---|
| 289 | //======================================================================================================================================================================== |
---|
| 290 | //======================================================================================================================================================================== |
---|
| 291 | //======================================================================================================================================================================== |
---|
| 292 | //======================================================================================================================================================================== |
---|
| 293 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
---|
[13932f14] | 294 | |
---|
[33a25f9] | 295 | // A NOTE ON THE ORDER OF TRAVERSAL |
---|
| 296 | // |
---|
| 297 | // Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is |
---|
| 298 | // no such thing as a recursive type or typedef. |
---|
| 299 | // |
---|
| 300 | // typedef struct { T *x; } T; // never allowed |
---|
| 301 | // |
---|
| 302 | // for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the |
---|
| 303 | // members are traversed, and then the complete type should be added (assuming the type is completed by this particular |
---|
| 304 | // declaration). |
---|
| 305 | // |
---|
| 306 | // struct T { struct T *x; }; // allowed |
---|
| 307 | // |
---|
| 308 | // It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that |
---|
| 309 | // traversal may modify the definition of the type and these modifications should be visible when the symbol table is |
---|
| 310 | // queried later in this pass. |
---|
| 311 | // |
---|
| 312 | // TODO: figure out whether recursive contexts are sensible/possible/reasonable. |
---|
[e0886db] | 313 | |
---|
| 314 | //-------------------------------------------------------------------------- |
---|
| 315 | // ObjectDecl |
---|
[13932f14] | 316 | template< typename pass_type > |
---|
[ab904dc] | 317 | void PassVisitor< pass_type >::visit( ObjectDecl * node ) { |
---|
[e0886db] | 318 | VISIT_START( node ); |
---|
| 319 | |
---|
| 320 | indexerScopedAccept( node->type , *this ); |
---|
| 321 | maybeAccept ( node->init , *this ); |
---|
| 322 | maybeAccept ( node->bitfieldWidth, *this ); |
---|
| 323 | |
---|
| 324 | if ( node->name != "" ) { |
---|
| 325 | indexerAddId( node ); |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | VISIT_END( node ); |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | template< typename pass_type > |
---|
| 332 | DeclarationWithType * PassVisitor< pass_type >::mutate( ObjectDecl * node ) { |
---|
| 333 | MUTATE_START( node ); |
---|
| 334 | |
---|
| 335 | indexerScopedMutate( node->type , *this ); |
---|
| 336 | maybeMutateRef ( node->init , *this ); |
---|
| 337 | maybeMutateRef ( node->bitfieldWidth, *this ); |
---|
| 338 | |
---|
| 339 | if ( node->name != "" ) { |
---|
| 340 | indexerAddId( node ); |
---|
| 341 | } |
---|
| 342 | |
---|
| 343 | MUTATE_END( DeclarationWithType, node ); |
---|
[13932f14] | 344 | } |
---|
| 345 | |
---|
[e0886db] | 346 | //-------------------------------------------------------------------------- |
---|
| 347 | // FunctionDecl |
---|
[13932f14] | 348 | template< typename pass_type > |
---|
[ab904dc] | 349 | void PassVisitor< pass_type >::visit( FunctionDecl * node ) { |
---|
[e0886db] | 350 | VISIT_START( node ); |
---|
| 351 | |
---|
| 352 | if ( node->name != "" ) { |
---|
| 353 | indexerAddId( node ); |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | { |
---|
| 357 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 358 | maybeAccept( node->type, *this ); |
---|
| 359 | maybeAccept( node->statements, *this ); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | VISIT_END( node ); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | template< typename pass_type > |
---|
| 366 | DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) { |
---|
| 367 | MUTATE_START( node ); |
---|
| 368 | |
---|
| 369 | if ( node->name != "" ) { |
---|
| 370 | indexerAddId( node ); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | { |
---|
| 374 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 375 | maybeMutateRef( node->type, *this ); |
---|
| 376 | maybeMutateRef( node->statements, *this ); |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | MUTATE_END( DeclarationWithType, node ); |
---|
[13932f14] | 380 | } |
---|
| 381 | |
---|
[e0886db] | 382 | //-------------------------------------------------------------------------- |
---|
| 383 | // StructDecl |
---|
[13932f14] | 384 | template< typename pass_type > |
---|
[ab904dc] | 385 | void PassVisitor< pass_type >::visit( StructDecl * node ) { |
---|
[e0886db] | 386 | VISIT_START( node ); |
---|
| 387 | |
---|
| 388 | // make up a forward declaration and add it before processing the members |
---|
| 389 | // needs to be on the heap because addStruct saves the pointer |
---|
| 390 | indexerAddStructFwd( node ); |
---|
| 391 | |
---|
| 392 | { |
---|
| 393 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 394 | maybeAccept( node->parameters, *this ); |
---|
| 395 | maybeAccept( node->members , *this ); |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | // this addition replaces the forward declaration |
---|
| 399 | indexerAddStruct( node ); |
---|
| 400 | |
---|
| 401 | VISIT_END( node ); |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | template< typename pass_type > |
---|
| 405 | Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) { |
---|
| 406 | MUTATE_START( node ); |
---|
| 407 | |
---|
| 408 | // make up a forward declaration and add it before processing the members |
---|
| 409 | // needs to be on the heap because addStruct saves the pointer |
---|
| 410 | indexerAddStructFwd( node ); |
---|
| 411 | |
---|
| 412 | { |
---|
| 413 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 414 | maybeMutateRef( node->parameters, *this ); |
---|
| 415 | maybeMutateRef( node->members , *this ); |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | // this addition replaces the forward declaration |
---|
| 419 | indexerAddStruct( node ); |
---|
| 420 | |
---|
| 421 | MUTATE_END( Declaration, node ); |
---|
[13932f14] | 422 | } |
---|
| 423 | |
---|
[e0886db] | 424 | //-------------------------------------------------------------------------- |
---|
| 425 | // UnionDecl |
---|
[13932f14] | 426 | template< typename pass_type > |
---|
[ab904dc] | 427 | void PassVisitor< pass_type >::visit( UnionDecl * node ) { |
---|
[e0886db] | 428 | VISIT_START( node ); |
---|
| 429 | |
---|
| 430 | // make up a forward declaration and add it before processing the members |
---|
| 431 | indexerAddUnionFwd( node ); |
---|
| 432 | |
---|
| 433 | { |
---|
| 434 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 435 | maybeAccept( node->parameters, *this ); |
---|
| 436 | maybeAccept( node->members , *this ); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | indexerAddUnion( node ); |
---|
| 440 | |
---|
| 441 | VISIT_END( node ); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | template< typename pass_type > |
---|
| 445 | Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) { |
---|
| 446 | MUTATE_START( node ); |
---|
| 447 | |
---|
| 448 | // make up a forward declaration and add it before processing the members |
---|
| 449 | indexerAddUnionFwd( node ); |
---|
| 450 | |
---|
| 451 | { |
---|
| 452 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 453 | maybeMutateRef( node->parameters, *this ); |
---|
| 454 | maybeMutateRef( node->members , *this ); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | indexerAddUnion( node ); |
---|
| 458 | |
---|
| 459 | MUTATE_END( Declaration, node ); |
---|
[13932f14] | 460 | } |
---|
| 461 | |
---|
[e0886db] | 462 | //-------------------------------------------------------------------------- |
---|
| 463 | // EnumDecl |
---|
[13932f14] | 464 | template< typename pass_type > |
---|
[ab904dc] | 465 | void PassVisitor< pass_type >::visit( EnumDecl * node ) { |
---|
[e0886db] | 466 | VISIT_START( node ); |
---|
| 467 | |
---|
| 468 | indexerAddEnum( node ); |
---|
| 469 | |
---|
[33a25f9] | 470 | // unlike structs, traits, and unions, enums inject their members into the global scope |
---|
[e0886db] | 471 | maybeAccept( node->parameters, *this ); |
---|
| 472 | maybeAccept( node->members , *this ); |
---|
| 473 | |
---|
| 474 | VISIT_END( node ); |
---|
[13932f14] | 475 | } |
---|
| 476 | |
---|
[e0886db] | 477 | template< typename pass_type > |
---|
| 478 | Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) { |
---|
| 479 | MUTATE_START( node ); |
---|
| 480 | |
---|
| 481 | indexerAddEnum( node ); |
---|
| 482 | |
---|
[522363e] | 483 | // unlike structs, traits, and unions, enums inject their members into the global scope |
---|
[e0886db] | 484 | maybeMutateRef( node->parameters, *this ); |
---|
| 485 | maybeMutateRef( node->members , *this ); |
---|
| 486 | |
---|
| 487 | MUTATE_END( Declaration, node ); |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | //-------------------------------------------------------------------------- |
---|
| 491 | // TraitDecl |
---|
[13932f14] | 492 | template< typename pass_type > |
---|
[ab904dc] | 493 | void PassVisitor< pass_type >::visit( TraitDecl * node ) { |
---|
[e0886db] | 494 | VISIT_START( node ); |
---|
| 495 | |
---|
| 496 | { |
---|
| 497 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 498 | maybeAccept( node->parameters, *this ); |
---|
| 499 | maybeAccept( node->members , *this ); |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | indexerAddTrait( node ); |
---|
| 503 | |
---|
| 504 | VISIT_END( node ); |
---|
[13932f14] | 505 | } |
---|
| 506 | |
---|
[e0886db] | 507 | template< typename pass_type > |
---|
| 508 | Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) { |
---|
| 509 | MUTATE_START( node ); |
---|
| 510 | |
---|
| 511 | { |
---|
| 512 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 513 | maybeMutateRef( node->parameters, *this ); |
---|
| 514 | maybeMutateRef( node->members , *this ); |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | indexerAddTrait( node ); |
---|
| 518 | |
---|
| 519 | MUTATE_END( Declaration, node ); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | //-------------------------------------------------------------------------- |
---|
| 523 | // TypeDecl |
---|
[13932f14] | 524 | template< typename pass_type > |
---|
[ab904dc] | 525 | void PassVisitor< pass_type >::visit( TypeDecl * node ) { |
---|
[e0886db] | 526 | VISIT_START( node ); |
---|
| 527 | |
---|
| 528 | { |
---|
| 529 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 530 | maybeAccept( node->parameters, *this ); |
---|
| 531 | maybeAccept( node->base , *this ); |
---|
| 532 | } |
---|
| 533 | |
---|
[33a25f9] | 534 | // see A NOTE ON THE ORDER OF TRAVERSAL, above |
---|
| 535 | // note that assertions come after the type is added to the symtab, since they are not part of the type proper |
---|
| 536 | // and may depend on the type itself |
---|
[e0886db] | 537 | indexerAddType( node ); |
---|
| 538 | |
---|
| 539 | maybeAccept( node->assertions, *this ); |
---|
| 540 | |
---|
| 541 | indexerScopedAccept( node->init, *this ); |
---|
| 542 | |
---|
| 543 | VISIT_END( node ); |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | template< typename pass_type > |
---|
[982832e] | 547 | Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) { |
---|
[e0886db] | 548 | MUTATE_START( node ); |
---|
| 549 | |
---|
| 550 | { |
---|
| 551 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 552 | maybeMutateRef( node->parameters, *this ); |
---|
| 553 | maybeMutateRef( node->base , *this ); |
---|
| 554 | } |
---|
| 555 | |
---|
[33a25f9] | 556 | // see A NOTE ON THE ORDER OF TRAVERSAL, above |
---|
| 557 | // note that assertions come after the type is added to the symtab, since they are not part of the type proper |
---|
| 558 | // and may depend on the type itself |
---|
[e0886db] | 559 | indexerAddType( node ); |
---|
| 560 | |
---|
| 561 | maybeMutateRef( node->assertions, *this ); |
---|
| 562 | |
---|
| 563 | indexerScopedMutate( node->init, *this ); |
---|
| 564 | |
---|
[982832e] | 565 | MUTATE_END( Declaration, node ); |
---|
[13932f14] | 566 | } |
---|
| 567 | |
---|
[e0886db] | 568 | //-------------------------------------------------------------------------- |
---|
| 569 | // TypedefDecl |
---|
[13932f14] | 570 | template< typename pass_type > |
---|
[ab904dc] | 571 | void PassVisitor< pass_type >::visit( TypedefDecl * node ) { |
---|
[e0886db] | 572 | VISIT_START( node ); |
---|
| 573 | |
---|
| 574 | { |
---|
| 575 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 576 | maybeAccept( node->parameters, *this ); |
---|
| 577 | maybeAccept( node->base , *this ); |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | indexerAddType( node ); |
---|
| 581 | |
---|
| 582 | maybeAccept( node->assertions, *this ); |
---|
| 583 | |
---|
| 584 | VISIT_END( node ); |
---|
[13932f14] | 585 | } |
---|
| 586 | |
---|
| 587 | template< typename pass_type > |
---|
[e0886db] | 588 | Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) { |
---|
| 589 | MUTATE_START( node ); |
---|
| 590 | |
---|
| 591 | { |
---|
| 592 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 593 | maybeMutateRef ( node->parameters, *this ); |
---|
| 594 | maybeMutateRef( node->base , *this ); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | indexerAddType( node ); |
---|
| 598 | |
---|
| 599 | maybeMutateRef( node->assertions, *this ); |
---|
| 600 | |
---|
| 601 | MUTATE_END( Declaration, node ); |
---|
[13932f14] | 602 | } |
---|
| 603 | |
---|
[9c1600c] | 604 | //-------------------------------------------------------------------------- |
---|
[e0886db] | 605 | // AsmDecl |
---|
[13932f14] | 606 | template< typename pass_type > |
---|
[e0886db] | 607 | void PassVisitor< pass_type >::visit( AsmDecl * node ) { |
---|
[9c1600c] | 608 | VISIT_START( node ); |
---|
| 609 | |
---|
[e0886db] | 610 | maybeAccept( node->stmt, *this ); |
---|
[9c1600c] | 611 | |
---|
| 612 | VISIT_END( node ); |
---|
[13932f14] | 613 | } |
---|
| 614 | |
---|
[296b2be] | 615 | template< typename pass_type > |
---|
[e0886db] | 616 | AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) { |
---|
[296b2be] | 617 | MUTATE_START( node ); |
---|
| 618 | |
---|
[e0886db] | 619 | maybeMutateRef( node->stmt, *this ); |
---|
| 620 | |
---|
| 621 | MUTATE_END( AsmDecl, node ); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | //-------------------------------------------------------------------------- |
---|
| 625 | // CompoundStmt |
---|
| 626 | template< typename pass_type > |
---|
| 627 | void PassVisitor< pass_type >::visit( CompoundStmt * node ) { |
---|
| 628 | VISIT_START( node ); |
---|
| 629 | { |
---|
| 630 | auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 631 | auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); |
---|
| 632 | visitStatementList( node->kids ); |
---|
| 633 | } |
---|
| 634 | VISIT_END( node ); |
---|
| 635 | } |
---|
[296b2be] | 636 | |
---|
[e0886db] | 637 | template< typename pass_type > |
---|
| 638 | CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) { |
---|
| 639 | MUTATE_START( node ); |
---|
| 640 | { |
---|
| 641 | auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 642 | auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); |
---|
| 643 | mutateStatementList( node->kids ); |
---|
| 644 | } |
---|
[296b2be] | 645 | MUTATE_END( CompoundStmt, node ); |
---|
| 646 | } |
---|
| 647 | |
---|
[9c1600c] | 648 | //-------------------------------------------------------------------------- |
---|
| 649 | // ExprStmt |
---|
[13932f14] | 650 | template< typename pass_type > |
---|
[ab904dc] | 651 | void PassVisitor< pass_type >::visit( ExprStmt * node ) { |
---|
[9c1600c] | 652 | VISIT_START( node ); |
---|
| 653 | |
---|
[e0886db] | 654 | visitExpression( node->expr ); |
---|
[9c1600c] | 655 | |
---|
| 656 | VISIT_END( node ); |
---|
[13932f14] | 657 | } |
---|
| 658 | |
---|
[296b2be] | 659 | template< typename pass_type > |
---|
| 660 | Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) { |
---|
| 661 | MUTATE_START( node ); |
---|
| 662 | |
---|
[e0886db] | 663 | node->expr = mutateExpression( node->expr ); |
---|
[296b2be] | 664 | |
---|
| 665 | MUTATE_END( Statement, node ); |
---|
| 666 | } |
---|
| 667 | |
---|
[6ca154b] | 668 | //-------------------------------------------------------------------------- |
---|
| 669 | // AsmStmt |
---|
[13932f14] | 670 | template< typename pass_type > |
---|
[ab904dc] | 671 | void PassVisitor< pass_type >::visit( AsmStmt * node ) { |
---|
[4551a6e] | 672 | VISIT_BODY( node ); |
---|
[13932f14] | 673 | } |
---|
| 674 | |
---|
[6ca154b] | 675 | template< typename pass_type > |
---|
| 676 | Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { |
---|
| 677 | MUTATE_BODY( Statement, node ); |
---|
| 678 | } |
---|
| 679 | |
---|
[9c1600c] | 680 | //-------------------------------------------------------------------------- |
---|
| 681 | // IfStmt |
---|
[13932f14] | 682 | template< typename pass_type > |
---|
[ab904dc] | 683 | void PassVisitor< pass_type >::visit( IfStmt * node ) { |
---|
[4551a6e] | 684 | VISIT_START( node ); |
---|
[33a25f9] | 685 | { |
---|
| 686 | // if statements introduce a level of scope (for the initialization) |
---|
| 687 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 688 | acceptAll( node->get_initialization(), *this ); |
---|
| 689 | visitExpression( node->condition ); |
---|
| 690 | node->thenPart = visitStatement( node->thenPart ); |
---|
| 691 | node->elsePart = visitStatement( node->elsePart ); |
---|
| 692 | } |
---|
[9c1600c] | 693 | VISIT_END( node ); |
---|
[13932f14] | 694 | } |
---|
| 695 | |
---|
[296b2be] | 696 | template< typename pass_type > |
---|
| 697 | Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { |
---|
[4551a6e] | 698 | MUTATE_START( node ); |
---|
[e0886db] | 699 | { |
---|
[33a25f9] | 700 | // if statements introduce a level of scope (for the initialization) |
---|
[e0886db] | 701 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
[33a25f9] | 702 | maybeMutateRef( node->get_initialization(), *this ); |
---|
[e0886db] | 703 | node->condition = mutateExpression( node->condition ); |
---|
| 704 | node->thenPart = mutateStatement ( node->thenPart ); |
---|
| 705 | node->elsePart = mutateStatement ( node->elsePart ); |
---|
| 706 | } |
---|
[296b2be] | 707 | MUTATE_END( Statement, node ); |
---|
| 708 | } |
---|
| 709 | |
---|
[9c1600c] | 710 | //-------------------------------------------------------------------------- |
---|
| 711 | // WhileStmt |
---|
[13932f14] | 712 | template< typename pass_type > |
---|
[ab904dc] | 713 | void PassVisitor< pass_type >::visit( WhileStmt * node ) { |
---|
[4551a6e] | 714 | VISIT_START( node ); |
---|
[9c1600c] | 715 | |
---|
[e0886db] | 716 | visitExpression( node->condition ); |
---|
| 717 | node->body = visitStatement( node->body ); |
---|
[9c1600c] | 718 | |
---|
| 719 | VISIT_END( node ); |
---|
[13932f14] | 720 | } |
---|
| 721 | |
---|
[296b2be] | 722 | template< typename pass_type > |
---|
| 723 | Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { |
---|
[4551a6e] | 724 | MUTATE_START( node ); |
---|
[296b2be] | 725 | |
---|
[e0886db] | 726 | node->condition = mutateExpression( node->condition ); |
---|
| 727 | node->body = mutateStatement ( node->body ); |
---|
[296b2be] | 728 | |
---|
| 729 | MUTATE_END( Statement, node ); |
---|
| 730 | } |
---|
| 731 | |
---|
[9c1600c] | 732 | //-------------------------------------------------------------------------- |
---|
[6ca154b] | 733 | // ForStmt |
---|
[13932f14] | 734 | template< typename pass_type > |
---|
[ab904dc] | 735 | void PassVisitor< pass_type >::visit( ForStmt * node ) { |
---|
[4551a6e] | 736 | VISIT_START( node ); |
---|
[e0886db] | 737 | { |
---|
[33a25f9] | 738 | // for statements introduce a level of scope (for the initialization) |
---|
[e0886db] | 739 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 740 | maybeAccept( node->initialization, *this ); |
---|
| 741 | visitExpression( node->condition ); |
---|
| 742 | visitExpression( node->increment ); |
---|
| 743 | node->body = visitStatement( node->body ); |
---|
| 744 | } |
---|
[9c1600c] | 745 | VISIT_END( node ); |
---|
[13932f14] | 746 | } |
---|
| 747 | |
---|
[296b2be] | 748 | template< typename pass_type > |
---|
| 749 | Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { |
---|
[4551a6e] | 750 | MUTATE_START( node ); |
---|
[e0886db] | 751 | { |
---|
[33a25f9] | 752 | // for statements introduce a level of scope (for the initialization) |
---|
[e0886db] | 753 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 754 | maybeMutateRef( node->initialization, *this ); |
---|
| 755 | node->condition = mutateExpression( node->condition ); |
---|
| 756 | node->increment = mutateExpression( node->increment ); |
---|
| 757 | node->body = mutateStatement ( node->body ); |
---|
| 758 | } |
---|
[296b2be] | 759 | MUTATE_END( Statement, node ); |
---|
| 760 | } |
---|
| 761 | |
---|
[9c1600c] | 762 | //-------------------------------------------------------------------------- |
---|
| 763 | // SwitchStmt |
---|
[13932f14] | 764 | template< typename pass_type > |
---|
[ab904dc] | 765 | void PassVisitor< pass_type >::visit( SwitchStmt * node ) { |
---|
[4551a6e] | 766 | VISIT_START( node ); |
---|
[9c1600c] | 767 | |
---|
[e0886db] | 768 | visitExpression ( node->condition ); |
---|
| 769 | visitStatementList( node->statements ); |
---|
[9c1600c] | 770 | |
---|
| 771 | VISIT_END( node ); |
---|
[13932f14] | 772 | } |
---|
| 773 | |
---|
[296b2be] | 774 | template< typename pass_type > |
---|
| 775 | Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { |
---|
[4551a6e] | 776 | MUTATE_START( node ); |
---|
| 777 | |
---|
[e0886db] | 778 | node->condition = mutateExpression( node->condition ); |
---|
| 779 | mutateStatementList( node->statements ); |
---|
[4551a6e] | 780 | |
---|
[296b2be] | 781 | MUTATE_END( Statement, node ); |
---|
| 782 | } |
---|
| 783 | |
---|
[9c1600c] | 784 | //-------------------------------------------------------------------------- |
---|
[35df560] | 785 | // CaseStmt |
---|
[13932f14] | 786 | template< typename pass_type > |
---|
[ab904dc] | 787 | void PassVisitor< pass_type >::visit( CaseStmt * node ) { |
---|
[4551a6e] | 788 | VISIT_START( node ); |
---|
| 789 | |
---|
[e0886db] | 790 | visitExpression ( node->condition ); |
---|
| 791 | visitStatementList( node->stmts ); |
---|
[4551a6e] | 792 | |
---|
[9c1600c] | 793 | VISIT_END( node ); |
---|
[13932f14] | 794 | } |
---|
| 795 | |
---|
[296b2be] | 796 | template< typename pass_type > |
---|
| 797 | Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { |
---|
[4551a6e] | 798 | MUTATE_START( node ); |
---|
| 799 | |
---|
[e0886db] | 800 | node->condition = mutateExpression( node->condition ); |
---|
| 801 | mutateStatementList( node->stmts ); |
---|
[4551a6e] | 802 | |
---|
[296b2be] | 803 | MUTATE_END( Statement, node ); |
---|
| 804 | } |
---|
| 805 | |
---|
[6ca154b] | 806 | //-------------------------------------------------------------------------- |
---|
| 807 | // BranchStmt |
---|
[13932f14] | 808 | template< typename pass_type > |
---|
[ab904dc] | 809 | void PassVisitor< pass_type >::visit( BranchStmt * node ) { |
---|
[4551a6e] | 810 | VISIT_BODY( node ); |
---|
[13932f14] | 811 | } |
---|
| 812 | |
---|
[6ca154b] | 813 | template< typename pass_type > |
---|
| 814 | Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { |
---|
| 815 | MUTATE_BODY( Statement, node ); |
---|
| 816 | } |
---|
| 817 | |
---|
[9c1600c] | 818 | //-------------------------------------------------------------------------- |
---|
| 819 | // ReturnStmt |
---|
[13932f14] | 820 | template< typename pass_type > |
---|
[ab904dc] | 821 | void PassVisitor< pass_type >::visit( ReturnStmt * node ) { |
---|
[9c1600c] | 822 | VISIT_START( node ); |
---|
| 823 | |
---|
[e0886db] | 824 | visitExpression( node->expr ); |
---|
[9c1600c] | 825 | |
---|
| 826 | VISIT_END( node ); |
---|
[13932f14] | 827 | } |
---|
| 828 | |
---|
[296b2be] | 829 | template< typename pass_type > |
---|
| 830 | Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) { |
---|
| 831 | MUTATE_START( node ); |
---|
| 832 | |
---|
[e0886db] | 833 | node->expr = mutateExpression( node->expr ); |
---|
[296b2be] | 834 | |
---|
| 835 | MUTATE_END( Statement, node ); |
---|
| 836 | } |
---|
| 837 | |
---|
[6e09f211] | 838 | //-------------------------------------------------------------------------- |
---|
| 839 | // ThrowStmt |
---|
| 840 | |
---|
| 841 | template< typename pass_type > |
---|
| 842 | void PassVisitor< pass_type >::visit( ThrowStmt * node ) { |
---|
| 843 | VISIT_BODY( node ); |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | template< typename pass_type > |
---|
| 847 | Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) { |
---|
| 848 | MUTATE_BODY( Statement, node ); |
---|
| 849 | } |
---|
| 850 | |
---|
[9c1600c] | 851 | //-------------------------------------------------------------------------- |
---|
| 852 | // TryStmt |
---|
[13932f14] | 853 | template< typename pass_type > |
---|
[ab904dc] | 854 | void PassVisitor< pass_type >::visit( TryStmt * node ) { |
---|
[9c1600c] | 855 | VISIT_START( node ); |
---|
| 856 | |
---|
[e0886db] | 857 | maybeAccept( node->block , *this ); |
---|
[9dcb653] | 858 | maybeAccept( node->handlers , *this ); |
---|
[e0886db] | 859 | maybeAccept( node->finallyBlock, *this ); |
---|
[9c1600c] | 860 | |
---|
| 861 | VISIT_END( node ); |
---|
[13932f14] | 862 | } |
---|
| 863 | |
---|
[296b2be] | 864 | template< typename pass_type > |
---|
| 865 | Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) { |
---|
| 866 | MUTATE_START( node ); |
---|
| 867 | |
---|
[e0886db] | 868 | maybeMutateRef( node->block , *this ); |
---|
[9dcb653] | 869 | maybeMutateRef( node->handlers , *this ); |
---|
[e0886db] | 870 | maybeMutateRef( node->finallyBlock, *this ); |
---|
[4551a6e] | 871 | |
---|
[296b2be] | 872 | MUTATE_END( Statement, node ); |
---|
| 873 | } |
---|
| 874 | |
---|
[9c1600c] | 875 | //-------------------------------------------------------------------------- |
---|
| 876 | // CatchStmt |
---|
[13932f14] | 877 | template< typename pass_type > |
---|
[ab904dc] | 878 | void PassVisitor< pass_type >::visit( CatchStmt * node ) { |
---|
[9c1600c] | 879 | VISIT_START( node ); |
---|
[e0886db] | 880 | { |
---|
[33a25f9] | 881 | // catch statements introduce a level of scope (for the caught exception) |
---|
[e0886db] | 882 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 883 | maybeAccept( node->decl, *this ); |
---|
| 884 | node->cond = visitExpression( node->cond ); |
---|
| 885 | node->body = visitStatement ( node->body ); |
---|
| 886 | } |
---|
[9c1600c] | 887 | VISIT_END( node ); |
---|
[13932f14] | 888 | } |
---|
| 889 | |
---|
[296b2be] | 890 | template< typename pass_type > |
---|
| 891 | Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { |
---|
| 892 | MUTATE_START( node ); |
---|
[e0886db] | 893 | { |
---|
[33a25f9] | 894 | // catch statements introduce a level of scope (for the caught exception) |
---|
[e0886db] | 895 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 896 | maybeMutateRef( node->decl, *this ); |
---|
| 897 | node->cond = mutateExpression( node->cond ); |
---|
| 898 | node->body = mutateStatement ( node->body ); |
---|
| 899 | } |
---|
[296b2be] | 900 | MUTATE_END( Statement, node ); |
---|
| 901 | } |
---|
| 902 | |
---|
[2065609] | 903 | //-------------------------------------------------------------------------- |
---|
| 904 | // FinallyStmt |
---|
[13932f14] | 905 | template< typename pass_type > |
---|
[ab904dc] | 906 | void PassVisitor< pass_type >::visit( FinallyStmt * node ) { |
---|
[4551a6e] | 907 | VISIT_BODY( node ); |
---|
[13932f14] | 908 | } |
---|
| 909 | |
---|
[2065609] | 910 | template< typename pass_type > |
---|
| 911 | Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { |
---|
| 912 | MUTATE_BODY( Statement, node ); |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | //-------------------------------------------------------------------------- |
---|
| 916 | // WaitForStmt |
---|
| 917 | template< typename pass_type > |
---|
| 918 | void PassVisitor< pass_type >::visit( WaitForStmt * node ) { |
---|
| 919 | VISIT_BODY( node ); |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | template< typename pass_type > |
---|
| 923 | Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) { |
---|
| 924 | MUTATE_BODY( Statement, node ); |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | //-------------------------------------------------------------------------- |
---|
| 928 | // NullStmt |
---|
[13932f14] | 929 | template< typename pass_type > |
---|
[ab904dc] | 930 | void PassVisitor< pass_type >::visit( NullStmt * node ) { |
---|
[4551a6e] | 931 | VISIT_BODY( node ); |
---|
[13932f14] | 932 | } |
---|
| 933 | |
---|
[2065609] | 934 | template< typename pass_type > |
---|
| 935 | NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) { |
---|
| 936 | MUTATE_BODY( NullStmt, node ); |
---|
| 937 | } |
---|
| 938 | |
---|
| 939 | //-------------------------------------------------------------------------- |
---|
| 940 | // DeclStmt |
---|
[13932f14] | 941 | template< typename pass_type > |
---|
[ab904dc] | 942 | void PassVisitor< pass_type >::visit( DeclStmt * node ) { |
---|
[4551a6e] | 943 | VISIT_BODY( node ); |
---|
[13932f14] | 944 | } |
---|
| 945 | |
---|
[2065609] | 946 | template< typename pass_type > |
---|
| 947 | Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) { |
---|
| 948 | MUTATE_BODY( Statement, node ); |
---|
| 949 | } |
---|
| 950 | |
---|
| 951 | //-------------------------------------------------------------------------- |
---|
| 952 | // ImplicitCtorDtorStmt |
---|
[13932f14] | 953 | template< typename pass_type > |
---|
[ab904dc] | 954 | void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { |
---|
[4551a6e] | 955 | VISIT_BODY( node ); |
---|
[13932f14] | 956 | } |
---|
| 957 | |
---|
[2065609] | 958 | template< typename pass_type > |
---|
| 959 | Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) { |
---|
| 960 | MUTATE_BODY( Statement, node ); |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | //-------------------------------------------------------------------------- |
---|
| 964 | // ApplicationExpr |
---|
[13932f14] | 965 | template< typename pass_type > |
---|
[ab904dc] | 966 | void PassVisitor< pass_type >::visit( ApplicationExpr * node ) { |
---|
[e0886db] | 967 | VISIT_START( node ); |
---|
| 968 | |
---|
| 969 | indexerScopedAccept( node->result , *this ); |
---|
| 970 | maybeAccept ( node->function, *this ); |
---|
[9dcb653] | 971 | maybeAccept ( node->args , *this ); |
---|
[e0886db] | 972 | |
---|
| 973 | VISIT_END( node ); |
---|
[13932f14] | 974 | } |
---|
| 975 | |
---|
[2065609] | 976 | template< typename pass_type > |
---|
| 977 | Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) { |
---|
[e0886db] | 978 | MUTATE_START( node ); |
---|
| 979 | |
---|
| 980 | indexerScopedMutate( node->env , *this ); |
---|
| 981 | indexerScopedMutate( node->result , *this ); |
---|
| 982 | maybeMutateRef ( node->function, *this ); |
---|
[9dcb653] | 983 | maybeMutateRef ( node->args , *this ); |
---|
[e0886db] | 984 | |
---|
| 985 | MUTATE_END( Expression, node ); |
---|
[2065609] | 986 | } |
---|
| 987 | |
---|
[9c1600c] | 988 | //-------------------------------------------------------------------------- |
---|
| 989 | // UntypedExpr |
---|
[13932f14] | 990 | template< typename pass_type > |
---|
[ab904dc] | 991 | void PassVisitor< pass_type >::visit( UntypedExpr * node ) { |
---|
[9c1600c] | 992 | VISIT_START( node ); |
---|
| 993 | |
---|
[2a7b3ca] | 994 | // maybeAccept( node->get_env(), *this ); |
---|
[e0886db] | 995 | indexerScopedAccept( node->result, *this ); |
---|
[2a7b3ca] | 996 | |
---|
[e0886db] | 997 | for ( auto expr : node->args ) { |
---|
[9c1600c] | 998 | visitExpression( expr ); |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | VISIT_END( node ); |
---|
[13932f14] | 1002 | } |
---|
| 1003 | |
---|
[296b2be] | 1004 | template< typename pass_type > |
---|
| 1005 | Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) { |
---|
| 1006 | MUTATE_START( node ); |
---|
| 1007 | |
---|
[e0886db] | 1008 | indexerScopedMutate( node->env , *this ); |
---|
| 1009 | indexerScopedMutate( node->result, *this ); |
---|
[2a7b3ca] | 1010 | |
---|
[e0886db] | 1011 | for ( auto& expr : node->args ) { |
---|
[296b2be] | 1012 | expr = mutateExpression( expr ); |
---|
| 1013 | } |
---|
| 1014 | |
---|
| 1015 | MUTATE_END( Expression, node ); |
---|
| 1016 | } |
---|
| 1017 | |
---|
[e0886db] | 1018 | //-------------------------------------------------------------------------- |
---|
| 1019 | // NameExpr |
---|
[13932f14] | 1020 | template< typename pass_type > |
---|
[ab904dc] | 1021 | void PassVisitor< pass_type >::visit( NameExpr * node ) { |
---|
[e0886db] | 1022 | VISIT_START( node ); |
---|
| 1023 | |
---|
| 1024 | indexerScopedAccept( node->result, *this ); |
---|
| 1025 | |
---|
| 1026 | VISIT_END( node ); |
---|
[13932f14] | 1027 | } |
---|
| 1028 | |
---|
| 1029 | template< typename pass_type > |
---|
[e0886db] | 1030 | Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) { |
---|
| 1031 | MUTATE_START( node ); |
---|
| 1032 | |
---|
| 1033 | indexerScopedMutate( node->env , *this ); |
---|
| 1034 | indexerScopedMutate( node->result, *this ); |
---|
| 1035 | |
---|
| 1036 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1037 | } |
---|
| 1038 | |
---|
[e0886db] | 1039 | //-------------------------------------------------------------------------- |
---|
| 1040 | // CastExpr |
---|
[a5f0529] | 1041 | template< typename pass_type > |
---|
[e0886db] | 1042 | void PassVisitor< pass_type >::visit( CastExpr * node ) { |
---|
| 1043 | VISIT_START( node ); |
---|
| 1044 | |
---|
| 1045 | indexerScopedAccept( node->result, *this ); |
---|
| 1046 | maybeAccept ( node->arg , *this ); |
---|
| 1047 | |
---|
| 1048 | VISIT_END( node ); |
---|
[a5f0529] | 1049 | } |
---|
| 1050 | |
---|
[13932f14] | 1051 | template< typename pass_type > |
---|
[e0886db] | 1052 | Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) { |
---|
| 1053 | MUTATE_START( node ); |
---|
| 1054 | |
---|
| 1055 | indexerScopedMutate( node->env , *this ); |
---|
| 1056 | indexerScopedMutate( node->result, *this ); |
---|
| 1057 | maybeMutateRef ( node->arg , *this ); |
---|
| 1058 | |
---|
| 1059 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1060 | } |
---|
| 1061 | |
---|
[e0886db] | 1062 | //-------------------------------------------------------------------------- |
---|
| 1063 | // VirtualCastExpr |
---|
[13932f14] | 1064 | template< typename pass_type > |
---|
[e0886db] | 1065 | void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) { |
---|
| 1066 | VISIT_START( node ); |
---|
| 1067 | |
---|
| 1068 | indexerScopedAccept( node->result, *this ); |
---|
| 1069 | maybeAccept( node->arg, *this ); |
---|
| 1070 | |
---|
| 1071 | VISIT_END( node ); |
---|
[13932f14] | 1072 | } |
---|
| 1073 | |
---|
| 1074 | template< typename pass_type > |
---|
[e0886db] | 1075 | Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) { |
---|
| 1076 | MUTATE_START( node ); |
---|
| 1077 | |
---|
| 1078 | indexerScopedMutate( node->env , *this ); |
---|
| 1079 | indexerScopedMutate( node->result, *this ); |
---|
| 1080 | maybeMutateRef ( node->arg , *this ); |
---|
| 1081 | |
---|
| 1082 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1083 | } |
---|
| 1084 | |
---|
[e0886db] | 1085 | //-------------------------------------------------------------------------- |
---|
| 1086 | // AddressExpr |
---|
[13932f14] | 1087 | template< typename pass_type > |
---|
[e0886db] | 1088 | void PassVisitor< pass_type >::visit( AddressExpr * node ) { |
---|
| 1089 | VISIT_START( node ); |
---|
| 1090 | |
---|
| 1091 | indexerScopedAccept( node->result, *this ); |
---|
| 1092 | maybeAccept ( node->arg , *this ); |
---|
| 1093 | |
---|
| 1094 | VISIT_END( node ); |
---|
[13932f14] | 1095 | } |
---|
| 1096 | |
---|
| 1097 | template< typename pass_type > |
---|
[e0886db] | 1098 | Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) { |
---|
| 1099 | MUTATE_START( node ); |
---|
| 1100 | |
---|
| 1101 | indexerScopedMutate( node->env , *this ); |
---|
| 1102 | indexerScopedMutate( node->result, *this ); |
---|
| 1103 | maybeMutateRef ( node->arg , *this ); |
---|
| 1104 | |
---|
| 1105 | MUTATE_END( Expression, node ); |
---|
| 1106 | } |
---|
| 1107 | |
---|
| 1108 | //-------------------------------------------------------------------------- |
---|
| 1109 | // LabelAddressExpr |
---|
| 1110 | template< typename pass_type > |
---|
| 1111 | void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) { |
---|
| 1112 | VISIT_START( node ); |
---|
| 1113 | |
---|
| 1114 | indexerScopedAccept( node->result, *this ); |
---|
| 1115 | |
---|
| 1116 | VISIT_END( node ); |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | template< typename pass_type > |
---|
| 1120 | Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) { |
---|
| 1121 | MUTATE_START( node ); |
---|
| 1122 | |
---|
| 1123 | indexerScopedMutate( node->env , *this ); |
---|
| 1124 | indexerScopedMutate( node->result, *this ); |
---|
| 1125 | |
---|
| 1126 | MUTATE_END( Expression, node ); |
---|
| 1127 | } |
---|
| 1128 | |
---|
| 1129 | //-------------------------------------------------------------------------- |
---|
| 1130 | // UntypedMemberExpr |
---|
| 1131 | template< typename pass_type > |
---|
| 1132 | void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { |
---|
| 1133 | VISIT_START( node ); |
---|
| 1134 | |
---|
| 1135 | indexerScopedAccept( node->result , *this ); |
---|
| 1136 | maybeAccept ( node->aggregate, *this ); |
---|
| 1137 | maybeAccept ( node->member , *this ); |
---|
| 1138 | |
---|
| 1139 | VISIT_END( node ); |
---|
[13932f14] | 1140 | } |
---|
| 1141 | |
---|
[e0886db] | 1142 | template< typename pass_type > |
---|
| 1143 | Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) { |
---|
| 1144 | MUTATE_START( node ); |
---|
| 1145 | |
---|
| 1146 | indexerScopedMutate( node->env , *this ); |
---|
| 1147 | indexerScopedMutate( node->result , *this ); |
---|
| 1148 | maybeMutateRef ( node->aggregate, *this ); |
---|
| 1149 | maybeMutateRef ( node->member , *this ); |
---|
| 1150 | |
---|
| 1151 | MUTATE_END( Expression, node ); |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | //-------------------------------------------------------------------------- |
---|
| 1155 | // MemberExpr |
---|
| 1156 | template< typename pass_type > |
---|
| 1157 | void PassVisitor< pass_type >::visit( MemberExpr * node ) { |
---|
| 1158 | VISIT_START( node ); |
---|
| 1159 | |
---|
| 1160 | indexerScopedAccept( node->result , *this ); |
---|
| 1161 | maybeAccept ( node->aggregate, *this ); |
---|
| 1162 | |
---|
| 1163 | VISIT_END( node ); |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | template< typename pass_type > |
---|
| 1167 | Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) { |
---|
| 1168 | MUTATE_START( node ); |
---|
| 1169 | |
---|
| 1170 | indexerScopedMutate( node->env , *this ); |
---|
| 1171 | indexerScopedMutate( node->result , *this ); |
---|
| 1172 | maybeMutateRef ( node->aggregate, *this ); |
---|
| 1173 | |
---|
| 1174 | MUTATE_END( Expression, node ); |
---|
| 1175 | } |
---|
| 1176 | |
---|
| 1177 | //-------------------------------------------------------------------------- |
---|
| 1178 | // VariableExpr |
---|
| 1179 | template< typename pass_type > |
---|
| 1180 | void PassVisitor< pass_type >::visit( VariableExpr * node ) { |
---|
| 1181 | VISIT_START( node ); |
---|
| 1182 | |
---|
| 1183 | indexerScopedAccept( node->result, *this ); |
---|
| 1184 | |
---|
| 1185 | VISIT_END( node ); |
---|
| 1186 | } |
---|
| 1187 | |
---|
| 1188 | template< typename pass_type > |
---|
| 1189 | Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) { |
---|
| 1190 | MUTATE_START( node ); |
---|
| 1191 | |
---|
| 1192 | indexerScopedMutate( node->env , *this ); |
---|
| 1193 | indexerScopedMutate( node->result, *this ); |
---|
| 1194 | |
---|
| 1195 | MUTATE_END( Expression, node ); |
---|
| 1196 | } |
---|
| 1197 | |
---|
| 1198 | //-------------------------------------------------------------------------- |
---|
| 1199 | // ConstantExpr |
---|
[13932f14] | 1200 | template< typename pass_type > |
---|
[ab904dc] | 1201 | void PassVisitor< pass_type >::visit( ConstantExpr * node ) { |
---|
[e0886db] | 1202 | VISIT_START( node ); |
---|
| 1203 | |
---|
| 1204 | indexerScopedAccept( node->result , *this ); |
---|
| 1205 | maybeAccept ( &node->constant, *this ); |
---|
| 1206 | |
---|
| 1207 | VISIT_END( node ); |
---|
[13932f14] | 1208 | } |
---|
| 1209 | |
---|
[e0886db] | 1210 | template< typename pass_type > |
---|
| 1211 | Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) { |
---|
| 1212 | MUTATE_START( node ); |
---|
| 1213 | |
---|
| 1214 | indexerScopedMutate( node->env , *this ); |
---|
| 1215 | indexerScopedMutate( node->result, *this ); |
---|
| 1216 | node->constant = *maybeMutate( &node->constant, *this ); |
---|
| 1217 | |
---|
| 1218 | MUTATE_END( Expression, node ); |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | //-------------------------------------------------------------------------- |
---|
| 1222 | // SizeofExpr |
---|
[13932f14] | 1223 | template< typename pass_type > |
---|
[ab904dc] | 1224 | void PassVisitor< pass_type >::visit( SizeofExpr * node ) { |
---|
[e0886db] | 1225 | VISIT_START( node ); |
---|
| 1226 | |
---|
| 1227 | indexerScopedAccept( node->result, *this ); |
---|
| 1228 | if ( node->get_isType() ) { |
---|
| 1229 | maybeAccept( node->type, *this ); |
---|
| 1230 | } else { |
---|
| 1231 | maybeAccept( node->expr, *this ); |
---|
| 1232 | } |
---|
| 1233 | |
---|
| 1234 | VISIT_END( node ); |
---|
[13932f14] | 1235 | } |
---|
| 1236 | |
---|
[e0886db] | 1237 | template< typename pass_type > |
---|
| 1238 | Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) { |
---|
| 1239 | MUTATE_START( node ); |
---|
| 1240 | |
---|
| 1241 | indexerScopedMutate( node->env , *this ); |
---|
| 1242 | indexerScopedMutate( node->result, *this ); |
---|
| 1243 | if ( node->get_isType() ) { |
---|
| 1244 | maybeMutateRef( node->type, *this ); |
---|
| 1245 | } else { |
---|
| 1246 | maybeMutateRef( node->expr, *this ); |
---|
| 1247 | } |
---|
| 1248 | |
---|
| 1249 | MUTATE_END( Expression, node ); |
---|
| 1250 | } |
---|
| 1251 | |
---|
| 1252 | //-------------------------------------------------------------------------- |
---|
| 1253 | // AlignofExpr |
---|
[13932f14] | 1254 | template< typename pass_type > |
---|
[ab904dc] | 1255 | void PassVisitor< pass_type >::visit( AlignofExpr * node ) { |
---|
[e0886db] | 1256 | VISIT_START( node ); |
---|
| 1257 | |
---|
| 1258 | indexerScopedAccept( node->result, *this ); |
---|
| 1259 | if ( node->get_isType() ) { |
---|
| 1260 | maybeAccept( node->type, *this ); |
---|
| 1261 | } else { |
---|
| 1262 | maybeAccept( node->expr, *this ); |
---|
| 1263 | } |
---|
| 1264 | |
---|
| 1265 | VISIT_END( node ); |
---|
[13932f14] | 1266 | } |
---|
| 1267 | |
---|
[e0886db] | 1268 | template< typename pass_type > |
---|
| 1269 | Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) { |
---|
| 1270 | MUTATE_START( node ); |
---|
| 1271 | |
---|
| 1272 | indexerScopedMutate( node->env , *this ); |
---|
| 1273 | indexerScopedMutate( node->result, *this ); |
---|
| 1274 | if ( node->get_isType() ) { |
---|
| 1275 | maybeMutateRef( node->type, *this ); |
---|
| 1276 | } else { |
---|
| 1277 | maybeMutateRef( node->expr, *this ); |
---|
| 1278 | } |
---|
| 1279 | |
---|
| 1280 | MUTATE_END( Expression, node ); |
---|
| 1281 | } |
---|
| 1282 | |
---|
| 1283 | //-------------------------------------------------------------------------- |
---|
| 1284 | // UntypedOffsetofExpr |
---|
[13932f14] | 1285 | template< typename pass_type > |
---|
[ab904dc] | 1286 | void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) { |
---|
[e0886db] | 1287 | VISIT_START( node ); |
---|
| 1288 | |
---|
| 1289 | indexerScopedAccept( node->result, *this ); |
---|
| 1290 | maybeAccept ( node->type , *this ); |
---|
| 1291 | |
---|
| 1292 | VISIT_END( node ); |
---|
[13932f14] | 1293 | } |
---|
| 1294 | |
---|
[e0886db] | 1295 | template< typename pass_type > |
---|
| 1296 | Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) { |
---|
| 1297 | MUTATE_START( node ); |
---|
| 1298 | |
---|
| 1299 | indexerScopedMutate( node->env , *this ); |
---|
| 1300 | indexerScopedMutate( node->result, *this ); |
---|
| 1301 | maybeMutateRef ( node->type , *this ); |
---|
| 1302 | |
---|
| 1303 | MUTATE_END( Expression, node ); |
---|
| 1304 | } |
---|
| 1305 | |
---|
| 1306 | //-------------------------------------------------------------------------- |
---|
| 1307 | // OffsetofExpr |
---|
[13932f14] | 1308 | template< typename pass_type > |
---|
[ab904dc] | 1309 | void PassVisitor< pass_type >::visit( OffsetofExpr * node ) { |
---|
[e0886db] | 1310 | VISIT_START( node ); |
---|
| 1311 | |
---|
| 1312 | indexerScopedAccept( node->result, *this ); |
---|
| 1313 | maybeAccept ( node->type , *this ); |
---|
| 1314 | maybeAccept ( node->member, *this ); |
---|
| 1315 | |
---|
| 1316 | VISIT_END( node ); |
---|
[13932f14] | 1317 | } |
---|
| 1318 | |
---|
[e0886db] | 1319 | template< typename pass_type > |
---|
| 1320 | Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) { |
---|
| 1321 | MUTATE_START( node ); |
---|
| 1322 | |
---|
| 1323 | indexerScopedMutate( node->env , *this ); |
---|
| 1324 | indexerScopedMutate( node->result, *this ); |
---|
| 1325 | maybeMutateRef ( node->type , *this ); |
---|
| 1326 | maybeMutateRef ( node->member, *this ); |
---|
| 1327 | |
---|
| 1328 | MUTATE_END( Expression, node ); |
---|
| 1329 | } |
---|
| 1330 | |
---|
| 1331 | //-------------------------------------------------------------------------- |
---|
| 1332 | // OffsetPackExpr |
---|
[13932f14] | 1333 | template< typename pass_type > |
---|
[ab904dc] | 1334 | void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) { |
---|
[e0886db] | 1335 | VISIT_START( node ); |
---|
| 1336 | |
---|
| 1337 | indexerScopedAccept( node->result, *this ); |
---|
| 1338 | maybeAccept ( node->type , *this ); |
---|
| 1339 | |
---|
| 1340 | VISIT_END( node ); |
---|
[13932f14] | 1341 | } |
---|
| 1342 | |
---|
[e0886db] | 1343 | template< typename pass_type > |
---|
| 1344 | Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) { |
---|
| 1345 | MUTATE_START( node ); |
---|
| 1346 | |
---|
| 1347 | indexerScopedMutate( node->env , *this ); |
---|
| 1348 | indexerScopedMutate( node->result, *this ); |
---|
| 1349 | maybeMutateRef ( node->type , *this ); |
---|
| 1350 | |
---|
| 1351 | MUTATE_END( Expression, node ); |
---|
| 1352 | } |
---|
| 1353 | |
---|
| 1354 | //-------------------------------------------------------------------------- |
---|
| 1355 | // AttrExpr |
---|
[13932f14] | 1356 | template< typename pass_type > |
---|
[ab904dc] | 1357 | void PassVisitor< pass_type >::visit( AttrExpr * node ) { |
---|
[e0886db] | 1358 | VISIT_START( node ); |
---|
| 1359 | |
---|
| 1360 | indexerScopedAccept( node->result, *this ); |
---|
| 1361 | if ( node->get_isType() ) { |
---|
| 1362 | maybeAccept( node->type, *this ); |
---|
| 1363 | } else { |
---|
| 1364 | maybeAccept( node->expr, *this ); |
---|
| 1365 | } |
---|
| 1366 | |
---|
| 1367 | VISIT_END( node ); |
---|
| 1368 | } |
---|
| 1369 | |
---|
| 1370 | template< typename pass_type > |
---|
| 1371 | Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) { |
---|
| 1372 | MUTATE_START( node ); |
---|
| 1373 | |
---|
| 1374 | indexerScopedMutate( node->env , *this ); |
---|
| 1375 | indexerScopedMutate( node->result, *this ); |
---|
| 1376 | if ( node->get_isType() ) { |
---|
| 1377 | maybeMutateRef( node->type, *this ); |
---|
| 1378 | } else { |
---|
| 1379 | maybeMutateRef( node->expr, *this ); |
---|
| 1380 | } |
---|
| 1381 | |
---|
| 1382 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1383 | } |
---|
| 1384 | |
---|
[e0886db] | 1385 | //-------------------------------------------------------------------------- |
---|
| 1386 | // LogicalExpr |
---|
[13932f14] | 1387 | template< typename pass_type > |
---|
[ab904dc] | 1388 | void PassVisitor< pass_type >::visit( LogicalExpr * node ) { |
---|
[e0886db] | 1389 | VISIT_START( node ); |
---|
| 1390 | |
---|
| 1391 | indexerScopedAccept( node->result, *this ); |
---|
| 1392 | maybeAccept ( node->arg1 , *this ); |
---|
| 1393 | maybeAccept ( node->arg2 , *this ); |
---|
| 1394 | |
---|
| 1395 | VISIT_END( node ); |
---|
| 1396 | } |
---|
| 1397 | |
---|
| 1398 | template< typename pass_type > |
---|
| 1399 | Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) { |
---|
| 1400 | MUTATE_START( node ); |
---|
| 1401 | |
---|
| 1402 | indexerScopedMutate( node->env , *this ); |
---|
| 1403 | indexerScopedMutate( node->result, *this ); |
---|
| 1404 | maybeMutateRef ( node->arg1 , *this ); |
---|
| 1405 | maybeMutateRef ( node->arg2 , *this ); |
---|
| 1406 | |
---|
| 1407 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1408 | } |
---|
| 1409 | |
---|
[e0886db] | 1410 | //-------------------------------------------------------------------------- |
---|
| 1411 | // ConditionalExpr |
---|
[13932f14] | 1412 | template< typename pass_type > |
---|
[ab904dc] | 1413 | void PassVisitor< pass_type >::visit( ConditionalExpr * node ) { |
---|
[e0886db] | 1414 | VISIT_START( node ); |
---|
| 1415 | |
---|
| 1416 | indexerScopedAccept( node->result, *this ); |
---|
| 1417 | maybeAccept ( node->arg1 , *this ); |
---|
| 1418 | maybeAccept ( node->arg2 , *this ); |
---|
| 1419 | maybeAccept ( node->arg3 , *this ); |
---|
| 1420 | |
---|
| 1421 | VISIT_END( node ); |
---|
[13932f14] | 1422 | } |
---|
| 1423 | |
---|
[e0886db] | 1424 | template< typename pass_type > |
---|
| 1425 | Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) { |
---|
| 1426 | MUTATE_START( node ); |
---|
| 1427 | |
---|
| 1428 | indexerScopedMutate( node->env , *this ); |
---|
| 1429 | indexerScopedMutate( node->result, *this ); |
---|
| 1430 | maybeMutateRef ( node->arg1 , *this ); |
---|
| 1431 | maybeMutateRef ( node->arg2 , *this ); |
---|
| 1432 | maybeMutateRef ( node->arg3 , *this ); |
---|
| 1433 | |
---|
| 1434 | MUTATE_END( Expression, node ); |
---|
| 1435 | } |
---|
| 1436 | |
---|
| 1437 | //-------------------------------------------------------------------------- |
---|
| 1438 | // CommaExpr |
---|
[13932f14] | 1439 | template< typename pass_type > |
---|
[ab904dc] | 1440 | void PassVisitor< pass_type >::visit( CommaExpr * node ) { |
---|
[e0886db] | 1441 | VISIT_START( node ); |
---|
| 1442 | |
---|
| 1443 | indexerScopedAccept( node->result, *this ); |
---|
| 1444 | maybeAccept ( node->arg1 , *this ); |
---|
| 1445 | maybeAccept ( node->arg2 , *this ); |
---|
| 1446 | |
---|
| 1447 | VISIT_END( node ); |
---|
| 1448 | } |
---|
| 1449 | |
---|
| 1450 | template< typename pass_type > |
---|
| 1451 | Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) { |
---|
| 1452 | MUTATE_START( node ); |
---|
| 1453 | |
---|
| 1454 | indexerScopedMutate( node->env , *this ); |
---|
| 1455 | indexerScopedMutate( node->result, *this ); |
---|
| 1456 | maybeMutateRef ( node->arg1 , *this ); |
---|
| 1457 | maybeMutateRef ( node->arg2 , *this ); |
---|
| 1458 | |
---|
| 1459 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1460 | } |
---|
| 1461 | |
---|
[e0886db] | 1462 | //-------------------------------------------------------------------------- |
---|
| 1463 | // TypeExpr |
---|
[13932f14] | 1464 | template< typename pass_type > |
---|
[ab904dc] | 1465 | void PassVisitor< pass_type >::visit( TypeExpr * node ) { |
---|
[e0886db] | 1466 | VISIT_START( node ); |
---|
| 1467 | |
---|
| 1468 | indexerScopedAccept( node->result, *this ); |
---|
| 1469 | maybeAccept ( node->type, *this ); |
---|
| 1470 | |
---|
| 1471 | VISIT_END( node ); |
---|
[13932f14] | 1472 | } |
---|
| 1473 | |
---|
[e0886db] | 1474 | template< typename pass_type > |
---|
| 1475 | Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) { |
---|
| 1476 | MUTATE_START( node ); |
---|
| 1477 | |
---|
| 1478 | indexerScopedMutate( node->env , *this ); |
---|
| 1479 | indexerScopedMutate( node->result, *this ); |
---|
| 1480 | maybeMutateRef ( node->type , *this ); |
---|
| 1481 | |
---|
| 1482 | MUTATE_END( Expression, node ); |
---|
| 1483 | } |
---|
| 1484 | |
---|
| 1485 | //-------------------------------------------------------------------------- |
---|
| 1486 | // AsmExpr |
---|
[13932f14] | 1487 | template< typename pass_type > |
---|
[ab904dc] | 1488 | void PassVisitor< pass_type >::visit( AsmExpr * node ) { |
---|
[e0886db] | 1489 | VISIT_START( node ); |
---|
| 1490 | |
---|
| 1491 | indexerScopedAccept( node->result , *this ); |
---|
| 1492 | maybeAccept ( node->inout , *this ); |
---|
| 1493 | maybeAccept ( node->constraint, *this ); |
---|
| 1494 | maybeAccept ( node->operand , *this ); |
---|
| 1495 | |
---|
| 1496 | VISIT_END( node ); |
---|
[13932f14] | 1497 | } |
---|
| 1498 | |
---|
[e0886db] | 1499 | template< typename pass_type > |
---|
| 1500 | Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) { |
---|
| 1501 | MUTATE_START( node ); |
---|
| 1502 | |
---|
| 1503 | indexerScopedMutate( node->env , *this ); |
---|
| 1504 | indexerScopedMutate( node->result , *this ); |
---|
| 1505 | maybeMutateRef ( node->inout , *this ); |
---|
| 1506 | maybeMutateRef ( node->constraint, *this ); |
---|
| 1507 | maybeMutateRef ( node->operand , *this ); |
---|
| 1508 | |
---|
| 1509 | MUTATE_END( Expression, node ); |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | //-------------------------------------------------------------------------- |
---|
| 1513 | // ImplicitCopyCtorExpr |
---|
[13932f14] | 1514 | template< typename pass_type > |
---|
[ab904dc] | 1515 | void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) { |
---|
[e0886db] | 1516 | VISIT_START( node ); |
---|
| 1517 | |
---|
| 1518 | indexerScopedAccept( node->result , *this ); |
---|
| 1519 | maybeAccept ( node->callExpr , *this ); |
---|
[9dcb653] | 1520 | maybeAccept ( node->tempDecls , *this ); |
---|
| 1521 | maybeAccept ( node->returnDecls, *this ); |
---|
| 1522 | maybeAccept ( node->dtors , *this ); |
---|
[e0886db] | 1523 | |
---|
| 1524 | VISIT_END( node ); |
---|
| 1525 | } |
---|
| 1526 | |
---|
| 1527 | template< typename pass_type > |
---|
| 1528 | Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) { |
---|
| 1529 | MUTATE_START( node ); |
---|
| 1530 | |
---|
| 1531 | indexerScopedMutate( node->env , *this ); |
---|
| 1532 | indexerScopedMutate( node->result , *this ); |
---|
| 1533 | maybeMutateRef ( node->callExpr , *this ); |
---|
[9dcb653] | 1534 | maybeMutateRef ( node->tempDecls , *this ); |
---|
| 1535 | maybeMutateRef ( node->returnDecls, *this ); |
---|
| 1536 | maybeMutateRef ( node->dtors , *this ); |
---|
[e0886db] | 1537 | |
---|
| 1538 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1539 | } |
---|
| 1540 | |
---|
[e0886db] | 1541 | //-------------------------------------------------------------------------- |
---|
| 1542 | // ConstructorExpr |
---|
[13932f14] | 1543 | template< typename pass_type > |
---|
[ab904dc] | 1544 | void PassVisitor< pass_type >::visit( ConstructorExpr * node ) { |
---|
[e0886db] | 1545 | VISIT_START( node ); |
---|
| 1546 | |
---|
| 1547 | indexerScopedAccept( node->result , *this ); |
---|
| 1548 | maybeAccept ( node->callExpr, *this ); |
---|
| 1549 | |
---|
| 1550 | VISIT_END( node ); |
---|
| 1551 | } |
---|
| 1552 | |
---|
| 1553 | template< typename pass_type > |
---|
| 1554 | Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) { |
---|
| 1555 | MUTATE_START( node ); |
---|
| 1556 | |
---|
| 1557 | indexerScopedMutate( node->env , *this ); |
---|
| 1558 | indexerScopedMutate( node->result , *this ); |
---|
| 1559 | maybeMutateRef ( node->callExpr, *this ); |
---|
| 1560 | |
---|
| 1561 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1562 | } |
---|
| 1563 | |
---|
[e0886db] | 1564 | //-------------------------------------------------------------------------- |
---|
| 1565 | // CompoundLiteralExpr |
---|
[13932f14] | 1566 | template< typename pass_type > |
---|
[ab904dc] | 1567 | void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) { |
---|
[e0886db] | 1568 | VISIT_START( node ); |
---|
| 1569 | |
---|
| 1570 | indexerScopedAccept( node->result , *this ); |
---|
| 1571 | maybeAccept ( node->initializer, *this ); |
---|
| 1572 | |
---|
| 1573 | VISIT_END( node ); |
---|
[13932f14] | 1574 | } |
---|
| 1575 | |
---|
[e0886db] | 1576 | template< typename pass_type > |
---|
| 1577 | Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) { |
---|
| 1578 | MUTATE_START( node ); |
---|
| 1579 | |
---|
| 1580 | indexerScopedMutate( node->env , *this ); |
---|
| 1581 | indexerScopedMutate( node->result , *this ); |
---|
| 1582 | maybeMutateRef ( node->initializer, *this ); |
---|
| 1583 | |
---|
| 1584 | MUTATE_END( Expression, node ); |
---|
| 1585 | } |
---|
| 1586 | |
---|
| 1587 | //-------------------------------------------------------------------------- |
---|
| 1588 | // RangeExpr |
---|
[13932f14] | 1589 | template< typename pass_type > |
---|
[ab904dc] | 1590 | void PassVisitor< pass_type >::visit( RangeExpr * node ) { |
---|
[e0886db] | 1591 | VISIT_START( node ); |
---|
| 1592 | |
---|
| 1593 | indexerScopedAccept( node->result, *this ); |
---|
| 1594 | maybeAccept ( node->low , *this ); |
---|
| 1595 | maybeAccept ( node->high , *this ); |
---|
| 1596 | |
---|
| 1597 | VISIT_END( node ); |
---|
[13932f14] | 1598 | } |
---|
| 1599 | |
---|
[e0886db] | 1600 | template< typename pass_type > |
---|
| 1601 | Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) { |
---|
| 1602 | MUTATE_START( node ); |
---|
| 1603 | |
---|
| 1604 | indexerScopedMutate( node->env , *this ); |
---|
| 1605 | indexerScopedMutate( node->result, *this ); |
---|
| 1606 | maybeMutateRef ( node->low , *this ); |
---|
| 1607 | maybeMutateRef ( node->high , *this ); |
---|
| 1608 | |
---|
| 1609 | MUTATE_END( Expression, node ); |
---|
| 1610 | } |
---|
| 1611 | |
---|
| 1612 | //-------------------------------------------------------------------------- |
---|
| 1613 | // UntypedTupleExpr |
---|
[13932f14] | 1614 | template< typename pass_type > |
---|
[ab904dc] | 1615 | void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) { |
---|
[e0886db] | 1616 | VISIT_START( node ); |
---|
| 1617 | |
---|
| 1618 | indexerScopedAccept( node->result, *this ); |
---|
[9dcb653] | 1619 | maybeAccept ( node->exprs , *this ); |
---|
[e0886db] | 1620 | |
---|
| 1621 | VISIT_END( node ); |
---|
| 1622 | } |
---|
| 1623 | |
---|
| 1624 | template< typename pass_type > |
---|
| 1625 | Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) { |
---|
| 1626 | MUTATE_START( node ); |
---|
| 1627 | |
---|
| 1628 | indexerScopedMutate( node->env , *this ); |
---|
| 1629 | indexerScopedMutate( node->result, *this ); |
---|
[9dcb653] | 1630 | maybeMutateRef ( node->exprs , *this ); |
---|
[e0886db] | 1631 | |
---|
| 1632 | MUTATE_END( Expression, node ); |
---|
| 1633 | } |
---|
| 1634 | |
---|
| 1635 | //-------------------------------------------------------------------------- |
---|
| 1636 | // TupleExpr |
---|
| 1637 | template< typename pass_type > |
---|
| 1638 | void PassVisitor< pass_type >::visit( TupleExpr * node ) { |
---|
| 1639 | VISIT_START( node ); |
---|
| 1640 | |
---|
| 1641 | indexerScopedAccept( node->result, *this ); |
---|
| 1642 | maybeAccept ( node->exprs , *this ); |
---|
| 1643 | |
---|
| 1644 | VISIT_END( node ); |
---|
| 1645 | } |
---|
| 1646 | |
---|
| 1647 | template< typename pass_type > |
---|
| 1648 | Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) { |
---|
| 1649 | MUTATE_START( node ); |
---|
| 1650 | |
---|
| 1651 | indexerScopedMutate( node->env , *this ); |
---|
| 1652 | indexerScopedMutate( node->result, *this ); |
---|
[9dcb653] | 1653 | maybeMutateRef ( node->exprs , *this ); |
---|
[e0886db] | 1654 | |
---|
| 1655 | MUTATE_END( Expression, node ); |
---|
| 1656 | } |
---|
| 1657 | |
---|
| 1658 | //-------------------------------------------------------------------------- |
---|
| 1659 | // TupleIndexExpr |
---|
| 1660 | template< typename pass_type > |
---|
| 1661 | void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) { |
---|
| 1662 | VISIT_START( node ); |
---|
| 1663 | |
---|
| 1664 | indexerScopedAccept( node->result, *this ); |
---|
| 1665 | maybeAccept ( node->tuple , *this ); |
---|
| 1666 | |
---|
| 1667 | VISIT_END( node ); |
---|
| 1668 | } |
---|
| 1669 | |
---|
| 1670 | template< typename pass_type > |
---|
| 1671 | Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) { |
---|
| 1672 | MUTATE_START( node ); |
---|
| 1673 | |
---|
| 1674 | indexerScopedMutate( node->env , *this ); |
---|
| 1675 | indexerScopedMutate( node->result, *this ); |
---|
| 1676 | maybeMutateRef ( node->tuple , *this ); |
---|
| 1677 | |
---|
| 1678 | MUTATE_END( Expression, node ); |
---|
| 1679 | } |
---|
| 1680 | |
---|
| 1681 | //-------------------------------------------------------------------------- |
---|
| 1682 | // TupleAssignExpr |
---|
| 1683 | template< typename pass_type > |
---|
| 1684 | void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) { |
---|
| 1685 | VISIT_START( node ); |
---|
| 1686 | |
---|
| 1687 | indexerScopedAccept( node->result , *this ); |
---|
| 1688 | maybeAccept ( node->stmtExpr, *this ); |
---|
| 1689 | |
---|
| 1690 | VISIT_END( node ); |
---|
[13932f14] | 1691 | } |
---|
| 1692 | |
---|
| 1693 | template< typename pass_type > |
---|
[e0886db] | 1694 | Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) { |
---|
| 1695 | MUTATE_START( node ); |
---|
[13932f14] | 1696 | |
---|
[e0886db] | 1697 | indexerScopedMutate( node->env , *this ); |
---|
| 1698 | indexerScopedMutate( node->result , *this ); |
---|
| 1699 | maybeMutateRef ( node->stmtExpr, *this ); |
---|
[13932f14] | 1700 | |
---|
[e0886db] | 1701 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1702 | } |
---|
| 1703 | |
---|
[9c1600c] | 1704 | //-------------------------------------------------------------------------- |
---|
[e0886db] | 1705 | // StmtExpr |
---|
[13932f14] | 1706 | template< typename pass_type > |
---|
[ab904dc] | 1707 | void PassVisitor< pass_type >::visit( StmtExpr * node ) { |
---|
[9c1600c] | 1708 | VISIT_START( node ); |
---|
| 1709 | |
---|
| 1710 | // don't want statements from outer CompoundStmts to be added to this StmtExpr |
---|
| 1711 | ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); |
---|
| 1712 | ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); |
---|
| 1713 | ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); |
---|
| 1714 | |
---|
[e0886db] | 1715 | indexerScopedAccept( node->result , *this ); |
---|
| 1716 | maybeAccept ( node->statements , *this ); |
---|
[9dcb653] | 1717 | maybeAccept ( node->returnDecls, *this ); |
---|
| 1718 | maybeAccept ( node->dtors , *this ); |
---|
[9c1600c] | 1719 | |
---|
| 1720 | VISIT_END( node ); |
---|
[13932f14] | 1721 | } |
---|
| 1722 | |
---|
[296b2be] | 1723 | template< typename pass_type > |
---|
| 1724 | Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { |
---|
| 1725 | MUTATE_START( node ); |
---|
[4551a6e] | 1726 | |
---|
[296b2be] | 1727 | // don't want statements from outer CompoundStmts to be added to this StmtExpr |
---|
[134322e] | 1728 | ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); |
---|
| 1729 | ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); |
---|
| 1730 | ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); |
---|
[296b2be] | 1731 | |
---|
[e0886db] | 1732 | indexerScopedMutate( node->result , *this ); |
---|
| 1733 | maybeMutateRef ( node->statements , *this ); |
---|
[9dcb653] | 1734 | maybeMutateRef ( node->returnDecls, *this ); |
---|
| 1735 | maybeMutateRef ( node->dtors , *this ); |
---|
[296b2be] | 1736 | |
---|
| 1737 | MUTATE_END( Expression, node ); |
---|
| 1738 | } |
---|
| 1739 | |
---|
[e0886db] | 1740 | //-------------------------------------------------------------------------- |
---|
| 1741 | // UniqueExpr |
---|
[13932f14] | 1742 | template< typename pass_type > |
---|
[ab904dc] | 1743 | void PassVisitor< pass_type >::visit( UniqueExpr * node ) { |
---|
[e0886db] | 1744 | VISIT_START( node ); |
---|
| 1745 | |
---|
| 1746 | indexerScopedAccept( node->result, *this ); |
---|
| 1747 | maybeAccept ( node->expr , *this ); |
---|
| 1748 | |
---|
| 1749 | VISIT_END( node ); |
---|
| 1750 | } |
---|
| 1751 | |
---|
| 1752 | template< typename pass_type > |
---|
| 1753 | Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) { |
---|
| 1754 | MUTATE_START( node ); |
---|
| 1755 | |
---|
| 1756 | indexerScopedMutate( node->env , *this ); |
---|
| 1757 | indexerScopedMutate( node->result, *this ); |
---|
| 1758 | maybeMutateRef ( node->expr , *this ); |
---|
| 1759 | |
---|
| 1760 | MUTATE_END( Expression, node ); |
---|
[13932f14] | 1761 | } |
---|
| 1762 | |
---|
| 1763 | template< typename pass_type > |
---|
[ab904dc] | 1764 | void PassVisitor< pass_type >::visit( VoidType * node ) { |
---|
[4551a6e] | 1765 | VISIT_BODY( node ); |
---|
[13932f14] | 1766 | } |
---|
| 1767 | |
---|
| 1768 | template< typename pass_type > |
---|
[ab904dc] | 1769 | void PassVisitor< pass_type >::visit( BasicType * node ) { |
---|
[4551a6e] | 1770 | VISIT_BODY( node ); |
---|
[13932f14] | 1771 | } |
---|
| 1772 | |
---|
| 1773 | template< typename pass_type > |
---|
[ab904dc] | 1774 | void PassVisitor< pass_type >::visit( PointerType * node ) { |
---|
[4551a6e] | 1775 | VISIT_BODY( node ); |
---|
[13932f14] | 1776 | } |
---|
| 1777 | |
---|
| 1778 | template< typename pass_type > |
---|
[ab904dc] | 1779 | void PassVisitor< pass_type >::visit( ArrayType * node ) { |
---|
[4551a6e] | 1780 | VISIT_BODY( node ); |
---|
[13932f14] | 1781 | } |
---|
| 1782 | |
---|
[6b9b047] | 1783 | template< typename pass_type > |
---|
| 1784 | void PassVisitor< pass_type >::visit( ReferenceType * node ) { |
---|
| 1785 | VISIT_BODY( node ); |
---|
| 1786 | } |
---|
| 1787 | |
---|
[13932f14] | 1788 | template< typename pass_type > |
---|
[ab904dc] | 1789 | void PassVisitor< pass_type >::visit( FunctionType * node ) { |
---|
[4551a6e] | 1790 | VISIT_BODY( node ); |
---|
[13932f14] | 1791 | } |
---|
| 1792 | |
---|
[e0886db] | 1793 | //-------------------------------------------------------------------------- |
---|
| 1794 | // StructInstType |
---|
[13932f14] | 1795 | template< typename pass_type > |
---|
[ab904dc] | 1796 | void PassVisitor< pass_type >::visit( StructInstType * node ) { |
---|
[e0886db] | 1797 | VISIT_START( node ); |
---|
| 1798 | |
---|
| 1799 | indexerAddStruct( node->name ); |
---|
| 1800 | |
---|
| 1801 | { |
---|
| 1802 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 1803 | maybeAccept( node->forall , *this ); |
---|
| 1804 | maybeAccept( node->parameters, *this ); |
---|
| 1805 | } |
---|
| 1806 | |
---|
| 1807 | VISIT_END( node ); |
---|
| 1808 | } |
---|
| 1809 | |
---|
| 1810 | template< typename pass_type > |
---|
| 1811 | Type * PassVisitor< pass_type >::mutate( StructInstType * node ) { |
---|
| 1812 | MUTATE_START( node ); |
---|
| 1813 | |
---|
| 1814 | indexerAddStruct( node->name ); |
---|
| 1815 | |
---|
| 1816 | { |
---|
| 1817 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 1818 | maybeMutateRef( node->forall , *this ); |
---|
| 1819 | maybeMutateRef( node->parameters, *this ); |
---|
| 1820 | } |
---|
| 1821 | |
---|
| 1822 | MUTATE_END( Type, node ); |
---|
[13932f14] | 1823 | } |
---|
| 1824 | |
---|
[e0886db] | 1825 | //-------------------------------------------------------------------------- |
---|
| 1826 | // UnionInstType |
---|
[13932f14] | 1827 | template< typename pass_type > |
---|
[ab904dc] | 1828 | void PassVisitor< pass_type >::visit( UnionInstType * node ) { |
---|
[e0886db] | 1829 | VISIT_START( node ); |
---|
| 1830 | |
---|
| 1831 | indexerAddStruct( node->name ); |
---|
| 1832 | |
---|
| 1833 | { |
---|
| 1834 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 1835 | maybeAccept( node->forall , *this ); |
---|
| 1836 | maybeAccept( node->parameters, *this ); |
---|
| 1837 | } |
---|
| 1838 | |
---|
| 1839 | VISIT_END( node ); |
---|
| 1840 | } |
---|
| 1841 | |
---|
| 1842 | template< typename pass_type > |
---|
| 1843 | Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) { |
---|
| 1844 | MUTATE_START( node ); |
---|
| 1845 | |
---|
| 1846 | indexerAddStruct( node->name ); |
---|
| 1847 | |
---|
| 1848 | { |
---|
| 1849 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
| 1850 | maybeMutateRef( node->forall , *this ); |
---|
| 1851 | maybeMutateRef( node->parameters, *this ); |
---|
| 1852 | } |
---|
| 1853 | |
---|
| 1854 | MUTATE_END( Type, node ); |
---|
[13932f14] | 1855 | } |
---|
| 1856 | |
---|
[e0886db] | 1857 | //-------------------------------------------------------------------------- |
---|
| 1858 | // EnumInstType |
---|
[13932f14] | 1859 | template< typename pass_type > |
---|
[ab904dc] | 1860 | void PassVisitor< pass_type >::visit( EnumInstType * node ) { |
---|
[4551a6e] | 1861 | VISIT_BODY( node ); |
---|
[13932f14] | 1862 | } |
---|
| 1863 | |
---|
[e0886db] | 1864 | template< typename pass_type > |
---|
| 1865 | Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) { |
---|
| 1866 | MUTATE_BODY( Type, node ); |
---|
| 1867 | } |
---|
| 1868 | |
---|
| 1869 | //-------------------------------------------------------------------------- |
---|
| 1870 | // TraitInstType |
---|
[13932f14] | 1871 | template< typename pass_type > |
---|
[ab904dc] | 1872 | void PassVisitor< pass_type >::visit( TraitInstType * node ) { |
---|
[e0886db] | 1873 | VISIT_START( node ); |
---|
| 1874 | |
---|
| 1875 | maybeAccept( node->forall , *this ); |
---|
| 1876 | maybeAccept( node->parameters, *this ); |
---|
| 1877 | |
---|
| 1878 | VISIT_END( node ); |
---|
| 1879 | } |
---|
| 1880 | |
---|
| 1881 | template< typename pass_type > |
---|
| 1882 | Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) { |
---|
| 1883 | MUTATE_START( node ); |
---|
| 1884 | |
---|
| 1885 | maybeMutateRef( node->forall , *this ); |
---|
| 1886 | maybeMutateRef( node->parameters, *this ); |
---|
| 1887 | |
---|
| 1888 | MUTATE_END( Type, node ); |
---|
[13932f14] | 1889 | } |
---|
| 1890 | |
---|
[e0886db] | 1891 | //-------------------------------------------------------------------------- |
---|
| 1892 | // TypeInstType |
---|
[13932f14] | 1893 | template< typename pass_type > |
---|
[ab904dc] | 1894 | void PassVisitor< pass_type >::visit( TypeInstType * node ) { |
---|
[4551a6e] | 1895 | VISIT_BODY( node ); |
---|
[13932f14] | 1896 | } |
---|
| 1897 | |
---|
| 1898 | template< typename pass_type > |
---|
[ab904dc] | 1899 | void PassVisitor< pass_type >::visit( TupleType * node ) { |
---|
[4551a6e] | 1900 | VISIT_BODY( node ); |
---|
[13932f14] | 1901 | } |
---|
| 1902 | |
---|
| 1903 | template< typename pass_type > |
---|
[ab904dc] | 1904 | void PassVisitor< pass_type >::visit( TypeofType * node ) { |
---|
[4551a6e] | 1905 | VISIT_BODY( node ); |
---|
[13932f14] | 1906 | } |
---|
| 1907 | |
---|
| 1908 | template< typename pass_type > |
---|
[ab904dc] | 1909 | void PassVisitor< pass_type >::visit( AttrType * node ) { |
---|
[4551a6e] | 1910 | VISIT_BODY( node ); |
---|
[13932f14] | 1911 | } |
---|
| 1912 | |
---|
| 1913 | template< typename pass_type > |
---|
[ab904dc] | 1914 | void PassVisitor< pass_type >::visit( VarArgsType * node ) { |
---|
[4551a6e] | 1915 | VISIT_BODY( node ); |
---|
[13932f14] | 1916 | } |
---|
| 1917 | |
---|
| 1918 | template< typename pass_type > |
---|
[ab904dc] | 1919 | void PassVisitor< pass_type >::visit( ZeroType * node ) { |
---|
[4551a6e] | 1920 | VISIT_BODY( node ); |
---|
[13932f14] | 1921 | } |
---|
| 1922 | |
---|
| 1923 | template< typename pass_type > |
---|
[ab904dc] | 1924 | void PassVisitor< pass_type >::visit( OneType * node ) { |
---|
[4551a6e] | 1925 | VISIT_BODY( node ); |
---|
[13932f14] | 1926 | } |
---|
| 1927 | |
---|
[9c1600c] | 1928 | //-------------------------------------------------------------------------- |
---|
[e0886db] | 1929 | // SingleInit |
---|
[13932f14] | 1930 | template< typename pass_type > |
---|
[ab904dc] | 1931 | void PassVisitor< pass_type >::visit( SingleInit * node ) { |
---|
[9c1600c] | 1932 | VISIT_START( node ); |
---|
| 1933 | |
---|
| 1934 | visitExpression( node->get_value() ); |
---|
| 1935 | |
---|
| 1936 | VISIT_END( node ); |
---|
[13932f14] | 1937 | } |
---|
| 1938 | |
---|
[296b2be] | 1939 | template< typename pass_type > |
---|
| 1940 | Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) { |
---|
| 1941 | MUTATE_START( node ); |
---|
| 1942 | |
---|
| 1943 | node->set_value( mutateExpression( node->get_value() ) ); |
---|
| 1944 | |
---|
| 1945 | MUTATE_END( Initializer, node ); |
---|
| 1946 | } |
---|
| 1947 | |
---|
[13932f14] | 1948 | template< typename pass_type > |
---|
[ab904dc] | 1949 | void PassVisitor< pass_type >::visit( ListInit * node ) { |
---|
[4551a6e] | 1950 | VISIT_BODY( node ); |
---|
[13932f14] | 1951 | } |
---|
| 1952 | |
---|
| 1953 | template< typename pass_type > |
---|
[ab904dc] | 1954 | void PassVisitor< pass_type >::visit( ConstructorInit * node ) { |
---|
[4551a6e] | 1955 | VISIT_BODY( node ); |
---|
[13932f14] | 1956 | } |
---|
| 1957 | |
---|
| 1958 | template< typename pass_type > |
---|
[ab904dc] | 1959 | void PassVisitor< pass_type >::visit( Subrange * node ) { |
---|
[4551a6e] | 1960 | VISIT_BODY( node ); |
---|
[13932f14] | 1961 | } |
---|
| 1962 | |
---|
| 1963 | template< typename pass_type > |
---|
[ab904dc] | 1964 | void PassVisitor< pass_type >::visit( Constant * node ) { |
---|
[4551a6e] | 1965 | VISIT_BODY( node ); |
---|
[13932f14] | 1966 | } |
---|
[ab904dc] | 1967 | |
---|
| 1968 | //--------------------------------------------------------------------------------------------------------------- |
---|
| 1969 | template< typename pass_type > |
---|
| 1970 | Type * PassVisitor< pass_type >::mutate( VoidType * node ) { |
---|
| 1971 | MUTATE_BODY( Type, node ); |
---|
| 1972 | } |
---|
| 1973 | |
---|
| 1974 | template< typename pass_type > |
---|
| 1975 | Type * PassVisitor< pass_type >::mutate( BasicType * node ) { |
---|
| 1976 | MUTATE_BODY( Type, node ); |
---|
| 1977 | } |
---|
| 1978 | |
---|
| 1979 | template< typename pass_type > |
---|
| 1980 | Type * PassVisitor< pass_type >::mutate( PointerType * node ) { |
---|
| 1981 | MUTATE_BODY( Type, node ); |
---|
| 1982 | } |
---|
| 1983 | |
---|
| 1984 | template< typename pass_type > |
---|
| 1985 | Type * PassVisitor< pass_type >::mutate( ArrayType * node ) { |
---|
| 1986 | MUTATE_BODY( Type, node ); |
---|
| 1987 | } |
---|
| 1988 | |
---|
| 1989 | template< typename pass_type > |
---|
[6b9b047] | 1990 | Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) { |
---|
| 1991 | MUTATE_BODY( Type, node ); |
---|
| 1992 | } |
---|
| 1993 | |
---|
| 1994 | template< typename pass_type > |
---|
[ab904dc] | 1995 | Type * PassVisitor< pass_type >::mutate( FunctionType * node ) { |
---|
| 1996 | MUTATE_BODY( Type, node ); |
---|
| 1997 | } |
---|
| 1998 | |
---|
| 1999 | template< typename pass_type > |
---|
| 2000 | Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) { |
---|
| 2001 | MUTATE_BODY( Type, node ); |
---|
| 2002 | } |
---|
| 2003 | |
---|
| 2004 | template< typename pass_type > |
---|
| 2005 | Type * PassVisitor< pass_type >::mutate( TupleType * node ) { |
---|
| 2006 | MUTATE_BODY( Type, node ); |
---|
| 2007 | } |
---|
| 2008 | |
---|
| 2009 | template< typename pass_type > |
---|
| 2010 | Type * PassVisitor< pass_type >::mutate( TypeofType * node ) { |
---|
| 2011 | MUTATE_BODY( Type, node ); |
---|
| 2012 | } |
---|
| 2013 | |
---|
| 2014 | template< typename pass_type > |
---|
| 2015 | Type * PassVisitor< pass_type >::mutate( AttrType * node ) { |
---|
| 2016 | MUTATE_BODY( Type, node ); |
---|
| 2017 | } |
---|
| 2018 | |
---|
| 2019 | template< typename pass_type > |
---|
| 2020 | Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) { |
---|
| 2021 | MUTATE_BODY( Type, node ); |
---|
| 2022 | } |
---|
| 2023 | |
---|
| 2024 | template< typename pass_type > |
---|
| 2025 | Type * PassVisitor< pass_type >::mutate( ZeroType * node ) { |
---|
| 2026 | MUTATE_BODY( Type, node ); |
---|
| 2027 | } |
---|
| 2028 | |
---|
| 2029 | template< typename pass_type > |
---|
| 2030 | Type * PassVisitor< pass_type >::mutate( OneType * node ) { |
---|
| 2031 | MUTATE_BODY( Type, node ); |
---|
| 2032 | } |
---|
| 2033 | |
---|
| 2034 | template< typename pass_type > |
---|
| 2035 | Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) { |
---|
| 2036 | MUTATE_BODY( Initializer, node ); |
---|
| 2037 | } |
---|
| 2038 | |
---|
| 2039 | template< typename pass_type > |
---|
| 2040 | Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) { |
---|
| 2041 | MUTATE_BODY( Initializer, node ); |
---|
| 2042 | } |
---|
| 2043 | |
---|
| 2044 | template< typename pass_type > |
---|
| 2045 | Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) { |
---|
| 2046 | MUTATE_BODY( Subrange, node ); |
---|
| 2047 | } |
---|
| 2048 | |
---|
| 2049 | template< typename pass_type > |
---|
| 2050 | Constant * PassVisitor< pass_type >::mutate( Constant * node ) { |
---|
| 2051 | MUTATE_BODY( Constant, node ); |
---|
[4551a6e] | 2052 | } |
---|