1//===-- lib/Parser/type-parsers.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_TYPE_PARSERS_H_
10#define FORTRAN_PARSER_TYPE_PARSERS_H_
11
12#include "flang/Parser/instrumented-parser.h"
13#include "flang/Parser/parse-tree.h"
14#include <optional>
15
16namespace Fortran::parser {
17
18// Many parsers in the grammar are defined as instances of this Parser<>
19// class template, i.e. as the anonymous sole parser for a given type.
20// This usage requires that their Parse() member functions be defined
21// separately, typically with a parsing expression wrapped up in an
22// TYPE_PARSER() macro call.
23template <typename A> struct Parser {
24 using resultType = A;
25 constexpr Parser() {}
26 constexpr Parser(const Parser &) = default;
27 static std::optional<resultType> Parse(ParseState &);
28};
29
30#define CONTEXT_PARSER(contextText, pexpr) \
31 instrumented((contextText), inContext((contextText), (pexpr)))
32
33// To allow use of the Fortran grammar (or parts of it) outside the
34// context of constructing the actual parser.
35#define TYPE_PARSER(pexpr)
36#define TYPE_CONTEXT_PARSER(context, pexpr)
37
38// Some specializations of Parser<> are used multiple times, or are
39// of some special importance, so we instantiate them once here and
40// give them names rather than referencing them as anonymous Parser<T>{}
41// objects in the right-hand sides of productions.
42constexpr Parser<Program> program; // R501 - the "top level" production
43constexpr Parser<SpecificationPart> specificationPart; // R504
44constexpr Parser<ImplicitPart> implicitPart; // R505
45constexpr Parser<DeclarationConstruct> declarationConstruct; // R507
46constexpr Parser<SpecificationConstruct> specificationConstruct; // R508
47constexpr Parser<ExecutionPart> executionPart; // R509
48constexpr Parser<ExecutionPartConstruct> executionPartConstruct; // R510
49constexpr Parser<InternalSubprogramPart> internalSubprogramPart; // R511
50constexpr Parser<ActionStmt> actionStmt; // R515
51constexpr Parser<Name> name; // R603
52constexpr Parser<LiteralConstant> literalConstant; // R605
53constexpr Parser<NamedConstant> namedConstant; // R606
54constexpr Parser<TypeParamValue> typeParamValue; // R701
55constexpr Parser<TypeSpec> typeSpec; // R702
56constexpr Parser<DeclarationTypeSpec> declarationTypeSpec; // R703
57constexpr Parser<IntrinsicTypeSpec> intrinsicTypeSpec; // R704
58constexpr Parser<IntegerTypeSpec> integerTypeSpec; // R705
59constexpr Parser<KindSelector> kindSelector; // R706
60constexpr Parser<SignedIntLiteralConstant> signedIntLiteralConstant; // R707
61constexpr Parser<IntLiteralConstant> intLiteralConstant; // R708
62constexpr Parser<KindParam> kindParam; // R709
63constexpr Parser<RealLiteralConstant> realLiteralConstant; // R714
64constexpr Parser<CharLength> charLength; // R723
65constexpr Parser<CharLiteralConstant> charLiteralConstant; // R724
66constexpr Parser<Initialization> initialization; // R743 & R805
67constexpr Parser<DerivedTypeSpec> derivedTypeSpec; // R754
68constexpr Parser<TypeDeclarationStmt> typeDeclarationStmt; // R801
69constexpr Parser<NullInit> nullInit; // R806
70constexpr Parser<AccessSpec> accessSpec; // R807
71constexpr Parser<LanguageBindingSpec> languageBindingSpec; // R808, R1528
72constexpr Parser<EntityDecl> entityDecl; // R803
73constexpr Parser<CoarraySpec> coarraySpec; // R809
74constexpr Parser<ArraySpec> arraySpec; // R815
75constexpr Parser<ExplicitShapeSpec> explicitShapeSpec; // R816
76constexpr Parser<DeferredShapeSpecList> deferredShapeSpecList; // R820
77constexpr Parser<AssumedImpliedSpec> assumedImpliedSpec; // R821
78constexpr Parser<IntentSpec> intentSpec; // R826
79constexpr Parser<DataStmt> dataStmt; // R837
80constexpr Parser<DataImpliedDo> dataImpliedDo; // R840
81constexpr Parser<ParameterStmt> parameterStmt; // R851
82constexpr Parser<OldParameterStmt> oldParameterStmt;
83constexpr Parser<Designator> designator; // R901
84constexpr Parser<Variable> variable; // R902
85constexpr Parser<Substring> substring; // R908
86constexpr Parser<DataRef> dataRef; // R911, R914, R917
87constexpr Parser<StructureComponent> structureComponent; // R913
88constexpr Parser<AllocateStmt> allocateStmt; // R927
89constexpr Parser<StatVariable> statVariable; // R929
90constexpr Parser<StatOrErrmsg> statOrErrmsg; // R942 & R1165
91constexpr Parser<DefinedOpName> definedOpName; // R1003, R1023, R1414, & R1415
92constexpr Parser<Expr> expr; // R1022
93constexpr Parser<SpecificationExpr> specificationExpr; // R1028
94constexpr Parser<AssignmentStmt> assignmentStmt; // R1032
95constexpr Parser<PointerAssignmentStmt> pointerAssignmentStmt; // R1033
96constexpr Parser<WhereStmt> whereStmt; // R1041, R1045, R1046
97constexpr Parser<WhereConstruct> whereConstruct; // R1042
98constexpr Parser<WhereBodyConstruct> whereBodyConstruct; // R1044
99constexpr Parser<ForallConstruct> forallConstruct; // R1050
100constexpr Parser<ForallAssignmentStmt> forallAssignmentStmt; // R1053
101constexpr Parser<ForallStmt> forallStmt; // R1055
102constexpr Parser<Selector> selector; // R1105
103constexpr Parser<EndSelectStmt> endSelectStmt; // R1143 & R1151 & R1155
104constexpr Parser<LoopControl> loopControl; // R1123
105constexpr Parser<ConcurrentHeader> concurrentHeader; // R1125
106constexpr Parser<IoUnit> ioUnit; // R1201, R1203
107constexpr Parser<FileUnitNumber> fileUnitNumber; // R1202
108constexpr Parser<IoControlSpec> ioControlSpec; // R1213, R1214
109constexpr Parser<Format> format; // R1215
110constexpr Parser<InputItem> inputItem; // R1216
111constexpr Parser<OutputItem> outputItem; // R1217
112constexpr Parser<InputImpliedDo> inputImpliedDo; // R1218, R1219
113constexpr Parser<OutputImpliedDo> outputImpliedDo; // R1218, R1219
114constexpr Parser<PositionOrFlushSpec> positionOrFlushSpec; // R1227 & R1229
115constexpr Parser<FormatStmt> formatStmt; // R1301
116constexpr Parser<InterfaceBlock> interfaceBlock; // R1501
117constexpr Parser<GenericSpec> genericSpec; // R1508
118constexpr Parser<ProcInterface> procInterface; // R1513
119constexpr Parser<ProcDecl> procDecl; // R1515
120constexpr Parser<FunctionReference> functionReference; // R1520
121constexpr Parser<ActualArgSpec> actualArgSpec; // R1523
122constexpr Parser<PrefixSpec> prefixSpec; // R1527
123constexpr Parser<FunctionSubprogram> functionSubprogram; // R1529
124constexpr Parser<FunctionStmt> functionStmt; // R1530
125constexpr Parser<Suffix> suffix; // R1532
126constexpr Parser<EndFunctionStmt> endFunctionStmt; // R1533
127constexpr Parser<SubroutineSubprogram> subroutineSubprogram; // R1534
128constexpr Parser<SubroutineStmt> subroutineStmt; // R1535
129constexpr Parser<DummyArg> dummyArg; // R1536
130constexpr Parser<EndSubroutineStmt> endSubroutineStmt; // R1537
131constexpr Parser<EntryStmt> entryStmt; // R1541
132constexpr Parser<ContainsStmt> containsStmt; // R1543
133constexpr Parser<CompilerDirective> compilerDirective;
134constexpr Parser<OpenACCConstruct> openaccConstruct;
135constexpr Parser<OpenACCDeclarativeConstruct> openaccDeclarativeConstruct;
136constexpr Parser<OpenMPConstruct> openmpConstruct;
137constexpr Parser<OpenMPDeclarativeConstruct> openmpDeclarativeConstruct;
138constexpr Parser<OmpEndLoopDirective> ompEndLoopDirective;
139constexpr Parser<IntrinsicVectorTypeSpec> intrinsicVectorTypeSpec; // Extension
140constexpr Parser<VectorTypeSpec> vectorTypeSpec; // Extension
141constexpr Parser<UnsignedTypeSpec> unsignedTypeSpec; // Extension
142} // namespace Fortran::parser
143#endif // FORTRAN_PARSER_TYPE_PARSERS_H_
144

source code of flang/lib/Parser/type-parsers.h