149 lines · c
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-exception6//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 defined21// separately, typically with a parsing expression wrapped up in an22// 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 the34// 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 are39// of some special importance, so we instantiate them once here and40// 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" production43constexpr Parser<SpecificationPart> specificationPart; // R50444constexpr Parser<ImplicitPart> implicitPart; // R50545constexpr Parser<DeclarationConstruct> declarationConstruct; // R50746constexpr Parser<SpecificationConstruct> specificationConstruct; // R50847constexpr Parser<ExecutionPart> executionPart; // R50948constexpr Parser<ExecutionPartConstruct> executionPartConstruct; // R51049constexpr Parser<InternalSubprogramPart> internalSubprogramPart; // R51150constexpr Parser<ActionStmt> actionStmt; // R51551constexpr Parser<Name> name; // R60352constexpr Parser<LiteralConstant> literalConstant; // R60553constexpr Parser<NamedConstant> namedConstant; // R60654constexpr Parser<TypeParamValue> typeParamValue; // R70155constexpr Parser<TypeSpec> typeSpec; // R70256constexpr Parser<DeclarationTypeSpec> declarationTypeSpec; // R70357constexpr Parser<IntrinsicTypeSpec> intrinsicTypeSpec; // R70458constexpr Parser<IntegerTypeSpec> integerTypeSpec; // R70559constexpr Parser<KindSelector> kindSelector; // R70660constexpr Parser<SignedIntLiteralConstant> signedIntLiteralConstant; // R70761constexpr Parser<IntLiteralConstant> intLiteralConstant; // R70862constexpr Parser<UnsignedLiteralConstant> unsignedLiteralConstant;63constexpr Parser<KindParam> kindParam; // R70964constexpr Parser<RealLiteralConstant> realLiteralConstant; // R71465constexpr Parser<CharLength> charLength; // R72366constexpr Parser<CharLiteralConstant> charLiteralConstant; // R72467constexpr Parser<CharLiteralConstantSubstring> charLiteralConstantSubstring;68constexpr Parser<Initialization> initialization; // R743 & R80569constexpr Parser<DerivedTypeSpec> derivedTypeSpec; // R75470constexpr Parser<TypeDeclarationStmt> typeDeclarationStmt; // R80171constexpr Parser<NullInit> nullInit; // R80672constexpr Parser<AccessSpec> accessSpec; // R80773constexpr Parser<LanguageBindingSpec> languageBindingSpec; // R808, R152874constexpr Parser<EntityDecl> entityDecl; // R80375constexpr Parser<CoarraySpec> coarraySpec; // R80976constexpr Parser<ArraySpec> arraySpec; // R81577constexpr Parser<ComponentArraySpec> componentArraySpec;78constexpr Parser<ExplicitShapeSpec> explicitShapeSpec; // R81679constexpr Parser<DeferredShapeSpecList> deferredShapeSpecList; // R82080constexpr Parser<AssumedImpliedSpec> assumedImpliedSpec; // R82181constexpr Parser<IntentSpec> intentSpec; // R82682constexpr Parser<DataStmt> dataStmt; // R83783constexpr Parser<DataImpliedDo> dataImpliedDo; // R84084constexpr Parser<ParameterStmt> parameterStmt; // R85185constexpr Parser<OldParameterStmt> oldParameterStmt;86constexpr Parser<Designator> designator; // R90187constexpr Parser<Variable> variable; // R90288constexpr Parser<Substring> substring; // R90889constexpr Parser<DataRef> dataRef; // R911, R914, R91790constexpr Parser<StructureComponent> structureComponent; // R91391constexpr Parser<SubscriptTriplet> subscriptTriplet; // R92192constexpr Parser<AllocateStmt> allocateStmt; // R92793constexpr Parser<StatVariable> statVariable; // R92994constexpr Parser<StatOrErrmsg> statOrErrmsg; // R942 & R116595constexpr Parser<DefinedOpName> definedOpName; // R1003, R1023, R1414, & R141596constexpr Parser<Expr> expr; // R102297constexpr Parser<SpecificationExpr> specificationExpr; // R102898constexpr Parser<AssignmentStmt> assignmentStmt; // R103299constexpr Parser<PointerAssignmentStmt> pointerAssignmentStmt; // R1033100constexpr Parser<WhereStmt> whereStmt; // R1041, R1045, R1046101constexpr Parser<WhereConstruct> whereConstruct; // R1042102constexpr Parser<WhereBodyConstruct> whereBodyConstruct; // R1044103constexpr Parser<ForallConstruct> forallConstruct; // R1050104constexpr Parser<ForallAssignmentStmt> forallAssignmentStmt; // R1053105constexpr Parser<ForallStmt> forallStmt; // R1055106constexpr Parser<Selector> selector; // R1105107constexpr Parser<EndSelectStmt> endSelectStmt; // R1143 & R1151 & R1155108constexpr Parser<ConcurrentHeader> concurrentHeader; // R1125109constexpr Parser<IoUnit> ioUnit; // R1201, R1203110constexpr Parser<FileUnitNumber> fileUnitNumber; // R1202111constexpr Parser<IoControlSpec> ioControlSpec; // R1213, R1214112constexpr Parser<Format> format; // R1215113constexpr Parser<InputItem> inputItem; // R1216114constexpr Parser<OutputItem> outputItem; // R1217115constexpr Parser<InputImpliedDo> inputImpliedDo; // R1218, R1219116constexpr Parser<OutputImpliedDo> outputImpliedDo; // R1218, R1219117constexpr Parser<PositionOrFlushSpec> positionOrFlushSpec; // R1227 & R1229118constexpr Parser<FormatStmt> formatStmt; // R1301119constexpr Parser<InterfaceBlock> interfaceBlock; // R1501120constexpr Parser<GenericSpec> genericSpec; // R1508121constexpr Parser<ProcInterface> procInterface; // R1513122constexpr Parser<ProcDecl> procDecl; // R1515123constexpr Parser<FunctionReference> functionReference; // R1520124constexpr Parser<ActualArgSpec> actualArgSpec; // R1523125constexpr Parser<PrefixSpec> prefixSpec; // R1527126constexpr Parser<FunctionSubprogram> functionSubprogram; // R1529127constexpr Parser<FunctionStmt> functionStmt; // R1530128constexpr Parser<Suffix> suffix; // R1532129constexpr Parser<EndFunctionStmt> endFunctionStmt; // R1533130constexpr Parser<SubroutineSubprogram> subroutineSubprogram; // R1534131constexpr Parser<SubroutineStmt> subroutineStmt; // R1535132constexpr Parser<DummyArg> dummyArg; // R1536133constexpr Parser<EndSubroutineStmt> endSubroutineStmt; // R1537134constexpr Parser<EntryStmt> entryStmt; // R1541135constexpr Parser<ContainsStmt> containsStmt; // R1543136constexpr Parser<CompilerDirective> compilerDirective;137constexpr Parser<OpenACCConstruct> openaccConstruct;138constexpr Parser<OpenACCDeclarativeConstruct> openaccDeclarativeConstruct;139constexpr Parser<OpenMPConstruct> openmpConstruct;140constexpr Parser<OpenMPExecDirective> openmpExecDirective;141constexpr Parser<OpenMPDeclarativeConstruct> openmpDeclarativeConstruct;142constexpr Parser<OpenMPMisplacedEndDirective> openmpMisplacedEndDirective;143constexpr Parser<OpenMPInvalidDirective> openmpInvalidDirective;144constexpr Parser<IntrinsicVectorTypeSpec> intrinsicVectorTypeSpec; // Extension145constexpr Parser<VectorTypeSpec> vectorTypeSpec; // Extension146constexpr Parser<UnsignedTypeSpec> unsignedTypeSpec; // Extension147} // namespace Fortran::parser148#endif // FORTRAN_PARSER_TYPE_PARSERS_H_149