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