Changes in / [6065b3aa:49c9773]
- Files:
-
- 8 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified doc/working/exception/impl/except.c ¶
r6065b3aa r49c9773 97 97 //is way more expansive than we might like 98 98 //The information we have is : 99 // - The GR (???) 99 // - The GR (Series of registers) 100 // GR1=GP Global Pointer of frame ref by context 100 101 // - The instruction pointer 101 102 // - The instruction pointer info (???) 102 // - The CFA ( ???)103 // - The CFA (Canonical Frame Address) 103 104 // - The BSP (Probably the base stack pointer) 104 105 -
TabularUnified doc/working/exception/impl/main.c ¶
r6065b3aa r49c9773 33 33 //libcfa but there is one problem left, see the exception table 34 34 //for details 35 __attribute__((noinline)) 35 36 void try( void (*try_block)(), void (*catch_block)() ) 36 37 { … … 129 130 raii_t a = { "Main dtor" }; 130 131 131 fo o();132 for (unsigned int i = 0 ; i < 100000000 ; ++i) foo(); 132 133 133 134 printf("End of program reached\n"); -
TabularUnified src/Common/PassVisitor.h ¶
r6065b3aa r49c9773 1 1 #pragma once 2 2 3 #include <stack> 4 5 #include "SynTree/Mutator.h" 3 6 #include "SynTree/Visitor.h" 4 7 5 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 6 //Deep magic (a.k.a template meta programming) to make the templated visitor work 7 //Basically the goal is to make 2 previsit_impl 8 // 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of 9 // 'pass.previsit( node )' that compiles will be used for that node for that type 10 // This requires that this option only compile for passes that actually define an appropriate visit. 11 // SFINAE will make sure the compilation errors in this function don't halt the build. 12 // See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE 13 // 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing. 14 // This is needed only to eliminate the need for passes to specify any kind of handlers. 15 // The second implementation only works because it has a lower priority. This is due to the bogus last parameter. 16 // The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0 17 // the first implementation takes priority in regards to overloading. 18 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 19 template<typename pass_type, typename node_type> 20 static inline auto previsit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.previsit( node ), void() ) { 21 pass.previsit( node ); 22 } 23 24 template<typename pass_type, typename node_type> 25 static inline void previsit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) { 26 //Do nothing 27 } 28 29 30 template<typename pass_type, typename node_type> 31 static inline auto postvisit_impl( pass_type& pass, node_type * node, __attribute__((unused)) int unused ) ->decltype( pass.postvisit( node ), void() ) { 32 pass.postvisit( node ); 33 } 34 35 template<typename pass_type, typename node_type> 36 static inline auto postvisit_impl( __attribute__((unused)) pass_type& pass, node_type * node, __attribute__((unused)) long unused ) { 37 //Do nothing 38 } 8 #include "SynTree/Initializer.h" 9 #include "SynTree/Statement.h" 10 #include "SynTree/Type.h" 11 #include "SynTree/Declaration.h" 12 #include "SynTree/Expression.h" 13 #include "SynTree/Constant.h" 14 15 #include "PassVisitor.proto.h" 39 16 40 17 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- … … 44 21 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 45 22 template< typename pass_type > 46 class PassVisitor final : public Visitor {23 class PassVisitor final : public Visitor, public Mutator { 47 24 public: 48 25 PassVisitor() = default; 49 26 50 27 template< typename... Args > 51 PassVisitor(Args &&... args) 28 PassVisitor(Args &&... args) 52 29 : pass( std::forward<Args>( args )... ) 53 30 {} 54 31 55 32 virtual ~PassVisitor() = default; 56 private: 33 57 34 pass_type pass; 58 59 public:60 35 61 36 virtual void visit( ObjectDecl *objectDecl ) override final; … … 145 120 virtual void visit( Constant *constant ) override final; 146 121 122 virtual DeclarationWithType* mutate( ObjectDecl *objectDecl ) override final; 123 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ) override final; 124 virtual Declaration* mutate( StructDecl *aggregateDecl ) override final; 125 virtual Declaration* mutate( UnionDecl *aggregateDecl ) override final; 126 virtual Declaration* mutate( EnumDecl *aggregateDecl ) override final; 127 virtual Declaration* mutate( TraitDecl *aggregateDecl ) override final; 128 virtual TypeDecl* mutate( TypeDecl *typeDecl ) override final; 129 virtual Declaration* mutate( TypedefDecl *typeDecl ) override final; 130 virtual AsmDecl* mutate( AsmDecl *asmDecl ) override final; 131 132 virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ) override final; 133 virtual Statement* mutate( ExprStmt *exprStmt ) override final; 134 virtual Statement* mutate( AsmStmt *asmStmt ) override final; 135 virtual Statement* mutate( IfStmt *ifStmt ) override final; 136 virtual Statement* mutate( WhileStmt *whileStmt ) override final; 137 virtual Statement* mutate( ForStmt *forStmt ) override final; 138 virtual Statement* mutate( SwitchStmt *switchStmt ) override final; 139 virtual Statement* mutate( CaseStmt *caseStmt ) override final; 140 virtual Statement* mutate( BranchStmt *branchStmt ) override final; 141 virtual Statement* mutate( ReturnStmt *returnStmt ) override final; 142 virtual Statement* mutate( TryStmt *returnStmt ) override final; 143 virtual Statement* mutate( CatchStmt *catchStmt ) override final; 144 virtual Statement* mutate( FinallyStmt *catchStmt ) override final; 145 virtual NullStmt* mutate( NullStmt *nullStmt ) override final; 146 virtual Statement* mutate( DeclStmt *declStmt ) override final; 147 virtual Statement* mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) override final; 148 149 virtual Expression* mutate( ApplicationExpr *applicationExpr ) override final; 150 virtual Expression* mutate( UntypedExpr *untypedExpr ) override final; 151 virtual Expression* mutate( NameExpr *nameExpr ) override final; 152 virtual Expression* mutate( AddressExpr *castExpr ) override final; 153 virtual Expression* mutate( LabelAddressExpr *labAddressExpr ) override final; 154 virtual Expression* mutate( CastExpr *castExpr ) override final; 155 virtual Expression* mutate( UntypedMemberExpr *memberExpr ) override final; 156 virtual Expression* mutate( MemberExpr *memberExpr ) override final; 157 virtual Expression* mutate( VariableExpr *variableExpr ) override final; 158 virtual Expression* mutate( ConstantExpr *constantExpr ) override final; 159 virtual Expression* mutate( SizeofExpr *sizeofExpr ) override final; 160 virtual Expression* mutate( AlignofExpr *alignofExpr ) override final; 161 virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr ) override final; 162 virtual Expression* mutate( OffsetofExpr *offsetofExpr ) override final; 163 virtual Expression* mutate( OffsetPackExpr *offsetPackExpr ) override final; 164 virtual Expression* mutate( AttrExpr *attrExpr ) override final; 165 virtual Expression* mutate( LogicalExpr *logicalExpr ) override final; 166 virtual Expression* mutate( ConditionalExpr *conditionalExpr ) override final; 167 virtual Expression* mutate( CommaExpr *commaExpr ) override final; 168 virtual Expression* mutate( TypeExpr *typeExpr ) override final; 169 virtual Expression* mutate( AsmExpr *asmExpr ) override final; 170 virtual Expression* mutate( ImplicitCopyCtorExpr *impCpCtorExpr ) override final; 171 virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final; 172 virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final; 173 virtual Expression* mutate( UntypedValofExpr *valofExpr ) override final; 174 virtual Expression* mutate( RangeExpr *rangeExpr ) override final; 175 virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final; 176 virtual Expression* mutate( TupleExpr *tupleExpr ) override final; 177 virtual Expression* mutate( TupleIndexExpr *tupleExpr ) override final; 178 virtual Expression* mutate( MemberTupleExpr *tupleExpr ) override final; 179 virtual Expression* mutate( TupleAssignExpr *assignExpr ) override final; 180 virtual Expression* mutate( StmtExpr * stmtExpr ) override final; 181 virtual Expression* mutate( UniqueExpr * uniqueExpr ) override final; 182 183 virtual Type* mutate( VoidType *basicType ) override final; 184 virtual Type* mutate( BasicType *basicType ) override final; 185 virtual Type* mutate( PointerType *pointerType ) override final; 186 virtual Type* mutate( ArrayType *arrayType ) override final; 187 virtual Type* mutate( FunctionType *functionType ) override final; 188 virtual Type* mutate( StructInstType *aggregateUseType ) override final; 189 virtual Type* mutate( UnionInstType *aggregateUseType ) override final; 190 virtual Type* mutate( EnumInstType *aggregateUseType ) override final; 191 virtual Type* mutate( TraitInstType *aggregateUseType ) override final; 192 virtual Type* mutate( TypeInstType *aggregateUseType ) override final; 193 virtual Type* mutate( TupleType *tupleType ) override final; 194 virtual Type* mutate( TypeofType *typeofType ) override final; 195 virtual Type* mutate( AttrType *attrType ) override final; 196 virtual Type* mutate( VarArgsType *varArgsType ) override final; 197 virtual Type* mutate( ZeroType *zeroType ) override final; 198 virtual Type* mutate( OneType *oneType ) override final; 199 200 virtual Initializer* mutate( SingleInit *singleInit ) override final; 201 virtual Initializer* mutate( ListInit *listInit ) override final; 202 virtual Initializer* mutate( ConstructorInit *ctorInit ) override final; 203 204 virtual Subrange *mutate( Subrange *subrange ) override final; 205 206 virtual Constant *mutate( Constant *constant ) override final; 207 147 208 private: 148 template<typename node_type> 149 auto call_previsit ( node_type * node ) 150 -> decltype( previsit_impl ( pass, node, 0 ), void() ) 151 { 152 previsit_impl ( pass, node, 0 ); 153 } 154 155 template<typename node_type> 156 auto call_postvisit( node_type * node ) 157 -> decltype( postvisit_impl( pass, node, 0 ), void() ) 158 { 159 postvisit_impl( pass, node, 0 ); 160 } 209 template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } 210 template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } 211 212 template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); } 213 template<typename return_type, typename node_type> return_type call_postmutate ( node_type * node ) { return postmutate_impl<return_type>( pass, node, 0 ); } 214 215 void call_beginScope() { begin_scope_impl( pass, 0 ); } 216 void call_endScope () { end_scope_impl ( pass, 0 ); } 217 218 void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } 219 220 void visitStatementList( std::list< Statement* > &statements ); 221 void mutateStatementList( std::list< Statement* > &statements ); 222 223 Statement * visitStatement( Statement * stmt ); 224 Statement * mutateStatement( Statement * stmt ); 225 226 void visitExpression( Expression * expr ); 227 Expression * mutateExpression( Expression * expr ); 228 229 230 TypeSubstitution ** get_env_ptr () { return env_impl ( pass, 0); } 231 std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } 232 std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } 161 233 }; 162 234 -
TabularUnified src/Common/PassVisitor.impl.h ¶
r6065b3aa r49c9773 1 1 #pragma once 2 3 #define MUTATE_START( node ) \ 4 call_premutate( node ); \ 5 6 7 #define MUTATE_END( type, node ) \ 8 return call_postmutate< type * >( node ); \ 9 2 10 3 11 #define VISIT_BODY( node ) \ … … 7 15 8 16 9 template< typename pass_type > 10 void PassVisitor< pass_type>::visit( ObjectDecl * node ) { 11 VISIT_BODY( node ); 12 } 13 14 template< typename pass_type > 15 void PassVisitor< pass_type>::visit( FunctionDecl * node ) { 16 VISIT_BODY( node ); 17 } 18 19 template< typename pass_type > 20 void PassVisitor< pass_type>::visit( StructDecl * node ) { 21 VISIT_BODY( node ); 22 } 23 24 template< typename pass_type > 25 void PassVisitor< pass_type>::visit( UnionDecl * node ) { 26 VISIT_BODY( node ); 27 } 28 29 template< typename pass_type > 30 void PassVisitor< pass_type>::visit( EnumDecl * node ) { 31 VISIT_BODY( node ); 32 } 33 34 template< typename pass_type > 35 void PassVisitor< pass_type>::visit( TraitDecl * node ) { 36 VISIT_BODY( node ); 37 } 38 39 template< typename pass_type > 40 void PassVisitor< pass_type>::visit( TypeDecl * node ) { 41 VISIT_BODY( node ); 42 } 43 44 template< typename pass_type > 45 void PassVisitor< pass_type>::visit( TypedefDecl * node ) { 46 VISIT_BODY( node ); 47 } 48 49 template< typename pass_type > 50 void PassVisitor< pass_type>::visit( AsmDecl * node ) { 51 VISIT_BODY( node ); 52 } 53 54 template< typename pass_type > 55 void PassVisitor< pass_type>::visit( CompoundStmt * node ) { 56 VISIT_BODY( node ); 57 } 58 59 template< typename pass_type > 60 void PassVisitor< pass_type>::visit( ExprStmt * node ) { 61 VISIT_BODY( node ); 62 } 63 64 template< typename pass_type > 65 void PassVisitor< pass_type>::visit( AsmStmt * node ) { 66 VISIT_BODY( node ); 67 } 68 69 template< typename pass_type > 70 void PassVisitor< pass_type>::visit( IfStmt * node ) { 71 VISIT_BODY( node ); 72 } 73 74 template< typename pass_type > 75 void PassVisitor< pass_type>::visit( WhileStmt * node ) { 76 VISIT_BODY( node ); 77 } 78 79 template< typename pass_type > 80 void PassVisitor< pass_type>::visit( ForStmt * node ) { 81 VISIT_BODY( node ); 82 } 83 84 template< typename pass_type > 85 void PassVisitor< pass_type>::visit( SwitchStmt * node ) { 86 VISIT_BODY( node ); 87 } 88 89 template< typename pass_type > 90 void PassVisitor< pass_type>::visit( CaseStmt * node ) { 91 VISIT_BODY( node ); 92 } 93 94 template< typename pass_type > 95 void PassVisitor< pass_type>::visit( BranchStmt * node ) { 96 VISIT_BODY( node ); 97 } 98 99 template< typename pass_type > 100 void PassVisitor< pass_type>::visit( ReturnStmt * node ) { 101 VISIT_BODY( node ); 102 } 103 104 template< typename pass_type > 105 void PassVisitor< pass_type>::visit( TryStmt * node ) { 106 VISIT_BODY( node ); 107 } 108 109 template< typename pass_type > 110 void PassVisitor< pass_type>::visit( CatchStmt * node ) { 111 VISIT_BODY( node ); 112 } 113 114 template< typename pass_type > 115 void PassVisitor< pass_type>::visit( FinallyStmt * node ) { 116 VISIT_BODY( node ); 117 } 118 119 template< typename pass_type > 120 void PassVisitor< pass_type>::visit( NullStmt * node ) { 121 VISIT_BODY( node ); 122 } 123 124 template< typename pass_type > 125 void PassVisitor< pass_type>::visit( DeclStmt * node ) { 126 VISIT_BODY( node ); 127 } 128 129 template< typename pass_type > 130 void PassVisitor< pass_type>::visit( ImplicitCtorDtorStmt * node ) { 131 VISIT_BODY( node ); 132 } 133 134 template< typename pass_type > 135 void PassVisitor< pass_type>::visit( ApplicationExpr * node ) { 136 VISIT_BODY( node ); 137 } 138 139 template< typename pass_type > 140 void PassVisitor< pass_type>::visit( UntypedExpr * node ) { 141 VISIT_BODY( node ); 142 } 143 144 template< typename pass_type > 145 void PassVisitor< pass_type>::visit( NameExpr * node ) { 146 VISIT_BODY( node ); 147 } 148 149 template< typename pass_type > 150 void PassVisitor< pass_type>::visit( CastExpr * node ) { 151 VISIT_BODY( node ); 152 } 153 154 template< typename pass_type > 155 void PassVisitor< pass_type>::visit( AddressExpr * node ) { 156 VISIT_BODY( node ); 157 } 158 159 template< typename pass_type > 160 void PassVisitor< pass_type>::visit( LabelAddressExpr * node ) { 161 VISIT_BODY( node ); 162 } 163 164 template< typename pass_type > 165 void PassVisitor< pass_type>::visit( UntypedMemberExpr * node ) { 166 VISIT_BODY( node ); 167 } 168 169 template< typename pass_type > 170 void PassVisitor< pass_type>::visit( MemberExpr * node ) { 171 VISIT_BODY( node ); 172 } 173 174 template< typename pass_type > 175 void PassVisitor< pass_type>::visit( VariableExpr * node ) { 176 VISIT_BODY( node ); 177 } 178 179 template< typename pass_type > 180 void PassVisitor< pass_type>::visit( ConstantExpr * node ) { 181 VISIT_BODY( node ); 182 } 183 184 template< typename pass_type > 185 void PassVisitor< pass_type>::visit( SizeofExpr * node ) { 186 VISIT_BODY( node ); 187 } 188 189 template< typename pass_type > 190 void PassVisitor< pass_type>::visit( AlignofExpr * node ) { 191 VISIT_BODY( node ); 192 } 193 194 template< typename pass_type > 195 void PassVisitor< pass_type>::visit( UntypedOffsetofExpr * node ) { 196 VISIT_BODY( node ); 197 } 198 199 template< typename pass_type > 200 void PassVisitor< pass_type>::visit( OffsetofExpr * node ) { 201 VISIT_BODY( node ); 202 } 203 204 template< typename pass_type > 205 void PassVisitor< pass_type>::visit( OffsetPackExpr * node ) { 206 VISIT_BODY( node ); 207 } 208 209 template< typename pass_type > 210 void PassVisitor< pass_type>::visit( AttrExpr * node ) { 211 VISIT_BODY( node ); 212 } 213 214 template< typename pass_type > 215 void PassVisitor< pass_type>::visit( LogicalExpr * node ) { 216 VISIT_BODY( node ); 217 } 218 219 template< typename pass_type > 220 void PassVisitor< pass_type>::visit( ConditionalExpr * node ) { 221 VISIT_BODY( node ); 222 } 223 224 template< typename pass_type > 225 void PassVisitor< pass_type>::visit( CommaExpr * node ) { 226 VISIT_BODY( node ); 227 } 228 229 template< typename pass_type > 230 void PassVisitor< pass_type>::visit( TypeExpr * node ) { 231 VISIT_BODY( node ); 232 } 233 234 template< typename pass_type > 235 void PassVisitor< pass_type>::visit( AsmExpr * node ) { 236 VISIT_BODY( node ); 237 } 238 239 template< typename pass_type > 240 void PassVisitor< pass_type>::visit( ImplicitCopyCtorExpr * node ) { 241 VISIT_BODY( node ); 242 } 243 244 template< typename pass_type > 245 void PassVisitor< pass_type>::visit( ConstructorExpr * node ) { 246 VISIT_BODY( node ); 247 } 248 249 template< typename pass_type > 250 void PassVisitor< pass_type>::visit( CompoundLiteralExpr * node ) { 251 VISIT_BODY( node ); 252 } 253 254 template< typename pass_type > 255 void PassVisitor< pass_type>::visit( UntypedValofExpr * node ) { 256 VISIT_BODY( node ); 257 } 258 259 template< typename pass_type > 260 void PassVisitor< pass_type>::visit( RangeExpr * node ) { 261 VISIT_BODY( node ); 262 } 263 264 template< typename pass_type > 265 void PassVisitor< pass_type>::visit( UntypedTupleExpr * node ) { 266 VISIT_BODY( node ); 267 } 268 269 template< typename pass_type > 270 void PassVisitor< pass_type>::visit( TupleExpr * node ) { 271 VISIT_BODY( node ); 272 } 273 274 template< typename pass_type > 275 void PassVisitor< pass_type>::visit( TupleIndexExpr * node ) { 276 VISIT_BODY( node ); 277 } 278 279 template< typename pass_type > 280 void PassVisitor< pass_type>::visit( MemberTupleExpr * node ) { 281 VISIT_BODY( node ); 282 } 283 284 template< typename pass_type > 285 void PassVisitor< pass_type>::visit( TupleAssignExpr * node ) { 286 VISIT_BODY( node ); 287 } 288 289 template< typename pass_type > 290 void PassVisitor< pass_type>::visit( StmtExpr * node ) { 291 VISIT_BODY( node ); 292 } 293 294 template< typename pass_type > 295 void PassVisitor< pass_type>::visit( UniqueExpr * node ) { 296 VISIT_BODY( node ); 297 } 298 299 template< typename pass_type > 300 void PassVisitor< pass_type>::visit( VoidType * node ) { 301 VISIT_BODY( node ); 302 } 303 304 template< typename pass_type > 305 void PassVisitor< pass_type>::visit( BasicType * node ) { 306 VISIT_BODY( node ); 307 } 308 309 template< typename pass_type > 310 void PassVisitor< pass_type>::visit( PointerType * node ) { 311 VISIT_BODY( node ); 312 } 313 314 template< typename pass_type > 315 void PassVisitor< pass_type>::visit( ArrayType * node ) { 316 VISIT_BODY( node ); 317 } 318 319 template< typename pass_type > 320 void PassVisitor< pass_type>::visit( FunctionType * node ) { 321 VISIT_BODY( node ); 322 } 323 324 template< typename pass_type > 325 void PassVisitor< pass_type>::visit( StructInstType * node ) { 326 VISIT_BODY( node ); 327 } 328 329 template< typename pass_type > 330 void PassVisitor< pass_type>::visit( UnionInstType * node ) { 331 VISIT_BODY( node ); 332 } 333 334 template< typename pass_type > 335 void PassVisitor< pass_type>::visit( EnumInstType * node ) { 336 VISIT_BODY( node ); 337 } 338 339 template< typename pass_type > 340 void PassVisitor< pass_type>::visit( TraitInstType * node ) { 341 VISIT_BODY( node ); 342 } 343 344 template< typename pass_type > 345 void PassVisitor< pass_type>::visit( TypeInstType * node ) { 346 VISIT_BODY( node ); 347 } 348 349 template< typename pass_type > 350 void PassVisitor< pass_type>::visit( TupleType * node ) { 351 VISIT_BODY( node ); 352 } 353 354 template< typename pass_type > 355 void PassVisitor< pass_type>::visit( TypeofType * node ) { 356 VISIT_BODY( node ); 357 } 358 359 template< typename pass_type > 360 void PassVisitor< pass_type>::visit( AttrType * node ) { 361 VISIT_BODY( node ); 362 } 363 364 template< typename pass_type > 365 void PassVisitor< pass_type>::visit( VarArgsType * node ) { 366 VISIT_BODY( node ); 367 } 368 369 template< typename pass_type > 370 void PassVisitor< pass_type>::visit( ZeroType * node ) { 371 VISIT_BODY( node ); 372 } 373 374 template< typename pass_type > 375 void PassVisitor< pass_type>::visit( OneType * node ) { 376 VISIT_BODY( node ); 377 } 378 379 template< typename pass_type > 380 void PassVisitor< pass_type>::visit( SingleInit * node ) { 381 VISIT_BODY( node ); 382 } 383 384 template< typename pass_type > 385 void PassVisitor< pass_type>::visit( ListInit * node ) { 386 VISIT_BODY( node ); 387 } 388 389 template< typename pass_type > 390 void PassVisitor< pass_type>::visit( ConstructorInit * node ) { 391 VISIT_BODY( node ); 392 } 393 394 template< typename pass_type > 395 void PassVisitor< pass_type>::visit( Subrange * node ) { 396 VISIT_BODY( node ); 397 } 398 399 template< typename pass_type > 400 void PassVisitor< pass_type>::visit( Constant * node ) { 401 VISIT_BODY( node ); 402 } 17 #define MUTATE_BODY( type, node ) \ 18 MUTATE_START( node ); \ 19 Mutator::mutate( node ); \ 20 MUTATE_END( type, node ); \ 21 22 23 24 template<typename T> 25 static inline bool empty( T * ptr ) { 26 return !ptr || ptr->empty(); 27 } 28 29 typedef std::list< Statement * > StmtList_t; 30 31 template< typename pass_type > 32 void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { 33 SemanticError errors; 34 35 StmtList_t* beforeStmts = get_beforeStmts(); 36 StmtList_t* afterStmts = get_afterStmts(); 37 38 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 39 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 40 try { 41 *i = (*i)->accept( *this ); 42 } catch ( SemanticError &e ) { 43 errors.append( e ); 44 } 45 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 46 } 47 48 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 49 if ( !errors.isEmpty() ) { throw errors; } 50 } 51 52 template< typename pass_type > 53 void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { 54 SemanticError errors; 55 56 StmtList_t* beforeStmts = get_beforeStmts(); 57 StmtList_t* afterStmts = get_afterStmts(); 58 59 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { 60 if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } 61 try { 62 *i = (*i)->acceptMutator( *this ); 63 } catch ( SemanticError &e ) { 64 errors.append( e ); 65 } 66 if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } 67 } 68 69 if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } 70 if ( !errors.isEmpty() ) { throw errors; } 71 } 72 73 template< typename pass_type > 74 Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { 75 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 76 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 77 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 78 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 79 80 Statement *newStmt = maybeVisit( stmt, *this ); 81 82 StmtList_t* beforeStmts = get_beforeStmts(); 83 StmtList_t* afterStmts = get_afterStmts(); 84 85 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 86 87 CompoundStmt *compound = new CompoundStmt( noLabels ); 88 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 89 compound->get_kids().push_back( newStmt ); 90 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 91 return compound; 92 } 93 94 template< typename pass_type > 95 Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { 96 // don't want statements from outer CompoundStmts to be added to this CompoundStmt 97 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 98 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 99 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 100 101 Statement *newStmt = maybeMutate( stmt, *this ); 102 103 StmtList_t* beforeStmts = get_beforeStmts(); 104 StmtList_t* afterStmts = get_afterStmts(); 105 106 if( empty(beforeStmts) && empty(afterStmts) ) { return newStmt; } 107 108 CompoundStmt *compound = new CompoundStmt( noLabels ); 109 if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } 110 compound->get_kids().push_back( newStmt ); 111 if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } 112 return compound; 113 } 114 115 116 117 template< typename pass_type > 118 void PassVisitor< pass_type >::visitExpression( Expression * expr ) { 119 if( !expr ) return; 120 121 auto env_ptr = get_env_ptr(); 122 if ( env_ptr && expr->get_env() ) { 123 *env_ptr = expr->get_env(); 124 } 125 // xxx - should env be cloned (or moved) onto the result of the mutate? 126 expr->accept( *this ); 127 } 128 129 template< typename pass_type > 130 Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { 131 if( !expr ) return nullptr; 132 133 auto env_ptr = get_env_ptr(); 134 if ( env_ptr && expr->get_env() ) { 135 *env_ptr = expr->get_env(); 136 } 137 // xxx - should env be cloned (or moved) onto the result of the mutate? 138 return expr->acceptMutator( *this ); 139 } 140 141 142 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 143 144 template< typename pass_type > 145 void PassVisitor< pass_type >::visit( ObjectDecl * node ) { 146 VISIT_BODY( node ); 147 } 148 149 template< typename pass_type > 150 void PassVisitor< pass_type >::visit( FunctionDecl * node ) { 151 VISIT_BODY( node ); 152 } 153 154 template< typename pass_type > 155 void PassVisitor< pass_type >::visit( StructDecl * node ) { 156 VISIT_BODY( node ); 157 } 158 159 template< typename pass_type > 160 void PassVisitor< pass_type >::visit( UnionDecl * node ) { 161 VISIT_BODY( node ); 162 } 163 164 template< typename pass_type > 165 void PassVisitor< pass_type >::visit( EnumDecl * node ) { 166 VISIT_BODY( node ); 167 } 168 169 template< typename pass_type > 170 void PassVisitor< pass_type >::visit( TraitDecl * node ) { 171 VISIT_BODY( node ); 172 } 173 174 template< typename pass_type > 175 void PassVisitor< pass_type >::visit( TypeDecl * node ) { 176 VISIT_BODY( node ); 177 } 178 179 template< typename pass_type > 180 void PassVisitor< pass_type >::visit( TypedefDecl * node ) { 181 VISIT_BODY( node ); 182 } 183 184 template< typename pass_type > 185 void PassVisitor< pass_type >::visit( AsmDecl * node ) { 186 VISIT_BODY( node ); 187 } 188 189 template< typename pass_type > 190 void PassVisitor< pass_type >::visit( CompoundStmt * node ) { 191 VISIT_BODY( node ); 192 } 193 194 template< typename pass_type > 195 CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) { 196 MUTATE_START( node ); 197 call_beginScope(); 198 199 mutateStatementList( node->get_kids() ); 200 201 call_endScope(); 202 MUTATE_END( CompoundStmt, node ); 203 } 204 205 template< typename pass_type > 206 void PassVisitor< pass_type >::visit( ExprStmt * node ) { 207 VISIT_BODY( node ); 208 } 209 210 template< typename pass_type > 211 Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) { 212 MUTATE_START( node ); 213 214 node->set_expr( mutateExpression( node->get_expr() ) ); 215 216 MUTATE_END( Statement, node ); 217 } 218 219 template< typename pass_type > 220 void PassVisitor< pass_type >::visit( AsmStmt * node ) { 221 VISIT_BODY( node ); 222 } 223 224 template< typename pass_type > 225 void PassVisitor< pass_type >::visit( IfStmt * node ) { 226 VISIT_BODY( node ); 227 } 228 229 template< typename pass_type > 230 Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { 231 MUTATE_START( node ); 232 233 node->set_condition( mutateExpression( node->get_condition() ) ); 234 node->set_thenPart ( mutateStatement ( node->get_thenPart() ) ); 235 node->set_elsePart ( mutateStatement ( node->get_elsePart() ) ); 236 237 MUTATE_END( Statement, node ); 238 } 239 240 template< typename pass_type > 241 void PassVisitor< pass_type >::visit( WhileStmt * node ) { 242 VISIT_BODY( node ); 243 } 244 245 template< typename pass_type > 246 Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { 247 MUTATE_START( node ); 248 249 node->set_condition( mutateExpression( node->get_condition() ) ); 250 node->set_body( mutateStatement( node->get_body() ) ); 251 252 MUTATE_END( Statement, node ); 253 } 254 255 256 template< typename pass_type > 257 void PassVisitor< pass_type >::visit( ForStmt * node ) { 258 VISIT_BODY( node ); 259 } 260 261 template< typename pass_type > 262 Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { 263 MUTATE_START( node ); 264 265 mutateAll( node->get_initialization(), *this ); 266 node->set_condition( mutateExpression( node->get_condition() ) ); 267 node->set_increment( mutateExpression( node->get_increment() ) ); 268 node->set_body( mutateStatement( node->get_body() ) ); 269 270 MUTATE_END( Statement, node ); 271 } 272 273 template< typename pass_type > 274 void PassVisitor< pass_type >::visit( SwitchStmt * node ) { 275 VISIT_BODY( node ); 276 } 277 278 template< typename pass_type > 279 Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { 280 MUTATE_START( node ); 281 282 node->set_condition( mutateExpression( node->get_condition() ) ); 283 mutateStatementList( node->get_statements() ); 284 285 MUTATE_END( Statement, node ); 286 } 287 288 template< typename pass_type > 289 void PassVisitor< pass_type >::visit( CaseStmt * node ) { 290 VISIT_BODY( node ); 291 } 292 293 template< typename pass_type > 294 Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { 295 MUTATE_START( node ); 296 297 node->set_condition( mutateExpression( node->get_condition() ) ); 298 mutateStatementList( node->get_statements() ); 299 300 MUTATE_END( Statement, node ); 301 } 302 303 template< typename pass_type > 304 void PassVisitor< pass_type >::visit( BranchStmt * node ) { 305 VISIT_BODY( node ); 306 } 307 308 template< typename pass_type > 309 void PassVisitor< pass_type >::visit( ReturnStmt * node ) { 310 VISIT_BODY( node ); 311 } 312 313 template< typename pass_type > 314 Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) { 315 MUTATE_START( node ); 316 317 node->set_expr( mutateExpression( node->get_expr() ) ); 318 319 MUTATE_END( Statement, node ); 320 } 321 322 template< typename pass_type > 323 void PassVisitor< pass_type >::visit( TryStmt * node ) { 324 VISIT_BODY( node ); 325 } 326 327 template< typename pass_type > 328 Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) { 329 MUTATE_START( node ); 330 331 node->set_block( maybeMutate( node->get_block(), *this ) ); 332 mutateAll( node->get_catchers(), *this ); 333 334 MUTATE_END( Statement, node ); 335 } 336 337 template< typename pass_type > 338 void PassVisitor< pass_type >::visit( CatchStmt * node ) { 339 VISIT_BODY( node ); 340 } 341 342 template< typename pass_type > 343 Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { 344 MUTATE_START( node ); 345 346 node->set_body( mutateStatement( node->get_body() ) ); 347 node->set_decl( maybeMutate( node->get_decl(), *this ) ); 348 349 MUTATE_END( Statement, node ); 350 } 351 352 template< typename pass_type > 353 void PassVisitor< pass_type >::visit( FinallyStmt * node ) { 354 VISIT_BODY( node ); 355 } 356 357 template< typename pass_type > 358 void PassVisitor< pass_type >::visit( NullStmt * node ) { 359 VISIT_BODY( node ); 360 } 361 362 template< typename pass_type > 363 void PassVisitor< pass_type >::visit( DeclStmt * node ) { 364 VISIT_BODY( node ); 365 } 366 367 template< typename pass_type > 368 void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { 369 VISIT_BODY( node ); 370 } 371 372 template< typename pass_type > 373 void PassVisitor< pass_type >::visit( ApplicationExpr * node ) { 374 VISIT_BODY( node ); 375 } 376 377 template< typename pass_type > 378 void PassVisitor< pass_type >::visit( UntypedExpr * node ) { 379 VISIT_BODY( node ); 380 } 381 382 template< typename pass_type > 383 Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) { 384 MUTATE_START( node ); 385 386 for ( auto& expr : node->get_args() ) { 387 expr = mutateExpression( expr ); 388 } 389 390 MUTATE_END( Expression, node ); 391 } 392 393 template< typename pass_type > 394 void PassVisitor< pass_type >::visit( NameExpr * node ) { 395 VISIT_BODY( node ); 396 } 397 398 template< typename pass_type > 399 void PassVisitor< pass_type >::visit( CastExpr * node ) { 400 VISIT_BODY( node ); 401 } 402 403 template< typename pass_type > 404 void PassVisitor< pass_type >::visit( AddressExpr * node ) { 405 VISIT_BODY( node ); 406 } 407 408 template< typename pass_type > 409 void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) { 410 VISIT_BODY( node ); 411 } 412 413 template< typename pass_type > 414 void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { 415 VISIT_BODY( node ); 416 } 417 418 template< typename pass_type > 419 void PassVisitor< pass_type >::visit( MemberExpr * node ) { 420 VISIT_BODY( node ); 421 } 422 423 template< typename pass_type > 424 void PassVisitor< pass_type >::visit( VariableExpr * node ) { 425 VISIT_BODY( node ); 426 } 427 428 template< typename pass_type > 429 void PassVisitor< pass_type >::visit( ConstantExpr * node ) { 430 VISIT_BODY( node ); 431 } 432 433 template< typename pass_type > 434 void PassVisitor< pass_type >::visit( SizeofExpr * node ) { 435 VISIT_BODY( node ); 436 } 437 438 template< typename pass_type > 439 void PassVisitor< pass_type >::visit( AlignofExpr * node ) { 440 VISIT_BODY( node ); 441 } 442 443 template< typename pass_type > 444 void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) { 445 VISIT_BODY( node ); 446 } 447 448 template< typename pass_type > 449 void PassVisitor< pass_type >::visit( OffsetofExpr * node ) { 450 VISIT_BODY( node ); 451 } 452 453 template< typename pass_type > 454 void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) { 455 VISIT_BODY( node ); 456 } 457 458 template< typename pass_type > 459 void PassVisitor< pass_type >::visit( AttrExpr * node ) { 460 VISIT_BODY( node ); 461 } 462 463 template< typename pass_type > 464 void PassVisitor< pass_type >::visit( LogicalExpr * node ) { 465 VISIT_BODY( node ); 466 } 467 468 template< typename pass_type > 469 void PassVisitor< pass_type >::visit( ConditionalExpr * node ) { 470 VISIT_BODY( node ); 471 } 472 473 template< typename pass_type > 474 void PassVisitor< pass_type >::visit( CommaExpr * node ) { 475 VISIT_BODY( node ); 476 } 477 478 template< typename pass_type > 479 void PassVisitor< pass_type >::visit( TypeExpr * node ) { 480 VISIT_BODY( node ); 481 } 482 483 template< typename pass_type > 484 void PassVisitor< pass_type >::visit( AsmExpr * node ) { 485 VISIT_BODY( node ); 486 } 487 488 template< typename pass_type > 489 void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) { 490 VISIT_BODY( node ); 491 } 492 493 template< typename pass_type > 494 void PassVisitor< pass_type >::visit( ConstructorExpr * node ) { 495 VISIT_BODY( node ); 496 } 497 498 template< typename pass_type > 499 void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) { 500 VISIT_BODY( node ); 501 } 502 503 template< typename pass_type > 504 void PassVisitor< pass_type >::visit( UntypedValofExpr * node ) { 505 VISIT_BODY( node ); 506 } 507 508 template< typename pass_type > 509 void PassVisitor< pass_type >::visit( RangeExpr * node ) { 510 VISIT_BODY( node ); 511 } 512 513 template< typename pass_type > 514 void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) { 515 VISIT_BODY( node ); 516 } 517 518 template< typename pass_type > 519 void PassVisitor< pass_type >::visit( TupleExpr * node ) { 520 VISIT_BODY( node ); 521 } 522 523 template< typename pass_type > 524 void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) { 525 VISIT_BODY( node ); 526 } 527 528 template< typename pass_type > 529 void PassVisitor< pass_type >::visit( MemberTupleExpr * node ) { 530 VISIT_BODY( node ); 531 } 532 533 template< typename pass_type > 534 void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) { 535 VISIT_BODY( node ); 536 } 537 538 template< typename pass_type > 539 void PassVisitor< pass_type >::visit( StmtExpr * node ) { 540 VISIT_BODY( node ); 541 } 542 543 template< typename pass_type > 544 Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { 545 MUTATE_START( node ); 546 547 // don't want statements from outer CompoundStmts to be added to this StmtExpr 548 ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); 549 ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); 550 ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); 551 552 Mutator::mutate( node ); 553 554 MUTATE_END( Expression, node ); 555 } 556 557 template< typename pass_type > 558 void PassVisitor< pass_type >::visit( UniqueExpr * node ) { 559 VISIT_BODY( node ); 560 } 561 562 template< typename pass_type > 563 void PassVisitor< pass_type >::visit( VoidType * node ) { 564 VISIT_BODY( node ); 565 } 566 567 template< typename pass_type > 568 void PassVisitor< pass_type >::visit( BasicType * node ) { 569 VISIT_BODY( node ); 570 } 571 572 template< typename pass_type > 573 void PassVisitor< pass_type >::visit( PointerType * node ) { 574 VISIT_BODY( node ); 575 } 576 577 template< typename pass_type > 578 void PassVisitor< pass_type >::visit( ArrayType * node ) { 579 VISIT_BODY( node ); 580 } 581 582 template< typename pass_type > 583 void PassVisitor< pass_type >::visit( FunctionType * node ) { 584 VISIT_BODY( node ); 585 } 586 587 template< typename pass_type > 588 void PassVisitor< pass_type >::visit( StructInstType * node ) { 589 VISIT_BODY( node ); 590 } 591 592 template< typename pass_type > 593 void PassVisitor< pass_type >::visit( UnionInstType * node ) { 594 VISIT_BODY( node ); 595 } 596 597 template< typename pass_type > 598 void PassVisitor< pass_type >::visit( EnumInstType * node ) { 599 VISIT_BODY( node ); 600 } 601 602 template< typename pass_type > 603 void PassVisitor< pass_type >::visit( TraitInstType * node ) { 604 VISIT_BODY( node ); 605 } 606 607 template< typename pass_type > 608 void PassVisitor< pass_type >::visit( TypeInstType * node ) { 609 VISIT_BODY( node ); 610 } 611 612 template< typename pass_type > 613 void PassVisitor< pass_type >::visit( TupleType * node ) { 614 VISIT_BODY( node ); 615 } 616 617 template< typename pass_type > 618 void PassVisitor< pass_type >::visit( TypeofType * node ) { 619 VISIT_BODY( node ); 620 } 621 622 template< typename pass_type > 623 void PassVisitor< pass_type >::visit( AttrType * node ) { 624 VISIT_BODY( node ); 625 } 626 627 template< typename pass_type > 628 void PassVisitor< pass_type >::visit( VarArgsType * node ) { 629 VISIT_BODY( node ); 630 } 631 632 template< typename pass_type > 633 void PassVisitor< pass_type >::visit( ZeroType * node ) { 634 VISIT_BODY( node ); 635 } 636 637 template< typename pass_type > 638 void PassVisitor< pass_type >::visit( OneType * node ) { 639 VISIT_BODY( node ); 640 } 641 642 template< typename pass_type > 643 void PassVisitor< pass_type >::visit( SingleInit * node ) { 644 VISIT_BODY( node ); 645 } 646 647 template< typename pass_type > 648 Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) { 649 MUTATE_START( node ); 650 651 node->set_value( mutateExpression( node->get_value() ) ); 652 653 MUTATE_END( Initializer, node ); 654 } 655 656 template< typename pass_type > 657 void PassVisitor< pass_type >::visit( ListInit * node ) { 658 VISIT_BODY( node ); 659 } 660 661 template< typename pass_type > 662 void PassVisitor< pass_type >::visit( ConstructorInit * node ) { 663 VISIT_BODY( node ); 664 } 665 666 template< typename pass_type > 667 void PassVisitor< pass_type >::visit( Subrange * node ) { 668 VISIT_BODY( node ); 669 } 670 671 template< typename pass_type > 672 void PassVisitor< pass_type >::visit( Constant * node ) { 673 VISIT_BODY( node ); 674 } 675 676 //--------------------------------------------------------------------------------------------------------------- 677 678 template< typename pass_type > 679 DeclarationWithType * PassVisitor< pass_type >::mutate( ObjectDecl * node ) { 680 MUTATE_BODY( DeclarationWithType, node ); 681 } 682 683 template< typename pass_type > 684 DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) { 685 MUTATE_BODY( DeclarationWithType, node ); 686 } 687 688 template< typename pass_type > 689 Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) { 690 MUTATE_BODY( Declaration, node ); 691 } 692 693 template< typename pass_type > 694 Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) { 695 MUTATE_BODY( Declaration, node ); 696 } 697 698 template< typename pass_type > 699 Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) { 700 MUTATE_BODY( Declaration, node ); 701 } 702 703 template< typename pass_type > 704 Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) { 705 MUTATE_BODY( Declaration, node ); 706 } 707 708 template< typename pass_type > 709 TypeDecl * PassVisitor< pass_type >::mutate( TypeDecl * node ) { 710 MUTATE_BODY( TypeDecl, node ); 711 } 712 713 template< typename pass_type > 714 Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) { 715 MUTATE_BODY( Declaration, node ); 716 } 717 718 template< typename pass_type > 719 AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) { 720 MUTATE_BODY( AsmDecl, node ); 721 } 722 723 template< typename pass_type > 724 Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { 725 MUTATE_BODY( Statement, node ); 726 } 727 728 template< typename pass_type > 729 Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { 730 MUTATE_BODY( Statement, node ); 731 } 732 733 template< typename pass_type > 734 Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { 735 MUTATE_BODY( Statement, node ); 736 } 737 738 template< typename pass_type > 739 NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) { 740 MUTATE_BODY( NullStmt, node ); 741 } 742 743 template< typename pass_type > 744 Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) { 745 MUTATE_BODY( Statement, node ); 746 } 747 748 template< typename pass_type > 749 Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) { 750 MUTATE_BODY( Statement, node ); 751 } 752 753 template< typename pass_type > 754 Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) { 755 MUTATE_BODY( Expression, node ); 756 } 757 758 template< typename pass_type > 759 Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) { 760 MUTATE_BODY( Expression, node ); 761 } 762 763 template< typename pass_type > 764 Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) { 765 MUTATE_BODY( Expression, node ); 766 } 767 768 template< typename pass_type > 769 Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) { 770 MUTATE_BODY( Expression, node ); 771 } 772 773 template< typename pass_type > 774 Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) { 775 MUTATE_BODY( Expression, node ); 776 } 777 778 template< typename pass_type > 779 Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) { 780 MUTATE_BODY( Expression, node ); 781 } 782 783 template< typename pass_type > 784 Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) { 785 MUTATE_BODY( Expression, node ); 786 } 787 788 template< typename pass_type > 789 Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) { 790 MUTATE_BODY( Expression, node ); 791 } 792 793 template< typename pass_type > 794 Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) { 795 MUTATE_BODY( Expression, node ); 796 } 797 798 template< typename pass_type > 799 Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) { 800 MUTATE_BODY( Expression, node ); 801 } 802 803 template< typename pass_type > 804 Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) { 805 MUTATE_BODY( Expression, node ); 806 } 807 808 template< typename pass_type > 809 Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) { 810 MUTATE_BODY( Expression, node ); 811 } 812 813 template< typename pass_type > 814 Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) { 815 MUTATE_BODY( Expression, node ); 816 } 817 818 template< typename pass_type > 819 Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) { 820 MUTATE_BODY( Expression, node ); 821 } 822 823 template< typename pass_type > 824 Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) { 825 MUTATE_BODY( Expression, node ); 826 } 827 828 template< typename pass_type > 829 Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) { 830 MUTATE_BODY( Expression, node ); 831 } 832 833 template< typename pass_type > 834 Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) { 835 MUTATE_BODY( Expression, node ); 836 } 837 838 template< typename pass_type > 839 Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) { 840 MUTATE_BODY( Expression, node ); 841 } 842 843 template< typename pass_type > 844 Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) { 845 MUTATE_BODY( Expression, node ); 846 } 847 848 template< typename pass_type > 849 Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) { 850 MUTATE_BODY( Expression, node ); 851 } 852 853 template< typename pass_type > 854 Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) { 855 MUTATE_BODY( Expression, node ); 856 } 857 858 template< typename pass_type > 859 Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) { 860 MUTATE_BODY( Expression, node ); 861 } 862 863 template< typename pass_type > 864 Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) { 865 MUTATE_BODY( Expression, node ); 866 } 867 868 template< typename pass_type > 869 Expression * PassVisitor< pass_type >::mutate( UntypedValofExpr * node ) { 870 MUTATE_BODY( Expression, node ); 871 } 872 873 template< typename pass_type > 874 Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) { 875 MUTATE_BODY( Expression, node ); 876 } 877 878 template< typename pass_type > 879 Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) { 880 MUTATE_BODY( Expression, node ); 881 } 882 883 template< typename pass_type > 884 Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) { 885 MUTATE_BODY( Expression, node ); 886 } 887 888 template< typename pass_type > 889 Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) { 890 MUTATE_BODY( Expression, node ); 891 } 892 893 template< typename pass_type > 894 Expression * PassVisitor< pass_type >::mutate( MemberTupleExpr * node ) { 895 MUTATE_BODY( Expression, node ); 896 } 897 898 template< typename pass_type > 899 Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) { 900 MUTATE_BODY( Expression, node ); 901 } 902 903 template< typename pass_type > 904 Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) { 905 MUTATE_BODY( Expression, node ); 906 } 907 908 template< typename pass_type > 909 Type * PassVisitor< pass_type >::mutate( VoidType * node ) { 910 MUTATE_BODY( Type, node ); 911 } 912 913 template< typename pass_type > 914 Type * PassVisitor< pass_type >::mutate( BasicType * node ) { 915 MUTATE_BODY( Type, node ); 916 } 917 918 template< typename pass_type > 919 Type * PassVisitor< pass_type >::mutate( PointerType * node ) { 920 MUTATE_BODY( Type, node ); 921 } 922 923 template< typename pass_type > 924 Type * PassVisitor< pass_type >::mutate( ArrayType * node ) { 925 MUTATE_BODY( Type, node ); 926 } 927 928 template< typename pass_type > 929 Type * PassVisitor< pass_type >::mutate( FunctionType * node ) { 930 MUTATE_BODY( Type, node ); 931 } 932 933 template< typename pass_type > 934 Type * PassVisitor< pass_type >::mutate( StructInstType * node ) { 935 MUTATE_BODY( Type, node ); 936 } 937 938 template< typename pass_type > 939 Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) { 940 MUTATE_BODY( Type, node ); 941 } 942 943 template< typename pass_type > 944 Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) { 945 MUTATE_BODY( Type, node ); 946 } 947 948 template< typename pass_type > 949 Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) { 950 MUTATE_BODY( Type, node ); 951 } 952 953 template< typename pass_type > 954 Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) { 955 MUTATE_BODY( Type, node ); 956 } 957 958 template< typename pass_type > 959 Type * PassVisitor< pass_type >::mutate( TupleType * node ) { 960 MUTATE_BODY( Type, node ); 961 } 962 963 template< typename pass_type > 964 Type * PassVisitor< pass_type >::mutate( TypeofType * node ) { 965 MUTATE_BODY( Type, node ); 966 } 967 968 template< typename pass_type > 969 Type * PassVisitor< pass_type >::mutate( AttrType * node ) { 970 MUTATE_BODY( Type, node ); 971 } 972 973 template< typename pass_type > 974 Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) { 975 MUTATE_BODY( Type, node ); 976 } 977 978 template< typename pass_type > 979 Type * PassVisitor< pass_type >::mutate( ZeroType * node ) { 980 MUTATE_BODY( Type, node ); 981 } 982 983 template< typename pass_type > 984 Type * PassVisitor< pass_type >::mutate( OneType * node ) { 985 MUTATE_BODY( Type, node ); 986 } 987 988 template< typename pass_type > 989 Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) { 990 MUTATE_BODY( Initializer, node ); 991 } 992 993 template< typename pass_type > 994 Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) { 995 MUTATE_BODY( Initializer, node ); 996 } 997 998 template< typename pass_type > 999 Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) { 1000 MUTATE_BODY( Subrange, node ); 1001 } 1002 1003 template< typename pass_type > 1004 Constant * PassVisitor< pass_type >::mutate( Constant * node ) { 1005 MUTATE_BODY( Constant, node ); 1006 } -
TabularUnified src/Common/utility.h ¶
r6065b3aa r49c9773 244 244 ValueGuard(T& inRef) : old(inRef), ref(inRef) {} 245 245 ~ValueGuard() { ref = old; } 246 }; 247 248 template< typename T > 249 struct ValueGuardPtr { 250 T old; 251 T* ref; 252 253 ValueGuardPtr(T * inRef) : old( inRef ? *inRef : T() ), ref(inRef) {} 254 ~ValueGuardPtr() { if( ref ) *ref = old; } 255 }; 256 257 template< typename T > 258 struct ValueGuardPtr< std::list< T > > { 259 std::list< T > old; 260 std::list< T >* ref; 261 262 ValueGuardPtr( std::list< T > * inRef) : old(), ref(inRef) { 263 if( ref ) { swap( *ref, old ); } 264 } 265 ~ValueGuardPtr() { if( ref ) { swap( *ref, old ); } } 246 266 }; 247 267 -
TabularUnified src/InitTweak/FixInit.cc ¶
r6065b3aa r49c9773 20 20 #include <unordered_map> 21 21 #include <unordered_set> 22 22 23 #include "InitTweak.h" 23 24 #include "GenInit.h" 24 25 #include "FixInit.h" 25 26 #include "FixGlobalInit.h" 27 #include "CodeGen/GenType.h" // for warning/error messages 28 #include "Common/PassVisitor.h" 29 #include "GenPoly/DeclMutator.h" 30 #include "GenPoly/PolyMutator.h" 26 31 #include "ResolvExpr/Resolver.h" 27 32 #include "ResolvExpr/typeops.h" 33 #include "SymTab/Autogen.h" 34 #include "SymTab/Indexer.h" 35 #include "SynTree/AddStmtVisitor.h" 36 #include "SynTree/Attribute.h" 28 37 #include "SynTree/Declaration.h" 29 #include "SynTree/Type.h"30 38 #include "SynTree/Expression.h" 31 #include "SynTree/Attribute.h"32 #include "SynTree/Statement.h"33 39 #include "SynTree/Initializer.h" 34 40 #include "SynTree/Mutator.h" 35 #include "SymTab/Indexer.h" 36 #include "SymTab/Autogen.h" 37 #include "GenPoly/PolyMutator.h" 38 #include "GenPoly/DeclMutator.h" 39 #include "SynTree/AddStmtVisitor.h" 40 #include "CodeGen/GenType.h" // for warning/error messages 41 #include "SynTree/Statement.h" 42 #include "SynTree/Type.h" 41 43 #include "Tuples/Tuples.h" 42 44 … … 54 56 typedef std::unordered_map< int, int > UnqCount; 55 57 56 class InsertImplicitCalls final : public GenPoly::PolyMutator{58 class InsertImplicitCalls { 57 59 public: 58 60 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 61 63 62 64 InsertImplicitCalls( EnvMap & envMap ) : envMap( envMap ) {} 63 typedef GenPoly::PolyMutator Parent; 64 using Parent::mutate; 65 virtual Expression * mutate( ApplicationExpr * appExpr ) override; 66 virtual Expression * mutate( StmtExpr * stmtExpr ) override; 65 66 Expression * postmutate( ApplicationExpr * appExpr ); 67 void premutate( StmtExpr * stmtExpr ); 67 68 68 69 // collects environments for relevant nodes 69 70 EnvMap & envMap; 71 TypeSubstitution * env; //Magically populated by the PassVisitor 70 72 }; 71 73 … … 190 192 }; 191 193 192 class FixInit final : public GenPoly::PolyMutator{194 class FixInit { 193 195 public: 194 196 /// expand each object declaration to use its constructor after it is declared. 195 197 static void fixInitializers( std::list< Declaration * > &translationUnit ); 196 198 197 typedef GenPoly::PolyMutator Parent; 198 using Parent::mutate; 199 virtual DeclarationWithType * mutate( ObjectDecl *objDecl ) override; 199 DeclarationWithType * postmutate( ObjectDecl *objDecl ); 200 200 201 201 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor 202 203 }; 203 204 … … 300 301 namespace { 301 302 void InsertImplicitCalls::insert( std::list< Declaration * > & translationUnit, EnvMap & envMap ) { 302 InsertImplicitCallsinserter( envMap );303 PassVisitor<InsertImplicitCalls> inserter( envMap ); 303 304 mutateAll( translationUnit, inserter ); 304 305 } … … 310 311 311 312 void FixInit::fixInitializers( std::list< Declaration * > & translationUnit ) { 312 FixInitfixer;313 PassVisitor<FixInit> fixer; 313 314 314 315 // can't use mutateAll, because need to insert declarations at top-level … … 318 319 try { 319 320 *i = maybeMutate( *i, fixer ); 320 translationUnit.splice( i, fixer. staticDtorDecls );321 translationUnit.splice( i, fixer.pass.staticDtorDecls ); 321 322 } catch( SemanticError &e ) { 322 323 e.set_location( (*i)->location ); … … 350 351 } 351 352 352 Expression * InsertImplicitCalls::mutate( ApplicationExpr * appExpr ) { 353 appExpr = dynamic_cast< ApplicationExpr * >( Parent::mutate( appExpr ) ); 353 Expression * InsertImplicitCalls::postmutate( ApplicationExpr * appExpr ) { 354 354 assert( appExpr ); 355 355 … … 393 393 } 394 394 395 Expression * InsertImplicitCalls::mutate( StmtExpr * stmtExpr ) {395 void InsertImplicitCalls::premutate( StmtExpr * stmtExpr ) { 396 396 assert( env ); 397 397 envMap[stmtExpr] = env; 398 return Parent::mutate( stmtExpr );399 398 } 400 399 … … 696 695 } 697 696 698 DeclarationWithType *FixInit::mutate( ObjectDecl *objDecl ) { 699 // first recursively handle pieces of ObjectDecl so that they aren't missed by other visitors when the init 700 // is removed from the ObjectDecl 701 objDecl = dynamic_cast< ObjectDecl * >( Parent::mutate( objDecl ) ); 697 DeclarationWithType *FixInit::postmutate( ObjectDecl *objDecl ) { 698 // since this removes the init field from objDecl, it must occur after children are mutated (i.e. postmutate) 702 699 if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) { 703 700 // a decision should have been made by the resolver, so ctor and init are not both non-NULL -
TabularUnified src/Tuples/TupleExpansion.cc ¶
r6065b3aa r49c9773 18 18 #include <cassert> 19 19 #include "Tuples.h" 20 #include "Common/PassVisitor.h" 21 #include "Common/ScopedMap.h" 20 22 #include "GenPoly/DeclMutator.h" 23 #include "InitTweak/GenInit.h" 24 #include "InitTweak/InitTweak.h" 25 #include "ResolvExpr/typeops.h" 26 #include "SymTab/Mangler.h" 27 #include "SynTree/Declaration.h" 28 #include "SynTree/Expression.h" 29 #include "SynTree/Initializer.h" 21 30 #include "SynTree/Mutator.h" 22 31 #include "SynTree/Statement.h" 23 #include "SynTree/Declaration.h"24 32 #include "SynTree/Type.h" 25 #include "SynTree/Expression.h"26 #include "SynTree/Initializer.h"27 #include "SymTab/Mangler.h"28 #include "Common/ScopedMap.h"29 #include "ResolvExpr/typeops.h"30 #include "InitTweak/GenInit.h"31 #include "InitTweak/InitTweak.h"32 33 33 34 namespace Tuples { … … 82 83 }; 83 84 84 class TupleIndexExpander final : public Mutator { 85 public: 86 typedef Mutator Parent; 87 using Parent::mutate; 88 89 virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override; 85 class TupleIndexExpander { 86 public: 87 Expression * postmutate( TupleIndexExpr * tupleExpr ); 90 88 }; 91 89 … … 116 114 replacer.mutateDeclarationList( translationUnit ); 117 115 118 TupleIndexExpanderidxExpander;116 PassVisitor<TupleIndexExpander> idxExpander; 119 117 mutateAll( translationUnit, idxExpander ); 120 118 … … 250 248 } 251 249 252 Expression * TupleIndexExpander:: mutate( TupleIndexExpr * tupleExpr ) {253 Expression * tuple = maybeMutate( tupleExpr->get_tuple(), *this);250 Expression * TupleIndexExpander::postmutate( TupleIndexExpr * tupleExpr ) { 251 Expression * tuple = tupleExpr->get_tuple(); 254 252 assert( tuple ); 255 253 tupleExpr->set_tuple( nullptr ); -
TabularUnified src/tests/test.py ¶
r6065b3aa r49c9773 253 253 # for each test to run 254 254 try : 255 results = pool.map_async(partial(run_test_worker, generate=generate, dry_run=dry_run, debug=debug), tests, chunksize = 1 ).get( 3600)255 results = pool.map_async(partial(run_test_worker, generate=generate, dry_run=dry_run, debug=debug), tests, chunksize = 1 ).get(7200) 256 256 except KeyboardInterrupt: 257 257 pool.terminate()
Note: See TracChangeset
for help on using the changeset viewer.