1 //===-- include/flang/Parser/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_PARSE_TREE_H_
10 #define FORTRAN_PARSER_PARSE_TREE_H_
11
12 // Defines the classes used to represent successful reductions of productions
13 // in the Fortran grammar. The names and content of these definitions
14 // adhere closely to the syntax specifications in the language standard (q.v.)
15 // that are transcribed here and referenced via their requirement numbers.
16 // The representations of some productions that may also be of use in the
17 // run-time I/O support library have been isolated into a distinct header file
18 // (viz., format-specification.h).
19
20 #include "char-block.h"
21 #include "characters.h"
22 #include "format-specification.h"
23 #include "message.h"
24 #include "provenance.h"
25 #include "flang/Common/Fortran.h"
26 #include "flang/Common/idioms.h"
27 #include "flang/Common/indirection.h"
28 #include "llvm/Frontend/OpenACC/ACC.h.inc"
29 #include "llvm/Frontend/OpenMP/OMPConstants.h"
30 #include <cinttypes>
31 #include <list>
32 #include <memory>
33 #include <optional>
34 #include <string>
35 #include <tuple>
36 #include <type_traits>
37 #include <utility>
38 #include <variant>
39
40 // Parse tree node class types do not have default constructors. They
41 // explicitly declare "T() {} = delete;" to make this clear. This restriction
42 // prevents the introduction of what would be a viral requirement to include
43 // std::monostate among most std::variant<> discriminated union members.
44
45 // Parse tree node class types do not have copy constructors or copy assignment
46 // operators. They are explicitly declared "= delete;" to make this clear,
47 // although a C++ compiler wouldn't default them anyway due to the presence
48 // of explicitly defaulted move constructors and move assignments.
49
50 CLASS_TRAIT(EmptyTrait)
CLASS_TRAIT(WrapperTrait)51 CLASS_TRAIT(WrapperTrait)
52 CLASS_TRAIT(UnionTrait)
53 CLASS_TRAIT(TupleTrait)
54 CLASS_TRAIT(ConstraintTrait)
55
56 // Some parse tree nodes have fields in them to cache the results of a
57 // successful semantic analysis later. Their types are forward declared
58 // here.
59 namespace Fortran::semantics {
60 class Symbol;
61 class DeclTypeSpec;
62 class DerivedTypeSpec;
63 } // namespace Fortran::semantics
64
65 // Expressions in the parse tree have owning pointers that can be set to
66 // type-checked generic expression representations by semantic analysis.
67 namespace Fortran::evaluate {
68 struct GenericExprWrapper; // forward definition, wraps Expr<SomeType>
69 struct GenericAssignmentWrapper; // forward definition, represent assignment
70 class ProcedureRef; // forward definition, represents a CALL statement
71 } // namespace Fortran::evaluate
72
73 // Most non-template classes in this file use these default definitions
74 // for their move constructor and move assignment operator=, and disable
75 // their copy constructor and copy assignment operator=.
76 #define COPY_AND_ASSIGN_BOILERPLATE(classname) \
77 classname(classname &&) = default; \
78 classname &operator=(classname &&) = default; \
79 classname(const classname &) = delete; \
80 classname &operator=(const classname &) = delete
81
82 // Almost all classes in this file have no default constructor.
83 #define BOILERPLATE(classname) \
84 COPY_AND_ASSIGN_BOILERPLATE(classname); \
85 classname() = delete
86
87 // Empty classes are often used below as alternatives in std::variant<>
88 // discriminated unions.
89 #define EMPTY_CLASS(classname) \
90 struct classname { \
91 classname() {} \
92 classname(const classname &) {} \
93 classname(classname &&) {} \
94 classname &operator=(const classname &) { return *this; }; \
95 classname &operator=(classname &&) { return *this; }; \
96 using EmptyTrait = std::true_type; \
97 }
98
99 // Many classes below simply wrap a std::variant<> discriminated union,
100 // which is conventionally named "u".
101 #define UNION_CLASS_BOILERPLATE(classname) \
102 template <typename A, typename = common::NoLvalue<A>> \
103 classname(A &&x) : u(std::move(x)) {} \
104 using UnionTrait = std::true_type; \
105 BOILERPLATE(classname)
106
107 // Many other classes below simply wrap a std::tuple<> structure, which
108 // is conventionally named "t".
109 #define TUPLE_CLASS_BOILERPLATE(classname) \
110 template <typename... Ts, typename = common::NoLvalue<Ts...>> \
111 classname(Ts &&...args) : t(std::move(args)...) {} \
112 using TupleTrait = std::true_type; \
113 BOILERPLATE(classname)
114
115 // Many other classes below simply wrap a single data member, which is
116 // conventionally named "v".
117 #define WRAPPER_CLASS_BOILERPLATE(classname, type) \
118 BOILERPLATE(classname); \
119 classname(type &&x) : v(std::move(x)) {} \
120 using WrapperTrait = std::true_type; \
121 type v
122
123 #define WRAPPER_CLASS(classname, type) \
124 struct classname { \
125 WRAPPER_CLASS_BOILERPLATE(classname, type); \
126 }
127
128 namespace Fortran::parser {
129
130 // These are the unavoidable recursively-defined productions of Fortran.
131 // Some references to the representations of their parses require
132 // indirection. The Indirect<> pointer wrapper class is used to
133 // enforce ownership semantics and non-nullability.
134 struct SpecificationPart; // R504
135 struct ExecutableConstruct; // R514
136 struct ActionStmt; // R515
137 struct AcImpliedDo; // R774
138 struct DataImpliedDo; // R840
139 struct Designator; // R901
140 struct Variable; // R902
141 struct Expr; // R1001
142 struct WhereConstruct; // R1042
143 struct ForallConstruct; // R1050
144 struct InputImpliedDo; // R1218
145 struct OutputImpliedDo; // R1218
146 struct FunctionReference; // R1520
147 struct FunctionSubprogram; // R1529
148 struct SubroutineSubprogram; // R1534
149
150 // These additional forward references are declared so that the order of
151 // class definitions in this header file can remain reasonably consistent
152 // with order of the the requirement productions in the grammar.
153 struct DerivedTypeDef; // R726
154 struct EnumDef; // R759
155 struct TypeDeclarationStmt; // R801
156 struct AccessStmt; // R827
157 struct AllocatableStmt; // R829
158 struct AsynchronousStmt; // R831
159 struct BindStmt; // R832
160 struct CodimensionStmt; // R834
161 struct ContiguousStmt; // R836
162 struct DataStmt; // R837
163 struct DataStmtValue; // R843
164 struct DimensionStmt; // R848
165 struct IntentStmt; // R849
166 struct OptionalStmt; // R850
167 struct ParameterStmt; // R851
168 struct OldParameterStmt;
169 struct PointerStmt; // R853
170 struct ProtectedStmt; // R855
171 struct SaveStmt; // R856
172 struct TargetStmt; // R859
173 struct ValueStmt; // R861
174 struct VolatileStmt; // R862
175 struct ImplicitStmt; // R863
176 struct ImportStmt; // R867
177 struct NamelistStmt; // R868
178 struct EquivalenceStmt; // R870
179 struct CommonStmt; // R873
180 struct Substring; // R908
181 struct CharLiteralConstantSubstring;
182 struct DataRef; // R911
183 struct StructureComponent; // R913
184 struct CoindexedNamedObject; // R914
185 struct ArrayElement; // R917
186 struct AllocateStmt; // R927
187 struct NullifyStmt; // R939
188 struct DeallocateStmt; // R941
189 struct AssignmentStmt; // R1032
190 struct PointerAssignmentStmt; // R1033
191 struct WhereStmt; // R1041, R1045, R1046
192 struct ForallStmt; // R1055
193 struct AssociateConstruct; // R1102
194 struct BlockConstruct; // R1107
195 struct ChangeTeamConstruct; // R1111
196 struct CriticalConstruct; // R1116
197 struct DoConstruct; // R1119
198 struct LabelDoStmt; // R1121
199 struct ConcurrentHeader; // R1125
200 struct EndDoStmt; // R1132
201 struct CycleStmt; // R1133
202 struct IfConstruct; // R1134
203 struct IfStmt; // R1139
204 struct CaseConstruct; // R1140
205 struct SelectRankConstruct; // R1148
206 struct SelectTypeConstruct; // R1152
207 struct ExitStmt; // R1156
208 struct GotoStmt; // R1157
209 struct ComputedGotoStmt; // R1158
210 struct StopStmt; // R1160, R1161
211 struct SyncAllStmt; // R1164
212 struct SyncImagesStmt; // R1166
213 struct SyncMemoryStmt; // R1168
214 struct SyncTeamStmt; // R1169
215 struct EventPostStmt; // R1170, R1171
216 struct EventWaitStmt; // R1172, R1173, R1174
217 struct FormTeamStmt; // R1175, R1176, R1177
218 struct LockStmt; // R1178
219 struct UnlockStmt; // R1180
220 struct OpenStmt; // R1204
221 struct CloseStmt; // R1208
222 struct ReadStmt; // R1210
223 struct WriteStmt; // R1211
224 struct PrintStmt; // R1212
225 struct WaitStmt; // R1222
226 struct BackspaceStmt; // R1224
227 struct EndfileStmt; // R1225
228 struct RewindStmt; // R1226
229 struct FlushStmt; // R1228
230 struct InquireStmt; // R1230
231 struct FormatStmt; // R1301
232 struct MainProgram; // R1401
233 struct Module; // R1404
234 struct UseStmt; // R1409
235 struct Submodule; // R1416
236 struct BlockData; // R1420
237 struct InterfaceBlock; // R1501
238 struct GenericSpec; // R1508
239 struct GenericStmt; // R1510
240 struct ExternalStmt; // R1511
241 struct ProcedureDeclarationStmt; // R1512
242 struct IntrinsicStmt; // R1519
243 struct Call; // R1520 & R1521
244 struct CallStmt; // R1521
245 struct ProcedureDesignator; // R1522
246 struct ActualArg; // R1524
247 struct SeparateModuleSubprogram; // R1538
248 struct EntryStmt; // R1541
249 struct ReturnStmt; // R1542
250 struct StmtFunctionStmt; // R1544
251
252 // Directives, extensions, and deprecated statements
253 struct CompilerDirective;
254 struct BasedPointerStmt;
255 struct StructureDef;
256 struct ArithmeticIfStmt;
257 struct AssignStmt;
258 struct AssignedGotoStmt;
259 struct PauseStmt;
260 struct OpenACCConstruct;
261 struct AccEndCombinedDirective;
262 struct OpenACCDeclarativeConstruct;
263 struct OpenMPConstruct;
264 struct OpenMPDeclarativeConstruct;
265 struct OmpEndLoopDirective;
266
267 // Cooked character stream locations
268 using Location = const char *;
269
270 // A parse tree node with provenance only
271 struct Verbatim {
272 BOILERPLATE(Verbatim);
273 using EmptyTrait = std::true_type;
274 CharBlock source;
275 };
276
277 // Implicit definitions of the Standard
278
279 // R403 scalar-xyz -> xyz
280 // These template class wrappers correspond to the Standard's modifiers
281 // scalar-xyz, constant-xzy, int-xzy, default-char-xyz, & logical-xyz.
282 template <typename A> struct Scalar {
283 using ConstraintTrait = std::true_type;
284 Scalar(Scalar &&that) = default;
ScalarScalar285 Scalar(A &&that) : thing(std::move(that)) {}
286 Scalar &operator=(Scalar &&) = default;
287 A thing;
288 };
289
290 template <typename A> struct Constant {
291 using ConstraintTrait = std::true_type;
292 Constant(Constant &&that) = default;
ConstantConstant293 Constant(A &&that) : thing(std::move(that)) {}
294 Constant &operator=(Constant &&) = default;
295 A thing;
296 };
297
298 template <typename A> struct Integer {
299 using ConstraintTrait = std::true_type;
300 Integer(Integer &&that) = default;
IntegerInteger301 Integer(A &&that) : thing(std::move(that)) {}
302 Integer &operator=(Integer &&) = default;
303 A thing;
304 };
305
306 template <typename A> struct Logical {
307 using ConstraintTrait = std::true_type;
308 Logical(Logical &&that) = default;
LogicalLogical309 Logical(A &&that) : thing(std::move(that)) {}
310 Logical &operator=(Logical &&) = default;
311 A thing;
312 };
313
314 template <typename A> struct DefaultChar {
315 using ConstraintTrait = std::true_type;
316 DefaultChar(DefaultChar &&that) = default;
DefaultCharDefaultChar317 DefaultChar(A &&that) : thing(std::move(that)) {}
318 DefaultChar &operator=(DefaultChar &&) = default;
319 A thing;
320 };
321
322 using LogicalExpr = Logical<common::Indirection<Expr>>; // R1024
323 using DefaultCharExpr = DefaultChar<common::Indirection<Expr>>; // R1025
324 using IntExpr = Integer<common::Indirection<Expr>>; // R1026
325 using ConstantExpr = Constant<common::Indirection<Expr>>; // R1029
326 using IntConstantExpr = Integer<ConstantExpr>; // R1031
327 using ScalarLogicalExpr = Scalar<LogicalExpr>;
328 using ScalarIntExpr = Scalar<IntExpr>;
329 using ScalarIntConstantExpr = Scalar<IntConstantExpr>;
330 using ScalarDefaultCharExpr = Scalar<DefaultCharExpr>;
331 // R1030 default-char-constant-expr is used in the Standard only as part of
332 // scalar-default-char-constant-expr.
333 using ScalarDefaultCharConstantExpr = Scalar<DefaultChar<ConstantExpr>>;
334
335 // R611 label -> digit [digit]...
336 using Label = common::Label; // validated later, must be in [1..99999]
337
338 // A wrapper for xzy-stmt productions that are statements, so that
339 // source provenances and labels have a uniform representation.
340 template <typename A> struct UnlabeledStatement {
UnlabeledStatementUnlabeledStatement341 explicit UnlabeledStatement(A &&s) : statement(std::move(s)) {}
342 CharBlock source;
343 A statement;
344 };
345 template <typename A> struct Statement : public UnlabeledStatement<A> {
StatementStatement346 Statement(std::optional<long> &&lab, A &&s)
347 : UnlabeledStatement<A>{std::move(s)}, label(std::move(lab)) {}
348 std::optional<Label> label;
349 };
350
351 // Error recovery marker
352 EMPTY_CLASS(ErrorRecovery);
353
354 // R513 other-specification-stmt ->
355 // access-stmt | allocatable-stmt | asynchronous-stmt | bind-stmt |
356 // codimension-stmt | contiguous-stmt | dimension-stmt | external-stmt |
357 // intent-stmt | intrinsic-stmt | namelist-stmt | optional-stmt |
358 // pointer-stmt | protected-stmt | save-stmt | target-stmt |
359 // volatile-stmt | value-stmt | common-stmt | equivalence-stmt
360 // Extension: (Cray) based POINTER statement
361 struct OtherSpecificationStmt {
362 UNION_CLASS_BOILERPLATE(OtherSpecificationStmt);
363 std::variant<common::Indirection<AccessStmt>,
364 common::Indirection<AllocatableStmt>,
365 common::Indirection<AsynchronousStmt>, common::Indirection<BindStmt>,
366 common::Indirection<CodimensionStmt>, common::Indirection<ContiguousStmt>,
367 common::Indirection<DimensionStmt>, common::Indirection<ExternalStmt>,
368 common::Indirection<IntentStmt>, common::Indirection<IntrinsicStmt>,
369 common::Indirection<NamelistStmt>, common::Indirection<OptionalStmt>,
370 common::Indirection<PointerStmt>, common::Indirection<ProtectedStmt>,
371 common::Indirection<SaveStmt>, common::Indirection<TargetStmt>,
372 common::Indirection<ValueStmt>, common::Indirection<VolatileStmt>,
373 common::Indirection<CommonStmt>, common::Indirection<EquivalenceStmt>,
374 common::Indirection<BasedPointerStmt>>
375 u;
376 };
377
378 // R508 specification-construct ->
379 // derived-type-def | enum-def | generic-stmt | interface-block |
380 // parameter-stmt | procedure-declaration-stmt |
381 // other-specification-stmt | type-declaration-stmt
382 struct SpecificationConstruct {
383 UNION_CLASS_BOILERPLATE(SpecificationConstruct);
384 std::variant<common::Indirection<DerivedTypeDef>,
385 common::Indirection<EnumDef>, Statement<common::Indirection<GenericStmt>>,
386 common::Indirection<InterfaceBlock>,
387 Statement<common::Indirection<ParameterStmt>>,
388 Statement<common::Indirection<OldParameterStmt>>,
389 Statement<common::Indirection<ProcedureDeclarationStmt>>,
390 Statement<OtherSpecificationStmt>,
391 Statement<common::Indirection<TypeDeclarationStmt>>,
392 common::Indirection<StructureDef>,
393 common::Indirection<OpenACCDeclarativeConstruct>,
394 common::Indirection<OpenMPDeclarativeConstruct>,
395 common::Indirection<CompilerDirective>>
396 u;
397 };
398
399 // R506 implicit-part-stmt ->
400 // implicit-stmt | parameter-stmt | format-stmt | entry-stmt
401 struct ImplicitPartStmt {
402 UNION_CLASS_BOILERPLATE(ImplicitPartStmt);
403 std::variant<Statement<common::Indirection<ImplicitStmt>>,
404 Statement<common::Indirection<ParameterStmt>>,
405 Statement<common::Indirection<OldParameterStmt>>,
406 Statement<common::Indirection<FormatStmt>>,
407 Statement<common::Indirection<EntryStmt>>,
408 common::Indirection<CompilerDirective>>
409 u;
410 };
411
412 // R505 implicit-part -> [implicit-part-stmt]... implicit-stmt
413 WRAPPER_CLASS(ImplicitPart, std::list<ImplicitPartStmt>);
414
415 // R507 declaration-construct ->
416 // specification-construct | data-stmt | format-stmt |
417 // entry-stmt | stmt-function-stmt
418 struct DeclarationConstruct {
419 UNION_CLASS_BOILERPLATE(DeclarationConstruct);
420 std::variant<SpecificationConstruct, Statement<common::Indirection<DataStmt>>,
421 Statement<common::Indirection<FormatStmt>>,
422 Statement<common::Indirection<EntryStmt>>,
423 Statement<common::Indirection<StmtFunctionStmt>>, ErrorRecovery>
424 u;
425 };
426
427 // R504 specification-part -> [use-stmt]... [import-stmt]... [implicit-part]
428 // [declaration-construct]...
429 // PARAMETER, FORMAT, and ENTRY statements that appear before any other
430 // kind of declaration-construct will be parsed into the implicit-part,
431 // even if there are no IMPLICIT statements.
432 struct SpecificationPart {
433 TUPLE_CLASS_BOILERPLATE(SpecificationPart);
434 std::tuple<std::list<OpenACCDeclarativeConstruct>,
435 std::list<OpenMPDeclarativeConstruct>,
436 std::list<common::Indirection<CompilerDirective>>,
437 std::list<Statement<common::Indirection<UseStmt>>>,
438 std::list<Statement<common::Indirection<ImportStmt>>>, ImplicitPart,
439 std::list<DeclarationConstruct>>
440 t;
441 };
442
443 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
444 struct InternalSubprogram {
445 UNION_CLASS_BOILERPLATE(InternalSubprogram);
446 std::variant<common::Indirection<FunctionSubprogram>,
447 common::Indirection<SubroutineSubprogram>>
448 u;
449 };
450
451 // R1543 contains-stmt -> CONTAINS
452 EMPTY_CLASS(ContainsStmt);
453
454 // R511 internal-subprogram-part -> contains-stmt [internal-subprogram]...
455 struct InternalSubprogramPart {
456 TUPLE_CLASS_BOILERPLATE(InternalSubprogramPart);
457 std::tuple<Statement<ContainsStmt>, std::list<InternalSubprogram>> t;
458 };
459
460 // R1159 continue-stmt -> CONTINUE
461 EMPTY_CLASS(ContinueStmt);
462
463 // R1163 fail-image-stmt -> FAIL IMAGE
464 EMPTY_CLASS(FailImageStmt);
465
466 // R515 action-stmt ->
467 // allocate-stmt | assignment-stmt | backspace-stmt | call-stmt |
468 // close-stmt | continue-stmt | cycle-stmt | deallocate-stmt |
469 // endfile-stmt | error-stop-stmt | event-post-stmt | event-wait-stmt |
470 // exit-stmt | fail-image-stmt | flush-stmt | form-team-stmt |
471 // goto-stmt | if-stmt | inquire-stmt | lock-stmt | nullify-stmt |
472 // open-stmt | pointer-assignment-stmt | print-stmt | read-stmt |
473 // return-stmt | rewind-stmt | stop-stmt | sync-all-stmt |
474 // sync-images-stmt | sync-memory-stmt | sync-team-stmt | unlock-stmt |
475 // wait-stmt | where-stmt | write-stmt | computed-goto-stmt | forall-stmt
476 struct ActionStmt {
477 UNION_CLASS_BOILERPLATE(ActionStmt);
478 std::variant<common::Indirection<AllocateStmt>,
479 common::Indirection<AssignmentStmt>, common::Indirection<BackspaceStmt>,
480 common::Indirection<CallStmt>, common::Indirection<CloseStmt>,
481 ContinueStmt, common::Indirection<CycleStmt>,
482 common::Indirection<DeallocateStmt>, common::Indirection<EndfileStmt>,
483 common::Indirection<EventPostStmt>, common::Indirection<EventWaitStmt>,
484 common::Indirection<ExitStmt>, FailImageStmt,
485 common::Indirection<FlushStmt>, common::Indirection<FormTeamStmt>,
486 common::Indirection<GotoStmt>, common::Indirection<IfStmt>,
487 common::Indirection<InquireStmt>, common::Indirection<LockStmt>,
488 common::Indirection<NullifyStmt>, common::Indirection<OpenStmt>,
489 common::Indirection<PointerAssignmentStmt>,
490 common::Indirection<PrintStmt>, common::Indirection<ReadStmt>,
491 common::Indirection<ReturnStmt>, common::Indirection<RewindStmt>,
492 common::Indirection<StopStmt>, common::Indirection<SyncAllStmt>,
493 common::Indirection<SyncImagesStmt>, common::Indirection<SyncMemoryStmt>,
494 common::Indirection<SyncTeamStmt>, common::Indirection<UnlockStmt>,
495 common::Indirection<WaitStmt>, common::Indirection<WhereStmt>,
496 common::Indirection<WriteStmt>, common::Indirection<ComputedGotoStmt>,
497 common::Indirection<ForallStmt>, common::Indirection<ArithmeticIfStmt>,
498 common::Indirection<AssignStmt>, common::Indirection<AssignedGotoStmt>,
499 common::Indirection<PauseStmt>>
500 u;
501 };
502
503 // R514 executable-construct ->
504 // action-stmt | associate-construct | block-construct |
505 // case-construct | change-team-construct | critical-construct |
506 // do-construct | if-construct | select-rank-construct |
507 // select-type-construct | where-construct | forall-construct
508 struct ExecutableConstruct {
509 UNION_CLASS_BOILERPLATE(ExecutableConstruct);
510 std::variant<Statement<ActionStmt>, common::Indirection<AssociateConstruct>,
511 common::Indirection<BlockConstruct>, common::Indirection<CaseConstruct>,
512 common::Indirection<ChangeTeamConstruct>,
513 common::Indirection<CriticalConstruct>,
514 Statement<common::Indirection<LabelDoStmt>>,
515 Statement<common::Indirection<EndDoStmt>>,
516 common::Indirection<DoConstruct>, common::Indirection<IfConstruct>,
517 common::Indirection<SelectRankConstruct>,
518 common::Indirection<SelectTypeConstruct>,
519 common::Indirection<WhereConstruct>, common::Indirection<ForallConstruct>,
520 common::Indirection<CompilerDirective>,
521 common::Indirection<OpenACCConstruct>,
522 common::Indirection<AccEndCombinedDirective>,
523 common::Indirection<OpenMPConstruct>,
524 common::Indirection<OmpEndLoopDirective>>
525 u;
526 };
527
528 // R510 execution-part-construct ->
529 // executable-construct | format-stmt | entry-stmt | data-stmt
530 // Extension (PGI/Intel): also accept NAMELIST in execution part
531 struct ExecutionPartConstruct {
532 UNION_CLASS_BOILERPLATE(ExecutionPartConstruct);
533 std::variant<ExecutableConstruct, Statement<common::Indirection<FormatStmt>>,
534 Statement<common::Indirection<EntryStmt>>,
535 Statement<common::Indirection<DataStmt>>,
536 Statement<common::Indirection<NamelistStmt>>, ErrorRecovery>
537 u;
538 };
539
540 // R509 execution-part -> executable-construct [execution-part-construct]...
541 WRAPPER_CLASS(ExecutionPart, std::list<ExecutionPartConstruct>);
542
543 // R502 program-unit ->
544 // main-program | external-subprogram | module | submodule | block-data
545 // R503 external-subprogram -> function-subprogram | subroutine-subprogram
546 struct ProgramUnit {
547 UNION_CLASS_BOILERPLATE(ProgramUnit);
548 std::variant<common::Indirection<MainProgram>,
549 common::Indirection<FunctionSubprogram>,
550 common::Indirection<SubroutineSubprogram>, common::Indirection<Module>,
551 common::Indirection<Submodule>, common::Indirection<BlockData>,
552 common::Indirection<CompilerDirective>>
553 u;
554 };
555
556 // R501 program -> program-unit [program-unit]...
557 // This is the top-level production.
558 WRAPPER_CLASS(Program, std::list<ProgramUnit>);
559
560 // R603 name -> letter [alphanumeric-character]...
561 struct Name {
ToStringName562 std::string ToString() const { return source.ToString(); }
563 CharBlock source;
564 mutable semantics::Symbol *symbol{nullptr}; // filled in during semantics
565 };
566
567 // R516 keyword -> name
568 WRAPPER_CLASS(Keyword, Name);
569
570 // R606 named-constant -> name
571 WRAPPER_CLASS(NamedConstant, Name);
572
573 // R1003 defined-unary-op -> . letter [letter]... .
574 // R1023 defined-binary-op -> . letter [letter]... .
575 // R1414 local-defined-operator -> defined-unary-op | defined-binary-op
576 // R1415 use-defined-operator -> defined-unary-op | defined-binary-op
577 // The Name here is stored with the dots; e.g., .FOO.
578 WRAPPER_CLASS(DefinedOpName, Name);
579
580 // R608 intrinsic-operator ->
581 // ** | * | / | + | - | // | .LT. | .LE. | .EQ. | .NE. | .GE. | .GT. |
582 // .NOT. | .AND. | .OR. | .EQV. | .NEQV.
583 // R609 defined-operator ->
584 // defined-unary-op | defined-binary-op | extended-intrinsic-op
585 // R610 extended-intrinsic-op -> intrinsic-operator
586 struct DefinedOperator {
587 UNION_CLASS_BOILERPLATE(DefinedOperator);
588 ENUM_CLASS(IntrinsicOperator, Power, Multiply, Divide, Add, Subtract, Concat,
589 LT, LE, EQ, NE, GE, GT, NOT, AND, OR, EQV, NEQV)
590 std::variant<DefinedOpName, IntrinsicOperator> u;
591 };
592
593 // R804 object-name -> name
594 using ObjectName = Name;
595
596 // R867 import-stmt ->
597 // IMPORT [[::] import-name-list] |
598 // IMPORT , ONLY : import-name-list | IMPORT , NONE | IMPORT , ALL
599 struct ImportStmt {
600 BOILERPLATE(ImportStmt);
ImportStmtImportStmt601 ImportStmt(common::ImportKind &&k) : kind{k} {}
ImportStmtImportStmt602 ImportStmt(std::list<Name> &&n) : names(std::move(n)) {}
603 ImportStmt(common::ImportKind &&, std::list<Name> &&);
604 common::ImportKind kind{common::ImportKind::Default};
605 std::list<Name> names;
606 };
607
608 // R868 namelist-stmt ->
609 // NAMELIST / namelist-group-name / namelist-group-object-list
610 // [[,] / namelist-group-name / namelist-group-object-list]...
611 // R869 namelist-group-object -> variable-name
612 struct NamelistStmt {
613 struct Group {
614 TUPLE_CLASS_BOILERPLATE(Group);
615 std::tuple<Name, std::list<Name>> t;
616 };
617 WRAPPER_CLASS_BOILERPLATE(NamelistStmt, std::list<Group>);
618 };
619
620 // R701 type-param-value -> scalar-int-expr | * | :
621 EMPTY_CLASS(Star);
622
623 struct TypeParamValue {
624 UNION_CLASS_BOILERPLATE(TypeParamValue);
625 EMPTY_CLASS(Deferred); // :
626 std::variant<ScalarIntExpr, Star, Deferred> u;
627 };
628
629 // R706 kind-selector -> ( [KIND =] scalar-int-constant-expr )
630 // Legacy extension: kind-selector -> * digit-string
631 // N.B. These are not semantically identical in the case of COMPLEX.
632 struct KindSelector {
633 UNION_CLASS_BOILERPLATE(KindSelector);
634 WRAPPER_CLASS(StarSize, std::uint64_t);
635 std::variant<ScalarIntConstantExpr, StarSize> u;
636 };
637
638 // R705 integer-type-spec -> INTEGER [kind-selector]
639 WRAPPER_CLASS(IntegerTypeSpec, std::optional<KindSelector>);
640
641 // R723 char-length -> ( type-param-value ) | digit-string
642 struct CharLength {
643 UNION_CLASS_BOILERPLATE(CharLength);
644 std::variant<TypeParamValue, std::uint64_t> u;
645 };
646
647 // R722 length-selector -> ( [LEN =] type-param-value ) | * char-length [,]
648 struct LengthSelector {
649 UNION_CLASS_BOILERPLATE(LengthSelector);
650 std::variant<TypeParamValue, CharLength> u;
651 };
652
653 // R721 char-selector ->
654 // length-selector |
655 // ( LEN = type-param-value , KIND = scalar-int-constant-expr ) |
656 // ( type-param-value , [KIND =] scalar-int-constant-expr ) |
657 // ( KIND = scalar-int-constant-expr [, LEN = type-param-value] )
658 struct CharSelector {
659 UNION_CLASS_BOILERPLATE(CharSelector);
660 struct LengthAndKind {
661 BOILERPLATE(LengthAndKind);
LengthAndKindCharSelector::LengthAndKind662 LengthAndKind(std::optional<TypeParamValue> &&l, ScalarIntConstantExpr &&k)
663 : length(std::move(l)), kind(std::move(k)) {}
664 std::optional<TypeParamValue> length;
665 ScalarIntConstantExpr kind;
666 };
CharSelectorCharSelector667 CharSelector(TypeParamValue &&l, ScalarIntConstantExpr &&k)
668 : u{LengthAndKind{std::make_optional(std::move(l)), std::move(k)}} {}
CharSelectorCharSelector669 CharSelector(ScalarIntConstantExpr &&k, std::optional<TypeParamValue> &&l)
670 : u{LengthAndKind{std::move(l), std::move(k)}} {}
671 std::variant<LengthSelector, LengthAndKind> u;
672 };
673
674 // R704 intrinsic-type-spec ->
675 // integer-type-spec | REAL [kind-selector] | DOUBLE PRECISION |
676 // COMPLEX [kind-selector] | CHARACTER [char-selector] |
677 // LOGICAL [kind-selector]
678 // Extensions: DOUBLE COMPLEX
679 struct IntrinsicTypeSpec {
680 UNION_CLASS_BOILERPLATE(IntrinsicTypeSpec);
681 struct Real {
682 BOILERPLATE(Real);
RealIntrinsicTypeSpec::Real683 Real(std::optional<KindSelector> &&k) : kind{std::move(k)} {}
684 std::optional<KindSelector> kind;
685 };
686 EMPTY_CLASS(DoublePrecision);
687 struct Complex {
688 BOILERPLATE(Complex);
ComplexIntrinsicTypeSpec::Complex689 Complex(std::optional<KindSelector> &&k) : kind{std::move(k)} {}
690 std::optional<KindSelector> kind;
691 };
692 struct Character {
693 BOILERPLATE(Character);
CharacterIntrinsicTypeSpec::Character694 Character(std::optional<CharSelector> &&s) : selector{std::move(s)} {}
695 std::optional<CharSelector> selector;
696 };
697 struct Logical {
698 BOILERPLATE(Logical);
LogicalIntrinsicTypeSpec::Logical699 Logical(std::optional<KindSelector> &&k) : kind{std::move(k)} {}
700 std::optional<KindSelector> kind;
701 };
702 EMPTY_CLASS(DoubleComplex);
703 std::variant<IntegerTypeSpec, Real, DoublePrecision, Complex, Character,
704 Logical, DoubleComplex>
705 u;
706 };
707
708 // R755 type-param-spec -> [keyword =] type-param-value
709 struct TypeParamSpec {
710 TUPLE_CLASS_BOILERPLATE(TypeParamSpec);
711 std::tuple<std::optional<Keyword>, TypeParamValue> t;
712 };
713
714 // R754 derived-type-spec -> type-name [(type-param-spec-list)]
715 struct DerivedTypeSpec {
716 TUPLE_CLASS_BOILERPLATE(DerivedTypeSpec);
717 mutable const semantics::DerivedTypeSpec *derivedTypeSpec{nullptr};
718 std::tuple<Name, std::list<TypeParamSpec>> t;
719 };
720
721 // R702 type-spec -> intrinsic-type-spec | derived-type-spec
722 struct TypeSpec {
723 UNION_CLASS_BOILERPLATE(TypeSpec);
724 mutable const semantics::DeclTypeSpec *declTypeSpec{nullptr};
725 std::variant<IntrinsicTypeSpec, DerivedTypeSpec> u;
726 };
727
728 // R703 declaration-type-spec ->
729 // intrinsic-type-spec | TYPE ( intrinsic-type-spec ) |
730 // TYPE ( derived-type-spec ) | CLASS ( derived-type-spec ) |
731 // CLASS ( * ) | TYPE ( * )
732 // Legacy extension: RECORD /struct/
733 struct DeclarationTypeSpec {
734 UNION_CLASS_BOILERPLATE(DeclarationTypeSpec);
735 struct Type {
736 BOILERPLATE(Type);
TypeDeclarationTypeSpec::Type737 Type(DerivedTypeSpec &&dt) : derived(std::move(dt)) {}
738 DerivedTypeSpec derived;
739 };
740 struct Class {
741 BOILERPLATE(Class);
ClassDeclarationTypeSpec::Class742 Class(DerivedTypeSpec &&dt) : derived(std::move(dt)) {}
743 DerivedTypeSpec derived;
744 };
745 EMPTY_CLASS(ClassStar);
746 EMPTY_CLASS(TypeStar);
747 WRAPPER_CLASS(Record, Name);
748 std::variant<IntrinsicTypeSpec, Type, Class, ClassStar, TypeStar, Record> u;
749 };
750
751 // R709 kind-param -> digit-string | scalar-int-constant-name
752 struct KindParam {
753 UNION_CLASS_BOILERPLATE(KindParam);
754 std::variant<std::uint64_t, Scalar<Integer<Constant<Name>>>> u;
755 };
756
757 // R707 signed-int-literal-constant -> [sign] int-literal-constant
758 struct SignedIntLiteralConstant {
759 TUPLE_CLASS_BOILERPLATE(SignedIntLiteralConstant);
760 CharBlock source;
761 std::tuple<CharBlock, std::optional<KindParam>> t;
762 };
763
764 // R708 int-literal-constant -> digit-string [_ kind-param]
765 struct IntLiteralConstant {
766 TUPLE_CLASS_BOILERPLATE(IntLiteralConstant);
767 std::tuple<CharBlock, std::optional<KindParam>> t;
768 };
769
770 // R712 sign -> + | -
771 enum class Sign { Positive, Negative };
772
773 // R714 real-literal-constant ->
774 // significand [exponent-letter exponent] [_ kind-param] |
775 // digit-string exponent-letter exponent [_ kind-param]
776 // R715 significand -> digit-string . [digit-string] | . digit-string
777 // R717 exponent -> signed-digit-string
778 struct RealLiteralConstant {
779 BOILERPLATE(RealLiteralConstant);
780 struct Real {
781 COPY_AND_ASSIGN_BOILERPLATE(Real);
RealRealLiteralConstant::Real782 Real() {}
783 CharBlock source;
784 };
RealLiteralConstantRealLiteralConstant785 RealLiteralConstant(Real &&r, std::optional<KindParam> &&k)
786 : real{std::move(r)}, kind{std::move(k)} {}
787 Real real;
788 std::optional<KindParam> kind;
789 };
790
791 // R713 signed-real-literal-constant -> [sign] real-literal-constant
792 struct SignedRealLiteralConstant {
793 TUPLE_CLASS_BOILERPLATE(SignedRealLiteralConstant);
794 std::tuple<std::optional<Sign>, RealLiteralConstant> t;
795 };
796
797 // R719 real-part ->
798 // signed-int-literal-constant | signed-real-literal-constant |
799 // named-constant
800 // R720 imag-part ->
801 // signed-int-literal-constant | signed-real-literal-constant |
802 // named-constant
803 struct ComplexPart {
804 UNION_CLASS_BOILERPLATE(ComplexPart);
805 std::variant<SignedIntLiteralConstant, SignedRealLiteralConstant,
806 NamedConstant>
807 u;
808 };
809
810 // R718 complex-literal-constant -> ( real-part , imag-part )
811 struct ComplexLiteralConstant {
812 TUPLE_CLASS_BOILERPLATE(ComplexLiteralConstant);
813 std::tuple<ComplexPart, ComplexPart> t; // real, imaginary
814 };
815
816 // Extension: signed COMPLEX constant
817 struct SignedComplexLiteralConstant {
818 TUPLE_CLASS_BOILERPLATE(SignedComplexLiteralConstant);
819 std::tuple<Sign, ComplexLiteralConstant> t;
820 };
821
822 // R724 char-literal-constant ->
823 // [kind-param _] ' [rep-char]... ' |
824 // [kind-param _] " [rep-char]... "
825 struct CharLiteralConstant {
826 TUPLE_CLASS_BOILERPLATE(CharLiteralConstant);
827 std::tuple<std::optional<KindParam>, std::string> t;
GetStringCharLiteralConstant828 std::string GetString() const { return std::get<std::string>(t); }
829 };
830
831 // legacy extension
832 struct HollerithLiteralConstant {
833 WRAPPER_CLASS_BOILERPLATE(HollerithLiteralConstant, std::string);
GetStringHollerithLiteralConstant834 std::string GetString() const { return v; }
835 };
836
837 // R725 logical-literal-constant ->
838 // .TRUE. [_ kind-param] | .FALSE. [_ kind-param]
839 struct LogicalLiteralConstant {
840 TUPLE_CLASS_BOILERPLATE(LogicalLiteralConstant);
841 std::tuple<bool, std::optional<KindParam>> t;
842 };
843
844 // R764 boz-literal-constant -> binary-constant | octal-constant | hex-constant
845 // R765 binary-constant -> B ' digit [digit]... ' | B " digit [digit]... "
846 // R766 octal-constant -> O ' digit [digit]... ' | O " digit [digit]... "
847 // R767 hex-constant ->
848 // Z ' hex-digit [hex-digit]... ' | Z " hex-digit [hex-digit]... "
849 // The constant must be large enough to hold any real or integer scalar
850 // of any supported kind (F'2018 7.7).
851 WRAPPER_CLASS(BOZLiteralConstant, std::string);
852
853 // R605 literal-constant ->
854 // int-literal-constant | real-literal-constant |
855 // complex-literal-constant | logical-literal-constant |
856 // char-literal-constant | boz-literal-constant
857 struct LiteralConstant {
858 UNION_CLASS_BOILERPLATE(LiteralConstant);
859 std::variant<HollerithLiteralConstant, IntLiteralConstant,
860 RealLiteralConstant, ComplexLiteralConstant, BOZLiteralConstant,
861 CharLiteralConstant, LogicalLiteralConstant>
862 u;
863 };
864
865 // R807 access-spec -> PUBLIC | PRIVATE
866 struct AccessSpec {
867 ENUM_CLASS(Kind, Public, Private)
868 WRAPPER_CLASS_BOILERPLATE(AccessSpec, Kind);
869 };
870
871 // R728 type-attr-spec ->
872 // ABSTRACT | access-spec | BIND(C) | EXTENDS ( parent-type-name )
873 EMPTY_CLASS(Abstract);
874 struct TypeAttrSpec {
875 UNION_CLASS_BOILERPLATE(TypeAttrSpec);
876 EMPTY_CLASS(BindC);
877 WRAPPER_CLASS(Extends, Name);
878 std::variant<Abstract, AccessSpec, BindC, Extends> u;
879 };
880
881 // R727 derived-type-stmt ->
882 // TYPE [[, type-attr-spec-list] ::] type-name [( type-param-name-list )]
883 struct DerivedTypeStmt {
884 TUPLE_CLASS_BOILERPLATE(DerivedTypeStmt);
885 std::tuple<std::list<TypeAttrSpec>, Name, std::list<Name>> t;
886 };
887
888 // R731 sequence-stmt -> SEQUENCE
889 EMPTY_CLASS(SequenceStmt);
890
891 // R745 private-components-stmt -> PRIVATE
892 // R747 binding-private-stmt -> PRIVATE
893 EMPTY_CLASS(PrivateStmt);
894
895 // R729 private-or-sequence -> private-components-stmt | sequence-stmt
896 struct PrivateOrSequence {
897 UNION_CLASS_BOILERPLATE(PrivateOrSequence);
898 std::variant<PrivateStmt, SequenceStmt> u;
899 };
900
901 // R733 type-param-decl -> type-param-name [= scalar-int-constant-expr]
902 struct TypeParamDecl {
903 TUPLE_CLASS_BOILERPLATE(TypeParamDecl);
904 std::tuple<Name, std::optional<ScalarIntConstantExpr>> t;
905 };
906
907 // R732 type-param-def-stmt ->
908 // integer-type-spec , type-param-attr-spec :: type-param-decl-list
909 // R734 type-param-attr-spec -> KIND | LEN
910 struct TypeParamDefStmt {
911 TUPLE_CLASS_BOILERPLATE(TypeParamDefStmt);
912 std::tuple<IntegerTypeSpec, common::TypeParamAttr, std::list<TypeParamDecl>>
913 t;
914 };
915
916 // R1028 specification-expr -> scalar-int-expr
917 WRAPPER_CLASS(SpecificationExpr, ScalarIntExpr);
918
919 // R816 explicit-shape-spec -> [lower-bound :] upper-bound
920 // R817 lower-bound -> specification-expr
921 // R818 upper-bound -> specification-expr
922 struct ExplicitShapeSpec {
923 TUPLE_CLASS_BOILERPLATE(ExplicitShapeSpec);
924 std::tuple<std::optional<SpecificationExpr>, SpecificationExpr> t;
925 };
926
927 // R810 deferred-coshape-spec -> :
928 // deferred-coshape-spec-list is just a count of the colons (i.e., the rank).
929 WRAPPER_CLASS(DeferredCoshapeSpecList, int);
930
931 // R811 explicit-coshape-spec ->
932 // [[lower-cobound :] upper-cobound ,]... [lower-cobound :] *
933 // R812 lower-cobound -> specification-expr
934 // R813 upper-cobound -> specification-expr
935 struct ExplicitCoshapeSpec {
936 TUPLE_CLASS_BOILERPLATE(ExplicitCoshapeSpec);
937 std::tuple<std::list<ExplicitShapeSpec>, std::optional<SpecificationExpr>> t;
938 };
939
940 // R809 coarray-spec -> deferred-coshape-spec-list | explicit-coshape-spec
941 struct CoarraySpec {
942 UNION_CLASS_BOILERPLATE(CoarraySpec);
943 std::variant<DeferredCoshapeSpecList, ExplicitCoshapeSpec> u;
944 };
945
946 // R820 deferred-shape-spec -> :
947 // deferred-shape-spec-list is just a count of the colons (i.e., the rank).
948 WRAPPER_CLASS(DeferredShapeSpecList, int);
949
950 // R740 component-array-spec ->
951 // explicit-shape-spec-list | deferred-shape-spec-list
952 struct ComponentArraySpec {
953 UNION_CLASS_BOILERPLATE(ComponentArraySpec);
954 std::variant<std::list<ExplicitShapeSpec>, DeferredShapeSpecList> u;
955 };
956
957 // R738 component-attr-spec ->
958 // access-spec | ALLOCATABLE |
959 // CODIMENSION lbracket coarray-spec rbracket |
960 // CONTIGUOUS | DIMENSION ( component-array-spec ) | POINTER
961 EMPTY_CLASS(Allocatable);
962 EMPTY_CLASS(Pointer);
963 EMPTY_CLASS(Contiguous);
964 struct ComponentAttrSpec {
965 UNION_CLASS_BOILERPLATE(ComponentAttrSpec);
966 std::variant<AccessSpec, Allocatable, CoarraySpec, Contiguous,
967 ComponentArraySpec, Pointer, ErrorRecovery>
968 u;
969 };
970
971 // R806 null-init -> function-reference ... which must be NULL()
972 WRAPPER_CLASS(NullInit, common::Indirection<Expr>);
973
974 // R744 initial-data-target -> designator
975 using InitialDataTarget = common::Indirection<Designator>;
976
977 // R743 component-initialization ->
978 // = constant-expr | => null-init | => initial-data-target
979 // R805 initialization ->
980 // = constant-expr | => null-init | => initial-data-target
981 // Universal extension: initialization -> / data-stmt-value-list /
982 struct Initialization {
983 UNION_CLASS_BOILERPLATE(Initialization);
984 std::variant<ConstantExpr, NullInit, InitialDataTarget,
985 std::list<common::Indirection<DataStmtValue>>>
986 u;
987 };
988
989 // R739 component-decl ->
990 // component-name [( component-array-spec )]
991 // [lbracket coarray-spec rbracket] [* char-length]
992 // [component-initialization]
993 struct ComponentDecl {
994 TUPLE_CLASS_BOILERPLATE(ComponentDecl);
995 std::tuple<Name, std::optional<ComponentArraySpec>,
996 std::optional<CoarraySpec>, std::optional<CharLength>,
997 std::optional<Initialization>>
998 t;
999 };
1000
1001 // R737 data-component-def-stmt ->
1002 // declaration-type-spec [[, component-attr-spec-list] ::]
1003 // component-decl-list
1004 struct DataComponentDefStmt {
1005 TUPLE_CLASS_BOILERPLATE(DataComponentDefStmt);
1006 std::tuple<DeclarationTypeSpec, std::list<ComponentAttrSpec>,
1007 std::list<ComponentDecl>>
1008 t;
1009 };
1010
1011 // R742 proc-component-attr-spec ->
1012 // access-spec | NOPASS | PASS [(arg-name)] | POINTER
1013 EMPTY_CLASS(NoPass);
1014 WRAPPER_CLASS(Pass, std::optional<Name>);
1015 struct ProcComponentAttrSpec {
1016 UNION_CLASS_BOILERPLATE(ProcComponentAttrSpec);
1017 std::variant<AccessSpec, NoPass, Pass, Pointer> u;
1018 };
1019
1020 // R1517 proc-pointer-init -> null-init | initial-proc-target
1021 // R1518 initial-proc-target -> procedure-name
1022 struct ProcPointerInit {
1023 UNION_CLASS_BOILERPLATE(ProcPointerInit);
1024 std::variant<NullInit, Name> u;
1025 };
1026
1027 // R1513 proc-interface -> interface-name | declaration-type-spec
1028 // R1516 interface-name -> name
1029 struct ProcInterface {
1030 UNION_CLASS_BOILERPLATE(ProcInterface);
1031 std::variant<Name, DeclarationTypeSpec> u;
1032 };
1033
1034 // R1515 proc-decl -> procedure-entity-name [=> proc-pointer-init]
1035 struct ProcDecl {
1036 TUPLE_CLASS_BOILERPLATE(ProcDecl);
1037 std::tuple<Name, std::optional<ProcPointerInit>> t;
1038 };
1039
1040 // R741 proc-component-def-stmt ->
1041 // PROCEDURE ( [proc-interface] ) , proc-component-attr-spec-list
1042 // :: proc-decl-list
1043 struct ProcComponentDefStmt {
1044 TUPLE_CLASS_BOILERPLATE(ProcComponentDefStmt);
1045 std::tuple<std::optional<ProcInterface>, std::list<ProcComponentAttrSpec>,
1046 std::list<ProcDecl>>
1047 t;
1048 };
1049
1050 // R736 component-def-stmt -> data-component-def-stmt | proc-component-def-stmt
1051 struct ComponentDefStmt {
1052 UNION_CLASS_BOILERPLATE(ComponentDefStmt);
1053 std::variant<DataComponentDefStmt, ProcComponentDefStmt, ErrorRecovery
1054 // , TypeParamDefStmt -- PGI accidental extension, not enabled
1055 >
1056 u;
1057 };
1058
1059 // R752 bind-attr ->
1060 // access-spec | DEFERRED | NON_OVERRIDABLE | NOPASS | PASS [(arg-name)]
1061 struct BindAttr {
1062 UNION_CLASS_BOILERPLATE(BindAttr);
1063 EMPTY_CLASS(Deferred);
1064 EMPTY_CLASS(Non_Overridable);
1065 std::variant<AccessSpec, Deferred, Non_Overridable, NoPass, Pass> u;
1066 };
1067
1068 // R750 type-bound-proc-decl -> binding-name [=> procedure-name]
1069 struct TypeBoundProcDecl {
1070 TUPLE_CLASS_BOILERPLATE(TypeBoundProcDecl);
1071 std::tuple<Name, std::optional<Name>> t;
1072 };
1073
1074 // R749 type-bound-procedure-stmt ->
1075 // PROCEDURE [[, bind-attr-list] ::] type-bound-proc-decl-list |
1076 // PROCEDURE ( interface-name ) , bind-attr-list :: binding-name-list
1077 // The second form, with interface-name, requires DEFERRED in bind-attr-list,
1078 // and thus can appear only in an abstract type.
1079 struct TypeBoundProcedureStmt {
1080 UNION_CLASS_BOILERPLATE(TypeBoundProcedureStmt);
1081 struct WithoutInterface {
1082 BOILERPLATE(WithoutInterface);
WithoutInterfaceTypeBoundProcedureStmt::WithoutInterface1083 WithoutInterface(
1084 std::list<BindAttr> &&as, std::list<TypeBoundProcDecl> &&ds)
1085 : attributes(std::move(as)), declarations(std::move(ds)) {}
1086 std::list<BindAttr> attributes;
1087 std::list<TypeBoundProcDecl> declarations;
1088 };
1089 struct WithInterface {
1090 BOILERPLATE(WithInterface);
WithInterfaceTypeBoundProcedureStmt::WithInterface1091 WithInterface(Name &&n, std::list<BindAttr> &&as, std::list<Name> &&bs)
1092 : interfaceName(std::move(n)), attributes(std::move(as)),
1093 bindingNames(std::move(bs)) {}
1094 Name interfaceName;
1095 std::list<BindAttr> attributes;
1096 std::list<Name> bindingNames;
1097 };
1098 std::variant<WithoutInterface, WithInterface> u;
1099 };
1100
1101 // R751 type-bound-generic-stmt ->
1102 // GENERIC [, access-spec] :: generic-spec => binding-name-list
1103 struct TypeBoundGenericStmt {
1104 TUPLE_CLASS_BOILERPLATE(TypeBoundGenericStmt);
1105 std::tuple<std::optional<AccessSpec>, common::Indirection<GenericSpec>,
1106 std::list<Name>>
1107 t;
1108 };
1109
1110 // R753 final-procedure-stmt -> FINAL [::] final-subroutine-name-list
1111 WRAPPER_CLASS(FinalProcedureStmt, std::list<Name>);
1112
1113 // R748 type-bound-proc-binding ->
1114 // type-bound-procedure-stmt | type-bound-generic-stmt |
1115 // final-procedure-stmt
1116 struct TypeBoundProcBinding {
1117 UNION_CLASS_BOILERPLATE(TypeBoundProcBinding);
1118 std::variant<TypeBoundProcedureStmt, TypeBoundGenericStmt, FinalProcedureStmt,
1119 ErrorRecovery>
1120 u;
1121 };
1122
1123 // R746 type-bound-procedure-part ->
1124 // contains-stmt [binding-private-stmt] [type-bound-proc-binding]...
1125 struct TypeBoundProcedurePart {
1126 TUPLE_CLASS_BOILERPLATE(TypeBoundProcedurePart);
1127 std::tuple<Statement<ContainsStmt>, std::optional<Statement<PrivateStmt>>,
1128 std::list<Statement<TypeBoundProcBinding>>>
1129 t;
1130 };
1131
1132 // R730 end-type-stmt -> END TYPE [type-name]
1133 WRAPPER_CLASS(EndTypeStmt, std::optional<Name>);
1134
1135 // R726 derived-type-def ->
1136 // derived-type-stmt [type-param-def-stmt]... [private-or-sequence]...
1137 // [component-part] [type-bound-procedure-part] end-type-stmt
1138 // R735 component-part -> [component-def-stmt]...
1139 struct DerivedTypeDef {
1140 TUPLE_CLASS_BOILERPLATE(DerivedTypeDef);
1141 std::tuple<Statement<DerivedTypeStmt>, std::list<Statement<TypeParamDefStmt>>,
1142 std::list<Statement<PrivateOrSequence>>,
1143 std::list<Statement<ComponentDefStmt>>,
1144 std::optional<TypeBoundProcedurePart>, Statement<EndTypeStmt>>
1145 t;
1146 };
1147
1148 // R758 component-data-source -> expr | data-target | proc-target
1149 // R1037 data-target -> expr
1150 // R1040 proc-target -> expr | procedure-name | proc-component-ref
1151 WRAPPER_CLASS(ComponentDataSource, common::Indirection<Expr>);
1152
1153 // R757 component-spec -> [keyword =] component-data-source
1154 struct ComponentSpec {
1155 TUPLE_CLASS_BOILERPLATE(ComponentSpec);
1156 std::tuple<std::optional<Keyword>, ComponentDataSource> t;
1157 };
1158
1159 // R756 structure-constructor -> derived-type-spec ( [component-spec-list] )
1160 struct StructureConstructor {
1161 TUPLE_CLASS_BOILERPLATE(StructureConstructor);
1162 std::tuple<DerivedTypeSpec, std::list<ComponentSpec>> t;
1163 };
1164
1165 // R760 enum-def-stmt -> ENUM, BIND(C)
1166 EMPTY_CLASS(EnumDefStmt);
1167
1168 // R762 enumerator -> named-constant [= scalar-int-constant-expr]
1169 struct Enumerator {
1170 TUPLE_CLASS_BOILERPLATE(Enumerator);
1171 std::tuple<NamedConstant, std::optional<ScalarIntConstantExpr>> t;
1172 };
1173
1174 // R761 enumerator-def-stmt -> ENUMERATOR [::] enumerator-list
1175 WRAPPER_CLASS(EnumeratorDefStmt, std::list<Enumerator>);
1176
1177 // R763 end-enum-stmt -> END ENUM
1178 EMPTY_CLASS(EndEnumStmt);
1179
1180 // R759 enum-def ->
1181 // enum-def-stmt enumerator-def-stmt [enumerator-def-stmt]...
1182 // end-enum-stmt
1183 struct EnumDef {
1184 TUPLE_CLASS_BOILERPLATE(EnumDef);
1185 std::tuple<Statement<EnumDefStmt>, std::list<Statement<EnumeratorDefStmt>>,
1186 Statement<EndEnumStmt>>
1187 t;
1188 };
1189
1190 // R773 ac-value -> expr | ac-implied-do
1191 struct AcValue {
1192 struct Triplet { // PGI/Intel extension
1193 TUPLE_CLASS_BOILERPLATE(Triplet);
1194 std::tuple<ScalarIntExpr, ScalarIntExpr, std::optional<ScalarIntExpr>> t;
1195 };
1196 UNION_CLASS_BOILERPLATE(AcValue);
1197 std::variant<Triplet, common::Indirection<Expr>,
1198 common::Indirection<AcImpliedDo>>
1199 u;
1200 };
1201
1202 // R770 ac-spec -> type-spec :: | [type-spec ::] ac-value-list
1203 struct AcSpec {
1204 BOILERPLATE(AcSpec);
AcSpecAcSpec1205 AcSpec(std::optional<TypeSpec> &&ts, std::list<AcValue> &&xs)
1206 : type(std::move(ts)), values(std::move(xs)) {}
AcSpecAcSpec1207 explicit AcSpec(TypeSpec &&ts) : type{std::move(ts)} {}
1208 std::optional<TypeSpec> type;
1209 std::list<AcValue> values;
1210 };
1211
1212 // R769 array-constructor -> (/ ac-spec /) | lbracket ac-spec rbracket
1213 WRAPPER_CLASS(ArrayConstructor, AcSpec);
1214
1215 // R1124 do-variable -> scalar-int-variable-name
1216 using DoVariable = Scalar<Integer<Name>>;
1217
1218 template <typename VAR, typename BOUND> struct LoopBounds {
1219 LoopBounds(LoopBounds &&that) = default;
LoopBoundsLoopBounds1220 LoopBounds(
1221 VAR &&name, BOUND &&lower, BOUND &&upper, std::optional<BOUND> &&step)
1222 : name{std::move(name)}, lower{std::move(lower)}, upper{std::move(upper)},
1223 step{std::move(step)} {}
1224 LoopBounds &operator=(LoopBounds &&) = default;
1225 VAR name;
1226 BOUND lower, upper;
1227 std::optional<BOUND> step;
1228 };
1229
1230 using ScalarName = Scalar<Name>;
1231 using ScalarExpr = Scalar<common::Indirection<Expr>>;
1232
1233 // R775 ac-implied-do-control ->
1234 // [integer-type-spec ::] ac-do-variable = scalar-int-expr ,
1235 // scalar-int-expr [, scalar-int-expr]
1236 // R776 ac-do-variable -> do-variable
1237 struct AcImpliedDoControl {
1238 TUPLE_CLASS_BOILERPLATE(AcImpliedDoControl);
1239 using Bounds = LoopBounds<DoVariable, ScalarIntExpr>;
1240 std::tuple<std::optional<IntegerTypeSpec>, Bounds> t;
1241 };
1242
1243 // R774 ac-implied-do -> ( ac-value-list , ac-implied-do-control )
1244 struct AcImpliedDo {
1245 TUPLE_CLASS_BOILERPLATE(AcImpliedDo);
1246 std::tuple<std::list<AcValue>, AcImpliedDoControl> t;
1247 };
1248
1249 // R808 language-binding-spec ->
1250 // BIND ( C [, NAME = scalar-default-char-constant-expr] )
1251 // R1528 proc-language-binding-spec -> language-binding-spec
1252 WRAPPER_CLASS(
1253 LanguageBindingSpec, std::optional<ScalarDefaultCharConstantExpr>);
1254
1255 // R852 named-constant-def -> named-constant = constant-expr
1256 struct NamedConstantDef {
1257 TUPLE_CLASS_BOILERPLATE(NamedConstantDef);
1258 std::tuple<NamedConstant, ConstantExpr> t;
1259 };
1260
1261 // R851 parameter-stmt -> PARAMETER ( named-constant-def-list )
1262 WRAPPER_CLASS(ParameterStmt, std::list<NamedConstantDef>);
1263
1264 // R819 assumed-shape-spec -> [lower-bound] :
1265 WRAPPER_CLASS(AssumedShapeSpec, std::optional<SpecificationExpr>);
1266
1267 // R821 assumed-implied-spec -> [lower-bound :] *
1268 WRAPPER_CLASS(AssumedImpliedSpec, std::optional<SpecificationExpr>);
1269
1270 // R822 assumed-size-spec -> explicit-shape-spec-list , assumed-implied-spec
1271 struct AssumedSizeSpec {
1272 TUPLE_CLASS_BOILERPLATE(AssumedSizeSpec);
1273 std::tuple<std::list<ExplicitShapeSpec>, AssumedImpliedSpec> t;
1274 };
1275
1276 // R823 implied-shape-or-assumed-size-spec -> assumed-implied-spec
1277 // R824 implied-shape-spec -> assumed-implied-spec , assumed-implied-spec-list
1278 // I.e., when the assumed-implied-spec-list has a single item, it constitutes an
1279 // implied-shape-or-assumed-size-spec; otherwise, an implied-shape-spec.
1280 WRAPPER_CLASS(ImpliedShapeSpec, std::list<AssumedImpliedSpec>);
1281
1282 // R825 assumed-rank-spec -> ..
1283 EMPTY_CLASS(AssumedRankSpec);
1284
1285 // R815 array-spec ->
1286 // explicit-shape-spec-list | assumed-shape-spec-list |
1287 // deferred-shape-spec-list | assumed-size-spec | implied-shape-spec |
1288 // implied-shape-or-assumed-size-spec | assumed-rank-spec
1289 struct ArraySpec {
1290 UNION_CLASS_BOILERPLATE(ArraySpec);
1291 std::variant<std::list<ExplicitShapeSpec>, std::list<AssumedShapeSpec>,
1292 DeferredShapeSpecList, AssumedSizeSpec, ImpliedShapeSpec, AssumedRankSpec>
1293 u;
1294 };
1295
1296 // R826 intent-spec -> IN | OUT | INOUT
1297 struct IntentSpec {
1298 ENUM_CLASS(Intent, In, Out, InOut)
1299 WRAPPER_CLASS_BOILERPLATE(IntentSpec, Intent);
1300 };
1301
1302 // R802 attr-spec ->
1303 // access-spec | ALLOCATABLE | ASYNCHRONOUS |
1304 // CODIMENSION lbracket coarray-spec rbracket | CONTIGUOUS |
1305 // DIMENSION ( array-spec ) | EXTERNAL | INTENT ( intent-spec ) |
1306 // INTRINSIC | language-binding-spec | OPTIONAL | PARAMETER | POINTER |
1307 // PROTECTED | SAVE | TARGET | VALUE | VOLATILE
1308 EMPTY_CLASS(Asynchronous);
1309 EMPTY_CLASS(External);
1310 EMPTY_CLASS(Intrinsic);
1311 EMPTY_CLASS(Optional);
1312 EMPTY_CLASS(Parameter);
1313 EMPTY_CLASS(Protected);
1314 EMPTY_CLASS(Save);
1315 EMPTY_CLASS(Target);
1316 EMPTY_CLASS(Value);
1317 EMPTY_CLASS(Volatile);
1318 struct AttrSpec {
1319 UNION_CLASS_BOILERPLATE(AttrSpec);
1320 std::variant<AccessSpec, Allocatable, Asynchronous, CoarraySpec, Contiguous,
1321 ArraySpec, External, IntentSpec, Intrinsic, LanguageBindingSpec, Optional,
1322 Parameter, Pointer, Protected, Save, Target, Value, Volatile>
1323 u;
1324 };
1325
1326 // R803 entity-decl ->
1327 // object-name [( array-spec )] [lbracket coarray-spec rbracket]
1328 // [* char-length] [initialization] |
1329 // function-name [* char-length]
1330 struct EntityDecl {
1331 TUPLE_CLASS_BOILERPLATE(EntityDecl);
1332 std::tuple<ObjectName, std::optional<ArraySpec>, std::optional<CoarraySpec>,
1333 std::optional<CharLength>, std::optional<Initialization>>
1334 t;
1335 };
1336
1337 // R801 type-declaration-stmt ->
1338 // declaration-type-spec [[, attr-spec]... ::] entity-decl-list
1339 struct TypeDeclarationStmt {
1340 TUPLE_CLASS_BOILERPLATE(TypeDeclarationStmt);
1341 std::tuple<DeclarationTypeSpec, std::list<AttrSpec>, std::list<EntityDecl>> t;
1342 };
1343
1344 // R828 access-id -> access-name | generic-spec
1345 struct AccessId {
1346 UNION_CLASS_BOILERPLATE(AccessId);
1347 std::variant<Name, common::Indirection<GenericSpec>> u;
1348 };
1349
1350 // R827 access-stmt -> access-spec [[::] access-id-list]
1351 struct AccessStmt {
1352 TUPLE_CLASS_BOILERPLATE(AccessStmt);
1353 std::tuple<AccessSpec, std::list<AccessId>> t;
1354 };
1355
1356 // R830 allocatable-decl ->
1357 // object-name [( array-spec )] [lbracket coarray-spec rbracket]
1358 // R860 target-decl ->
1359 // object-name [( array-spec )] [lbracket coarray-spec rbracket]
1360 struct ObjectDecl {
1361 TUPLE_CLASS_BOILERPLATE(ObjectDecl);
1362 std::tuple<ObjectName, std::optional<ArraySpec>, std::optional<CoarraySpec>>
1363 t;
1364 };
1365
1366 // R829 allocatable-stmt -> ALLOCATABLE [::] allocatable-decl-list
1367 WRAPPER_CLASS(AllocatableStmt, std::list<ObjectDecl>);
1368
1369 // R831 asynchronous-stmt -> ASYNCHRONOUS [::] object-name-list
1370 WRAPPER_CLASS(AsynchronousStmt, std::list<ObjectName>);
1371
1372 // R833 bind-entity -> entity-name | / common-block-name /
1373 struct BindEntity {
1374 TUPLE_CLASS_BOILERPLATE(BindEntity);
1375 ENUM_CLASS(Kind, Object, Common)
1376 std::tuple<Kind, Name> t;
1377 };
1378
1379 // R832 bind-stmt -> language-binding-spec [::] bind-entity-list
1380 struct BindStmt {
1381 TUPLE_CLASS_BOILERPLATE(BindStmt);
1382 std::tuple<LanguageBindingSpec, std::list<BindEntity>> t;
1383 };
1384
1385 // R835 codimension-decl -> coarray-name lbracket coarray-spec rbracket
1386 struct CodimensionDecl {
1387 TUPLE_CLASS_BOILERPLATE(CodimensionDecl);
1388 std::tuple<Name, CoarraySpec> t;
1389 };
1390
1391 // R834 codimension-stmt -> CODIMENSION [::] codimension-decl-list
1392 WRAPPER_CLASS(CodimensionStmt, std::list<CodimensionDecl>);
1393
1394 // R836 contiguous-stmt -> CONTIGUOUS [::] object-name-list
1395 WRAPPER_CLASS(ContiguousStmt, std::list<ObjectName>);
1396
1397 // R847 constant-subobject -> designator
1398 // R846 int-constant-subobject -> constant-subobject
1399 using ConstantSubobject = Constant<common::Indirection<Designator>>;
1400
1401 // Represents an analyzed expression
1402 using TypedExpr = common::ForwardOwningPointer<evaluate::GenericExprWrapper>;
1403
1404 // R845 data-stmt-constant ->
1405 // scalar-constant | scalar-constant-subobject |
1406 // signed-int-literal-constant | signed-real-literal-constant |
1407 // null-init | initial-data-target |
1408 // structure-constructor
1409 // N.B. Parsing ambiguities abound here without recourse to symbols
1410 // (see comments on R845's parser).
1411 struct DataStmtConstant {
1412 UNION_CLASS_BOILERPLATE(DataStmtConstant);
1413 CharBlock source;
1414 mutable TypedExpr typedExpr;
1415 std::variant<LiteralConstant, SignedIntLiteralConstant,
1416 SignedRealLiteralConstant, SignedComplexLiteralConstant, NullInit,
1417 common::Indirection<Designator>, StructureConstructor>
1418 u;
1419 };
1420
1421 // R844 data-stmt-repeat -> scalar-int-constant | scalar-int-constant-subobject
1422 // R607 int-constant -> constant
1423 // R604 constant -> literal-constant | named-constant
1424 // (only literal-constant -> int-literal-constant applies)
1425 struct DataStmtRepeat {
1426 UNION_CLASS_BOILERPLATE(DataStmtRepeat);
1427 std::variant<IntLiteralConstant, Scalar<Integer<ConstantSubobject>>> u;
1428 };
1429
1430 // R843 data-stmt-value -> [data-stmt-repeat *] data-stmt-constant
1431 struct DataStmtValue {
1432 TUPLE_CLASS_BOILERPLATE(DataStmtValue);
1433 mutable std::int64_t repetitions{1}; // replaced during semantics
1434 std::tuple<std::optional<DataStmtRepeat>, DataStmtConstant> t;
1435 };
1436
1437 // R841 data-i-do-object ->
1438 // array-element | scalar-structure-component | data-implied-do
1439 struct DataIDoObject {
1440 UNION_CLASS_BOILERPLATE(DataIDoObject);
1441 std::variant<Scalar<common::Indirection<Designator>>,
1442 common::Indirection<DataImpliedDo>>
1443 u;
1444 };
1445
1446 // R840 data-implied-do ->
1447 // ( data-i-do-object-list , [integer-type-spec ::] data-i-do-variable
1448 // = scalar-int-constant-expr , scalar-int-constant-expr
1449 // [, scalar-int-constant-expr] )
1450 // R842 data-i-do-variable -> do-variable
1451 struct DataImpliedDo {
1452 TUPLE_CLASS_BOILERPLATE(DataImpliedDo);
1453 using Bounds = LoopBounds<DoVariable, ScalarIntConstantExpr>;
1454 std::tuple<std::list<DataIDoObject>, std::optional<IntegerTypeSpec>, Bounds>
1455 t;
1456 };
1457
1458 // R839 data-stmt-object -> variable | data-implied-do
1459 struct DataStmtObject {
1460 UNION_CLASS_BOILERPLATE(DataStmtObject);
1461 std::variant<common::Indirection<Variable>, DataImpliedDo> u;
1462 };
1463
1464 // R838 data-stmt-set -> data-stmt-object-list / data-stmt-value-list /
1465 struct DataStmtSet {
1466 TUPLE_CLASS_BOILERPLATE(DataStmtSet);
1467 std::tuple<std::list<DataStmtObject>, std::list<DataStmtValue>> t;
1468 };
1469
1470 // R837 data-stmt -> DATA data-stmt-set [[,] data-stmt-set]...
1471 WRAPPER_CLASS(DataStmt, std::list<DataStmtSet>);
1472
1473 // R848 dimension-stmt ->
1474 // DIMENSION [::] array-name ( array-spec )
1475 // [, array-name ( array-spec )]...
1476 struct DimensionStmt {
1477 struct Declaration {
1478 TUPLE_CLASS_BOILERPLATE(Declaration);
1479 std::tuple<Name, ArraySpec> t;
1480 };
1481 WRAPPER_CLASS_BOILERPLATE(DimensionStmt, std::list<Declaration>);
1482 };
1483
1484 // R849 intent-stmt -> INTENT ( intent-spec ) [::] dummy-arg-name-list
1485 struct IntentStmt {
1486 TUPLE_CLASS_BOILERPLATE(IntentStmt);
1487 std::tuple<IntentSpec, std::list<Name>> t;
1488 };
1489
1490 // R850 optional-stmt -> OPTIONAL [::] dummy-arg-name-list
1491 WRAPPER_CLASS(OptionalStmt, std::list<Name>);
1492
1493 // R854 pointer-decl ->
1494 // object-name [( deferred-shape-spec-list )] | proc-entity-name
1495 struct PointerDecl {
1496 TUPLE_CLASS_BOILERPLATE(PointerDecl);
1497 std::tuple<Name, std::optional<DeferredShapeSpecList>> t;
1498 };
1499
1500 // R853 pointer-stmt -> POINTER [::] pointer-decl-list
1501 WRAPPER_CLASS(PointerStmt, std::list<PointerDecl>);
1502
1503 // R855 protected-stmt -> PROTECTED [::] entity-name-list
1504 WRAPPER_CLASS(ProtectedStmt, std::list<Name>);
1505
1506 // R857 saved-entity -> object-name | proc-pointer-name | / common-block-name /
1507 // R858 proc-pointer-name -> name
1508 struct SavedEntity {
1509 TUPLE_CLASS_BOILERPLATE(SavedEntity);
1510 ENUM_CLASS(Kind, Entity, Common)
1511 std::tuple<Kind, Name> t;
1512 };
1513
1514 // R856 save-stmt -> SAVE [[::] saved-entity-list]
1515 WRAPPER_CLASS(SaveStmt, std::list<SavedEntity>);
1516
1517 // R859 target-stmt -> TARGET [::] target-decl-list
1518 WRAPPER_CLASS(TargetStmt, std::list<ObjectDecl>);
1519
1520 // R861 value-stmt -> VALUE [::] dummy-arg-name-list
1521 WRAPPER_CLASS(ValueStmt, std::list<Name>);
1522
1523 // R862 volatile-stmt -> VOLATILE [::] object-name-list
1524 WRAPPER_CLASS(VolatileStmt, std::list<ObjectName>);
1525
1526 // R865 letter-spec -> letter [- letter]
1527 struct LetterSpec {
1528 TUPLE_CLASS_BOILERPLATE(LetterSpec);
1529 std::tuple<Location, std::optional<Location>> t;
1530 };
1531
1532 // R864 implicit-spec -> declaration-type-spec ( letter-spec-list )
1533 struct ImplicitSpec {
1534 TUPLE_CLASS_BOILERPLATE(ImplicitSpec);
1535 std::tuple<DeclarationTypeSpec, std::list<LetterSpec>> t;
1536 };
1537
1538 // R863 implicit-stmt ->
1539 // IMPLICIT implicit-spec-list |
1540 // IMPLICIT NONE [( [implicit-name-spec-list] )]
1541 // R866 implicit-name-spec -> EXTERNAL | TYPE
1542 struct ImplicitStmt {
1543 UNION_CLASS_BOILERPLATE(ImplicitStmt);
1544 ENUM_CLASS(ImplicitNoneNameSpec, External, Type) // R866
1545 std::variant<std::list<ImplicitSpec>, std::list<ImplicitNoneNameSpec>> u;
1546 };
1547
1548 // R874 common-block-object -> variable-name [( array-spec )]
1549 struct CommonBlockObject {
1550 TUPLE_CLASS_BOILERPLATE(CommonBlockObject);
1551 std::tuple<Name, std::optional<ArraySpec>> t;
1552 };
1553
1554 // R873 common-stmt ->
1555 // COMMON [/ [common-block-name] /] common-block-object-list
1556 // [[,] / [common-block-name] / common-block-object-list]...
1557 struct CommonStmt {
1558 struct Block {
1559 TUPLE_CLASS_BOILERPLATE(Block);
1560 std::tuple<std::optional<Name>, std::list<CommonBlockObject>> t;
1561 };
1562 BOILERPLATE(CommonStmt);
1563 CommonStmt(std::optional<Name> &&, std::list<CommonBlockObject> &&,
1564 std::list<Block> &&);
1565 std::list<Block> blocks;
1566 };
1567
1568 // R872 equivalence-object -> variable-name | array-element | substring
1569 WRAPPER_CLASS(EquivalenceObject, common::Indirection<Designator>);
1570
1571 // R870 equivalence-stmt -> EQUIVALENCE equivalence-set-list
1572 // R871 equivalence-set -> ( equivalence-object , equivalence-object-list )
1573 WRAPPER_CLASS(EquivalenceStmt, std::list<std::list<EquivalenceObject>>);
1574
1575 // R910 substring-range -> [scalar-int-expr] : [scalar-int-expr]
1576 struct SubstringRange {
1577 TUPLE_CLASS_BOILERPLATE(SubstringRange);
1578 std::tuple<std::optional<ScalarIntExpr>, std::optional<ScalarIntExpr>> t;
1579 };
1580
1581 // R919 subscript -> scalar-int-expr
1582 using Subscript = ScalarIntExpr;
1583
1584 // R921 subscript-triplet -> [subscript] : [subscript] [: stride]
1585 struct SubscriptTriplet {
1586 TUPLE_CLASS_BOILERPLATE(SubscriptTriplet);
1587 std::tuple<std::optional<Subscript>, std::optional<Subscript>,
1588 std::optional<Subscript>>
1589 t;
1590 };
1591
1592 // R920 section-subscript -> subscript | subscript-triplet | vector-subscript
1593 // R923 vector-subscript -> int-expr
1594 struct SectionSubscript {
1595 UNION_CLASS_BOILERPLATE(SectionSubscript);
1596 std::variant<IntExpr, SubscriptTriplet> u;
1597 };
1598
1599 // R925 cosubscript -> scalar-int-expr
1600 using Cosubscript = ScalarIntExpr;
1601
1602 // R1115 team-value -> scalar-expr
1603 WRAPPER_CLASS(TeamValue, Scalar<common::Indirection<Expr>>);
1604
1605 // R926 image-selector-spec ->
1606 // STAT = stat-variable | TEAM = team-value |
1607 // TEAM_NUMBER = scalar-int-expr
1608 struct ImageSelectorSpec {
1609 WRAPPER_CLASS(Stat, Scalar<Integer<common::Indirection<Variable>>>);
1610 WRAPPER_CLASS(Team_Number, ScalarIntExpr);
1611 UNION_CLASS_BOILERPLATE(ImageSelectorSpec);
1612 std::variant<Stat, TeamValue, Team_Number> u;
1613 };
1614
1615 // R924 image-selector ->
1616 // lbracket cosubscript-list [, image-selector-spec-list] rbracket
1617 struct ImageSelector {
1618 TUPLE_CLASS_BOILERPLATE(ImageSelector);
1619 std::tuple<std::list<Cosubscript>, std::list<ImageSelectorSpec>> t;
1620 };
1621
1622 // R1001 - R1022 expressions
1623 struct Expr {
1624 UNION_CLASS_BOILERPLATE(Expr);
1625
1626 WRAPPER_CLASS(IntrinsicUnary, common::Indirection<Expr>);
1627 struct Parentheses : public IntrinsicUnary {
1628 using IntrinsicUnary::IntrinsicUnary;
1629 };
1630 struct UnaryPlus : public IntrinsicUnary {
1631 using IntrinsicUnary::IntrinsicUnary;
1632 };
1633 struct Negate : public IntrinsicUnary {
1634 using IntrinsicUnary::IntrinsicUnary;
1635 };
1636 struct NOT : public IntrinsicUnary {
1637 using IntrinsicUnary::IntrinsicUnary;
1638 };
1639
1640 WRAPPER_CLASS(PercentLoc, common::Indirection<Variable>); // %LOC(v) extension
1641
1642 struct DefinedUnary {
1643 TUPLE_CLASS_BOILERPLATE(DefinedUnary);
1644 std::tuple<DefinedOpName, common::Indirection<Expr>> t;
1645 };
1646
1647 struct IntrinsicBinary {
1648 TUPLE_CLASS_BOILERPLATE(IntrinsicBinary);
1649 std::tuple<common::Indirection<Expr>, common::Indirection<Expr>> t;
1650 };
1651 struct Power : public IntrinsicBinary {
1652 using IntrinsicBinary::IntrinsicBinary;
1653 };
1654 struct Multiply : public IntrinsicBinary {
1655 using IntrinsicBinary::IntrinsicBinary;
1656 };
1657 struct Divide : public IntrinsicBinary {
1658 using IntrinsicBinary::IntrinsicBinary;
1659 };
1660 struct Add : public IntrinsicBinary {
1661 using IntrinsicBinary::IntrinsicBinary;
1662 };
1663 struct Subtract : public IntrinsicBinary {
1664 using IntrinsicBinary::IntrinsicBinary;
1665 };
1666 struct Concat : public IntrinsicBinary {
1667 using IntrinsicBinary::IntrinsicBinary;
1668 };
1669 struct LT : public IntrinsicBinary {
1670 using IntrinsicBinary::IntrinsicBinary;
1671 };
1672 struct LE : public IntrinsicBinary {
1673 using IntrinsicBinary::IntrinsicBinary;
1674 };
1675 struct EQ : public IntrinsicBinary {
1676 using IntrinsicBinary::IntrinsicBinary;
1677 };
1678 struct NE : public IntrinsicBinary {
1679 using IntrinsicBinary::IntrinsicBinary;
1680 };
1681 struct GE : public IntrinsicBinary {
1682 using IntrinsicBinary::IntrinsicBinary;
1683 };
1684 struct GT : public IntrinsicBinary {
1685 using IntrinsicBinary::IntrinsicBinary;
1686 };
1687 struct AND : public IntrinsicBinary {
1688 using IntrinsicBinary::IntrinsicBinary;
1689 };
1690 struct OR : public IntrinsicBinary {
1691 using IntrinsicBinary::IntrinsicBinary;
1692 };
1693 struct EQV : public IntrinsicBinary {
1694 using IntrinsicBinary::IntrinsicBinary;
1695 };
1696 struct NEQV : public IntrinsicBinary {
1697 using IntrinsicBinary::IntrinsicBinary;
1698 };
1699
1700 // PGI/XLF extension: (x,y), not both constant
1701 struct ComplexConstructor : public IntrinsicBinary {
1702 using IntrinsicBinary::IntrinsicBinary;
1703 };
1704
1705 struct DefinedBinary {
1706 TUPLE_CLASS_BOILERPLATE(DefinedBinary);
1707 std::tuple<DefinedOpName, common::Indirection<Expr>,
1708 common::Indirection<Expr>>
1709 t;
1710 };
1711
1712 explicit Expr(Designator &&);
1713 explicit Expr(FunctionReference &&);
1714
1715 mutable TypedExpr typedExpr;
1716
1717 CharBlock source;
1718
1719 std::variant<common::Indirection<CharLiteralConstantSubstring>,
1720 LiteralConstant, common::Indirection<Designator>, ArrayConstructor,
1721 StructureConstructor, common::Indirection<FunctionReference>, Parentheses,
1722 UnaryPlus, Negate, NOT, PercentLoc, DefinedUnary, Power, Multiply, Divide,
1723 Add, Subtract, Concat, LT, LE, EQ, NE, GE, GT, AND, OR, EQV, NEQV,
1724 DefinedBinary, ComplexConstructor>
1725 u;
1726 };
1727
1728 // R912 part-ref -> part-name [( section-subscript-list )] [image-selector]
1729 struct PartRef {
1730 BOILERPLATE(PartRef);
PartRefPartRef1731 PartRef(Name &&n, std::list<SectionSubscript> &&ss,
1732 std::optional<ImageSelector> &&is)
1733 : name{std::move(n)},
1734 subscripts(std::move(ss)), imageSelector{std::move(is)} {}
1735 Name name;
1736 std::list<SectionSubscript> subscripts;
1737 std::optional<ImageSelector> imageSelector;
1738 };
1739
1740 // R911 data-ref -> part-ref [% part-ref]...
1741 struct DataRef {
1742 UNION_CLASS_BOILERPLATE(DataRef);
1743 explicit DataRef(std::list<PartRef> &&);
1744 std::variant<Name, common::Indirection<StructureComponent>,
1745 common::Indirection<ArrayElement>,
1746 common::Indirection<CoindexedNamedObject>>
1747 u;
1748 };
1749
1750 // R908 substring -> parent-string ( substring-range )
1751 // R909 parent-string ->
1752 // scalar-variable-name | array-element | coindexed-named-object |
1753 // scalar-structure-component | scalar-char-literal-constant |
1754 // scalar-named-constant
1755 // Substrings of character literals have been factored out into their
1756 // own productions so that they can't appear as designators in any context
1757 // other than a primary expression.
1758 struct Substring {
1759 TUPLE_CLASS_BOILERPLATE(Substring);
1760 std::tuple<DataRef, SubstringRange> t;
1761 };
1762
1763 struct CharLiteralConstantSubstring {
1764 TUPLE_CLASS_BOILERPLATE(CharLiteralConstantSubstring);
1765 std::tuple<CharLiteralConstant, SubstringRange> t;
1766 };
1767
1768 // R901 designator -> object-name | array-element | array-section |
1769 // coindexed-named-object | complex-part-designator |
1770 // structure-component | substring
1771 struct Designator {
1772 UNION_CLASS_BOILERPLATE(Designator);
1773 bool EndsInBareName() const;
1774 CharBlock source;
1775 std::variant<DataRef, Substring> u;
1776 };
1777
1778 // R902 variable -> designator | function-reference
1779 struct Variable {
1780 UNION_CLASS_BOILERPLATE(Variable);
1781 mutable TypedExpr typedExpr;
1782 parser::CharBlock GetSource() const;
1783 std::variant<common::Indirection<Designator>,
1784 common::Indirection<FunctionReference>>
1785 u;
1786 };
1787
1788 // R904 logical-variable -> variable
1789 // Appears only as part of scalar-logical-variable.
1790 using ScalarLogicalVariable = Scalar<Logical<Variable>>;
1791
1792 // R906 default-char-variable -> variable
1793 // Appears only as part of scalar-default-char-variable.
1794 using ScalarDefaultCharVariable = Scalar<DefaultChar<Variable>>;
1795
1796 // R907 int-variable -> variable
1797 // Appears only as part of scalar-int-variable.
1798 using ScalarIntVariable = Scalar<Integer<Variable>>;
1799
1800 // R913 structure-component -> data-ref
1801 struct StructureComponent {
1802 BOILERPLATE(StructureComponent);
StructureComponentStructureComponent1803 StructureComponent(DataRef &&dr, Name &&n)
1804 : base{std::move(dr)}, component(std::move(n)) {}
1805 DataRef base;
1806 Name component;
1807 };
1808
1809 // R1039 proc-component-ref -> scalar-variable % procedure-component-name
1810 // C1027 constrains the scalar-variable to be a data-ref without coindices.
1811 struct ProcComponentRef {
1812 WRAPPER_CLASS_BOILERPLATE(ProcComponentRef, Scalar<StructureComponent>);
1813 };
1814
1815 // R914 coindexed-named-object -> data-ref
1816 struct CoindexedNamedObject {
1817 BOILERPLATE(CoindexedNamedObject);
CoindexedNamedObjectCoindexedNamedObject1818 CoindexedNamedObject(DataRef &&dr, ImageSelector &&is)
1819 : base{std::move(dr)}, imageSelector{std::move(is)} {}
1820 DataRef base;
1821 ImageSelector imageSelector;
1822 };
1823
1824 // R917 array-element -> data-ref
1825 struct ArrayElement {
1826 BOILERPLATE(ArrayElement);
ArrayElementArrayElement1827 ArrayElement(DataRef &&dr, std::list<SectionSubscript> &&ss)
1828 : base{std::move(dr)}, subscripts(std::move(ss)) {}
1829 Substring ConvertToSubstring();
1830 StructureConstructor ConvertToStructureConstructor(
1831 const semantics::DerivedTypeSpec &);
1832 DataRef base;
1833 std::list<SectionSubscript> subscripts;
1834 };
1835
1836 // R933 allocate-object -> variable-name | structure-component
1837 struct AllocateObject {
1838 UNION_CLASS_BOILERPLATE(AllocateObject);
1839 std::variant<Name, StructureComponent> u;
1840 };
1841
1842 // R935 lower-bound-expr -> scalar-int-expr
1843 // R936 upper-bound-expr -> scalar-int-expr
1844 using BoundExpr = ScalarIntExpr;
1845
1846 // R934 allocate-shape-spec -> [lower-bound-expr :] upper-bound-expr
1847 // R938 allocate-coshape-spec -> [lower-bound-expr :] upper-bound-expr
1848 struct AllocateShapeSpec {
1849 TUPLE_CLASS_BOILERPLATE(AllocateShapeSpec);
1850 std::tuple<std::optional<BoundExpr>, BoundExpr> t;
1851 };
1852
1853 using AllocateCoshapeSpec = AllocateShapeSpec;
1854
1855 // R937 allocate-coarray-spec ->
1856 // [allocate-coshape-spec-list ,] [lower-bound-expr :] *
1857 struct AllocateCoarraySpec {
1858 TUPLE_CLASS_BOILERPLATE(AllocateCoarraySpec);
1859 std::tuple<std::list<AllocateCoshapeSpec>, std::optional<BoundExpr>> t;
1860 };
1861
1862 // R932 allocation ->
1863 // allocate-object [( allocate-shape-spec-list )]
1864 // [lbracket allocate-coarray-spec rbracket]
1865 struct Allocation {
1866 TUPLE_CLASS_BOILERPLATE(Allocation);
1867 std::tuple<AllocateObject, std::list<AllocateShapeSpec>,
1868 std::optional<AllocateCoarraySpec>>
1869 t;
1870 };
1871
1872 // R929 stat-variable -> scalar-int-variable
1873 WRAPPER_CLASS(StatVariable, ScalarIntVariable);
1874
1875 // R930 errmsg-variable -> scalar-default-char-variable
1876 // R1207 iomsg-variable -> scalar-default-char-variable
1877 WRAPPER_CLASS(MsgVariable, ScalarDefaultCharVariable);
1878
1879 // R942 dealloc-opt -> STAT = stat-variable | ERRMSG = errmsg-variable
1880 // R1165 sync-stat -> STAT = stat-variable | ERRMSG = errmsg-variable
1881 struct StatOrErrmsg {
1882 UNION_CLASS_BOILERPLATE(StatOrErrmsg);
1883 std::variant<StatVariable, MsgVariable> u;
1884 };
1885
1886 // R928 alloc-opt ->
1887 // ERRMSG = errmsg-variable | MOLD = source-expr |
1888 // SOURCE = source-expr | STAT = stat-variable
1889 // R931 source-expr -> expr
1890 struct AllocOpt {
1891 UNION_CLASS_BOILERPLATE(AllocOpt);
1892 WRAPPER_CLASS(Mold, common::Indirection<Expr>);
1893 WRAPPER_CLASS(Source, common::Indirection<Expr>);
1894 std::variant<Mold, Source, StatOrErrmsg> u;
1895 };
1896
1897 // R927 allocate-stmt ->
1898 // ALLOCATE ( [type-spec ::] allocation-list [, alloc-opt-list] )
1899 struct AllocateStmt {
1900 TUPLE_CLASS_BOILERPLATE(AllocateStmt);
1901 std::tuple<std::optional<TypeSpec>, std::list<Allocation>,
1902 std::list<AllocOpt>>
1903 t;
1904 };
1905
1906 // R940 pointer-object ->
1907 // variable-name | structure-component | proc-pointer-name
1908 struct PointerObject {
1909 UNION_CLASS_BOILERPLATE(PointerObject);
1910 std::variant<Name, StructureComponent> u;
1911 };
1912
1913 // R939 nullify-stmt -> NULLIFY ( pointer-object-list )
1914 WRAPPER_CLASS(NullifyStmt, std::list<PointerObject>);
1915
1916 // R941 deallocate-stmt ->
1917 // DEALLOCATE ( allocate-object-list [, dealloc-opt-list] )
1918 struct DeallocateStmt {
1919 TUPLE_CLASS_BOILERPLATE(DeallocateStmt);
1920 std::tuple<std::list<AllocateObject>, std::list<StatOrErrmsg>> t;
1921 };
1922
1923 // R1032 assignment-stmt -> variable = expr
1924 struct AssignmentStmt {
1925 TUPLE_CLASS_BOILERPLATE(AssignmentStmt);
1926 using TypedAssignment =
1927 common::ForwardOwningPointer<evaluate::GenericAssignmentWrapper>;
1928 mutable TypedAssignment typedAssignment;
1929 std::tuple<Variable, Expr> t;
1930 };
1931
1932 // R1035 bounds-spec -> lower-bound-expr :
1933 WRAPPER_CLASS(BoundsSpec, BoundExpr);
1934
1935 // R1036 bounds-remapping -> lower-bound-expr : upper-bound-expr
1936 struct BoundsRemapping {
1937 TUPLE_CLASS_BOILERPLATE(BoundsRemapping);
1938 std::tuple<BoundExpr, BoundExpr> t;
1939 };
1940
1941 // R1033 pointer-assignment-stmt ->
1942 // data-pointer-object [( bounds-spec-list )] => data-target |
1943 // data-pointer-object ( bounds-remapping-list ) => data-target |
1944 // proc-pointer-object => proc-target
1945 // R1034 data-pointer-object ->
1946 // variable-name | scalar-variable % data-pointer-component-name
1947 // R1038 proc-pointer-object -> proc-pointer-name | proc-component-ref
1948 struct PointerAssignmentStmt {
1949 struct Bounds {
1950 UNION_CLASS_BOILERPLATE(Bounds);
1951 std::variant<std::list<BoundsRemapping>, std::list<BoundsSpec>> u;
1952 };
1953 TUPLE_CLASS_BOILERPLATE(PointerAssignmentStmt);
1954 mutable AssignmentStmt::TypedAssignment typedAssignment;
1955 std::tuple<DataRef, Bounds, Expr> t;
1956 };
1957
1958 // R1041 where-stmt -> WHERE ( mask-expr ) where-assignment-stmt
1959 // R1045 where-assignment-stmt -> assignment-stmt
1960 // R1046 mask-expr -> logical-expr
1961 struct WhereStmt {
1962 TUPLE_CLASS_BOILERPLATE(WhereStmt);
1963 std::tuple<LogicalExpr, AssignmentStmt> t;
1964 };
1965
1966 // R1043 where-construct-stmt -> [where-construct-name :] WHERE ( mask-expr )
1967 struct WhereConstructStmt {
1968 TUPLE_CLASS_BOILERPLATE(WhereConstructStmt);
1969 std::tuple<std::optional<Name>, LogicalExpr> t;
1970 };
1971
1972 // R1044 where-body-construct ->
1973 // where-assignment-stmt | where-stmt | where-construct
1974 struct WhereBodyConstruct {
1975 UNION_CLASS_BOILERPLATE(WhereBodyConstruct);
1976 std::variant<Statement<AssignmentStmt>, Statement<WhereStmt>,
1977 common::Indirection<WhereConstruct>>
1978 u;
1979 };
1980
1981 // R1047 masked-elsewhere-stmt ->
1982 // ELSEWHERE ( mask-expr ) [where-construct-name]
1983 struct MaskedElsewhereStmt {
1984 TUPLE_CLASS_BOILERPLATE(MaskedElsewhereStmt);
1985 std::tuple<LogicalExpr, std::optional<Name>> t;
1986 };
1987
1988 // R1048 elsewhere-stmt -> ELSEWHERE [where-construct-name]
1989 WRAPPER_CLASS(ElsewhereStmt, std::optional<Name>);
1990
1991 // R1049 end-where-stmt -> END WHERE [where-construct-name]
1992 WRAPPER_CLASS(EndWhereStmt, std::optional<Name>);
1993
1994 // R1042 where-construct ->
1995 // where-construct-stmt [where-body-construct]...
1996 // [masked-elsewhere-stmt [where-body-construct]...]...
1997 // [elsewhere-stmt [where-body-construct]...] end-where-stmt
1998 struct WhereConstruct {
1999 struct MaskedElsewhere {
2000 TUPLE_CLASS_BOILERPLATE(MaskedElsewhere);
2001 std::tuple<Statement<MaskedElsewhereStmt>, std::list<WhereBodyConstruct>> t;
2002 };
2003 struct Elsewhere {
2004 TUPLE_CLASS_BOILERPLATE(Elsewhere);
2005 std::tuple<Statement<ElsewhereStmt>, std::list<WhereBodyConstruct>> t;
2006 };
2007 TUPLE_CLASS_BOILERPLATE(WhereConstruct);
2008 std::tuple<Statement<WhereConstructStmt>, std::list<WhereBodyConstruct>,
2009 std::list<MaskedElsewhere>, std::optional<Elsewhere>,
2010 Statement<EndWhereStmt>>
2011 t;
2012 };
2013
2014 // R1051 forall-construct-stmt ->
2015 // [forall-construct-name :] FORALL concurrent-header
2016 struct ForallConstructStmt {
2017 TUPLE_CLASS_BOILERPLATE(ForallConstructStmt);
2018 std::tuple<std::optional<Name>, common::Indirection<ConcurrentHeader>> t;
2019 };
2020
2021 // R1053 forall-assignment-stmt -> assignment-stmt | pointer-assignment-stmt
2022 struct ForallAssignmentStmt {
2023 UNION_CLASS_BOILERPLATE(ForallAssignmentStmt);
2024 std::variant<AssignmentStmt, PointerAssignmentStmt> u;
2025 };
2026
2027 // R1055 forall-stmt -> FORALL concurrent-header forall-assignment-stmt
2028 struct ForallStmt {
2029 TUPLE_CLASS_BOILERPLATE(ForallStmt);
2030 std::tuple<common::Indirection<ConcurrentHeader>,
2031 UnlabeledStatement<ForallAssignmentStmt>>
2032 t;
2033 };
2034
2035 // R1052 forall-body-construct ->
2036 // forall-assignment-stmt | where-stmt | where-construct |
2037 // forall-construct | forall-stmt
2038 struct ForallBodyConstruct {
2039 UNION_CLASS_BOILERPLATE(ForallBodyConstruct);
2040 std::variant<Statement<ForallAssignmentStmt>, Statement<WhereStmt>,
2041 WhereConstruct, common::Indirection<ForallConstruct>,
2042 Statement<ForallStmt>>
2043 u;
2044 };
2045
2046 // R1054 end-forall-stmt -> END FORALL [forall-construct-name]
2047 WRAPPER_CLASS(EndForallStmt, std::optional<Name>);
2048
2049 // R1050 forall-construct ->
2050 // forall-construct-stmt [forall-body-construct]... end-forall-stmt
2051 struct ForallConstruct {
2052 TUPLE_CLASS_BOILERPLATE(ForallConstruct);
2053 std::tuple<Statement<ForallConstructStmt>, std::list<ForallBodyConstruct>,
2054 Statement<EndForallStmt>>
2055 t;
2056 };
2057
2058 // R1101 block -> [execution-part-construct]...
2059 using Block = std::list<ExecutionPartConstruct>;
2060
2061 // R1105 selector -> expr | variable
2062 struct Selector {
2063 UNION_CLASS_BOILERPLATE(Selector);
2064 std::variant<Expr, Variable> u;
2065 };
2066
2067 // R1104 association -> associate-name => selector
2068 struct Association {
2069 TUPLE_CLASS_BOILERPLATE(Association);
2070 std::tuple<Name, Selector> t;
2071 };
2072
2073 // R1103 associate-stmt ->
2074 // [associate-construct-name :] ASSOCIATE ( association-list )
2075 struct AssociateStmt {
2076 TUPLE_CLASS_BOILERPLATE(AssociateStmt);
2077 std::tuple<std::optional<Name>, std::list<Association>> t;
2078 };
2079
2080 // R1106 end-associate-stmt -> END ASSOCIATE [associate-construct-name]
2081 WRAPPER_CLASS(EndAssociateStmt, std::optional<Name>);
2082
2083 // R1102 associate-construct -> associate-stmt block end-associate-stmt
2084 struct AssociateConstruct {
2085 TUPLE_CLASS_BOILERPLATE(AssociateConstruct);
2086 std::tuple<Statement<AssociateStmt>, Block, Statement<EndAssociateStmt>> t;
2087 };
2088
2089 // R1108 block-stmt -> [block-construct-name :] BLOCK
2090 WRAPPER_CLASS(BlockStmt, std::optional<Name>);
2091
2092 // R1110 end-block-stmt -> END BLOCK [block-construct-name]
2093 WRAPPER_CLASS(EndBlockStmt, std::optional<Name>);
2094
2095 // R1109 block-specification-part ->
2096 // [use-stmt]... [import-stmt]...
2097 // [[declaration-construct]... specification-construct]
2098 // N.B. Because BlockSpecificationPart just wraps the more general
2099 // SpecificationPart, it can misrecognize an ImplicitPart as part of
2100 // the BlockSpecificationPart during parsing, and we have to detect and
2101 // flag such usage in semantics.
2102 WRAPPER_CLASS(BlockSpecificationPart, SpecificationPart);
2103
2104 // R1107 block-construct ->
2105 // block-stmt [block-specification-part] block end-block-stmt
2106 struct BlockConstruct {
2107 TUPLE_CLASS_BOILERPLATE(BlockConstruct);
2108 std::tuple<Statement<BlockStmt>, BlockSpecificationPart, Block,
2109 Statement<EndBlockStmt>>
2110 t;
2111 };
2112
2113 // R1113 coarray-association -> codimension-decl => selector
2114 struct CoarrayAssociation {
2115 TUPLE_CLASS_BOILERPLATE(CoarrayAssociation);
2116 std::tuple<CodimensionDecl, Selector> t;
2117 };
2118
2119 // R1112 change-team-stmt ->
2120 // [team-construct-name :] CHANGE TEAM
2121 // ( team-value [, coarray-association-list] [, sync-stat-list] )
2122 struct ChangeTeamStmt {
2123 TUPLE_CLASS_BOILERPLATE(ChangeTeamStmt);
2124 std::tuple<std::optional<Name>, TeamValue, std::list<CoarrayAssociation>,
2125 std::list<StatOrErrmsg>>
2126 t;
2127 };
2128
2129 // R1114 end-change-team-stmt ->
2130 // END TEAM [( [sync-stat-list] )] [team-construct-name]
2131 struct EndChangeTeamStmt {
2132 TUPLE_CLASS_BOILERPLATE(EndChangeTeamStmt);
2133 std::tuple<std::list<StatOrErrmsg>, std::optional<Name>> t;
2134 };
2135
2136 // R1111 change-team-construct -> change-team-stmt block end-change-team-stmt
2137 struct ChangeTeamConstruct {
2138 TUPLE_CLASS_BOILERPLATE(ChangeTeamConstruct);
2139 std::tuple<Statement<ChangeTeamStmt>, Block, Statement<EndChangeTeamStmt>> t;
2140 };
2141
2142 // R1117 critical-stmt ->
2143 // [critical-construct-name :] CRITICAL [( [sync-stat-list] )]
2144 struct CriticalStmt {
2145 TUPLE_CLASS_BOILERPLATE(CriticalStmt);
2146 std::tuple<std::optional<Name>, std::list<StatOrErrmsg>> t;
2147 };
2148
2149 // R1118 end-critical-stmt -> END CRITICAL [critical-construct-name]
2150 WRAPPER_CLASS(EndCriticalStmt, std::optional<Name>);
2151
2152 // R1116 critical-construct -> critical-stmt block end-critical-stmt
2153 struct CriticalConstruct {
2154 TUPLE_CLASS_BOILERPLATE(CriticalConstruct);
2155 std::tuple<Statement<CriticalStmt>, Block, Statement<EndCriticalStmt>> t;
2156 };
2157
2158 // R1126 concurrent-control ->
2159 // index-name = concurrent-limit : concurrent-limit [: concurrent-step]
2160 // R1127 concurrent-limit -> scalar-int-expr
2161 // R1128 concurrent-step -> scalar-int-expr
2162 struct ConcurrentControl {
2163 TUPLE_CLASS_BOILERPLATE(ConcurrentControl);
2164 std::tuple<Name, ScalarIntExpr, ScalarIntExpr, std::optional<ScalarIntExpr>>
2165 t;
2166 };
2167
2168 // R1125 concurrent-header ->
2169 // ( [integer-type-spec ::] concurrent-control-list
2170 // [, scalar-mask-expr] )
2171 struct ConcurrentHeader {
2172 TUPLE_CLASS_BOILERPLATE(ConcurrentHeader);
2173 std::tuple<std::optional<IntegerTypeSpec>, std::list<ConcurrentControl>,
2174 std::optional<ScalarLogicalExpr>>
2175 t;
2176 };
2177
2178 // R1130 locality-spec ->
2179 // LOCAL ( variable-name-list ) | LOCAL_INIT ( variable-name-list ) |
2180 // SHARED ( variable-name-list ) | DEFAULT ( NONE )
2181 struct LocalitySpec {
2182 UNION_CLASS_BOILERPLATE(LocalitySpec);
2183 WRAPPER_CLASS(Local, std::list<Name>);
2184 WRAPPER_CLASS(LocalInit, std::list<Name>);
2185 WRAPPER_CLASS(Shared, std::list<Name>);
2186 EMPTY_CLASS(DefaultNone);
2187 std::variant<Local, LocalInit, Shared, DefaultNone> u;
2188 };
2189
2190 // R1123 loop-control ->
2191 // [,] do-variable = scalar-int-expr , scalar-int-expr
2192 // [, scalar-int-expr] |
2193 // [,] WHILE ( scalar-logical-expr ) |
2194 // [,] CONCURRENT concurrent-header concurrent-locality
2195 // R1129 concurrent-locality -> [locality-spec]...
2196 struct LoopControl {
2197 UNION_CLASS_BOILERPLATE(LoopControl);
2198 struct Concurrent {
2199 TUPLE_CLASS_BOILERPLATE(Concurrent);
2200 std::tuple<ConcurrentHeader, std::list<LocalitySpec>> t;
2201 };
2202 using Bounds = LoopBounds<ScalarName, ScalarExpr>;
2203 std::variant<Bounds, ScalarLogicalExpr, Concurrent> u;
2204 };
2205
2206 // R1121 label-do-stmt -> [do-construct-name :] DO label [loop-control]
2207 struct LabelDoStmt {
2208 TUPLE_CLASS_BOILERPLATE(LabelDoStmt);
2209 std::tuple<std::optional<Name>, Label, std::optional<LoopControl>> t;
2210 };
2211
2212 // R1122 nonlabel-do-stmt -> [do-construct-name :] DO [loop-control]
2213 struct NonLabelDoStmt {
2214 TUPLE_CLASS_BOILERPLATE(NonLabelDoStmt);
2215 std::tuple<std::optional<Name>, std::optional<LoopControl>> t;
2216 };
2217
2218 // R1132 end-do-stmt -> END DO [do-construct-name]
2219 WRAPPER_CLASS(EndDoStmt, std::optional<Name>);
2220
2221 // R1131 end-do -> end-do-stmt | continue-stmt
2222
2223 // R1119 do-construct -> do-stmt block end-do
2224 // R1120 do-stmt -> nonlabel-do-stmt | label-do-stmt
2225 // Deprecated, but supported: "label DO" loops ending on statements other
2226 // than END DO and CONTINUE, and multiple "label DO" loops ending on the
2227 // same label.
2228 struct DoConstruct {
2229 TUPLE_CLASS_BOILERPLATE(DoConstruct);
2230 const std::optional<LoopControl> &GetLoopControl() const;
2231 bool IsDoNormal() const;
2232 bool IsDoWhile() const;
2233 bool IsDoConcurrent() const;
2234 std::tuple<Statement<NonLabelDoStmt>, Block, Statement<EndDoStmt>> t;
2235 };
2236
2237 // R1133 cycle-stmt -> CYCLE [do-construct-name]
2238 WRAPPER_CLASS(CycleStmt, std::optional<Name>);
2239
2240 // R1135 if-then-stmt -> [if-construct-name :] IF ( scalar-logical-expr ) THEN
2241 struct IfThenStmt {
2242 TUPLE_CLASS_BOILERPLATE(IfThenStmt);
2243 std::tuple<std::optional<Name>, ScalarLogicalExpr> t;
2244 };
2245
2246 // R1136 else-if-stmt ->
2247 // ELSE IF ( scalar-logical-expr ) THEN [if-construct-name]
2248 struct ElseIfStmt {
2249 TUPLE_CLASS_BOILERPLATE(ElseIfStmt);
2250 std::tuple<ScalarLogicalExpr, std::optional<Name>> t;
2251 };
2252
2253 // R1137 else-stmt -> ELSE [if-construct-name]
2254 WRAPPER_CLASS(ElseStmt, std::optional<Name>);
2255
2256 // R1138 end-if-stmt -> END IF [if-construct-name]
2257 WRAPPER_CLASS(EndIfStmt, std::optional<Name>);
2258
2259 // R1134 if-construct ->
2260 // if-then-stmt block [else-if-stmt block]...
2261 // [else-stmt block] end-if-stmt
2262 struct IfConstruct {
2263 struct ElseIfBlock {
2264 TUPLE_CLASS_BOILERPLATE(ElseIfBlock);
2265 std::tuple<Statement<ElseIfStmt>, Block> t;
2266 };
2267 struct ElseBlock {
2268 TUPLE_CLASS_BOILERPLATE(ElseBlock);
2269 std::tuple<Statement<ElseStmt>, Block> t;
2270 };
2271 TUPLE_CLASS_BOILERPLATE(IfConstruct);
2272 std::tuple<Statement<IfThenStmt>, Block, std::list<ElseIfBlock>,
2273 std::optional<ElseBlock>, Statement<EndIfStmt>>
2274 t;
2275 };
2276
2277 // R1139 if-stmt -> IF ( scalar-logical-expr ) action-stmt
2278 struct IfStmt {
2279 TUPLE_CLASS_BOILERPLATE(IfStmt);
2280 std::tuple<ScalarLogicalExpr, UnlabeledStatement<ActionStmt>> t;
2281 };
2282
2283 // R1141 select-case-stmt -> [case-construct-name :] SELECT CASE ( case-expr )
2284 // R1144 case-expr -> scalar-expr
2285 struct SelectCaseStmt {
2286 TUPLE_CLASS_BOILERPLATE(SelectCaseStmt);
2287 std::tuple<std::optional<Name>, Scalar<Expr>> t;
2288 };
2289
2290 // R1147 case-value -> scalar-constant-expr
2291 using CaseValue = Scalar<ConstantExpr>;
2292
2293 // R1146 case-value-range ->
2294 // case-value | case-value : | : case-value | case-value : case-value
2295 struct CaseValueRange {
2296 UNION_CLASS_BOILERPLATE(CaseValueRange);
2297 struct Range {
2298 BOILERPLATE(Range);
RangeCaseValueRange::Range2299 Range(std::optional<CaseValue> &&l, std::optional<CaseValue> &&u)
2300 : lower{std::move(l)}, upper{std::move(u)} {}
2301 std::optional<CaseValue> lower, upper; // not both missing
2302 };
2303 std::variant<CaseValue, Range> u;
2304 };
2305
2306 // R1145 case-selector -> ( case-value-range-list ) | DEFAULT
2307 EMPTY_CLASS(Default);
2308
2309 struct CaseSelector {
2310 UNION_CLASS_BOILERPLATE(CaseSelector);
2311 std::variant<std::list<CaseValueRange>, Default> u;
2312 };
2313
2314 // R1142 case-stmt -> CASE case-selector [case-construct-name]
2315 struct CaseStmt {
2316 TUPLE_CLASS_BOILERPLATE(CaseStmt);
2317 std::tuple<CaseSelector, std::optional<Name>> t;
2318 };
2319
2320 // R1143 end-select-stmt -> END SELECT [case-construct-name]
2321 // R1151 end-select-rank-stmt -> END SELECT [select-construct-name]
2322 // R1155 end-select-type-stmt -> END SELECT [select-construct-name]
2323 WRAPPER_CLASS(EndSelectStmt, std::optional<Name>);
2324
2325 // R1140 case-construct ->
2326 // select-case-stmt [case-stmt block]... end-select-stmt
2327 struct CaseConstruct {
2328 struct Case {
2329 TUPLE_CLASS_BOILERPLATE(Case);
2330 std::tuple<Statement<CaseStmt>, Block> t;
2331 };
2332 TUPLE_CLASS_BOILERPLATE(CaseConstruct);
2333 std::tuple<Statement<SelectCaseStmt>, std::list<Case>,
2334 Statement<EndSelectStmt>>
2335 t;
2336 };
2337
2338 // R1149 select-rank-stmt ->
2339 // [select-construct-name :] SELECT RANK
2340 // ( [associate-name =>] selector )
2341 struct SelectRankStmt {
2342 TUPLE_CLASS_BOILERPLATE(SelectRankStmt);
2343 std::tuple<std::optional<Name>, std::optional<Name>, Selector> t;
2344 };
2345
2346 // R1150 select-rank-case-stmt ->
2347 // RANK ( scalar-int-constant-expr ) [select-construct-name] |
2348 // RANK ( * ) [select-construct-name] |
2349 // RANK DEFAULT [select-construct-name]
2350 struct SelectRankCaseStmt {
2351 struct Rank {
2352 UNION_CLASS_BOILERPLATE(Rank);
2353 std::variant<ScalarIntConstantExpr, Star, Default> u;
2354 };
2355 TUPLE_CLASS_BOILERPLATE(SelectRankCaseStmt);
2356 std::tuple<Rank, std::optional<Name>> t;
2357 };
2358
2359 // R1148 select-rank-construct ->
2360 // select-rank-stmt [select-rank-case-stmt block]...
2361 // end-select-rank-stmt
2362 struct SelectRankConstruct {
2363 TUPLE_CLASS_BOILERPLATE(SelectRankConstruct);
2364 struct RankCase {
2365 TUPLE_CLASS_BOILERPLATE(RankCase);
2366 std::tuple<Statement<SelectRankCaseStmt>, Block> t;
2367 };
2368 std::tuple<Statement<SelectRankStmt>, std::list<RankCase>,
2369 Statement<EndSelectStmt>>
2370 t;
2371 };
2372
2373 // R1153 select-type-stmt ->
2374 // [select-construct-name :] SELECT TYPE
2375 // ( [associate-name =>] selector )
2376 struct SelectTypeStmt {
2377 TUPLE_CLASS_BOILERPLATE(SelectTypeStmt);
2378 std::tuple<std::optional<Name>, std::optional<Name>, Selector> t;
2379 };
2380
2381 // R1154 type-guard-stmt ->
2382 // TYPE IS ( type-spec ) [select-construct-name] |
2383 // CLASS IS ( derived-type-spec ) [select-construct-name] |
2384 // CLASS DEFAULT [select-construct-name]
2385 struct TypeGuardStmt {
2386 struct Guard {
2387 UNION_CLASS_BOILERPLATE(Guard);
2388 std::variant<TypeSpec, DerivedTypeSpec, Default> u;
2389 };
2390 TUPLE_CLASS_BOILERPLATE(TypeGuardStmt);
2391 std::tuple<Guard, std::optional<Name>> t;
2392 };
2393
2394 // R1152 select-type-construct ->
2395 // select-type-stmt [type-guard-stmt block]... end-select-type-stmt
2396 struct SelectTypeConstruct {
2397 TUPLE_CLASS_BOILERPLATE(SelectTypeConstruct);
2398 struct TypeCase {
2399 TUPLE_CLASS_BOILERPLATE(TypeCase);
2400 std::tuple<Statement<TypeGuardStmt>, Block> t;
2401 };
2402 std::tuple<Statement<SelectTypeStmt>, std::list<TypeCase>,
2403 Statement<EndSelectStmt>>
2404 t;
2405 };
2406
2407 // R1156 exit-stmt -> EXIT [construct-name]
2408 WRAPPER_CLASS(ExitStmt, std::optional<Name>);
2409
2410 // R1157 goto-stmt -> GO TO label
2411 WRAPPER_CLASS(GotoStmt, Label);
2412
2413 // R1158 computed-goto-stmt -> GO TO ( label-list ) [,] scalar-int-expr
2414 struct ComputedGotoStmt {
2415 TUPLE_CLASS_BOILERPLATE(ComputedGotoStmt);
2416 std::tuple<std::list<Label>, ScalarIntExpr> t;
2417 };
2418
2419 // R1162 stop-code -> scalar-default-char-expr | scalar-int-expr
2420 // We can't distinguish character expressions from integer
2421 // expressions during parsing, so we just parse an expr and
2422 // check its type later.
2423 WRAPPER_CLASS(StopCode, Scalar<Expr>);
2424
2425 // R1160 stop-stmt -> STOP [stop-code] [, QUIET = scalar-logical-expr]
2426 // R1161 error-stop-stmt ->
2427 // ERROR STOP [stop-code] [, QUIET = scalar-logical-expr]
2428 struct StopStmt {
2429 ENUM_CLASS(Kind, Stop, ErrorStop)
2430 TUPLE_CLASS_BOILERPLATE(StopStmt);
2431 std::tuple<Kind, std::optional<StopCode>, std::optional<ScalarLogicalExpr>> t;
2432 };
2433
2434 // R1164 sync-all-stmt -> SYNC ALL [( [sync-stat-list] )]
2435 WRAPPER_CLASS(SyncAllStmt, std::list<StatOrErrmsg>);
2436
2437 // R1166 sync-images-stmt -> SYNC IMAGES ( image-set [, sync-stat-list] )
2438 // R1167 image-set -> int-expr | *
2439 struct SyncImagesStmt {
2440 struct ImageSet {
2441 UNION_CLASS_BOILERPLATE(ImageSet);
2442 std::variant<IntExpr, Star> u;
2443 };
2444 TUPLE_CLASS_BOILERPLATE(SyncImagesStmt);
2445 std::tuple<ImageSet, std::list<StatOrErrmsg>> t;
2446 };
2447
2448 // R1168 sync-memory-stmt -> SYNC MEMORY [( [sync-stat-list] )]
2449 WRAPPER_CLASS(SyncMemoryStmt, std::list<StatOrErrmsg>);
2450
2451 // R1169 sync-team-stmt -> SYNC TEAM ( team-value [, sync-stat-list] )
2452 struct SyncTeamStmt {
2453 TUPLE_CLASS_BOILERPLATE(SyncTeamStmt);
2454 std::tuple<TeamValue, std::list<StatOrErrmsg>> t;
2455 };
2456
2457 // R1171 event-variable -> scalar-variable
2458 using EventVariable = Scalar<Variable>;
2459
2460 // R1170 event-post-stmt -> EVENT POST ( event-variable [, sync-stat-list] )
2461 struct EventPostStmt {
2462 TUPLE_CLASS_BOILERPLATE(EventPostStmt);
2463 std::tuple<EventVariable, std::list<StatOrErrmsg>> t;
2464 };
2465
2466 // R1172 event-wait-stmt ->
2467 // EVENT WAIT ( event-variable [, event-wait-spec-list] )
2468 // R1173 event-wait-spec -> until-spec | sync-stat
2469 // R1174 until-spec -> UNTIL_COUNT = scalar-int-expr
2470 struct EventWaitStmt {
2471 struct EventWaitSpec {
2472 UNION_CLASS_BOILERPLATE(EventWaitSpec);
2473 std::variant<ScalarIntExpr, StatOrErrmsg> u;
2474 };
2475 TUPLE_CLASS_BOILERPLATE(EventWaitStmt);
2476 std::tuple<EventVariable, std::list<EventWaitSpec>> t;
2477 };
2478
2479 // R1177 team-variable -> scalar-variable
2480 using TeamVariable = Scalar<Variable>;
2481
2482 // R1175 form-team-stmt ->
2483 // FORM TEAM ( team-number , team-variable [, form-team-spec-list] )
2484 // R1176 team-number -> scalar-int-expr
2485 // R1178 form-team-spec -> NEW_INDEX = scalar-int-expr | sync-stat
2486 struct FormTeamStmt {
2487 struct FormTeamSpec {
2488 UNION_CLASS_BOILERPLATE(FormTeamSpec);
2489 std::variant<ScalarIntExpr, StatOrErrmsg> u;
2490 };
2491 TUPLE_CLASS_BOILERPLATE(FormTeamStmt);
2492 std::tuple<ScalarIntExpr, TeamVariable, std::list<FormTeamSpec>> t;
2493 };
2494
2495 // R1182 lock-variable -> scalar-variable
2496 using LockVariable = Scalar<Variable>;
2497
2498 // R1179 lock-stmt -> LOCK ( lock-variable [, lock-stat-list] )
2499 // R1180 lock-stat -> ACQUIRED_LOCK = scalar-logical-variable | sync-stat
2500 struct LockStmt {
2501 struct LockStat {
2502 UNION_CLASS_BOILERPLATE(LockStat);
2503 std::variant<Scalar<Logical<Variable>>, StatOrErrmsg> u;
2504 };
2505 TUPLE_CLASS_BOILERPLATE(LockStmt);
2506 std::tuple<LockVariable, std::list<LockStat>> t;
2507 };
2508
2509 // R1181 unlock-stmt -> UNLOCK ( lock-variable [, sync-stat-list] )
2510 struct UnlockStmt {
2511 TUPLE_CLASS_BOILERPLATE(UnlockStmt);
2512 std::tuple<LockVariable, std::list<StatOrErrmsg>> t;
2513 };
2514
2515 // R1202 file-unit-number -> scalar-int-expr
2516 WRAPPER_CLASS(FileUnitNumber, ScalarIntExpr);
2517
2518 // R1201 io-unit -> file-unit-number | * | internal-file-variable
2519 // R1203 internal-file-variable -> char-variable
2520 // R905 char-variable -> variable
2521 // When Variable appears as an IoUnit, it must be character of a default,
2522 // ASCII, or Unicode kind; this constraint is not automatically checked.
2523 // The parse is ambiguous and is repaired if necessary once the types of
2524 // symbols are known.
2525 struct IoUnit {
2526 UNION_CLASS_BOILERPLATE(IoUnit);
2527 std::variant<Variable, FileUnitNumber, Star> u;
2528 };
2529
2530 // R1206 file-name-expr -> scalar-default-char-expr
2531 using FileNameExpr = ScalarDefaultCharExpr;
2532
2533 // R1205 connect-spec ->
2534 // [UNIT =] file-unit-number | ACCESS = scalar-default-char-expr |
2535 // ACTION = scalar-default-char-expr |
2536 // ASYNCHRONOUS = scalar-default-char-expr |
2537 // BLANK = scalar-default-char-expr |
2538 // DECIMAL = scalar-default-char-expr |
2539 // DELIM = scalar-default-char-expr |
2540 // ENCODING = scalar-default-char-expr | ERR = label |
2541 // FILE = file-name-expr | FORM = scalar-default-char-expr |
2542 // IOMSG = iomsg-variable | IOSTAT = scalar-int-variable |
2543 // NEWUNIT = scalar-int-variable | PAD = scalar-default-char-expr |
2544 // POSITION = scalar-default-char-expr | RECL = scalar-int-expr |
2545 // ROUND = scalar-default-char-expr | SIGN = scalar-default-char-expr |
2546 // STATUS = scalar-default-char-expr
2547 // @ | CARRIAGECONTROL = scalar-default-char-variable
2548 // | CONVERT = scalar-default-char-variable
2549 // | DISPOSE = scalar-default-char-variable
2550 WRAPPER_CLASS(StatusExpr, ScalarDefaultCharExpr);
2551 WRAPPER_CLASS(ErrLabel, Label);
2552
2553 struct ConnectSpec {
2554 UNION_CLASS_BOILERPLATE(ConnectSpec);
2555 struct CharExpr {
2556 ENUM_CLASS(Kind, Access, Action, Asynchronous, Blank, Decimal, Delim,
2557 Encoding, Form, Pad, Position, Round, Sign,
2558 /* extensions: */ Carriagecontrol, Convert, Dispose)
2559 TUPLE_CLASS_BOILERPLATE(CharExpr);
2560 std::tuple<Kind, ScalarDefaultCharExpr> t;
2561 };
2562 WRAPPER_CLASS(Recl, ScalarIntExpr);
2563 WRAPPER_CLASS(Newunit, ScalarIntVariable);
2564 std::variant<FileUnitNumber, FileNameExpr, CharExpr, MsgVariable,
2565 StatVariable, Recl, Newunit, ErrLabel, StatusExpr>
2566 u;
2567 };
2568
2569 // R1204 open-stmt -> OPEN ( connect-spec-list )
2570 WRAPPER_CLASS(OpenStmt, std::list<ConnectSpec>);
2571
2572 // R1208 close-stmt -> CLOSE ( close-spec-list )
2573 // R1209 close-spec ->
2574 // [UNIT =] file-unit-number | IOSTAT = scalar-int-variable |
2575 // IOMSG = iomsg-variable | ERR = label |
2576 // STATUS = scalar-default-char-expr
2577 struct CloseStmt {
2578 struct CloseSpec {
2579 UNION_CLASS_BOILERPLATE(CloseSpec);
2580 std::variant<FileUnitNumber, StatVariable, MsgVariable, ErrLabel,
2581 StatusExpr>
2582 u;
2583 };
2584 WRAPPER_CLASS_BOILERPLATE(CloseStmt, std::list<CloseSpec>);
2585 };
2586
2587 // R1215 format -> default-char-expr | label | *
2588 // deprecated(ASSIGN): | scalar-int-name
2589 struct Format {
2590 UNION_CLASS_BOILERPLATE(Format);
2591 std::variant<Expr, Label, Star> u;
2592 };
2593
2594 // R1214 id-variable -> scalar-int-variable
2595 WRAPPER_CLASS(IdVariable, ScalarIntVariable);
2596
2597 // R1213 io-control-spec ->
2598 // [UNIT =] io-unit | [FMT =] format | [NML =] namelist-group-name |
2599 // ADVANCE = scalar-default-char-expr |
2600 // ASYNCHRONOUS = scalar-default-char-constant-expr |
2601 // BLANK = scalar-default-char-expr |
2602 // DECIMAL = scalar-default-char-expr |
2603 // DELIM = scalar-default-char-expr | END = label | EOR = label |
2604 // ERR = label | ID = id-variable | IOMSG = iomsg-variable |
2605 // IOSTAT = scalar-int-variable | PAD = scalar-default-char-expr |
2606 // POS = scalar-int-expr | REC = scalar-int-expr |
2607 // ROUND = scalar-default-char-expr | SIGN = scalar-default-char-expr |
2608 // SIZE = scalar-int-variable
2609 WRAPPER_CLASS(EndLabel, Label);
2610 WRAPPER_CLASS(EorLabel, Label);
2611 struct IoControlSpec {
2612 UNION_CLASS_BOILERPLATE(IoControlSpec);
2613 struct CharExpr {
2614 ENUM_CLASS(Kind, Advance, Blank, Decimal, Delim, Pad, Round, Sign)
2615 TUPLE_CLASS_BOILERPLATE(CharExpr);
2616 std::tuple<Kind, ScalarDefaultCharExpr> t;
2617 };
2618 WRAPPER_CLASS(Asynchronous, ScalarDefaultCharConstantExpr);
2619 WRAPPER_CLASS(Pos, ScalarIntExpr);
2620 WRAPPER_CLASS(Rec, ScalarIntExpr);
2621 WRAPPER_CLASS(Size, ScalarIntVariable);
2622 std::variant<IoUnit, Format, Name, CharExpr, Asynchronous, EndLabel, EorLabel,
2623 ErrLabel, IdVariable, MsgVariable, StatVariable, Pos, Rec, Size>
2624 u;
2625 };
2626
2627 // R1216 input-item -> variable | io-implied-do
2628 struct InputItem {
2629 UNION_CLASS_BOILERPLATE(InputItem);
2630 std::variant<Variable, common::Indirection<InputImpliedDo>> u;
2631 };
2632
2633 // R1210 read-stmt ->
2634 // READ ( io-control-spec-list ) [input-item-list] |
2635 // READ format [, input-item-list]
2636 struct ReadStmt {
2637 BOILERPLATE(ReadStmt);
ReadStmtReadStmt2638 ReadStmt(std::optional<IoUnit> &&i, std::optional<Format> &&f,
2639 std::list<IoControlSpec> &&cs, std::list<InputItem> &&its)
2640 : iounit{std::move(i)}, format{std::move(f)}, controls(std::move(cs)),
2641 items(std::move(its)) {}
2642 std::optional<IoUnit> iounit; // if first in controls without UNIT= &/or
2643 // followed by untagged format/namelist
2644 std::optional<Format> format; // if second in controls without FMT=/NML=, or
2645 // no (io-control-spec-list); might be
2646 // an untagged namelist group name
2647 std::list<IoControlSpec> controls;
2648 std::list<InputItem> items;
2649 };
2650
2651 // R1217 output-item -> expr | io-implied-do
2652 struct OutputItem {
2653 UNION_CLASS_BOILERPLATE(OutputItem);
2654 std::variant<Expr, common::Indirection<OutputImpliedDo>> u;
2655 };
2656
2657 // R1211 write-stmt -> WRITE ( io-control-spec-list ) [output-item-list]
2658 struct WriteStmt {
2659 BOILERPLATE(WriteStmt);
WriteStmtWriteStmt2660 WriteStmt(std::optional<IoUnit> &&i, std::optional<Format> &&f,
2661 std::list<IoControlSpec> &&cs, std::list<OutputItem> &&its)
2662 : iounit{std::move(i)}, format{std::move(f)}, controls(std::move(cs)),
2663 items(std::move(its)) {}
2664 std::optional<IoUnit> iounit; // if first in controls without UNIT= &/or
2665 // followed by untagged format/namelist
2666 std::optional<Format> format; // if second in controls without FMT=/NML=;
2667 // might be an untagged namelist group, too
2668 std::list<IoControlSpec> controls;
2669 std::list<OutputItem> items;
2670 };
2671
2672 // R1212 print-stmt PRINT format [, output-item-list]
2673 struct PrintStmt {
2674 TUPLE_CLASS_BOILERPLATE(PrintStmt);
2675 std::tuple<Format, std::list<OutputItem>> t;
2676 };
2677
2678 // R1220 io-implied-do-control ->
2679 // do-variable = scalar-int-expr , scalar-int-expr [, scalar-int-expr]
2680 using IoImpliedDoControl = LoopBounds<DoVariable, ScalarIntExpr>;
2681
2682 // R1218 io-implied-do -> ( io-implied-do-object-list , io-implied-do-control )
2683 // R1219 io-implied-do-object -> input-item | output-item
2684 struct InputImpliedDo {
2685 TUPLE_CLASS_BOILERPLATE(InputImpliedDo);
2686 std::tuple<std::list<InputItem>, IoImpliedDoControl> t;
2687 };
2688
2689 struct OutputImpliedDo {
2690 TUPLE_CLASS_BOILERPLATE(OutputImpliedDo);
2691 std::tuple<std::list<OutputItem>, IoImpliedDoControl> t;
2692 };
2693
2694 // R1223 wait-spec ->
2695 // [UNIT =] file-unit-number | END = label | EOR = label | ERR = label |
2696 // ID = scalar-int-expr | IOMSG = iomsg-variable |
2697 // IOSTAT = scalar-int-variable
2698 WRAPPER_CLASS(IdExpr, ScalarIntExpr);
2699 struct WaitSpec {
2700 UNION_CLASS_BOILERPLATE(WaitSpec);
2701 std::variant<FileUnitNumber, EndLabel, EorLabel, ErrLabel, IdExpr,
2702 MsgVariable, StatVariable>
2703 u;
2704 };
2705
2706 // R1222 wait-stmt -> WAIT ( wait-spec-list )
2707 WRAPPER_CLASS(WaitStmt, std::list<WaitSpec>);
2708
2709 // R1227 position-spec ->
2710 // [UNIT =] file-unit-number | IOMSG = iomsg-variable |
2711 // IOSTAT = scalar-int-variable | ERR = label
2712 // R1229 flush-spec ->
2713 // [UNIT =] file-unit-number | IOSTAT = scalar-int-variable |
2714 // IOMSG = iomsg-variable | ERR = label
2715 struct PositionOrFlushSpec {
2716 UNION_CLASS_BOILERPLATE(PositionOrFlushSpec);
2717 std::variant<FileUnitNumber, MsgVariable, StatVariable, ErrLabel> u;
2718 };
2719
2720 // R1224 backspace-stmt ->
2721 // BACKSPACE file-unit-number | BACKSPACE ( position-spec-list )
2722 WRAPPER_CLASS(BackspaceStmt, std::list<PositionOrFlushSpec>);
2723
2724 // R1225 endfile-stmt ->
2725 // ENDFILE file-unit-number | ENDFILE ( position-spec-list )
2726 WRAPPER_CLASS(EndfileStmt, std::list<PositionOrFlushSpec>);
2727
2728 // R1226 rewind-stmt -> REWIND file-unit-number | REWIND ( position-spec-list )
2729 WRAPPER_CLASS(RewindStmt, std::list<PositionOrFlushSpec>);
2730
2731 // R1228 flush-stmt -> FLUSH file-unit-number | FLUSH ( flush-spec-list )
2732 WRAPPER_CLASS(FlushStmt, std::list<PositionOrFlushSpec>);
2733
2734 // R1231 inquire-spec ->
2735 // [UNIT =] file-unit-number | FILE = file-name-expr |
2736 // ACCESS = scalar-default-char-variable |
2737 // ACTION = scalar-default-char-variable |
2738 // ASYNCHRONOUS = scalar-default-char-variable |
2739 // BLANK = scalar-default-char-variable |
2740 // DECIMAL = scalar-default-char-variable |
2741 // DELIM = scalar-default-char-variable |
2742 // DIRECT = scalar-default-char-variable |
2743 // ENCODING = scalar-default-char-variable |
2744 // ERR = label | EXIST = scalar-logical-variable |
2745 // FORM = scalar-default-char-variable |
2746 // FORMATTED = scalar-default-char-variable |
2747 // ID = scalar-int-expr | IOMSG = iomsg-variable |
2748 // IOSTAT = scalar-int-variable |
2749 // NAME = scalar-default-char-variable |
2750 // NAMED = scalar-logical-variable |
2751 // NEXTREC = scalar-int-variable | NUMBER = scalar-int-variable |
2752 // OPENED = scalar-logical-variable |
2753 // PAD = scalar-default-char-variable |
2754 // PENDING = scalar-logical-variable | POS = scalar-int-variable |
2755 // POSITION = scalar-default-char-variable |
2756 // READ = scalar-default-char-variable |
2757 // READWRITE = scalar-default-char-variable |
2758 // RECL = scalar-int-variable | ROUND = scalar-default-char-variable |
2759 // SEQUENTIAL = scalar-default-char-variable |
2760 // SIGN = scalar-default-char-variable |
2761 // SIZE = scalar-int-variable |
2762 // STREAM = scalar-default-char-variable |
2763 // STATUS = scalar-default-char-variable |
2764 // UNFORMATTED = scalar-default-char-variable |
2765 // WRITE = scalar-default-char-variable
2766 // @ | CARRIAGECONTROL = scalar-default-char-variable
2767 // | CONVERT = scalar-default-char-variable
2768 // | DISPOSE = scalar-default-char-variable
2769 struct InquireSpec {
2770 UNION_CLASS_BOILERPLATE(InquireSpec);
2771 struct CharVar {
2772 ENUM_CLASS(Kind, Access, Action, Asynchronous, Blank, Decimal, Delim,
2773 Direct, Encoding, Form, Formatted, Iomsg, Name, Pad, Position, Read,
2774 Readwrite, Round, Sequential, Sign, Stream, Status, Unformatted, Write,
2775 /* extensions: */ Carriagecontrol, Convert, Dispose)
2776 TUPLE_CLASS_BOILERPLATE(CharVar);
2777 std::tuple<Kind, ScalarDefaultCharVariable> t;
2778 };
2779 struct IntVar {
2780 ENUM_CLASS(Kind, Iostat, Nextrec, Number, Pos, Recl, Size)
2781 TUPLE_CLASS_BOILERPLATE(IntVar);
2782 std::tuple<Kind, ScalarIntVariable> t;
2783 };
2784 struct LogVar {
2785 ENUM_CLASS(Kind, Exist, Named, Opened, Pending)
2786 TUPLE_CLASS_BOILERPLATE(LogVar);
2787 std::tuple<Kind, Scalar<Logical<Variable>>> t;
2788 };
2789 std::variant<FileUnitNumber, FileNameExpr, CharVar, IntVar, LogVar, IdExpr,
2790 ErrLabel>
2791 u;
2792 };
2793
2794 // R1230 inquire-stmt ->
2795 // INQUIRE ( inquire-spec-list ) |
2796 // INQUIRE ( IOLENGTH = scalar-int-variable ) output-item-list
2797 struct InquireStmt {
2798 UNION_CLASS_BOILERPLATE(InquireStmt);
2799 struct Iolength {
2800 TUPLE_CLASS_BOILERPLATE(Iolength);
2801 std::tuple<ScalarIntVariable, std::list<OutputItem>> t;
2802 };
2803 std::variant<std::list<InquireSpec>, Iolength> u;
2804 };
2805
2806 // R1301 format-stmt -> FORMAT format-specification
2807 WRAPPER_CLASS(FormatStmt, format::FormatSpecification);
2808
2809 // R1402 program-stmt -> PROGRAM program-name
2810 WRAPPER_CLASS(ProgramStmt, Name);
2811
2812 // R1403 end-program-stmt -> END [PROGRAM [program-name]]
2813 WRAPPER_CLASS(EndProgramStmt, std::optional<Name>);
2814
2815 // R1401 main-program ->
2816 // [program-stmt] [specification-part] [execution-part]
2817 // [internal-subprogram-part] end-program-stmt
2818 struct MainProgram {
2819 TUPLE_CLASS_BOILERPLATE(MainProgram);
2820 std::tuple<std::optional<Statement<ProgramStmt>>, SpecificationPart,
2821 ExecutionPart, std::optional<InternalSubprogramPart>,
2822 Statement<EndProgramStmt>>
2823 t;
2824 };
2825
2826 // R1405 module-stmt -> MODULE module-name
2827 WRAPPER_CLASS(ModuleStmt, Name);
2828
2829 // R1408 module-subprogram ->
2830 // function-subprogram | subroutine-subprogram |
2831 // separate-module-subprogram
2832 struct ModuleSubprogram {
2833 UNION_CLASS_BOILERPLATE(ModuleSubprogram);
2834 std::variant<common::Indirection<FunctionSubprogram>,
2835 common::Indirection<SubroutineSubprogram>,
2836 common::Indirection<SeparateModuleSubprogram>>
2837 u;
2838 };
2839
2840 // R1407 module-subprogram-part -> contains-stmt [module-subprogram]...
2841 struct ModuleSubprogramPart {
2842 TUPLE_CLASS_BOILERPLATE(ModuleSubprogramPart);
2843 std::tuple<Statement<ContainsStmt>, std::list<ModuleSubprogram>> t;
2844 };
2845
2846 // R1406 end-module-stmt -> END [MODULE [module-name]]
2847 WRAPPER_CLASS(EndModuleStmt, std::optional<Name>);
2848
2849 // R1404 module ->
2850 // module-stmt [specification-part] [module-subprogram-part]
2851 // end-module-stmt
2852 struct Module {
2853 TUPLE_CLASS_BOILERPLATE(Module);
2854 std::tuple<Statement<ModuleStmt>, SpecificationPart,
2855 std::optional<ModuleSubprogramPart>, Statement<EndModuleStmt>>
2856 t;
2857 };
2858
2859 // R1411 rename ->
2860 // local-name => use-name |
2861 // OPERATOR ( local-defined-operator ) =>
2862 // OPERATOR ( use-defined-operator )
2863 struct Rename {
2864 UNION_CLASS_BOILERPLATE(Rename);
2865 struct Names {
2866 TUPLE_CLASS_BOILERPLATE(Names);
2867 std::tuple<Name, Name> t;
2868 };
2869 struct Operators {
2870 TUPLE_CLASS_BOILERPLATE(Operators);
2871 std::tuple<DefinedOpName, DefinedOpName> t;
2872 };
2873 std::variant<Names, Operators> u;
2874 };
2875
2876 // R1418 parent-identifier -> ancestor-module-name [: parent-submodule-name]
2877 struct ParentIdentifier {
2878 TUPLE_CLASS_BOILERPLATE(ParentIdentifier);
2879 std::tuple<Name, std::optional<Name>> t;
2880 };
2881
2882 // R1417 submodule-stmt -> SUBMODULE ( parent-identifier ) submodule-name
2883 struct SubmoduleStmt {
2884 TUPLE_CLASS_BOILERPLATE(SubmoduleStmt);
2885 std::tuple<ParentIdentifier, Name> t;
2886 };
2887
2888 // R1419 end-submodule-stmt -> END [SUBMODULE [submodule-name]]
2889 WRAPPER_CLASS(EndSubmoduleStmt, std::optional<Name>);
2890
2891 // R1416 submodule ->
2892 // submodule-stmt [specification-part] [module-subprogram-part]
2893 // end-submodule-stmt
2894 struct Submodule {
2895 TUPLE_CLASS_BOILERPLATE(Submodule);
2896 std::tuple<Statement<SubmoduleStmt>, SpecificationPart,
2897 std::optional<ModuleSubprogramPart>, Statement<EndSubmoduleStmt>>
2898 t;
2899 };
2900
2901 // R1421 block-data-stmt -> BLOCK DATA [block-data-name]
2902 WRAPPER_CLASS(BlockDataStmt, std::optional<Name>);
2903
2904 // R1422 end-block-data-stmt -> END [BLOCK DATA [block-data-name]]
2905 WRAPPER_CLASS(EndBlockDataStmt, std::optional<Name>);
2906
2907 // R1420 block-data -> block-data-stmt [specification-part] end-block-data-stmt
2908 struct BlockData {
2909 TUPLE_CLASS_BOILERPLATE(BlockData);
2910 std::tuple<Statement<BlockDataStmt>, SpecificationPart,
2911 Statement<EndBlockDataStmt>>
2912 t;
2913 };
2914
2915 // R1508 generic-spec ->
2916 // generic-name | OPERATOR ( defined-operator ) |
2917 // ASSIGNMENT ( = ) | defined-io-generic-spec
2918 // R1509 defined-io-generic-spec ->
2919 // READ ( FORMATTED ) | READ ( UNFORMATTED ) |
2920 // WRITE ( FORMATTED ) | WRITE ( UNFORMATTED )
2921 struct GenericSpec {
2922 UNION_CLASS_BOILERPLATE(GenericSpec);
2923 EMPTY_CLASS(Assignment);
2924 EMPTY_CLASS(ReadFormatted);
2925 EMPTY_CLASS(ReadUnformatted);
2926 EMPTY_CLASS(WriteFormatted);
2927 EMPTY_CLASS(WriteUnformatted);
2928 CharBlock source;
2929 std::variant<Name, DefinedOperator, Assignment, ReadFormatted,
2930 ReadUnformatted, WriteFormatted, WriteUnformatted>
2931 u;
2932 };
2933
2934 // R1510 generic-stmt ->
2935 // GENERIC [, access-spec] :: generic-spec => specific-procedure-list
2936 struct GenericStmt {
2937 TUPLE_CLASS_BOILERPLATE(GenericStmt);
2938 std::tuple<std::optional<AccessSpec>, GenericSpec, std::list<Name>> t;
2939 };
2940
2941 // R1503 interface-stmt -> INTERFACE [generic-spec] | ABSTRACT INTERFACE
2942 struct InterfaceStmt {
2943 UNION_CLASS_BOILERPLATE(InterfaceStmt);
2944 // Workaround for clang with libstc++10 bug
InterfaceStmtInterfaceStmt2945 InterfaceStmt(Abstract x) : u{x} {}
2946
2947 std::variant<std::optional<GenericSpec>, Abstract> u;
2948 };
2949
2950 // R1412 only -> generic-spec | only-use-name | rename
2951 // R1413 only-use-name -> use-name
2952 struct Only {
2953 UNION_CLASS_BOILERPLATE(Only);
2954 std::variant<common::Indirection<GenericSpec>, Name, Rename> u;
2955 };
2956
2957 // R1409 use-stmt ->
2958 // USE [[, module-nature] ::] module-name [, rename-list] |
2959 // USE [[, module-nature] ::] module-name , ONLY : [only-list]
2960 // R1410 module-nature -> INTRINSIC | NON_INTRINSIC
2961 struct UseStmt {
2962 BOILERPLATE(UseStmt);
ENUM_CLASSUseStmt2963 ENUM_CLASS(ModuleNature, Intrinsic, Non_Intrinsic) // R1410
2964 template <typename A>
2965 UseStmt(std::optional<ModuleNature> &&nat, Name &&n, std::list<A> &&x)
2966 : nature(std::move(nat)), moduleName(std::move(n)), u(std::move(x)) {}
2967 std::optional<ModuleNature> nature;
2968 Name moduleName;
2969 std::variant<std::list<Rename>, std::list<Only>> u;
2970 };
2971
2972 // R1514 proc-attr-spec ->
2973 // access-spec | proc-language-binding-spec | INTENT ( intent-spec ) |
2974 // OPTIONAL | POINTER | PROTECTED | SAVE
2975 struct ProcAttrSpec {
2976 UNION_CLASS_BOILERPLATE(ProcAttrSpec);
2977 std::variant<AccessSpec, LanguageBindingSpec, IntentSpec, Optional, Pointer,
2978 Protected, Save>
2979 u;
2980 };
2981
2982 // R1512 procedure-declaration-stmt ->
2983 // PROCEDURE ( [proc-interface] ) [[, proc-attr-spec]... ::]
2984 // proc-decl-list
2985 struct ProcedureDeclarationStmt {
2986 TUPLE_CLASS_BOILERPLATE(ProcedureDeclarationStmt);
2987 std::tuple<std::optional<ProcInterface>, std::list<ProcAttrSpec>,
2988 std::list<ProcDecl>>
2989 t;
2990 };
2991
2992 // R1527 prefix-spec ->
2993 // declaration-type-spec | ELEMENTAL | IMPURE | MODULE |
2994 // NON_RECURSIVE | PURE | RECURSIVE
2995 struct PrefixSpec {
2996 UNION_CLASS_BOILERPLATE(PrefixSpec);
2997 EMPTY_CLASS(Elemental);
2998 EMPTY_CLASS(Impure);
2999 EMPTY_CLASS(Module);
3000 EMPTY_CLASS(Non_Recursive);
3001 EMPTY_CLASS(Pure);
3002 EMPTY_CLASS(Recursive);
3003 std::variant<DeclarationTypeSpec, Elemental, Impure, Module, Non_Recursive,
3004 Pure, Recursive>
3005 u;
3006 };
3007
3008 // R1532 suffix ->
3009 // proc-language-binding-spec [RESULT ( result-name )] |
3010 // RESULT ( result-name ) [proc-language-binding-spec]
3011 struct Suffix {
3012 BOILERPLATE(Suffix);
SuffixSuffix3013 Suffix(LanguageBindingSpec &&lbs, std::optional<Name> &&rn)
3014 : binding(std::move(lbs)), resultName(std::move(rn)) {}
SuffixSuffix3015 Suffix(Name &&rn, std::optional<LanguageBindingSpec> &&lbs)
3016 : binding(std::move(lbs)), resultName(std::move(rn)) {}
3017 std::optional<LanguageBindingSpec> binding;
3018 std::optional<Name> resultName;
3019 };
3020
3021 // R1530 function-stmt ->
3022 // [prefix] FUNCTION function-name ( [dummy-arg-name-list] ) [suffix]
3023 // R1526 prefix -> prefix-spec [prefix-spec]...
3024 // R1531 dummy-arg-name -> name
3025 struct FunctionStmt {
3026 TUPLE_CLASS_BOILERPLATE(FunctionStmt);
3027 std::tuple<std::list<PrefixSpec>, Name, std::list<Name>,
3028 std::optional<Suffix>>
3029 t;
3030 };
3031
3032 // R1533 end-function-stmt -> END [FUNCTION [function-name]]
3033 WRAPPER_CLASS(EndFunctionStmt, std::optional<Name>);
3034
3035 // R1536 dummy-arg -> dummy-arg-name | *
3036 struct DummyArg {
3037 UNION_CLASS_BOILERPLATE(DummyArg);
3038 std::variant<Name, Star> u;
3039 };
3040
3041 // R1535 subroutine-stmt ->
3042 // [prefix] SUBROUTINE subroutine-name [( [dummy-arg-list] )
3043 // [proc-language-binding-spec]]
3044 struct SubroutineStmt {
3045 TUPLE_CLASS_BOILERPLATE(SubroutineStmt);
3046 std::tuple<std::list<PrefixSpec>, Name, std::list<DummyArg>,
3047 std::optional<LanguageBindingSpec>>
3048 t;
3049 };
3050
3051 // R1537 end-subroutine-stmt -> END [SUBROUTINE [subroutine-name]]
3052 WRAPPER_CLASS(EndSubroutineStmt, std::optional<Name>);
3053
3054 // R1505 interface-body ->
3055 // function-stmt [specification-part] end-function-stmt |
3056 // subroutine-stmt [specification-part] end-subroutine-stmt
3057 struct InterfaceBody {
3058 UNION_CLASS_BOILERPLATE(InterfaceBody);
3059 struct Function {
3060 TUPLE_CLASS_BOILERPLATE(Function);
3061 std::tuple<Statement<FunctionStmt>, common::Indirection<SpecificationPart>,
3062 Statement<EndFunctionStmt>>
3063 t;
3064 };
3065 struct Subroutine {
3066 TUPLE_CLASS_BOILERPLATE(Subroutine);
3067 std::tuple<Statement<SubroutineStmt>,
3068 common::Indirection<SpecificationPart>, Statement<EndSubroutineStmt>>
3069 t;
3070 };
3071 std::variant<Function, Subroutine> u;
3072 };
3073
3074 // R1506 procedure-stmt -> [MODULE] PROCEDURE [::] specific-procedure-list
3075 struct ProcedureStmt {
3076 ENUM_CLASS(Kind, ModuleProcedure, Procedure)
3077 TUPLE_CLASS_BOILERPLATE(ProcedureStmt);
3078 std::tuple<Kind, std::list<Name>> t;
3079 };
3080
3081 // R1502 interface-specification -> interface-body | procedure-stmt
3082 struct InterfaceSpecification {
3083 UNION_CLASS_BOILERPLATE(InterfaceSpecification);
3084 std::variant<InterfaceBody, Statement<ProcedureStmt>> u;
3085 };
3086
3087 // R1504 end-interface-stmt -> END INTERFACE [generic-spec]
3088 WRAPPER_CLASS(EndInterfaceStmt, std::optional<GenericSpec>);
3089
3090 // R1501 interface-block ->
3091 // interface-stmt [interface-specification]... end-interface-stmt
3092 struct InterfaceBlock {
3093 TUPLE_CLASS_BOILERPLATE(InterfaceBlock);
3094 std::tuple<Statement<InterfaceStmt>, std::list<InterfaceSpecification>,
3095 Statement<EndInterfaceStmt>>
3096 t;
3097 };
3098
3099 // R1511 external-stmt -> EXTERNAL [::] external-name-list
3100 WRAPPER_CLASS(ExternalStmt, std::list<Name>);
3101
3102 // R1519 intrinsic-stmt -> INTRINSIC [::] intrinsic-procedure-name-list
3103 WRAPPER_CLASS(IntrinsicStmt, std::list<Name>);
3104
3105 // R1522 procedure-designator ->
3106 // procedure-name | proc-component-ref | data-ref % binding-name
3107 struct ProcedureDesignator {
3108 UNION_CLASS_BOILERPLATE(ProcedureDesignator);
3109 std::variant<Name, ProcComponentRef> u;
3110 };
3111
3112 // R1525 alt-return-spec -> * label
3113 WRAPPER_CLASS(AltReturnSpec, Label);
3114
3115 // R1524 actual-arg ->
3116 // expr | variable | procedure-name | proc-component-ref |
3117 // alt-return-spec
3118 struct ActualArg {
3119 WRAPPER_CLASS(PercentRef, Variable); // %REF(v) extension
3120 WRAPPER_CLASS(PercentVal, Expr); // %VAL(x) extension
3121 UNION_CLASS_BOILERPLATE(ActualArg);
ActualArgActualArg3122 ActualArg(Expr &&x) : u{common::Indirection<Expr>(std::move(x))} {}
3123 std::variant<common::Indirection<Expr>, AltReturnSpec, PercentRef, PercentVal>
3124 u;
3125 };
3126
3127 // R1523 actual-arg-spec -> [keyword =] actual-arg
3128 struct ActualArgSpec {
3129 TUPLE_CLASS_BOILERPLATE(ActualArgSpec);
3130 std::tuple<std::optional<Keyword>, ActualArg> t;
3131 };
3132
3133 // R1520 function-reference -> procedure-designator ( [actual-arg-spec-list] )
3134 struct Call {
3135 TUPLE_CLASS_BOILERPLATE(Call);
3136 CharBlock source;
3137 std::tuple<ProcedureDesignator, std::list<ActualArgSpec>> t;
3138 };
3139
3140 struct FunctionReference {
3141 WRAPPER_CLASS_BOILERPLATE(FunctionReference, Call);
3142 Designator ConvertToArrayElementRef();
3143 StructureConstructor ConvertToStructureConstructor(
3144 const semantics::DerivedTypeSpec &);
3145 };
3146
3147 // R1521 call-stmt -> CALL procedure-designator [( [actual-arg-spec-list] )]
3148 struct CallStmt {
3149 WRAPPER_CLASS_BOILERPLATE(CallStmt, Call);
3150 mutable common::ForwardOwningPointer<evaluate::ProcedureRef>
3151 typedCall; // filled by semantics
3152 };
3153
3154 // R1529 function-subprogram ->
3155 // function-stmt [specification-part] [execution-part]
3156 // [internal-subprogram-part] end-function-stmt
3157 struct FunctionSubprogram {
3158 TUPLE_CLASS_BOILERPLATE(FunctionSubprogram);
3159 std::tuple<Statement<FunctionStmt>, SpecificationPart, ExecutionPart,
3160 std::optional<InternalSubprogramPart>, Statement<EndFunctionStmt>>
3161 t;
3162 };
3163
3164 // R1534 subroutine-subprogram ->
3165 // subroutine-stmt [specification-part] [execution-part]
3166 // [internal-subprogram-part] end-subroutine-stmt
3167 struct SubroutineSubprogram {
3168 TUPLE_CLASS_BOILERPLATE(SubroutineSubprogram);
3169 std::tuple<Statement<SubroutineStmt>, SpecificationPart, ExecutionPart,
3170 std::optional<InternalSubprogramPart>, Statement<EndSubroutineStmt>>
3171 t;
3172 };
3173
3174 // R1539 mp-subprogram-stmt -> MODULE PROCEDURE procedure-name
3175 WRAPPER_CLASS(MpSubprogramStmt, Name);
3176
3177 // R1540 end-mp-subprogram-stmt -> END [PROCEDURE [procedure-name]]
3178 WRAPPER_CLASS(EndMpSubprogramStmt, std::optional<Name>);
3179
3180 // R1538 separate-module-subprogram ->
3181 // mp-subprogram-stmt [specification-part] [execution-part]
3182 // [internal-subprogram-part] end-mp-subprogram-stmt
3183 struct SeparateModuleSubprogram {
3184 TUPLE_CLASS_BOILERPLATE(SeparateModuleSubprogram);
3185 std::tuple<Statement<MpSubprogramStmt>, SpecificationPart, ExecutionPart,
3186 std::optional<InternalSubprogramPart>, Statement<EndMpSubprogramStmt>>
3187 t;
3188 };
3189
3190 // R1541 entry-stmt -> ENTRY entry-name [( [dummy-arg-list] ) [suffix]]
3191 struct EntryStmt {
3192 TUPLE_CLASS_BOILERPLATE(EntryStmt);
3193 std::tuple<Name, std::list<DummyArg>, std::optional<Suffix>> t;
3194 };
3195
3196 // R1542 return-stmt -> RETURN [scalar-int-expr]
3197 WRAPPER_CLASS(ReturnStmt, std::optional<ScalarIntExpr>);
3198
3199 // R1544 stmt-function-stmt ->
3200 // function-name ( [dummy-arg-name-list] ) = scalar-expr
3201 struct StmtFunctionStmt {
3202 TUPLE_CLASS_BOILERPLATE(StmtFunctionStmt);
3203 std::tuple<Name, std::list<Name>, Scalar<Expr>> t;
3204 Statement<ActionStmt> ConvertToAssignment();
3205 };
3206
3207 // Compiler directives
3208 // !DIR$ IGNORE_TKR [ [(tkr...)] name ]...
3209 // !DIR$ name...
3210 struct CompilerDirective {
3211 UNION_CLASS_BOILERPLATE(CompilerDirective);
3212 struct IgnoreTKR {
3213 TUPLE_CLASS_BOILERPLATE(IgnoreTKR);
3214 std::tuple<std::list<const char *>, Name> t;
3215 };
3216 struct NameValue {
3217 TUPLE_CLASS_BOILERPLATE(NameValue);
3218 std::tuple<Name, std::optional<std::uint64_t>> t;
3219 };
3220 CharBlock source;
3221 std::variant<std::list<IgnoreTKR>, std::list<NameValue>> u;
3222 };
3223
3224 // Legacy extensions
3225 struct BasedPointer {
3226 TUPLE_CLASS_BOILERPLATE(BasedPointer);
3227 std::tuple<ObjectName, ObjectName, std::optional<ArraySpec>> t;
3228 };
3229 WRAPPER_CLASS(BasedPointerStmt, std::list<BasedPointer>);
3230
3231 struct Union;
3232 struct StructureDef;
3233
3234 struct StructureField {
3235 UNION_CLASS_BOILERPLATE(StructureField);
3236 std::variant<Statement<DataComponentDefStmt>,
3237 common::Indirection<StructureDef>, common::Indirection<Union>>
3238 u;
3239 };
3240
3241 struct Map {
3242 EMPTY_CLASS(MapStmt);
3243 EMPTY_CLASS(EndMapStmt);
3244 TUPLE_CLASS_BOILERPLATE(Map);
3245 std::tuple<Statement<MapStmt>, std::list<StructureField>,
3246 Statement<EndMapStmt>>
3247 t;
3248 };
3249
3250 struct Union {
3251 EMPTY_CLASS(UnionStmt);
3252 EMPTY_CLASS(EndUnionStmt);
3253 TUPLE_CLASS_BOILERPLATE(Union);
3254 std::tuple<Statement<UnionStmt>, std::list<Map>, Statement<EndUnionStmt>> t;
3255 };
3256
3257 struct StructureStmt {
3258 TUPLE_CLASS_BOILERPLATE(StructureStmt);
3259 std::tuple<Name, bool /*slashes*/, std::list<EntityDecl>> t;
3260 };
3261
3262 struct StructureDef {
3263 EMPTY_CLASS(EndStructureStmt);
3264 TUPLE_CLASS_BOILERPLATE(StructureDef);
3265 std::tuple<Statement<StructureStmt>, std::list<StructureField>,
3266 Statement<EndStructureStmt>>
3267 t;
3268 };
3269
3270 // Old style PARAMETER statement without parentheses.
3271 // Types are determined entirely from the right-hand sides, not the names.
3272 WRAPPER_CLASS(OldParameterStmt, std::list<NamedConstantDef>);
3273
3274 // Deprecations
3275 struct ArithmeticIfStmt {
3276 TUPLE_CLASS_BOILERPLATE(ArithmeticIfStmt);
3277 std::tuple<Expr, Label, Label, Label> t;
3278 };
3279
3280 struct AssignStmt {
3281 TUPLE_CLASS_BOILERPLATE(AssignStmt);
3282 std::tuple<Label, Name> t;
3283 };
3284
3285 struct AssignedGotoStmt {
3286 TUPLE_CLASS_BOILERPLATE(AssignedGotoStmt);
3287 std::tuple<Name, std::list<Label>> t;
3288 };
3289
3290 WRAPPER_CLASS(PauseStmt, std::optional<StopCode>);
3291
3292 // Parse tree nodes for OpenMP 4.5 directives and clauses
3293
3294 // 2.5 proc-bind-clause -> PROC_BIND (MASTER | CLOSE | SPREAD)
3295 struct OmpProcBindClause {
3296 ENUM_CLASS(Type, Close, Master, Spread)
3297 WRAPPER_CLASS_BOILERPLATE(OmpProcBindClause, Type);
3298 };
3299
3300 // 2.15.3.1 default-clause -> DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE)
3301 struct OmpDefaultClause {
3302 ENUM_CLASS(Type, Private, Firstprivate, Shared, None)
3303 WRAPPER_CLASS_BOILERPLATE(OmpDefaultClause, Type);
3304 };
3305
3306 // 2.1 Directives or clauses may accept a list or extended-list.
3307 // A list item is a variable, array section or common block name (enclosed
3308 // in slashes). An extended list item is a list item or a procedure Name.
3309 // variable-name | / common-block / | array-sections
3310 struct OmpObject {
3311 UNION_CLASS_BOILERPLATE(OmpObject);
3312 std::variant<Designator, /*common block*/ Name> u;
3313 };
3314
3315 WRAPPER_CLASS(OmpObjectList, std::list<OmpObject>);
3316
3317 // 2.15.5.1 map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE
3318 struct OmpMapType {
3319 TUPLE_CLASS_BOILERPLATE(OmpMapType);
3320 EMPTY_CLASS(Always);
3321 ENUM_CLASS(Type, To, From, Tofrom, Alloc, Release, Delete)
3322 std::tuple<std::optional<Always>, Type> t;
3323 };
3324
3325 // 2.15.5.1 map -> MAP ([ [ALWAYS[,]] map-type : ] variable-name-list)
3326 struct OmpMapClause {
3327 TUPLE_CLASS_BOILERPLATE(OmpMapClause);
3328 std::tuple<std::optional<OmpMapType>, OmpObjectList> t;
3329 };
3330
3331 // 2.15.5.2 defaultmap -> DEFAULTMAP (implicit-behavior[:variable-category])
3332 struct OmpDefaultmapClause {
3333 TUPLE_CLASS_BOILERPLATE(OmpDefaultmapClause);
3334 ENUM_CLASS(ImplicitBehavior, Tofrom)
3335 ENUM_CLASS(VariableCategory, Scalar)
3336 std::tuple<ImplicitBehavior, std::optional<VariableCategory>> t;
3337 };
3338
3339 // 2.7.1 sched-modifier -> MONOTONIC | NONMONOTONIC | SIMD
3340 struct OmpScheduleModifierType {
3341 ENUM_CLASS(ModType, Monotonic, Nonmonotonic, Simd)
3342 WRAPPER_CLASS_BOILERPLATE(OmpScheduleModifierType, ModType);
3343 };
3344
3345 struct OmpScheduleModifier {
3346 TUPLE_CLASS_BOILERPLATE(OmpScheduleModifier);
3347 WRAPPER_CLASS(Modifier1, OmpScheduleModifierType);
3348 WRAPPER_CLASS(Modifier2, OmpScheduleModifierType);
3349 std::tuple<Modifier1, std::optional<Modifier2>> t;
3350 };
3351
3352 // 2.7.1 schedule-clause -> SCHEDULE ([sched-modifier1] [, sched-modifier2]:]
3353 // kind[, chunk_size])
3354 struct OmpScheduleClause {
3355 TUPLE_CLASS_BOILERPLATE(OmpScheduleClause);
3356 ENUM_CLASS(ScheduleType, Static, Dynamic, Guided, Auto, Runtime)
3357 std::tuple<std::optional<OmpScheduleModifier>, ScheduleType,
3358 std::optional<ScalarIntExpr>>
3359 t;
3360 };
3361
3362 // 2.12 if-clause -> IF ([ directive-name-modifier :] scalar-logical-expr)
3363 struct OmpIfClause {
3364 TUPLE_CLASS_BOILERPLATE(OmpIfClause);
3365 ENUM_CLASS(DirectiveNameModifier, Parallel, Target, TargetEnterData,
3366 TargetExitData, TargetData, TargetUpdate, Taskloop, Task)
3367 std::tuple<std::optional<DirectiveNameModifier>, ScalarLogicalExpr> t;
3368 };
3369
3370 // 2.8.1 aligned-clause -> ALIGNED (variable-name-list[ : scalar-constant])
3371 struct OmpAlignedClause {
3372 TUPLE_CLASS_BOILERPLATE(OmpAlignedClause);
3373 CharBlock source;
3374 std::tuple<std::list<Name>, std::optional<ScalarIntConstantExpr>> t;
3375 };
3376
3377 // 2.15.3.7 linear-modifier -> REF | VAL | UVAL
3378 struct OmpLinearModifier {
3379 ENUM_CLASS(Type, Ref, Val, Uval)
3380 WRAPPER_CLASS_BOILERPLATE(OmpLinearModifier, Type);
3381 };
3382
3383 // 2.15.3.7 linear-clause -> LINEAR (linear-list[ : linear-step])
3384 // linear-list -> list | linear-modifier(list)
3385 struct OmpLinearClause {
3386 UNION_CLASS_BOILERPLATE(OmpLinearClause);
3387 struct WithModifier {
3388 BOILERPLATE(WithModifier);
WithModifierOmpLinearClause::WithModifier3389 WithModifier(OmpLinearModifier &&m, std::list<Name> &&n,
3390 std::optional<ScalarIntConstantExpr> &&s)
3391 : modifier(std::move(m)), names(std::move(n)), step(std::move(s)) {}
3392 OmpLinearModifier modifier;
3393 std::list<Name> names;
3394 std::optional<ScalarIntConstantExpr> step;
3395 };
3396 struct WithoutModifier {
3397 BOILERPLATE(WithoutModifier);
WithoutModifierOmpLinearClause::WithoutModifier3398 WithoutModifier(
3399 std::list<Name> &&n, std::optional<ScalarIntConstantExpr> &&s)
3400 : names(std::move(n)), step(std::move(s)) {}
3401 std::list<Name> names;
3402 std::optional<ScalarIntConstantExpr> step;
3403 };
3404 std::variant<WithModifier, WithoutModifier> u;
3405 };
3406
3407 // 2.15.3.6 reduction-identifier -> + | - | * | .AND. | .OR. | .EQV. | .NEQV. |
3408 // MAX | MIN | IAND | IOR | IEOR
3409 struct OmpReductionOperator {
3410 UNION_CLASS_BOILERPLATE(OmpReductionOperator);
3411 std::variant<DefinedOperator, ProcedureDesignator> u;
3412 };
3413
3414 // 2.15.3.6 reduction-clause -> REDUCTION (reduction-identifier:
3415 // variable-name-list)
3416 struct OmpReductionClause {
3417 TUPLE_CLASS_BOILERPLATE(OmpReductionClause);
3418 std::tuple<OmpReductionOperator, OmpObjectList> t;
3419 };
3420
3421 // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)
3422 struct OmpAllocateClause {
3423 TUPLE_CLASS_BOILERPLATE(OmpAllocateClause);
3424 WRAPPER_CLASS(Allocator, ScalarIntExpr);
3425 std::tuple<std::optional<Allocator>, OmpObjectList> t;
3426 };
3427
3428 // 2.13.9 depend-vec-length -> +/- non-negative-constant
3429 struct OmpDependSinkVecLength {
3430 TUPLE_CLASS_BOILERPLATE(OmpDependSinkVecLength);
3431 std::tuple<DefinedOperator, ScalarIntConstantExpr> t;
3432 };
3433
3434 // 2.13.9 depend-vec -> iterator [+/- depend-vec-length],...,iterator[...]
3435 struct OmpDependSinkVec {
3436 TUPLE_CLASS_BOILERPLATE(OmpDependSinkVec);
3437 std::tuple<Name, std::optional<OmpDependSinkVecLength>> t;
3438 };
3439
3440 // 2.13.9 depend-type -> IN | OUT | INOUT | SOURCE | SINK
3441 struct OmpDependenceType {
3442 ENUM_CLASS(Type, In, Out, Inout, Source, Sink)
3443 WRAPPER_CLASS_BOILERPLATE(OmpDependenceType, Type);
3444 };
3445
3446 // 2.13.9 depend-clause -> DEPEND (((IN | OUT | INOUT) : variable-name-list) |
3447 // SOURCE | SINK : depend-vec)
3448 struct OmpDependClause {
3449 UNION_CLASS_BOILERPLATE(OmpDependClause);
3450 EMPTY_CLASS(Source);
3451 WRAPPER_CLASS(Sink, std::list<OmpDependSinkVec>);
3452 struct InOut {
3453 TUPLE_CLASS_BOILERPLATE(InOut);
3454 std::tuple<OmpDependenceType, std::list<Designator>> t;
3455 };
3456 std::variant<Source, Sink, InOut> u;
3457 };
3458
3459 // OpenMP Clauses
3460 struct OmpClause {
3461 UNION_CLASS_BOILERPLATE(OmpClause);
3462
3463 #define GEN_FLANG_CLAUSE_PARSER_CLASSES
3464 #include "llvm/Frontend/OpenMP/OMP.inc"
3465
3466 CharBlock source;
3467
3468 std::variant<
3469 #define GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
3470 #include "llvm/Frontend/OpenMP/OMP.inc"
3471 >
3472 u;
3473 };
3474
3475 struct OmpClauseList {
3476 WRAPPER_CLASS_BOILERPLATE(OmpClauseList, std::list<OmpClause>);
3477 CharBlock source;
3478 };
3479
3480 // 2.7.2 SECTIONS
3481 // 2.11.2 PARALLEL SECTIONS
3482 struct OmpSectionsDirective {
3483 WRAPPER_CLASS_BOILERPLATE(OmpSectionsDirective, llvm::omp::Directive);
3484 CharBlock source;
3485 };
3486
3487 struct OmpBeginSectionsDirective {
3488 TUPLE_CLASS_BOILERPLATE(OmpBeginSectionsDirective);
3489 std::tuple<OmpSectionsDirective, OmpClauseList> t;
3490 CharBlock source;
3491 };
3492 struct OmpEndSectionsDirective {
3493 TUPLE_CLASS_BOILERPLATE(OmpEndSectionsDirective);
3494 std::tuple<OmpSectionsDirective, OmpClauseList> t;
3495 CharBlock source;
3496 };
3497
3498 // [!$omp section]
3499 // structured-block
3500 // [!$omp section
3501 // structured-block]
3502 // ...
3503 WRAPPER_CLASS(OmpSectionBlocks, std::list<Block>);
3504
3505 struct OpenMPSectionsConstruct {
3506 TUPLE_CLASS_BOILERPLATE(OpenMPSectionsConstruct);
3507 std::tuple<OmpBeginSectionsDirective, OmpSectionBlocks,
3508 OmpEndSectionsDirective>
3509 t;
3510 };
3511
3512 // OpenMP directive beginning or ending a block
3513 struct OmpBlockDirective {
3514 WRAPPER_CLASS_BOILERPLATE(OmpBlockDirective, llvm::omp::Directive);
3515 CharBlock source;
3516 };
3517
3518 // 2.10.6 declare-target -> DECLARE TARGET (extended-list) |
3519 // DECLARE TARGET [declare-target-clause[ [,]
3520 // declare-target-clause]...]
3521 struct OmpDeclareTargetWithList {
3522 WRAPPER_CLASS_BOILERPLATE(OmpDeclareTargetWithList, OmpObjectList);
3523 CharBlock source;
3524 };
3525
3526 struct OmpDeclareTargetWithClause {
3527 WRAPPER_CLASS_BOILERPLATE(OmpDeclareTargetWithClause, OmpClauseList);
3528 CharBlock source;
3529 };
3530
3531 struct OmpDeclareTargetSpecifier {
3532 UNION_CLASS_BOILERPLATE(OmpDeclareTargetSpecifier);
3533 std::variant<OmpDeclareTargetWithList, OmpDeclareTargetWithClause> u;
3534 };
3535
3536 struct OpenMPDeclareTargetConstruct {
3537 TUPLE_CLASS_BOILERPLATE(OpenMPDeclareTargetConstruct);
3538 CharBlock source;
3539 std::tuple<Verbatim, OmpDeclareTargetSpecifier> t;
3540 };
3541
3542 // 2.16 declare-reduction -> DECLARE REDUCTION (reduction-identifier : type-list
3543 // : combiner) [initializer-clause]
3544 struct OmpReductionCombiner {
3545 UNION_CLASS_BOILERPLATE(OmpReductionCombiner);
3546 WRAPPER_CLASS(FunctionCombiner, Call);
3547 std::variant<AssignmentStmt, FunctionCombiner> u;
3548 };
3549
3550 WRAPPER_CLASS(OmpReductionInitializerClause, Expr);
3551
3552 struct OpenMPDeclareReductionConstruct {
3553 TUPLE_CLASS_BOILERPLATE(OpenMPDeclareReductionConstruct);
3554 CharBlock source;
3555 std::tuple<Verbatim, OmpReductionOperator, std::list<DeclarationTypeSpec>,
3556 OmpReductionCombiner, std::optional<OmpReductionInitializerClause>>
3557 t;
3558 };
3559
3560 // 2.8.2 declare-simd -> DECLARE SIMD [(proc-name)] [declare-simd-clause[ [,]
3561 // declare-simd-clause]...]
3562 struct OpenMPDeclareSimdConstruct {
3563 TUPLE_CLASS_BOILERPLATE(OpenMPDeclareSimdConstruct);
3564 CharBlock source;
3565 std::tuple<Verbatim, std::optional<Name>, OmpClauseList> t;
3566 };
3567
3568 // 2.15.2 threadprivate -> THREADPRIVATE (variable-name-list)
3569 struct OpenMPThreadprivate {
3570 TUPLE_CLASS_BOILERPLATE(OpenMPThreadprivate);
3571 CharBlock source;
3572 std::tuple<Verbatim, OmpObjectList> t;
3573 };
3574
3575 // 2.11.3 allocate -> ALLOCATE (variable-name-list) [clause]
3576 struct OpenMPDeclarativeAllocate {
3577 TUPLE_CLASS_BOILERPLATE(OpenMPDeclarativeAllocate);
3578 CharBlock source;
3579 std::tuple<Verbatim, OmpObjectList, OmpClauseList> t;
3580 };
3581
3582 struct OpenMPDeclarativeConstruct {
3583 UNION_CLASS_BOILERPLATE(OpenMPDeclarativeConstruct);
3584 CharBlock source;
3585 std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareReductionConstruct,
3586 OpenMPDeclareSimdConstruct, OpenMPDeclareTargetConstruct,
3587 OpenMPThreadprivate>
3588 u;
3589 };
3590
3591 // 2.13.2 CRITICAL [Name] <block> END CRITICAL [Name]
3592 struct OmpCriticalDirective {
3593 TUPLE_CLASS_BOILERPLATE(OmpCriticalDirective);
3594 CharBlock source;
3595 std::tuple<Verbatim, std::optional<Name>, std::optional<OmpClause>> t;
3596 };
3597 struct OmpEndCriticalDirective {
3598 TUPLE_CLASS_BOILERPLATE(OmpEndCriticalDirective);
3599 CharBlock source;
3600 std::tuple<Verbatim, std::optional<Name>> t;
3601 };
3602 struct OpenMPCriticalConstruct {
3603 TUPLE_CLASS_BOILERPLATE(OpenMPCriticalConstruct);
3604 std::tuple<OmpCriticalDirective, Block, OmpEndCriticalDirective> t;
3605 };
3606
3607 // 2.11.3 allocate -> ALLOCATE [(variable-name-list)] [clause]
3608 // [ALLOCATE (variable-name-list) [clause] [...]]
3609 // allocate-statement
3610 // clause -> allocator-clause
3611 struct OpenMPExecutableAllocate {
3612 TUPLE_CLASS_BOILERPLATE(OpenMPExecutableAllocate);
3613 CharBlock source;
3614 std::tuple<Verbatim, std::optional<OmpObjectList>, OmpClauseList,
3615 std::optional<std::list<OpenMPDeclarativeAllocate>>,
3616 Statement<AllocateStmt>>
3617 t;
3618 };
3619
3620 // 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0]
3621 // memory-order-clause -> acq_rel
3622 // release
3623 // acquire
3624 // seq_cst
3625 // relaxed
3626 struct OmpMemoryOrderClause {
3627 WRAPPER_CLASS_BOILERPLATE(OmpMemoryOrderClause, OmpClause);
3628 CharBlock source;
3629 };
3630
3631 // 2.17.7 Atomic construct
3632 // atomic-clause -> memory-order-clause | HINT(hint-expression)
3633 struct OmpAtomicClause {
3634 UNION_CLASS_BOILERPLATE(OmpAtomicClause);
3635 CharBlock source;
3636 std::variant<OmpMemoryOrderClause, OmpClause> u;
3637 };
3638
3639 // atomic-clause-list -> [atomic-clause, [atomic-clause], ...]
3640 struct OmpAtomicClauseList {
3641 WRAPPER_CLASS_BOILERPLATE(OmpAtomicClauseList, std::list<OmpAtomicClause>);
3642 CharBlock source;
3643 };
3644
3645 // END ATOMIC
3646 EMPTY_CLASS(OmpEndAtomic);
3647
3648 // ATOMIC READ
3649 struct OmpAtomicRead {
3650 TUPLE_CLASS_BOILERPLATE(OmpAtomicRead);
3651 CharBlock source;
3652 std::tuple<OmpAtomicClauseList, Verbatim, OmpAtomicClauseList,
3653 Statement<AssignmentStmt>, std::optional<OmpEndAtomic>>
3654 t;
3655 };
3656
3657 // ATOMIC WRITE
3658 struct OmpAtomicWrite {
3659 TUPLE_CLASS_BOILERPLATE(OmpAtomicWrite);
3660 CharBlock source;
3661 std::tuple<OmpAtomicClauseList, Verbatim, OmpAtomicClauseList,
3662 Statement<AssignmentStmt>, std::optional<OmpEndAtomic>>
3663 t;
3664 };
3665
3666 // ATOMIC UPDATE
3667 struct OmpAtomicUpdate {
3668 TUPLE_CLASS_BOILERPLATE(OmpAtomicUpdate);
3669 CharBlock source;
3670 std::tuple<OmpAtomicClauseList, Verbatim, OmpAtomicClauseList,
3671 Statement<AssignmentStmt>, std::optional<OmpEndAtomic>>
3672 t;
3673 };
3674
3675 // ATOMIC CAPTURE
3676 struct OmpAtomicCapture {
3677 TUPLE_CLASS_BOILERPLATE(OmpAtomicCapture);
3678 CharBlock source;
3679 WRAPPER_CLASS(Stmt1, Statement<AssignmentStmt>);
3680 WRAPPER_CLASS(Stmt2, Statement<AssignmentStmt>);
3681 std::tuple<OmpAtomicClauseList, Verbatim, OmpAtomicClauseList, Stmt1, Stmt2,
3682 OmpEndAtomic>
3683 t;
3684 };
3685
3686 // ATOMIC
3687 struct OmpAtomic {
3688 TUPLE_CLASS_BOILERPLATE(OmpAtomic);
3689 CharBlock source;
3690 std::tuple<Verbatim, OmpAtomicClauseList, Statement<AssignmentStmt>,
3691 std::optional<OmpEndAtomic>>
3692 t;
3693 };
3694
3695 // 2.17.7 atomic ->
3696 // ATOMIC [atomic-clause-list] atomic-construct [atomic-clause-list] |
3697 // ATOMIC [atomic-clause-list]
3698 // atomic-construct -> READ | WRITE | UPDATE | CAPTURE
3699 struct OpenMPAtomicConstruct {
3700 UNION_CLASS_BOILERPLATE(OpenMPAtomicConstruct);
3701 std::variant<OmpAtomicRead, OmpAtomicWrite, OmpAtomicCapture, OmpAtomicUpdate,
3702 OmpAtomic>
3703 u;
3704 };
3705
3706 // OpenMP directives that associate with loop(s)
3707 struct OmpLoopDirective {
3708 WRAPPER_CLASS_BOILERPLATE(OmpLoopDirective, llvm::omp::Directive);
3709 CharBlock source;
3710 };
3711
3712 // 2.14.1 construct-type-clause -> PARALLEL | SECTIONS | DO | TASKGROUP
3713 struct OmpCancelType {
3714 ENUM_CLASS(Type, Parallel, Sections, Do, Taskgroup)
3715 WRAPPER_CLASS_BOILERPLATE(OmpCancelType, Type);
3716 CharBlock source;
3717 };
3718
3719 // 2.14.2 cancellation-point -> CANCELLATION POINT construct-type-clause
3720 struct OpenMPCancellationPointConstruct {
3721 TUPLE_CLASS_BOILERPLATE(OpenMPCancellationPointConstruct);
3722 CharBlock source;
3723 std::tuple<Verbatim, OmpCancelType> t;
3724 };
3725
3726 // 2.14.1 cancel -> CANCEL construct-type-clause [ [,] if-clause]
3727 struct OpenMPCancelConstruct {
3728 TUPLE_CLASS_BOILERPLATE(OpenMPCancelConstruct);
3729 WRAPPER_CLASS(If, ScalarLogicalExpr);
3730 CharBlock source;
3731 std::tuple<Verbatim, OmpCancelType, std::optional<If>> t;
3732 };
3733
3734
3735 // 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
3736 struct OpenMPFlushConstruct {
3737 TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
3738 CharBlock source;
3739 std::tuple<Verbatim, std::optional<std::list<OmpMemoryOrderClause>>,
3740 std::optional<OmpObjectList>>
3741 t;
3742 };
3743
3744 struct OmpSimpleStandaloneDirective {
3745 WRAPPER_CLASS_BOILERPLATE(OmpSimpleStandaloneDirective, llvm::omp::Directive);
3746 CharBlock source;
3747 };
3748
3749 struct OpenMPSimpleStandaloneConstruct {
3750 TUPLE_CLASS_BOILERPLATE(OpenMPSimpleStandaloneConstruct);
3751 CharBlock source;
3752 std::tuple<OmpSimpleStandaloneDirective, OmpClauseList> t;
3753 };
3754
3755 struct OpenMPStandaloneConstruct {
3756 UNION_CLASS_BOILERPLATE(OpenMPStandaloneConstruct);
3757 CharBlock source;
3758 std::variant<OpenMPSimpleStandaloneConstruct, OpenMPFlushConstruct,
3759 OpenMPCancelConstruct, OpenMPCancellationPointConstruct>
3760 u;
3761 };
3762
3763 struct OmpBeginLoopDirective {
3764 TUPLE_CLASS_BOILERPLATE(OmpBeginLoopDirective);
3765 std::tuple<OmpLoopDirective, OmpClauseList> t;
3766 CharBlock source;
3767 };
3768
3769 struct OmpEndLoopDirective {
3770 TUPLE_CLASS_BOILERPLATE(OmpEndLoopDirective);
3771 std::tuple<OmpLoopDirective, OmpClauseList> t;
3772 CharBlock source;
3773 };
3774
3775 struct OmpBeginBlockDirective {
3776 TUPLE_CLASS_BOILERPLATE(OmpBeginBlockDirective);
3777 std::tuple<OmpBlockDirective, OmpClauseList> t;
3778 CharBlock source;
3779 };
3780
3781 struct OmpEndBlockDirective {
3782 TUPLE_CLASS_BOILERPLATE(OmpEndBlockDirective);
3783 std::tuple<OmpBlockDirective, OmpClauseList> t;
3784 CharBlock source;
3785 };
3786
3787 struct OpenMPBlockConstruct {
3788 TUPLE_CLASS_BOILERPLATE(OpenMPBlockConstruct);
3789 std::tuple<OmpBeginBlockDirective, Block, OmpEndBlockDirective> t;
3790 };
3791
3792 // OpenMP directives enclosing do loop
3793 struct OpenMPLoopConstruct {
3794 TUPLE_CLASS_BOILERPLATE(OpenMPLoopConstruct);
OpenMPLoopConstructOpenMPLoopConstruct3795 OpenMPLoopConstruct(OmpBeginLoopDirective &&a)
3796 : t({std::move(a), std::nullopt, std::nullopt}) {}
3797 std::tuple<OmpBeginLoopDirective, std::optional<DoConstruct>,
3798 std::optional<OmpEndLoopDirective>>
3799 t;
3800 };
3801
3802 struct OpenMPConstruct {
3803 UNION_CLASS_BOILERPLATE(OpenMPConstruct);
3804 std::variant<OpenMPStandaloneConstruct, OpenMPSectionsConstruct,
3805 OpenMPLoopConstruct, OpenMPBlockConstruct, OpenMPAtomicConstruct,
3806 OpenMPExecutableAllocate, OpenMPDeclarativeAllocate,
3807 OpenMPCriticalConstruct>
3808 u;
3809 };
3810
3811 // Parse tree nodes for OpenACC 3.1 directives and clauses
3812
3813 struct AccObject {
3814 UNION_CLASS_BOILERPLATE(AccObject);
3815 std::variant<Designator, /*common block*/ Name> u;
3816 };
3817
3818 WRAPPER_CLASS(AccObjectList, std::list<AccObject>);
3819
3820 // OpenACC directive beginning or ending a block
3821 struct AccBlockDirective {
3822 WRAPPER_CLASS_BOILERPLATE(AccBlockDirective, llvm::acc::Directive);
3823 CharBlock source;
3824 };
3825
3826 struct AccLoopDirective {
3827 WRAPPER_CLASS_BOILERPLATE(AccLoopDirective, llvm::acc::Directive);
3828 CharBlock source;
3829 };
3830
3831 struct AccStandaloneDirective {
3832 WRAPPER_CLASS_BOILERPLATE(AccStandaloneDirective, llvm::acc::Directive);
3833 CharBlock source;
3834 };
3835
3836 // 2.11 Combined constructs
3837 struct AccCombinedDirective {
3838 WRAPPER_CLASS_BOILERPLATE(AccCombinedDirective, llvm::acc::Directive);
3839 CharBlock source;
3840 };
3841
3842 struct AccDeclarativeDirective {
3843 WRAPPER_CLASS_BOILERPLATE(AccDeclarativeDirective, llvm::acc::Directive);
3844 CharBlock source;
3845 };
3846
3847 // OpenACC Clauses
3848 struct AccBindClause {
3849 UNION_CLASS_BOILERPLATE(AccBindClause);
3850 std::variant<Name, ScalarDefaultCharExpr> u;
3851 CharBlock source;
3852 };
3853
3854 struct AccDefaultClause {
3855 WRAPPER_CLASS_BOILERPLATE(AccDefaultClause, llvm::acc::DefaultValue);
3856 CharBlock source;
3857 };
3858
3859 struct AccDataModifier {
3860 ENUM_CLASS(Modifier, ReadOnly, Zero)
3861 WRAPPER_CLASS_BOILERPLATE(AccDataModifier, Modifier);
3862 CharBlock source;
3863 };
3864
3865 struct AccObjectListWithModifier {
3866 TUPLE_CLASS_BOILERPLATE(AccObjectListWithModifier);
3867 std::tuple<std::optional<AccDataModifier>, AccObjectList> t;
3868 };
3869
3870 // 2.5.13: + | * | max | min | iand | ior | ieor | .and. | .or. | .eqv. | .neqv.
3871 struct AccReductionOperator {
3872 ENUM_CLASS(
3873 Operator, Plus, Multiply, Max, Min, Iand, Ior, Ieor, And, Or, Eqv, Neqv)
3874 WRAPPER_CLASS_BOILERPLATE(AccReductionOperator, Operator);
3875 CharBlock source;
3876 };
3877
3878 struct AccObjectListWithReduction {
3879 TUPLE_CLASS_BOILERPLATE(AccObjectListWithReduction);
3880 std::tuple<AccReductionOperator, AccObjectList> t;
3881 };
3882
3883 struct AccWaitArgument {
3884 TUPLE_CLASS_BOILERPLATE(AccWaitArgument);
3885 std::tuple<std::optional<ScalarIntExpr>, std::list<ScalarIntExpr>> t;
3886 };
3887
3888 struct AccTileExpr {
3889 TUPLE_CLASS_BOILERPLATE(AccTileExpr);
3890 CharBlock source;
3891 std::tuple<std::optional<ScalarIntConstantExpr>> t; // if null then *
3892 };
3893
3894 struct AccTileExprList {
3895 WRAPPER_CLASS_BOILERPLATE(AccTileExprList, std::list<AccTileExpr>);
3896 };
3897
3898 struct AccSizeExpr {
3899 TUPLE_CLASS_BOILERPLATE(AccSizeExpr);
3900 CharBlock source;
3901 std::tuple<std::optional<ScalarIntExpr>> t; // if null then *
3902 };
3903
3904 struct AccSizeExprList {
3905 WRAPPER_CLASS_BOILERPLATE(AccSizeExprList, std::list<AccSizeExpr>);
3906 };
3907
3908 struct AccSelfClause {
3909 UNION_CLASS_BOILERPLATE(AccSelfClause);
3910 std::variant<std::optional<ScalarLogicalExpr>, AccObjectList> u;
3911 CharBlock source;
3912 };
3913
3914 struct AccGangArgument {
3915 TUPLE_CLASS_BOILERPLATE(AccGangArgument);
3916 std::tuple<std::optional<ScalarIntExpr>, std::optional<AccSizeExpr>> t;
3917 };
3918
3919 struct AccClause {
3920 UNION_CLASS_BOILERPLATE(AccClause);
3921
3922 #define GEN_FLANG_CLAUSE_PARSER_CLASSES
3923 #include "llvm/Frontend/OpenACC/ACC.inc"
3924
3925 CharBlock source;
3926
3927 std::variant<
3928 #define GEN_FLANG_CLAUSE_PARSER_CLASSES_LIST
3929 #include "llvm/Frontend/OpenACC/ACC.inc"
3930 >
3931 u;
3932 };
3933
3934 struct AccClauseList {
3935 WRAPPER_CLASS_BOILERPLATE(AccClauseList, std::list<AccClause>);
3936 CharBlock source;
3937 };
3938
3939 struct OpenACCRoutineConstruct {
3940 TUPLE_CLASS_BOILERPLATE(OpenACCRoutineConstruct);
3941 CharBlock source;
3942 std::tuple<Verbatim, std::optional<Name>, AccClauseList> t;
3943 };
3944
3945 struct OpenACCCacheConstruct {
3946 TUPLE_CLASS_BOILERPLATE(OpenACCCacheConstruct);
3947 CharBlock source;
3948 std::tuple<Verbatim, AccObjectListWithModifier> t;
3949 };
3950
3951 struct OpenACCWaitConstruct {
3952 TUPLE_CLASS_BOILERPLATE(OpenACCWaitConstruct);
3953 CharBlock source;
3954 std::tuple<Verbatim, std::optional<AccWaitArgument>, AccClauseList> t;
3955 };
3956
3957 struct AccBeginLoopDirective {
3958 TUPLE_CLASS_BOILERPLATE(AccBeginLoopDirective);
3959 std::tuple<AccLoopDirective, AccClauseList> t;
3960 CharBlock source;
3961 };
3962
3963 struct AccBeginBlockDirective {
3964 TUPLE_CLASS_BOILERPLATE(AccBeginBlockDirective);
3965 CharBlock source;
3966 std::tuple<AccBlockDirective, AccClauseList> t;
3967 };
3968
3969 struct AccEndBlockDirective {
3970 CharBlock source;
3971 WRAPPER_CLASS_BOILERPLATE(AccEndBlockDirective, AccBlockDirective);
3972 };
3973
3974 // ACC END ATOMIC
3975 EMPTY_CLASS(AccEndAtomic);
3976
3977 // ACC ATOMIC READ
3978 struct AccAtomicRead {
3979 TUPLE_CLASS_BOILERPLATE(AccAtomicRead);
3980 std::tuple<Verbatim, Statement<AssignmentStmt>, std::optional<AccEndAtomic>>
3981 t;
3982 };
3983
3984 // ACC ATOMIC WRITE
3985 struct AccAtomicWrite {
3986 TUPLE_CLASS_BOILERPLATE(AccAtomicWrite);
3987 std::tuple<Verbatim, Statement<AssignmentStmt>, std::optional<AccEndAtomic>>
3988 t;
3989 };
3990
3991 // ACC ATOMIC UPDATE
3992 struct AccAtomicUpdate {
3993 TUPLE_CLASS_BOILERPLATE(AccAtomicUpdate);
3994 std::tuple<std::optional<Verbatim>, Statement<AssignmentStmt>,
3995 std::optional<AccEndAtomic>>
3996 t;
3997 };
3998
3999 // ACC ATOMIC CAPTURE
4000 struct AccAtomicCapture {
4001 TUPLE_CLASS_BOILERPLATE(AccAtomicCapture);
4002 WRAPPER_CLASS(Stmt1, Statement<AssignmentStmt>);
4003 WRAPPER_CLASS(Stmt2, Statement<AssignmentStmt>);
4004 std::tuple<Verbatim, Stmt1, Stmt2, AccEndAtomic> t;
4005 };
4006
4007 struct OpenACCAtomicConstruct {
4008 UNION_CLASS_BOILERPLATE(OpenACCAtomicConstruct);
4009 std::variant<AccAtomicRead, AccAtomicWrite, AccAtomicCapture, AccAtomicUpdate>
4010 u;
4011 CharBlock source;
4012 };
4013
4014 struct OpenACCBlockConstruct {
4015 TUPLE_CLASS_BOILERPLATE(OpenACCBlockConstruct);
4016 std::tuple<AccBeginBlockDirective, Block, AccEndBlockDirective> t;
4017 };
4018
4019 struct OpenACCStandaloneDeclarativeConstruct {
4020 TUPLE_CLASS_BOILERPLATE(OpenACCStandaloneDeclarativeConstruct);
4021 CharBlock source;
4022 std::tuple<AccDeclarativeDirective, AccClauseList> t;
4023 };
4024
4025 struct AccBeginCombinedDirective {
4026 TUPLE_CLASS_BOILERPLATE(AccBeginCombinedDirective);
4027 CharBlock source;
4028 std::tuple<AccCombinedDirective, AccClauseList> t;
4029 };
4030
4031 struct AccEndCombinedDirective {
4032 WRAPPER_CLASS_BOILERPLATE(AccEndCombinedDirective, AccCombinedDirective);
4033 CharBlock source;
4034 };
4035
4036 struct OpenACCCombinedConstruct {
4037 TUPLE_CLASS_BOILERPLATE(OpenACCCombinedConstruct);
4038 CharBlock source;
OpenACCCombinedConstructOpenACCCombinedConstruct4039 OpenACCCombinedConstruct(AccBeginCombinedDirective &&a)
4040 : t({std::move(a), std::nullopt, std::nullopt}) {}
4041 std::tuple<AccBeginCombinedDirective, std::optional<DoConstruct>,
4042 std::optional<AccEndCombinedDirective>>
4043 t;
4044 };
4045
4046 struct OpenACCDeclarativeConstruct {
4047 UNION_CLASS_BOILERPLATE(OpenACCDeclarativeConstruct);
4048 CharBlock source;
4049 std::variant<OpenACCStandaloneDeclarativeConstruct, OpenACCRoutineConstruct>
4050 u;
4051 };
4052
4053 // OpenACC directives enclosing do loop
4054 struct OpenACCLoopConstruct {
4055 TUPLE_CLASS_BOILERPLATE(OpenACCLoopConstruct);
OpenACCLoopConstructOpenACCLoopConstruct4056 OpenACCLoopConstruct(AccBeginLoopDirective &&a)
4057 : t({std::move(a), std::nullopt}) {}
4058 std::tuple<AccBeginLoopDirective, std::optional<DoConstruct>> t;
4059 };
4060
4061 struct OpenACCStandaloneConstruct {
4062 TUPLE_CLASS_BOILERPLATE(OpenACCStandaloneConstruct);
4063 CharBlock source;
4064 std::tuple<AccStandaloneDirective, AccClauseList> t;
4065 };
4066
4067 struct OpenACCConstruct {
4068 UNION_CLASS_BOILERPLATE(OpenACCConstruct);
4069 std::variant<OpenACCBlockConstruct, OpenACCCombinedConstruct,
4070 OpenACCLoopConstruct, OpenACCStandaloneConstruct, OpenACCCacheConstruct,
4071 OpenACCWaitConstruct, OpenACCAtomicConstruct>
4072 u;
4073 };
4074
4075 } // namespace Fortran::parser
4076 #endif // FORTRAN_PARSER_PARSE_TREE_H_
4077