[flang] Get clean parse-unparse-reparse-unparse on f90_correct too.
authorpeter klausler <pklausler@nvidia.com>
Thu, 15 Mar 2018 17:59:46 +0000 (10:59 -0700)
committerpeter klausler <pklausler@nvidia.com>
Thu, 15 Mar 2018 17:59:46 +0000 (10:59 -0700)
Original-commit: flang-compiler/f18@901a9e462c13e801e589cacdc049d319ceb2dcca
Reviewed-on: https://github.com/flang-compiler/f18/pull/25
Tree-same-pre-rewrite: false

flang/documentation/f2018-grammar.txt
flang/lib/parser/grammar.h
flang/lib/parser/parse-tree.h
flang/lib/parser/unparse.cc

index 5d5a836..1ca684a 100644 (file)
@@ -114,7 +114,8 @@ R722 length-selector -> ( [LEN =] type-param-value ) | * char-length [,]
 R723 char-length -> ( type-param-value ) | digit-string
 R724 char-literal-constant ->
        [kind-param _] ' [rep-char]... ' | [kind-param _] " [rep-char]... "
-R725 logical-literal-constant -> .TRUE. | .FALSE.  @ | .T. | .F.
+R725 logical-literal-constant ->
+       .TRUE. [_ kind-param] | .FALSE. [_ kind-param] @ | .T. | .F.
 R726 derived-type-def ->
        derived-type-stmt [type-param-def-stmt]... [private-or-sequence]...
        [component-part] [type-bound-procedure-part] end-type-stmt
index fccf23b..3fd4f57 100644 (file)
@@ -862,13 +862,15 @@ constexpr auto rawHollerithLiteral = deprecated(HollerithLiteral{});
 TYPE_CONTEXT_PARSER("Hollerith"_en_US,
     construct<HollerithLiteralConstant>{}(rawHollerithLiteral))
 
-// R725 logical-literal-constant -> .TRUE. | .FALSE.
+// R725 logical-literal-constant ->
+//        .TRUE. [_ kind-param] | .FALSE. [_ kind-param]
 // Also accept .T. and .F. as extensions.
-TYPE_PARSER(".TRUE." >> construct<LogicalLiteralConstant>{}(pure(true)) ||
-    ".FALSE." >> construct<LogicalLiteralConstant>{}(pure(false)) ||
-    // PGI/Cray extensions
-    extension(".T."_tok >> construct<LogicalLiteralConstant>{}(pure(true))) ||
-    extension(".F."_tok >> construct<LogicalLiteralConstant>{}(pure(false))))
+TYPE_PARSER(construct<LogicalLiteralConstant>{}(
+                (".TRUE."_tok || extension(".T."_tok)) >> pure(true),
+                maybe(underscore >> kindParam)) ||
+    construct<LogicalLiteralConstant>{}(
+        (".FALSE."_tok || extension(".F."_tok)) >> pure(false),
+        maybe(underscore >> kindParam)))
 
 // R726 derived-type-def ->
 //        derived-type-stmt [type-param-def-stmt]...
index 3fd3147..a25557d 100644 (file)
@@ -754,8 +754,12 @@ struct HollerithLiteralConstant {
   std::string GetString() const { return v; }
 };
 
-// R725 logical-literal-constant -> .TRUE. | .FALSE.
-WRAPPER_CLASS(LogicalLiteralConstant, bool);
+// R725 logical-literal-constant ->
+//        .TRUE. [_ kind-param] | .FALSE. [_ kind-param]
+struct LogicalLiteralConstant {
+  TUPLE_CLASS_BOILERPLATE(LogicalLiteralConstant);
+  std::tuple<bool, std::optional<KindParam>> t;
+};
 
 // R764 boz-literal-constant -> binary-constant | octal-constant | hex-constant
 // R765 binary-constant -> B ' digit [digit]... ' | B " digit [digit]... "
index a5950b3..78c045c 100644 (file)
@@ -202,7 +202,8 @@ public:
     return true;
   }
   bool Pre(const LogicalLiteralConstant &x) {  // R725
-    Put(x.v ? ".TRUE." : ".FALSE.");
+    Put(std::get<bool>(x.t) ? ".TRUE." : ".FALSE.");
+    Walk("_", std::get<std::optional<KindParam>>(x.t));
     return false;
   }
   bool Pre(const DerivedTypeStmt &x) {  // R727
@@ -857,10 +858,6 @@ public:
     Word("%LOC("), Walk(x.v), Put(')');
     return false;
   }
-  bool Pre(const Expr::DefinedUnary &x) {
-    Put('.'), Walk(x.t, ". ");
-    return false;
-  }
   bool Pre(const Expr::Power &x) {
     Walk(x.t, "**");
     return false;