| 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; |
| 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. |
| 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<UnsignedLiteralConstant> unsignedLiteralConstant; |
| 63 | constexpr Parser<KindParam> kindParam; // R709 |
| 64 | constexpr Parser<RealLiteralConstant> realLiteralConstant; // R714 |
| 65 | constexpr Parser<CharLength> charLength; // R723 |
| 66 | constexpr Parser<CharLiteralConstant> charLiteralConstant; // R724 |
| 67 | constexpr Parser<CharLiteralConstantSubstring> charLiteralConstantSubstring; |
| 68 | constexpr Parser<Initialization> initialization; // R743 & R805 |
| 69 | constexpr Parser<DerivedTypeSpec> derivedTypeSpec; // R754 |
| 70 | constexpr Parser<TypeDeclarationStmt> typeDeclarationStmt; // R801 |
| 71 | constexpr Parser<NullInit> nullInit; // R806 |
| 72 | constexpr Parser<AccessSpec> accessSpec; // R807 |
| 73 | constexpr Parser<LanguageBindingSpec> languageBindingSpec; // R808, R1528 |
| 74 | constexpr Parser<EntityDecl> entityDecl; // R803 |
| 75 | constexpr Parser<CoarraySpec> coarraySpec; // R809 |
| 76 | constexpr Parser<ArraySpec> arraySpec; // R815 |
| 77 | constexpr Parser<ComponentArraySpec> componentArraySpec; |
| 78 | constexpr Parser<ExplicitShapeSpec> explicitShapeSpec; // R816 |
| 79 | constexpr Parser<DeferredShapeSpecList> deferredShapeSpecList; // R820 |
| 80 | constexpr Parser<AssumedImpliedSpec> assumedImpliedSpec; // R821 |
| 81 | constexpr Parser<IntentSpec> intentSpec; // R826 |
| 82 | constexpr Parser<DataStmt> dataStmt; // R837 |
| 83 | constexpr Parser<DataImpliedDo> dataImpliedDo; // R840 |
| 84 | constexpr Parser<ParameterStmt> parameterStmt; // R851 |
| 85 | constexpr Parser<OldParameterStmt> oldParameterStmt; |
| 86 | constexpr Parser<Designator> designator; // R901 |
| 87 | constexpr Parser<Variable> variable; // R902 |
| 88 | constexpr Parser<Substring> substring; // R908 |
| 89 | constexpr Parser<DataRef> dataRef; // R911, R914, R917 |
| 90 | constexpr Parser<StructureComponent> structureComponent; // R913 |
| 91 | constexpr Parser<SubscriptTriplet> subscriptTriplet; // R921 |
| 92 | constexpr Parser<AllocateStmt> allocateStmt; // R927 |
| 93 | constexpr Parser<StatVariable> statVariable; // R929 |
| 94 | constexpr Parser<StatOrErrmsg> statOrErrmsg; // R942 & R1165 |
| 95 | constexpr Parser<DefinedOpName> definedOpName; // R1003, R1023, R1414, & R1415 |
| 96 | constexpr Parser<Expr> expr; // R1022 |
| 97 | constexpr Parser<SpecificationExpr> specificationExpr; // R1028 |
| 98 | constexpr Parser<AssignmentStmt> assignmentStmt; // R1032 |
| 99 | constexpr Parser<PointerAssignmentStmt> pointerAssignmentStmt; // R1033 |
| 100 | constexpr Parser<WhereStmt> whereStmt; // R1041, R1045, R1046 |
| 101 | constexpr Parser<WhereConstruct> whereConstruct; // R1042 |
| 102 | constexpr Parser<WhereBodyConstruct> whereBodyConstruct; // R1044 |
| 103 | constexpr Parser<ForallConstruct> forallConstruct; // R1050 |
| 104 | constexpr Parser<ForallAssignmentStmt> forallAssignmentStmt; // R1053 |
| 105 | constexpr Parser<ForallStmt> forallStmt; // R1055 |
| 106 | constexpr Parser<Selector> selector; // R1105 |
| 107 | constexpr Parser<EndSelectStmt> endSelectStmt; // R1143 & R1151 & R1155 |
| 108 | constexpr Parser<ConcurrentHeader> ; // R1125 |
| 109 | constexpr Parser<IoUnit> ioUnit; // R1201, R1203 |
| 110 | constexpr Parser<FileUnitNumber> fileUnitNumber; // R1202 |
| 111 | constexpr Parser<IoControlSpec> ioControlSpec; // R1213, R1214 |
| 112 | constexpr Parser<Format> format; // R1215 |
| 113 | constexpr Parser<InputItem> inputItem; // R1216 |
| 114 | constexpr Parser<OutputItem> outputItem; // R1217 |
| 115 | constexpr Parser<InputImpliedDo> inputImpliedDo; // R1218, R1219 |
| 116 | constexpr Parser<OutputImpliedDo> outputImpliedDo; // R1218, R1219 |
| 117 | constexpr Parser<PositionOrFlushSpec> positionOrFlushSpec; // R1227 & R1229 |
| 118 | constexpr Parser<FormatStmt> formatStmt; // R1301 |
| 119 | constexpr Parser<InterfaceBlock> interfaceBlock; // R1501 |
| 120 | constexpr Parser<GenericSpec> genericSpec; // R1508 |
| 121 | constexpr Parser<ProcInterface> procInterface; // R1513 |
| 122 | constexpr Parser<ProcDecl> procDecl; // R1515 |
| 123 | constexpr Parser<FunctionReference> functionReference; // R1520 |
| 124 | constexpr Parser<ActualArgSpec> actualArgSpec; // R1523 |
| 125 | constexpr Parser<PrefixSpec> prefixSpec; // R1527 |
| 126 | constexpr Parser<FunctionSubprogram> functionSubprogram; // R1529 |
| 127 | constexpr Parser<FunctionStmt> functionStmt; // R1530 |
| 128 | constexpr Parser<Suffix> suffix; // R1532 |
| 129 | constexpr Parser<EndFunctionStmt> endFunctionStmt; // R1533 |
| 130 | constexpr Parser<SubroutineSubprogram> subroutineSubprogram; // R1534 |
| 131 | constexpr Parser<SubroutineStmt> subroutineStmt; // R1535 |
| 132 | constexpr Parser<DummyArg> dummyArg; // R1536 |
| 133 | constexpr Parser<EndSubroutineStmt> endSubroutineStmt; // R1537 |
| 134 | constexpr Parser<EntryStmt> entryStmt; // R1541 |
| 135 | constexpr Parser<ContainsStmt> containsStmt; // R1543 |
| 136 | constexpr Parser<CompilerDirective> compilerDirective; |
| 137 | constexpr Parser<OpenACCConstruct> openaccConstruct; |
| 138 | constexpr Parser<OpenACCDeclarativeConstruct> openaccDeclarativeConstruct; |
| 139 | constexpr Parser<OpenMPConstruct> openmpConstruct; |
| 140 | constexpr Parser<OpenMPDeclarativeConstruct> openmpDeclarativeConstruct; |
| 141 | constexpr Parser<OmpEndLoopDirective> ompEndLoopDirective; |
| 142 | constexpr Parser<IntrinsicVectorTypeSpec> intrinsicVectorTypeSpec; // Extension |
| 143 | constexpr Parser<VectorTypeSpec> vectorTypeSpec; // Extension |
| 144 | constexpr Parser<UnsignedTypeSpec> unsignedTypeSpec; // Extension |
| 145 | } // namespace Fortran::parser |
| 146 | #endif // FORTRAN_PARSER_TYPE_PARSERS_H_ |
| 147 | |