From: peter klausler Date: Wed, 14 Nov 2018 22:35:10 +0000 (-0800) Subject: [flang] review comments X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa34fc6042a5f6ac9ba1d5f18c8eb0b4eea91060;p=platform%2Fupstream%2Fllvm.git [flang] review comments Original-commit: flang-compiler/f18@32c02cb668f17e31061c3f52c834e4029e410381 Reviewed-on: https://github.com/flang-compiler/f18/pull/225 --- diff --git a/flang/documentation/C++style.md b/flang/documentation/C++style.md index 768f44b..b6fbf9c 100644 --- a/flang/documentation/C++style.md +++ b/flang/documentation/C++style.md @@ -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 diff --git a/flang/lib/evaluate/complex.cc b/flang/lib/evaluate/complex.cc index 1665519..6883cf5 100644 --- a/flang/lib/evaluate/complex.cc +++ b/flang/lib/evaluate/complex.cc @@ -95,6 +95,12 @@ template std::string Complex::DumpHexadecimal() const { return result; } +template std::ostream &Complex::AsFortran(std::ostream &o, int kind) const { + re_.AsFortran(o << '(', kind); + im_.AsFortran(o << ',', kind); + return o << ')'; +} + template class Complex, 11>>; template class Complex, 24>>; template class Complex, 53>>; diff --git a/flang/lib/evaluate/complex.h b/flang/lib/evaluate/complex.h index cc20b03..f1498fc 100644 --- a/flang/lib/evaluate/complex.h +++ b/flang/lib/evaluate/complex.h @@ -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 diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index 0a83adf..0a9b0ce 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -45,17 +45,25 @@ std::ostream &Convert::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 std::ostream &Relational::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::AsFortran(std::ostream &o) const { @@ -66,10 +74,10 @@ std::ostream &Relational::AsFortran(std::ostream &o) const { template std::ostream &LogicalOperation::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::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 std::ostream &ExpressionBase::AsFortran(std::ostream &o) const { std::visit( common::visitors{[&](const BOZLiteralConstant &x) { - o << "Z'" << x.Hexadecimal() << "'"; + o << "z'" << x.Hexadecimal() << "'"; }, [&](const CopyableIndirection &s) { s->AsFortran(o); }, [&](const auto &x) { x.AsFortran(o); }}, diff --git a/flang/lib/evaluate/real.cc b/flang/lib/evaluate/real.cc index 304c4eb..f1e6e9c 100644 --- a/flang/lib/evaluate/real.cc +++ b/flang/lib/evaluate/real.cc @@ -570,7 +570,7 @@ std::ostream &Real::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) {