[13932f14] | 1 | #pragma once |
---|
| 2 | |
---|
[08fc48f] | 3 | // IWYU pragma: private, include "Common/PassVisitor.h" |
---|
| 4 | |
---|
[296b2be] | 5 | #include <stack> |
---|
| 6 | |
---|
[ab904dc] | 7 | #include "SynTree/Mutator.h" |
---|
[13932f14] | 8 | #include "SynTree/Visitor.h" |
---|
| 9 | |
---|
[ab904dc] | 10 | #include "SynTree/Initializer.h" |
---|
| 11 | #include "SynTree/Statement.h" |
---|
| 12 | #include "SynTree/Type.h" |
---|
| 13 | #include "SynTree/Declaration.h" |
---|
| 14 | #include "SynTree/Expression.h" |
---|
| 15 | #include "SynTree/Constant.h" |
---|
[2a7b3ca] | 16 | #include "SynTree/TypeSubstitution.h" |
---|
[ab904dc] | 17 | |
---|
[296b2be] | 18 | #include "PassVisitor.proto.h" |
---|
[ab904dc] | 19 | |
---|
[13932f14] | 20 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
---|
[5d88a0a] | 21 | // Templated visitor type |
---|
| 22 | // To use declare a PassVisitor< YOUR VISITOR TYPE > |
---|
[5e298d7] | 23 | // The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired. |
---|
[4551a6e] | 24 | // Note: previsit/postvisit/premutate/postmutate must be **public** members |
---|
[5e298d7] | 25 | // |
---|
| 26 | // Several additional features are available through inheritance |
---|
| 27 | // | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression |
---|
| 28 | // | WithStmtsToAdd - provides the ability to insert statements before or after the current statement by adding new statements into |
---|
| 29 | // stmtsToAddBefore or stmtsToAddAfter respectively. |
---|
[6ca154b] | 30 | // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children |
---|
[d24d4e1] | 31 | // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable |
---|
[5e298d7] | 32 | // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. |
---|
[13932f14] | 33 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
---|
| 34 | template< typename pass_type > |
---|
[ab904dc] | 35 | class PassVisitor final : public Visitor, public Mutator { |
---|
[13932f14] | 36 | public: |
---|
| 37 | |
---|
| 38 | template< typename... Args > |
---|
[aff3af4] | 39 | PassVisitor(Args &&... args) |
---|
[13932f14] | 40 | : pass( std::forward<Args>( args )... ) |
---|
[b73bd70] | 41 | { |
---|
| 42 | typedef PassVisitor<pass_type> this_t; |
---|
| 43 | this_t * const * visitor = visitor_impl(pass, 0); |
---|
| 44 | if(visitor) { |
---|
| 45 | *const_cast<this_t **>( visitor ) = this; |
---|
| 46 | } |
---|
| 47 | } |
---|
[13932f14] | 48 | |
---|
| 49 | virtual ~PassVisitor() = default; |
---|
| 50 | |
---|
[aff3af4] | 51 | pass_type pass; |
---|
[13932f14] | 52 | |
---|
| 53 | virtual void visit( ObjectDecl *objectDecl ) override final; |
---|
| 54 | virtual void visit( FunctionDecl *functionDecl ) override final; |
---|
| 55 | virtual void visit( StructDecl *aggregateDecl ) override final; |
---|
| 56 | virtual void visit( UnionDecl *aggregateDecl ) override final; |
---|
| 57 | virtual void visit( EnumDecl *aggregateDecl ) override final; |
---|
| 58 | virtual void visit( TraitDecl *aggregateDecl ) override final; |
---|
| 59 | virtual void visit( TypeDecl *typeDecl ) override final; |
---|
| 60 | virtual void visit( TypedefDecl *typeDecl ) override final; |
---|
| 61 | virtual void visit( AsmDecl *asmDecl ) override final; |
---|
| 62 | |
---|
| 63 | virtual void visit( CompoundStmt *compoundStmt ) override final; |
---|
| 64 | virtual void visit( ExprStmt *exprStmt ) override final; |
---|
| 65 | virtual void visit( AsmStmt *asmStmt ) override final; |
---|
| 66 | virtual void visit( IfStmt *ifStmt ) override final; |
---|
| 67 | virtual void visit( WhileStmt *whileStmt ) override final; |
---|
| 68 | virtual void visit( ForStmt *forStmt ) override final; |
---|
| 69 | virtual void visit( SwitchStmt *switchStmt ) override final; |
---|
| 70 | virtual void visit( CaseStmt *caseStmt ) override final; |
---|
| 71 | virtual void visit( BranchStmt *branchStmt ) override final; |
---|
| 72 | virtual void visit( ReturnStmt *returnStmt ) override final; |
---|
[6e09f211] | 73 | virtual void visit( ThrowStmt *throwStmt ) override final; |
---|
[13932f14] | 74 | virtual void visit( TryStmt *tryStmt ) override final; |
---|
| 75 | virtual void visit( CatchStmt *catchStmt ) override final; |
---|
| 76 | virtual void visit( FinallyStmt *finallyStmt ) override final; |
---|
[2065609] | 77 | virtual void visit( WaitForStmt *waitforStmt ) override final; |
---|
[13932f14] | 78 | virtual void visit( NullStmt *nullStmt ) override final; |
---|
| 79 | virtual void visit( DeclStmt *declStmt ) override final; |
---|
| 80 | virtual void visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) override final; |
---|
| 81 | |
---|
| 82 | virtual void visit( ApplicationExpr *applicationExpr ) override final; |
---|
| 83 | virtual void visit( UntypedExpr *untypedExpr ) override final; |
---|
| 84 | virtual void visit( NameExpr *nameExpr ) override final; |
---|
| 85 | virtual void visit( CastExpr *castExpr ) override final; |
---|
[a5f0529] | 86 | virtual void visit( VirtualCastExpr *castExpr ) override final; |
---|
[13932f14] | 87 | virtual void visit( AddressExpr *addressExpr ) override final; |
---|
| 88 | virtual void visit( LabelAddressExpr *labAddressExpr ) override final; |
---|
| 89 | virtual void visit( UntypedMemberExpr *memberExpr ) override final; |
---|
| 90 | virtual void visit( MemberExpr *memberExpr ) override final; |
---|
| 91 | virtual void visit( VariableExpr *variableExpr ) override final; |
---|
| 92 | virtual void visit( ConstantExpr *constantExpr ) override final; |
---|
| 93 | virtual void visit( SizeofExpr *sizeofExpr ) override final; |
---|
| 94 | virtual void visit( AlignofExpr *alignofExpr ) override final; |
---|
| 95 | virtual void visit( UntypedOffsetofExpr *offsetofExpr ) override final; |
---|
| 96 | virtual void visit( OffsetofExpr *offsetofExpr ) override final; |
---|
| 97 | virtual void visit( OffsetPackExpr *offsetPackExpr ) override final; |
---|
| 98 | virtual void visit( AttrExpr *attrExpr ) override final; |
---|
| 99 | virtual void visit( LogicalExpr *logicalExpr ) override final; |
---|
| 100 | virtual void visit( ConditionalExpr *conditionalExpr ) override final; |
---|
| 101 | virtual void visit( CommaExpr *commaExpr ) override final; |
---|
| 102 | virtual void visit( TypeExpr *typeExpr ) override final; |
---|
| 103 | virtual void visit( AsmExpr *asmExpr ) override final; |
---|
| 104 | virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr ) override final; |
---|
| 105 | virtual void visit( ConstructorExpr * ctorExpr ) override final; |
---|
| 106 | virtual void visit( CompoundLiteralExpr *compLitExpr ) override final; |
---|
| 107 | virtual void visit( RangeExpr *rangeExpr ) override final; |
---|
| 108 | virtual void visit( UntypedTupleExpr *tupleExpr ) override final; |
---|
| 109 | virtual void visit( TupleExpr *tupleExpr ) override final; |
---|
| 110 | virtual void visit( TupleIndexExpr *tupleExpr ) override final; |
---|
| 111 | virtual void visit( TupleAssignExpr *assignExpr ) override final; |
---|
| 112 | virtual void visit( StmtExpr * stmtExpr ) override final; |
---|
| 113 | virtual void visit( UniqueExpr * uniqueExpr ) override final; |
---|
| 114 | |
---|
| 115 | virtual void visit( VoidType *basicType ) override final; |
---|
| 116 | virtual void visit( BasicType *basicType ) override final; |
---|
| 117 | virtual void visit( PointerType *pointerType ) override final; |
---|
| 118 | virtual void visit( ArrayType *arrayType ) override final; |
---|
[6b9b047] | 119 | virtual void visit( ReferenceType *referenceType ) override final; |
---|
[13932f14] | 120 | virtual void visit( FunctionType *functionType ) override final; |
---|
| 121 | virtual void visit( StructInstType *aggregateUseType ) override final; |
---|
| 122 | virtual void visit( UnionInstType *aggregateUseType ) override final; |
---|
| 123 | virtual void visit( EnumInstType *aggregateUseType ) override final; |
---|
| 124 | virtual void visit( TraitInstType *aggregateUseType ) override final; |
---|
| 125 | virtual void visit( TypeInstType *aggregateUseType ) override final; |
---|
| 126 | virtual void visit( TupleType *tupleType ) override final; |
---|
| 127 | virtual void visit( TypeofType *typeofType ) override final; |
---|
| 128 | virtual void visit( AttrType *attrType ) override final; |
---|
| 129 | virtual void visit( VarArgsType *varArgsType ) override final; |
---|
| 130 | virtual void visit( ZeroType *zeroType ) override final; |
---|
| 131 | virtual void visit( OneType *oneType ) override final; |
---|
| 132 | |
---|
| 133 | virtual void visit( SingleInit *singleInit ) override final; |
---|
| 134 | virtual void visit( ListInit *listInit ) override final; |
---|
| 135 | virtual void visit( ConstructorInit *ctorInit ) override final; |
---|
| 136 | |
---|
| 137 | virtual void visit( Subrange *subrange ) override final; |
---|
| 138 | |
---|
| 139 | virtual void visit( Constant *constant ) override final; |
---|
| 140 | |
---|
[ab904dc] | 141 | virtual DeclarationWithType* mutate( ObjectDecl *objectDecl ) override final; |
---|
| 142 | virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ) override final; |
---|
| 143 | virtual Declaration* mutate( StructDecl *aggregateDecl ) override final; |
---|
| 144 | virtual Declaration* mutate( UnionDecl *aggregateDecl ) override final; |
---|
| 145 | virtual Declaration* mutate( EnumDecl *aggregateDecl ) override final; |
---|
| 146 | virtual Declaration* mutate( TraitDecl *aggregateDecl ) override final; |
---|
[96f9ef5] | 147 | virtual Declaration* mutate( TypeDecl *typeDecl ) override final; |
---|
[ab904dc] | 148 | virtual Declaration* mutate( TypedefDecl *typeDecl ) override final; |
---|
| 149 | virtual AsmDecl* mutate( AsmDecl *asmDecl ) override final; |
---|
| 150 | |
---|
| 151 | virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ) override final; |
---|
| 152 | virtual Statement* mutate( ExprStmt *exprStmt ) override final; |
---|
| 153 | virtual Statement* mutate( AsmStmt *asmStmt ) override final; |
---|
| 154 | virtual Statement* mutate( IfStmt *ifStmt ) override final; |
---|
| 155 | virtual Statement* mutate( WhileStmt *whileStmt ) override final; |
---|
| 156 | virtual Statement* mutate( ForStmt *forStmt ) override final; |
---|
| 157 | virtual Statement* mutate( SwitchStmt *switchStmt ) override final; |
---|
| 158 | virtual Statement* mutate( CaseStmt *caseStmt ) override final; |
---|
| 159 | virtual Statement* mutate( BranchStmt *branchStmt ) override final; |
---|
| 160 | virtual Statement* mutate( ReturnStmt *returnStmt ) override final; |
---|
[6e09f211] | 161 | virtual Statement* mutate( ThrowStmt *throwStmt ) override final; |
---|
[2065609] | 162 | virtual Statement* mutate( TryStmt *tryStmt ) override final; |
---|
[ab904dc] | 163 | virtual Statement* mutate( CatchStmt *catchStmt ) override final; |
---|
[2065609] | 164 | virtual Statement* mutate( FinallyStmt *finallyStmt ) override final; |
---|
| 165 | virtual Statement* mutate( WaitForStmt *waitforStmt ) override final; |
---|
[ab904dc] | 166 | virtual NullStmt* mutate( NullStmt *nullStmt ) override final; |
---|
| 167 | virtual Statement* mutate( DeclStmt *declStmt ) override final; |
---|
| 168 | virtual Statement* mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) override final; |
---|
| 169 | |
---|
| 170 | virtual Expression* mutate( ApplicationExpr *applicationExpr ) override final; |
---|
| 171 | virtual Expression* mutate( UntypedExpr *untypedExpr ) override final; |
---|
| 172 | virtual Expression* mutate( NameExpr *nameExpr ) override final; |
---|
| 173 | virtual Expression* mutate( AddressExpr *castExpr ) override final; |
---|
| 174 | virtual Expression* mutate( LabelAddressExpr *labAddressExpr ) override final; |
---|
| 175 | virtual Expression* mutate( CastExpr *castExpr ) override final; |
---|
[a5f0529] | 176 | virtual Expression* mutate( VirtualCastExpr *castExpr ) override final; |
---|
[ab904dc] | 177 | virtual Expression* mutate( UntypedMemberExpr *memberExpr ) override final; |
---|
| 178 | virtual Expression* mutate( MemberExpr *memberExpr ) override final; |
---|
| 179 | virtual Expression* mutate( VariableExpr *variableExpr ) override final; |
---|
| 180 | virtual Expression* mutate( ConstantExpr *constantExpr ) override final; |
---|
| 181 | virtual Expression* mutate( SizeofExpr *sizeofExpr ) override final; |
---|
| 182 | virtual Expression* mutate( AlignofExpr *alignofExpr ) override final; |
---|
| 183 | virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr ) override final; |
---|
| 184 | virtual Expression* mutate( OffsetofExpr *offsetofExpr ) override final; |
---|
| 185 | virtual Expression* mutate( OffsetPackExpr *offsetPackExpr ) override final; |
---|
| 186 | virtual Expression* mutate( AttrExpr *attrExpr ) override final; |
---|
| 187 | virtual Expression* mutate( LogicalExpr *logicalExpr ) override final; |
---|
| 188 | virtual Expression* mutate( ConditionalExpr *conditionalExpr ) override final; |
---|
| 189 | virtual Expression* mutate( CommaExpr *commaExpr ) override final; |
---|
| 190 | virtual Expression* mutate( TypeExpr *typeExpr ) override final; |
---|
| 191 | virtual Expression* mutate( AsmExpr *asmExpr ) override final; |
---|
| 192 | virtual Expression* mutate( ImplicitCopyCtorExpr *impCpCtorExpr ) override final; |
---|
| 193 | virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final; |
---|
| 194 | virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final; |
---|
| 195 | virtual Expression* mutate( RangeExpr *rangeExpr ) override final; |
---|
| 196 | virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final; |
---|
| 197 | virtual Expression* mutate( TupleExpr *tupleExpr ) override final; |
---|
| 198 | virtual Expression* mutate( TupleIndexExpr *tupleExpr ) override final; |
---|
| 199 | virtual Expression* mutate( TupleAssignExpr *assignExpr ) override final; |
---|
| 200 | virtual Expression* mutate( StmtExpr * stmtExpr ) override final; |
---|
| 201 | virtual Expression* mutate( UniqueExpr * uniqueExpr ) override final; |
---|
| 202 | |
---|
| 203 | virtual Type* mutate( VoidType *basicType ) override final; |
---|
| 204 | virtual Type* mutate( BasicType *basicType ) override final; |
---|
| 205 | virtual Type* mutate( PointerType *pointerType ) override final; |
---|
| 206 | virtual Type* mutate( ArrayType *arrayType ) override final; |
---|
[6b9b047] | 207 | virtual Type* mutate( ReferenceType *referenceType ) override final; |
---|
[ab904dc] | 208 | virtual Type* mutate( FunctionType *functionType ) override final; |
---|
| 209 | virtual Type* mutate( StructInstType *aggregateUseType ) override final; |
---|
| 210 | virtual Type* mutate( UnionInstType *aggregateUseType ) override final; |
---|
| 211 | virtual Type* mutate( EnumInstType *aggregateUseType ) override final; |
---|
| 212 | virtual Type* mutate( TraitInstType *aggregateUseType ) override final; |
---|
| 213 | virtual Type* mutate( TypeInstType *aggregateUseType ) override final; |
---|
| 214 | virtual Type* mutate( TupleType *tupleType ) override final; |
---|
| 215 | virtual Type* mutate( TypeofType *typeofType ) override final; |
---|
| 216 | virtual Type* mutate( AttrType *attrType ) override final; |
---|
| 217 | virtual Type* mutate( VarArgsType *varArgsType ) override final; |
---|
| 218 | virtual Type* mutate( ZeroType *zeroType ) override final; |
---|
| 219 | virtual Type* mutate( OneType *oneType ) override final; |
---|
| 220 | |
---|
| 221 | virtual Initializer* mutate( SingleInit *singleInit ) override final; |
---|
| 222 | virtual Initializer* mutate( ListInit *listInit ) override final; |
---|
| 223 | virtual Initializer* mutate( ConstructorInit *ctorInit ) override final; |
---|
| 224 | |
---|
| 225 | virtual Subrange *mutate( Subrange *subrange ) override final; |
---|
| 226 | |
---|
| 227 | virtual Constant *mutate( Constant *constant ) override final; |
---|
| 228 | |
---|
[13932f14] | 229 | private: |
---|
[6ca154b] | 230 | template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); |
---|
| 231 | template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); |
---|
| 232 | |
---|
[296b2be] | 233 | template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } |
---|
| 234 | template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } |
---|
[13932f14] | 235 | |
---|
[296b2be] | 236 | template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); } |
---|
| 237 | template<typename return_type, typename node_type> return_type call_postmutate ( node_type * node ) { return postmutate_impl<return_type>( pass, node, 0 ); } |
---|
[ab904dc] | 238 | |
---|
[296b2be] | 239 | void call_beginScope() { begin_scope_impl( pass, 0 ); } |
---|
| 240 | void call_endScope () { end_scope_impl ( pass, 0 ); } |
---|
| 241 | |
---|
[3fb9a83] | 242 | void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } |
---|
| 243 | |
---|
[6ca154b] | 244 | template< typename func_t > |
---|
| 245 | void handleStatementList( std::list< Statement * > & statements, func_t func ); |
---|
| 246 | void visitStatementList ( std::list< Statement* > &statements ); |
---|
[296b2be] | 247 | void mutateStatementList( std::list< Statement* > &statements ); |
---|
[134322e] | 248 | |
---|
[6ca154b] | 249 | template< typename func_t > |
---|
| 250 | Statement * handleStatement( Statement * stmt, func_t func ); |
---|
| 251 | Statement * visitStatement ( Statement * stmt ); |
---|
[296b2be] | 252 | Statement * mutateStatement( Statement * stmt ); |
---|
[134322e] | 253 | |
---|
[6ca154b] | 254 | template< typename func_t > |
---|
| 255 | Expression * handleExpression( Expression * expr, func_t func ); |
---|
| 256 | Expression * visitExpression ( Expression * expr ); |
---|
[296b2be] | 257 | Expression * mutateExpression( Expression * expr ); |
---|
| 258 | |
---|
[ab904dc] | 259 | |
---|
[134322e] | 260 | TypeSubstitution ** get_env_ptr () { return env_impl ( pass, 0); } |
---|
| 261 | std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } |
---|
| 262 | std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } |
---|
[35df560] | 263 | std::list< Declaration* > * get_beforeDecls() { return declsToAddBefore_impl( pass, 0); } |
---|
| 264 | std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); } |
---|
[b73bd70] | 265 | |
---|
| 266 | void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); } |
---|
[13932f14] | 267 | }; |
---|
| 268 | |
---|
[6e09f211] | 269 | template<typename pass_type, typename T> |
---|
| 270 | void GuardValue( pass_type * pass, T& val ) { |
---|
| 271 | pass->at_cleanup( [ val ]( void * newVal ) { |
---|
| 272 | * static_cast< T * >( newVal ) = val; |
---|
| 273 | }, static_cast< void * >( & val ) ); |
---|
| 274 | } |
---|
| 275 | |
---|
[637568b] | 276 | class WithTypeSubstitution { |
---|
| 277 | protected: |
---|
| 278 | WithTypeSubstitution() = default; |
---|
| 279 | ~WithTypeSubstitution() = default; |
---|
| 280 | |
---|
[4eb31f2b] | 281 | public: |
---|
[d24d4e1] | 282 | TypeSubstitution * env = nullptr; |
---|
[637568b] | 283 | }; |
---|
| 284 | |
---|
| 285 | class WithStmtsToAdd { |
---|
| 286 | protected: |
---|
| 287 | WithStmtsToAdd() = default; |
---|
| 288 | ~WithStmtsToAdd() = default; |
---|
| 289 | |
---|
[4eb31f2b] | 290 | public: |
---|
[637568b] | 291 | std::list< Statement* > stmtsToAddBefore; |
---|
| 292 | std::list< Statement* > stmtsToAddAfter; |
---|
| 293 | }; |
---|
[d24d4e1] | 294 | |
---|
| 295 | class WithDeclsToAdd { |
---|
| 296 | protected: |
---|
| 297 | WithDeclsToAdd() = default; |
---|
| 298 | ~WithDeclsToAdd() = default; |
---|
| 299 | |
---|
| 300 | public: |
---|
| 301 | std::list< Declaration* > declsToAddBefore; |
---|
| 302 | std::list< Declaration* > declsToAddAfter; |
---|
| 303 | }; |
---|
| 304 | |
---|
[637568b] | 305 | class WithShortCircuiting { |
---|
| 306 | protected: |
---|
| 307 | WithShortCircuiting() = default; |
---|
| 308 | ~WithShortCircuiting() = default; |
---|
| 309 | |
---|
[4eb31f2b] | 310 | public: |
---|
[b73bd70] | 311 | bool_ref visit_children; |
---|
[637568b] | 312 | }; |
---|
| 313 | |
---|
[d24d4e1] | 314 | class WithGuards { |
---|
[637568b] | 315 | protected: |
---|
[d24d4e1] | 316 | WithGuards() = default; |
---|
| 317 | ~WithGuards() = default; |
---|
[637568b] | 318 | |
---|
[4eb31f2b] | 319 | public: |
---|
[637568b] | 320 | at_cleanup_t at_cleanup; |
---|
| 321 | |
---|
[4eb31f2b] | 322 | template< typename T > |
---|
[637568b] | 323 | void GuardValue( T& val ) { |
---|
| 324 | at_cleanup( [ val ]( void * newVal ) { |
---|
| 325 | * static_cast< T * >( newVal ) = val; |
---|
| 326 | }, static_cast< void * >( & val ) ); |
---|
| 327 | } |
---|
[5dd0704] | 328 | |
---|
[d24d4e1] | 329 | template< typename T > |
---|
| 330 | void GuardScope( T& val ) { |
---|
| 331 | val.beginScope(); |
---|
| 332 | at_cleanup( []( void * val ) { |
---|
| 333 | static_cast< T * >( val )->endScope(); |
---|
| 334 | }, static_cast< void * >( & val ) ); |
---|
| 335 | } |
---|
| 336 | |
---|
[5dd0704] | 337 | template< typename Func > |
---|
[d24d4e1] | 338 | void GuardAction( Func func ) { |
---|
| 339 | at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr ); |
---|
[5dd0704] | 340 | } |
---|
[637568b] | 341 | }; |
---|
| 342 | |
---|
[b73bd70] | 343 | template<typename pass_type> |
---|
| 344 | class WithVisitorRef { |
---|
| 345 | protected: |
---|
[d24d4e1] | 346 | WithVisitorRef() {} |
---|
| 347 | ~WithVisitorRef() {} |
---|
[b73bd70] | 348 | |
---|
| 349 | public: |
---|
[d24d4e1] | 350 | PassVisitor<pass_type> * const visitor = nullptr; |
---|
[b73bd70] | 351 | }; |
---|
[637568b] | 352 | |
---|
[aff3af4] | 353 | #include "PassVisitor.impl.h" |
---|