Changeset f53acdf8 for src/Common
- Timestamp:
- Jul 19, 2019, 2:16:01 PM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4eb43fa
- Parents:
- 1f1c102 (diff), 8ac3b0e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/Common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.h
r1f1c102 rf53acdf8 60 60 61 61 virtual void visit( ObjectDecl * objectDecl ) override final; 62 virtual void visit( const ObjectDecl * objectDecl ) override final; 62 63 virtual void visit( FunctionDecl * functionDecl ) override final; 64 virtual void visit( const FunctionDecl * functionDecl ) override final; 63 65 virtual void visit( StructDecl * aggregateDecl ) override final; 66 virtual void visit( const StructDecl * aggregateDecl ) override final; 64 67 virtual void visit( UnionDecl * aggregateDecl ) override final; 68 virtual void visit( const UnionDecl * aggregateDecl ) override final; 65 69 virtual void visit( EnumDecl * aggregateDecl ) override final; 70 virtual void visit( const EnumDecl * aggregateDecl ) override final; 66 71 virtual void visit( TraitDecl * aggregateDecl ) override final; 72 virtual void visit( const TraitDecl * aggregateDecl ) override final; 67 73 virtual void visit( TypeDecl * typeDecl ) override final; 74 virtual void visit( const TypeDecl * typeDecl ) override final; 68 75 virtual void visit( TypedefDecl * typeDecl ) override final; 76 virtual void visit( const TypedefDecl * typeDecl ) override final; 69 77 virtual void visit( AsmDecl * asmDecl ) override final; 78 virtual void visit( const AsmDecl * asmDecl ) override final; 70 79 virtual void visit( StaticAssertDecl * assertDecl ) override final; 80 virtual void visit( const StaticAssertDecl * assertDecl ) override final; 71 81 72 82 virtual void visit( CompoundStmt * compoundStmt ) override final; 83 virtual void visit( const CompoundStmt * compoundStmt ) override final; 73 84 virtual void visit( ExprStmt * exprStmt ) override final; 85 virtual void visit( const ExprStmt * exprStmt ) override final; 74 86 virtual void visit( AsmStmt * asmStmt ) override final; 87 virtual void visit( const AsmStmt * asmStmt ) override final; 75 88 virtual void visit( DirectiveStmt * dirStmt ) override final; 89 virtual void visit( const DirectiveStmt * dirStmt ) override final; 76 90 virtual void visit( IfStmt * ifStmt ) override final; 91 virtual void visit( const IfStmt * ifStmt ) override final; 77 92 virtual void visit( WhileStmt * whileStmt ) override final; 93 virtual void visit( const WhileStmt * whileStmt ) override final; 78 94 virtual void visit( ForStmt * forStmt ) override final; 95 virtual void visit( const ForStmt * forStmt ) override final; 79 96 virtual void visit( SwitchStmt * switchStmt ) override final; 97 virtual void visit( const SwitchStmt * switchStmt ) override final; 80 98 virtual void visit( CaseStmt * caseStmt ) override final; 99 virtual void visit( const CaseStmt * caseStmt ) override final; 81 100 virtual void visit( BranchStmt * branchStmt ) override final; 101 virtual void visit( const BranchStmt * branchStmt ) override final; 82 102 virtual void visit( ReturnStmt * returnStmt ) override final; 103 virtual void visit( const ReturnStmt * returnStmt ) override final; 83 104 virtual void visit( ThrowStmt * throwStmt ) override final; 105 virtual void visit( const ThrowStmt * throwStmt ) override final; 84 106 virtual void visit( TryStmt * tryStmt ) override final; 107 virtual void visit( const TryStmt * tryStmt ) override final; 85 108 virtual void visit( CatchStmt * catchStmt ) override final; 109 virtual void visit( const CatchStmt * catchStmt ) override final; 86 110 virtual void visit( FinallyStmt * finallyStmt ) override final; 111 virtual void visit( const FinallyStmt * finallyStmt ) override final; 87 112 virtual void visit( WaitForStmt * waitforStmt ) override final; 113 virtual void visit( const WaitForStmt * waitforStmt ) override final; 88 114 virtual void visit( WithStmt * withStmt ) override final; 115 virtual void visit( const WithStmt * withStmt ) override final; 89 116 virtual void visit( NullStmt * nullStmt ) override final; 117 virtual void visit( const NullStmt * nullStmt ) override final; 90 118 virtual void visit( DeclStmt * declStmt ) override final; 119 virtual void visit( const DeclStmt * declStmt ) override final; 91 120 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) override final; 121 virtual void visit( const ImplicitCtorDtorStmt * impCtorDtorStmt ) override final; 92 122 93 123 virtual void visit( ApplicationExpr * applicationExpr ) override final; 124 virtual void visit( const ApplicationExpr * applicationExpr ) override final; 94 125 virtual void visit( UntypedExpr * untypedExpr ) override final; 126 virtual void visit( const UntypedExpr * untypedExpr ) override final; 95 127 virtual void visit( NameExpr * nameExpr ) override final; 128 virtual void visit( const NameExpr * nameExpr ) override final; 96 129 virtual void visit( CastExpr * castExpr ) override final; 130 virtual void visit( const CastExpr * castExpr ) override final; 97 131 virtual void visit( KeywordCastExpr * castExpr ) override final; 132 virtual void visit( const KeywordCastExpr * castExpr ) override final; 98 133 virtual void visit( VirtualCastExpr * castExpr ) override final; 134 virtual void visit( const VirtualCastExpr * castExpr ) override final; 99 135 virtual void visit( AddressExpr * addressExpr ) override final; 136 virtual void visit( const AddressExpr * addressExpr ) override final; 100 137 virtual void visit( LabelAddressExpr * labAddressExpr ) override final; 138 virtual void visit( const LabelAddressExpr * labAddressExpr ) override final; 101 139 virtual void visit( UntypedMemberExpr * memberExpr ) override final; 140 virtual void visit( const UntypedMemberExpr * memberExpr ) override final; 102 141 virtual void visit( MemberExpr * memberExpr ) override final; 142 virtual void visit( const MemberExpr * memberExpr ) override final; 103 143 virtual void visit( VariableExpr * variableExpr ) override final; 144 virtual void visit( const VariableExpr * variableExpr ) override final; 104 145 virtual void visit( ConstantExpr * constantExpr ) override final; 146 virtual void visit( const ConstantExpr * constantExpr ) override final; 105 147 virtual void visit( SizeofExpr * sizeofExpr ) override final; 148 virtual void visit( const SizeofExpr * sizeofExpr ) override final; 106 149 virtual void visit( AlignofExpr * alignofExpr ) override final; 150 virtual void visit( const AlignofExpr * alignofExpr ) override final; 107 151 virtual void visit( UntypedOffsetofExpr * offsetofExpr ) override final; 152 virtual void visit( const UntypedOffsetofExpr * offsetofExpr ) override final; 108 153 virtual void visit( OffsetofExpr * offsetofExpr ) override final; 154 virtual void visit( const OffsetofExpr * offsetofExpr ) override final; 109 155 virtual void visit( OffsetPackExpr * offsetPackExpr ) override final; 156 virtual void visit( const OffsetPackExpr * offsetPackExpr ) override final; 110 157 virtual void visit( AttrExpr * attrExpr ) override final; 158 virtual void visit( const AttrExpr * attrExpr ) override final; 111 159 virtual void visit( LogicalExpr * logicalExpr ) override final; 160 virtual void visit( const LogicalExpr * logicalExpr ) override final; 112 161 virtual void visit( ConditionalExpr * conditionalExpr ) override final; 162 virtual void visit( const ConditionalExpr * conditionalExpr ) override final; 113 163 virtual void visit( CommaExpr * commaExpr ) override final; 164 virtual void visit( const CommaExpr * commaExpr ) override final; 114 165 virtual void visit( TypeExpr * typeExpr ) override final; 166 virtual void visit( const TypeExpr * typeExpr ) override final; 115 167 virtual void visit( AsmExpr * asmExpr ) override final; 168 virtual void visit( const AsmExpr * asmExpr ) override final; 116 169 virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) override final; 170 virtual void visit( const ImplicitCopyCtorExpr * impCpCtorExpr ) override final; 117 171 virtual void visit( ConstructorExpr * ctorExpr ) override final; 172 virtual void visit( const ConstructorExpr * ctorExpr ) override final; 118 173 virtual void visit( CompoundLiteralExpr * compLitExpr ) override final; 174 virtual void visit( const CompoundLiteralExpr * compLitExpr ) override final; 119 175 virtual void visit( RangeExpr * rangeExpr ) override final; 176 virtual void visit( const RangeExpr * rangeExpr ) override final; 120 177 virtual void visit( UntypedTupleExpr * tupleExpr ) override final; 178 virtual void visit( const UntypedTupleExpr * tupleExpr ) override final; 121 179 virtual void visit( TupleExpr * tupleExpr ) override final; 180 virtual void visit( const TupleExpr * tupleExpr ) override final; 122 181 virtual void visit( TupleIndexExpr * tupleExpr ) override final; 182 virtual void visit( const TupleIndexExpr * tupleExpr ) override final; 123 183 virtual void visit( TupleAssignExpr * assignExpr ) override final; 184 virtual void visit( const TupleAssignExpr * assignExpr ) override final; 124 185 virtual void visit( StmtExpr * stmtExpr ) override final; 186 virtual void visit( const StmtExpr * stmtExpr ) override final; 125 187 virtual void visit( UniqueExpr * uniqueExpr ) override final; 188 virtual void visit( const UniqueExpr * uniqueExpr ) override final; 126 189 virtual void visit( UntypedInitExpr * initExpr ) override final; 190 virtual void visit( const UntypedInitExpr * initExpr ) override final; 127 191 virtual void visit( InitExpr * initExpr ) override final; 192 virtual void visit( const InitExpr * initExpr ) override final; 128 193 virtual void visit( DeletedExpr * delExpr ) override final; 194 virtual void visit( const DeletedExpr * delExpr ) override final; 129 195 virtual void visit( DefaultArgExpr * argExpr ) override final; 196 virtual void visit( const DefaultArgExpr * argExpr ) override final; 130 197 virtual void visit( GenericExpr * genExpr ) override final; 198 virtual void visit( const GenericExpr * genExpr ) override final; 131 199 132 200 virtual void visit( VoidType * basicType ) override final; 201 virtual void visit( const VoidType * basicType ) override final; 133 202 virtual void visit( BasicType * basicType ) override final; 203 virtual void visit( const BasicType * basicType ) override final; 134 204 virtual void visit( PointerType * pointerType ) override final; 205 virtual void visit( const PointerType * pointerType ) override final; 135 206 virtual void visit( ArrayType * arrayType ) override final; 207 virtual void visit( const ArrayType * arrayType ) override final; 136 208 virtual void visit( ReferenceType * referenceType ) override final; 209 virtual void visit( const ReferenceType * referenceType ) override final; 137 210 virtual void visit( QualifiedType * qualType ) override final; 211 virtual void visit( const QualifiedType * qualType ) override final; 138 212 virtual void visit( FunctionType * functionType ) override final; 213 virtual void visit( const FunctionType * functionType ) override final; 139 214 virtual void visit( StructInstType * aggregateUseType ) override final; 215 virtual void visit( const StructInstType * aggregateUseType ) override final; 140 216 virtual void visit( UnionInstType * aggregateUseType ) override final; 217 virtual void visit( const UnionInstType * aggregateUseType ) override final; 141 218 virtual void visit( EnumInstType * aggregateUseType ) override final; 219 virtual void visit( const EnumInstType * aggregateUseType ) override final; 142 220 virtual void visit( TraitInstType * aggregateUseType ) override final; 221 virtual void visit( const TraitInstType * aggregateUseType ) override final; 143 222 virtual void visit( TypeInstType * aggregateUseType ) override final; 223 virtual void visit( const TypeInstType * aggregateUseType ) override final; 144 224 virtual void visit( TupleType * tupleType ) override final; 225 virtual void visit( const TupleType * tupleType ) override final; 145 226 virtual void visit( TypeofType * typeofType ) override final; 227 virtual void visit( const TypeofType * typeofType ) override final; 146 228 virtual void visit( AttrType * attrType ) override final; 229 virtual void visit( const AttrType * attrType ) override final; 147 230 virtual void visit( VarArgsType * varArgsType ) override final; 231 virtual void visit( const VarArgsType * varArgsType ) override final; 148 232 virtual void visit( ZeroType * zeroType ) override final; 233 virtual void visit( const ZeroType * zeroType ) override final; 149 234 virtual void visit( OneType * oneType ) override final; 235 virtual void visit( const OneType * oneType ) override final; 150 236 virtual void visit( GlobalScopeType * globalType ) override final; 237 virtual void visit( const GlobalScopeType * globalType ) override final; 151 238 152 239 virtual void visit( Designation * designation ) override final; 240 virtual void visit( const Designation * designation ) override final; 153 241 virtual void visit( SingleInit * singleInit ) override final; 242 virtual void visit( const SingleInit * singleInit ) override final; 154 243 virtual void visit( ListInit * listInit ) override final; 244 virtual void visit( const ListInit * listInit ) override final; 155 245 virtual void visit( ConstructorInit * ctorInit ) override final; 246 virtual void visit( const ConstructorInit * ctorInit ) override final; 156 247 157 248 virtual void visit( Constant * constant ) override final; 249 virtual void visit( const Constant * constant ) override final; 158 250 159 251 virtual void visit( Attribute * attribute ) override final; 252 virtual void visit( const Attribute * attribute ) override final; 160 253 161 254 virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override final; … … 186 279 virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; 187 280 virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; 188 virtual Statement* mutate( WithStmt * withStmt ) override final;281 virtual Declaration * mutate( WithStmt * withStmt ) override final; 189 282 virtual NullStmt * mutate( NullStmt * nullStmt ) override final; 190 283 virtual Statement * mutate( DeclStmt * declStmt ) override final; … … 265 358 266 359 template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 360 template<typename pass_t> friend void acceptAll( const std::list< const Declaration * > &decls, PassVisitor< pass_t >& visitor ); 267 361 template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 268 362 template< typename TreeType, typename pass_t > friend void maybeAccept_impl( TreeType * tree, PassVisitor< pass_t > & visitor ); 363 template< typename TreeType, typename pass_t > friend void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_t > & visitor ); 269 364 template< typename TreeType, typename pass_t > friend void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_t > & mutator ); 270 365 template< typename Container, typename pass_t > friend void maybeAccept_impl( Container & container, PassVisitor< pass_t > & visitor ); 366 template< typename Container, typename pass_t > friend void maybeAccept_impl( const Container & container, PassVisitor< pass_t > & visitor ); 271 367 template< typename Container, typename pass_t > friend void maybeMutate_impl( Container & container, PassVisitor< pass_t > & mutator ); 272 368 273 369 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } 370 template<typename node_type> void call_previsit ( const node_type * node ) { previsit_impl ( pass, node, 0 ); } 274 371 template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } 372 template<typename node_type> void call_postvisit( const node_type * node ) { postvisit_impl( pass, node, 0 ); } 275 373 276 374 template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); } … … 286 384 void visitStatementList ( std::list< Statement* > &statements ); 287 385 void mutateStatementList( std::list< Statement* > &statements ); 386 void visitStatementList ( const std::list< Statement * > & statements ); 288 387 289 388 template< typename func_t > … … 291 390 Statement * visitStatement ( Statement * stmt ); 292 391 Statement * mutateStatement( Statement * stmt ); 392 void visitStatement ( const Statement * stmt ); 293 393 294 394 template< typename func_t > … … 296 396 Expression * visitExpression ( Expression * expr ); 297 397 Expression * mutateExpression( Expression * expr ); 398 void visitExpression ( const Expression * expr ); 298 399 299 400 … … 309 410 void indexerScopeEnter () { indexer_impl_enterScope ( pass, 0 ); } 310 411 void indexerScopeLeave () { indexer_impl_leaveScope ( pass, 0 ); } 311 void indexerAddId ( DeclarationWithType* node ) { indexer_impl_addId ( pass, 0, node ); }312 void indexerAddType ( NamedTypeDecl* node ) { indexer_impl_addType ( pass, 0, node ); }412 void indexerAddId ( const DeclarationWithType * node ) { indexer_impl_addId ( pass, 0, node ); } 413 void indexerAddType ( const NamedTypeDecl * node ) { indexer_impl_addType ( pass, 0, node ); } 313 414 void indexerAddStruct ( const std::string & id ) { indexer_impl_addStruct ( pass, 0, id ); } 314 void indexerAddStruct ( StructDecl* node ) { indexer_impl_addStruct ( pass, 0, node ); }315 void indexerAddStructFwd( StructDecl* node ) { indexer_impl_addStructFwd( pass, 0, node ); }316 void indexerAddEnum ( EnumDecl* node ) { indexer_impl_addEnum ( pass, 0, node ); }415 void indexerAddStruct ( const StructDecl * node ) { indexer_impl_addStruct ( pass, 0, node ); } 416 void indexerAddStructFwd( const StructDecl * node ) { indexer_impl_addStructFwd( pass, 0, node ); } 417 void indexerAddEnum ( const EnumDecl * node ) { indexer_impl_addEnum ( pass, 0, node ); } 317 418 void indexerAddUnion ( const std::string & id ) { indexer_impl_addUnion ( pass, 0, id ); } 318 void indexerAddUnion ( UnionDecl* node ) { indexer_impl_addUnion ( pass, 0, node ); }319 void indexerAddUnionFwd ( UnionDecl* node ) { indexer_impl_addUnionFwd ( pass, 0, node ); }320 void indexerAddTrait ( TraitDecl* node ) { indexer_impl_addTrait ( pass, 0, node ); }321 void indexerAddWith ( std::list< Expression * > & exprs, BaseSyntaxNode* withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); }419 void indexerAddUnion ( const UnionDecl * node ) { indexer_impl_addUnion ( pass, 0, node ); } 420 void indexerAddUnionFwd ( const UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); } 421 void indexerAddTrait ( const TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); } 422 void indexerAddWith ( const std::list< Expression * > & exprs, const Declaration * withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); } 322 423 323 424 324 425 template< typename TreeType, typename VisitorType > 325 friend inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor );426 friend inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ); 326 427 327 428 template< typename TreeType, typename VisitorType > 328 friend inline void indexerScopedMutate( TreeType *& tree, VisitorType &visitor ); 429 friend inline void indexerScopedAccept( const TreeType * tree, VisitorType & visitor ); 430 431 template< typename TreeType, typename VisitorType > 432 friend inline void indexerScopedMutate( TreeType *& tree, VisitorType & visitor ); 329 433 }; 330 434 -
src/Common/PassVisitor.impl.h
r1f1c102 rf53acdf8 80 80 81 81 template< typename pass_type > 82 inline void acceptAll( const std::list< const Declaration * > & decls, PassVisitor< pass_type >& visitor ) { 83 SemanticErrorException errors; 84 85 pass_visitor_stats.depth++; 86 pass_visitor_stats.max->push(pass_visitor_stats.depth); 87 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 88 for ( const Declaration * decl : decls ) { 89 try { 90 // run visitor on declaration 91 maybeAccept_impl( decl, visitor ); 92 } 93 catch( SemanticErrorException &e ) { 94 errors.append( e ); 95 } 96 } 97 pass_visitor_stats.depth--; 98 if ( ! errors.isEmpty() ) { 99 throw errors; 100 } 101 } 102 103 template< typename pass_type > 82 104 inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { 83 105 DeclList_t* beforeDecls = mutator.get_beforeDecls(); … … 117 139 } 118 140 141 template< typename TreeType, typename pass_type > 142 inline void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_type > & visitor ) { 143 if ( ! visitor.get_visit_children() ) return; 144 if ( tree ) { 145 tree->accept( visitor ); 146 } 147 } 148 119 149 template< typename Container, typename pass_type > 120 150 inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) { … … 129 159 if ( *i ) { 130 160 (*i)->accept( visitor ); 161 } 162 } catch( SemanticErrorException &e ) { 163 errors.append( e ); 164 } 165 } 166 pass_visitor_stats.depth--; 167 if ( ! errors.isEmpty() ) { 168 throw errors; 169 } 170 } 171 172 template< typename Container, typename pass_type > 173 inline void maybeAccept_impl( const Container & container, PassVisitor< pass_type > & visitor ) { 174 if ( ! visitor.get_visit_children() ) return; 175 SemanticErrorException errors; 176 177 pass_visitor_stats.depth++; 178 pass_visitor_stats.max->push(pass_visitor_stats.depth); 179 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 180 for ( const auto & i : container ) { 181 try { 182 if ( i ) { 183 i->accept( visitor ); 131 184 } 132 185 } catch( SemanticErrorException &e ) { … … 227 280 228 281 template< typename pass_type > 282 void PassVisitor< pass_type >::visitStatementList( const std::list< Statement * > & statements ) { 283 if ( ! get_visit_children() ) return; 284 SemanticErrorException errors; 285 286 pass_visitor_stats.depth++; 287 pass_visitor_stats.max->push(pass_visitor_stats.depth); 288 pass_visitor_stats.avg->push(pass_visitor_stats.depth); 289 for ( const Statement * i : statements ) { 290 try { 291 maybeAccept_impl( i, *this ); 292 } catch ( SemanticErrorException &e ) { 293 errors.append( e ); 294 } 295 } 296 pass_visitor_stats.depth--; 297 if ( !errors.isEmpty() ) { throw errors; } 298 } 299 300 template< typename pass_type > 229 301 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 230 302 handleStatementList( statements, [this]( Statement *& stmt) { … … 275 347 276 348 template< typename pass_type > 349 void PassVisitor< pass_type >::visitStatement( const Statement * stmt ) { 350 if ( ! get_visit_children() ) return; 351 352 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 353 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() ); 354 355 maybeAccept_impl( stmt, *this ); 356 } 357 358 template< typename pass_type > 277 359 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 278 360 return handleStatement( stmt, [this]( Statement * stmt ) { … … 306 388 307 389 template< typename pass_type > 390 void PassVisitor< pass_type >::visitExpression( const Expression * expr ) { 391 if ( ! get_visit_children() ) return; 392 if( !expr ) return; 393 394 auto env_ptr = get_env_ptr(); 395 if ( env_ptr && expr->get_env() ) { 396 *env_ptr = expr->get_env(); 397 } 398 399 maybeAccept_impl( expr, *this ); 400 } 401 402 template< typename pass_type > 308 403 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 309 404 return handleExpression(expr, [this]( Expression * expr ) { … … 315 410 template< typename TreeType, typename VisitorType > 316 411 inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) { 412 if ( ! visitor.get_visit_children() ) return; 413 auto guard = makeFuncGuard( 414 [&visitor]() { visitor.indexerScopeEnter(); }, 415 [&visitor]() { visitor.indexerScopeLeave(); } 416 ); 417 maybeAccept_impl( tree, visitor ); 418 } 419 420 template< typename TreeType, typename VisitorType > 421 inline void indexerScopedAccept( const TreeType * tree, VisitorType & visitor ) { 317 422 if ( ! visitor.get_visit_children() ) return; 318 423 auto guard = makeFuncGuard( … … 372 477 373 478 indexerAddId( node ); 479 480 VISIT_END( node ); 481 } 482 483 template< typename pass_type > 484 void PassVisitor< pass_type >::visit( const ObjectDecl * node ) { 485 VISIT_START( node ); 486 487 maybeAccept_impl( node->type , *this ); 488 maybeAccept_impl( node->init , *this ); 489 maybeAccept_impl( node->bitfieldWidth, *this ); 490 maybeAccept_impl( node->attributes , *this ); 374 491 375 492 VISIT_END( node ); … … 428 545 429 546 template< typename pass_type > 547 void PassVisitor< pass_type >::visit( const FunctionDecl * node ) { 548 VISIT_START( node ); 549 550 indexerAddId( node ); 551 552 maybeAccept_impl( node->withExprs, *this ); 553 { 554 // with clause introduces a level of scope (for the with expression members). 555 // with clause exprs are added to the indexer before parameters so that parameters 556 // shadow with exprs and not the other way around. 557 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 558 indexerAddWith( node->withExprs, node ); 559 { 560 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 561 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 562 static ObjectDecl func( 563 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 564 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 565 nullptr 566 ); 567 indexerAddId( &func ); 568 maybeAccept_impl( node->type, *this ); 569 // function body needs to have the same scope as parameters - CompoundStmt will not enter 570 // a new scope if inFunction is true 571 ValueGuard< bool > oldInFunction( inFunction ); 572 inFunction = true; 573 maybeAccept_impl( node->statements, *this ); 574 maybeAccept_impl( node->attributes, *this ); 575 } 576 } 577 578 VISIT_END( node ); 579 } 580 581 template< typename pass_type > 430 582 DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) { 431 583 MUTATE_START( node ); … … 484 636 485 637 template< typename pass_type > 486 Declaration * PassVisitor< pass_type >::mutate(StructDecl * node ) {487 MUTATE_START( node );638 void PassVisitor< pass_type >::visit( const StructDecl * node ) { 639 VISIT_START( node ); 488 640 489 641 // make up a forward declaration and add it before processing the members … … 493 645 { 494 646 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 647 maybeAccept_impl( node->parameters, *this ); 648 maybeAccept_impl( node->members , *this ); 649 } 650 651 // this addition replaces the forward declaration 652 indexerAddStruct( node ); 653 654 VISIT_END( node ); 655 } 656 657 template< typename pass_type > 658 Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) { 659 MUTATE_START( node ); 660 661 // make up a forward declaration and add it before processing the members 662 // needs to be on the heap because addStruct saves the pointer 663 indexerAddStructFwd( node ); 664 665 { 666 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 495 667 maybeMutate_impl( node->parameters, *this ); 496 668 maybeMutate_impl( node->members , *this ); … … 522 694 VISIT_END( node ); 523 695 } 696 template< typename pass_type > 697 void PassVisitor< pass_type >::visit( const UnionDecl * node ) { 698 VISIT_START( node ); 699 700 // make up a forward declaration and add it before processing the members 701 indexerAddUnionFwd( node ); 702 703 { 704 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 705 maybeAccept_impl( node->parameters, *this ); 706 maybeAccept_impl( node->members , *this ); 707 } 708 709 indexerAddUnion( node ); 710 711 VISIT_END( node ); 712 } 524 713 525 714 template< typename pass_type > … … 557 746 558 747 template< typename pass_type > 748 void PassVisitor< pass_type >::visit( const EnumDecl * node ) { 749 VISIT_START( node ); 750 751 indexerAddEnum( node ); 752 753 // unlike structs, traits, and unions, enums inject their members into the global scope 754 maybeAccept_impl( node->parameters, *this ); 755 maybeAccept_impl( node->members , *this ); 756 757 VISIT_END( node ); 758 } 759 760 template< typename pass_type > 559 761 Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) { 560 762 MUTATE_START( node ); … … 573 775 template< typename pass_type > 574 776 void PassVisitor< pass_type >::visit( TraitDecl * node ) { 777 VISIT_START( node ); 778 779 { 780 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 781 maybeAccept_impl( node->parameters, *this ); 782 maybeAccept_impl( node->members , *this ); 783 } 784 785 indexerAddTrait( node ); 786 787 VISIT_END( node ); 788 } 789 790 template< typename pass_type > 791 void PassVisitor< pass_type >::visit( const TraitDecl * node ) { 575 792 VISIT_START( node ); 576 793 … … 625 842 } 626 843 627 template< typename pass_type > 628 Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) { 629 MUTATE_START( node ); 844 845 template< typename pass_type > 846 void PassVisitor< pass_type >::visit( const TypeDecl * node ) { 847 VISIT_START( node ); 630 848 631 849 { 632 850 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 633 maybe Mutate_impl( node->parameters, *this );634 maybe Mutate_impl( node->base , *this );851 maybeAccept_impl( node->parameters, *this ); 852 maybeAccept_impl( node->base , *this ); 635 853 } 636 854 … … 640 858 indexerAddType( node ); 641 859 860 maybeAccept_impl( node->assertions, *this ); 861 862 indexerScopedAccept( node->init, *this ); 863 864 VISIT_END( node ); 865 } 866 867 template< typename pass_type > 868 Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) { 869 MUTATE_START( node ); 870 871 { 872 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 873 maybeMutate_impl( node->parameters, *this ); 874 maybeMutate_impl( node->base , *this ); 875 } 876 877 // see A NOTE ON THE ORDER OF TRAVERSAL, above 878 // note that assertions come after the type is added to the symtab, since they are not part of the type proper 879 // and may depend on the type itself 880 indexerAddType( node ); 881 642 882 maybeMutate_impl( node->assertions, *this ); 643 883 … … 667 907 668 908 template< typename pass_type > 909 void PassVisitor< pass_type >::visit( const TypedefDecl * node ) { 910 VISIT_START( node ); 911 912 { 913 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 914 maybeAccept_impl( node->parameters, *this ); 915 maybeAccept_impl( node->base , *this ); 916 } 917 918 indexerAddType( node ); 919 920 maybeAccept_impl( node->assertions, *this ); 921 922 VISIT_END( node ); 923 } 924 925 template< typename pass_type > 669 926 Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) { 670 927 MUTATE_START( node ); … … 695 952 696 953 template< typename pass_type > 954 void PassVisitor< pass_type >::visit( const AsmDecl * node ) { 955 VISIT_START( node ); 956 957 maybeAccept_impl( node->stmt, *this ); 958 959 VISIT_END( node ); 960 } 961 962 template< typename pass_type > 697 963 AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) { 698 964 MUTATE_START( node ); … … 710 976 711 977 node->condition = visitExpression( node->condition ); 978 maybeAccept_impl( node->message, *this ); 979 980 VISIT_END( node ); 981 } 982 983 template< typename pass_type > 984 void PassVisitor< pass_type >::visit( const StaticAssertDecl * node ) { 985 VISIT_START( node ); 986 987 visitExpression( node->condition ); 712 988 maybeAccept_impl( node->message, *this ); 713 989 … … 742 1018 743 1019 template< typename pass_type > 1020 void PassVisitor< pass_type >::visit( const CompoundStmt * node ) { 1021 VISIT_START( node ); 1022 { 1023 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 1024 ValueGuard< bool > oldInFunction( inFunction ); 1025 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } ); 1026 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); 1027 inFunction = false; 1028 visitStatementList( node->kids ); 1029 } 1030 VISIT_END( node ); 1031 } 1032 1033 template< typename pass_type > 744 1034 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) { 745 1035 MUTATE_START( node ); … … 767 1057 768 1058 template< typename pass_type > 1059 void PassVisitor< pass_type >::visit( const ExprStmt * node ) { 1060 VISIT_START( node ); 1061 1062 visitExpression( node->expr ); 1063 1064 VISIT_END( node ); 1065 } 1066 1067 template< typename pass_type > 769 1068 Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) { 770 1069 MUTATE_START( node ); … … 790 1089 791 1090 template< typename pass_type > 1091 void PassVisitor< pass_type >::visit( const AsmStmt * node ) { 1092 VISIT_START( node ) 1093 1094 maybeAccept_impl( node->instruction, *this ); 1095 maybeAccept_impl( node->output, *this ); 1096 maybeAccept_impl( node->input, *this ); 1097 maybeAccept_impl( node->clobber, *this ); 1098 1099 VISIT_END( node ); 1100 } 1101 1102 template< typename pass_type > 792 1103 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { 793 1104 MUTATE_START( node ); … … 811 1122 812 1123 template< typename pass_type > 1124 void PassVisitor< pass_type >::visit( const DirectiveStmt * node ) { 1125 VISIT_START( node ) 1126 1127 VISIT_END( node ); 1128 } 1129 1130 template< typename pass_type > 813 1131 Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) { 814 1132 MUTATE_START( node ); … … 825 1143 // if statements introduce a level of scope (for the initialization) 826 1144 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 827 maybeAccept_impl( node-> get_initialization(), *this );1145 maybeAccept_impl( node->initialization, *this ); 828 1146 visitExpression ( node->condition ); 829 1147 node->thenPart = visitStatement( node->thenPart ); … … 834 1152 835 1153 template< typename pass_type > 836 Statement * PassVisitor< pass_type >::mutate(IfStmt * node ) {837 MUTATE_START( node );1154 void PassVisitor< pass_type >::visit( const IfStmt * node ) { 1155 VISIT_START( node ); 838 1156 { 839 1157 // if statements introduce a level of scope (for the initialization) 840 1158 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 841 maybeMutate_impl( node->get_initialization(), *this ); 1159 maybeAccept_impl( node->initialization, *this ); 1160 visitExpression ( node->condition ); 1161 visitStatement ( node->thenPart ); 1162 visitStatement ( node->elsePart ); 1163 } 1164 VISIT_END( node ); 1165 } 1166 1167 template< typename pass_type > 1168 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 1169 MUTATE_START( node ); 1170 { 1171 // if statements introduce a level of scope (for the initialization) 1172 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1173 maybeMutate_impl( node->initialization, *this ); 842 1174 node->condition = mutateExpression( node->condition ); 843 1175 node->thenPart = mutateStatement ( node->thenPart ); … … 859 1191 visitExpression ( node->condition ); 860 1192 node->body = visitStatement( node->body ); 1193 } 1194 1195 VISIT_END( node ); 1196 } 1197 1198 template< typename pass_type > 1199 void PassVisitor< pass_type >::visit( const WhileStmt * node ) { 1200 VISIT_START( node ); 1201 1202 { 1203 // while statements introduce a level of scope (for the initialization) 1204 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1205 maybeAccept_impl( node->initialization, *this ); 1206 visitExpression ( node->condition ); 1207 visitStatement ( node->body ); 861 1208 } 862 1209 … … 897 1244 898 1245 template< typename pass_type > 1246 void PassVisitor< pass_type >::visit( const ForStmt * node ) { 1247 VISIT_START( node ); 1248 { 1249 // for statements introduce a level of scope (for the initialization) 1250 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1251 maybeAccept_impl( node->initialization, *this ); 1252 visitExpression( node->condition ); 1253 visitExpression( node->increment ); 1254 visitStatement ( node->body ); 1255 } 1256 VISIT_END( node ); 1257 } 1258 1259 template< typename pass_type > 899 1260 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { 900 1261 MUTATE_START( node ); … … 923 1284 924 1285 template< typename pass_type > 1286 void PassVisitor< pass_type >::visit( const SwitchStmt * node ) { 1287 VISIT_START( node ); 1288 1289 visitExpression ( node->condition ); 1290 visitStatementList( node->statements ); 1291 1292 VISIT_END( node ); 1293 } 1294 1295 template< typename pass_type > 925 1296 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { 926 1297 MUTATE_START( node ); … … 945 1316 946 1317 template< typename pass_type > 1318 void PassVisitor< pass_type >::visit( const CaseStmt * node ) { 1319 VISIT_START( node ); 1320 1321 visitExpression ( node->condition ); 1322 visitStatementList( node->stmts ); 1323 1324 VISIT_END( node ); 1325 } 1326 1327 template< typename pass_type > 947 1328 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { 948 1329 MUTATE_START( node ); … … 963 1344 964 1345 template< typename pass_type > 1346 void PassVisitor< pass_type >::visit( const BranchStmt * node ) { 1347 VISIT_START( node ); 1348 VISIT_END( node ); 1349 } 1350 1351 template< typename pass_type > 965 1352 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { 966 1353 MUTATE_START( node ); … … 980 1367 981 1368 template< typename pass_type > 1369 void PassVisitor< pass_type >::visit( const ReturnStmt * node ) { 1370 VISIT_START( node ); 1371 1372 visitExpression( node->expr ); 1373 1374 VISIT_END( node ); 1375 } 1376 1377 template< typename pass_type > 982 1378 Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) { 983 1379 MUTATE_START( node ); … … 990 1386 //-------------------------------------------------------------------------- 991 1387 // ThrowStmt 992 993 1388 template< typename pass_type > 994 1389 void PassVisitor< pass_type >::visit( ThrowStmt * node ) { … … 1002 1397 1003 1398 template< typename pass_type > 1399 void PassVisitor< pass_type >::visit( const ThrowStmt * node ) { 1400 VISIT_START( node ); 1401 1402 maybeAccept_impl( node->expr, *this ); 1403 maybeAccept_impl( node->target, *this ); 1404 1405 VISIT_END( node ); 1406 } 1407 1408 template< typename pass_type > 1004 1409 Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) { 1005 1410 MUTATE_START( node ); … … 1015 1420 template< typename pass_type > 1016 1421 void PassVisitor< pass_type >::visit( TryStmt * node ) { 1422 VISIT_START( node ); 1423 1424 maybeAccept_impl( node->block , *this ); 1425 maybeAccept_impl( node->handlers , *this ); 1426 maybeAccept_impl( node->finallyBlock, *this ); 1427 1428 VISIT_END( node ); 1429 } 1430 1431 template< typename pass_type > 1432 void PassVisitor< pass_type >::visit( const TryStmt * node ) { 1017 1433 VISIT_START( node ); 1018 1434 … … 1051 1467 1052 1468 template< typename pass_type > 1469 void PassVisitor< pass_type >::visit( const CatchStmt * node ) { 1470 VISIT_START( node ); 1471 { 1472 // catch statements introduce a level of scope (for the caught exception) 1473 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1474 maybeAccept_impl( node->decl, *this ); 1475 visitExpression ( node->cond ); 1476 visitStatement ( node->body ); 1477 } 1478 VISIT_END( node ); 1479 } 1480 1481 template< typename pass_type > 1053 1482 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { 1054 1483 MUTATE_START( node ); … … 1075 1504 1076 1505 template< typename pass_type > 1506 void PassVisitor< pass_type >::visit( const FinallyStmt * node ) { 1507 VISIT_START( node ); 1508 1509 maybeAccept_impl( node->block, *this ); 1510 1511 VISIT_END( node ); 1512 } 1513 1514 template< typename pass_type > 1077 1515 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 1078 1516 MUTATE_START( node ); … … 1107 1545 1108 1546 template< typename pass_type > 1547 void PassVisitor< pass_type >::visit( const WaitForStmt * node ) { 1548 VISIT_START( node ); 1549 1550 for( auto & clause : node->clauses ) { 1551 maybeAccept_impl( clause.target.function, *this ); 1552 maybeAccept_impl( clause.target.arguments, *this ); 1553 1554 maybeAccept_impl( clause.statement, *this ); 1555 maybeAccept_impl( clause.condition, *this ); 1556 } 1557 1558 maybeAccept_impl( node->timeout.time, *this ); 1559 maybeAccept_impl( node->timeout.statement, *this ); 1560 maybeAccept_impl( node->timeout.condition, *this ); 1561 maybeAccept_impl( node->orelse.statement, *this ); 1562 maybeAccept_impl( node->orelse.condition, *this ); 1563 1564 VISIT_END( node ); 1565 } 1566 1567 template< typename pass_type > 1109 1568 Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) { 1110 1569 MUTATE_START( node ); … … 1130 1589 1131 1590 //-------------------------------------------------------------------------- 1132 // NullStmt1591 // WithStmt 1133 1592 template< typename pass_type > 1134 1593 void PassVisitor< pass_type >::visit( WithStmt * node ) { … … 1145 1604 1146 1605 template< typename pass_type > 1147 Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) { 1606 void PassVisitor< pass_type >::visit( const WithStmt * node ) { 1607 VISIT_START( node ); 1608 maybeAccept_impl( node->exprs, *this ); 1609 { 1610 // catch statements introduce a level of scope (for the caught exception) 1611 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1612 indexerAddWith( node->exprs, node ); 1613 maybeAccept_impl( node->stmt, *this ); 1614 } 1615 VISIT_END( node ); 1616 } 1617 1618 template< typename pass_type > 1619 Declaration * PassVisitor< pass_type >::mutate( WithStmt * node ) { 1148 1620 MUTATE_START( node ); 1149 1621 maybeMutate_impl( node->exprs, *this ); … … 1154 1626 maybeMutate_impl( node->stmt, *this ); 1155 1627 } 1628 MUTATE_END( Declaration, node ); 1629 } 1630 1631 //-------------------------------------------------------------------------- 1632 // NullStmt 1633 template< typename pass_type > 1634 void PassVisitor< pass_type >::visit( NullStmt * node ) { 1635 VISIT_START( node ); 1636 VISIT_END( node ); 1637 } 1638 1639 template< typename pass_type > 1640 void PassVisitor< pass_type >::visit( const NullStmt * node ) { 1641 VISIT_START( node ); 1642 VISIT_END( node ); 1643 } 1644 1645 template< typename pass_type > 1646 NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) { 1647 MUTATE_START( node ); 1648 MUTATE_END( NullStmt, node ); 1649 } 1650 1651 //-------------------------------------------------------------------------- 1652 // DeclStmt 1653 template< typename pass_type > 1654 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 1655 VISIT_START( node ); 1656 1657 maybeAccept_impl( node->decl, *this ); 1658 1659 VISIT_END( node ); 1660 } 1661 1662 template< typename pass_type > 1663 void PassVisitor< pass_type >::visit( const DeclStmt * node ) { 1664 VISIT_START( node ); 1665 1666 maybeAccept_impl( node->decl, *this ); 1667 1668 VISIT_END( node ); 1669 } 1670 1671 template< typename pass_type > 1672 Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) { 1673 MUTATE_START( node ); 1674 1675 maybeMutate_impl( node->decl, *this ); 1676 1156 1677 MUTATE_END( Statement, node ); 1157 1678 } 1158 1679 1159 1680 //-------------------------------------------------------------------------- 1160 // NullStmt 1161 template< typename pass_type > 1162 void PassVisitor< pass_type >::visit( NullStmt * node ) { 1163 VISIT_START( node ); 1164 VISIT_END( node ); 1165 } 1166 1167 template< typename pass_type > 1168 NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) { 1169 MUTATE_START( node ); 1170 MUTATE_END( NullStmt, node ); 1171 } 1172 1173 //-------------------------------------------------------------------------- 1174 // DeclStmt 1175 template< typename pass_type > 1176 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 1177 VISIT_START( node ); 1178 1179 maybeAccept_impl( node->decl, *this ); 1180 1181 VISIT_END( node ); 1182 } 1183 1184 template< typename pass_type > 1185 Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) { 1186 MUTATE_START( node ); 1187 1188 maybeMutate_impl( node->decl, *this ); 1681 // ImplicitCtorDtorStmt 1682 template< typename pass_type > 1683 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { 1684 VISIT_START( node ); 1685 1686 maybeAccept_impl( node->callStmt, *this ); 1687 1688 VISIT_END( node ); 1689 } 1690 1691 template< typename pass_type > 1692 void PassVisitor< pass_type >::visit( const ImplicitCtorDtorStmt * node ) { 1693 VISIT_START( node ); 1694 1695 maybeAccept_impl( node->callStmt, *this ); 1696 1697 VISIT_END( node ); 1698 } 1699 1700 template< typename pass_type > 1701 Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) { 1702 MUTATE_START( node ); 1703 1704 maybeMutate_impl( node->callStmt, *this ); 1189 1705 1190 1706 MUTATE_END( Statement, node ); … … 1192 1708 1193 1709 //-------------------------------------------------------------------------- 1194 // ImplicitCtorDtorStmt1195 template< typename pass_type >1196 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) {1197 VISIT_START( node );1198 1199 maybeAccept_impl( node->callStmt, *this );1200 1201 VISIT_END( node );1202 }1203 1204 template< typename pass_type >1205 Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) {1206 MUTATE_START( node );1207 1208 maybeMutate_impl( node->callStmt, *this );1209 1210 MUTATE_END( Statement, node );1211 }1212 1213 //--------------------------------------------------------------------------1214 1710 // ApplicationExpr 1215 1711 template< typename pass_type > … … 1218 1714 1219 1715 indexerScopedAccept( node->result , *this ); 1220 maybeAccept_impl ( node->function, *this ); 1221 maybeAccept_impl ( node->args , *this ); 1716 maybeAccept_impl ( node->function, *this ); 1717 maybeAccept_impl ( node->args , *this ); 1718 1719 VISIT_END( node ); 1720 } 1721 1722 template< typename pass_type > 1723 void PassVisitor< pass_type >::visit( const ApplicationExpr * node ) { 1724 VISIT_START( node ); 1725 1726 indexerScopedAccept( node->result , *this ); 1727 maybeAccept_impl ( node->function, *this ); 1728 maybeAccept_impl ( node->args , *this ); 1222 1729 1223 1730 VISIT_END( node ); … … 1253 1760 1254 1761 template< typename pass_type > 1762 void PassVisitor< pass_type >::visit( const UntypedExpr * node ) { 1763 VISIT_START( node ); 1764 1765 indexerScopedAccept( node->result, *this ); 1766 1767 for ( auto expr : node->args ) { 1768 visitExpression( expr ); 1769 } 1770 1771 VISIT_END( node ); 1772 } 1773 1774 template< typename pass_type > 1255 1775 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) { 1256 1776 MUTATE_START( node ); … … 1278 1798 1279 1799 template< typename pass_type > 1800 void PassVisitor< pass_type >::visit( const NameExpr * node ) { 1801 VISIT_START( node ); 1802 1803 indexerScopedAccept( node->result, *this ); 1804 1805 VISIT_END( node ); 1806 } 1807 1808 template< typename pass_type > 1280 1809 Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) { 1281 1810 MUTATE_START( node ); … … 1294 1823 1295 1824 indexerScopedAccept( node->result, *this ); 1296 maybeAccept_impl ( node->arg , *this ); 1825 maybeAccept_impl ( node->arg , *this ); 1826 1827 VISIT_END( node ); 1828 } 1829 1830 template< typename pass_type > 1831 void PassVisitor< pass_type >::visit( const CastExpr * node ) { 1832 VISIT_START( node ); 1833 1834 indexerScopedAccept( node->result, *this ); 1835 maybeAccept_impl ( node->arg , *this ); 1297 1836 1298 1837 VISIT_END( node ); … … 1323 1862 1324 1863 template< typename pass_type > 1864 void PassVisitor< pass_type >::visit( const KeywordCastExpr * node ) { 1865 VISIT_START( node ); 1866 1867 indexerScopedAccept( node->result, *this ); 1868 maybeAccept_impl ( node->arg , *this ); 1869 1870 VISIT_END( node ); 1871 } 1872 1873 template< typename pass_type > 1325 1874 Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) { 1326 1875 MUTATE_START( node ); … … 1340 1889 1341 1890 indexerScopedAccept( node->result, *this ); 1342 maybeAccept_impl( node->arg, *this ); 1891 maybeAccept_impl ( node->arg, *this ); 1892 1893 VISIT_END( node ); 1894 } 1895 1896 template< typename pass_type > 1897 void PassVisitor< pass_type >::visit( const VirtualCastExpr * node ) { 1898 VISIT_START( node ); 1899 1900 indexerScopedAccept( node->result, *this ); 1901 maybeAccept_impl ( node->arg, *this ); 1343 1902 1344 1903 VISIT_END( node ); … … 1369 1928 1370 1929 template< typename pass_type > 1930 void PassVisitor< pass_type >::visit( const AddressExpr * node ) { 1931 VISIT_START( node ); 1932 1933 indexerScopedAccept( node->result, *this ); 1934 maybeAccept_impl ( node->arg , *this ); 1935 1936 VISIT_END( node ); 1937 } 1938 1939 template< typename pass_type > 1371 1940 Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) { 1372 1941 MUTATE_START( node ); … … 1391 1960 1392 1961 template< typename pass_type > 1962 void PassVisitor< pass_type >::visit( const LabelAddressExpr * node ) { 1963 VISIT_START( node ); 1964 1965 indexerScopedAccept( node->result, *this ); 1966 1967 VISIT_END( node ); 1968 } 1969 1970 template< typename pass_type > 1393 1971 Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) { 1394 1972 MUTATE_START( node ); … … 1404 1982 template< typename pass_type > 1405 1983 void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { 1984 VISIT_START( node ); 1985 1986 indexerScopedAccept( node->result , *this ); 1987 maybeAccept_impl ( node->aggregate, *this ); 1988 maybeAccept_impl ( node->member , *this ); 1989 1990 VISIT_END( node ); 1991 } 1992 1993 template< typename pass_type > 1994 void PassVisitor< pass_type >::visit( const UntypedMemberExpr * node ) { 1406 1995 VISIT_START( node ); 1407 1996 … … 1438 2027 1439 2028 template< typename pass_type > 2029 void PassVisitor< pass_type >::visit( const MemberExpr * node ) { 2030 VISIT_START( node ); 2031 2032 indexerScopedAccept( node->result , *this ); 2033 maybeAccept_impl ( node->aggregate, *this ); 2034 2035 VISIT_END( node ); 2036 } 2037 2038 template< typename pass_type > 1440 2039 Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) { 1441 2040 MUTATE_START( node ); … … 1460 2059 1461 2060 template< typename pass_type > 2061 void PassVisitor< pass_type >::visit( const VariableExpr * node ) { 2062 VISIT_START( node ); 2063 2064 indexerScopedAccept( node->result, *this ); 2065 2066 VISIT_END( node ); 2067 } 2068 2069 template< typename pass_type > 1462 2070 Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) { 1463 2071 MUTATE_START( node ); … … 1473 2081 template< typename pass_type > 1474 2082 void PassVisitor< pass_type >::visit( ConstantExpr * node ) { 2083 VISIT_START( node ); 2084 2085 indexerScopedAccept( node->result , *this ); 2086 maybeAccept_impl ( &node->constant, *this ); 2087 2088 VISIT_END( node ); 2089 } 2090 2091 template< typename pass_type > 2092 void PassVisitor< pass_type >::visit( const ConstantExpr * node ) { 1475 2093 VISIT_START( node ); 1476 2094 … … 1498 2116 template< typename pass_type > 1499 2117 void PassVisitor< pass_type >::visit( SizeofExpr * node ) { 2118 VISIT_START( node ); 2119 2120 indexerScopedAccept( node->result, *this ); 2121 if ( node->get_isType() ) { 2122 maybeAccept_impl( node->type, *this ); 2123 } else { 2124 maybeAccept_impl( node->expr, *this ); 2125 } 2126 2127 VISIT_END( node ); 2128 } 2129 2130 template< typename pass_type > 2131 void PassVisitor< pass_type >::visit( const SizeofExpr * node ) { 1500 2132 VISIT_START( node ); 1501 2133 … … 1542 2174 1543 2175 template< typename pass_type > 2176 void PassVisitor< pass_type >::visit( const AlignofExpr * node ) { 2177 VISIT_START( node ); 2178 2179 indexerScopedAccept( node->result, *this ); 2180 if ( node->get_isType() ) { 2181 maybeAccept_impl( node->type, *this ); 2182 } else { 2183 maybeAccept_impl( node->expr, *this ); 2184 } 2185 2186 VISIT_END( node ); 2187 } 2188 2189 template< typename pass_type > 1544 2190 Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) { 1545 2191 MUTATE_START( node ); … … 1569 2215 1570 2216 template< typename pass_type > 2217 void PassVisitor< pass_type >::visit( const UntypedOffsetofExpr * node ) { 2218 VISIT_START( node ); 2219 2220 indexerScopedAccept( node->result, *this ); 2221 maybeAccept_impl ( node->type , *this ); 2222 2223 VISIT_END( node ); 2224 } 2225 2226 template< typename pass_type > 1571 2227 Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) { 1572 2228 MUTATE_START( node ); … … 1592 2248 1593 2249 template< typename pass_type > 2250 void PassVisitor< pass_type >::visit( const OffsetofExpr * node ) { 2251 VISIT_START( node ); 2252 2253 indexerScopedAccept( node->result, *this ); 2254 maybeAccept_impl ( node->type , *this ); 2255 2256 VISIT_END( node ); 2257 } 2258 2259 template< typename pass_type > 1594 2260 Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) { 1595 2261 MUTATE_START( node ); … … 1615 2281 1616 2282 template< typename pass_type > 2283 void PassVisitor< pass_type >::visit( const OffsetPackExpr * node ) { 2284 VISIT_START( node ); 2285 2286 indexerScopedAccept( node->result, *this ); 2287 maybeAccept_impl ( node->type , *this ); 2288 2289 VISIT_END( node ); 2290 } 2291 2292 template< typename pass_type > 1617 2293 Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) { 1618 2294 MUTATE_START( node ); … … 1629 2305 template< typename pass_type > 1630 2306 void PassVisitor< pass_type >::visit( AttrExpr * node ) { 2307 VISIT_START( node ); 2308 2309 indexerScopedAccept( node->result, *this ); 2310 if ( node->get_isType() ) { 2311 maybeAccept_impl( node->type, *this ); 2312 } else { 2313 maybeAccept_impl( node->expr, *this ); 2314 } 2315 2316 VISIT_END( node ); 2317 } 2318 2319 template< typename pass_type > 2320 void PassVisitor< pass_type >::visit( const AttrExpr * node ) { 1631 2321 VISIT_START( node ); 1632 2322 … … 1670 2360 1671 2361 template< typename pass_type > 2362 void PassVisitor< pass_type >::visit( const LogicalExpr * node ) { 2363 VISIT_START( node ); 2364 2365 indexerScopedAccept( node->result, *this ); 2366 maybeAccept_impl ( node->arg1 , *this ); 2367 maybeAccept_impl ( node->arg2 , *this ); 2368 2369 VISIT_END( node ); 2370 } 2371 2372 template< typename pass_type > 1672 2373 Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) { 1673 2374 MUTATE_START( node ); … … 1691 2392 maybeAccept_impl ( node->arg2 , *this ); 1692 2393 maybeAccept_impl ( node->arg3 , *this ); 2394 2395 VISIT_END( node ); 2396 } 2397 2398 template< typename pass_type > 2399 void PassVisitor< pass_type >::visit( const ConditionalExpr * node ) { 2400 VISIT_START( node ); 2401 2402 indexerScopedAccept( node->result, *this ); 2403 maybeAccept_impl ( node->arg1 , *this ); 2404 maybeAccept_impl ( node->arg2 , *this ); 2405 maybeAccept_impl ( node->arg3 , *this ); 1693 2406 1694 2407 VISIT_END( node ); … … 1722 2435 1723 2436 template< typename pass_type > 2437 void PassVisitor< pass_type >::visit( const CommaExpr * node ) { 2438 VISIT_START( node ); 2439 2440 indexerScopedAccept( node->result, *this ); 2441 maybeAccept_impl ( node->arg1 , *this ); 2442 maybeAccept_impl ( node->arg2 , *this ); 2443 2444 VISIT_END( node ); 2445 } 2446 2447 template< typename pass_type > 1724 2448 Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) { 1725 2449 MUTATE_START( node ); … … 1746 2470 1747 2471 template< typename pass_type > 2472 void PassVisitor< pass_type >::visit( const TypeExpr * node ) { 2473 VISIT_START( node ); 2474 2475 indexerScopedAccept( node->result, *this ); 2476 maybeAccept_impl ( node->type, *this ); 2477 2478 VISIT_END( node ); 2479 } 2480 2481 template< typename pass_type > 1748 2482 Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) { 1749 2483 MUTATE_START( node ); … … 1760 2494 template< typename pass_type > 1761 2495 void PassVisitor< pass_type >::visit( AsmExpr * node ) { 2496 VISIT_START( node ); 2497 2498 indexerScopedAccept( node->result , *this ); 2499 maybeAccept_impl ( node->inout , *this ); 2500 maybeAccept_impl ( node->constraint, *this ); 2501 maybeAccept_impl ( node->operand , *this ); 2502 2503 VISIT_END( node ); 2504 } 2505 2506 template< typename pass_type > 2507 void PassVisitor< pass_type >::visit( const AsmExpr * node ) { 1762 2508 VISIT_START( node ); 1763 2509 … … 1796 2542 1797 2543 template< typename pass_type > 2544 void PassVisitor< pass_type >::visit( const ImplicitCopyCtorExpr * node ) { 2545 VISIT_START( node ); 2546 2547 indexerScopedAccept( node->result , *this ); 2548 maybeAccept_impl ( node->callExpr , *this ); 2549 2550 VISIT_END( node ); 2551 } 2552 2553 template< typename pass_type > 1798 2554 Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) { 1799 2555 MUTATE_START( node ); … … 1819 2575 1820 2576 template< typename pass_type > 2577 void PassVisitor< pass_type >::visit( const ConstructorExpr * node ) { 2578 VISIT_START( node ); 2579 2580 indexerScopedAccept( node->result , *this ); 2581 maybeAccept_impl ( node->callExpr, *this ); 2582 2583 VISIT_END( node ); 2584 } 2585 2586 template< typename pass_type > 1821 2587 Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) { 1822 2588 MUTATE_START( node ); … … 1842 2608 1843 2609 template< typename pass_type > 2610 void PassVisitor< pass_type >::visit( const CompoundLiteralExpr * node ) { 2611 VISIT_START( node ); 2612 2613 indexerScopedAccept( node->result , *this ); 2614 maybeAccept_impl ( node->initializer, *this ); 2615 2616 VISIT_END( node ); 2617 } 2618 2619 template< typename pass_type > 1844 2620 Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) { 1845 2621 MUTATE_START( node ); … … 1856 2632 template< typename pass_type > 1857 2633 void PassVisitor< pass_type >::visit( RangeExpr * node ) { 2634 VISIT_START( node ); 2635 2636 indexerScopedAccept( node->result, *this ); 2637 maybeAccept_impl ( node->low , *this ); 2638 maybeAccept_impl ( node->high , *this ); 2639 2640 VISIT_END( node ); 2641 } 2642 2643 template< typename pass_type > 2644 void PassVisitor< pass_type >::visit( const RangeExpr * node ) { 1858 2645 VISIT_START( node ); 1859 2646 … … 1890 2677 1891 2678 template< typename pass_type > 2679 void PassVisitor< pass_type >::visit( const UntypedTupleExpr * node ) { 2680 VISIT_START( node ); 2681 2682 indexerScopedAccept( node->result, *this ); 2683 maybeAccept_impl ( node->exprs , *this ); 2684 2685 VISIT_END( node ); 2686 } 2687 2688 template< typename pass_type > 1892 2689 Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) { 1893 2690 MUTATE_START( node ); … … 1913 2710 1914 2711 template< typename pass_type > 2712 void PassVisitor< pass_type >::visit( const TupleExpr * node ) { 2713 VISIT_START( node ); 2714 2715 indexerScopedAccept( node->result, *this ); 2716 maybeAccept_impl ( node->exprs , *this ); 2717 2718 VISIT_END( node ); 2719 } 2720 2721 template< typename pass_type > 1915 2722 Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) { 1916 2723 MUTATE_START( node ); … … 1936 2743 1937 2744 template< typename pass_type > 2745 void PassVisitor< pass_type >::visit( const TupleIndexExpr * node ) { 2746 VISIT_START( node ); 2747 2748 indexerScopedAccept( node->result, *this ); 2749 maybeAccept_impl ( node->tuple , *this ); 2750 2751 VISIT_END( node ); 2752 } 2753 2754 template< typename pass_type > 1938 2755 Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) { 1939 2756 MUTATE_START( node ); … … 1954 2771 indexerScopedAccept( node->result , *this ); 1955 2772 maybeAccept_impl ( node->stmtExpr, *this ); 2773 2774 VISIT_END( node ); 2775 } 2776 2777 template< typename pass_type > 2778 void PassVisitor< pass_type >::visit( const TupleAssignExpr * node ) { 2779 VISIT_START( node ); 2780 2781 indexerScopedAccept( node->result , *this ); 2782 maybeAccept_impl( node->stmtExpr, *this ); 1956 2783 1957 2784 VISIT_END( node ); … … 1989 2816 1990 2817 template< typename pass_type > 1991 Expression * PassVisitor< pass_type >::mutate(StmtExpr * node ) {1992 MUTATE_START( node );2818 void PassVisitor< pass_type >::visit( const StmtExpr * node ) { 2819 VISIT_START( node ); 1993 2820 1994 2821 // don't want statements from outer CompoundStmts to be added to this StmtExpr … … 1997 2824 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 1998 2825 2826 indexerScopedAccept( node->result , *this ); 2827 maybeAccept_impl ( node->statements , *this ); 2828 maybeAccept_impl ( node->returnDecls, *this ); 2829 maybeAccept_impl ( node->dtors , *this ); 2830 2831 VISIT_END( node ); 2832 } 2833 2834 template< typename pass_type > 2835 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { 2836 MUTATE_START( node ); 2837 2838 // don't want statements from outer CompoundStmts to be added to this StmtExpr 2839 ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type > oldEnv( get_env_ptr() ); 2840 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 2841 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 2842 1999 2843 indexerScopedMutate( node->result , *this ); 2000 2844 maybeMutate_impl ( node->statements , *this ); … … 2018 2862 2019 2863 template< typename pass_type > 2864 void PassVisitor< pass_type >::visit( const UniqueExpr * node ) { 2865 VISIT_START( node ); 2866 2867 indexerScopedAccept( node->result, *this ); 2868 maybeAccept_impl ( node->expr , *this ); 2869 2870 VISIT_END( node ); 2871 } 2872 2873 template< typename pass_type > 2020 2874 Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) { 2021 2875 MUTATE_START( node ); … … 2032 2886 template< typename pass_type > 2033 2887 void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) { 2888 VISIT_START( node ); 2889 2890 indexerScopedAccept( node->result, *this ); 2891 maybeAccept_impl ( node->expr , *this ); 2892 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. 2893 2894 VISIT_END( node ); 2895 } 2896 2897 template< typename pass_type > 2898 void PassVisitor< pass_type >::visit( const UntypedInitExpr * node ) { 2034 2899 VISIT_START( node ); 2035 2900 … … 2067 2932 2068 2933 template< typename pass_type > 2934 void PassVisitor< pass_type >::visit( const InitExpr * node ) { 2935 VISIT_START( node ); 2936 2937 indexerScopedAccept( node->result, *this ); 2938 maybeAccept_impl ( node->expr , *this ); 2939 maybeAccept_impl ( node->designation, *this ); 2940 2941 VISIT_END( node ); 2942 } 2943 2944 template< typename pass_type > 2069 2945 Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) { 2070 2946 MUTATE_START( node ); … … 2085 2961 2086 2962 indexerScopedAccept( node->result, *this ); 2087 maybeAccept_impl( node->expr, *this ); 2963 maybeAccept_impl ( node->expr, *this ); 2964 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. 2965 2966 VISIT_END( node ); 2967 } 2968 2969 template< typename pass_type > 2970 void PassVisitor< pass_type >::visit( const DeletedExpr * node ) { 2971 VISIT_START( node ); 2972 2973 indexerScopedAccept( node->result, *this ); 2974 maybeAccept_impl ( node->expr, *this ); 2088 2975 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. 2089 2976 … … 2109 2996 2110 2997 indexerScopedAccept( node->result, *this ); 2111 maybeAccept_impl( node->expr, *this ); 2998 maybeAccept_impl ( node->expr, *this ); 2999 3000 VISIT_END( node ); 3001 } 3002 3003 template< typename pass_type > 3004 void PassVisitor< pass_type >::visit( const DefaultArgExpr * node ) { 3005 VISIT_START( node ); 3006 3007 indexerScopedAccept( node->result, *this ); 3008 maybeAccept_impl ( node->expr, *this ); 2112 3009 2113 3010 VISIT_END( node ); … … 2134 3031 maybeAccept_impl( node->control, *this ); 2135 3032 for ( GenericExpr::Association & assoc : node->associations ) { 3033 indexerScopedAccept( assoc.type, *this ); 3034 maybeAccept_impl( assoc.expr, *this ); 3035 } 3036 3037 VISIT_END( node ); 3038 } 3039 3040 template< typename pass_type > 3041 void PassVisitor< pass_type >::visit( const GenericExpr * node ) { 3042 VISIT_START( node ); 3043 3044 indexerScopedAccept( node->result, *this ); 3045 maybeAccept_impl( node->control, *this ); 3046 for ( const GenericExpr::Association & assoc : node->associations ) { 2136 3047 indexerScopedAccept( assoc.type, *this ); 2137 3048 maybeAccept_impl( assoc.expr, *this ); … … 2168 3079 2169 3080 template< typename pass_type > 3081 void PassVisitor< pass_type >::visit( const VoidType * node ) { 3082 VISIT_START( node ); 3083 3084 maybeAccept_impl( node->forall, *this ); 3085 3086 VISIT_END( node ); 3087 } 3088 3089 template< typename pass_type > 2170 3090 Type * PassVisitor< pass_type >::mutate( VoidType * node ) { 2171 3091 MUTATE_START( node ); … … 2180 3100 template< typename pass_type > 2181 3101 void PassVisitor< pass_type >::visit( BasicType * node ) { 3102 VISIT_START( node ); 3103 3104 maybeAccept_impl( node->forall, *this ); 3105 3106 VISIT_END( node ); 3107 } 3108 3109 template< typename pass_type > 3110 void PassVisitor< pass_type >::visit( const BasicType * node ) { 2182 3111 VISIT_START( node ); 2183 3112 … … 2210 3139 2211 3140 template< typename pass_type > 3141 void PassVisitor< pass_type >::visit( const PointerType * node ) { 3142 VISIT_START( node ); 3143 3144 maybeAccept_impl( node->forall, *this ); 3145 // xxx - should PointerType visit/mutate dimension? 3146 maybeAccept_impl( node->base, *this ); 3147 3148 VISIT_END( node ); 3149 } 3150 3151 template< typename pass_type > 2212 3152 Type * PassVisitor< pass_type >::mutate( PointerType * node ) { 2213 3153 MUTATE_START( node ); … … 2234 3174 2235 3175 template< typename pass_type > 3176 void PassVisitor< pass_type >::visit( const ArrayType * node ) { 3177 VISIT_START( node ); 3178 3179 maybeAccept_impl( node->forall, *this ); 3180 maybeAccept_impl( node->dimension, *this ); 3181 maybeAccept_impl( node->base, *this ); 3182 3183 VISIT_END( node ); 3184 } 3185 3186 template< typename pass_type > 2236 3187 Type * PassVisitor< pass_type >::mutate( ArrayType * node ) { 2237 3188 MUTATE_START( node ); … … 2257 3208 2258 3209 template< typename pass_type > 3210 void PassVisitor< pass_type >::visit( const ReferenceType * node ) { 3211 VISIT_START( node ); 3212 3213 maybeAccept_impl( node->forall, *this ); 3214 maybeAccept_impl( node->base, *this ); 3215 3216 VISIT_END( node ); 3217 } 3218 3219 template< typename pass_type > 2259 3220 Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) { 2260 3221 MUTATE_START( node ); … … 2280 3241 2281 3242 template< typename pass_type > 3243 void PassVisitor< pass_type >::visit( const QualifiedType * node ) { 3244 VISIT_START( node ); 3245 3246 maybeAccept_impl( node->forall, *this ); 3247 maybeAccept_impl( node->parent, *this ); 3248 maybeAccept_impl( node->child, *this ); 3249 3250 VISIT_END( node ); 3251 } 3252 3253 template< typename pass_type > 2282 3254 Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) { 2283 3255 MUTATE_START( node ); … … 2304 3276 2305 3277 template< typename pass_type > 3278 void PassVisitor< pass_type >::visit( const FunctionType * node ) { 3279 VISIT_START( node ); 3280 3281 maybeAccept_impl( node->forall, *this ); 3282 maybeAccept_impl( node->returnVals, *this ); 3283 maybeAccept_impl( node->parameters, *this ); 3284 3285 VISIT_END( node ); 3286 } 3287 3288 template< typename pass_type > 2306 3289 Type * PassVisitor< pass_type >::mutate( FunctionType * node ) { 2307 3290 MUTATE_START( node ); … … 2332 3315 2333 3316 template< typename pass_type > 3317 void PassVisitor< pass_type >::visit( const StructInstType * node ) { 3318 VISIT_START( node ); 3319 3320 indexerAddStruct( node->name ); 3321 3322 { 3323 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 3324 maybeAccept_impl( node->forall , *this ); 3325 maybeAccept_impl( node->parameters, *this ); 3326 } 3327 3328 VISIT_END( node ); 3329 } 3330 3331 template< typename pass_type > 2334 3332 Type * PassVisitor< pass_type >::mutate( StructInstType * node ) { 2335 3333 MUTATE_START( node ); … … 2364 3362 2365 3363 template< typename pass_type > 3364 void PassVisitor< pass_type >::visit( const UnionInstType * node ) { 3365 VISIT_START( node ); 3366 3367 indexerAddStruct( node->name ); 3368 3369 { 3370 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 3371 maybeAccept_impl( node->forall , *this ); 3372 maybeAccept_impl( node->parameters, *this ); 3373 } 3374 3375 VISIT_END( node ); 3376 } 3377 3378 template< typename pass_type > 2366 3379 Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) { 2367 3380 MUTATE_START( node ); … … 2391 3404 2392 3405 template< typename pass_type > 3406 void PassVisitor< pass_type >::visit( const EnumInstType * node ) { 3407 VISIT_START( node ); 3408 3409 maybeAccept_impl( node->forall, *this ); 3410 maybeAccept_impl( node->parameters, *this ); 3411 3412 VISIT_END( node ); 3413 } 3414 3415 template< typename pass_type > 2393 3416 Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) { 2394 3417 MUTATE_START( node ); … … 2413 3436 2414 3437 template< typename pass_type > 3438 void PassVisitor< pass_type >::visit( const TraitInstType * node ) { 3439 VISIT_START( node ); 3440 3441 maybeAccept_impl( node->forall , *this ); 3442 maybeAccept_impl( node->parameters, *this ); 3443 3444 VISIT_END( node ); 3445 } 3446 3447 template< typename pass_type > 2415 3448 Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) { 2416 3449 MUTATE_START( node ); … … 2426 3459 template< typename pass_type > 2427 3460 void PassVisitor< pass_type >::visit( TypeInstType * node ) { 3461 VISIT_START( node ); 3462 3463 maybeAccept_impl( node->forall , *this ); 3464 maybeAccept_impl( node->parameters, *this ); 3465 3466 VISIT_END( node ); 3467 } 3468 3469 template< typename pass_type > 3470 void PassVisitor< pass_type >::visit( const TypeInstType * node ) { 2428 3471 VISIT_START( node ); 2429 3472 … … 2458 3501 2459 3502 template< typename pass_type > 3503 void PassVisitor< pass_type >::visit( const TupleType * node ) { 3504 VISIT_START( node ); 3505 3506 maybeAccept_impl( node->forall, *this ); 3507 maybeAccept_impl( node->types, *this ); 3508 maybeAccept_impl( node->members, *this ); 3509 3510 VISIT_END( node ); 3511 } 3512 3513 template< typename pass_type > 2460 3514 Type * PassVisitor< pass_type >::mutate( TupleType * node ) { 2461 3515 MUTATE_START( node ); … … 2472 3526 template< typename pass_type > 2473 3527 void PassVisitor< pass_type >::visit( TypeofType * node ) { 3528 VISIT_START( node ); 3529 3530 assert( node->expr ); 3531 maybeAccept_impl( node->expr, *this ); 3532 3533 VISIT_END( node ); 3534 } 3535 3536 template< typename pass_type > 3537 void PassVisitor< pass_type >::visit( const TypeofType * node ) { 2474 3538 VISIT_START( node ); 2475 3539 … … 2508 3572 2509 3573 template< typename pass_type > 3574 void PassVisitor< pass_type >::visit( const AttrType * node ) { 3575 VISIT_START( node ); 3576 3577 if ( node->isType ) { 3578 assert( node->type ); 3579 maybeAccept_impl( node->type, *this ); 3580 } else { 3581 assert( node->expr ); 3582 maybeAccept_impl( node->expr, *this ); 3583 } // if 3584 3585 VISIT_END( node ); 3586 } 3587 3588 template< typename pass_type > 2510 3589 Type * PassVisitor< pass_type >::mutate( AttrType * node ) { 2511 3590 MUTATE_START( node ); … … 2534 3613 2535 3614 template< typename pass_type > 3615 void PassVisitor< pass_type >::visit( const VarArgsType * node ) { 3616 VISIT_START( node ); 3617 3618 maybeAccept_impl( node->forall, *this ); 3619 3620 VISIT_END( node ); 3621 } 3622 3623 template< typename pass_type > 2536 3624 Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) { 2537 3625 MUTATE_START( node ); … … 2554 3642 2555 3643 template< typename pass_type > 3644 void PassVisitor< pass_type >::visit( const ZeroType * node ) { 3645 VISIT_START( node ); 3646 3647 maybeAccept_impl( node->forall, *this ); 3648 3649 VISIT_END( node ); 3650 } 3651 3652 template< typename pass_type > 2556 3653 Type * PassVisitor< pass_type >::mutate( ZeroType * node ) { 2557 3654 MUTATE_START( node ); … … 2574 3671 2575 3672 template< typename pass_type > 3673 void PassVisitor< pass_type >::visit( const OneType * node ) { 3674 VISIT_START( node ); 3675 3676 maybeAccept_impl( node->forall, *this ); 3677 3678 VISIT_END( node ); 3679 } 3680 3681 template< typename pass_type > 2576 3682 Type * PassVisitor< pass_type >::mutate( OneType * node ) { 2577 3683 MUTATE_START( node ); … … 2594 3700 2595 3701 template< typename pass_type > 3702 void PassVisitor< pass_type >::visit( const GlobalScopeType * node ) { 3703 VISIT_START( node ); 3704 3705 maybeAccept_impl( node->forall, *this ); 3706 3707 VISIT_END( node ); 3708 } 3709 3710 template< typename pass_type > 2596 3711 Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) { 2597 3712 MUTATE_START( node ); … … 2614 3729 2615 3730 template< typename pass_type > 3731 void PassVisitor< pass_type >::visit( const Designation * node ) { 3732 VISIT_START( node ); 3733 3734 maybeAccept_impl( node->designators, *this ); 3735 3736 VISIT_END( node ); 3737 } 3738 3739 template< typename pass_type > 2616 3740 Designation * PassVisitor< pass_type >::mutate( Designation * node ) { 2617 3741 MUTATE_START( node ); … … 2634 3758 2635 3759 template< typename pass_type > 3760 void PassVisitor< pass_type >::visit( const SingleInit * node ) { 3761 VISIT_START( node ); 3762 3763 visitExpression( node->value ); 3764 3765 VISIT_END( node ); 3766 } 3767 3768 template< typename pass_type > 2636 3769 Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) { 2637 3770 MUTATE_START( node ); … … 2646 3779 template< typename pass_type > 2647 3780 void PassVisitor< pass_type >::visit( ListInit * node ) { 3781 VISIT_START( node ); 3782 3783 maybeAccept_impl( node->designations, *this ); 3784 maybeAccept_impl( node->initializers, *this ); 3785 3786 VISIT_END( node ); 3787 } 3788 3789 template< typename pass_type > 3790 void PassVisitor< pass_type >::visit( const ListInit * node ) { 2648 3791 VISIT_START( node ); 2649 3792 … … 2678 3821 2679 3822 template< typename pass_type > 3823 void PassVisitor< pass_type >::visit( const ConstructorInit * node ) { 3824 VISIT_START( node ); 3825 3826 maybeAccept_impl( node->ctor, *this ); 3827 maybeAccept_impl( node->dtor, *this ); 3828 maybeAccept_impl( node->init, *this ); 3829 3830 VISIT_END( node ); 3831 } 3832 3833 template< typename pass_type > 2680 3834 Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) { 2681 3835 MUTATE_START( node ); … … 2698 3852 2699 3853 template< typename pass_type > 3854 void PassVisitor< pass_type >::visit( const Constant * node ) { 3855 VISIT_START( node ); 3856 3857 VISIT_END( node ); 3858 } 3859 3860 template< typename pass_type > 2700 3861 Constant * PassVisitor< pass_type >::mutate( Constant * node ) { 2701 3862 MUTATE_START( node ); … … 2708 3869 template< typename pass_type > 2709 3870 void PassVisitor< pass_type >::visit( Attribute * node ) { 3871 VISIT_START( node ); 3872 3873 maybeAccept_impl( node->parameters, *this ); 3874 3875 VISIT_END( node ); 3876 } 3877 3878 template< typename pass_type > 3879 void PassVisitor< pass_type >::visit( const Attribute * node ) { 2710 3880 VISIT_START( node ); 2711 3881 -
src/Common/PassVisitor.proto.h
r1f1c102 rf53acdf8 118 118 static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) node_type * node, __attribute__((unused)) long unused ) {} 119 119 120 template<typename pass_type, typename node_type> 121 static inline auto previsit_impl( pass_type& pass, const node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.previsit( node ), void() ) { 122 pass.previsit( node ); 123 } 124 125 template<typename pass_type, typename node_type> 126 static inline void previsit_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) const node_type * node, __attribute__((unused)) long unused ) {} 127 128 129 template<typename pass_type, typename node_type> 130 static inline auto postvisit_impl( pass_type& pass, const node_type * node, __attribute__((unused)) int unused ) -> decltype( pass.postvisit( node ), void() ) { 131 pass.postvisit( node ); 132 } 133 134 template<typename pass_type, typename node_type> 135 static inline void postvisit_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) const node_type * node, __attribute__((unused)) long unused ) {} 136 120 137 //--------------------------------------------------------- 121 138 // Mutate … … 200 217 pass.indexer.func( arg ); \ 201 218 } \ 202 \ 203 template<typename pass_type> \ 204 static inline void indexer_impl_##func ( pass_type &, long, type ) { } \ 219 template<typename pass_type> \ 220 static inline void indexer_impl_##func ( pass_type &, long, type ) { } 205 221 206 222 #define INDEXER_FUNC2( func, type1, type2 ) \ … … 209 225 pass.indexer.func( arg1, arg2 ); \ 210 226 } \ 211 \212 227 template<typename pass_type> \ 213 228 static inline void indexer_impl_##func ( pass_type &, long, type1, type2 ) { } 214 229 215 230 216 INDEXER_FUNC1( addId , DeclarationWithType * );217 INDEXER_FUNC1( addType , NamedTypeDecl * );218 INDEXER_FUNC1( addStruct , StructDecl * );219 INDEXER_FUNC1( addEnum , EnumDecl * );220 INDEXER_FUNC1( addUnion , UnionDecl * );221 INDEXER_FUNC1( addTrait , TraitDecl * );222 INDEXER_FUNC2( addWith , std::list< Expression * > &, BaseSyntaxNode* );231 INDEXER_FUNC1( addId , const DeclarationWithType * ); 232 INDEXER_FUNC1( addType , const NamedTypeDecl * ); 233 INDEXER_FUNC1( addStruct , const StructDecl * ); 234 INDEXER_FUNC1( addEnum , const EnumDecl * ); 235 INDEXER_FUNC1( addUnion , const UnionDecl * ); 236 INDEXER_FUNC1( addTrait , const TraitDecl * ); 237 INDEXER_FUNC2( addWith , const std::list< Expression * > &, const Declaration * ); 223 238 224 239 #undef INDEXER_FUNC1 … … 226 241 227 242 template<typename pass_type> 228 static inline auto indexer_impl_addStructFwd( pass_type & pass, int, StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {243 static inline auto indexer_impl_addStructFwd( pass_type & pass, int, const StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) { 229 244 StructDecl * fwd = new StructDecl( decl->name ); 230 245 cloneAll( decl->parameters, fwd->parameters ); … … 233 248 234 249 template<typename pass_type> 235 static inline auto indexer_impl_addStructFwd( pass_type &, long, StructDecl * ) {}236 237 template<typename pass_type> 238 static inline auto indexer_impl_addUnionFwd( pass_type & pass, int, UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {250 static inline auto indexer_impl_addStructFwd( pass_type &, long, const StructDecl * ) {} 251 252 template<typename pass_type> 253 static inline auto indexer_impl_addUnionFwd( pass_type & pass, int, const UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) { 239 254 UnionDecl * fwd = new UnionDecl( decl->name ); 240 255 cloneAll( decl->parameters, fwd->parameters ); … … 243 258 244 259 template<typename pass_type> 245 static inline auto indexer_impl_addUnionFwd( pass_type &, long, UnionDecl * ) {}260 static inline auto indexer_impl_addUnionFwd( pass_type &, long, const UnionDecl * ) {} 246 261 247 262 template<typename pass_type>
Note:
See TracChangeset
for help on using the changeset viewer.