diff --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h index dfce05c99cd5..823fa85ad12e 100644 --- a/flang/include/flang/Common/Fortran-features.h +++ b/flang/include/flang/Common/Fortran-features.h @@ -61,5 +61,5 @@ private: LanguageFeatures warn_; bool warnAll_{false}; }; -} -#endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_FORTRAN_FEATURES_H_ diff --git a/flang/include/flang/Common/Fortran.h b/flang/include/flang/Common/Fortran.h index 20a507aed415..df6b27c8ce3b 100644 --- a/flang/include/flang/Common/Fortran.h +++ b/flang/include/flang/Common/Fortran.h @@ -52,21 +52,21 @@ ENUM_CLASS(IoSpecKind, Access, Action, Advance, Asynchronous, Blank, Decimal, Id, Iomsg, Iostat, Name, Named, Newunit, Nextrec, Nml, Number, Opened, Pad, Pending, Pos, Position, Read, Readwrite, Rec, Recl, Round, Sequential, Sign, Size, Status, Stream, Unformatted, Unit, Write, - Convert, // nonstandard - Dispose, // nonstandard + Convert, // nonstandard + Dispose, // nonstandard ) // Floating-point rounding modes; these are packed into a byte to save // room in the runtime's format processing context structure. enum class RoundingMode : std::uint8_t { - TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding - ToZero, // ROUND=ZERO, RZ - truncation - Down, // ROUND=DOWN, RD - Up, // ROUND=UP, RU - TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero + TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding + ToZero, // ROUND=ZERO, RZ - truncation + Down, // ROUND=DOWN, RD + Up, // ROUND=UP, RU + TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero }; // Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6). static constexpr int maxRank{15}; -} -#endif // FORTRAN_COMMON_FORTRAN_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_FORTRAN_H_ diff --git a/flang/include/flang/Common/bit-population-count.h b/flang/include/flang/Common/bit-population-count.h index af3a1f22fd30..83d767ce0eee 100644 --- a/flang/include/flang/Common/bit-population-count.h +++ b/flang/include/flang/Common/bit-population-count.h @@ -70,18 +70,18 @@ inline constexpr int BitPopulationCount(std::uint8_t x) { return (x & 0xf) + (x >> 4); } -template inline constexpr bool Parity(UINT x) { +template inline constexpr bool Parity(UINT x) { return BitPopulationCount(x) & 1; } // "Parity is for farmers." -- Seymour R. Cray -template inline constexpr int TrailingZeroBitCount(UINT x) { +template inline constexpr int TrailingZeroBitCount(UINT x) { if ((x & 1) != 0) { - return 0; // fast path for odd values + return 0; // fast path for odd values } else { return BitPopulationCount(static_cast(x ^ (x - 1))) - !!x; } } -} -#endif // FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_BIT_POPULATION_COUNT_H_ diff --git a/flang/include/flang/Common/constexpr-bitset.h b/flang/include/flang/Common/constexpr-bitset.h index eae11f57d1e1..f1f468268909 100644 --- a/flang/include/flang/Common/constexpr-bitset.h +++ b/flang/include/flang/Common/constexpr-bitset.h @@ -21,7 +21,7 @@ namespace Fortran::common { -template class BitSet { +template class BitSet { static_assert(BITS > 0 && BITS <= 64); static constexpr bool partialWord{BITS != 32 && BITS != 64}; using Word = std::conditional_t<(BITS > 32), std::uint64_t, std::uint32_t>; @@ -143,5 +143,5 @@ public: private: Word bits_{0}; }; -} -#endif // FORTRAN_COMMON_CONSTEXPR_BITSET_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_CONSTEXPR_BITSET_H_ diff --git a/flang/include/flang/Common/default-kinds.h b/flang/include/flang/Common/default-kinds.h index c3610b23745f..6c66b98e98a0 100644 --- a/flang/include/flang/Common/default-kinds.h +++ b/flang/include/flang/Common/default-kinds.h @@ -50,12 +50,12 @@ private: // comprise two default REAL components. int defaultIntegerKind_{4}; int subscriptIntegerKind_{8}; - int sizeIntegerKind_{4}; // SIZE(), UBOUND(), &c. default KIND= + int sizeIntegerKind_{4}; // SIZE(), UBOUND(), &c. default KIND= int defaultRealKind_{defaultIntegerKind_}; int doublePrecisionKind_{2 * defaultRealKind_}; int quadPrecisionKind_{2 * doublePrecisionKind_}; int defaultCharacterKind_{1}; int defaultLogicalKind_{defaultIntegerKind_}; }; -} -#endif // FORTRAN_COMMON_DEFAULT_KINDS_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_DEFAULT_KINDS_H_ diff --git a/flang/include/flang/Common/enum-set.h b/flang/include/flang/Common/enum-set.h index ca8bc0cbd838..185c48825621 100644 --- a/flang/include/flang/Common/enum-set.h +++ b/flang/include/flang/Common/enum-set.h @@ -26,7 +26,7 @@ namespace Fortran::common { -template class EnumSet { +template class EnumSet { static_assert(BITS > 0); public: @@ -191,7 +191,7 @@ public: } } - template void IterateOverMembers(const FUNC &f) const { + template void IterateOverMembers(const FUNC &f) const { EnumSet copy{*this}; while (auto least{copy.LeastElement()}) { f(*least); @@ -212,13 +212,13 @@ public: private: bitsetType bitset_{}; }; -} +} // namespace Fortran::common -template +template struct std::hash> { std::size_t operator()( const Fortran::common::EnumSet &x) const { return std::hash(x.bitset()); } }; -#endif // FORTRAN_COMMON_ENUM_SET_H_ +#endif // FORTRAN_COMMON_ENUM_SET_H_ diff --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h index 4cb274c81cd5..99b8cbe41d7c 100644 --- a/flang/include/flang/Common/format.h +++ b/flang/include/flang/Common/format.h @@ -29,30 +29,30 @@ namespace Fortran::common { struct FormatMessage { - const char *text; // message text; may have one %s argument - const char *arg; // optional %s argument value - int offset; // offset to message marker - int length; // length of message marker - bool isError; // vs. warning + const char *text; // message text; may have one %s argument + const char *arg; // optional %s argument value + int offset; // offset to message marker + int length; // length of message marker + bool isError; // vs. warning }; // This declaration is logically private to class FormatValidator. // It is placed here to work around a clang compilation problem. ENUM_CLASS(TokenKind, None, A, B, BN, BZ, D, DC, DP, DT, E, EN, ES, EX, F, G, I, L, O, P, RC, RD, RN, RP, RU, RZ, S, SP, SS, T, TL, TR, X, Z, Colon, Slash, - Backslash, // nonstandard: inhibit newline on output - Dollar, // nonstandard: inhibit newline on output on terminals + Backslash, // nonstandard: inhibit newline on output + Dollar, // nonstandard: inhibit newline on output on terminals Star, LParen, RParen, Comma, Point, Sign, - UnsignedInteger, // value in integerValue_ - String) // char-literal-constant or Hollerith constant + UnsignedInteger, // value in integerValue_ + String) // char-literal-constant or Hollerith constant -template class FormatValidator { +template class FormatValidator { public: using Reporter = std::function; FormatValidator(const CHAR *format, size_t length, Reporter reporter, IoStmtKind stmt = IoStmtKind::None) - : format_{format}, end_{format + length}, reporter_{reporter}, stmt_{stmt}, - cursor_{format - 1} { + : format_{format}, end_{format + length}, reporter_{reporter}, + stmt_{stmt}, cursor_{format - 1} { CHECK(format); } @@ -128,54 +128,54 @@ private: bool check_d(); void check_e(); - const CHAR *const format_; // format text - const CHAR *const end_; // one-past-last of format_ text + const CHAR *const format_; // format text + const CHAR *const end_; // one-past-last of format_ text Reporter reporter_; IoStmtKind stmt_; - const CHAR *cursor_{}; // current location in format_ - const CHAR *laCursor_{}; // lookahead cursor - Token token_{}; // current token - int64_t integerValue_{-1}; // value of UnsignedInteger token - Token knrToken_{}; // k, n, or r UnsignedInteger token - int64_t knrValue_{-1}; // -1 ==> not present + const CHAR *cursor_{}; // current location in format_ + const CHAR *laCursor_{}; // lookahead cursor + Token token_{}; // current token + int64_t integerValue_{-1}; // value of UnsignedInteger token + Token knrToken_{}; // k, n, or r UnsignedInteger token + int64_t knrValue_{-1}; // -1 ==> not present int64_t wValue_{-1}; bool previousTokenWasInt_{false}; - char argString_[3]{}; // 1-2 character msg arg; usually edit descriptor name + char argString_[3]{}; // 1-2 character msg arg; usually edit descriptor name bool formatHasErrors_{false}; bool unterminatedFormatError_{false}; bool suppressMessageCascade_{false}; bool reporterExit_{false}; - int maxNesting_{0}; // max level of nested parentheses + int maxNesting_{0}; // max level of nested parentheses }; -template CHAR FormatValidator::NextChar() { +template CHAR FormatValidator::NextChar() { for (++cursor_; cursor_ < end_; ++cursor_) { if (*cursor_ != ' ') { return toupper(*cursor_); } } - cursor_ = end_; // don't allow cursor_ > end_ + cursor_ = end_; // don't allow cursor_ > end_ return ' '; } -template CHAR FormatValidator::LookAheadChar() { +template CHAR FormatValidator::LookAheadChar() { for (laCursor_ = cursor_ + 1; laCursor_ < end_; ++laCursor_) { if (*laCursor_ != ' ') { return toupper(*laCursor_); } } - laCursor_ = end_; // don't allow laCursor_ > end_ + laCursor_ = end_; // don't allow laCursor_ > end_ return ' '; } // After a call to LookAheadChar, set token kind and advance cursor to laCursor. -template void FormatValidator::Advance(TokenKind tk) { +template void FormatValidator::Advance(TokenKind tk) { cursor_ = laCursor_; token_.set_kind(tk); } -template void FormatValidator::NextToken() { +template void FormatValidator::NextToken() { // At entry, cursor_ points before the start of the next token. // At exit, cursor_ points to last CHAR of token_. @@ -184,7 +184,7 @@ template void FormatValidator::NextToken() { token_.set_kind(TokenKind::None); token_.set_offset(cursor_ - format_); token_.set_length(1); - if (c == '_' && integerValue_ >= 0) { // C1305, C1309, C1310, C1312, C1313 + if (c == '_' && integerValue_ >= 0) { // C1305, C1309, C1310, C1312, C1313 ReportError("Kind parameter '_' character in format expression"); } integerValue_ = -1; @@ -232,7 +232,7 @@ template void FormatValidator::NextToken() { cursor_ = end_; } SetLength(); - if (stmt_ == IoStmtKind::Read) { // 13.3.2p6 + if (stmt_ == IoStmtKind::Read) { // 13.3.2p6 ReportError("'H' edit descriptor in READ format expression"); } else if (token_.kind() == TokenKind::None) { ReportError("Unterminated 'H' edit descriptor"); @@ -241,72 +241,154 @@ template void FormatValidator::NextToken() { } break; } - case 'A': token_.set_kind(TokenKind::A); break; + case 'A': + token_.set_kind(TokenKind::A); + break; case 'B': switch (LookAheadChar()) { - case 'N': Advance(TokenKind::BN); break; - case 'Z': Advance(TokenKind::BZ); break; - default: token_.set_kind(TokenKind::B); break; + case 'N': + Advance(TokenKind::BN); + break; + case 'Z': + Advance(TokenKind::BZ); + break; + default: + token_.set_kind(TokenKind::B); + break; } break; case 'D': switch (LookAheadChar()) { - case 'C': Advance(TokenKind::DC); break; - case 'P': Advance(TokenKind::DP); break; - case 'T': Advance(TokenKind::DT); break; - default: token_.set_kind(TokenKind::D); break; + case 'C': + Advance(TokenKind::DC); + break; + case 'P': + Advance(TokenKind::DP); + break; + case 'T': + Advance(TokenKind::DT); + break; + default: + token_.set_kind(TokenKind::D); + break; } break; case 'E': switch (LookAheadChar()) { - case 'N': Advance(TokenKind::EN); break; - case 'S': Advance(TokenKind::ES); break; - case 'X': Advance(TokenKind::EX); break; - default: token_.set_kind(TokenKind::E); break; + case 'N': + Advance(TokenKind::EN); + break; + case 'S': + Advance(TokenKind::ES); + break; + case 'X': + Advance(TokenKind::EX); + break; + default: + token_.set_kind(TokenKind::E); + break; } break; - case 'F': token_.set_kind(TokenKind::F); break; - case 'G': token_.set_kind(TokenKind::G); break; - case 'I': token_.set_kind(TokenKind::I); break; - case 'L': token_.set_kind(TokenKind::L); break; - case 'O': token_.set_kind(TokenKind::O); break; - case 'P': token_.set_kind(TokenKind::P); break; + case 'F': + token_.set_kind(TokenKind::F); + break; + case 'G': + token_.set_kind(TokenKind::G); + break; + case 'I': + token_.set_kind(TokenKind::I); + break; + case 'L': + token_.set_kind(TokenKind::L); + break; + case 'O': + token_.set_kind(TokenKind::O); + break; + case 'P': + token_.set_kind(TokenKind::P); + break; case 'R': switch (LookAheadChar()) { - case 'C': Advance(TokenKind::RC); break; - case 'D': Advance(TokenKind::RD); break; - case 'N': Advance(TokenKind::RN); break; - case 'P': Advance(TokenKind::RP); break; - case 'U': Advance(TokenKind::RU); break; - case 'Z': Advance(TokenKind::RZ); break; - default: token_.set_kind(TokenKind::None); break; + case 'C': + Advance(TokenKind::RC); + break; + case 'D': + Advance(TokenKind::RD); + break; + case 'N': + Advance(TokenKind::RN); + break; + case 'P': + Advance(TokenKind::RP); + break; + case 'U': + Advance(TokenKind::RU); + break; + case 'Z': + Advance(TokenKind::RZ); + break; + default: + token_.set_kind(TokenKind::None); + break; } break; case 'S': switch (LookAheadChar()) { - case 'P': Advance(TokenKind::SP); break; - case 'S': Advance(TokenKind::SS); break; - default: token_.set_kind(TokenKind::S); break; + case 'P': + Advance(TokenKind::SP); + break; + case 'S': + Advance(TokenKind::SS); + break; + default: + token_.set_kind(TokenKind::S); + break; } break; case 'T': switch (LookAheadChar()) { - case 'L': Advance(TokenKind::TL); break; - case 'R': Advance(TokenKind::TR); break; - default: token_.set_kind(TokenKind::T); break; + case 'L': + Advance(TokenKind::TL); + break; + case 'R': + Advance(TokenKind::TR); + break; + default: + token_.set_kind(TokenKind::T); + break; } break; - case 'X': token_.set_kind(TokenKind::X); break; - case 'Z': token_.set_kind(TokenKind::Z); break; + case 'X': + token_.set_kind(TokenKind::X); + break; + case 'Z': + token_.set_kind(TokenKind::Z); + break; case '-': - case '+': token_.set_kind(TokenKind::Sign); break; - case '/': token_.set_kind(TokenKind::Slash); break; - case '(': token_.set_kind(TokenKind::LParen); break; - case ')': token_.set_kind(TokenKind::RParen); break; - case '.': token_.set_kind(TokenKind::Point); break; - case ':': token_.set_kind(TokenKind::Colon); break; - case '\\': token_.set_kind(TokenKind::Backslash); break; - case '$': token_.set_kind(TokenKind::Dollar); break; + case '+': + token_.set_kind(TokenKind::Sign); + break; + case '/': + token_.set_kind(TokenKind::Slash); + break; + case '(': + token_.set_kind(TokenKind::LParen); + break; + case ')': + token_.set_kind(TokenKind::RParen); + break; + case '.': + token_.set_kind(TokenKind::Point); + break; + case ':': + token_.set_kind(TokenKind::Colon); + break; + case '\\': + token_.set_kind(TokenKind::Backslash); + break; + case '$': + token_.set_kind(TokenKind::Dollar); + break; case '*': token_.set_kind(LookAheadChar() == '(' ? TokenKind::Star : TokenKind::None); break; @@ -334,7 +416,7 @@ template void FormatValidator::NextToken() { } } SetLength(); - if (stmt_ == IoStmtKind::Read) { // 13.3.2p6 + if (stmt_ == IoStmtKind::Read) { // 13.3.2p6 ReportError("String edit descriptor in READ format expression"); } else if (token_.kind() != TokenKind::String) { ReportError("Unterminated string"); @@ -353,34 +435,34 @@ template void FormatValidator::NextToken() { SetLength(); } -template void FormatValidator::check_r(bool allowed) { +template void FormatValidator::check_r(bool allowed) { if (!allowed && knrValue_ >= 0) { ReportError("Repeat specifier before '%s' edit descriptor", knrToken_); } else if (knrValue_ == 0) { ReportError("'%s' edit descriptor repeat specifier must be positive", - knrToken_); // C1304 + knrToken_); // C1304 } } // Return the predicate "w value is present" to control further processing. -template bool FormatValidator::check_w() { +template bool FormatValidator::check_w() { if (token_.kind() == TokenKind::UnsignedInteger) { wValue_ = integerValue_; if (wValue_ == 0 && (*argString_ == 'A' || *argString_ == 'L' || - stmt_ == IoStmtKind::Read)) { // C1306, 13.7.2.1p6 + stmt_ == IoStmtKind::Read)) { // C1306, 13.7.2.1p6 ReportError("'%s' edit descriptor 'w' value must be positive"); } NextToken(); return true; } if (*argString_ != 'A') { - ReportWarning("Expected '%s' edit descriptor 'w' value"); // C1306 + ReportWarning("Expected '%s' edit descriptor 'w' value"); // C1306 } return false; } -template void FormatValidator::check_m() { +template void FormatValidator::check_m() { if (token_.kind() != TokenKind::Point) { return; } @@ -390,14 +472,14 @@ template void FormatValidator::check_m() { return; } if ((stmt_ == IoStmtKind::Print || stmt_ == IoStmtKind::Write) && - wValue_ > 0 && integerValue_ > wValue_) { // 13.7.2.2p5, 13.7.2.4p6 + wValue_ > 0 && integerValue_ > wValue_) { // 13.7.2.2p5, 13.7.2.4p6 ReportError("'%s' edit descriptor 'm' value is greater than 'w' value"); } NextToken(); } // Return the predicate "d value is present" to control further processing. -template bool FormatValidator::check_d() { +template bool FormatValidator::check_d() { if (token_.kind() != TokenKind::Point) { ReportError("Expected '%s' edit descriptor '.d' value"); return false; @@ -411,7 +493,7 @@ template bool FormatValidator::check_d() { return true; } -template void FormatValidator::check_e() { +template void FormatValidator::check_e() { if (token_.kind() != TokenKind::E) { return; } @@ -423,7 +505,7 @@ template void FormatValidator::check_e() { NextToken(); } -template bool FormatValidator::Check() { +template bool FormatValidator::Check() { if (!*format_) { ReportError("Empty format expression"); return formatHasErrors_; @@ -435,8 +517,8 @@ template bool FormatValidator::Check() { } NextToken(); - int nestLevel{0}; // Outer level ()s are at level 0. - Token starToken{}; // unlimited format token + int nestLevel{0}; // Outer level ()s are at level 0. + Token starToken{}; // unlimited format token bool hasDataEditDesc{false}; // Subject to error recovery exceptions, a loop iteration processes one @@ -446,7 +528,7 @@ template bool FormatValidator::Check() { // - the error reporter requests termination (error threshold reached) while (!reporterExit_) { Token signToken{}; - knrValue_ = -1; // -1 ==> not present + knrValue_ = -1; // -1 ==> not present wValue_ = -1; bool commaRequired{true}; @@ -519,12 +601,12 @@ template bool FormatValidator::Check() { NextToken(); if (check_w()) { if (wValue_ > 0) { - if (check_d()) { // C1307 + if (check_d()) { // C1307 check_e(); } } else if (token_.kind() == TokenKind::Point && check_d() && token_.kind() == TokenKind::E) { - ReportError("Unexpected 'e' in 'G0' edit descriptor"); // C1308 + ReportError("Unexpected 'e' in 'G0' edit descriptor"); // C1308 NextToken(); if (token_.kind() == TokenKind::UnsignedInteger) { NextToken(); @@ -616,7 +698,9 @@ template bool FormatValidator::Check() { case TokenKind::ES: case TokenKind::EX: case TokenKind::F: - case TokenKind::G: commaRequired = false; break; + case TokenKind::G: + commaRequired = false; + break; default:; } cursor_ = saveCursor; @@ -629,14 +713,14 @@ template bool FormatValidator::Check() { // R1315 position-edit-desc -> T n | TL n | TR n check_r(false); NextToken(); - if (integerValue_ <= 0) { // C1311 + if (integerValue_ <= 0) { // C1311 ReportError("'%s' edit descriptor must have a positive position value"); } NextToken(); break; case TokenKind::X: // R1315 position-edit-desc -> n X - if (knrValue_ == 0) { // C1311 + if (knrValue_ == 0) { // C1311 ReportError("'X' edit descriptor must have a positive position value", knrToken_); } else if (knrValue_ < 0) { @@ -695,11 +779,11 @@ template bool FormatValidator::Check() { do { if (nestLevel == 0) { // Any characters after level-0 ) are ignored. - return formatHasErrors_; // normal exit (may have messages) + return formatHasErrors_; // normal exit (may have messages) } if (nestLevel == 1 && starToken.IsSet() && !hasDataEditDesc) { SetLength(starToken); - ReportError( // C1303 + ReportError( // C1303 "Unlimited format item list must contain a data edit descriptor", starToken); } @@ -718,31 +802,33 @@ template bool FormatValidator::Check() { break; } [[fallthrough]]; - default: ReportError("Unexpected '%s' in format expression"); NextToken(); + default: + ReportError("Unexpected '%s' in format expression"); + NextToken(); } // Process comma separator and exit an incomplete format. switch (token_.kind()) { - case TokenKind::Colon: // Comma not required; token not yet processed. - case TokenKind::Slash: // Comma not required; token not yet processed. - case TokenKind::RParen: // Comma not allowed; token not yet processed. + case TokenKind::Colon: // Comma not required; token not yet processed. + case TokenKind::Slash: // Comma not required; token not yet processed. + case TokenKind::RParen: // Comma not allowed; token not yet processed. suppressMessageCascade_ = false; break; - case TokenKind::LParen: // Comma not allowed; token already processed. - case TokenKind::Comma: // Normal comma case; move past token. + case TokenKind::LParen: // Comma not allowed; token already processed. + case TokenKind::Comma: // Normal comma case; move past token. suppressMessageCascade_ = false; NextToken(); break; - case TokenKind::Sign: // Error; main switch has a better message. - case TokenKind::None: // Error; token not yet processed. + case TokenKind::Sign: // Error; main switch has a better message. + case TokenKind::None: // Error; token not yet processed. if (cursor_ >= end_) { - return formatHasErrors_; // incomplete format error exit + return formatHasErrors_; // incomplete format error exit } break; default: // Possible first token of the next format item; token not yet processed. if (commaRequired) { - const char *s{"Expected ',' or ')' in format expression"}; // C1302 + const char *s{"Expected ',' or ')' in format expression"}; // C1302 if (previousTokenWasInt_ && itemsWithLeadingInts_.test(token_.kind())) { ReportError(s); } else { @@ -752,8 +838,8 @@ template bool FormatValidator::Check() { } } - return formatHasErrors_; // error reporter (message threshold) exit + return formatHasErrors_; // error reporter (message threshold) exit } -} -#endif // FORTRAN_COMMON_FORMAT_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_FORMAT_H_ diff --git a/flang/include/flang/Common/idioms.h b/flang/include/flang/Common/idioms.h index 84862f4976da..3f4f8f2eec6b 100644 --- a/flang/include/flang/Common/idioms.h +++ b/flang/include/flang/Common/idioms.h @@ -34,11 +34,11 @@ #if __GNUC__ == 7 // Avoid a deduction bug in GNU 7.x headers by forcing the answer. namespace std { -template +template struct is_trivially_copy_constructible> : false_type {}; -template +template struct is_trivially_copy_constructible>> : false_type {}; -} +} // namespace std #endif // enable "this is a std::string"s with the 's' suffix @@ -54,11 +54,11 @@ namespace Fortran::common { // ... // [&](const auto &catchAll) { ... }}, variantObject); -template struct visitors : LAMBDAS... { +template struct visitors : LAMBDAS... { using LAMBDAS::operator()...; }; -template visitors(LAMBDAS... x)->visitors; +template visitors(LAMBDAS... x) -> visitors; // Calls std::fprintf(stderr, ...), then abort(). [[noreturn]] void die(const char *, ...); @@ -93,11 +93,11 @@ template visitors(LAMBDAS... x)->visitors; // in template specialization definitions. #define CLASS_TRAIT(T) \ namespace class_trait_ns_##T { \ - template std::true_type test(typename A::T *); \ - template std::false_type test(...); \ - template \ + template std::true_type test(typename A::T *); \ + template std::false_type test(...); \ + template \ constexpr bool has_trait{decltype(test(nullptr))::value}; \ - template constexpr bool trait_value() { \ + template constexpr bool trait_value() { \ if constexpr (has_trait) { \ using U = typename A::T; \ return U::value; \ @@ -106,7 +106,7 @@ template visitors(LAMBDAS... x)->visitors; } \ } \ } \ - template constexpr bool T{class_trait_ns_##T::trait_value()}; + template constexpr bool T{class_trait_ns_##T::trait_value()}; #if !defined ATTRIBUTE_UNUSED && (__clang__ || __GNUC__) #define ATTRIBUTE_UNUSED __attribute__((unused)) @@ -119,7 +119,7 @@ template visitors(LAMBDAS... x)->visitors; std::string EnumIndexToString(int index, const char *names); -template struct ListItemCount { +template struct ListItemCount { constexpr ListItemCount(std::initializer_list list) : value{list.size()} {} const std::size_t value; }; @@ -138,7 +138,7 @@ template struct ListItemCount { // Check that a pointer is non-null and dereference it #define DEREF(p) Fortran::common::Deref(p, __FILE__, __LINE__) -template constexpr T &Deref(T *p, const char *file, int line) { +template constexpr T &Deref(T *p, const char *file, int line) { if (!p) { Fortran::common::die("nullptr dereference at %s(%d)", file, line); } @@ -146,7 +146,7 @@ template constexpr T &Deref(T *p, const char *file, int line) { } // Given a const reference to a value, return a copy of the value. -template A Clone(const A &x) { return x; } +template A Clone(const A &x) { return x; } // C++ does a weird and dangerous thing when deducing template type parameters // from function arguments: lvalue references are allowed to match rvalue @@ -159,8 +159,8 @@ template A Clone(const A &x) { return x; } // or, for constructors, // template> int foo(A &&); // This works with parameter packs too. -template +template using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v), A>; -template using NoLvalue = IfNoLvalue; -} -#endif // FORTRAN_COMMON_IDIOMS_H_ +template using NoLvalue = IfNoLvalue; +} // namespace Fortran::common +#endif // FORTRAN_COMMON_IDIOMS_H_ diff --git a/flang/include/flang/Common/indirection.h b/flang/include/flang/Common/indirection.h index a79fc19a388f..f34d561ae049 100644 --- a/flang/include/flang/Common/indirection.h +++ b/flang/include/flang/Common/indirection.h @@ -28,7 +28,7 @@ namespace Fortran::common { // The default case does not support (deep) copy construction or assignment. -template class Indirection { +template class Indirection { public: using element_type = A; Indirection() = delete; @@ -59,7 +59,7 @@ public: bool operator==(const A &that) const { return *p_ == that; } bool operator==(const Indirection &that) const { return *p_ == *that.p_; } - template + template static common::IfNoLvalue Make(ARGS &&... args) { return {new A(std::move(args)...)}; } @@ -69,7 +69,7 @@ private: }; // Variant with copy construction and assignment -template class Indirection { +template class Indirection { public: using element_type = A; @@ -111,7 +111,7 @@ public: bool operator==(const A &that) const { return *p_ == that; } bool operator==(const Indirection &that) const { return *p_ == *that.p_; } - template + template static common::IfNoLvalue Make(ARGS &&... args) { return {new A(std::move(args)...)}; } @@ -120,7 +120,7 @@ private: A *p_{nullptr}; }; -template using CopyableIndirection = Indirection; +template using CopyableIndirection = Indirection; // For use with std::unique_ptr<> when declaring owning pointers to // forward-referenced types, here's a minimal custom deleter that avoids @@ -129,13 +129,13 @@ template using CopyableIndirection = Indirection; // type is visible. Be advised, std::unique_ptr<> does not have copy // semantics; if you need ownership, copy semantics, and nullability, // std::optional> works. -template class Deleter { +template class Deleter { public: void operator()(A *) const; }; -} +} // namespace Fortran::common #define DEFINE_DELETER(A) \ - template<> void Fortran::common::Deleter::operator()(A *p) const { \ + template <> void Fortran::common::Deleter::operator()(A *p) const { \ delete p; \ } -#endif // FORTRAN_COMMON_INDIRECTION_H_ +#endif // FORTRAN_COMMON_INDIRECTION_H_ diff --git a/flang/include/flang/Common/interval.h b/flang/include/flang/Common/interval.h index c1d1cfb890c8..baaa35b9efc5 100644 --- a/flang/include/flang/Common/interval.h +++ b/flang/include/flang/Common/interval.h @@ -19,13 +19,13 @@ namespace Fortran::common { -template class Interval { +template class Interval { public: using type = A; constexpr Interval() {} constexpr Interval(const A &s, std::size_t n = 1) : start_{s}, size_{n} {} constexpr Interval(A &&s, std::size_t n = 1) - : start_{std::move(s)}, size_{n} {} + : start_{std::move(s)}, size_{n} {} constexpr Interval(const Interval &) = default; constexpr Interval(Interval &&) = default; constexpr Interval &operator=(const Interval &) = default; @@ -111,5 +111,5 @@ private: A start_; std::size_t size_{0}; }; -} -#endif // FORTRAN_COMMON_INTERVAL_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_INTERVAL_H_ diff --git a/flang/include/flang/Common/leading-zero-bit-count.h b/flang/include/flang/Common/leading-zero-bit-count.h index 48fc3f129059..a296e0b44691 100644 --- a/flang/include/flang/Common/leading-zero-bit-count.h +++ b/flang/include/flang/Common/leading-zero-bit-count.h @@ -40,7 +40,7 @@ static constexpr std::uint8_t mapping[64]{63, 0, 58, 1, 59, 47, 53, 2, 60, 39, 48, 27, 54, 33, 42, 3, 61, 51, 37, 40, 49, 18, 28, 20, 55, 30, 34, 11, 43, 14, 22, 4, 62, 57, 46, 52, 38, 26, 32, 41, 50, 36, 17, 19, 29, 10, 13, 21, 56, 45, 25, 31, 35, 16, 9, 12, 44, 24, 15, 8, 23, 7, 6, 5}; -} +} // namespace inline constexpr int LeadingZeroBitCount(std::uint64_t x) { if (x == 0) { @@ -53,13 +53,13 @@ inline constexpr int LeadingZeroBitCount(std::uint64_t x) { x |= x >> 16; x |= x >> 32; // All of the bits below the uppermost set bit are now also set. - x -= x >> 1; // All of the bits below the uppermost are now clear. + x -= x >> 1; // All of the bits below the uppermost are now clear. // x now has exactly one bit set, so it is a power of two, so // multiplication by x is equivalent to a left shift by its // base-2 logarithm. We calculate that unknown base-2 logarithm // by shifting the deBruijn sequence and mapping the framed value. int base2Log{mapping[(x * deBruijn) >> 58]}; - return 63 - base2Log; // convert to leading zero count + return 63 - base2Log; // convert to leading zero count } } @@ -89,8 +89,8 @@ inline constexpr int LeadingZeroBitCount(std::uint8_t x) { return eightBitLeadingZeroBitCount[x]; } -template inline constexpr int BitsNeededFor(A x) { +template inline constexpr int BitsNeededFor(A x) { return 8 * sizeof x - LeadingZeroBitCount(x); } -} -#endif // FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_LEADING_ZERO_BIT_COUNT_H_ diff --git a/flang/include/flang/Common/real.h b/flang/include/flang/Common/real.h index 4688e440a82d..eec29f1ca7b3 100644 --- a/flang/include/flang/Common/real.h +++ b/flang/include/flang/Common/real.h @@ -20,14 +20,22 @@ namespace Fortran::common { // Total representation size in bits for each type static constexpr int BitsForBinaryPrecision(int binaryPrecision) { switch (binaryPrecision) { - case 8: return 16; // IEEE single (truncated): 1+8+7 - case 11: return 16; // IEEE half precision: 1+5+10 - case 24: return 32; // IEEE single precision: 1+8+23 - case 53: return 64; // IEEE double precision: 1+11+52 - case 64: return 80; // x87 extended precision: 1+15+64 - case 106: return 128; // "double-double": 2*(1+11+52) - case 113: return 128; // IEEE quad precision: 1+15+112 - default: return -1; + case 8: + return 16; // IEEE single (truncated): 1+8+7 + case 11: + return 16; // IEEE half precision: 1+5+10 + case 24: + return 32; // IEEE single precision: 1+8+23 + case 53: + return 64; // IEEE double precision: 1+11+52 + case 64: + return 80; // x87 extended precision: 1+15+64 + case 106: + return 128; // "double-double": 2*(1+11+52) + case 113: + return 128; // IEEE quad precision: 1+15+112 + default: + return -1; } } @@ -37,18 +45,26 @@ static constexpr int BitsForBinaryPrecision(int binaryPrecision) { // exactly with FORMAT(E0.22981). static constexpr int MaxDecimalConversionDigits(int binaryPrecision) { switch (binaryPrecision) { - case 8: return 93; - case 11: return 17; - case 24: return 105; - case 53: return 751; - case 64: return 11495; - case 106: return 2 * 751; - case 113: return 11530; - default: return -1; + case 8: + return 93; + case 11: + return 17; + case 24: + return 105; + case 53: + return 751; + case 64: + return 11495; + case 106: + return 2 * 751; + case 113: + return 11530; + default: + return -1; } } -template class RealDetails { +template class RealDetails { private: // Converts bit widths to whole decimal digits static constexpr int LogBaseTwoToLogBaseTen(int logb2) { @@ -82,5 +98,5 @@ public: static_assert(exponentBits <= 15); }; -} -#endif // FORTRAN_COMMON_REAL_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_REAL_H_ diff --git a/flang/include/flang/Common/reference-counted.h b/flang/include/flang/Common/reference-counted.h index 2a96741bb8f7..6aae6cface46 100644 --- a/flang/include/flang/Common/reference-counted.h +++ b/flang/include/flang/Common/reference-counted.h @@ -16,7 +16,7 @@ namespace Fortran::common { // A base class for reference-counted objects. Must be public. -template class ReferenceCounted { +template class ReferenceCounted { public: ReferenceCounted() {} void TakeReference() { ++references_; } @@ -31,7 +31,7 @@ private: }; // A reference to a reference-counted object. -template class CountedReference { +template class CountedReference { public: using type = A; CountedReference() {} @@ -72,5 +72,5 @@ private: type *p_{nullptr}; }; -} -#endif // FORTRAN_COMMON_REFERENCE_COUNTED_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_REFERENCE_COUNTED_H_ diff --git a/flang/include/flang/Common/reference.h b/flang/include/flang/Common/reference.h index f204b8f8b352..0c579de44bd7 100644 --- a/flang/include/flang/Common/reference.h +++ b/flang/include/flang/Common/reference.h @@ -15,7 +15,7 @@ #define FORTRAN_COMMON_REFERENCE_H_ #include namespace Fortran::common { -template class Reference { +template class Reference { public: using type = A; Reference(type &x) : p_{&x} {} @@ -35,8 +35,8 @@ public: // creation of a temporary copy in cases like: // Reference ref; // const Type &x{ref}; // creates ref to temp copy! - operator std::conditional_t, type &, void>() const - noexcept { + operator std::conditional_t, type &, void>() + const noexcept { if constexpr (std::is_const_v) { return *p_; } @@ -56,8 +56,8 @@ public: bool operator!=(const Reference &that) const { return !(*this == that); } private: - type *p_; // never null + type *p_; // never null }; -template Reference(A &)->Reference; -} +template Reference(A &) -> Reference; +} // namespace Fortran::common #endif diff --git a/flang/include/flang/Common/restorer.h b/flang/include/flang/Common/restorer.h index 26ddcfca0820..47e54237fe43 100644 --- a/flang/include/flang/Common/restorer.h +++ b/flang/include/flang/Common/restorer.h @@ -20,7 +20,7 @@ #define FORTRAN_COMMON_RESTORER_H_ #include "idioms.h" namespace Fortran::common { -template class Restorer { +template class Restorer { public: explicit Restorer(A &p) : p_{p}, original_{std::move(p)} {} ~Restorer() { p_ = std::move(original_); } @@ -30,17 +30,17 @@ private: A original_; }; -template +template common::IfNoLvalue, B> ScopedSet(A &to, B &&from) { Restorer result{to}; to = std::move(from); return result; } -template +template common::IfNoLvalue, B> ScopedSet(A &to, const B &from) { Restorer result{to}; to = from; return result; } -} -#endif // FORTRAN_COMMON_RESTORER_H_ +} // namespace Fortran::common +#endif // FORTRAN_COMMON_RESTORER_H_ diff --git a/flang/include/flang/Common/template.h b/flang/include/flang/Common/template.h index 2f726fe6cc39..866292cfcf48 100644 --- a/flang/include/flang/Common/template.h +++ b/flang/include/flang/Common/template.h @@ -26,7 +26,7 @@ namespace Fortran::common { // index of the first type T in the list for which PREDICATE::value() is // true is returned, or -1 if the predicate is false for every type in the list. // This is a compile-time operation; see SearchTypes below for a run-time form. -template class PREDICATE, typename TUPLE> +template class PREDICATE, typename TUPLE> struct SearchTypeListHelper { static constexpr int value() { if constexpr (N >= std::tuple_size_v) { @@ -39,41 +39,41 @@ struct SearchTypeListHelper { } }; -template class PREDICATE, typename... TYPES> +template