[flang] review comments
authorpeter klausler <pklausler@nvidia.com>
Wed, 14 Nov 2018 22:35:10 +0000 (14:35 -0800)
committerpeter klausler <pklausler@nvidia.com>
Wed, 14 Nov 2018 22:35:10 +0000 (14:35 -0800)
Original-commit: flang-compiler/f18@32c02cb668f17e31061c3f52c834e4029e410381
Reviewed-on: https://github.com/flang-compiler/f18/pull/225

flang/documentation/C++style.md
flang/lib/evaluate/complex.cc
flang/lib/evaluate/complex.h
flang/lib/evaluate/expression.cc
flang/lib/evaluate/real.cc

index 768f44b..b6fbf9c 100644 (file)
@@ -200,15 +200,15 @@ of that standard feature is prohibitive.
 
 A feature matrix:
 
-| pointer | nullable | default null | owning | reassignable | copyable | undefined type ok? |
-| ------- | -------- | ------------ | ------ | ------------ | -------- | ------------------ |
-| `*p` | yes | no | no | yes | shallowly | yes |
-| `&r` | no | n/a | no | no | shallowly | yes |
-| `unique_ptr<>` | yes | yes | yes | yes | no | no |
-| `shared_ptr<>` | yes | yes | yes | yes | shallowly | no |
-| `OwningPointer<>` | yes | yes | yes | yes | no | yes |
-| `Indirection<>` | no | n/a | yes | yes | optionally deeply | no |
-| `CountedReference<>` | yes | yes | yes | yes | shallowly | no |
+| pointer              | nullable | default null | owning | reassignable | copyable          | undefined type ok? |
+| -------              | -------- | ------------ | ------ | ------------ | --------          | ------------------ |
+| `*p`                 | yes      | no           | no     | yes          | shallowly         | yes                |
+| `&r`                 | no       | n/a          | no     | no           | shallowly         | yes                |
+| `unique_ptr<>`       | yes      | yes          | yes    | yes          | no                | no                 |
+| `shared_ptr<>`       | yes      | yes          | yes    | yes          | shallowly         | no                 |
+| `OwningPointer<>`    | yes      | yes          | yes    | yes          | no                | yes                |
+| `Indirection<>`      | no       | n/a          | yes    | yes          | optionally deeply | no                 |
+| `CountedReference<>` | yes      | yes          | yes    | yes          | shallowly         | no                 |
 
 ### Overall design preferences
 Don't use dynamic solutions to solve problems that can be solved at
index 1665519..6883cf5 100644 (file)
@@ -95,6 +95,12 @@ template<typename R> std::string Complex<R>::DumpHexadecimal() const {
   return result;
 }
 
+template<typename R> std::ostream &Complex<R>::AsFortran(std::ostream &o, int kind) const {
+  re_.AsFortran(o << '(', kind);
+  im_.AsFortran(o << ',', kind);
+  return o << ')';
+}
+
 template class Complex<Real<Integer<16>, 11>>;
 template class Complex<Real<Integer<32>, 24>>;
 template class Complex<Real<Integer<64>, 53>>;
index cc20b03..f1498fc 100644 (file)
@@ -83,6 +83,8 @@ public:
   }
 
   std::string DumpHexadecimal() const;
+  std::ostream &AsFortran(std::ostream &, int kind) const;
+
   // TODO: (C)ABS once Real::HYPOT is done
   // TODO: unit testing
 
index 0a83adf..0a9b0ce 100644 (file)
@@ -45,17 +45,25 @@ std::ostream &Convert<TO, FROMCAT>::AsFortran(std::ostream &o) const {
       TO::category == TypeCategory::Real ||
       TO::category == TypeCategory::Logical || !"Convert<> to bad category!");
   if constexpr (TO::category == TypeCategory::Integer) {
-    o << "INT";
+    o << "int";
   } else if constexpr (TO::category == TypeCategory::Real) {
-    o << "REAL";
+    o << "real";
   } else if constexpr (TO::category == TypeCategory::Logical) {
-    o << "LOGICAL";
+    o << "logical";
   }
-  return this->left().AsFortran(o << '(') << ",KIND=" << TO::kind << ')';
+  return this->left().AsFortran(o << '(') << ",kind=" << TO::kind << ')';
 }
 
 template<typename A> std::ostream &Relational<A>::Infix(std::ostream &o) const {
-  return o << '.' << EnumToString(opr) << '.';
+  switch (opr) {
+  case RelationalOperator::LT: o << '<'; break;
+  case RelationalOperator::LE: o << "<="; break;
+  case RelationalOperator::EQ: o << "=="; break;
+  case RelationalOperator::NE: o << "/="; break;
+  case RelationalOperator::GE: o << ">="; break;
+  case RelationalOperator::GT: o << '>'; break;
+  }
+  return o;
 }
 
 std::ostream &Relational<SomeType>::AsFortran(std::ostream &o) const {
@@ -66,10 +74,10 @@ std::ostream &Relational<SomeType>::AsFortran(std::ostream &o) const {
 template<int KIND>
 std::ostream &LogicalOperation<KIND>::Infix(std::ostream &o) const {
   switch (logicalOperator) {
-  case LogicalOperator::And: o << ".AND."; break;
-  case LogicalOperator::Or: o << ".OR."; break;
-  case LogicalOperator::Eqv: o << ".EQV."; break;
-  case LogicalOperator::Neqv: o << ".NEQV."; break;
+  case LogicalOperator::And: o << ".and."; break;
+  case LogicalOperator::Or: o << ".or."; break;
+  case LogicalOperator::Eqv: o << ".eqv."; break;
+  case LogicalOperator::Neqv: o << ".neqv."; break;
   }
   return o;
 }
@@ -80,14 +88,14 @@ std::ostream &Constant<T>::AsFortran(std::ostream &o) const {
     return o << value.SignedDecimal() << '_' << T::kind;
   } else if constexpr (T::category == TypeCategory::Real ||
       T::category == TypeCategory::Complex) {
-    return o << value.DumpHexadecimal() << '_' << T::kind;
+    return value.AsFortran(o, T::kind);
   } else if constexpr (T::category == TypeCategory::Character) {
     return o << T::kind << '_' << parser::QuoteCharacterLiteral(value);
   } else if constexpr (T::category == TypeCategory::Logical) {
     if (value.IsTrue()) {
-      o << ".TRUE.";
+      o << ".true.";
     } else {
-      o << ".FALSE.";
+      o << ".false.";
     }
     return o << '_' << Result::kind;
   } else {
@@ -137,7 +145,7 @@ template<typename RESULT>
 std::ostream &ExpressionBase<RESULT>::AsFortran(std::ostream &o) const {
   std::visit(
       common::visitors{[&](const BOZLiteralConstant &x) {
-                         o << "Z'" << x.Hexadecimal() << "'";
+                         o << "z'" << x.Hexadecimal() << "'";
                        },
           [&](const CopyableIndirection<Substring> &s) { s->AsFortran(o); },
           [&](const auto &x) { x.AsFortran(o); }},
index 304c4eb..f1e6e9c 100644 (file)
@@ -570,7 +570,7 @@ std::ostream &Real<W, P, IM>::AsFortran(std::ostream &o, int kind) const {
     int exponent = scaled.value.decimalExponent + digits.size() - 1;
     o << digits[0] << '.' << digits.substr(1);
     if (exponent != 0) {
-      o << 'E' << exponent;
+      o << 'e' << exponent;
     }
     o << '_' << kind;
     if (scaled.value.negative) {