[flang] Begin moving UserState action parsers into user-state.{h,cc}.
authorpeter klausler <pklausler@nvidia.com>
Fri, 20 Apr 2018 21:27:49 +0000 (14:27 -0700)
committerpeter klausler <pklausler@nvidia.com>
Mon, 23 Apr 2018 22:44:25 +0000 (15:44 -0700)
Original-commit: flang-compiler/f18@5c31402146bf24873b37fdb4fa83dbe6256f30c3
Reviewed-on: https://github.com/flang-compiler/f18/pull/66
Tree-same-pre-rewrite: false

flang/lib/parser/CMakeLists.txt
flang/lib/parser/basic-parsers.h
flang/lib/parser/grammar.h
flang/lib/parser/user-state.h

index c92712c..e2f33f2 100644 (file)
@@ -13,4 +13,5 @@ add_library(FortranParser
   source.cc
   token-sequence.cc
   unparse.cc
+  user-state.cc
 )
index 2bcb541..4719908 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "char-block.h"
 #include "idioms.h"
+#include "indirection.h"
 #include "message.h"
 #include "parse-state.h"
 #include "provenance.h"
index c9f36bb..217664e 100644 (file)
@@ -259,16 +259,7 @@ constexpr auto scalarIntConstantExpr = scalar(intConstantExpr);
 
 // R501 program -> program-unit [program-unit]...
 // This is the top-level production for the Fortran language.
-struct StartNewSubprogram {
-  using resultType = Success;
-  static std::optional<Success> Parse(ParseState &state) {
-    if (auto ustate = state.userState()) {
-      ustate->NewSubprogram();
-    }
-    return {Success{}};
-  }
-} startNewSubprogram;
-
+constexpr StartNewSubprogram startNewSubprogram;
 TYPE_PARSER(
     construct<Program>{}(
         // statements consume only trailing noise; consume leading noise here.
index a8c4222..1574225 100644 (file)
@@ -6,8 +6,10 @@
 // parse tree construction so as to avoid any need for representing
 // state in static data.
 
+#include "basic-parsers.h"
 #include "char-block.h"
 #include <cinttypes>
+#include <optional>
 #include <set>
 #include <unordered_set>
 
@@ -16,6 +18,7 @@ namespace parser {
 
 class CookedSource;
 class ParsingLog;
+class ParseState;
 
 class UserState {
 public:
@@ -75,6 +78,11 @@ private:
 
   std::set<CharBlock> oldStructureComponents_;
 };
+
+struct StartNewSubprogram {
+  using resultType = Success;
+  static std::optional<Success> Parse(ParseState &);
+};
 }  // namespace parser
 }  // namespace Fortran
 #endif  // FORTRAN_PARSER_USER_STATE_H_