Ignore:
Timestamp:
May 21, 2019, 4:53:35 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
907c545
Parents:
5b35c21 (diff), 514a791 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r5b35c21 ra1b154d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Pass.impl.hpp --
     7// ast::Pass.impl.hpp --
    88//
    99// Author           : Thierry Delisle
     
    121121        template< typename pass_t >
    122122        template< typename node_t >
    123         auto Pass< pass_t >::call_accept( const node_t * node )
     123        auto ast::Pass< pass_t >::call_accept( const node_t * node )
    124124                -> typename std::enable_if<
    125125                                !std::is_base_of<ast::Expr, node_t>::value &&
     
    139139
    140140        template< typename pass_t >
    141         const ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {
     141        const ast::Expr * ast::Pass< pass_t >::call_accept( const ast::Expr * expr ) {
    142142                __pedantic_pass_assert( __visit_children() );
    143143                __pedantic_pass_assert( expr );
     
    152152
    153153        template< typename pass_t >
    154         const ast::Stmt * Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {
     154        const ast::Stmt * ast::Pass< pass_t >::call_accept( const ast::Stmt * stmt ) {
    155155                __pedantic_pass_assert( __visit_children() );
    156156                __pedantic_pass_assert( stmt );
     
    204204        template< typename pass_t >
    205205        template< template <class...> class container_t >
    206         container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
     206        container_t< ptr<Stmt> > ast::Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    207207                __pedantic_pass_assert( __visit_children() );
    208208                if( statements.empty() ) return {};
     
    270270        template< typename pass_t >
    271271        template< template <class...> class container_t, typename node_t >
    272         container_t< ast::ptr<node_t> > Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
     272        container_t< ast::ptr<node_t> > ast::Pass< pass_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    273273                __pedantic_pass_assert( __visit_children() );
    274274                if( container.empty() ) return {};
     
    301301        template< typename pass_t >
    302302        template<typename node_t, typename parent_t, typename child_t>
    303         void Pass< pass_t >::maybe_accept(
     303        void ast::Pass< pass_t >::maybe_accept(
    304304                const node_t * & parent,
    305305                child_t parent_t::*child
     
    571571        __pass::indexer::addType( pass, 0, node );
    572572
    573         maybe_accept( node, &TypedefDecl::assertions );
     573        VISIT( maybe_accept( node, &TypedefDecl::assertions ); )
    574574
    575575        VISIT_END( Decl, node );
     
    596596
    597597        VISIT(
    598                 maybe_accept( node, &StaticAssertDecl::condition );
    599                 maybe_accept( node, &StaticAssertDecl::msg       );
     598                maybe_accept( node, &StaticAssertDecl::cond );
     599                maybe_accept( node, &StaticAssertDecl::msg  );
    600600        )
    601601
     
    626626// ExprStmt
    627627template< typename pass_t >
    628 const ast::Stmt * ast::Pass< pass_t >::visit( const ExprStmt * node ) {
     628const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ExprStmt * node ) {
    629629        VISIT_START( node );
    630630
     
    666666const ast::Stmt * ast::Pass< pass_t >::visit( const ast::IfStmt * node ) {
    667667        VISIT_START( node );
     668
    668669        VISIT({
    669670                // if statements introduce a level of scope (for the initialization)
     
    674675                maybe_accept( node, &IfStmt::elsePart );
    675676        })
     677
    676678        VISIT_END( Stmt, node );
    677679}
     
    680682// WhileStmt
    681683template< typename pass_t >
    682 const ast::Stmt * ast::Pass< pass_t >::visit( const WhileStmt * node ) {
     684const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WhileStmt * node ) {
    683685        VISIT_START( node );
    684686
     
    832834                //      maybeAccept_impl( clause.condition, *this );
    833835                // }
     836
     837        VISIT({
     838                std::vector<WaitForStmt::Clause> new_clauses;
     839                new_clauses.reserve( node->clauses.size() );
     840                bool mutated = false;
     841                for( const auto & clause : node->clauses ) {
     842
     843                        Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;
     844                        if(func != clause.target.func) mutated = true;
     845
     846                        std::vector<ptr<Expr>> new_args;
     847                        new_args.reserve(clause.target.args.size());
     848                        for( const auto & arg : clause.target.args ) {
     849                                auto a = arg->accept(*this);
     850                                new_args.push_back( a );
     851                                if( a != arg ) mutated = true;
     852                        }
     853
     854                        Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;
     855                        if(stmt != clause.stmt) mutated = true;
     856
     857                        Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;
     858                        if(cond != clause.cond) mutated = true;
     859
     860                        new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } );
     861                }
     862
     863                if(mutated) {
     864                        auto n = mutate(node);
     865                        n->clauses = std::move( new_clauses );
     866                        node = n;
     867                }
     868        })
    834869
    835870        #define maybe_accept(field) \
     
    910945}
    911946
    912 
    913 
    914 
    915 
     947//--------------------------------------------------------------------------
     948// ApplicationExpr
     949template< typename pass_t >
     950const ast::Expr * ast::Pass< pass_t >::visit( const ast::ApplicationExpr * node ) {
     951        VISIT_START( node );
     952
     953        VISIT(
     954                {
     955                        guard_indexer guard { *this };
     956                        maybe_accept( node, &ApplicationExpr::result );
     957                }
     958                maybe_accept( node, &ApplicationExpr::func );
     959                maybe_accept( node, &ApplicationExpr::args );
     960        )
     961
     962        VISIT_END( Expr, node );
     963}
     964
     965//--------------------------------------------------------------------------
     966// UntypedExpr
     967template< typename pass_t >
     968const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedExpr * node ) {
     969        VISIT_START( node );
     970
     971        VISIT(
     972                {
     973                        guard_indexer guard { *this };
     974                        maybe_accept( node, &UntypedExpr::result );
     975                }
     976
     977                maybe_accept( node, &UntypedExpr::args );
     978        )
     979
     980        VISIT_END( Expr, node );
     981}
     982
     983//--------------------------------------------------------------------------
     984// NameExpr
     985template< typename pass_t >
     986const ast::Expr * ast::Pass< pass_t >::visit( const ast::NameExpr * node ) {
     987        VISIT_START( node );
     988
     989        VISIT({
     990                guard_indexer guard { *this };
     991                maybe_accept( node, &NameExpr::result );
     992        })
     993
     994        VISIT_END( Expr, node );
     995}
     996
     997//--------------------------------------------------------------------------
     998// CastExpr
     999template< typename pass_t >
     1000const ast::Expr * ast::Pass< pass_t >::visit( const ast::CastExpr * node ) {
     1001        VISIT_START( node );
     1002
     1003        VISIT({
     1004                        guard_indexer guard { *this };
     1005                        maybe_accept( node, &CastExpr::result );
     1006                }
     1007                maybe_accept( node, &CastExpr::arg );
     1008        )
     1009
     1010        VISIT_END( Expr, node );
     1011}
     1012
     1013//--------------------------------------------------------------------------
     1014// KeywordCastExpr
     1015template< typename pass_t >
     1016const ast::Expr * ast::Pass< pass_t >::visit( const ast::KeywordCastExpr * node ) {
     1017        VISIT_START( node );
     1018
     1019        VISIT({
     1020                        guard_indexer guard { *this };
     1021                        maybe_accept( node, &KeywordCastExpr::result );
     1022                }
     1023                maybe_accept( node, &KeywordCastExpr::arg );
     1024        )
     1025
     1026        VISIT_END( Expr, node );
     1027}
     1028
     1029//--------------------------------------------------------------------------
     1030// VirtualCastExpr
     1031template< typename pass_t >
     1032const ast::Expr * ast::Pass< pass_t >::visit( const ast::VirtualCastExpr * node ) {
     1033        VISIT_START( node );
     1034
     1035        VISIT({
     1036                        guard_indexer guard { *this };
     1037                        maybe_accept( node, &VirtualCastExpr::result );
     1038                }
     1039                maybe_accept( node, &VirtualCastExpr::arg );
     1040        )
     1041
     1042        VISIT_END( Expr, node );
     1043}
     1044
     1045//--------------------------------------------------------------------------
     1046// AddressExpr
     1047template< typename pass_t >
     1048const ast::Expr * ast::Pass< pass_t >::visit( const ast::AddressExpr * node ) {
     1049        VISIT_START( node );
     1050
     1051        VISIT({
     1052                        guard_indexer guard { *this };
     1053                        maybe_accept( node, &AddressExpr::result );
     1054                }
     1055                maybe_accept( node, &AddressExpr::arg );
     1056        )
     1057
     1058        VISIT_END( Expr, node );
     1059}
     1060
     1061//--------------------------------------------------------------------------
     1062// LabelAddressExpr
     1063template< typename pass_t >
     1064const ast::Expr * ast::Pass< pass_t >::visit( const ast::LabelAddressExpr * node ) {
     1065        VISIT_START( node );
     1066
     1067        VISIT({
     1068                guard_indexer guard { *this };
     1069                maybe_accept( node, &LabelAddressExpr::result );
     1070        })
     1071
     1072        VISIT_END( Expr, node );
     1073}
     1074
     1075//--------------------------------------------------------------------------
     1076// UntypedMemberExpr
     1077template< typename pass_t >
     1078const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedMemberExpr * node ) {
     1079        VISIT_START( node );
     1080
     1081        VISIT({
     1082                        guard_indexer guard { *this };
     1083                        maybe_accept( node, &UntypedMemberExpr::result );
     1084                }
     1085                maybe_accept( node, &UntypedMemberExpr::aggregate );
     1086                maybe_accept( node, &UntypedMemberExpr::member    );
     1087        )
     1088
     1089        VISIT_END( Expr, node );
     1090}
     1091
     1092//--------------------------------------------------------------------------
     1093// MemberExpr
     1094template< typename pass_t >
     1095const ast::Expr * ast::Pass< pass_t >::visit( const ast::MemberExpr * node ) {
     1096        VISIT_START( node );
     1097
     1098        VISIT({
     1099                        guard_indexer guard { *this };
     1100                        maybe_accept( node, &MemberExpr::result );
     1101                }
     1102                maybe_accept( node, &MemberExpr::aggregate );
     1103        )
     1104
     1105        VISIT_END( Expr, node );
     1106}
     1107
     1108//--------------------------------------------------------------------------
     1109// VariableExpr
     1110template< typename pass_t >
     1111const ast::Expr * ast::Pass< pass_t >::visit( const ast::VariableExpr * node ) {
     1112        VISIT_START( node );
     1113
     1114        VISIT({
     1115                guard_indexer guard { *this };
     1116                maybe_accept( node, &VariableExpr::result );
     1117        })
     1118
     1119        VISIT_END( Expr, node );
     1120}
     1121
     1122//--------------------------------------------------------------------------
     1123// ConstantExpr
     1124template< typename pass_t >
     1125const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstantExpr * node ) {
     1126        VISIT_START( node );
     1127
     1128        VISIT({
     1129                guard_indexer guard { *this };
     1130                maybe_accept( node, &ConstantExpr::result );
     1131        })
     1132
     1133        VISIT_END( Expr, node );
     1134}
     1135
     1136//--------------------------------------------------------------------------
     1137// SizeofExpr
     1138template< typename pass_t >
     1139const ast::Expr * ast::Pass< pass_t >::visit( const ast::SizeofExpr * node ) {
     1140        VISIT_START( node );
     1141
     1142        VISIT({
     1143                        guard_indexer guard { *this };
     1144                        maybe_accept( node, &SizeofExpr::result );
     1145                }
     1146                if ( node->type ) {
     1147                        maybe_accept( node, &SizeofExpr::type );
     1148                } else {
     1149                        maybe_accept( node, &SizeofExpr::expr );
     1150                }
     1151        )
     1152
     1153        VISIT_END( Expr, node );
     1154}
     1155
     1156//--------------------------------------------------------------------------
     1157// AlignofExpr
     1158template< typename pass_t >
     1159const ast::Expr * ast::Pass< pass_t >::visit( const ast::AlignofExpr * node ) {
     1160        VISIT_START( node );
     1161
     1162        VISIT({
     1163                        guard_indexer guard { *this };
     1164                        maybe_accept( node, &AlignofExpr::result );
     1165                }
     1166                if ( node->type ) {
     1167                        maybe_accept( node, &AlignofExpr::type );
     1168                } else {
     1169                        maybe_accept( node, &AlignofExpr::expr );
     1170                }
     1171        )
     1172
     1173        VISIT_END( Expr, node );
     1174}
     1175
     1176//--------------------------------------------------------------------------
     1177// UntypedOffsetofExpr
     1178template< typename pass_t >
     1179const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedOffsetofExpr * node ) {
     1180        VISIT_START( node );
     1181
     1182        VISIT({
     1183                        guard_indexer guard { *this };
     1184                        maybe_accept( node, &UntypedOffsetofExpr::result );
     1185                }
     1186                maybe_accept( node, &UntypedOffsetofExpr::type   );
     1187        )
     1188
     1189        VISIT_END( Expr, node );
     1190}
     1191
     1192//--------------------------------------------------------------------------
     1193// OffsetofExpr
     1194template< typename pass_t >
     1195const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetofExpr * node ) {
     1196        VISIT_START( node );
     1197
     1198        VISIT({
     1199                        guard_indexer guard { *this };
     1200                        maybe_accept( node, &OffsetofExpr::result );
     1201                }
     1202                maybe_accept( node, &OffsetofExpr::type   );
     1203        )
     1204
     1205        VISIT_END( Expr, node );
     1206}
     1207
     1208//--------------------------------------------------------------------------
     1209// OffsetPackExpr
     1210template< typename pass_t >
     1211const ast::Expr * ast::Pass< pass_t >::visit( const ast::OffsetPackExpr * node ) {
     1212        VISIT_START( node );
     1213
     1214        VISIT({
     1215                        guard_indexer guard { *this };
     1216                        maybe_accept( node, &OffsetPackExpr::result );
     1217                }
     1218                maybe_accept( node, &OffsetPackExpr::type   );
     1219        )
     1220
     1221        VISIT_END( Expr, node );
     1222}
     1223
     1224//--------------------------------------------------------------------------
     1225// LogicalExpr
     1226template< typename pass_t >
     1227const ast::Expr * ast::Pass< pass_t >::visit( const ast::LogicalExpr * node ) {
     1228        VISIT_START( node );
     1229
     1230        VISIT({
     1231                        guard_indexer guard { *this };
     1232                        maybe_accept( node, &LogicalExpr::result );
     1233                }
     1234                maybe_accept( node, &LogicalExpr::arg1 );
     1235                maybe_accept( node, &LogicalExpr::arg2 );
     1236        )
     1237
     1238        VISIT_END( Expr, node );
     1239}
     1240
     1241//--------------------------------------------------------------------------
     1242// ConditionalExpr
     1243template< typename pass_t >
     1244const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConditionalExpr * node ) {
     1245        VISIT_START( node );
     1246
     1247        VISIT({
     1248                        guard_indexer guard { *this };
     1249                        maybe_accept( node, &ConditionalExpr::result );
     1250                }
     1251                maybe_accept( node, &ConditionalExpr::arg1 );
     1252                maybe_accept( node, &ConditionalExpr::arg2 );
     1253                maybe_accept( node, &ConditionalExpr::arg3 );
     1254        )
     1255
     1256        VISIT_END( Expr, node );
     1257}
     1258
     1259//--------------------------------------------------------------------------
     1260// CommaExpr
     1261template< typename pass_t >
     1262const ast::Expr * ast::Pass< pass_t >::visit( const ast::CommaExpr * node ) {
     1263        VISIT_START( node );
     1264
     1265        VISIT({
     1266                        guard_indexer guard { *this };
     1267                        maybe_accept( node, &CommaExpr::result );
     1268                }
     1269                maybe_accept( node, &CommaExpr::arg1 );
     1270                maybe_accept( node, &CommaExpr::arg2 );
     1271        )
     1272
     1273        VISIT_END( Expr, node );
     1274}
     1275
     1276//--------------------------------------------------------------------------
     1277// TypeExpr
     1278template< typename pass_t >
     1279const ast::Expr * ast::Pass< pass_t >::visit( const ast::TypeExpr * node ) {
     1280        VISIT_START( node );
     1281
     1282        VISIT({
     1283                        guard_indexer guard { *this };
     1284                        maybe_accept( node, &TypeExpr::result );
     1285                }
     1286                maybe_accept( node, &TypeExpr::type );
     1287        )
     1288
     1289        VISIT_END( Expr, node );
     1290}
     1291
     1292//--------------------------------------------------------------------------
     1293// AsmExpr
     1294template< typename pass_t >
     1295const ast::Expr * ast::Pass< pass_t >::visit( const ast::AsmExpr * node ) {
     1296        VISIT_START( node );
     1297
     1298        VISIT({
     1299                        guard_indexer guard { *this };
     1300                        maybe_accept( node, &AsmExpr::result );
     1301                }
     1302                maybe_accept( node, &AsmExpr::inout      );
     1303                maybe_accept( node, &AsmExpr::constraint );
     1304                maybe_accept( node, &AsmExpr::operand    );
     1305        )
     1306
     1307        VISIT_END( Expr, node );
     1308}
     1309
     1310//--------------------------------------------------------------------------
     1311// ImplicitCopyCtorExpr
     1312template< typename pass_t >
     1313const ast::Expr * ast::Pass< pass_t >::visit( const ast::ImplicitCopyCtorExpr * node ) {
     1314        VISIT_START( node );
     1315
     1316        VISIT({
     1317                        guard_indexer guard { *this };
     1318                        maybe_accept( node, &ImplicitCopyCtorExpr::result );
     1319                }
     1320                maybe_accept( node, &ImplicitCopyCtorExpr::callExpr    );
     1321                maybe_accept( node, &ImplicitCopyCtorExpr::tempDecls   );
     1322                maybe_accept( node, &ImplicitCopyCtorExpr::returnDecls );
     1323                maybe_accept( node, &ImplicitCopyCtorExpr::dtors       );
     1324        )
     1325
     1326        VISIT_END( Expr, node );
     1327}
     1328
     1329//--------------------------------------------------------------------------
     1330// ConstructorExpr
     1331template< typename pass_t >
     1332const ast::Expr * ast::Pass< pass_t >::visit( const ast::ConstructorExpr * node ) {
     1333        VISIT_START( node );
     1334
     1335        VISIT({
     1336                        guard_indexer guard { *this };
     1337                        maybe_accept( node, &ConstructorExpr::result );
     1338                }
     1339                maybe_accept( node, &ConstructorExpr::callExpr );
     1340        )
     1341
     1342        VISIT_END( Expr, node );
     1343}
     1344
     1345//--------------------------------------------------------------------------
     1346// CompoundLiteralExpr
     1347template< typename pass_t >
     1348const ast::Expr * ast::Pass< pass_t >::visit( const ast::CompoundLiteralExpr * node ) {
     1349        VISIT_START( node );
     1350
     1351        VISIT({
     1352                        guard_indexer guard { *this };
     1353                        maybe_accept( node, &CompoundLiteralExpr::result );
     1354                }
     1355                maybe_accept( node, &CompoundLiteralExpr::init );
     1356        )
     1357
     1358        VISIT_END( Expr, node );
     1359}
     1360
     1361//--------------------------------------------------------------------------
     1362// RangeExpr
     1363template< typename pass_t >
     1364const ast::Expr * ast::Pass< pass_t >::visit( const ast::RangeExpr * node ) {
     1365        VISIT_START( node );
     1366
     1367        VISIT({
     1368                        guard_indexer guard { *this };
     1369                        maybe_accept( node, &RangeExpr::result );
     1370                }
     1371                maybe_accept( node, &RangeExpr::low    );
     1372                maybe_accept( node, &RangeExpr::high   );
     1373        )
     1374
     1375        VISIT_END( Expr, node );
     1376}
     1377
     1378//--------------------------------------------------------------------------
     1379// UntypedTupleExpr
     1380template< typename pass_t >
     1381const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedTupleExpr * node ) {
     1382        VISIT_START( node );
     1383
     1384        VISIT({
     1385                        guard_indexer guard { *this };
     1386                        maybe_accept( node, &UntypedTupleExpr::result );
     1387                }
     1388                maybe_accept( node, &UntypedTupleExpr::exprs  );
     1389        )
     1390
     1391        VISIT_END( Expr, node );
     1392}
     1393
     1394//--------------------------------------------------------------------------
     1395// TupleExpr
     1396template< typename pass_t >
     1397const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleExpr * node ) {
     1398        VISIT_START( node );
     1399
     1400        VISIT({
     1401                        guard_indexer guard { *this };
     1402                        maybe_accept( node, &TupleExpr::result );
     1403                }
     1404                maybe_accept( node, &TupleExpr::exprs  );
     1405        )
     1406
     1407        VISIT_END( Expr, node );
     1408}
     1409
     1410//--------------------------------------------------------------------------
     1411// TupleIndexExpr
     1412template< typename pass_t >
     1413const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleIndexExpr * node ) {
     1414        VISIT_START( node );
     1415
     1416        VISIT({
     1417                        guard_indexer guard { *this };
     1418                        maybe_accept( node, &TupleIndexExpr::result );
     1419                }
     1420                maybe_accept( node, &TupleIndexExpr::tuple  );
     1421        )
     1422
     1423        VISIT_END( Expr, node );
     1424}
     1425
     1426//--------------------------------------------------------------------------
     1427// TupleAssignExpr
     1428template< typename pass_t >
     1429const ast::Expr * ast::Pass< pass_t >::visit( const ast::TupleAssignExpr * node ) {
     1430        VISIT_START( node );
     1431
     1432        VISIT({
     1433                        guard_indexer guard { *this };
     1434                        maybe_accept( node, &TupleAssignExpr::result );
     1435                }
     1436                maybe_accept( node, &TupleAssignExpr::stmtExpr );
     1437        )
     1438
     1439        VISIT_END( Expr, node );
     1440}
     1441
     1442//--------------------------------------------------------------------------
     1443// StmtExpr
     1444template< typename pass_t >
     1445const ast::Expr * ast::Pass< pass_t >::visit( const ast::StmtExpr * node ) {
     1446        VISIT_START( node );
     1447
     1448        VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr
     1449                // get the stmts that will need to be spliced in
     1450                auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
     1451                auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
     1452
     1453                // These may be modified by subnode but most be restored once we exit this statemnet.
     1454                ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::env( pass, 0) );
     1455                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
     1456                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     1457
     1458                {
     1459                        guard_indexer guard { *this };
     1460                        maybe_accept( node, &StmtExpr::result );
     1461                }
     1462                maybe_accept( node, &StmtExpr::stmts       );
     1463                maybe_accept( node, &StmtExpr::returnDecls );
     1464                maybe_accept( node, &StmtExpr::dtors       );
     1465        )
     1466
     1467        VISIT_END( Expr, node );
     1468}
     1469
     1470//--------------------------------------------------------------------------
     1471// UniqueExpr
     1472template< typename pass_t >
     1473const ast::Expr * ast::Pass< pass_t >::visit( const ast::UniqueExpr * node ) {
     1474        VISIT_START( node );
     1475
     1476        VISIT({
     1477                        guard_indexer guard { *this };
     1478                        maybe_accept( node, &UniqueExpr::result );
     1479                }
     1480                maybe_accept( node, &UniqueExpr::expr   );
     1481        )
     1482
     1483        VISIT_END( Expr, node );
     1484}
     1485
     1486//--------------------------------------------------------------------------
     1487// UntypedInitExpr
     1488template< typename pass_t >
     1489const ast::Expr * ast::Pass< pass_t >::visit( const ast::UntypedInitExpr * node ) {
     1490        VISIT_START( node );
     1491
     1492        VISIT({
     1493                        guard_indexer guard { *this };
     1494                        maybe_accept( node, &UntypedInitExpr::result );
     1495                }
     1496                maybe_accept( node, &UntypedInitExpr::expr   );
     1497                // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver.
     1498        )
     1499
     1500        VISIT_END( Expr, node );
     1501}
     1502
     1503//--------------------------------------------------------------------------
     1504// InitExpr
     1505template< typename pass_t >
     1506const ast::Expr * ast::Pass< pass_t >::visit( const ast::InitExpr * node ) {
     1507        VISIT_START( node );
     1508
     1509        VISIT({
     1510                        guard_indexer guard { *this };
     1511                        maybe_accept( node, &InitExpr::result );
     1512                }
     1513                maybe_accept( node, &InitExpr::expr   );
     1514                maybe_accept( node, &InitExpr::designation );
     1515        )
     1516
     1517        VISIT_END( Expr, node );
     1518}
     1519
     1520//--------------------------------------------------------------------------
     1521// DeletedExpr
     1522template< typename pass_t >
     1523const ast::Expr * ast::Pass< pass_t >::visit( const ast::DeletedExpr * node ) {
     1524        VISIT_START( node );
     1525
     1526        VISIT({
     1527                        guard_indexer guard { *this };
     1528                        maybe_accept( node, &DeletedExpr::result );
     1529                }
     1530                maybe_accept( node, &DeletedExpr::expr );
     1531                // don't visit deleteStmt, because it is a pointer to somewhere else in the tree.
     1532        )
     1533
     1534        VISIT_END( Expr, node );
     1535}
     1536
     1537//--------------------------------------------------------------------------
     1538// DefaultArgExpr
     1539template< typename pass_t >
     1540const ast::Expr * ast::Pass< pass_t >::visit( const ast::DefaultArgExpr * node ) {
     1541        VISIT_START( node );
     1542
     1543        VISIT({
     1544                        guard_indexer guard { *this };
     1545                        maybe_accept( node, &DefaultArgExpr::result );
     1546                }
     1547                maybe_accept( node, &DefaultArgExpr::expr );
     1548        )
     1549
     1550        VISIT_END( Expr, node );
     1551}
     1552
     1553//--------------------------------------------------------------------------
     1554// GenericExpr
     1555template< typename pass_t >
     1556const ast::Expr * ast::Pass< pass_t >::visit( const ast::GenericExpr * node ) {
     1557        VISIT_START( node );
     1558
     1559        VISIT({
     1560                        guard_indexer guard { *this };
     1561                        maybe_accept( node, &GenericExpr::result );
     1562                }
     1563                maybe_accept( node, &GenericExpr::control );
     1564
     1565                std::vector<GenericExpr::Association> new_kids;
     1566                new_kids.reserve(node->associations.size());
     1567                bool mutated = false;
     1568                for( const auto & assoc : node->associations ) {
     1569                        Type * type = nullptr;
     1570                        if( assoc.type ) {
     1571                                guard_indexer guard { *this };
     1572                                type = assoc.type->accept( *this );
     1573                                if( type != assoc.type ) mutated = true;
     1574                        }
     1575                        Expr * expr = nullptr;
     1576                        if( assoc.expr ) {
     1577                                expr = assoc.expr->accept( *this );
     1578                                if( expr != assoc.expr ) mutated = true;
     1579                        }
     1580                        new_kids.emplace_back( type, expr );
     1581                }
     1582
     1583                if(mutated) {
     1584                        auto n = mutate(node);
     1585                        n->associations = std::move( new_kids );
     1586                        node = n;
     1587                }
     1588        )
     1589
     1590        VISIT_END( Expr, node );
     1591}
     1592
     1593//--------------------------------------------------------------------------
     1594// VoidType
     1595template< typename pass_t >
     1596const ast::Type * ast::Pass< pass_t >::visit( const ast::VoidType * node ) {
     1597        VISIT_START( node );
     1598
     1599        VISIT_END( Type, node );
     1600}
     1601
     1602//--------------------------------------------------------------------------
     1603// BasicType
     1604template< typename pass_t >
     1605const ast::Type * ast::Pass< pass_t >::visit( const ast::BasicType * node ) {
     1606        VISIT_START( node );
     1607
     1608        VISIT_END( Type, node );
     1609}
     1610
     1611//--------------------------------------------------------------------------
     1612// PointerType
     1613template< typename pass_t >
     1614const ast::Type * ast::Pass< pass_t >::visit( const ast::PointerType * node ) {
     1615        VISIT_START( node );
     1616
     1617        VISIT(
     1618                // xxx - should PointerType visit/mutate dimension?
     1619                maybe_accept( node, &PointerType::base );
     1620        )
     1621
     1622        VISIT_END( Type, node );
     1623}
     1624
     1625//--------------------------------------------------------------------------
     1626// ArrayType
     1627template< typename pass_t >
     1628const ast::Type * ast::Pass< pass_t >::visit( const ast::ArrayType * node ) {
     1629        VISIT_START( node );
     1630
     1631        VISIT(
     1632                maybe_accept( node, &ArrayType::dimension );
     1633                maybe_accept( node, &ArrayType::base );
     1634        )
     1635
     1636        VISIT_END( Type, node );
     1637}
     1638
     1639//--------------------------------------------------------------------------
     1640// ReferenceType
     1641template< typename pass_t >
     1642const ast::Type * ast::Pass< pass_t >::visit( const ast::ReferenceType * node ) {
     1643        VISIT_START( node );
     1644
     1645        VISIT(
     1646                maybe_accept( node, &ReferenceType::base );
     1647        )
     1648
     1649        VISIT_END( Type, node );
     1650}
     1651
     1652//--------------------------------------------------------------------------
     1653// QualifiedType
     1654template< typename pass_t >
     1655const ast::Type * ast::Pass< pass_t >::visit( const ast::QualifiedType * node ) {
     1656        VISIT_START( node );
     1657
     1658        VISIT(
     1659                maybe_accept( node, &QualifiedType::parent );
     1660                maybe_accept( node, &QualifiedType::child );
     1661        )
     1662
     1663        VISIT_END( Type, node );
     1664}
     1665
     1666//--------------------------------------------------------------------------
     1667// FunctionType
     1668template< typename pass_t >
     1669const ast::Type * ast::Pass< pass_t >::visit( const ast::FunctionType * node ) {
     1670        VISIT_START( node );
     1671
     1672        VISIT(
     1673                maybe_accept( node, &FunctionType::forall  );
     1674                maybe_accept( node, &FunctionType::returns );
     1675                maybe_accept( node, &FunctionType::params  );
     1676        )
     1677
     1678        VISIT_END( Type, node );
     1679}
     1680
     1681//--------------------------------------------------------------------------
     1682// StructInstType
     1683template< typename pass_t >
     1684const ast::Type * ast::Pass< pass_t >::visit( const ast::StructInstType * node ) {
     1685        VISIT_START( node );
     1686
     1687        __pass::indexer::addStruct( node->name, 0, pass );
     1688
     1689        VISIT({
     1690                guard_indexer guard { *this };
     1691                maybe_accept( node, &StructInstType::forall );
     1692                maybe_accept( node, &StructInstType::params );
     1693        })
     1694
     1695        VISIT_END( Type, node );
     1696}
     1697
     1698//--------------------------------------------------------------------------
     1699// UnionInstType
     1700template< typename pass_t >
     1701const ast::Type * ast::Pass< pass_t >::visit( const ast::UnionInstType * node ) {
     1702        VISIT_START( node );
     1703
     1704        __pass::indexer::addStruct( node->name, 0, pass );
     1705
     1706        {
     1707                guard_indexer guard { *this };
     1708                maybe_accept( node, &UnionInstType::forall );
     1709                maybe_accept( node, &UnionInstType::params );
     1710        }
     1711
     1712        VISIT_END( Type, node );
     1713}
     1714
     1715//--------------------------------------------------------------------------
     1716// EnumInstType
     1717template< typename pass_t >
     1718const ast::Type * ast::Pass< pass_t >::visit( const ast::EnumInstType * node ) {
     1719        VISIT_START( node );
     1720
     1721        VISIT(
     1722                maybe_accept( node, &EnumInstType::forall );
     1723                maybe_accept( node, &EnumInstType::params );
     1724        )
     1725
     1726        VISIT_END( Type, node );
     1727}
     1728
     1729//--------------------------------------------------------------------------
     1730// TraitInstType
     1731template< typename pass_t >
     1732const ast::Type * ast::Pass< pass_t >::visit( const ast::TraitInstType * node ) {
     1733        VISIT_START( node );
     1734
     1735        VISIT(
     1736                maybe_accept( node, &TraitInstType::forall );
     1737                maybe_accept( node, &TraitInstType::params );
     1738        )
     1739
     1740        VISIT_END( Type, node );
     1741}
     1742
     1743//--------------------------------------------------------------------------
     1744// TypeInstType
     1745template< typename pass_t >
     1746const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeInstType * node ) {
     1747        VISIT_START( node );
     1748
     1749        VISIT(
     1750                maybe_accept( node, &TypeInstType::forall );
     1751                maybe_accept( node, &TypeInstType::params );
     1752        )
     1753
     1754        VISIT_END( Type, node );
     1755}
     1756
     1757//--------------------------------------------------------------------------
     1758// TupleType
     1759template< typename pass_t >
     1760const ast::Type * ast::Pass< pass_t >::visit( const ast::TupleType * node ) {
     1761        VISIT_START( node );
     1762
     1763        VISIT(
     1764                maybe_accept( node, &TupleType::types );
     1765                maybe_accept( node, &TupleType::members );
     1766        )
     1767
     1768        VISIT_END( Type, node );
     1769}
     1770
     1771//--------------------------------------------------------------------------
     1772// TypeofType
     1773template< typename pass_t >
     1774const ast::Type * ast::Pass< pass_t >::visit( const ast::TypeofType * node ) {
     1775        VISIT_START( node );
     1776
     1777        VISIT(
     1778                maybe_accept( node, &TypeofType::expr );
     1779        )
     1780
     1781        VISIT_END( Type, node );
     1782}
     1783
     1784//--------------------------------------------------------------------------
     1785// VarArgsType
     1786template< typename pass_t >
     1787const ast::Type * ast::Pass< pass_t >::visit( const ast::VarArgsType * node ) {
     1788        VISIT_START( node );
     1789
     1790        VISIT_END( Type, node );
     1791}
     1792
     1793//--------------------------------------------------------------------------
     1794// ZeroType
     1795template< typename pass_t >
     1796const ast::Type * ast::Pass< pass_t >::visit( const ast::ZeroType * node ) {
     1797        VISIT_START( node );
     1798
     1799        VISIT_END( Type, node );
     1800}
     1801
     1802//--------------------------------------------------------------------------
     1803// OneType
     1804template< typename pass_t >
     1805const ast::Type * ast::Pass< pass_t >::visit( const ast::OneType * node ) {
     1806        VISIT_START( node );
     1807
     1808        VISIT_END( Type, node );
     1809}
     1810
     1811//--------------------------------------------------------------------------
     1812// GlobalScopeType
     1813template< typename pass_t >
     1814const ast::Type * ast::Pass< pass_t >::visit( const ast::GlobalScopeType * node ) {
     1815        VISIT_START( node );
     1816
     1817        VISIT_END( Type, node );
     1818}
     1819
     1820
     1821//--------------------------------------------------------------------------
     1822// Designation
     1823template< typename pass_t >
     1824const ast::Designation * ast::Pass< pass_t >::visit( const ast::Designation * node ) {
     1825        VISIT_START( node );
     1826
     1827        VISIT( maybe_accept( node, &Designation::designators ); )
     1828
     1829        VISIT_END( Designation, node );
     1830}
    9161831
    9171832//--------------------------------------------------------------------------
     
    9701885}
    9711886
    972 //--------------------------------------------------------------------------
    973 // TypeSubstitution
    974 template< typename pass_t >
    975 const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {
    976         VISIT_START( node );
    977 
    978         VISIT(
    979                 {
    980                         bool mutated = false;
    981                         std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
    982                         for ( const auto & p : node->typeEnv ) {
    983                                 guard_indexer guard { *this };
    984                                 auto new_node = p.second->accept( *this );
    985                                 if (new_node != p.second) mutated = false;
    986                                 new_map.insert({ p.first, new_node });
    987                         }
    988                         if (mutated) {
    989                                 auto new_node = mutate( node );
    990                                 new_node->typeEnv.swap( new_map );
    991                                 node = new_node;
    992                         }
    993                 }
    994 
    995                 {
    996                         bool mutated = false;
    997                         std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
    998                         for ( const auto & p : node->varEnv ) {
    999                                 guard_indexer guard { *this };
    1000                                 auto new_node = p.second->accept( *this );
    1001                                 if (new_node != p.second) mutated = false;
    1002                                 new_map.insert({ p.first, new_node });
    1003                         }
    1004                         if (mutated) {
    1005                                 auto new_node = mutate( node );
    1006                                 new_node->varEnv.swap( new_map );
    1007                                 node = new_node;
    1008                         }
    1009                 }
    1010         )
    1011 
    1012         VISIT_END( TypeSubstitution, node );
    1013 }
     1887// //--------------------------------------------------------------------------
     1888// // TypeSubstitution
     1889// template< typename pass_t >
     1890// const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {
     1891//      VISIT_START( node );
     1892
     1893//      VISIT(
     1894//              {
     1895//                      bool mutated = false;
     1896//                      std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
     1897//                      for ( const auto & p : node->typeEnv ) {
     1898//                              guard_indexer guard { *this };
     1899//                              auto new_node = p.second->accept( *this );
     1900//                              if (new_node != p.second) mutated = false;
     1901//                              new_map.insert({ p.first, new_node });
     1902//                      }
     1903//                      if (mutated) {
     1904//                              auto new_node = mutate( node );
     1905//                              new_node->typeEnv.swap( new_map );
     1906//                              node = new_node;
     1907//                      }
     1908//              }
     1909
     1910//              {
     1911//                      bool mutated = false;
     1912//                      std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
     1913//                      for ( const auto & p : node->varEnv ) {
     1914//                              guard_indexer guard { *this };
     1915//                              auto new_node = p.second->accept( *this );
     1916//                              if (new_node != p.second) mutated = false;
     1917//                              new_map.insert({ p.first, new_node });
     1918//                      }
     1919//                      if (mutated) {
     1920//                              auto new_node = mutate( node );
     1921//                              new_node->varEnv.swap( new_map );
     1922//                              node = new_node;
     1923//                      }
     1924//              }
     1925//      )
     1926
     1927//      VISIT_END( TypeSubstitution, node );
     1928// }
    10141929
    10151930#undef VISIT_START
Note: See TracChangeset for help on using the changeset viewer.