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