Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===-- include/flang/Parser/dump-parse-tree.h ------------------*- C++ -*-===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef FORTRAN_PARSER_DUMP_PARSE_TREE_H_ |
10 | #define FORTRAN_PARSER_DUMP_PARSE_TREE_H_ |
11 | |
12 | #include "format-specification.h" |
13 | #include "parse-tree-visitor.h" |
14 | #include "parse-tree.h" |
15 | #include "tools.h" |
16 | #include "unparse.h" |
17 | #include "flang/Common/Fortran.h" |
18 | #include "flang/Common/idioms.h" |
19 | #include "flang/Common/indirection.h" |
20 | #include "llvm/Support/raw_ostream.h" |
21 | #include <string> |
22 | #include <type_traits> |
23 | |
24 | namespace Fortran::parser { |
25 | |
26 | // |
27 | // Dump the Parse Tree hierarchy of any node 'x' of the parse tree. |
28 | // |
29 | |
30 | class ParseTreeDumper { |
31 | public: |
32 | explicit ParseTreeDumper(llvm::raw_ostream &out, |
33 | const AnalyzedObjectsAsFortran *asFortran = nullptr) |
34 | : out_(out), asFortran_{asFortran} {} |
35 | |
36 | static constexpr const char *GetNodeName(const char *) { return "char *"; } |
37 | #define NODE_NAME(T, N) \ |
38 | static constexpr const char *GetNodeName(const T &) { return N; } |
39 | #define NODE_ENUM(T, E) \ |
40 | static std::string GetNodeName(const T::E &x) { \ |
41 | return #E " = "s + std::string{T::EnumToString(x)}; \ |
42 | } |
43 | #define NODE(T1, T2) NODE_NAME(T1::T2, #T2) |
44 | NODE_NAME(bool, "bool") |
45 | NODE_NAME(int, "int") |
46 | NODE(std, string) |
47 | NODE(std, int64_t) |
48 | NODE(std, uint64_t) |
49 | NODE_ENUM(common, CUDADataAttr) |
50 | NODE_ENUM(common, CUDASubprogramAttrs) |
51 | NODE_ENUM(common, OpenACCDeviceType) |
52 | NODE(format, ControlEditDesc) |
53 | NODE(format::ControlEditDesc, Kind) |
54 | NODE(format, DerivedTypeDataEditDesc) |
55 | NODE(format, FormatItem) |
56 | NODE(format, FormatSpecification) |
57 | NODE(format, IntrinsicTypeDataEditDesc) |
58 | NODE(format::IntrinsicTypeDataEditDesc, Kind) |
59 | NODE(parser, Abstract) |
60 | NODE(parser, AccAtomicCapture) |
61 | NODE(AccAtomicCapture, Stmt1) |
62 | NODE(AccAtomicCapture, Stmt2) |
63 | NODE(parser, AccAtomicRead) |
64 | NODE(parser, AccAtomicUpdate) |
65 | NODE(parser, AccAtomicWrite) |
66 | NODE(parser, AccBeginBlockDirective) |
67 | NODE(parser, AccBeginCombinedDirective) |
68 | NODE(parser, AccBeginLoopDirective) |
69 | NODE(parser, AccBlockDirective) |
70 | NODE(parser, AccClause) |
71 | #define GEN_FLANG_DUMP_PARSE_TREE_CLAUSES |
72 | #include "llvm/Frontend/OpenACC/ACC.inc" |
73 | NODE(parser, AccBindClause) |
74 | NODE(parser, AccDefaultClause) |
75 | static std::string GetNodeName(const llvm::acc::DefaultValue &x) { |
76 | return llvm::Twine( |
77 | "llvm::acc::DefaultValue = ", llvm::acc::getOpenACCDefaultValueName(x)) |
78 | .str(); |
79 | } |
80 | NODE(parser, AccClauseList) |
81 | NODE(parser, AccCombinedDirective) |
82 | NODE(parser, AccDataModifier) |
83 | NODE_ENUM(parser::AccDataModifier, Modifier) |
84 | NODE(parser, AccDeclarativeDirective) |
85 | NODE(parser, AccEndAtomic) |
86 | NODE(parser, AccEndBlockDirective) |
87 | NODE(parser, AccEndCombinedDirective) |
88 | NODE(parser, AccCollapseArg) |
89 | NODE(parser, AccGangArg) |
90 | NODE(AccGangArg, Num) |
91 | NODE(AccGangArg, Dim) |
92 | NODE(AccGangArg, Static) |
93 | NODE(parser, AccGangArgList) |
94 | NODE(parser, AccObject) |
95 | NODE(parser, AccObjectList) |
96 | NODE(parser, AccObjectListWithModifier) |
97 | NODE(parser, AccObjectListWithReduction) |
98 | NODE(parser, AccReductionOperator) |
99 | NODE_ENUM(parser::AccReductionOperator, Operator) |
100 | NODE(parser, AccSizeExpr) |
101 | NODE(parser, AccSizeExprList) |
102 | NODE(parser, AccSelfClause) |
103 | NODE(parser, AccStandaloneDirective) |
104 | NODE(parser, AccDeviceTypeExpr) |
105 | |
106 | NODE(parser, AccDeviceTypeExprList) |
107 | NODE(parser, AccTileExpr) |
108 | NODE(parser, AccTileExprList) |
109 | NODE(parser, AccLoopDirective) |
110 | NODE(parser, AccEndLoop) |
111 | NODE(parser, AccWaitArgument) |
112 | static std::string GetNodeName(const llvm::acc::Directive &x) { |
113 | return llvm::Twine( |
114 | "llvm::acc::Directive = ", llvm::acc::getOpenACCDirectiveName(x)) |
115 | .str(); |
116 | } |
117 | NODE(parser, AcImpliedDo) |
118 | NODE(parser, AcImpliedDoControl) |
119 | NODE(parser, AcValue) |
120 | NODE(parser, AccessStmt) |
121 | NODE(parser, AccessId) |
122 | NODE(parser, AccessSpec) |
123 | NODE_ENUM(AccessSpec, Kind) |
124 | NODE(parser, AcSpec) |
125 | NODE(parser, ActionStmt) |
126 | NODE(parser, ActualArg) |
127 | NODE(ActualArg, PercentRef) |
128 | NODE(ActualArg, PercentVal) |
129 | NODE(parser, ActualArgSpec) |
130 | NODE(AcValue, Triplet) |
131 | NODE(parser, AllocOpt) |
132 | NODE(AllocOpt, Mold) |
133 | NODE(AllocOpt, Source) |
134 | NODE(AllocOpt, Stream) |
135 | NODE(AllocOpt, Pinned) |
136 | NODE(parser, Allocatable) |
137 | NODE(parser, AllocatableStmt) |
138 | NODE(parser, AllocateCoarraySpec) |
139 | NODE(parser, AllocateObject) |
140 | NODE(parser, AllocateShapeSpec) |
141 | NODE(parser, AllocateStmt) |
142 | NODE(parser, Allocation) |
143 | NODE(parser, AltReturnSpec) |
144 | NODE(parser, ArithmeticIfStmt) |
145 | NODE(parser, ArrayConstructor) |
146 | NODE(parser, ArrayElement) |
147 | NODE(parser, ArraySpec) |
148 | NODE(parser, AssignStmt) |
149 | NODE(parser, AssignedGotoStmt) |
150 | NODE(parser, AssignmentStmt) |
151 | NODE(parser, AssociateConstruct) |
152 | NODE(parser, AssociateStmt) |
153 | NODE(parser, Association) |
154 | NODE(parser, AssumedImpliedSpec) |
155 | NODE(parser, AssumedRankSpec) |
156 | NODE(parser, AssumedShapeSpec) |
157 | NODE(parser, AssumedSizeSpec) |
158 | NODE(parser, Asynchronous) |
159 | NODE(parser, AsynchronousStmt) |
160 | NODE(parser, AttrSpec) |
161 | NODE(parser, BOZLiteralConstant) |
162 | NODE(parser, BackspaceStmt) |
163 | NODE(parser, BasedPointer) |
164 | NODE(parser, BasedPointerStmt) |
165 | NODE(parser, BindAttr) |
166 | NODE(BindAttr, Deferred) |
167 | NODE(BindAttr, Non_Overridable) |
168 | NODE(parser, BindEntity) |
169 | NODE_ENUM(BindEntity, Kind) |
170 | NODE(parser, BindStmt) |
171 | NODE(parser, Block) |
172 | NODE(parser, BlockConstruct) |
173 | NODE(parser, BlockData) |
174 | NODE(parser, BlockDataStmt) |
175 | NODE(parser, BlockSpecificationPart) |
176 | NODE(parser, BlockStmt) |
177 | NODE(parser, BoundsRemapping) |
178 | NODE(parser, BoundsSpec) |
179 | NODE(parser, Call) |
180 | NODE(parser, CallStmt) |
181 | NODE(CallStmt, Chevrons) |
182 | NODE(parser, CaseConstruct) |
183 | NODE(CaseConstruct, Case) |
184 | NODE(parser, CaseSelector) |
185 | NODE(parser, CaseStmt) |
186 | NODE(parser, CaseValueRange) |
187 | NODE(CaseValueRange, Range) |
188 | NODE(parser, ChangeTeamConstruct) |
189 | NODE(parser, ChangeTeamStmt) |
190 | NODE(parser, CharLength) |
191 | NODE(parser, CharLiteralConstant) |
192 | NODE(parser, CharLiteralConstantSubstring) |
193 | NODE(parser, CharSelector) |
194 | NODE(CharSelector, LengthAndKind) |
195 | NODE(parser, CloseStmt) |
196 | NODE(CloseStmt, CloseSpec) |
197 | NODE(parser, CoarrayAssociation) |
198 | NODE(parser, CoarraySpec) |
199 | NODE(parser, CodimensionDecl) |
200 | NODE(parser, CodimensionStmt) |
201 | NODE(parser, CoindexedNamedObject) |
202 | NODE(parser, CommonBlockObject) |
203 | NODE(parser, CommonStmt) |
204 | NODE(CommonStmt, Block) |
205 | NODE(parser, CompilerDirective) |
206 | NODE(CompilerDirective, IgnoreTKR) |
207 | NODE(CompilerDirective, LoopCount) |
208 | NODE(CompilerDirective, AssumeAligned) |
209 | NODE(CompilerDirective, NameValue) |
210 | NODE(CompilerDirective, Unrecognized) |
211 | NODE(parser, ComplexLiteralConstant) |
212 | NODE(parser, ComplexPart) |
213 | NODE(parser, ComponentArraySpec) |
214 | NODE(parser, ComponentAttrSpec) |
215 | NODE(parser, ComponentDataSource) |
216 | NODE(parser, ComponentDecl) |
217 | NODE(parser, FillDecl) |
218 | NODE(parser, ComponentOrFill) |
219 | NODE(parser, ComponentDefStmt) |
220 | NODE(parser, ComponentSpec) |
221 | NODE(parser, ComputedGotoStmt) |
222 | NODE(parser, ConcurrentControl) |
223 | NODE(parser, ConcurrentHeader) |
224 | NODE(parser, ConnectSpec) |
225 | NODE(ConnectSpec, CharExpr) |
226 | NODE_ENUM(ConnectSpec::CharExpr, Kind) |
227 | NODE(ConnectSpec, Newunit) |
228 | NODE(ConnectSpec, Recl) |
229 | NODE(parser, ContainsStmt) |
230 | NODE(parser, Contiguous) |
231 | NODE(parser, ContiguousStmt) |
232 | NODE(parser, ContinueStmt) |
233 | NODE(parser, CriticalConstruct) |
234 | NODE(parser, CriticalStmt) |
235 | NODE(parser, CUDAAttributesStmt) |
236 | NODE(parser, CUFKernelDoConstruct) |
237 | NODE(CUFKernelDoConstruct, StarOrExpr) |
238 | NODE(CUFKernelDoConstruct, Directive) |
239 | NODE(parser, CycleStmt) |
240 | NODE(parser, DataComponentDefStmt) |
241 | NODE(parser, DataIDoObject) |
242 | NODE(parser, DataImpliedDo) |
243 | NODE(parser, DataRef) |
244 | NODE(parser, DataStmt) |
245 | NODE(parser, DataStmtConstant) |
246 | NODE(parser, DataStmtObject) |
247 | NODE(parser, DataStmtRepeat) |
248 | NODE(parser, DataStmtSet) |
249 | NODE(parser, DataStmtValue) |
250 | NODE(parser, DeallocateStmt) |
251 | NODE(parser, DeclarationConstruct) |
252 | NODE(parser, DeclarationTypeSpec) |
253 | NODE(DeclarationTypeSpec, Class) |
254 | NODE(DeclarationTypeSpec, ClassStar) |
255 | NODE(DeclarationTypeSpec, Record) |
256 | NODE(DeclarationTypeSpec, Type) |
257 | NODE(DeclarationTypeSpec, TypeStar) |
258 | NODE(parser, Default) |
259 | NODE(parser, DeferredCoshapeSpecList) |
260 | NODE(parser, DeferredShapeSpecList) |
261 | NODE(parser, DefinedOpName) |
262 | NODE(parser, DefinedOperator) |
263 | NODE_ENUM(DefinedOperator, IntrinsicOperator) |
264 | NODE(parser, DerivedTypeDef) |
265 | NODE(parser, DerivedTypeSpec) |
266 | NODE(parser, DerivedTypeStmt) |
267 | NODE(parser, Designator) |
268 | NODE(parser, DimensionStmt) |
269 | NODE(DimensionStmt, Declaration) |
270 | NODE(parser, DoConstruct) |
271 | NODE(parser, DummyArg) |
272 | NODE(parser, ElseIfStmt) |
273 | NODE(parser, ElseStmt) |
274 | NODE(parser, ElsewhereStmt) |
275 | NODE(parser, EndAssociateStmt) |
276 | NODE(parser, EndBlockDataStmt) |
277 | NODE(parser, EndBlockStmt) |
278 | NODE(parser, EndChangeTeamStmt) |
279 | NODE(parser, EndCriticalStmt) |
280 | NODE(parser, EndDoStmt) |
281 | NODE(parser, EndEnumStmt) |
282 | NODE(parser, EndForallStmt) |
283 | NODE(parser, EndFunctionStmt) |
284 | NODE(parser, EndIfStmt) |
285 | NODE(parser, EndInterfaceStmt) |
286 | NODE(parser, EndLabel) |
287 | NODE(parser, EndModuleStmt) |
288 | NODE(parser, EndMpSubprogramStmt) |
289 | NODE(parser, EndProgramStmt) |
290 | NODE(parser, EndSelectStmt) |
291 | NODE(parser, EndSubmoduleStmt) |
292 | NODE(parser, EndSubroutineStmt) |
293 | NODE(parser, EndTypeStmt) |
294 | NODE(parser, EndWhereStmt) |
295 | NODE(parser, EndfileStmt) |
296 | NODE(parser, EntityDecl) |
297 | NODE(parser, EntryStmt) |
298 | NODE(parser, EnumDef) |
299 | NODE(parser, EnumDefStmt) |
300 | NODE(parser, Enumerator) |
301 | NODE(parser, EnumeratorDefStmt) |
302 | NODE(parser, EorLabel) |
303 | NODE(parser, EquivalenceObject) |
304 | NODE(parser, EquivalenceStmt) |
305 | NODE(parser, ErrLabel) |
306 | NODE(parser, ErrorRecovery) |
307 | NODE(parser, EventPostStmt) |
308 | NODE(parser, EventWaitSpec) |
309 | NODE(parser, EventWaitStmt) |
310 | NODE(parser, ExecutableConstruct) |
311 | NODE(parser, ExecutionPart) |
312 | NODE(parser, ExecutionPartConstruct) |
313 | NODE(parser, ExitStmt) |
314 | NODE(parser, ExplicitCoshapeSpec) |
315 | NODE(parser, ExplicitShapeSpec) |
316 | NODE(parser, Expr) |
317 | NODE(Expr, Parentheses) |
318 | NODE(Expr, UnaryPlus) |
319 | NODE(Expr, Negate) |
320 | NODE(Expr, NOT) |
321 | NODE(Expr, PercentLoc) |
322 | NODE(Expr, DefinedUnary) |
323 | NODE(Expr, Power) |
324 | NODE(Expr, Multiply) |
325 | NODE(Expr, Divide) |
326 | NODE(Expr, Add) |
327 | NODE(Expr, Subtract) |
328 | NODE(Expr, Concat) |
329 | NODE(Expr, LT) |
330 | NODE(Expr, LE) |
331 | NODE(Expr, EQ) |
332 | NODE(Expr, NE) |
333 | NODE(Expr, GE) |
334 | NODE(Expr, GT) |
335 | NODE(Expr, AND) |
336 | NODE(Expr, OR) |
337 | NODE(Expr, EQV) |
338 | NODE(Expr, NEQV) |
339 | NODE(Expr, DefinedBinary) |
340 | NODE(Expr, ComplexConstructor) |
341 | NODE(parser, External) |
342 | NODE(parser, ExternalStmt) |
343 | NODE(parser, FailImageStmt) |
344 | NODE(parser, FileUnitNumber) |
345 | NODE(parser, FinalProcedureStmt) |
346 | NODE(parser, FlushStmt) |
347 | NODE(parser, ForallAssignmentStmt) |
348 | NODE(parser, ForallBodyConstruct) |
349 | NODE(parser, ForallConstruct) |
350 | NODE(parser, ForallConstructStmt) |
351 | NODE(parser, ForallStmt) |
352 | NODE(parser, FormTeamStmt) |
353 | NODE(FormTeamStmt, FormTeamSpec) |
354 | NODE(parser, Format) |
355 | NODE(parser, FormatStmt) |
356 | NODE(parser, FunctionReference) |
357 | NODE(parser, FunctionStmt) |
358 | NODE(parser, FunctionSubprogram) |
359 | NODE(parser, GenericSpec) |
360 | NODE(GenericSpec, Assignment) |
361 | NODE(GenericSpec, ReadFormatted) |
362 | NODE(GenericSpec, ReadUnformatted) |
363 | NODE(GenericSpec, WriteFormatted) |
364 | NODE(GenericSpec, WriteUnformatted) |
365 | NODE(parser, GenericStmt) |
366 | NODE(parser, GotoStmt) |
367 | NODE(parser, HollerithLiteralConstant) |
368 | NODE(parser, IdExpr) |
369 | NODE(parser, IdVariable) |
370 | NODE(parser, IfConstruct) |
371 | NODE(IfConstruct, ElseBlock) |
372 | NODE(IfConstruct, ElseIfBlock) |
373 | NODE(parser, IfStmt) |
374 | NODE(parser, IfThenStmt) |
375 | NODE(parser, TeamValue) |
376 | NODE(parser, ImageSelector) |
377 | NODE(parser, ImageSelectorSpec) |
378 | NODE(ImageSelectorSpec, Stat) |
379 | NODE(ImageSelectorSpec, Team_Number) |
380 | NODE(parser, ImplicitPart) |
381 | NODE(parser, ImplicitPartStmt) |
382 | NODE(parser, ImplicitSpec) |
383 | NODE(parser, ImplicitStmt) |
384 | NODE_ENUM(ImplicitStmt, ImplicitNoneNameSpec) |
385 | NODE(parser, ImpliedShapeSpec) |
386 | NODE(parser, ImportStmt) |
387 | NODE(parser, Initialization) |
388 | NODE(parser, InputImpliedDo) |
389 | NODE(parser, InputItem) |
390 | NODE(parser, InquireSpec) |
391 | NODE(InquireSpec, CharVar) |
392 | NODE_ENUM(InquireSpec::CharVar, Kind) |
393 | NODE(InquireSpec, IntVar) |
394 | NODE_ENUM(InquireSpec::IntVar, Kind) |
395 | NODE(InquireSpec, LogVar) |
396 | NODE_ENUM(InquireSpec::LogVar, Kind) |
397 | NODE(parser, InquireStmt) |
398 | NODE(InquireStmt, Iolength) |
399 | NODE(parser, IntegerTypeSpec) |
400 | NODE(parser, IntentSpec) |
401 | NODE_ENUM(IntentSpec, Intent) |
402 | NODE(parser, IntentStmt) |
403 | NODE(parser, InterfaceBlock) |
404 | NODE(parser, InterfaceBody) |
405 | NODE(InterfaceBody, Function) |
406 | NODE(InterfaceBody, Subroutine) |
407 | NODE(parser, InterfaceSpecification) |
408 | NODE(parser, InterfaceStmt) |
409 | NODE(parser, InternalSubprogram) |
410 | NODE(parser, InternalSubprogramPart) |
411 | NODE(parser, Intrinsic) |
412 | NODE(parser, IntrinsicStmt) |
413 | NODE(parser, IntrinsicTypeSpec) |
414 | NODE(IntrinsicTypeSpec, Character) |
415 | NODE(IntrinsicTypeSpec, Complex) |
416 | NODE(IntrinsicTypeSpec, DoubleComplex) |
417 | NODE(IntrinsicTypeSpec, DoublePrecision) |
418 | NODE(IntrinsicTypeSpec, Logical) |
419 | NODE(IntrinsicTypeSpec, Real) |
420 | NODE(parser, IoControlSpec) |
421 | NODE(IoControlSpec, Asynchronous) |
422 | NODE(IoControlSpec, CharExpr) |
423 | NODE_ENUM(IoControlSpec::CharExpr, Kind) |
424 | NODE(IoControlSpec, Pos) |
425 | NODE(IoControlSpec, Rec) |
426 | NODE(IoControlSpec, Size) |
427 | NODE(parser, IoUnit) |
428 | NODE(parser, Keyword) |
429 | NODE(parser, KindParam) |
430 | NODE(parser, KindSelector) |
431 | NODE(KindSelector, StarSize) |
432 | NODE(parser, LabelDoStmt) |
433 | NODE(parser, LanguageBindingSpec) |
434 | NODE(parser, LengthSelector) |
435 | NODE(parser, LetterSpec) |
436 | NODE(parser, LiteralConstant) |
437 | NODE(parser, IntLiteralConstant) |
438 | NODE(parser, LocalitySpec) |
439 | NODE(LocalitySpec, DefaultNone) |
440 | NODE(LocalitySpec, Local) |
441 | NODE(LocalitySpec, LocalInit) |
442 | NODE(LocalitySpec, Shared) |
443 | NODE(parser, LockStmt) |
444 | NODE(LockStmt, LockStat) |
445 | NODE(parser, LogicalLiteralConstant) |
446 | NODE_NAME(LoopControl::Bounds, "LoopBounds") |
447 | NODE_NAME(AcImpliedDoControl::Bounds, "LoopBounds") |
448 | NODE_NAME(DataImpliedDo::Bounds, "LoopBounds") |
449 | NODE(parser, LoopControl) |
450 | NODE(LoopControl, Concurrent) |
451 | NODE(parser, MainProgram) |
452 | NODE(parser, Map) |
453 | NODE(Map, EndMapStmt) |
454 | NODE(Map, MapStmt) |
455 | NODE(parser, MaskedElsewhereStmt) |
456 | NODE(parser, Module) |
457 | NODE(parser, ModuleStmt) |
458 | NODE(parser, ModuleSubprogram) |
459 | NODE(parser, ModuleSubprogramPart) |
460 | NODE(parser, MpSubprogramStmt) |
461 | NODE(parser, MsgVariable) |
462 | NODE(parser, Name) |
463 | NODE(parser, NamedConstant) |
464 | NODE(parser, NamedConstantDef) |
465 | NODE(parser, NamelistStmt) |
466 | NODE(NamelistStmt, Group) |
467 | NODE(parser, NonLabelDoStmt) |
468 | NODE(parser, NoPass) |
469 | NODE(parser, NotifyWaitStmt) |
470 | NODE(parser, NullifyStmt) |
471 | NODE(parser, NullInit) |
472 | NODE(parser, ObjectDecl) |
473 | NODE(parser, OldParameterStmt) |
474 | NODE(parser, OmpAlignedClause) |
475 | NODE(parser, OmpAtomic) |
476 | NODE(parser, OmpAtomicCapture) |
477 | NODE(OmpAtomicCapture, Stmt1) |
478 | NODE(OmpAtomicCapture, Stmt2) |
479 | NODE(parser, OmpAtomicRead) |
480 | NODE(parser, OmpAtomicUpdate) |
481 | NODE(parser, OmpAtomicWrite) |
482 | NODE(parser, OmpBeginBlockDirective) |
483 | NODE(parser, OmpBeginLoopDirective) |
484 | NODE(parser, OmpBeginSectionsDirective) |
485 | NODE(parser, OmpBlockDirective) |
486 | static std::string GetNodeName(const llvm::omp::Directive &x) { |
487 | return llvm::Twine( |
488 | "llvm::omp::Directive = ", llvm::omp::getOpenMPDirectiveName(x)) |
489 | .str(); |
490 | } |
491 | NODE(parser, OmpCancelType) |
492 | NODE_ENUM(OmpCancelType, Type) |
493 | NODE(parser, OmpClause) |
494 | #define GEN_FLANG_DUMP_PARSE_TREE_CLAUSES |
495 | #include "llvm/Frontend/OpenMP/OMP.inc" |
496 | NODE(parser, OmpClauseList) |
497 | NODE(parser, OmpCriticalDirective) |
498 | NODE(parser, OmpDeclareTargetSpecifier) |
499 | NODE(parser, OmpDeclareTargetWithClause) |
500 | NODE(parser, OmpDeclareTargetWithList) |
501 | NODE(parser, OmpDefaultClause) |
502 | NODE_ENUM(OmpDefaultClause, Type) |
503 | NODE(parser, OmpDefaultmapClause) |
504 | NODE_ENUM(OmpDefaultmapClause, ImplicitBehavior) |
505 | NODE_ENUM(OmpDefaultmapClause, VariableCategory) |
506 | NODE(parser, OmpDependClause) |
507 | NODE(OmpDependClause, InOut) |
508 | NODE(OmpDependClause, Sink) |
509 | NODE(OmpDependClause, Source) |
510 | NODE(parser, OmpDependenceType) |
511 | NODE_ENUM(OmpDependenceType, Type) |
512 | NODE(parser, OmpDependSinkVec) |
513 | NODE(parser, OmpDependSinkVecLength) |
514 | NODE(parser, OmpEndAllocators) |
515 | NODE(parser, OmpEndAtomic) |
516 | NODE(parser, OmpEndBlockDirective) |
517 | NODE(parser, OmpEndCriticalDirective) |
518 | NODE(parser, OmpEndLoopDirective) |
519 | NODE(parser, OmpEndSectionsDirective) |
520 | NODE(parser, OmpIfClause) |
521 | NODE_ENUM(OmpIfClause, DirectiveNameModifier) |
522 | NODE(parser, OmpLinearClause) |
523 | NODE(OmpLinearClause, WithModifier) |
524 | NODE(OmpLinearClause, WithoutModifier) |
525 | NODE(parser, OmpLinearModifier) |
526 | NODE_ENUM(OmpLinearModifier, Type) |
527 | NODE(parser, OmpLoopDirective) |
528 | NODE(parser, OmpMapClause) |
529 | NODE(parser, OmpMapType) |
530 | NODE(OmpMapType, Always) |
531 | NODE_ENUM(OmpMapType, Type) |
532 | static std::string GetNodeName(const llvm::omp::Clause &x) { |
533 | return llvm::Twine( |
534 | "llvm::omp::Clause = ", llvm::omp::getOpenMPClauseName(x)) |
535 | .str(); |
536 | } |
537 | NODE(parser, OmpObject) |
538 | NODE(parser, OmpObjectList) |
539 | NODE(parser, OmpOrderClause) |
540 | NODE_ENUM(OmpOrderClause, Type) |
541 | NODE(parser, OmpOrderModifier) |
542 | NODE_ENUM(OmpOrderModifier, Kind) |
543 | NODE(parser, OmpProcBindClause) |
544 | NODE_ENUM(OmpProcBindClause, Type) |
545 | NODE_ENUM(OmpReductionClause, ReductionModifier) |
546 | NODE(parser, OmpReductionClause) |
547 | NODE(parser, OmpInReductionClause) |
548 | NODE(parser, OmpReductionCombiner) |
549 | NODE(OmpReductionCombiner, FunctionCombiner) |
550 | NODE(parser, OmpReductionInitializerClause) |
551 | NODE(parser, OmpReductionOperator) |
552 | NODE(parser, OmpAllocateClause) |
553 | NODE(OmpAllocateClause, AllocateModifier) |
554 | NODE(OmpAllocateClause::AllocateModifier, Allocator) |
555 | NODE(OmpAllocateClause::AllocateModifier, ComplexModifier) |
556 | NODE(OmpAllocateClause::AllocateModifier, Align) |
557 | NODE(parser, OmpScheduleClause) |
558 | NODE_ENUM(OmpScheduleClause, ScheduleType) |
559 | NODE(parser, OmpDeviceClause) |
560 | NODE_ENUM(OmpDeviceClause, DeviceModifier) |
561 | NODE(parser, OmpDeviceTypeClause) |
562 | NODE_ENUM(OmpDeviceTypeClause, Type) |
563 | NODE(parser, OmpScheduleModifier) |
564 | NODE(OmpScheduleModifier, Modifier1) |
565 | NODE(OmpScheduleModifier, Modifier2) |
566 | NODE(parser, OmpScheduleModifierType) |
567 | NODE_ENUM(OmpScheduleModifierType, ModType) |
568 | NODE(parser, OmpSectionBlocks) |
569 | NODE(parser, OmpSectionsDirective) |
570 | NODE(parser, OmpSimpleStandaloneDirective) |
571 | NODE(parser, Only) |
572 | NODE(parser, OpenACCAtomicConstruct) |
573 | NODE(parser, OpenACCBlockConstruct) |
574 | NODE(parser, OpenACCCacheConstruct) |
575 | NODE(parser, OpenACCCombinedConstruct) |
576 | NODE(parser, OpenACCConstruct) |
577 | NODE(parser, OpenACCDeclarativeConstruct) |
578 | NODE(parser, OpenACCEndConstruct) |
579 | NODE(parser, OpenACCLoopConstruct) |
580 | NODE(parser, OpenACCRoutineConstruct) |
581 | NODE(parser, OpenACCStandaloneDeclarativeConstruct) |
582 | NODE(parser, OpenACCStandaloneConstruct) |
583 | NODE(parser, OpenACCWaitConstruct) |
584 | NODE(parser, OpenMPAtomicConstruct) |
585 | NODE(parser, OpenMPBlockConstruct) |
586 | NODE(parser, OpenMPCancelConstruct) |
587 | NODE(OpenMPCancelConstruct, If) |
588 | NODE(parser, OpenMPCancellationPointConstruct) |
589 | NODE(parser, OpenMPConstruct) |
590 | NODE(parser, OpenMPCriticalConstruct) |
591 | NODE(parser, OpenMPDeclarativeAllocate) |
592 | NODE(parser, OpenMPDeclarativeConstruct) |
593 | NODE(parser, OpenMPDeclareReductionConstruct) |
594 | NODE(parser, OpenMPDeclareSimdConstruct) |
595 | NODE(parser, OpenMPDeclareTargetConstruct) |
596 | NODE(parser, OmpMemoryOrderClause) |
597 | NODE(parser, OmpAtomicClause) |
598 | NODE(parser, OmpAtomicClauseList) |
599 | NODE(parser, OmpAtomicDefaultMemOrderClause) |
600 | NODE_ENUM(common, OmpAtomicDefaultMemOrderType) |
601 | NODE(parser, OpenMPFlushConstruct) |
602 | NODE(parser, OpenMPLoopConstruct) |
603 | NODE(parser, OpenMPExecutableAllocate) |
604 | NODE(parser, OpenMPAllocatorsConstruct) |
605 | NODE(parser, OpenMPRequiresConstruct) |
606 | NODE(parser, OpenMPSimpleStandaloneConstruct) |
607 | NODE(parser, OpenMPStandaloneConstruct) |
608 | NODE(parser, OpenMPSectionConstruct) |
609 | NODE(parser, OpenMPSectionsConstruct) |
610 | NODE(parser, OpenMPThreadprivate) |
611 | NODE(parser, OpenStmt) |
612 | NODE(parser, Optional) |
613 | NODE(parser, OptionalStmt) |
614 | NODE(parser, OtherSpecificationStmt) |
615 | NODE(parser, OutputImpliedDo) |
616 | NODE(parser, OutputItem) |
617 | NODE(parser, Parameter) |
618 | NODE(parser, ParameterStmt) |
619 | NODE(parser, ParentIdentifier) |
620 | NODE(parser, Pass) |
621 | NODE(parser, PauseStmt) |
622 | NODE(parser, Pointer) |
623 | NODE(parser, PointerAssignmentStmt) |
624 | NODE(PointerAssignmentStmt, Bounds) |
625 | NODE(parser, PointerDecl) |
626 | NODE(parser, PointerObject) |
627 | NODE(parser, PointerStmt) |
628 | NODE(parser, PositionOrFlushSpec) |
629 | NODE(parser, PrefixSpec) |
630 | NODE(PrefixSpec, Elemental) |
631 | NODE(PrefixSpec, Impure) |
632 | NODE(PrefixSpec, Module) |
633 | NODE(PrefixSpec, Non_Recursive) |
634 | NODE(PrefixSpec, Pure) |
635 | NODE(PrefixSpec, Recursive) |
636 | NODE(PrefixSpec, Attributes) |
637 | NODE(PrefixSpec, Launch_Bounds) |
638 | NODE(PrefixSpec, Cluster_Dims) |
639 | NODE(parser, PrintStmt) |
640 | NODE(parser, PrivateStmt) |
641 | NODE(parser, PrivateOrSequence) |
642 | NODE(parser, ProcAttrSpec) |
643 | NODE(parser, ProcComponentAttrSpec) |
644 | NODE(parser, ProcComponentDefStmt) |
645 | NODE(parser, ProcComponentRef) |
646 | NODE(parser, ProcDecl) |
647 | NODE(parser, ProcInterface) |
648 | NODE(parser, ProcPointerInit) |
649 | NODE(parser, ProcedureDeclarationStmt) |
650 | NODE(parser, ProcedureDesignator) |
651 | NODE(parser, ProcedureStmt) |
652 | NODE_ENUM(ProcedureStmt, Kind) |
653 | NODE(parser, Program) |
654 | NODE(parser, ProgramStmt) |
655 | NODE(parser, ProgramUnit) |
656 | NODE(parser, Protected) |
657 | NODE(parser, ProtectedStmt) |
658 | NODE(parser, ReadStmt) |
659 | NODE(parser, RealLiteralConstant) |
660 | NODE(RealLiteralConstant, Real) |
661 | NODE(parser, Rename) |
662 | NODE(Rename, Names) |
663 | NODE(Rename, Operators) |
664 | NODE(parser, ReturnStmt) |
665 | NODE(parser, RewindStmt) |
666 | NODE(parser, Save) |
667 | NODE(parser, SaveStmt) |
668 | NODE(parser, SavedEntity) |
669 | NODE_ENUM(SavedEntity, Kind) |
670 | NODE(parser, SectionSubscript) |
671 | NODE(parser, SelectCaseStmt) |
672 | NODE(parser, SelectRankCaseStmt) |
673 | NODE(SelectRankCaseStmt, Rank) |
674 | NODE(parser, SelectRankConstruct) |
675 | NODE(SelectRankConstruct, RankCase) |
676 | NODE(parser, SelectRankStmt) |
677 | NODE(parser, SelectTypeConstruct) |
678 | NODE(SelectTypeConstruct, TypeCase) |
679 | NODE(parser, SelectTypeStmt) |
680 | NODE(parser, Selector) |
681 | NODE(parser, SeparateModuleSubprogram) |
682 | NODE(parser, SequenceStmt) |
683 | NODE(parser, Sign) |
684 | NODE(parser, SignedComplexLiteralConstant) |
685 | NODE(parser, SignedIntLiteralConstant) |
686 | NODE(parser, SignedRealLiteralConstant) |
687 | NODE(parser, SpecificationConstruct) |
688 | NODE(parser, SpecificationExpr) |
689 | NODE(parser, SpecificationPart) |
690 | NODE(parser, Star) |
691 | NODE(parser, StatOrErrmsg) |
692 | NODE(parser, StatVariable) |
693 | NODE(parser, StatusExpr) |
694 | NODE(parser, StmtFunctionStmt) |
695 | NODE(parser, StopCode) |
696 | NODE(parser, StopStmt) |
697 | NODE_ENUM(StopStmt, Kind) |
698 | NODE(parser, StructureComponent) |
699 | NODE(parser, StructureConstructor) |
700 | NODE(parser, StructureDef) |
701 | NODE(StructureDef, EndStructureStmt) |
702 | NODE(parser, StructureField) |
703 | NODE(parser, StructureStmt) |
704 | NODE(parser, Submodule) |
705 | NODE(parser, SubmoduleStmt) |
706 | NODE(parser, SubroutineStmt) |
707 | NODE(parser, SubroutineSubprogram) |
708 | NODE(parser, SubscriptTriplet) |
709 | NODE(parser, Substring) |
710 | NODE(parser, SubstringInquiry) |
711 | NODE(parser, SubstringRange) |
712 | NODE(parser, Suffix) |
713 | NODE(parser, SyncAllStmt) |
714 | NODE(parser, SyncImagesStmt) |
715 | NODE(SyncImagesStmt, ImageSet) |
716 | NODE(parser, SyncMemoryStmt) |
717 | NODE(parser, SyncTeamStmt) |
718 | NODE(parser, Target) |
719 | NODE(parser, TargetStmt) |
720 | NODE(parser, TypeAttrSpec) |
721 | NODE(TypeAttrSpec, BindC) |
722 | NODE(TypeAttrSpec, Extends) |
723 | NODE(parser, TypeBoundGenericStmt) |
724 | NODE(parser, TypeBoundProcBinding) |
725 | NODE(parser, TypeBoundProcDecl) |
726 | NODE(parser, TypeBoundProcedurePart) |
727 | NODE(parser, TypeBoundProcedureStmt) |
728 | NODE(TypeBoundProcedureStmt, WithInterface) |
729 | NODE(TypeBoundProcedureStmt, WithoutInterface) |
730 | NODE(parser, TypeDeclarationStmt) |
731 | NODE(parser, TypeGuardStmt) |
732 | NODE(TypeGuardStmt, Guard) |
733 | NODE(parser, TypeParamDecl) |
734 | NODE(parser, TypeParamDefStmt) |
735 | NODE(common, TypeParamAttr) |
736 | NODE(parser, TypeParamSpec) |
737 | NODE(parser, TypeParamValue) |
738 | NODE(TypeParamValue, Deferred) |
739 | NODE(parser, TypeSpec) |
740 | NODE(parser, Union) |
741 | NODE(Union, EndUnionStmt) |
742 | NODE(Union, UnionStmt) |
743 | NODE(parser, UnlockStmt) |
744 | NODE(parser, UnsignedTypeSpec) |
745 | NODE(parser, UseStmt) |
746 | NODE_ENUM(UseStmt, ModuleNature) |
747 | NODE(parser, Value) |
748 | NODE(parser, ValueStmt) |
749 | NODE(parser, Variable) |
750 | NODE(parser, VectorTypeSpec) |
751 | NODE(VectorTypeSpec, PairVectorTypeSpec) |
752 | NODE(VectorTypeSpec, QuadVectorTypeSpec) |
753 | NODE(parser, IntrinsicVectorTypeSpec) |
754 | NODE(parser, VectorElementType) |
755 | NODE(parser, Verbatim) |
756 | NODE(parser, Volatile) |
757 | NODE(parser, VolatileStmt) |
758 | NODE(parser, WaitSpec) |
759 | NODE(parser, WaitStmt) |
760 | NODE(parser, WhereBodyConstruct) |
761 | NODE(parser, WhereConstruct) |
762 | NODE(WhereConstruct, Elsewhere) |
763 | NODE(WhereConstruct, MaskedElsewhere) |
764 | NODE(parser, WhereConstructStmt) |
765 | NODE(parser, WhereStmt) |
766 | NODE(parser, WriteStmt) |
767 | #undef NODE |
768 | #undef NODE_NAME |
769 | |
770 | template <typename T> bool Pre(const T &x) { |
771 | std::string fortran{AsFortran<T>(x)}; |
772 | if (fortran.empty() && (UnionTrait<T> || WrapperTrait<T>)) { |
773 | Prefix(GetNodeName(x)); |
774 | } else { |
775 | IndentEmptyLine(); |
776 | out_ << GetNodeName(x); |
777 | if (!fortran.empty()) { |
778 | out_ << " = '" << fortran << '\''; |
779 | } |
780 | EndLine(); |
781 | ++indent_; |
782 | } |
783 | return true; |
784 | } |
785 | |
786 | template <typename T> void Post(const T &x) { |
787 | if (AsFortran<T>(x).empty() && (UnionTrait<T> || WrapperTrait<T>)) { |
788 | EndLineIfNonempty(); |
789 | } else { |
790 | --indent_; |
791 | } |
792 | } |
793 | |
794 | // A few types we want to ignore |
795 | |
796 | bool Pre(const CharBlock &) { return true; } |
797 | void Post(const CharBlock &) {} |
798 | |
799 | template <typename T> bool Pre(const Statement<T> &) { return true; } |
800 | template <typename T> void Post(const Statement<T> &) {} |
801 | template <typename T> bool Pre(const UnlabeledStatement<T> &) { return true; } |
802 | template <typename T> void Post(const UnlabeledStatement<T> &) {} |
803 | |
804 | template <typename T> bool Pre(const common::Indirection<T> &) { |
805 | return true; |
806 | } |
807 | template <typename T> void Post(const common::Indirection<T> &) {} |
808 | |
809 | template <typename A> bool Pre(const Scalar<A> &) { |
810 | Prefix("Scalar"); |
811 | return true; |
812 | } |
813 | template <typename A> void Post(const Scalar<A> &) { EndLineIfNonempty(); } |
814 | |
815 | template <typename A> bool Pre(const Constant<A> &) { |
816 | Prefix("Constant"); |
817 | return true; |
818 | } |
819 | template <typename A> void Post(const Constant<A> &) { EndLineIfNonempty(); } |
820 | |
821 | template <typename A> bool Pre(const Integer<A> &) { |
822 | Prefix("Integer"); |
823 | return true; |
824 | } |
825 | template <typename A> void Post(const Integer<A> &) { EndLineIfNonempty(); } |
826 | |
827 | template <typename A> bool Pre(const Logical<A> &) { |
828 | Prefix("Logical"); |
829 | return true; |
830 | } |
831 | template <typename A> void Post(const Logical<A> &) { EndLineIfNonempty(); } |
832 | |
833 | template <typename A> bool Pre(const DefaultChar<A> &) { |
834 | Prefix("DefaultChar"); |
835 | return true; |
836 | } |
837 | template <typename A> void Post(const DefaultChar<A> &) { |
838 | EndLineIfNonempty(); |
839 | } |
840 | |
841 | template <typename... A> bool Pre(const std::tuple<A...> &) { return true; } |
842 | template <typename... A> void Post(const std::tuple<A...> &) {} |
843 | |
844 | template <typename... A> bool Pre(const std::variant<A...> &) { return true; } |
845 | template <typename... A> void Post(const std::variant<A...> &) {} |
846 | |
847 | protected: |
848 | // Return a Fortran representation of this node to include in the dump |
849 | template <typename T> std::string AsFortran(const T &x) { |
850 | std::string buf; |
851 | llvm::raw_string_ostream ss{buf}; |
852 | if constexpr (HasTypedExpr<T>::value) { |
853 | if (asFortran_ && x.typedExpr) { |
854 | asFortran_->expr(ss, *x.typedExpr); |
855 | } |
856 | } else if constexpr (std::is_same_v<T, AssignmentStmt> || |
857 | std::is_same_v<T, PointerAssignmentStmt>) { |
858 | if (asFortran_ && x.typedAssignment) { |
859 | asFortran_->assignment(ss, *x.typedAssignment); |
860 | } |
861 | } else if constexpr (std::is_same_v<T, CallStmt>) { |
862 | if (asFortran_ && x.typedCall) { |
863 | asFortran_->call(ss, *x.typedCall); |
864 | } |
865 | } else if constexpr (std::is_same_v<T, IntLiteralConstant> || |
866 | std::is_same_v<T, SignedIntLiteralConstant>) { |
867 | ss << std::get<CharBlock>(x.t); |
868 | } else if constexpr (std::is_same_v<T, RealLiteralConstant::Real>) { |
869 | ss << x.source; |
870 | } else if constexpr (std::is_same_v<T, std::string> || |
871 | std::is_same_v<T, std::int64_t> || std::is_same_v<T, std::uint64_t>) { |
872 | ss << x; |
873 | } |
874 | if (ss.tell()) { |
875 | return ss.str(); |
876 | } |
877 | if constexpr (std::is_same_v<T, Name>) { |
878 | return x.source.ToString(); |
879 | #ifdef SHOW_ALL_SOURCE_MEMBERS |
880 | } else if constexpr (HasSource<T>::value) { |
881 | return x.source.ToString(); |
882 | #endif |
883 | } else if constexpr (std::is_same_v<T, std::string>) { |
884 | return x; |
885 | } else { |
886 | return ""; |
887 | } |
888 | } |
889 | |
890 | void IndentEmptyLine() { |
891 | if (emptyline_ && indent_ > 0) { |
892 | for (int i{0}; i < indent_; ++i) { |
893 | out_ << "| "; |
894 | } |
895 | emptyline_ = false; |
896 | } |
897 | } |
898 | |
899 | void Prefix(const char *str) { |
900 | IndentEmptyLine(); |
901 | out_ << str << " -> "; |
902 | emptyline_ = false; |
903 | } |
904 | |
905 | void Prefix(const std::string &str) { |
906 | IndentEmptyLine(); |
907 | out_ << str << " -> "; |
908 | emptyline_ = false; |
909 | } |
910 | |
911 | void EndLine() { |
912 | out_ << '\n'; |
913 | emptyline_ = true; |
914 | } |
915 | |
916 | void EndLineIfNonempty() { |
917 | if (!emptyline_) { |
918 | EndLine(); |
919 | } |
920 | } |
921 | |
922 | private: |
923 | int indent_{0}; |
924 | llvm::raw_ostream &out_; |
925 | const AnalyzedObjectsAsFortran *const asFortran_; |
926 | bool emptyline_{false}; |
927 | }; |
928 | |
929 | template <typename T> |
930 | llvm::raw_ostream &DumpTree(llvm::raw_ostream &out, const T &x, |
931 | const AnalyzedObjectsAsFortran *asFortran = nullptr) { |
932 | ParseTreeDumper dumper{out, asFortran}; |
933 | Walk(x, dumper); |
934 | return out; |
935 | } |
936 | |
937 | } // namespace Fortran::parser |
938 | #endif // FORTRAN_PARSER_DUMP_PARSE_TREE_H_ |
939 |
Warning: This file is not a C or C++ file. It does not have highlighting.