[13932f14] | 1 | #pragma once |
---|
| 2 | |
---|
[08fc48f] | 3 | // IWYU pragma: private, include "Common/PassVisitor.h" |
---|
| 4 | |
---|
[296b2be] | 5 | #include <stack> |
---|
[02fdb8e] | 6 | #include <type_traits> |
---|
[296b2be] | 7 | |
---|
[675716e] | 8 | #include "Common/Stats.h" |
---|
[3c398b6] | 9 | #include "Common/utility.h" |
---|
| 10 | |
---|
[ab904dc] | 11 | #include "SynTree/Mutator.h" |
---|
[13932f14] | 12 | #include "SynTree/Visitor.h" |
---|
| 13 | |
---|
[e0886db] | 14 | #include "SymTab/Indexer.h" |
---|
| 15 | |
---|
[5ea7a22] | 16 | #include "SynTree/Attribute.h" |
---|
[ab904dc] | 17 | #include "SynTree/Initializer.h" |
---|
| 18 | #include "SynTree/Statement.h" |
---|
| 19 | #include "SynTree/Type.h" |
---|
| 20 | #include "SynTree/Declaration.h" |
---|
| 21 | #include "SynTree/Expression.h" |
---|
| 22 | #include "SynTree/Constant.h" |
---|
[07c178f0] | 23 | |
---|
| 24 | class TypeSubstitution; |
---|
[ab904dc] | 25 | |
---|
[296b2be] | 26 | #include "PassVisitor.proto.h" |
---|
[ab904dc] | 27 | |
---|
[13932f14] | 28 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
---|
[5d88a0a] | 29 | // Templated visitor type |
---|
| 30 | // To use declare a PassVisitor< YOUR VISITOR TYPE > |
---|
[5e298d7] | 31 | // The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired. |
---|
[4551a6e] | 32 | // Note: previsit/postvisit/premutate/postmutate must be **public** members |
---|
[5e298d7] | 33 | // |
---|
| 34 | // Several additional features are available through inheritance |
---|
| 35 | // | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression |
---|
| 36 | // | WithStmtsToAdd - provides the ability to insert statements before or after the current statement by adding new statements into |
---|
| 37 | // stmtsToAddBefore or stmtsToAddAfter respectively. |
---|
[6ca154b] | 38 | // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children |
---|
[d24d4e1] | 39 | // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable |
---|
[5e298d7] | 40 | // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates. |
---|
[13932f14] | 41 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
---|
| 42 | template< typename pass_type > |
---|
[ab904dc] | 43 | class PassVisitor final : public Visitor, public Mutator { |
---|
[13932f14] | 44 | public: |
---|
| 45 | |
---|
| 46 | template< typename... Args > |
---|
[aff3af4] | 47 | PassVisitor(Args &&... args) |
---|
[13932f14] | 48 | : pass( std::forward<Args>( args )... ) |
---|
[b73bd70] | 49 | { |
---|
| 50 | typedef PassVisitor<pass_type> this_t; |
---|
| 51 | this_t * const * visitor = visitor_impl(pass, 0); |
---|
| 52 | if(visitor) { |
---|
| 53 | *const_cast<this_t **>( visitor ) = this; |
---|
| 54 | } |
---|
| 55 | } |
---|
[13932f14] | 56 | |
---|
| 57 | virtual ~PassVisitor() = default; |
---|
| 58 | |
---|
[aff3af4] | 59 | pass_type pass; |
---|
[13932f14] | 60 | |
---|
[5ea7a22] | 61 | virtual void visit( ObjectDecl * objectDecl ) override final; |
---|
[7870799] | 62 | virtual void visit( const ObjectDecl * objectDecl ) override final; |
---|
[5ea7a22] | 63 | virtual void visit( FunctionDecl * functionDecl ) override final; |
---|
[7870799] | 64 | virtual void visit( const FunctionDecl * functionDecl ) override final; |
---|
[5ea7a22] | 65 | virtual void visit( StructDecl * aggregateDecl ) override final; |
---|
[7870799] | 66 | virtual void visit( const StructDecl * aggregateDecl ) override final; |
---|
[5ea7a22] | 67 | virtual void visit( UnionDecl * aggregateDecl ) override final; |
---|
[7870799] | 68 | virtual void visit( const UnionDecl * aggregateDecl ) override final; |
---|
[5ea7a22] | 69 | virtual void visit( EnumDecl * aggregateDecl ) override final; |
---|
[7870799] | 70 | virtual void visit( const EnumDecl * aggregateDecl ) override final; |
---|
[5ea7a22] | 71 | virtual void visit( TraitDecl * aggregateDecl ) override final; |
---|
[7870799] | 72 | virtual void visit( const TraitDecl * aggregateDecl ) override final; |
---|
[5ea7a22] | 73 | virtual void visit( TypeDecl * typeDecl ) override final; |
---|
[7870799] | 74 | virtual void visit( const TypeDecl * typeDecl ) override final; |
---|
[5ea7a22] | 75 | virtual void visit( TypedefDecl * typeDecl ) override final; |
---|
[7870799] | 76 | virtual void visit( const TypedefDecl * typeDecl ) override final; |
---|
[5ea7a22] | 77 | virtual void visit( AsmDecl * asmDecl ) override final; |
---|
[7870799] | 78 | virtual void visit( const AsmDecl * asmDecl ) override final; |
---|
[f6e3e34] | 79 | virtual void visit( StaticAssertDecl * assertDecl ) override final; |
---|
[7870799] | 80 | virtual void visit( const StaticAssertDecl * assertDecl ) override final; |
---|
[5ea7a22] | 81 | |
---|
| 82 | virtual void visit( CompoundStmt * compoundStmt ) override final; |
---|
[7870799] | 83 | virtual void visit( const CompoundStmt * compoundStmt ) override final; |
---|
[5ea7a22] | 84 | virtual void visit( ExprStmt * exprStmt ) override final; |
---|
[7870799] | 85 | virtual void visit( const ExprStmt * exprStmt ) override final; |
---|
[5ea7a22] | 86 | virtual void visit( AsmStmt * asmStmt ) override final; |
---|
[7870799] | 87 | virtual void visit( const AsmStmt * asmStmt ) override final; |
---|
[cc32d83] | 88 | virtual void visit( DirectiveStmt * dirStmt ) override final; |
---|
[7870799] | 89 | virtual void visit( const DirectiveStmt * dirStmt ) override final; |
---|
[5ea7a22] | 90 | virtual void visit( IfStmt * ifStmt ) override final; |
---|
[7870799] | 91 | virtual void visit( const IfStmt * ifStmt ) override final; |
---|
[5ea7a22] | 92 | virtual void visit( WhileStmt * whileStmt ) override final; |
---|
[7870799] | 93 | virtual void visit( const WhileStmt * whileStmt ) override final; |
---|
[5ea7a22] | 94 | virtual void visit( ForStmt * forStmt ) override final; |
---|
[7870799] | 95 | virtual void visit( const ForStmt * forStmt ) override final; |
---|
[5ea7a22] | 96 | virtual void visit( SwitchStmt * switchStmt ) override final; |
---|
[7870799] | 97 | virtual void visit( const SwitchStmt * switchStmt ) override final; |
---|
[5ea7a22] | 98 | virtual void visit( CaseStmt * caseStmt ) override final; |
---|
[7870799] | 99 | virtual void visit( const CaseStmt * caseStmt ) override final; |
---|
[5ea7a22] | 100 | virtual void visit( BranchStmt * branchStmt ) override final; |
---|
[7870799] | 101 | virtual void visit( const BranchStmt * branchStmt ) override final; |
---|
[5ea7a22] | 102 | virtual void visit( ReturnStmt * returnStmt ) override final; |
---|
[7870799] | 103 | virtual void visit( const ReturnStmt * returnStmt ) override final; |
---|
[5ea7a22] | 104 | virtual void visit( ThrowStmt * throwStmt ) override final; |
---|
[7870799] | 105 | virtual void visit( const ThrowStmt * throwStmt ) override final; |
---|
[5ea7a22] | 106 | virtual void visit( TryStmt * tryStmt ) override final; |
---|
[7870799] | 107 | virtual void visit( const TryStmt * tryStmt ) override final; |
---|
[5ea7a22] | 108 | virtual void visit( CatchStmt * catchStmt ) override final; |
---|
[7870799] | 109 | virtual void visit( const CatchStmt * catchStmt ) override final; |
---|
[5ea7a22] | 110 | virtual void visit( FinallyStmt * finallyStmt ) override final; |
---|
[7870799] | 111 | virtual void visit( const FinallyStmt * finallyStmt ) override final; |
---|
[5ea7a22] | 112 | virtual void visit( WaitForStmt * waitforStmt ) override final; |
---|
[7870799] | 113 | virtual void visit( const WaitForStmt * waitforStmt ) override final; |
---|
[61255ad] | 114 | virtual void visit( WithStmt * withStmt ) override final; |
---|
[7870799] | 115 | virtual void visit( const WithStmt * withStmt ) override final; |
---|
[5ea7a22] | 116 | virtual void visit( NullStmt * nullStmt ) override final; |
---|
[7870799] | 117 | virtual void visit( const NullStmt * nullStmt ) override final; |
---|
[5ea7a22] | 118 | virtual void visit( DeclStmt * declStmt ) override final; |
---|
[7870799] | 119 | virtual void visit( const DeclStmt * declStmt ) override final; |
---|
[5ea7a22] | 120 | virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) override final; |
---|
[7870799] | 121 | virtual void visit( const ImplicitCtorDtorStmt * impCtorDtorStmt ) override final; |
---|
[5ea7a22] | 122 | |
---|
| 123 | virtual void visit( ApplicationExpr * applicationExpr ) override final; |
---|
[7870799] | 124 | virtual void visit( const ApplicationExpr * applicationExpr ) override final; |
---|
[5ea7a22] | 125 | virtual void visit( UntypedExpr * untypedExpr ) override final; |
---|
[7870799] | 126 | virtual void visit( const UntypedExpr * untypedExpr ) override final; |
---|
[5ea7a22] | 127 | virtual void visit( NameExpr * nameExpr ) override final; |
---|
[7870799] | 128 | virtual void visit( const NameExpr * nameExpr ) override final; |
---|
[5ea7a22] | 129 | virtual void visit( CastExpr * castExpr ) override final; |
---|
[7870799] | 130 | virtual void visit( const CastExpr * castExpr ) override final; |
---|
[9a705dc8] | 131 | virtual void visit( KeywordCastExpr * castExpr ) override final; |
---|
[7870799] | 132 | virtual void visit( const KeywordCastExpr * castExpr ) override final; |
---|
[5ea7a22] | 133 | virtual void visit( VirtualCastExpr * castExpr ) override final; |
---|
[7870799] | 134 | virtual void visit( const VirtualCastExpr * castExpr ) override final; |
---|
[5ea7a22] | 135 | virtual void visit( AddressExpr * addressExpr ) override final; |
---|
[7870799] | 136 | virtual void visit( const AddressExpr * addressExpr ) override final; |
---|
[5ea7a22] | 137 | virtual void visit( LabelAddressExpr * labAddressExpr ) override final; |
---|
[7870799] | 138 | virtual void visit( const LabelAddressExpr * labAddressExpr ) override final; |
---|
[5ea7a22] | 139 | virtual void visit( UntypedMemberExpr * memberExpr ) override final; |
---|
[7870799] | 140 | virtual void visit( const UntypedMemberExpr * memberExpr ) override final; |
---|
[5ea7a22] | 141 | virtual void visit( MemberExpr * memberExpr ) override final; |
---|
[7870799] | 142 | virtual void visit( const MemberExpr * memberExpr ) override final; |
---|
[5ea7a22] | 143 | virtual void visit( VariableExpr * variableExpr ) override final; |
---|
[7870799] | 144 | virtual void visit( const VariableExpr * variableExpr ) override final; |
---|
[5ea7a22] | 145 | virtual void visit( ConstantExpr * constantExpr ) override final; |
---|
[7870799] | 146 | virtual void visit( const ConstantExpr * constantExpr ) override final; |
---|
[5ea7a22] | 147 | virtual void visit( SizeofExpr * sizeofExpr ) override final; |
---|
[7870799] | 148 | virtual void visit( const SizeofExpr * sizeofExpr ) override final; |
---|
[5ea7a22] | 149 | virtual void visit( AlignofExpr * alignofExpr ) override final; |
---|
[7870799] | 150 | virtual void visit( const AlignofExpr * alignofExpr ) override final; |
---|
[5ea7a22] | 151 | virtual void visit( UntypedOffsetofExpr * offsetofExpr ) override final; |
---|
[7870799] | 152 | virtual void visit( const UntypedOffsetofExpr * offsetofExpr ) override final; |
---|
[5ea7a22] | 153 | virtual void visit( OffsetofExpr * offsetofExpr ) override final; |
---|
[7870799] | 154 | virtual void visit( const OffsetofExpr * offsetofExpr ) override final; |
---|
[5ea7a22] | 155 | virtual void visit( OffsetPackExpr * offsetPackExpr ) override final; |
---|
[7870799] | 156 | virtual void visit( const OffsetPackExpr * offsetPackExpr ) override final; |
---|
[5ea7a22] | 157 | virtual void visit( LogicalExpr * logicalExpr ) override final; |
---|
[7870799] | 158 | virtual void visit( const LogicalExpr * logicalExpr ) override final; |
---|
[5ea7a22] | 159 | virtual void visit( ConditionalExpr * conditionalExpr ) override final; |
---|
[7870799] | 160 | virtual void visit( const ConditionalExpr * conditionalExpr ) override final; |
---|
[5ea7a22] | 161 | virtual void visit( CommaExpr * commaExpr ) override final; |
---|
[7870799] | 162 | virtual void visit( const CommaExpr * commaExpr ) override final; |
---|
[5ea7a22] | 163 | virtual void visit( TypeExpr * typeExpr ) override final; |
---|
[7870799] | 164 | virtual void visit( const TypeExpr * typeExpr ) override final; |
---|
[5ea7a22] | 165 | virtual void visit( AsmExpr * asmExpr ) override final; |
---|
[7870799] | 166 | virtual void visit( const AsmExpr * asmExpr ) override final; |
---|
[5ea7a22] | 167 | virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr ) override final; |
---|
[7870799] | 168 | virtual void visit( const ImplicitCopyCtorExpr * impCpCtorExpr ) override final; |
---|
[5ea7a22] | 169 | virtual void visit( ConstructorExpr * ctorExpr ) override final; |
---|
[7870799] | 170 | virtual void visit( const ConstructorExpr * ctorExpr ) override final; |
---|
[5ea7a22] | 171 | virtual void visit( CompoundLiteralExpr * compLitExpr ) override final; |
---|
[7870799] | 172 | virtual void visit( const CompoundLiteralExpr * compLitExpr ) override final; |
---|
[5ea7a22] | 173 | virtual void visit( RangeExpr * rangeExpr ) override final; |
---|
[7870799] | 174 | virtual void visit( const RangeExpr * rangeExpr ) override final; |
---|
[5ea7a22] | 175 | virtual void visit( UntypedTupleExpr * tupleExpr ) override final; |
---|
[7870799] | 176 | virtual void visit( const UntypedTupleExpr * tupleExpr ) override final; |
---|
[5ea7a22] | 177 | virtual void visit( TupleExpr * tupleExpr ) override final; |
---|
[7870799] | 178 | virtual void visit( const TupleExpr * tupleExpr ) override final; |
---|
[5ea7a22] | 179 | virtual void visit( TupleIndexExpr * tupleExpr ) override final; |
---|
[7870799] | 180 | virtual void visit( const TupleIndexExpr * tupleExpr ) override final; |
---|
[5ea7a22] | 181 | virtual void visit( TupleAssignExpr * assignExpr ) override final; |
---|
[7870799] | 182 | virtual void visit( const TupleAssignExpr * assignExpr ) override final; |
---|
[5ea7a22] | 183 | virtual void visit( StmtExpr * stmtExpr ) override final; |
---|
[7870799] | 184 | virtual void visit( const StmtExpr * stmtExpr ) override final; |
---|
[5ea7a22] | 185 | virtual void visit( UniqueExpr * uniqueExpr ) override final; |
---|
[7870799] | 186 | virtual void visit( const UniqueExpr * uniqueExpr ) override final; |
---|
[73367a8] | 187 | virtual void visit( UntypedInitExpr * initExpr ) override final; |
---|
[7870799] | 188 | virtual void visit( const UntypedInitExpr * initExpr ) override final; |
---|
[73367a8] | 189 | virtual void visit( InitExpr * initExpr ) override final; |
---|
[7870799] | 190 | virtual void visit( const InitExpr * initExpr ) override final; |
---|
[44b4114] | 191 | virtual void visit( DeletedExpr * delExpr ) override final; |
---|
[7870799] | 192 | virtual void visit( const DeletedExpr * delExpr ) override final; |
---|
[0f79853] | 193 | virtual void visit( DefaultArgExpr * argExpr ) override final; |
---|
[7870799] | 194 | virtual void visit( const DefaultArgExpr * argExpr ) override final; |
---|
[d807ca28] | 195 | virtual void visit( GenericExpr * genExpr ) override final; |
---|
[7870799] | 196 | virtual void visit( const GenericExpr * genExpr ) override final; |
---|
[5ea7a22] | 197 | |
---|
| 198 | virtual void visit( VoidType * basicType ) override final; |
---|
[7870799] | 199 | virtual void visit( const VoidType * basicType ) override final; |
---|
[5ea7a22] | 200 | virtual void visit( BasicType * basicType ) override final; |
---|
[7870799] | 201 | virtual void visit( const BasicType * basicType ) override final; |
---|
[5ea7a22] | 202 | virtual void visit( PointerType * pointerType ) override final; |
---|
[7870799] | 203 | virtual void visit( const PointerType * pointerType ) override final; |
---|
[5ea7a22] | 204 | virtual void visit( ArrayType * arrayType ) override final; |
---|
[7870799] | 205 | virtual void visit( const ArrayType * arrayType ) override final; |
---|
[5ea7a22] | 206 | virtual void visit( ReferenceType * referenceType ) override final; |
---|
[7870799] | 207 | virtual void visit( const ReferenceType * referenceType ) override final; |
---|
[c5d7701] | 208 | virtual void visit( QualifiedType * qualType ) override final; |
---|
[7870799] | 209 | virtual void visit( const QualifiedType * qualType ) override final; |
---|
[5ea7a22] | 210 | virtual void visit( FunctionType * functionType ) override final; |
---|
[7870799] | 211 | virtual void visit( const FunctionType * functionType ) override final; |
---|
[5ea7a22] | 212 | virtual void visit( StructInstType * aggregateUseType ) override final; |
---|
[7870799] | 213 | virtual void visit( const StructInstType * aggregateUseType ) override final; |
---|
[5ea7a22] | 214 | virtual void visit( UnionInstType * aggregateUseType ) override final; |
---|
[7870799] | 215 | virtual void visit( const UnionInstType * aggregateUseType ) override final; |
---|
[5ea7a22] | 216 | virtual void visit( EnumInstType * aggregateUseType ) override final; |
---|
[7870799] | 217 | virtual void visit( const EnumInstType * aggregateUseType ) override final; |
---|
[5ea7a22] | 218 | virtual void visit( TraitInstType * aggregateUseType ) override final; |
---|
[7870799] | 219 | virtual void visit( const TraitInstType * aggregateUseType ) override final; |
---|
[5ea7a22] | 220 | virtual void visit( TypeInstType * aggregateUseType ) override final; |
---|
[7870799] | 221 | virtual void visit( const TypeInstType * aggregateUseType ) override final; |
---|
[5ea7a22] | 222 | virtual void visit( TupleType * tupleType ) override final; |
---|
[7870799] | 223 | virtual void visit( const TupleType * tupleType ) override final; |
---|
[5ea7a22] | 224 | virtual void visit( TypeofType * typeofType ) override final; |
---|
[7870799] | 225 | virtual void visit( const TypeofType * typeofType ) override final; |
---|
[5ea7a22] | 226 | virtual void visit( AttrType * attrType ) override final; |
---|
[7870799] | 227 | virtual void visit( const AttrType * attrType ) override final; |
---|
[5ea7a22] | 228 | virtual void visit( VarArgsType * varArgsType ) override final; |
---|
[7870799] | 229 | virtual void visit( const VarArgsType * varArgsType ) override final; |
---|
[5ea7a22] | 230 | virtual void visit( ZeroType * zeroType ) override final; |
---|
[7870799] | 231 | virtual void visit( const ZeroType * zeroType ) override final; |
---|
[5ea7a22] | 232 | virtual void visit( OneType * oneType ) override final; |
---|
[7870799] | 233 | virtual void visit( const OneType * oneType ) override final; |
---|
[47498bd] | 234 | virtual void visit( GlobalScopeType * globalType ) override final; |
---|
[7870799] | 235 | virtual void visit( const GlobalScopeType * globalType ) override final; |
---|
[5ea7a22] | 236 | |
---|
| 237 | virtual void visit( Designation * designation ) override final; |
---|
[7870799] | 238 | virtual void visit( const Designation * designation ) override final; |
---|
[5ea7a22] | 239 | virtual void visit( SingleInit * singleInit ) override final; |
---|
[7870799] | 240 | virtual void visit( const SingleInit * singleInit ) override final; |
---|
[5ea7a22] | 241 | virtual void visit( ListInit * listInit ) override final; |
---|
[7870799] | 242 | virtual void visit( const ListInit * listInit ) override final; |
---|
[5ea7a22] | 243 | virtual void visit( ConstructorInit * ctorInit ) override final; |
---|
[7870799] | 244 | virtual void visit( const ConstructorInit * ctorInit ) override final; |
---|
[5ea7a22] | 245 | |
---|
| 246 | virtual void visit( Constant * constant ) override final; |
---|
[7870799] | 247 | virtual void visit( const Constant * constant ) override final; |
---|
[5ea7a22] | 248 | |
---|
| 249 | virtual void visit( Attribute * attribute ) override final; |
---|
[7870799] | 250 | virtual void visit( const Attribute * attribute ) override final; |
---|
[5ea7a22] | 251 | |
---|
| 252 | virtual DeclarationWithType * mutate( ObjectDecl * objectDecl ) override final; |
---|
| 253 | virtual DeclarationWithType * mutate( FunctionDecl * functionDecl ) override final; |
---|
| 254 | virtual Declaration * mutate( StructDecl * aggregateDecl ) override final; |
---|
| 255 | virtual Declaration * mutate( UnionDecl * aggregateDecl ) override final; |
---|
| 256 | virtual Declaration * mutate( EnumDecl * aggregateDecl ) override final; |
---|
| 257 | virtual Declaration * mutate( TraitDecl * aggregateDecl ) override final; |
---|
| 258 | virtual Declaration * mutate( TypeDecl * typeDecl ) override final; |
---|
| 259 | virtual Declaration * mutate( TypedefDecl * typeDecl ) override final; |
---|
| 260 | virtual AsmDecl * mutate( AsmDecl * asmDecl ) override final; |
---|
[f6e3e34] | 261 | virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final; |
---|
[5ea7a22] | 262 | |
---|
| 263 | virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override final; |
---|
| 264 | virtual Statement * mutate( ExprStmt * exprStmt ) override final; |
---|
| 265 | virtual Statement * mutate( AsmStmt * asmStmt ) override final; |
---|
[cc32d83] | 266 | virtual Statement * mutate( DirectiveStmt * dirStmt ) override final; |
---|
[5ea7a22] | 267 | virtual Statement * mutate( IfStmt * ifStmt ) override final; |
---|
| 268 | virtual Statement * mutate( WhileStmt * whileStmt ) override final; |
---|
| 269 | virtual Statement * mutate( ForStmt * forStmt ) override final; |
---|
| 270 | virtual Statement * mutate( SwitchStmt * switchStmt ) override final; |
---|
| 271 | virtual Statement * mutate( CaseStmt * caseStmt ) override final; |
---|
| 272 | virtual Statement * mutate( BranchStmt * branchStmt ) override final; |
---|
| 273 | virtual Statement * mutate( ReturnStmt * returnStmt ) override final; |
---|
| 274 | virtual Statement * mutate( ThrowStmt * throwStmt ) override final; |
---|
| 275 | virtual Statement * mutate( TryStmt * tryStmt ) override final; |
---|
| 276 | virtual Statement * mutate( CatchStmt * catchStmt ) override final; |
---|
| 277 | virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; |
---|
| 278 | virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; |
---|
[e67991f] | 279 | virtual Declaration * mutate( WithStmt * withStmt ) override final; |
---|
[5ea7a22] | 280 | virtual NullStmt * mutate( NullStmt * nullStmt ) override final; |
---|
| 281 | virtual Statement * mutate( DeclStmt * declStmt ) override final; |
---|
| 282 | virtual Statement * mutate( ImplicitCtorDtorStmt * impCtorDtorStmt ) override final; |
---|
| 283 | |
---|
| 284 | virtual Expression * mutate( ApplicationExpr * applicationExpr ) override final; |
---|
| 285 | virtual Expression * mutate( UntypedExpr * untypedExpr ) override final; |
---|
| 286 | virtual Expression * mutate( NameExpr * nameExpr ) override final; |
---|
[9a705dc8] | 287 | virtual Expression * mutate( AddressExpr * addrExpr ) override final; |
---|
[5ea7a22] | 288 | virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) override final; |
---|
| 289 | virtual Expression * mutate( CastExpr * castExpr ) override final; |
---|
[9a705dc8] | 290 | virtual Expression * mutate( KeywordCastExpr * castExpr ) override final; |
---|
[5ea7a22] | 291 | virtual Expression * mutate( VirtualCastExpr * castExpr ) override final; |
---|
| 292 | virtual Expression * mutate( UntypedMemberExpr * memberExpr ) override final; |
---|
| 293 | virtual Expression * mutate( MemberExpr * memberExpr ) override final; |
---|
| 294 | virtual Expression * mutate( VariableExpr * variableExpr ) override final; |
---|
| 295 | virtual Expression * mutate( ConstantExpr * constantExpr ) override final; |
---|
| 296 | virtual Expression * mutate( SizeofExpr * sizeofExpr ) override final; |
---|
| 297 | virtual Expression * mutate( AlignofExpr * alignofExpr ) override final; |
---|
| 298 | virtual Expression * mutate( UntypedOffsetofExpr * offsetofExpr ) override final; |
---|
| 299 | virtual Expression * mutate( OffsetofExpr * offsetofExpr ) override final; |
---|
| 300 | virtual Expression * mutate( OffsetPackExpr * offsetPackExpr ) override final; |
---|
| 301 | virtual Expression * mutate( LogicalExpr * logicalExpr ) override final; |
---|
| 302 | virtual Expression * mutate( ConditionalExpr * conditionalExpr ) override final; |
---|
| 303 | virtual Expression * mutate( CommaExpr * commaExpr ) override final; |
---|
| 304 | virtual Expression * mutate( TypeExpr * typeExpr ) override final; |
---|
| 305 | virtual Expression * mutate( AsmExpr * asmExpr ) override final; |
---|
| 306 | virtual Expression * mutate( ImplicitCopyCtorExpr * impCpCtorExpr ) override final; |
---|
| 307 | virtual Expression * mutate( ConstructorExpr * ctorExpr ) override final; |
---|
| 308 | virtual Expression * mutate( CompoundLiteralExpr * compLitExpr ) override final; |
---|
| 309 | virtual Expression * mutate( RangeExpr * rangeExpr ) override final; |
---|
| 310 | virtual Expression * mutate( UntypedTupleExpr * tupleExpr ) override final; |
---|
| 311 | virtual Expression * mutate( TupleExpr * tupleExpr ) override final; |
---|
| 312 | virtual Expression * mutate( TupleIndexExpr * tupleExpr ) override final; |
---|
| 313 | virtual Expression * mutate( TupleAssignExpr * assignExpr ) override final; |
---|
| 314 | virtual Expression * mutate( StmtExpr * stmtExpr ) override final; |
---|
| 315 | virtual Expression * mutate( UniqueExpr * uniqueExpr ) override final; |
---|
[73367a8] | 316 | virtual Expression * mutate( UntypedInitExpr * initExpr ) override final; |
---|
| 317 | virtual Expression * mutate( InitExpr * initExpr ) override final; |
---|
[44b4114] | 318 | virtual Expression * mutate( DeletedExpr * delExpr ) override final; |
---|
[0f79853] | 319 | virtual Expression * mutate( DefaultArgExpr * argExpr ) override final; |
---|
[d807ca28] | 320 | virtual Expression * mutate( GenericExpr * genExpr ) override final; |
---|
[5ea7a22] | 321 | |
---|
| 322 | virtual Type * mutate( VoidType * basicType ) override final; |
---|
| 323 | virtual Type * mutate( BasicType * basicType ) override final; |
---|
| 324 | virtual Type * mutate( PointerType * pointerType ) override final; |
---|
| 325 | virtual Type * mutate( ArrayType * arrayType ) override final; |
---|
| 326 | virtual Type * mutate( ReferenceType * referenceType ) override final; |
---|
[c5d7701] | 327 | virtual Type * mutate( QualifiedType * qualType ) override final; |
---|
[5ea7a22] | 328 | virtual Type * mutate( FunctionType * functionType ) override final; |
---|
| 329 | virtual Type * mutate( StructInstType * aggregateUseType ) override final; |
---|
| 330 | virtual Type * mutate( UnionInstType * aggregateUseType ) override final; |
---|
| 331 | virtual Type * mutate( EnumInstType * aggregateUseType ) override final; |
---|
| 332 | virtual Type * mutate( TraitInstType * aggregateUseType ) override final; |
---|
| 333 | virtual Type * mutate( TypeInstType * aggregateUseType ) override final; |
---|
| 334 | virtual Type * mutate( TupleType * tupleType ) override final; |
---|
| 335 | virtual Type * mutate( TypeofType * typeofType ) override final; |
---|
| 336 | virtual Type * mutate( AttrType * attrType ) override final; |
---|
| 337 | virtual Type * mutate( VarArgsType * varArgsType ) override final; |
---|
| 338 | virtual Type * mutate( ZeroType * zeroType ) override final; |
---|
| 339 | virtual Type * mutate( OneType * oneType ) override final; |
---|
[47498bd] | 340 | virtual Type * mutate( GlobalScopeType * globalType ) override final; |
---|
[5ea7a22] | 341 | |
---|
| 342 | virtual Designation * mutate( Designation * designation ) override final; |
---|
| 343 | virtual Initializer * mutate( SingleInit * singleInit ) override final; |
---|
| 344 | virtual Initializer * mutate( ListInit * listInit ) override final; |
---|
| 345 | virtual Initializer * mutate( ConstructorInit * ctorInit ) override final; |
---|
| 346 | |
---|
| 347 | virtual Constant * mutate( Constant * constant ) override final; |
---|
| 348 | |
---|
| 349 | virtual Attribute * mutate( Attribute * attribute ) override final; |
---|
[447c356] | 350 | |
---|
| 351 | virtual TypeSubstitution * mutate( TypeSubstitution * sub ) final; |
---|
[ab904dc] | 352 | |
---|
[13932f14] | 353 | private: |
---|
[61d9b4b] | 354 | bool inFunction = false; |
---|
| 355 | |
---|
[6ca154b] | 356 | template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); |
---|
[7870799] | 357 | template<typename pass_t> friend void acceptAll( const std::list< const Declaration * > &decls, PassVisitor< pass_t >& visitor ); |
---|
[6ca154b] | 358 | template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); |
---|
[3c398b6] | 359 | template< typename TreeType, typename pass_t > friend void maybeAccept_impl( TreeType * tree, PassVisitor< pass_t > & visitor ); |
---|
[7870799] | 360 | template< typename TreeType, typename pass_t > friend void maybeAccept_impl( const TreeType * tree, PassVisitor< pass_t > & visitor ); |
---|
[3c398b6] | 361 | template< typename TreeType, typename pass_t > friend void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_t > & mutator ); |
---|
| 362 | template< typename Container, typename pass_t > friend void maybeAccept_impl( Container & container, PassVisitor< pass_t > & visitor ); |
---|
[7870799] | 363 | template< typename Container, typename pass_t > friend void maybeAccept_impl( const Container & container, PassVisitor< pass_t > & visitor ); |
---|
[3c398b6] | 364 | template< typename Container, typename pass_t > friend void maybeMutate_impl( Container & container, PassVisitor< pass_t > & mutator ); |
---|
[6ca154b] | 365 | |
---|
[296b2be] | 366 | template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); } |
---|
[7870799] | 367 | template<typename node_type> void call_previsit ( const node_type * node ) { previsit_impl ( pass, node, 0 ); } |
---|
[296b2be] | 368 | template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); } |
---|
[7870799] | 369 | template<typename node_type> void call_postvisit( const node_type * node ) { postvisit_impl( pass, node, 0 ); } |
---|
[13932f14] | 370 | |
---|
[296b2be] | 371 | template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); } |
---|
| 372 | template<typename return_type, typename node_type> return_type call_postmutate ( node_type * node ) { return postmutate_impl<return_type>( pass, node, 0 ); } |
---|
[ab904dc] | 373 | |
---|
[296b2be] | 374 | void call_beginScope() { begin_scope_impl( pass, 0 ); } |
---|
| 375 | void call_endScope () { end_scope_impl ( pass, 0 ); } |
---|
| 376 | |
---|
[3fb9a83] | 377 | void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); } |
---|
| 378 | |
---|
[6ca154b] | 379 | template< typename func_t > |
---|
| 380 | void handleStatementList( std::list< Statement * > & statements, func_t func ); |
---|
| 381 | void visitStatementList ( std::list< Statement* > &statements ); |
---|
[296b2be] | 382 | void mutateStatementList( std::list< Statement* > &statements ); |
---|
[7870799] | 383 | void visitStatementList ( const std::list< Statement * > & statements ); |
---|
[134322e] | 384 | |
---|
[6ca154b] | 385 | template< typename func_t > |
---|
| 386 | Statement * handleStatement( Statement * stmt, func_t func ); |
---|
| 387 | Statement * visitStatement ( Statement * stmt ); |
---|
[296b2be] | 388 | Statement * mutateStatement( Statement * stmt ); |
---|
[7870799] | 389 | void visitStatement ( const Statement * stmt ); |
---|
[134322e] | 390 | |
---|
[6ca154b] | 391 | template< typename func_t > |
---|
| 392 | Expression * handleExpression( Expression * expr, func_t func ); |
---|
| 393 | Expression * visitExpression ( Expression * expr ); |
---|
[296b2be] | 394 | Expression * mutateExpression( Expression * expr ); |
---|
[7870799] | 395 | void visitExpression ( const Expression * expr ); |
---|
[296b2be] | 396 | |
---|
[ab904dc] | 397 | |
---|
[02fdb8e] | 398 | auto get_env_ptr () -> decltype(env_impl( pass, 0)) { return env_impl( pass, 0); } |
---|
[134322e] | 399 | std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); } |
---|
| 400 | std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); } |
---|
[35df560] | 401 | std::list< Declaration* > * get_beforeDecls() { return declsToAddBefore_impl( pass, 0); } |
---|
| 402 | std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); } |
---|
[b73bd70] | 403 | |
---|
[3c398b6] | 404 | bool get_visit_children () { bool_ref * ptr = visit_children_impl(pass, 0); return ptr ? *ptr : true; } |
---|
| 405 | bool_ref * get_visit_children_ptr() { return visit_children_impl(pass, 0); } |
---|
[e0886db] | 406 | |
---|
[4670c79] | 407 | void indexerScopeEnter () { indexer_impl_enterScope ( pass, 0 ); } |
---|
| 408 | void indexerScopeLeave () { indexer_impl_leaveScope ( pass, 0 ); } |
---|
[e3d7f9f] | 409 | void indexerAddId ( const DeclarationWithType * node ) { indexer_impl_addId ( pass, 0, node ); } |
---|
| 410 | void indexerAddType ( const NamedTypeDecl * node ) { indexer_impl_addType ( pass, 0, node ); } |
---|
[4670c79] | 411 | void indexerAddStruct ( const std::string & id ) { indexer_impl_addStruct ( pass, 0, id ); } |
---|
[e3d7f9f] | 412 | void indexerAddStruct ( const StructDecl * node ) { indexer_impl_addStruct ( pass, 0, node ); } |
---|
| 413 | void indexerAddStructFwd( const StructDecl * node ) { indexer_impl_addStructFwd( pass, 0, node ); } |
---|
| 414 | void indexerAddEnum ( const EnumDecl * node ) { indexer_impl_addEnum ( pass, 0, node ); } |
---|
[4670c79] | 415 | void indexerAddUnion ( const std::string & id ) { indexer_impl_addUnion ( pass, 0, id ); } |
---|
[e3d7f9f] | 416 | void indexerAddUnion ( const UnionDecl * node ) { indexer_impl_addUnion ( pass, 0, node ); } |
---|
| 417 | void indexerAddUnionFwd ( const UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); } |
---|
| 418 | void indexerAddTrait ( const TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); } |
---|
[e67991f] | 419 | void indexerAddWith ( const std::list< Expression * > & exprs, const Declaration * withStmt ) { indexer_impl_addWith( pass, 0, exprs, withStmt ); } |
---|
[d8893ca] | 420 | |
---|
[e0886db] | 421 | |
---|
| 422 | template< typename TreeType, typename VisitorType > |
---|
[e3d7f9f] | 423 | friend inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ); |
---|
[e0886db] | 424 | |
---|
| 425 | template< typename TreeType, typename VisitorType > |
---|
[e3d7f9f] | 426 | friend inline void indexerScopedAccept( const TreeType * tree, VisitorType & visitor ); |
---|
| 427 | |
---|
| 428 | template< typename TreeType, typename VisitorType > |
---|
| 429 | friend inline void indexerScopedMutate( TreeType *& tree, VisitorType & visitor ); |
---|
[13932f14] | 430 | }; |
---|
| 431 | |
---|
[6e09f211] | 432 | template<typename pass_type, typename T> |
---|
| 433 | void GuardValue( pass_type * pass, T& val ) { |
---|
| 434 | pass->at_cleanup( [ val ]( void * newVal ) { |
---|
| 435 | * static_cast< T * >( newVal ) = val; |
---|
| 436 | }, static_cast< void * >( & val ) ); |
---|
| 437 | } |
---|
| 438 | |
---|
[637568b] | 439 | class WithTypeSubstitution { |
---|
| 440 | protected: |
---|
| 441 | WithTypeSubstitution() = default; |
---|
| 442 | ~WithTypeSubstitution() = default; |
---|
| 443 | |
---|
[4eb31f2b] | 444 | public: |
---|
[d24d4e1] | 445 | TypeSubstitution * env = nullptr; |
---|
[637568b] | 446 | }; |
---|
| 447 | |
---|
[02fdb8e] | 448 | class WithConstTypeSubstitution { |
---|
| 449 | protected: |
---|
| 450 | WithConstTypeSubstitution() = default; |
---|
| 451 | ~WithConstTypeSubstitution() = default; |
---|
| 452 | |
---|
| 453 | public: |
---|
| 454 | const TypeSubstitution * env = nullptr; |
---|
| 455 | }; |
---|
| 456 | |
---|
[637568b] | 457 | class WithStmtsToAdd { |
---|
| 458 | protected: |
---|
| 459 | WithStmtsToAdd() = default; |
---|
| 460 | ~WithStmtsToAdd() = default; |
---|
| 461 | |
---|
[4eb31f2b] | 462 | public: |
---|
[637568b] | 463 | std::list< Statement* > stmtsToAddBefore; |
---|
| 464 | std::list< Statement* > stmtsToAddAfter; |
---|
| 465 | }; |
---|
[d24d4e1] | 466 | |
---|
| 467 | class WithDeclsToAdd { |
---|
| 468 | protected: |
---|
| 469 | WithDeclsToAdd() = default; |
---|
[e0886db] | 470 | ~WithDeclsToAdd() { |
---|
| 471 | assert( declsToAddBefore.empty() ); |
---|
| 472 | } |
---|
[d24d4e1] | 473 | |
---|
| 474 | public: |
---|
| 475 | std::list< Declaration* > declsToAddBefore; |
---|
| 476 | std::list< Declaration* > declsToAddAfter; |
---|
| 477 | }; |
---|
| 478 | |
---|
[637568b] | 479 | class WithShortCircuiting { |
---|
| 480 | protected: |
---|
| 481 | WithShortCircuiting() = default; |
---|
| 482 | ~WithShortCircuiting() = default; |
---|
| 483 | |
---|
[4eb31f2b] | 484 | public: |
---|
[b73bd70] | 485 | bool_ref visit_children; |
---|
[637568b] | 486 | }; |
---|
| 487 | |
---|
[d24d4e1] | 488 | class WithGuards { |
---|
[637568b] | 489 | protected: |
---|
[d24d4e1] | 490 | WithGuards() = default; |
---|
| 491 | ~WithGuards() = default; |
---|
[637568b] | 492 | |
---|
[4eb31f2b] | 493 | public: |
---|
[637568b] | 494 | at_cleanup_t at_cleanup; |
---|
| 495 | |
---|
[4eb31f2b] | 496 | template< typename T > |
---|
[637568b] | 497 | void GuardValue( T& val ) { |
---|
| 498 | at_cleanup( [ val ]( void * newVal ) { |
---|
| 499 | * static_cast< T * >( newVal ) = val; |
---|
| 500 | }, static_cast< void * >( & val ) ); |
---|
| 501 | } |
---|
[5dd0704] | 502 | |
---|
[d24d4e1] | 503 | template< typename T > |
---|
| 504 | void GuardScope( T& val ) { |
---|
| 505 | val.beginScope(); |
---|
| 506 | at_cleanup( []( void * val ) { |
---|
| 507 | static_cast< T * >( val )->endScope(); |
---|
| 508 | }, static_cast< void * >( & val ) ); |
---|
| 509 | } |
---|
| 510 | |
---|
[5dd0704] | 511 | template< typename Func > |
---|
[d24d4e1] | 512 | void GuardAction( Func func ) { |
---|
| 513 | at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr ); |
---|
[5dd0704] | 514 | } |
---|
[637568b] | 515 | }; |
---|
| 516 | |
---|
[b73bd70] | 517 | template<typename pass_type> |
---|
| 518 | class WithVisitorRef { |
---|
| 519 | protected: |
---|
[d24d4e1] | 520 | WithVisitorRef() {} |
---|
| 521 | ~WithVisitorRef() {} |
---|
[b73bd70] | 522 | |
---|
| 523 | public: |
---|
[d24d4e1] | 524 | PassVisitor<pass_type> * const visitor = nullptr; |
---|
[b73bd70] | 525 | }; |
---|
[637568b] | 526 | |
---|
[e0886db] | 527 | class WithIndexer { |
---|
| 528 | protected: |
---|
| 529 | WithIndexer() {} |
---|
| 530 | ~WithIndexer() {} |
---|
| 531 | |
---|
| 532 | public: |
---|
| 533 | SymTab::Indexer indexer; |
---|
| 534 | }; |
---|
| 535 | |
---|
[675716e] | 536 | #include "Common/Stats.h" |
---|
| 537 | |
---|
| 538 | extern struct PassVisitorStats { |
---|
| 539 | size_t depth = 0; |
---|
| 540 | Stats::Counters::MaxCounter<double> * max = nullptr; |
---|
| 541 | Stats::Counters::AverageCounter<double> * avg = nullptr; |
---|
| 542 | } pass_visitor_stats; |
---|
| 543 | |
---|
[07c178f0] | 544 | #include "SynTree/TypeSubstitution.h" |
---|
[aff3af4] | 545 | #include "PassVisitor.impl.h" |
---|