Changes in src/Common/PassVisitor.impl.h [d8893ca:c194661]
- File:
-
- 1 edited
-
src/Common/PassVisitor.impl.h (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Common/PassVisitor.impl.h
rd8893ca rc194661 55 55 it, 56 56 [](Declaration * decl) -> auto { 57 return new DeclStmt( noLabels,decl );57 return new DeclStmt( decl ); 58 58 } 59 59 ); … … 62 62 63 63 template< typename pass_type > 64 staticinline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) {64 inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) { 65 65 DeclList_t* beforeDecls = visitor.get_beforeDecls(); 66 66 DeclList_t* afterDecls = visitor.get_afterDecls(); 67 SemanticError errors;67 SemanticErrorException errors; 68 68 69 69 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 76 76 // run visitor on declaration 77 77 maybeAccept_impl( *i, visitor ); 78 } catch( SemanticError &e ) { 79 e.set_location( (*i)->location ); 78 } catch( SemanticErrorException &e ) { 80 79 errors.append( e ); 81 80 } … … 90 89 91 90 template< typename pass_type > 92 staticinline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) {91 inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { 93 92 DeclList_t* beforeDecls = mutator.get_beforeDecls(); 94 93 DeclList_t* afterDecls = mutator.get_afterDecls(); 95 SemanticError errors;94 SemanticErrorException errors; 96 95 97 96 for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { … … 103 102 // run mutator on declaration 104 103 maybeMutate_impl( *i, mutator ); 105 } catch( SemanticError &e ) { 106 e.set_location( (*i)->location ); 104 } catch( SemanticErrorException &e ) { 107 105 errors.append( e ); 108 106 } … … 127 125 inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) { 128 126 if ( ! visitor.get_visit_children() ) return; 129 SemanticError errors;127 SemanticErrorException errors; 130 128 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 131 129 try { … … 133 131 (*i)->accept( visitor ); 134 132 } 135 } catch( SemanticError &e ) { 136 e.set_location( (*i)->location ); 133 } catch( SemanticErrorException &e ) { 137 134 errors.append( e ); 138 135 } … … 155 152 inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) { 156 153 if ( ! mutator.get_visit_children() ) return; 157 SemanticError errors;154 SemanticErrorException errors; 158 155 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 159 156 try { … … 162 159 assert( *i ); 163 160 } // if 164 } catch( SemanticError &e ) { 165 e.set_location( (*i)->location ); 161 } catch( SemanticErrorException &e ) { 166 162 errors.append( e ); 167 163 } // try … … 176 172 void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { 177 173 if ( ! get_visit_children() ) return; 178 SemanticError errors;174 SemanticErrorException errors; 179 175 180 176 // don't want statements from outer CompoundStmts to be added to this CompoundStmt … … 199 195 || ( empty( beforeDecls ) && empty( afterDecls )) ); 200 196 201 } catch ( SemanticError &e ) { 202 e.set_location( (*i)->location ); 197 } catch ( SemanticErrorException &e ) { 203 198 errors.append( e ); 204 199 } … … 251 246 || ( empty( beforeDecls ) && empty( afterDecls )) ); 252 247 253 CompoundStmt *compound = new CompoundStmt( noLabels);248 CompoundStmt *compound = new CompoundStmt(); 254 249 if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } 255 250 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } … … 365 360 maybeAccept_impl ( node->attributes , *this ); 366 361 367 if ( node->name != "" ) { 368 indexerAddId( node ); 369 } 362 indexerAddId( node ); 370 363 371 364 VISIT_END( node ); … … 381 374 maybeMutate_impl ( node->attributes , *this ); 382 375 383 if ( node->name != "" ) { 384 indexerAddId( node ); 385 } 376 indexerAddId( node ); 386 377 387 378 MUTATE_END( DeclarationWithType, node ); … … 394 385 VISIT_START( node ); 395 386 396 if ( node->name != "" ) { 397 indexerAddId( node ); 398 } 399 387 indexerAddId( node ); 388 389 maybeAccept_impl( node->withExprs, *this ); 400 390 { 391 // with clause introduces a level of scope (for the with expression members). 392 // with clause exprs are added to the indexer before parameters so that parameters 393 // shadow with exprs and not the other way around. 401 394 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 402 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 403 static ObjectDecl func( 404 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 405 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 406 nullptr 407 ); 408 indexerAddId( &func ); 409 maybeAccept_impl( node->type, *this ); 410 maybeAccept_impl( node->statements, *this ); 411 maybeAccept_impl( node->attributes, *this ); 395 indexerAddWith( node->withExprs, node ); 396 { 397 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 398 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 399 static ObjectDecl func( 400 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 401 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 402 nullptr 403 ); 404 indexerAddId( &func ); 405 maybeAccept_impl( node->type, *this ); 406 // function body needs to have the same scope as parameters - CompoundStmt will not enter 407 // a new scope if inFunction is true 408 ValueGuard< bool > oldInFunction( inFunction ); 409 inFunction = true; 410 maybeAccept_impl( node->statements, *this ); 411 maybeAccept_impl( node->attributes, *this ); 412 } 412 413 } 413 414 … … 419 420 MUTATE_START( node ); 420 421 421 if ( node->name != "" ) { 422 indexerAddId( node ); 423 } 422 indexerAddId( node ); 424 423 425 424 { 425 // with clause introduces a level of scope (for the with expression members). 426 // with clause exprs are added to the indexer before parameters so that parameters 427 // shadow with exprs and not the other way around. 426 428 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 427 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 428 static ObjectDecl func( 429 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 430 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 431 nullptr 432 ); 433 indexerAddId( &func ); 434 maybeMutate_impl( node->type, *this ); 435 maybeMutate_impl( node->statements, *this ); 436 maybeMutate_impl( node->attributes, *this ); 429 indexerAddWith( node->withExprs, node ); 430 { 431 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 432 // implicit add __func__ identifier as specified in the C manual 6.4.2.2 433 static ObjectDecl func( 434 "__func__", noStorageClasses, LinkageSpec::C, nullptr, 435 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), 436 nullptr 437 ); 438 indexerAddId( &func ); 439 maybeMutate_impl( node->type, *this ); 440 // function body needs to have the same scope as parameters - CompoundStmt will not enter 441 // a new scope if inFunction is true 442 ValueGuard< bool > oldInFunction( inFunction ); 443 inFunction = true; 444 maybeMutate_impl( node->statements, *this ); 445 maybeMutate_impl( node->attributes, *this ); 446 } 437 447 } 438 448 … … 683 693 684 694 //-------------------------------------------------------------------------- 695 // StaticAssertDecl 696 template< typename pass_type > 697 void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) { 698 VISIT_START( node ); 699 700 node->condition = visitExpression( node->condition ); 701 maybeAccept_impl( node->message, *this ); 702 703 VISIT_END( node ); 704 } 705 706 template< typename pass_type > 707 StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) { 708 MUTATE_START( node ); 709 710 node->condition = mutateExpression( node->condition ); 711 maybeMutate_impl( node->message, *this ); 712 713 MUTATE_END( StaticAssertDecl, node ); 714 } 715 716 //-------------------------------------------------------------------------- 685 717 // CompoundStmt 686 718 template< typename pass_type > … … 688 720 VISIT_START( node ); 689 721 { 690 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 722 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 723 ValueGuard< bool > oldInFunction( inFunction ); 724 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } ); 691 725 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); 726 inFunction = false; 692 727 visitStatementList( node->kids ); 693 728 } … … 699 734 MUTATE_START( node ); 700 735 { 701 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 736 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 737 ValueGuard< bool > oldInFunction( inFunction ); 738 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } ); 702 739 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); 740 inFunction = false; 703 741 mutateStatementList( node->kids ); 704 742 } … … 730 768 template< typename pass_type > 731 769 void PassVisitor< pass_type >::visit( AsmStmt * node ) { 732 VISIT_BODY( node ); 770 VISIT_START( node ) 771 772 maybeAccept_impl( node->instruction, *this ); 773 maybeAccept_impl( node->output, *this ); 774 maybeAccept_impl( node->input, *this ); 775 maybeAccept_impl( node->clobber, *this ); 776 777 VISIT_END( node ); 733 778 } 734 779 735 780 template< typename pass_type > 736 781 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { 737 MUTATE_BODY( Statement, node ); 782 MUTATE_START( node ); 783 784 maybeMutate_impl( node->instruction, *this ); 785 maybeMutate_impl( node->output, *this ); 786 maybeMutate_impl( node->input, *this ); 787 maybeMutate_impl( node->clobber, *this ); 788 789 MUTATE_END( Statement, node ); 790 } 791 792 //-------------------------------------------------------------------------- 793 // AsmStmt 794 template< typename pass_type > 795 void PassVisitor< pass_type >::visit( DirectiveStmt * node ) { 796 VISIT_START( node ) 797 798 VISIT_END( node ); 799 } 800 801 template< typename pass_type > 802 Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) { 803 MUTATE_START( node ); 804 805 MUTATE_END( Statement, node ); 738 806 } 739 807 … … 774 842 VISIT_START( node ); 775 843 776 visitExpression( node->condition ); 777 node->body = visitStatement( node->body ); 844 { 845 // while statements introduce a level of scope (for the initialization) 846 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 847 maybeAccept_impl( node->initialization, *this ); 848 visitExpression ( node->condition ); 849 node->body = visitStatement( node->body ); 850 } 778 851 779 852 VISIT_END( node ); … … 784 857 MUTATE_START( node ); 785 858 786 node->condition = mutateExpression( node->condition ); 787 node->body = mutateStatement ( node->body ); 859 { 860 // while statements introduce a level of scope (for the initialization) 861 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 862 maybeMutate_impl( node->initialization, *this ); 863 node->condition = mutateExpression( node->condition ); 864 node->body = mutateStatement ( node->body ); 865 } 866 788 867 789 868 MUTATE_END( Statement, node ); … … 868 947 template< typename pass_type > 869 948 void PassVisitor< pass_type >::visit( BranchStmt * node ) { 870 VISIT_BODY( node ); 949 VISIT_START( node ); 950 VISIT_END( node ); 871 951 } 872 952 873 953 template< typename pass_type > 874 954 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { 875 MUTATE_BODY( Statement, node ); 955 MUTATE_START( node ); 956 MUTATE_END( Statement, node ); 876 957 } 877 958 … … 901 982 template< typename pass_type > 902 983 void PassVisitor< pass_type >::visit( ThrowStmt * node ) { 903 VISIT_BODY( node ); 984 VISIT_START( node ); 985 986 maybeAccept_impl( node->expr, *this ); 987 maybeAccept_impl( node->target, *this ); 988 989 VISIT_END( node ); 904 990 } 905 991 906 992 template< typename pass_type > 907 993 Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) { 908 MUTATE_BODY( Statement, node ); 994 MUTATE_START( node ); 995 996 maybeMutate_impl( node->expr, *this ); 997 maybeMutate_impl( node->target, *this ); 998 999 MUTATE_END( Statement, node ); 909 1000 } 910 1001 … … 965 1056 template< typename pass_type > 966 1057 void PassVisitor< pass_type >::visit( FinallyStmt * node ) { 967 VISIT_BODY( node ); 1058 VISIT_START( node ); 1059 1060 maybeAccept_impl( node->block, *this ); 1061 1062 VISIT_END( node ); 968 1063 } 969 1064 970 1065 template< typename pass_type > 971 1066 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 972 MUTATE_BODY( Statement, node ); 1067 MUTATE_START( node ); 1068 1069 maybeMutate_impl( node->block, *this ); 1070 1071 MUTATE_END( Statement, node ); 973 1072 } 974 1073 … … 977 1076 template< typename pass_type > 978 1077 void PassVisitor< pass_type >::visit( WaitForStmt * node ) { 979 VISIT_BODY( node ); 1078 VISIT_START( node ); 1079 1080 for( auto & clause : node->clauses ) { 1081 maybeAccept_impl( clause.target.function, *this ); 1082 maybeAccept_impl( clause.target.arguments, *this ); 1083 1084 maybeAccept_impl( clause.statement, *this ); 1085 maybeAccept_impl( clause.condition, *this ); 1086 } 1087 1088 maybeAccept_impl( node->timeout.time, *this ); 1089 maybeAccept_impl( node->timeout.statement, *this ); 1090 maybeAccept_impl( node->timeout.condition, *this ); 1091 maybeAccept_impl( node->orelse.statement, *this ); 1092 maybeAccept_impl( node->orelse.condition, *this ); 1093 1094 VISIT_END( node ); 980 1095 } 981 1096 982 1097 template< typename pass_type > 983 1098 Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) { 984 MUTATE_BODY( Statement, node ); 1099 MUTATE_START( node ); 1100 1101 for( auto & clause : node->clauses ) { 1102 maybeMutate_impl( clause.target.function, *this ); 1103 maybeMutate_impl( clause.target.arguments, *this ); 1104 1105 maybeMutate_impl( clause.statement, *this ); 1106 maybeMutate_impl( clause.condition, *this ); 1107 } 1108 1109 maybeMutate_impl( node->timeout.time, *this ); 1110 maybeMutate_impl( node->timeout.statement, *this ); 1111 maybeMutate_impl( node->timeout.condition, *this ); 1112 maybeMutate_impl( node->orelse.statement, *this ); 1113 maybeMutate_impl( node->orelse.condition, *this ); 1114 1115 MUTATE_END( Statement, node ); 985 1116 } 986 1117 … … 996 1127 // catch statements introduce a level of scope (for the caught exception) 997 1128 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 998 indexerAddWith( node );1129 indexerAddWith( node->exprs, node ); 999 1130 maybeAccept_impl( node->stmt, *this ); 1000 1131 } … … 1009 1140 // catch statements introduce a level of scope (for the caught exception) 1010 1141 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 1011 indexerAddWith( node );1142 indexerAddWith( node->exprs, node ); 1012 1143 maybeMutate_impl( node->stmt, *this ); 1013 1144 } … … 1019 1150 template< typename pass_type > 1020 1151 void PassVisitor< pass_type >::visit( NullStmt * node ) { 1021 VISIT_BODY( node ); 1152 VISIT_START( node ); 1153 VISIT_END( node ); 1022 1154 } 1023 1155 1024 1156 template< typename pass_type > 1025 1157 NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) { 1026 MUTATE_BODY( NullStmt, node ); 1158 MUTATE_START( node ); 1159 MUTATE_END( NullStmt, node ); 1027 1160 } 1028 1161 … … 1031 1164 template< typename pass_type > 1032 1165 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 1033 VISIT_BODY( node ); 1166 VISIT_START( node ); 1167 1168 maybeAccept_impl( node->decl, *this ); 1169 1170 VISIT_END( node ); 1034 1171 } 1035 1172 1036 1173 template< typename pass_type > 1037 1174 Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) { 1038 MUTATE_BODY( Statement, node ); 1175 MUTATE_START( node ); 1176 1177 maybeMutate_impl( node->decl, *this ); 1178 1179 MUTATE_END( Statement, node ); 1039 1180 } 1040 1181 … … 1043 1184 template< typename pass_type > 1044 1185 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { 1045 VISIT_BODY( node ); 1186 VISIT_START( node ); 1187 1188 maybeAccept_impl( node->callStmt, *this ); 1189 1190 VISIT_END( node ); 1046 1191 } 1047 1192 1048 1193 template< typename pass_type > 1049 1194 Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) { 1050 MUTATE_BODY( Statement, node ); 1195 MUTATE_START( node ); 1196 1197 maybeMutate_impl( node->callStmt, *this ); 1198 1199 MUTATE_END( Statement, node ); 1051 1200 } 1052 1201 … … 1141 1290 template< typename pass_type > 1142 1291 Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) { 1292 MUTATE_START( node ); 1293 1294 indexerScopedMutate( node->env , *this ); 1295 indexerScopedMutate( node->result, *this ); 1296 maybeMutate_impl ( node->arg , *this ); 1297 1298 MUTATE_END( Expression, node ); 1299 } 1300 1301 //-------------------------------------------------------------------------- 1302 // KeywordCastExpr 1303 template< typename pass_type > 1304 void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) { 1305 VISIT_START( node ); 1306 1307 indexerScopedAccept( node->result, *this ); 1308 maybeAccept_impl ( node->arg , *this ); 1309 1310 VISIT_END( node ); 1311 } 1312 1313 template< typename pass_type > 1314 Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) { 1143 1315 MUTATE_START( node ); 1144 1316 … … 1404 1576 indexerScopedAccept( node->result, *this ); 1405 1577 maybeAccept_impl ( node->type , *this ); 1406 maybeAccept_impl ( node->member, *this );1407 1578 1408 1579 VISIT_END( node ); … … 1416 1587 indexerScopedMutate( node->result, *this ); 1417 1588 maybeMutate_impl ( node->type , *this ); 1418 maybeMutate_impl ( node->member, *this );1419 1589 1420 1590 MUTATE_END( Expression, node ); … … 1853 2023 } 1854 2024 2025 //-------------------------------------------------------------------------- 2026 // UntypedInitExpr 2027 template< typename pass_type > 2028 void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) { 2029 VISIT_START( node ); 2030 2031 indexerScopedAccept( node->result, *this ); 2032 maybeAccept_impl ( node->expr , *this ); 2033 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. 2034 2035 VISIT_END( node ); 2036 } 2037 2038 template< typename pass_type > 2039 Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) { 2040 MUTATE_START( node ); 2041 2042 indexerScopedMutate( node->env , *this ); 2043 indexerScopedMutate( node->result, *this ); 2044 maybeMutate_impl ( node->expr , *this ); 2045 // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. 2046 2047 MUTATE_END( Expression, node ); 2048 } 2049 2050 //-------------------------------------------------------------------------- 2051 // InitExpr 2052 template< typename pass_type > 2053 void PassVisitor< pass_type >::visit( InitExpr * node ) { 2054 VISIT_START( node ); 2055 2056 indexerScopedAccept( node->result, *this ); 2057 maybeAccept_impl ( node->expr , *this ); 2058 maybeAccept_impl ( node->designation, *this ); 2059 2060 VISIT_END( node ); 2061 } 2062 2063 template< typename pass_type > 2064 Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) { 2065 MUTATE_START( node ); 2066 2067 indexerScopedMutate( node->env , *this ); 2068 indexerScopedMutate( node->result, *this ); 2069 maybeMutate_impl ( node->expr , *this ); 2070 maybeMutate_impl ( node->designation, *this ); 2071 2072 MUTATE_END( Expression, node ); 2073 } 2074 2075 //-------------------------------------------------------------------------- 2076 // DeletedExpr 2077 template< typename pass_type > 2078 void PassVisitor< pass_type >::visit( DeletedExpr * node ) { 2079 VISIT_START( node ); 2080 2081 indexerScopedAccept( node->result, *this ); 2082 maybeAccept_impl( node->expr, *this ); 2083 // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. 2084 2085 VISIT_END( node ); 2086 } 2087 2088 template< typename pass_type > 2089 Expression * PassVisitor< pass_type >::mutate( DeletedExpr * node ) { 2090 MUTATE_START( node ); 2091 2092 indexerScopedMutate( node->env, *this ); 2093 indexerScopedMutate( node->result, *this ); 2094 maybeMutate_impl( node->expr, *this ); 2095 2096 MUTATE_END( Expression, node ); 2097 } 2098 2099 //-------------------------------------------------------------------------- 2100 // DefaultArgExpr 2101 template< typename pass_type > 2102 void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) { 2103 VISIT_START( node ); 2104 2105 indexerScopedAccept( node->result, *this ); 2106 maybeAccept_impl( node->expr, *this ); 2107 2108 VISIT_END( node ); 2109 } 2110 2111 template< typename pass_type > 2112 Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) { 2113 MUTATE_START( node ); 2114 2115 indexerScopedMutate( node->env, *this ); 2116 indexerScopedMutate( node->result, *this ); 2117 maybeMutate_impl( node->expr, *this ); 2118 2119 MUTATE_END( Expression, node ); 2120 } 2121 2122 //-------------------------------------------------------------------------- 2123 // GenericExpr 2124 template< typename pass_type > 2125 void PassVisitor< pass_type >::visit( GenericExpr * node ) { 2126 VISIT_START( node ); 2127 2128 indexerScopedAccept( node->result, *this ); 2129 maybeAccept_impl( node->control, *this ); 2130 for ( GenericExpr::Association & assoc : node->associations ) { 2131 indexerScopedAccept( assoc.type, *this ); 2132 maybeAccept_impl( assoc.expr, *this ); 2133 } 2134 2135 VISIT_END( node ); 2136 } 2137 2138 template< typename pass_type > 2139 Expression * PassVisitor< pass_type >::mutate( GenericExpr * node ) { 2140 MUTATE_START( node ); 2141 2142 indexerScopedMutate( node->env, *this ); 2143 indexerScopedMutate( node->result, *this ); 2144 maybeMutate_impl( node->control, *this ); 2145 for ( GenericExpr::Association & assoc : node->associations ) { 2146 indexerScopedMutate( assoc.type, *this ); 2147 maybeMutate_impl( assoc.expr, *this ); 2148 } 2149 2150 MUTATE_END( Expression, node ); 2151 } 2152 2153 //-------------------------------------------------------------------------- 2154 // VoidType 1855 2155 template< typename pass_type > 1856 2156 void PassVisitor< pass_type >::visit( VoidType * node ) { 1857 VISIT_BODY( node ); 1858 } 1859 2157 VISIT_START( node ); 2158 2159 maybeAccept_impl( node->forall, *this ); 2160 2161 VISIT_END( node ); 2162 } 2163 2164 template< typename pass_type > 2165 Type * PassVisitor< pass_type >::mutate( VoidType * node ) { 2166 MUTATE_START( node ); 2167 2168 maybeMutate_impl( node->forall, *this ); 2169 2170 MUTATE_END( Type, node ); 2171 } 2172 2173 //-------------------------------------------------------------------------- 2174 // BasicType 1860 2175 template< typename pass_type > 1861 2176 void PassVisitor< pass_type >::visit( BasicType * node ) { 1862 VISIT_BODY( node ); 1863 } 1864 2177 VISIT_START( node ); 2178 2179 maybeAccept_impl( node->forall, *this ); 2180 2181 VISIT_END( node ); 2182 } 2183 2184 template< typename pass_type > 2185 Type * PassVisitor< pass_type >::mutate( BasicType * node ) { 2186 MUTATE_START( node ); 2187 2188 maybeMutate_impl( node->forall, *this ); 2189 2190 MUTATE_END( Type, node ); 2191 } 2192 2193 //-------------------------------------------------------------------------- 2194 // PointerType 1865 2195 template< typename pass_type > 1866 2196 void PassVisitor< pass_type >::visit( PointerType * node ) { 1867 VISIT_BODY( node ); 1868 } 1869 2197 VISIT_START( node ); 2198 2199 maybeAccept_impl( node->forall, *this ); 2200 // xxx - should PointerType visit/mutate dimension? 2201 maybeAccept_impl( node->base, *this ); 2202 2203 VISIT_END( node ); 2204 } 2205 2206 template< typename pass_type > 2207 Type * PassVisitor< pass_type >::mutate( PointerType * node ) { 2208 MUTATE_START( node ); 2209 2210 maybeMutate_impl( node->forall, *this ); 2211 // xxx - should PointerType visit/mutate dimension? 2212 maybeMutate_impl( node->base, *this ); 2213 2214 MUTATE_END( Type, node ); 2215 } 2216 2217 //-------------------------------------------------------------------------- 2218 // ArrayType 1870 2219 template< typename pass_type > 1871 2220 void PassVisitor< pass_type >::visit( ArrayType * node ) { 1872 VISIT_BODY( node ); 1873 } 1874 2221 VISIT_START( node ); 2222 2223 maybeAccept_impl( node->forall, *this ); 2224 maybeAccept_impl( node->dimension, *this ); 2225 maybeAccept_impl( node->base, *this ); 2226 2227 VISIT_END( node ); 2228 } 2229 2230 template< typename pass_type > 2231 Type * PassVisitor< pass_type >::mutate( ArrayType * node ) { 2232 MUTATE_START( node ); 2233 2234 maybeMutate_impl( node->forall, *this ); 2235 maybeMutate_impl( node->dimension, *this ); 2236 maybeMutate_impl( node->base, *this ); 2237 2238 MUTATE_END( Type, node ); 2239 } 2240 2241 //-------------------------------------------------------------------------- 2242 // ReferenceType 1875 2243 template< typename pass_type > 1876 2244 void PassVisitor< pass_type >::visit( ReferenceType * node ) { 1877 VISIT_BODY( node ); 1878 } 1879 2245 VISIT_START( node ); 2246 2247 maybeAccept_impl( node->forall, *this ); 2248 maybeAccept_impl( node->base, *this ); 2249 2250 VISIT_END( node ); 2251 } 2252 2253 template< typename pass_type > 2254 Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) { 2255 MUTATE_START( node ); 2256 2257 maybeMutate_impl( node->forall, *this ); 2258 maybeMutate_impl( node->base, *this ); 2259 2260 MUTATE_END( Type, node ); 2261 } 2262 2263 //-------------------------------------------------------------------------- 2264 // QualifiedType 2265 template< typename pass_type > 2266 void PassVisitor< pass_type >::visit( QualifiedType * node ) { 2267 VISIT_START( node ); 2268 2269 maybeAccept_impl( node->forall, *this ); 2270 maybeAccept_impl( node->parent, *this ); 2271 maybeAccept_impl( node->child, *this ); 2272 2273 VISIT_END( node ); 2274 } 2275 2276 template< typename pass_type > 2277 Type * PassVisitor< pass_type >::mutate( QualifiedType * node ) { 2278 MUTATE_START( node ); 2279 2280 maybeMutate_impl( node->forall, *this ); 2281 maybeMutate_impl( node->parent, *this ); 2282 maybeMutate_impl( node->child, *this ); 2283 2284 MUTATE_END( Type, node ); 2285 } 2286 2287 //-------------------------------------------------------------------------- 2288 // FunctionType 1880 2289 template< typename pass_type > 1881 2290 void PassVisitor< pass_type >::visit( FunctionType * node ) { 1882 VISIT_BODY( node ); 2291 VISIT_START( node ); 2292 2293 maybeAccept_impl( node->forall, *this ); 2294 maybeAccept_impl( node->returnVals, *this ); 2295 maybeAccept_impl( node->parameters, *this ); 2296 2297 VISIT_END( node ); 2298 } 2299 2300 template< typename pass_type > 2301 Type * PassVisitor< pass_type >::mutate( FunctionType * node ) { 2302 MUTATE_START( node ); 2303 2304 maybeMutate_impl( node->forall, *this ); 2305 maybeMutate_impl( node->returnVals, *this ); 2306 maybeMutate_impl( node->parameters, *this ); 2307 2308 MUTATE_END( Type, node ); 1883 2309 } 1884 2310 … … 1951 2377 template< typename pass_type > 1952 2378 void PassVisitor< pass_type >::visit( EnumInstType * node ) { 1953 VISIT_BODY( node ); 2379 VISIT_START( node ); 2380 2381 maybeAccept_impl( node->forall, *this ); 2382 maybeAccept_impl( node->parameters, *this ); 2383 2384 VISIT_END( node ); 1954 2385 } 1955 2386 1956 2387 template< typename pass_type > 1957 2388 Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) { 1958 MUTATE_BODY( Type, node ); 2389 MUTATE_START( node ); 2390 2391 maybeMutate_impl( node->forall, *this ); 2392 maybeMutate_impl( node->parameters, *this ); 2393 2394 MUTATE_END( Type, node ); 1959 2395 } 1960 2396 … … 1985 2421 template< typename pass_type > 1986 2422 void PassVisitor< pass_type >::visit( TypeInstType * node ) { 1987 VISIT_BODY( node ); 1988 } 1989 2423 VISIT_START( node ); 2424 2425 maybeAccept_impl( node->forall , *this ); 2426 maybeAccept_impl( node->parameters, *this ); 2427 2428 VISIT_END( node ); 2429 } 2430 2431 template< typename pass_type > 2432 Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) { 2433 MUTATE_START( node ); 2434 2435 maybeMutate_impl( node->forall , *this ); 2436 maybeMutate_impl( node->parameters, *this ); 2437 2438 MUTATE_END( Type, node ); 2439 } 2440 2441 //-------------------------------------------------------------------------- 2442 // TupleType 1990 2443 template< typename pass_type > 1991 2444 void PassVisitor< pass_type >::visit( TupleType * node ) { 1992 VISIT_BODY( node ); 1993 } 1994 2445 VISIT_START( node ); 2446 2447 maybeAccept_impl( node->forall, *this ); 2448 maybeAccept_impl( node->types, *this ); 2449 maybeAccept_impl( node->members, *this ); 2450 2451 VISIT_END( node ); 2452 } 2453 2454 template< typename pass_type > 2455 Type * PassVisitor< pass_type >::mutate( TupleType * node ) { 2456 MUTATE_START( node ); 2457 2458 maybeMutate_impl( node->forall, *this ); 2459 maybeMutate_impl( node->types, *this ); 2460 maybeMutate_impl( node->members, *this ); 2461 2462 MUTATE_END( Type, node ); 2463 } 2464 2465 //-------------------------------------------------------------------------- 2466 // TypeofType 1995 2467 template< typename pass_type > 1996 2468 void PassVisitor< pass_type >::visit( TypeofType * node ) { 1997 VISIT_BODY( node ); 1998 } 1999 2469 VISIT_START( node ); 2470 2471 assert( node->expr ); 2472 maybeAccept_impl( node->expr, *this ); 2473 2474 VISIT_END( node ); 2475 } 2476 2477 template< typename pass_type > 2478 Type * PassVisitor< pass_type >::mutate( TypeofType * node ) { 2479 MUTATE_START( node ); 2480 2481 assert( node->expr ); 2482 maybeMutate_impl( node->expr, *this ); 2483 2484 MUTATE_END( Type, node ); 2485 } 2486 2487 //-------------------------------------------------------------------------- 2488 // AttrType 2000 2489 template< typename pass_type > 2001 2490 void PassVisitor< pass_type >::visit( AttrType * node ) { 2002 VISIT_BODY( node ); 2003 } 2004 2491 VISIT_START( node ); 2492 2493 if ( node->isType ) { 2494 assert( node->type ); 2495 maybeAccept_impl( node->type, *this ); 2496 } else { 2497 assert( node->expr ); 2498 maybeAccept_impl( node->expr, *this ); 2499 } // if 2500 2501 VISIT_END( node ); 2502 } 2503 2504 template< typename pass_type > 2505 Type * PassVisitor< pass_type >::mutate( AttrType * node ) { 2506 MUTATE_START( node ); 2507 2508 if ( node->isType ) { 2509 assert( node->type ); 2510 maybeMutate_impl( node->type, *this ); 2511 } else { 2512 assert( node->expr ); 2513 maybeMutate_impl( node->expr, *this ); 2514 } // if 2515 2516 MUTATE_END( Type, node ); 2517 } 2518 2519 //-------------------------------------------------------------------------- 2520 // VarArgsType 2005 2521 template< typename pass_type > 2006 2522 void PassVisitor< pass_type >::visit( VarArgsType * node ) { 2007 VISIT_BODY( node ); 2008 } 2009 2523 VISIT_START( node ); 2524 2525 maybeAccept_impl( node->forall, *this ); 2526 2527 VISIT_END( node ); 2528 } 2529 2530 template< typename pass_type > 2531 Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) { 2532 MUTATE_START( node ); 2533 2534 maybeMutate_impl( node->forall, *this ); 2535 2536 MUTATE_END( Type, node ); 2537 } 2538 2539 //-------------------------------------------------------------------------- 2540 // ZeroType 2010 2541 template< typename pass_type > 2011 2542 void PassVisitor< pass_type >::visit( ZeroType * node ) { 2012 VISIT_BODY( node ); 2013 } 2014 2543 VISIT_START( node ); 2544 2545 maybeAccept_impl( node->forall, *this ); 2546 2547 VISIT_END( node ); 2548 } 2549 2550 template< typename pass_type > 2551 Type * PassVisitor< pass_type >::mutate( ZeroType * node ) { 2552 MUTATE_START( node ); 2553 2554 maybeMutate_impl( node->forall, *this ); 2555 2556 MUTATE_END( Type, node ); 2557 } 2558 2559 //-------------------------------------------------------------------------- 2560 // OneType 2015 2561 template< typename pass_type > 2016 2562 void PassVisitor< pass_type >::visit( OneType * node ) { 2017 VISIT_BODY( node ); 2018 } 2019 2563 VISIT_START( node ); 2564 2565 maybeAccept_impl( node->forall, *this ); 2566 2567 VISIT_END( node ); 2568 } 2569 2570 template< typename pass_type > 2571 Type * PassVisitor< pass_type >::mutate( OneType * node ) { 2572 MUTATE_START( node ); 2573 2574 maybeMutate_impl( node->forall, *this ); 2575 2576 MUTATE_END( Type, node ); 2577 } 2578 2579 //-------------------------------------------------------------------------- 2580 // GlobalScopeType 2581 template< typename pass_type > 2582 void PassVisitor< pass_type >::visit( GlobalScopeType * node ) { 2583 VISIT_START( node ); 2584 2585 maybeAccept_impl( node->forall, *this ); 2586 2587 VISIT_END( node ); 2588 } 2589 2590 template< typename pass_type > 2591 Type * PassVisitor< pass_type >::mutate( GlobalScopeType * node ) { 2592 MUTATE_START( node ); 2593 2594 maybeMutate_impl( node->forall, *this ); 2595 2596 MUTATE_END( Type, node ); 2597 } 2598 2599 //-------------------------------------------------------------------------- 2600 // Designation 2020 2601 template< typename pass_type > 2021 2602 void PassVisitor< pass_type >::visit( Designation * node ) { 2022 2603 VISIT_START( node ); 2023 2604 2024 maybeAccept_impl( node-> get_designators(), *this );2605 maybeAccept_impl( node->designators, *this ); 2025 2606 2026 2607 VISIT_END( node ); … … 2031 2612 MUTATE_START( node ); 2032 2613 2033 maybeMutate_impl( node-> get_designators(), *this );2614 maybeMutate_impl( node->designators, *this ); 2034 2615 2035 2616 MUTATE_END( Designation, node ); … … 2042 2623 VISIT_START( node ); 2043 2624 2044 visitExpression( node-> get_value());2625 visitExpression( node->value ); 2045 2626 2046 2627 VISIT_END( node ); … … 2051 2632 MUTATE_START( node ); 2052 2633 2053 node-> set_value( mutateExpression( node->get_value() ));2634 node->value = mutateExpression( node->value ); 2054 2635 2055 2636 MUTATE_END( Initializer, node ); 2056 2637 } 2057 2638 2639 //-------------------------------------------------------------------------- 2640 // ListInit 2058 2641 template< typename pass_type > 2059 2642 void PassVisitor< pass_type >::visit( ListInit * node ) { 2060 VISIT_BODY( node ); 2061 } 2062 2643 VISIT_START( node ); 2644 2645 maybeAccept_impl( node->designations, *this ); 2646 maybeAccept_impl( node->initializers, *this ); 2647 2648 VISIT_END( node ); 2649 } 2650 2651 template< typename pass_type > 2652 Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) { 2653 MUTATE_START( node ); 2654 2655 maybeMutate_impl( node->designations, *this ); 2656 maybeMutate_impl( node->initializers, *this ); 2657 2658 MUTATE_END( Initializer, node ); 2659 } 2660 2661 //-------------------------------------------------------------------------- 2662 // ConstructorInit 2063 2663 template< typename pass_type > 2064 2664 void PassVisitor< pass_type >::visit( ConstructorInit * node ) { 2065 VISIT_BODY( node ); 2066 } 2067 2665 VISIT_START( node ); 2666 2667 maybeAccept_impl( node->ctor, *this ); 2668 maybeAccept_impl( node->dtor, *this ); 2669 maybeAccept_impl( node->init, *this ); 2670 2671 VISIT_END( node ); 2672 } 2673 2674 template< typename pass_type > 2675 Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) { 2676 MUTATE_START( node ); 2677 2678 maybeMutate_impl( node->ctor, *this ); 2679 maybeMutate_impl( node->dtor, *this ); 2680 maybeMutate_impl( node->init, *this ); 2681 2682 MUTATE_END( Initializer, node ); 2683 } 2684 2685 //-------------------------------------------------------------------------- 2686 // Subrange 2068 2687 template< typename pass_type > 2069 2688 void PassVisitor< pass_type >::visit( Subrange * node ) { 2070 VISIT_BODY( node ); 2071 } 2072 2689 VISIT_START( node ); 2690 2691 VISIT_END( node ); 2692 } 2693 2694 template< typename pass_type > 2695 Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) { 2696 MUTATE_START( node ); 2697 2698 MUTATE_END( Subrange, node ); 2699 } 2700 2701 //-------------------------------------------------------------------------- 2702 // Attribute 2073 2703 template< typename pass_type > 2074 2704 void PassVisitor< pass_type >::visit( Constant * node ) { 2075 VISIT_BODY( node ); 2076 } 2077 2705 VISIT_START( node ); 2706 2707 VISIT_END( node ); 2708 } 2709 2710 template< typename pass_type > 2711 Constant * PassVisitor< pass_type >::mutate( Constant * node ) { 2712 MUTATE_START( node ); 2713 2714 MUTATE_END( Constant, node ); 2715 } 2716 2717 //-------------------------------------------------------------------------- 2718 // Attribute 2078 2719 template< typename pass_type > 2079 2720 void PassVisitor< pass_type >::visit( Attribute * node ) { 2080 VISIT_BODY( node ); 2081 } 2082 2083 //--------------------------------------------------------------------------------------------------------------- 2084 template< typename pass_type > 2085 Type * PassVisitor< pass_type >::mutate( VoidType * node ) { 2086 MUTATE_BODY( Type, node ); 2087 } 2088 2089 template< typename pass_type > 2090 Type * PassVisitor< pass_type >::mutate( BasicType * node ) { 2091 MUTATE_BODY( Type, node ); 2092 } 2093 2094 template< typename pass_type > 2095 Type * PassVisitor< pass_type >::mutate( PointerType * node ) { 2096 MUTATE_BODY( Type, node ); 2097 } 2098 2099 template< typename pass_type > 2100 Type * PassVisitor< pass_type >::mutate( ArrayType * node ) { 2101 MUTATE_BODY( Type, node ); 2102 } 2103 2104 template< typename pass_type > 2105 Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) { 2106 MUTATE_BODY( Type, node ); 2107 } 2108 2109 template< typename pass_type > 2110 Type * PassVisitor< pass_type >::mutate( FunctionType * node ) { 2111 MUTATE_BODY( Type, node ); 2112 } 2113 2114 template< typename pass_type > 2115 Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) { 2116 MUTATE_BODY( Type, node ); 2117 } 2118 2119 template< typename pass_type > 2120 Type * PassVisitor< pass_type >::mutate( TupleType * node ) { 2121 MUTATE_BODY( Type, node ); 2122 } 2123 2124 template< typename pass_type > 2125 Type * PassVisitor< pass_type >::mutate( TypeofType * node ) { 2126 MUTATE_BODY( Type, node ); 2127 } 2128 2129 template< typename pass_type > 2130 Type * PassVisitor< pass_type >::mutate( AttrType * node ) { 2131 MUTATE_BODY( Type, node ); 2132 } 2133 2134 template< typename pass_type > 2135 Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) { 2136 MUTATE_BODY( Type, node ); 2137 } 2138 2139 template< typename pass_type > 2140 Type * PassVisitor< pass_type >::mutate( ZeroType * node ) { 2141 MUTATE_BODY( Type, node ); 2142 } 2143 2144 template< typename pass_type > 2145 Type * PassVisitor< pass_type >::mutate( OneType * node ) { 2146 MUTATE_BODY( Type, node ); 2147 } 2148 2149 template< typename pass_type > 2150 Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) { 2151 MUTATE_BODY( Initializer, node ); 2152 } 2153 2154 template< typename pass_type > 2155 Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) { 2156 MUTATE_BODY( Initializer, node ); 2157 } 2158 2159 template< typename pass_type > 2160 Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) { 2161 MUTATE_BODY( Subrange, node ); 2162 } 2163 2164 template< typename pass_type > 2165 Constant * PassVisitor< pass_type >::mutate( Constant * node ) { 2166 MUTATE_BODY( Constant, node ); 2721 VISIT_START( node ); 2722 2723 maybeAccept_impl( node->parameters, *this ); 2724 2725 VISIT_END( node ); 2167 2726 } 2168 2727 2169 2728 template< typename pass_type > 2170 2729 Attribute * PassVisitor< pass_type >::mutate( Attribute * node ) { 2171 MUTATE_BODY( Attribute, node ); 2172 } 2173 2730 MUTATE_START( node ); 2731 2732 maybeMutate_impl( node->parameters, *this ); 2733 2734 MUTATE_END( Attribute, node ); 2735 } 2736 2737 //-------------------------------------------------------------------------- 2738 // TypeSubstitution 2174 2739 template< typename pass_type > 2175 2740 TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
Note:
See TracChangeset
for help on using the changeset viewer.