1 /**
2  * Defines a visitor for the AST.
3  *
4  * Other visitors derive from this class.
5  *
6  * Documentation:  https://dlang.org/phobos/dmd_parsetimevisitor.html
7  * Coverage:    https://codecov.io/gh/dlang/dmd/src/master/src/dmd/parsetimevisitor.d
8  */
9 
10 module dmd.parsetimevisitor;
11 
12 /** Basic and dumm visitor which implements a visit method for each AST node
13   * implemented in AST. This visitor is the parent of strict, transitive
14   * and permissive visitors.
15   */
16 extern (C++) class ParseTimeVisitor(AST)
17 {
18 public:
19     void visit(AST.Dsymbol) { assert(0); }
20     void visit(AST.Parameter) { assert(0); }
21     void visit(AST.Statement) { assert(0); }
22     void visit(AST.Type) { assert(0); }
23     void visit(AST.Expression) { assert(0); }
24     void visit(AST.TemplateParameter) { assert(0); }
25     void visit(AST.Condition) { assert(0); }
26     void visit(AST.Initializer) { assert(0); }
27 
28     //=======================================================================================
29     // Dsymbols
30     void visit(AST.AliasThis s) { visit(cast(AST.Dsymbol)s); }
31     void visit(AST.Declaration s) { visit(cast(AST.Dsymbol)s); }
32     void visit(AST.ScopeDsymbol s) { visit(cast(AST.Dsymbol)s); }
33     void visit(AST.Import s) { visit(cast(AST.Dsymbol)s); }
34     void visit(AST.AttribDeclaration s) { visit(cast(AST.Dsymbol)s); }
35     void visit(AST.StaticAssert s) { visit(cast(AST.Dsymbol)s); }
36     void visit(AST.DebugSymbol s) { visit(cast(AST.Dsymbol)s); }
37     void visit(AST.VersionSymbol s) { visit(cast(AST.Dsymbol)s); }
38 
39     // ScopeDsymbols
40     void visit(AST.Package s) { visit(cast(AST.ScopeDsymbol)s); }
41     void visit(AST.EnumDeclaration s) { visit(cast(AST.ScopeDsymbol)s); }
42     void visit(AST.AggregateDeclaration s) { visit(cast(AST.ScopeDsymbol)s); }
43     void visit(AST.TemplateDeclaration s) { visit(cast(AST.ScopeDsymbol)s); }
44     void visit(AST.TemplateInstance s) { visit(cast(AST.ScopeDsymbol)s); }
45     void visit(AST.Nspace s) { visit(cast(AST.ScopeDsymbol)s); }
46 
47     //=========================================================================================
48     // Declarations
49     void visit(AST.VarDeclaration s) { visit(cast(AST.Declaration)s); }
50     void visit(AST.FuncDeclaration s) { visit(cast(AST.Declaration)s); }
51     void visit(AST.AliasDeclaration s) { visit(cast(AST.Declaration)s); }
52     void visit(AST.TupleDeclaration s) { visit(cast(AST.Declaration)s); }
53 
54     // FuncDeclarations
55     void visit(AST.FuncLiteralDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
56     void visit(AST.PostBlitDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
57     void visit(AST.CtorDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
58     void visit(AST.DtorDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
59     void visit(AST.InvariantDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
60     void visit(AST.UnitTestDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
61     void visit(AST.NewDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
62     void visit(AST.StaticCtorDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
63     void visit(AST.StaticDtorDeclaration s) { visit(cast(AST.FuncDeclaration)s); }
64     void visit(AST.SharedStaticCtorDeclaration s) { visit(cast(AST.StaticCtorDeclaration)s); }
65     void visit(AST.SharedStaticDtorDeclaration s) { visit(cast(AST.StaticDtorDeclaration)s); }
66 
67     // AttribDeclarations
68     void visit(AST.CompileDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
69     void visit(AST.UserAttributeDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
70     void visit(AST.LinkDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
71     void visit(AST.AnonDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
72     void visit(AST.AlignDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
73     void visit(AST.CPPMangleDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
74     void visit(AST.CPPNamespaceDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
75     void visit(AST.ProtDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
76     void visit(AST.PragmaDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
77     void visit(AST.StorageClassDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
78     void visit(AST.ConditionalDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
79     void visit(AST.StaticForeachDeclaration s) { visit(cast(AST.AttribDeclaration)s); }
80 
81     //==============================================================================================
82     // Miscellaneous
83     void visit(AST.DeprecatedDeclaration s) { visit(cast(AST.StorageClassDeclaration)s); }
84     void visit(AST.StaticIfDeclaration s) { visit(cast(AST.ConditionalDeclaration)s); }
85     void visit(AST.EnumMember s) { visit(cast(AST.VarDeclaration)s); }
86     void visit(AST.Module s) { visit(cast(AST.Package)s); }
87     void visit(AST.StructDeclaration s) { visit(cast(AST.AggregateDeclaration)s); }
88     void visit(AST.UnionDeclaration s) { visit(cast(AST.StructDeclaration)s); }
89     void visit(AST.ClassDeclaration s) { visit(cast(AST.AggregateDeclaration)s); }
90     void visit(AST.InterfaceDeclaration s) { visit(cast(AST.ClassDeclaration)s); }
91     void visit(AST.TemplateMixin s) { visit(cast(AST.TemplateInstance)s); }
92 
93     //============================================================================================
94     // Statements
95     void visit(AST.ImportStatement s) { visit(cast(AST.Statement)s); }
96     void visit(AST.ScopeStatement s) { visit(cast(AST.Statement)s); }
97     void visit(AST.ReturnStatement s) { visit(cast(AST.Statement)s); }
98     void visit(AST.LabelStatement s) { visit(cast(AST.Statement)s); }
99     void visit(AST.StaticAssertStatement s) { visit(cast(AST.Statement)s); }
100     void visit(AST.CompileStatement s) { visit(cast(AST.Statement)s); }
101     void visit(AST.WhileStatement s) { visit(cast(AST.Statement)s); }
102     void visit(AST.ForStatement s) { visit(cast(AST.Statement)s); }
103     void visit(AST.DoStatement s) { visit(cast(AST.Statement)s); }
104     void visit(AST.ForeachRangeStatement s) { visit(cast(AST.Statement)s); }
105     void visit(AST.ForeachStatement s) { visit(cast(AST.Statement)s); }
106     void visit(AST.IfStatement s) { visit(cast(AST.Statement)s); }
107     void visit(AST.ScopeGuardStatement s) { visit(cast(AST.Statement)s); }
108     void visit(AST.ConditionalStatement s) { visit(cast(AST.Statement)s); }
109     void visit(AST.StaticForeachStatement s) { visit(cast(AST.Statement)s); }
110     void visit(AST.PragmaStatement s) { visit(cast(AST.Statement)s); }
111     void visit(AST.SwitchStatement s) { visit(cast(AST.Statement)s); }
112     void visit(AST.CaseRangeStatement s) { visit(cast(AST.Statement)s); }
113     void visit(AST.CaseStatement s) { visit(cast(AST.Statement)s); }
114     void visit(AST.DefaultStatement s) { visit(cast(AST.Statement)s); }
115     void visit(AST.BreakStatement s) { visit(cast(AST.Statement)s); }
116     void visit(AST.ContinueStatement s) { visit(cast(AST.Statement)s); }
117     void visit(AST.GotoDefaultStatement s) { visit(cast(AST.Statement)s); }
118     void visit(AST.GotoCaseStatement s) { visit(cast(AST.Statement)s); }
119     void visit(AST.GotoStatement s) { visit(cast(AST.Statement)s); }
120     void visit(AST.SynchronizedStatement s) { visit(cast(AST.Statement)s); }
121     void visit(AST.WithStatement s) { visit(cast(AST.Statement)s); }
122     void visit(AST.TryCatchStatement s) { visit(cast(AST.Statement)s); }
123     void visit(AST.TryFinallyStatement s) { visit(cast(AST.Statement)s); }
124     void visit(AST.ThrowStatement s) { visit(cast(AST.Statement)s); }
125     void visit(AST.AsmStatement s) { visit(cast(AST.Statement)s); }
126     void visit(AST.ExpStatement s) { visit(cast(AST.Statement)s); }
127     void visit(AST.CompoundStatement s) { visit(cast(AST.Statement)s); }
128 
129     // CompoundStatements
130     void visit(AST.CompoundDeclarationStatement s) { visit(cast(AST.CompoundStatement)s); }
131     void visit(AST.CompoundAsmStatement s) { visit(cast(AST.CompoundStatement)s); }
132 
133     // AsmStatements
134     void visit(AST.InlineAsmStatement s) { visit(cast(AST.AsmStatement)s); }
135     void visit(AST.GccAsmStatement s) { visit(cast(AST.AsmStatement)s); }
136 
137     //=========================================================================================
138     // Types
139     void visit(AST.TypeBasic t) { visit(cast(AST.Type)t); }
140     void visit(AST.TypeError t) { visit(cast(AST.Type)t); }
141     void visit(AST.TypeNull t) { visit(cast(AST.Type)t); }
142     void visit(AST.TypeVector t) { visit(cast(AST.Type)t); }
143     void visit(AST.TypeEnum t) { visit(cast(AST.Type)t); }
144     void visit(AST.TypeTuple t) { visit(cast(AST.Type)t); }
145     void visit(AST.TypeClass t) { visit(cast(AST.Type)t); }
146     void visit(AST.TypeStruct t) { visit(cast(AST.Type)t); }
147     void visit(AST.TypeNext t) { visit(cast(AST.Type)t); }
148     void visit(AST.TypeQualified t) { visit(cast(AST.Type)t); }
149     void visit(AST.TypeTraits t) { visit(cast(AST.Type)t); }
150     void visit(AST.TypeMixin t) { visit(cast(AST.Type)t); }
151 
152     // TypeNext
153     void visit(AST.TypeReference t) { visit(cast(AST.TypeNext)t); }
154     void visit(AST.TypeSlice t) { visit(cast(AST.TypeNext)t); }
155     void visit(AST.TypeDelegate t) { visit(cast(AST.TypeNext)t); }
156     void visit(AST.TypePointer t) { visit(cast(AST.TypeNext)t); }
157     void visit(AST.TypeFunction t) { visit(cast(AST.TypeNext)t); }
158     void visit(AST.TypeArray t) { visit(cast(AST.TypeNext)t); }
159 
160     // TypeArray
161     void visit(AST.TypeDArray t) { visit(cast(AST.TypeArray)t); }
162     void visit(AST.TypeAArray t) { visit(cast(AST.TypeArray)t); }
163     void visit(AST.TypeSArray t) { visit(cast(AST.TypeArray)t); }
164 
165     // TypeQualified
166     void visit(AST.TypeIdentifier t) { visit(cast(AST.TypeQualified)t); }
167     void visit(AST.TypeReturn t) { visit(cast(AST.TypeQualified)t); }
168     void visit(AST.TypeTypeof t) { visit(cast(AST.TypeQualified)t); }
169     void visit(AST.TypeInstance t) { visit(cast(AST.TypeQualified)t); }
170 
171     //=================================================================================
172     // Expressions
173     void visit(AST.DeclarationExp e) { visit(cast(AST.Expression)e); }
174     void visit(AST.IntegerExp e) { visit(cast(AST.Expression)e); }
175     void visit(AST.NewAnonClassExp e) { visit(cast(AST.Expression)e); }
176     void visit(AST.IsExp e) { visit(cast(AST.Expression)e); }
177     void visit(AST.RealExp e) { visit(cast(AST.Expression)e); }
178     void visit(AST.NullExp e) { visit(cast(AST.Expression)e); }
179     void visit(AST.TypeidExp e) { visit(cast(AST.Expression)e); }
180     void visit(AST.TraitsExp e) { visit(cast(AST.Expression)e); }
181     void visit(AST.StringExp e) { visit(cast(AST.Expression)e); }
182     void visit(AST.NewExp e) { visit(cast(AST.Expression)e); }
183     void visit(AST.AssocArrayLiteralExp e) { visit(cast(AST.Expression)e); }
184     void visit(AST.ArrayLiteralExp e) { visit(cast(AST.Expression)e); }
185     void visit(AST.CompileExp e) { visit(cast(AST.Expression)e); }
186     void visit(AST.FuncExp e) { visit(cast(AST.Expression)e); }
187     void visit(AST.IntervalExp e) { visit(cast(AST.Expression)e); }
188     void visit(AST.TypeExp e) { visit(cast(AST.Expression)e); }
189     void visit(AST.ScopeExp e) { visit(cast(AST.Expression)e); }
190     void visit(AST.IdentifierExp e) { visit(cast(AST.Expression)e); }
191     void visit(AST.UnaExp e) { visit(cast(AST.Expression)e); }
192     void visit(AST.DefaultInitExp e) { visit(cast(AST.Expression)e); }
193     void visit(AST.BinExp e) { visit(cast(AST.Expression)e); }
194     void visit(AST.DsymbolExp e) { visit(cast(AST.Expression)e); }
195     void visit(AST.TemplateExp e) { visit(cast(AST.Expression)e); }
196     void visit(AST.SymbolExp e) { visit(cast(AST.Expression)e); }
197     void visit(AST.TupleExp e) { visit(cast(AST.Expression)e); }
198     void visit(AST.ThisExp e) { visit(cast(AST.Expression)e); }
199 
200     // Miscellaneous
201     void visit(AST.VarExp e) { visit(cast(AST.SymbolExp)e); }
202     void visit(AST.DollarExp e) { visit(cast(AST.IdentifierExp)e); }
203     void visit(AST.SuperExp e) { visit(cast(AST.ThisExp)e); }
204 
205     // UnaExp
206     void visit(AST.AddrExp e) { visit(cast(AST.UnaExp)e); }
207     void visit(AST.PreExp e) { visit(cast(AST.UnaExp)e); }
208     void visit(AST.PtrExp e) { visit(cast(AST.UnaExp)e); }
209     void visit(AST.NegExp e) { visit(cast(AST.UnaExp)e); }
210     void visit(AST.UAddExp e) { visit(cast(AST.UnaExp)e); }
211     void visit(AST.NotExp e) { visit(cast(AST.UnaExp)e); }
212     void visit(AST.ComExp e) { visit(cast(AST.UnaExp)e); }
213     void visit(AST.DeleteExp e) { visit(cast(AST.UnaExp)e); }
214     void visit(AST.CastExp e) { visit(cast(AST.UnaExp)e); }
215     void visit(AST.CallExp e) { visit(cast(AST.UnaExp)e); }
216     void visit(AST.DotIdExp e) { visit(cast(AST.UnaExp)e); }
217     void visit(AST.AssertExp e) { visit(cast(AST.UnaExp)e); }
218     void visit(AST.ImportExp e) { visit(cast(AST.UnaExp)e); }
219     void visit(AST.DotTemplateInstanceExp e) { visit(cast(AST.UnaExp)e); }
220     void visit(AST.ArrayExp e) { visit(cast(AST.UnaExp)e); }
221 
222     // DefaultInitExp
223     void visit(AST.FuncInitExp e) { visit(cast(AST.DefaultInitExp)e); }
224     void visit(AST.PrettyFuncInitExp e) { visit(cast(AST.DefaultInitExp)e); }
225     void visit(AST.FileInitExp e) { visit(cast(AST.DefaultInitExp)e); }
226     void visit(AST.LineInitExp e) { visit(cast(AST.DefaultInitExp)e); }
227     void visit(AST.ModuleInitExp e) { visit(cast(AST.DefaultInitExp)e); }
228 
229     // BinExp
230     void visit(AST.CommaExp e) { visit(cast(AST.BinExp)e); }
231     void visit(AST.PostExp e) { visit(cast(AST.BinExp)e); }
232     void visit(AST.PowExp e) { visit(cast(AST.BinExp)e); }
233     void visit(AST.MulExp e) { visit(cast(AST.BinExp)e); }
234     void visit(AST.DivExp e) { visit(cast(AST.BinExp)e); }
235     void visit(AST.ModExp e) { visit(cast(AST.BinExp)e); }
236     void visit(AST.AddExp e) { visit(cast(AST.BinExp)e); }
237     void visit(AST.MinExp e) { visit(cast(AST.BinExp)e); }
238     void visit(AST.CatExp e) { visit(cast(AST.BinExp)e); }
239     void visit(AST.ShlExp e) { visit(cast(AST.BinExp)e); }
240     void visit(AST.ShrExp e) { visit(cast(AST.BinExp)e); }
241     void visit(AST.UshrExp e) { visit(cast(AST.BinExp)e); }
242     void visit(AST.EqualExp e) { visit(cast(AST.BinExp)e); }
243     void visit(AST.InExp e) { visit(cast(AST.BinExp)e); }
244     void visit(AST.IdentityExp e) { visit(cast(AST.BinExp)e); }
245     void visit(AST.CmpExp e) { visit(cast(AST.BinExp)e); }
246     void visit(AST.AndExp e) { visit(cast(AST.BinExp)e); }
247     void visit(AST.XorExp e) { visit(cast(AST.BinExp)e); }
248     void visit(AST.OrExp e) { visit(cast(AST.BinExp)e); }
249     void visit(AST.LogicalExp e) { visit(cast(AST.BinExp)e); }
250     void visit(AST.CondExp e) { visit(cast(AST.BinExp)e); }
251     void visit(AST.AssignExp e) { visit(cast(AST.BinExp)e); }
252     void visit(AST.BinAssignExp e) { visit(cast(AST.BinExp)e); }
253 
254     // BinAssignExp
255     void visit(AST.AddAssignExp e) { visit(cast(AST.BinAssignExp)e); }
256     void visit(AST.MinAssignExp e) { visit(cast(AST.BinAssignExp)e); }
257     void visit(AST.MulAssignExp e) { visit(cast(AST.BinAssignExp)e); }
258     void visit(AST.DivAssignExp e) { visit(cast(AST.BinAssignExp)e); }
259     void visit(AST.ModAssignExp e) { visit(cast(AST.BinAssignExp)e); }
260     void visit(AST.PowAssignExp e) { visit(cast(AST.BinAssignExp)e); }
261     void visit(AST.AndAssignExp e) { visit(cast(AST.BinAssignExp)e); }
262     void visit(AST.OrAssignExp e) { visit(cast(AST.BinAssignExp)e); }
263     void visit(AST.XorAssignExp e) { visit(cast(AST.BinAssignExp)e); }
264     void visit(AST.ShlAssignExp e) { visit(cast(AST.BinAssignExp)e); }
265     void visit(AST.ShrAssignExp e) { visit(cast(AST.BinAssignExp)e); }
266     void visit(AST.UshrAssignExp e) { visit(cast(AST.BinAssignExp)e); }
267     void visit(AST.CatAssignExp e) { visit(cast(AST.BinAssignExp)e); }
268 
269     //===============================================================================
270     // TemplateParameter
271     void visit(AST.TemplateAliasParameter tp) { visit(cast(AST.TemplateParameter)tp); }
272     void visit(AST.TemplateTypeParameter tp) { visit(cast(AST.TemplateParameter)tp); }
273     void visit(AST.TemplateTupleParameter tp) { visit(cast(AST.TemplateParameter)tp); }
274     void visit(AST.TemplateValueParameter tp) { visit(cast(AST.TemplateParameter)tp); }
275 
276     void visit(AST.TemplateThisParameter tp) { visit(cast(AST.TemplateTypeParameter)tp); }
277 
278     //===============================================================================
279     // Condition
280     void visit(AST.StaticIfCondition c) { visit(cast(AST.Condition)c); }
281     void visit(AST.DVCondition c) { visit(cast(AST.Condition)c); }
282     void visit(AST.DebugCondition c) { visit(cast(AST.DVCondition)c); }
283     void visit(AST.VersionCondition c) { visit(cast(AST.DVCondition)c); }
284 
285     //===============================================================================
286     // Initializer
287     void visit(AST.ExpInitializer i) { visit(cast(AST.Initializer)i); }
288     void visit(AST.StructInitializer i) { visit(cast(AST.Initializer)i); }
289     void visit(AST.ArrayInitializer i) { visit(cast(AST.Initializer)i); }
290     void visit(AST.VoidInitializer i) { visit(cast(AST.Initializer)i); }
291 }