[flang] Address review comments (thanks!).
authorpeter klausler <pklausler@nvidia.com>
Tue, 3 Apr 2018 17:29:04 +0000 (10:29 -0700)
committerpeter klausler <pklausler@nvidia.com>
Tue, 3 Apr 2018 17:29:04 +0000 (10:29 -0700)
Original-commit: flang-compiler/f18@1e61fbaeae5402fcd0c732de244bfe02aadfe6ff
Reviewed-on: https://github.com/flang-compiler/f18/pull/38

flang/lib/parser/characters.h
flang/lib/parser/message.h
flang/lib/parser/unparse.cc

index 4725811..ed0da5c 100644 (file)
@@ -17,6 +17,9 @@ enum class Encoding { UTF8, EUC_JP };
 inline constexpr bool IsUpperCaseLetter(char ch) {
   if constexpr ('A' == static_cast<char>(0xc1)) {
     // EBCDIC
+    // TODO: Handle EBCDIC in a more generalized character set
+    // encoding framework; don't just assume that the native
+    // C++ character set is the same as that of the Fortran source.
     return (ch >= 'A' && ch <= 'I') || (ch >= 'J' && ch <= 'R') ||
         (ch >= 'S' && ch <= 'Z');
   } else {
index 9d166ec..d3804be 100644 (file)
@@ -42,6 +42,7 @@ private:
   bool isFatal_{false};
 };
 
+inline namespace literals {
 constexpr MessageFixedText operator""_en_US(const char str[], std::size_t n) {
   return MessageFixedText{str, n, false /* not fatal */};
 }
@@ -50,6 +51,7 @@ constexpr MessageFixedText operator""_err_en_US(
     const char str[], std::size_t n) {
   return MessageFixedText{str, n, true /* fatal */};
 }
+}  // namespace literals
 
 std::ostream &operator<<(std::ostream &, const MessageFixedText &);
 
index e9d01e7..595cb8c 100644 (file)
@@ -1717,8 +1717,7 @@ public:
     return true;
   }
   bool Pre(const EndProgramStmt &x) {  // R1403
-    Outdent(), Word("END PROGRAM"), Walk(" ", x.v);
-    EndSubprogram();
+    EndSubprogram("PROGRAM", x.v);
     return false;
   }
   bool Pre(const ModuleStmt &) {  // R1405
@@ -1726,7 +1725,7 @@ public:
     return true;
   }
   bool Pre(const EndModuleStmt &x) {  // R1406
-    Outdent(), Word("END MODULE"), Walk(" ", x.v);
+    EndSubprogram("MODULE", x.v);
     return false;
   }
   bool Pre(const UseStmt &x) {  // R1409
@@ -1755,7 +1754,7 @@ public:
     return false;
   }
   bool Pre(const EndSubmoduleStmt &x) {  // R1419
-    Outdent(), Word("END SUBMODULE"), Walk(" ", x.v);
+    EndSubprogram("SUBMODULE", x.v);
     return false;
   }
   bool Pre(const BlockDataStmt &x) {  // R1421
@@ -1763,7 +1762,7 @@ public:
     return false;
   }
   bool Pre(const EndBlockDataStmt &x) {  // R1422
-    Outdent(), Word("END BLOCK DATA"), Walk(" ", x.v);
+    EndSubprogram("BLOCK DATA", x.v);
     return false;
   }
 
@@ -1897,8 +1896,7 @@ public:
     return false;
   }
   bool Pre(const EndFunctionStmt &x) {  // R1533
-    Outdent(), Word("END FUNCTION"), Walk(" ", x.v);
-    EndSubprogram();
+    EndSubprogram("FUNCTION", x.v);
     return false;
   }
   bool Pre(const SubroutineStmt &x) {  // R1535
@@ -1916,8 +1914,7 @@ public:
     return false;
   }
   bool Pre(const EndSubroutineStmt &x) {  // R1537
-    Outdent(), Word("END SUBROUTINE"), Walk(" ", x.v);
-    EndSubprogram();
+    EndSubprogram("SUBROUTINE", x.v);
     return false;
   }
   bool Pre(const MpSubprogramStmt &) {  // R1539
@@ -1925,8 +1922,7 @@ public:
     return true;
   }
   bool Pre(const EndMpSubprogramStmt &x) {  // R1540
-    Outdent(), Word("END PROCEDURE"), Walk(" ", x.v);
-    EndSubprogram();
+    EndSubprogram("PROCEDURE", x.v);
     return false;
   }
   bool Pre(const EntryStmt &x) {  // R1541
@@ -2124,7 +2120,10 @@ private:
     WalkTupleElements(tuple, separator);
   }
 
-  void EndSubprogram() { structureComponents_.clear(); }
+  void EndSubprogram(const char *kind, const std::optional<Name> &name) {
+    Outdent(), Word("END "), Word(kind), Walk(" ", name);
+    structureComponents_.clear();
+  }
 
   std::ostream &out_;
   int indent_{0};