[flang] Complete merge of provenance feature.
authorpeter klausler <pklausler@nvidia.com>
Thu, 15 Feb 2018 23:26:10 +0000 (15:26 -0800)
committerGitHub <noreply@github.com>
Thu, 15 Feb 2018 23:58:44 +0000 (15:58 -0800)
Original-commit: flang-compiler/f18@646f68be61b1bf0f653cc332a51374df71f0ed0b
Reviewed-on: https://github.com/flang-compiler/f18/pull/9
Tree-same-pre-rewrite: false

flang/CMakeLists.txt
flang/tools/f18/test-type.cc

index 8dc9180..1f74767 100644 (file)
@@ -5,6 +5,7 @@ set(CMAKE_CXX_COMPILER "${GCC}/bin/g++")
 set(CMAKE_INSTALL_RPATH "${GCC}/lib64")
 set(CMAKE_BUILD_WITH_INSTALL_RPATH true)
 
+# project(f18)
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -std=c++17")
 set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DDEBUG")
 set(CMAKE_CXX_FLAGS_MINSIZEREL "-O2 '-DCHECK=(void)'")
@@ -32,9 +33,10 @@ set(SOURCES_TEST_TYPE
   lib/parser/idioms.cc
   lib/parser/message.cc
   lib/parser/parse-tree.cc
-  lib/parser/position.cc
   lib/parser/preprocessor.cc
   lib/parser/prescan.cc
+  lib/parser/provenance.cc
   lib/parser/source.cc
+  lib/parser/token-sequence.cc
 )
 add_executable(test-type ${SOURCES_TEST_TYPE})
index 3c07c63..c41047e 100644 (file)
@@ -12,7 +12,9 @@
 #include "../../lib/parser/message.h"
 #include "../../lib/parser/parse-state.h"
 #include "../../lib/parser/parse-tree.h"
-#include "../../lib/parser/position.h"
+#include "../../lib/parser/preprocessor.h"
+#include "../../lib/parser/prescan.h"
+#include "../../lib/parser/provenance.h"
 #include "../../lib/parser/source.h"
 #include "../../lib/parser/user-state.h"
 #include "../../lib/semantics/attr.h"
@@ -30,26 +32,31 @@ int main(int argc, char *const argv[]) {
   }
 
   std::string path{argv[1]};
-  Fortran::parser::SourceFile source;
+  AllSources allSources;
   std::stringstream error;
-  if (!source.Open(path, &error)) {
+  const auto *sourceFile = allSources.Open(path, &error);
+  if (!sourceFile) {
     std::cerr << error.str() << '\n';
-    return EXIT_FAILURE;
+    return 1;
   }
 
-  const char *sourceContent{source.content()};
-  size_t sourceBytes{source.bytes()};
-
-  Fortran::parser::ParseState state{sourceContent, sourceBytes};
-  state.PushContext("source file '"s + path + "'");
-  Fortran::parser::UserState ustate;
-  state.set_userState(&ustate);
-
-  std::optional<Program> result;
-  result = program.Parse(&state);
-  if (!result.has_value()) {
-    std::cerr << "parse FAILED " << state.position() << '\n'
-              << *state.messages();
+  ProvenanceRange range{allSources.AddIncludedFile(
+      *sourceFile, ProvenanceRange{})};
+  Messages messages{allSources};
+  CookedSource cooked{&allSources};
+  Preprocessor preprocessor{&allSources};
+  bool prescanOk{Prescanner{&messages, &cooked, &preprocessor}.Prescan(range)};
+  messages.Emit(std::cerr);
+  if (!prescanOk) {
+    return EXIT_FAILURE;
+  }
+  cooked.Marshal();
+  ParseState state{cooked};
+  UserState ustate;
+  std::optional<Program> result{program.Parse(&state)};
+  if (!result.has_value() || state.anyErrorRecovery()) {
+    std::cerr << "parse FAILED\n";
+    state.messages()->Emit(std::cerr);
     return EXIT_FAILURE;
   }
   for (const ProgramUnit &unit : result->v) {