[flang] review comments

Original-commit: flang-compiler/f18@32c02cb668
Reviewed-on: https://github.com/flang-compiler/f18/pull/225
This commit is contained in:
peter klausler 2018-11-14 14:35:10 -08:00
parent 12b0f643ab
commit aa34fc6042
5 changed files with 39 additions and 23 deletions

View 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

View 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>>;

View 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

View 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); }},

View 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) {