• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 namespace 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.
23 template <typename A> struct Parser {
24   using resultType = A;
ParserParser25   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.
42 constexpr Parser<Program> program; //  R501 - the "top level" production
43 constexpr Parser<SpecificationPart> specificationPart; //  R504
44 constexpr Parser<ImplicitPart> implicitPart; //  R505
45 constexpr Parser<DeclarationConstruct> declarationConstruct; //  R507
46 constexpr Parser<SpecificationConstruct> specificationConstruct; //  R508
47 constexpr Parser<ExecutionPart> executionPart; //  R509
48 constexpr Parser<ExecutionPartConstruct> executionPartConstruct; //  R510
49 constexpr Parser<InternalSubprogramPart> internalSubprogramPart; //  R511
50 constexpr Parser<ActionStmt> actionStmt; // R515
51 constexpr Parser<Name> name; // R603
52 constexpr Parser<LiteralConstant> literalConstant; // R605
53 constexpr Parser<NamedConstant> namedConstant; // R606
54 constexpr Parser<TypeParamValue> typeParamValue; // R701
55 constexpr Parser<TypeSpec> typeSpec; // R702
56 constexpr Parser<DeclarationTypeSpec> declarationTypeSpec; // R703
57 constexpr Parser<IntrinsicTypeSpec> intrinsicTypeSpec; // R704
58 constexpr Parser<IntegerTypeSpec> integerTypeSpec; // R705
59 constexpr Parser<KindSelector> kindSelector; // R706
60 constexpr Parser<SignedIntLiteralConstant> signedIntLiteralConstant; // R707
61 constexpr Parser<IntLiteralConstant> intLiteralConstant; // R708
62 constexpr Parser<KindParam> kindParam; // R709
63 constexpr Parser<RealLiteralConstant> realLiteralConstant; // R714
64 constexpr Parser<CharLength> charLength; // R723
65 constexpr Parser<CharLiteralConstant> charLiteralConstant; // R724
66 constexpr Parser<Initialization> initialization; // R743 & R805
67 constexpr Parser<DerivedTypeSpec> derivedTypeSpec; // R754
68 constexpr Parser<TypeDeclarationStmt> typeDeclarationStmt; // R801
69 constexpr Parser<NullInit> nullInit; // R806
70 constexpr Parser<AccessSpec> accessSpec; // R807
71 constexpr Parser<LanguageBindingSpec> languageBindingSpec; // R808, R1528
72 constexpr Parser<EntityDecl> entityDecl; // R803
73 constexpr Parser<CoarraySpec> coarraySpec; // R809
74 constexpr Parser<ArraySpec> arraySpec; // R815
75 constexpr Parser<ExplicitShapeSpec> explicitShapeSpec; // R816
76 constexpr Parser<DeferredShapeSpecList> deferredShapeSpecList; // R820
77 constexpr Parser<AssumedImpliedSpec> assumedImpliedSpec; // R821
78 constexpr Parser<IntentSpec> intentSpec; // R826
79 constexpr Parser<DataStmt> dataStmt; // R837
80 constexpr Parser<DataImpliedDo> dataImpliedDo; // R840
81 constexpr Parser<ParameterStmt> parameterStmt; // R851
82 constexpr Parser<OldParameterStmt> oldParameterStmt;
83 constexpr Parser<Designator> designator; // R901
84 constexpr Parser<Variable> variable; // R902
85 constexpr Parser<Substring> substring; // R908
86 constexpr Parser<DataRef> dataRef; // R911, R914, R917
87 constexpr Parser<StructureComponent> structureComponent; // R913
88 constexpr Parser<StatVariable> statVariable; // R929
89 constexpr Parser<StatOrErrmsg> statOrErrmsg; // R942 & R1165
90 constexpr Parser<DefinedOpName> definedOpName; // R1003, R1023, R1414, & R1415
91 constexpr Parser<Expr> expr; // R1022
92 constexpr Parser<SpecificationExpr> specificationExpr; // R1028
93 constexpr Parser<AssignmentStmt> assignmentStmt; // R1032
94 constexpr Parser<PointerAssignmentStmt> pointerAssignmentStmt; // R1033
95 constexpr Parser<WhereStmt> whereStmt; // R1041, R1045, R1046
96 constexpr Parser<WhereConstruct> whereConstruct; // R1042
97 constexpr Parser<WhereBodyConstruct> whereBodyConstruct; // R1044
98 constexpr Parser<ForallConstruct> forallConstruct; // R1050
99 constexpr Parser<ForallAssignmentStmt> forallAssignmentStmt; // R1053
100 constexpr Parser<ForallStmt> forallStmt; // R1055
101 constexpr Parser<Selector> selector; // R1105
102 constexpr Parser<EndSelectStmt> endSelectStmt; // R1143 & R1151 & R1155
103 constexpr Parser<LoopControl> loopControl; // R1123
104 constexpr Parser<ConcurrentHeader> concurrentHeader; // R1125
105 constexpr Parser<IoUnit> ioUnit; // R1201, R1203
106 constexpr Parser<FileUnitNumber> fileUnitNumber; // R1202
107 constexpr Parser<IoControlSpec> ioControlSpec; // R1213, R1214
108 constexpr Parser<Format> format; // R1215
109 constexpr Parser<InputItem> inputItem; // R1216
110 constexpr Parser<OutputItem> outputItem; // R1217
111 constexpr Parser<InputImpliedDo> inputImpliedDo; // R1218, R1219
112 constexpr Parser<OutputImpliedDo> outputImpliedDo; // R1218, R1219
113 constexpr Parser<PositionOrFlushSpec> positionOrFlushSpec; // R1227 & R1229
114 constexpr Parser<FormatStmt> formatStmt; // R1301
115 constexpr Parser<InterfaceBlock> interfaceBlock; // R1501
116 constexpr Parser<GenericSpec> genericSpec; // R1508
117 constexpr Parser<ProcInterface> procInterface; // R1513
118 constexpr Parser<ProcDecl> procDecl; // R1515
119 constexpr Parser<FunctionReference> functionReference; // R1520
120 constexpr Parser<ActualArgSpec> actualArgSpec; // R1523
121 constexpr Parser<PrefixSpec> prefixSpec; // R1527
122 constexpr Parser<FunctionSubprogram> functionSubprogram; // R1529
123 constexpr Parser<FunctionStmt> functionStmt; // R1530
124 constexpr Parser<Suffix> suffix; // R1532
125 constexpr Parser<EndFunctionStmt> endFunctionStmt; // R1533
126 constexpr Parser<SubroutineSubprogram> subroutineSubprogram; // R1534
127 constexpr Parser<SubroutineStmt> subroutineStmt; // R1535
128 constexpr Parser<DummyArg> dummyArg; // R1536
129 constexpr Parser<EndSubroutineStmt> endSubroutineStmt; // R1537
130 constexpr Parser<EntryStmt> entryStmt; // R1541
131 constexpr Parser<ContainsStmt> containsStmt; // R1543
132 constexpr Parser<CompilerDirective> compilerDirective;
133 constexpr Parser<OpenACCConstruct> openaccConstruct;
134 constexpr Parser<AccEndCombinedDirective> accEndCombinedDirective;
135 constexpr Parser<OpenACCDeclarativeConstruct> openaccDeclarativeConstruct;
136 constexpr Parser<OpenMPConstruct> openmpConstruct;
137 constexpr Parser<OpenMPDeclarativeConstruct> openmpDeclarativeConstruct;
138 constexpr Parser<OmpEndLoopDirective> ompEndLoopDirective;
139 } // namespace Fortran::parser
140 #endif // FORTRAN_PARSER_TYPE_PARSERS_H_
141