From d2306759fc23366b2f018ce38454259c8f73e49d Mon Sep 17 00:00:00 2001 From: peter klausler Date: Fri, 20 Apr 2018 15:47:40 -0700 Subject: [PATCH] [flang] Finish moving user state action parsers into user-state.{h,cc}. Original-commit: flang-compiler/f18@79c8a4cefe566bd64692acc8bc13e0a25c4f6be4 Reviewed-on: https://github.com/flang-compiler/f18/pull/66 Tree-same-pre-rewrite: false --- flang/lib/parser/grammar.h | 64 ++++-------------------------------------- flang/lib/parser/user-state.cc | 38 +++++++++++++++++++++++++ flang/lib/parser/user-state.h | 19 +++++++++++++ 3 files changed, 63 insertions(+), 58 deletions(-) diff --git a/flang/lib/parser/grammar.h b/flang/lib/parser/grammar.h index 6d0be78..2829f67 100644 --- a/flang/lib/parser/grammar.h +++ b/flang/lib/parser/grammar.h @@ -327,8 +327,6 @@ TYPE_PARSER(construct{}(indirect(Parser{})) || // END DO statements appear only at the ends of do-constructs that begin // with a nonlabel-do-stmt, so care must be taken to recognize this case and // essentially treat them like CONTINUE statements. -constexpr CapturedLabelDoStmt capturedLabelDoStmt; -constexpr EndDoStmtForCapturedLabelDoStmt endDoStmtForCapturedLabelDoStmt; // R514 executable-construct -> // action-stmt | associate-construct | block-construct | @@ -342,8 +340,8 @@ constexpr auto executableConstruct = construct{}(indirect(Parser{})) || construct{}(indirect(Parser{})) || construct{}(indirect(Parser{})) || - construct{}(capturedLabelDoStmt) || - construct{}(endDoStmtForCapturedLabelDoStmt) || + construct{}(CapturedLabelDoStmt{}) || + construct{}(EndDoStmtForCapturedLabelDoStmt{}) || construct{}(indirect(Parser{})) || construct{}(indirect(Parser{})) || construct{}(indirect(Parser{})) || @@ -1313,23 +1311,9 @@ TYPE_PARSER(construct{}(name, maybe(arraySpec))) TYPE_CONTEXT_PARSER("designator"_en_US, construct{}(substring) || construct{}(dataRef)) -constexpr struct OldStructureComponentName { - using resultType = Name; - static inline std::optional Parse(ParseState &state) { - if (std::optional n{name.Parse(state)}) { - if (const auto *user = state.userState()) { - if (user->IsOldStructureComponent(n->source)) { - return n; - } - } - } - return {}; - } -} oldStructureComponentName; - constexpr auto percentOrDot = "%"_tok || // legacy VAX extension for RECORD field access - extension("."_tok / lookAhead(oldStructureComponentName)); + extension("."_tok / lookAhead(OldStructureComponentName{})); // R902 variable -> designator | function-reference // This production appears to be left-recursive in the grammar via @@ -2035,30 +2019,10 @@ TYPE_PARSER("END CRITICAL" >> construct{}(maybe(name))) // R1119 do-construct -> do-stmt block end-do // R1120 do-stmt -> nonlabel-do-stmt | label-do-stmt -constexpr struct EnterNonlabelDoConstruct { - using resultType = Success; - static inline std::optional Parse(ParseState &state) { - if (auto ustate = state.userState()) { - ustate->EnterNonlabelDoConstruct(); - } - return {Success{}}; - } -} enterNonlabelDoConstruct; - -constexpr struct LeaveDoConstruct { - using resultType = Success; - static inline std::optional Parse(ParseState &state) { - if (auto ustate = state.userState()) { - ustate->LeaveDoConstruct(); - } - return {Success{}}; - } -} leaveDoConstruct; - TYPE_CONTEXT_PARSER("DO construct"_en_US, construct{}( - statement(Parser{}) / enterNonlabelDoConstruct, block, - statement(endDoStmt) / leaveDoConstruct)) + statement(Parser{}) / EnterNonlabelDoConstruct{}, block, + statement(endDoStmt) / LeaveDoConstruct{})) // R1125 concurrent-header -> // ( [integer-type-spec ::] concurrent-control-list @@ -3342,23 +3306,7 @@ TYPE_PARSER(construct{}("STRUCTURE /" >> name / "/", pure(true), construct{}( "STRUCTURE" >> name, pure(false), defaulted(cut >> many(entityDecl)))) -constexpr struct StructureComponents { - using resultType = DataComponentDefStmt; - static inline std::optional Parse(ParseState &state) { - static constexpr auto stmt = Parser{}; - std::optional defs{stmt.Parse(state)}; - if (defs.has_value()) { - if (auto ustate = state.userState()) { - for (const auto &decl : std::get>(defs->t)) { - ustate->NoteOldStructureComponent(std::get(decl.t).source); - } - } - } - return defs; - } -} structureComponents; - -TYPE_PARSER(construct{}(statement(structureComponents)) || +TYPE_PARSER(construct{}(statement(StructureComponents{})) || construct{}(indirect(Parser{})) || construct{}(indirect(Parser{}))) diff --git a/flang/lib/parser/user-state.cc b/flang/lib/parser/user-state.cc index 236ff4c..332583a 100644 --- a/flang/lib/parser/user-state.cc +++ b/flang/lib/parser/user-state.cc @@ -44,5 +44,43 @@ EndDoStmtForCapturedLabelDoStmt::Parse(ParseState &state) { return {}; } +std::optional EnterNonlabelDoConstruct::Parse(ParseState &state) { + if (auto ustate = state.userState()) { + ustate->EnterNonlabelDoConstruct(); + } + return {Success{}}; +} + +std::optional LeaveDoConstruct::Parse(ParseState &state) { + if (auto ustate = state.userState()) { + ustate->LeaveDoConstruct(); + } + return {Success{}}; +} + +std::optional OldStructureComponentName::Parse(ParseState &state) { + if (std::optional n{name.Parse(state)}) { + if (const auto *ustate = state.userState()) { + if (ustate->IsOldStructureComponent(n->source)) { + return n; + } + } + } + return {}; +} + +std::optional StructureComponents::Parse( + ParseState &state) { + static constexpr auto stmt = Parser{}; + std::optional defs{stmt.Parse(state)}; + if (defs.has_value()) { + if (auto ustate = state.userState()) { + for (const auto &decl : std::get>(defs->t)) { + ustate->NoteOldStructureComponent(std::get(decl.t).source); + } + } + } + return defs; +} } // namespace parser } // namespace Fortran diff --git a/flang/lib/parser/user-state.h b/flang/lib/parser/user-state.h index aa7a8f9..00a4e27 100644 --- a/flang/lib/parser/user-state.h +++ b/flang/lib/parser/user-state.h @@ -96,6 +96,25 @@ struct EndDoStmtForCapturedLabelDoStmt { static std::optional Parse(ParseState &); }; +struct EnterNonlabelDoConstruct { + using resultType = Success; + static std::optional Parse(ParseState &); +}; + +struct LeaveDoConstruct { + using resultType = Success; + static std::optional Parse(ParseState &); +}; + +struct OldStructureComponentName { + using resultType = Name; + static std::optional Parse(ParseState &); +}; + +struct StructureComponents { + using resultType = DataComponentDefStmt; + static std::optional Parse(ParseState &); +}; } // namespace parser } // namespace Fortran #endif // FORTRAN_PARSER_USER_STATE_H_ -- 2.7.4