[flang] Remove a temporary #include <iostream> and auto-detect -Mfixed from a .f...
authorpeter klausler <pklausler@nvidia.com>
Fri, 16 Feb 2018 01:12:50 +0000 (17:12 -0800)
committerpeter klausler <pklausler@nvidia.com>
Fri, 16 Feb 2018 01:12:50 +0000 (17:12 -0800)
Original-commit: flang-compiler/f18@962c7ed0ef01a9904e7ccf0d2850b38d0c6bb46e
Reviewed-on: https://github.com/flang-compiler/f18/pull/10

flang/lib/parser/preprocessor.cc
flang/tools/f18/f18.cc

index aa3486b..6074daa 100644 (file)
@@ -10,7 +10,6 @@
 #include <set>
 #include <sstream>
 #include <utility>
-#include <iostream>  // TODO pmk rm
 
 namespace Fortran {
 namespace parser {
index d7c27fd..1d7dc07 100644 (file)
@@ -50,7 +50,7 @@ int main(int argc, char *const argv[]) {
   args.pop_front();
 
   bool dumpCookedChars{false}, dumpProvenance{false};
-  bool fixedForm{false};
+  bool fixedForm{false}, freeForm{false};
   bool backslashEscapes{true};
   bool standard{false};
   bool enableOldDebugLines{false};
@@ -71,6 +71,8 @@ int main(int argc, char *const argv[]) {
       args.pop_front();
       if (flag == "-Mfixed") {
         fixedForm = true;
+      } else if (flag == "-Mfree") {
+        freeForm = true;
       } else if (flag == "-Mbackslash") {
         backslashEscapes = false;
       } else if (flag == "-Mstandard") {
@@ -90,7 +92,7 @@ int main(int argc, char *const argv[]) {
         allSources.PushSearchPathDirectory(flag.substr(2, std::string::npos));
       } else {
         std::cerr << "unknown flag: '" << flag << "'\n";
-        return 1;
+        return EXIT_FAILURE;
       }
     }
   }
@@ -101,8 +103,7 @@ int main(int argc, char *const argv[]) {
     args.pop_front();
     if (!args.empty()) {
       std::cerr << "multiple input files\n";
-      ;
-      return 1;
+      return EXIT_FAILURE;
     }
   }
 
@@ -110,7 +111,17 @@ int main(int argc, char *const argv[]) {
   const auto *sourceFile = allSources.Open(path, &error);
   if (!sourceFile) {
     std::cerr << error.str() << '\n';
-    return 1;
+    return EXIT_FAILURE;
+  }
+
+  if (!freeForm) {
+    auto dot = path.rfind(".");
+    if (dot != std::string::npos) {
+      std::string suffix{path.substr(dot + 1, std::string::npos)};
+      if (suffix == "f" || suffix == "F") {
+        fixedForm = true;
+      }
+    }
   }
 
   Fortran::parser::ProvenanceRange range{allSources.AddIncludedFile(