From: peter klausler Date: Thu, 19 Jul 2018 17:12:25 +0000 (-0700) Subject: [flang] reformat X-Git-Tag: 2020.06-alpha~50^2~2673^2~2344 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9a503392b475e5e4664ad51ada237dcbd7c658d7;p=platform%2Fupstream%2Fllvm.git [flang] reformat Original-commit: flang-compiler/f18@3c93a9edbc66206b9d18211d7ffa13b29ffa85c3 Reviewed-on: https://github.com/flang-compiler/f18/pull/144 Tree-same-pre-rewrite: false --- diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index f2032eca7039..68491e849e58 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -432,29 +432,34 @@ void LogicalExpr::Fold(FoldingContext &context) { } std::optional GenericExpr::ConstantValue() const { - return std::visit([](const auto &x) -> std::optional { - if (auto c{x.ConstantValue()}) { - return {GenericConstant{std::move(*c)}}; - } - return {}; - }, u); + return std::visit( + [](const auto &x) -> std::optional { + if (auto c{x.ConstantValue()}) { + return {GenericConstant{std::move(*c)}}; + } + return {}; + }, + u); } -template std::optional> CategoryExpr::ConstantValue() const { - return std::visit([](const auto &x) -> std::optional> { - if (auto c{x.ConstantValue()}) { - return {CategoryConstant{std::move(*c)}}; - } - return {}; - }, u); +template +std::optional> CategoryExpr::ConstantValue() const { + return std::visit( + [](const auto &x) -> std::optional> { + if (auto c{x.ConstantValue()}) { + return {CategoryConstant{std::move(*c)}}; + } + return {}; + }, + u); } template void CategoryExpr::Fold(FoldingContext &context) { - std::visit([&](auto &x){ x.Fold(context); }, u); + std::visit([&](auto &x) { x.Fold(context); }, u); } void GenericExpr::Fold(FoldingContext &context) { - std::visit([&](auto &x){ x.Fold(context); }, u); + std::visit([&](auto &x) { x.Fold(context); }, u); } template struct CategoryExpr; diff --git a/flang/lib/evaluate/expression.h b/flang/lib/evaluate/expression.h index 947e1763dd3c..435de2ba7f7e 100644 --- a/flang/lib/evaluate/expression.h +++ b/flang/lib/evaluate/expression.h @@ -369,8 +369,7 @@ extern template struct Comparison>; template struct CategoryComparison { CLASS_BOILERPLATE(CategoryComparison) template using KindComparison = Comparison>; - template - CategoryComparison(const KindComparison &x) : u{x} {} + template CategoryComparison(const KindComparison &x) : u{x} {} template CategoryComparison(KindComparison &&x) : u{std::move(x)} {} std::optional Fold(FoldingContext &c); @@ -445,7 +444,9 @@ template struct CategoryConstant { CLASS_BOILERPLATE(CategoryConstant) template using KindConstant = typename Expr::Constant; template CategoryConstant(const A &x) : u{x} {} - template CategoryConstant(std::enable_if_t, A> &&x) : u{std::move(x)} {} + template + CategoryConstant(std::enable_if_t, A> &&x) + : u{std::move(x)} {} typename KindsVariant::type u; }; @@ -453,14 +454,19 @@ template struct CategoryConstant { struct GenericConstant { CLASS_BOILERPLATE(GenericConstant) template - GenericConstant(const typename Expr::Constant &x) : u{CategoryConstant{x}} {} + GenericConstant(const typename Expr::Constant &x) + : u{CategoryConstant{x}} {} template - GenericConstant(typename Expr::Constant &&x) : u{CategoryConstant{std::move(x)}} {} + GenericConstant(typename Expr::Constant &&x) + : u{CategoryConstant{std::move(x)}} {} template GenericConstant(const A &x) : u{x} {} template GenericConstant(std::enable_if_t, A> &&x) : u{std::move(x)} {} - std::variant, CategoryConstant, CategoryConstant, CategoryConstant, bool> u; + std::variant, + CategoryConstant, CategoryConstant, + CategoryConstant, bool> + u; }; // Dynamically polymorphic expressions that can hold any supported kind diff --git a/flang/lib/evaluate/type.h b/flang/lib/evaluate/type.h index 809be00bd5f1..d16eadf145e0 100644 --- a/flang/lib/evaluate/type.h +++ b/flang/lib/evaluate/type.h @@ -120,11 +120,11 @@ using SubscriptInteger = Type; // These macros invoke other macros on each of the supported kinds of // a given category. #define COMMA , -#define FOR_EACH_INTEGER_KIND(M,SEP) M(1) SEP M(2) SEP M(4) SEP M(8) SEP M(16) -#define FOR_EACH_REAL_KIND(M,SEP) M(2) SEP M(4) SEP M(8) SEP M(10) SEP M(16) -#define FOR_EACH_COMPLEX_KIND(M,SEP) FOR_EACH_REAL_KIND(M,SEP) -#define FOR_EACH_CHARACTER_KIND(M,SEP) M(1) -#define FOR_EACH_LOGICAL_KIND(M,SEP) M(1) SEP M(2) SEP M(4) SEP M(8) +#define FOR_EACH_INTEGER_KIND(M, SEP) M(1) SEP M(2) SEP M(4) SEP M(8) SEP M(16) +#define FOR_EACH_REAL_KIND(M, SEP) M(2) SEP M(4) SEP M(8) SEP M(10) SEP M(16) +#define FOR_EACH_COMPLEX_KIND(M, SEP) FOR_EACH_REAL_KIND(M, SEP) +#define FOR_EACH_CHARACTER_KIND(M, SEP) M(1) +#define FOR_EACH_LOGICAL_KIND(M, SEP) M(1) SEP M(2) SEP M(4) SEP M(8) // These templates create instances of std::variant<> that can contain // applications of some class template to all of the supported kinds of @@ -132,7 +132,7 @@ using SubscriptInteger = Type; #define TKIND(K) T template class T> struct KindsVariant; template class T> struct KindsVariant { - using type = std::variant; + using type = std::variant; }; // TODO use FOR_EACH... template class T> struct KindsVariant { diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index 297ec280c3ec..d0ed4628b2e8 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -20,13 +20,14 @@ using namespace Fortran::parser::literals; namespace Fortran::semantics { template -std::optional AnalyzeHelper(ExpressionAnalyzer &ea, const A &tree) { +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const A &tree) { return ea.Analyze(tree); } template -std::optional AnalyzeHelper(ExpressionAnalyzer &ea, - const parser::Scalar &tree) { +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const parser::Scalar &tree) { std::optional result{AnalyzeHelper(ea, tree.thing)}; if (result.has_value()) { if (result->Rank() > 1) { @@ -38,8 +39,8 @@ std::optional AnalyzeHelper(ExpressionAnalyzer &ea, } template -std::optional AnalyzeHelper(ExpressionAnalyzer &ea, - const parser::Constant &tree) { +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const parser::Constant &tree) { std::optional result{AnalyzeHelper(ea, tree.thing)}; if (result.has_value()) { result->Fold(ea.context()); @@ -52,68 +53,84 @@ std::optional AnalyzeHelper(ExpressionAnalyzer &ea, } template -std::optional AnalyzeHelper(ExpressionAnalyzer &ea, - const parser::Integer &tree) { +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const parser::Integer &tree) { std::optional result{AnalyzeHelper(ea, tree.thing)}; - if (result.has_value() && !std::holds_alternative(result->u)) { + if (result.has_value() && + !std::holds_alternative(result->u)) { ea.Say("must be integer"_err_en_US); return {}; } return result; } -template<> std::optional AnalyzeHelper(ExpressionAnalyzer &ea, - const parser::Name &n) { +template<> +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const parser::Name &n) { // TODO return {}; } -ExpressionAnalyzer::KindParam -ExpressionAnalyzer::Analyze(const std::optional &kindParam, - KindParam defaultKind, KindParam kanjiKind) { +ExpressionAnalyzer::KindParam ExpressionAnalyzer::Analyze( + const std::optional &kindParam, KindParam defaultKind, + KindParam kanjiKind) { if (!kindParam.has_value()) { return defaultKind; } - return std::visit(common::visitors{[](std::uint64_t k) { return static_cast(k); }, - [&](const parser::Scalar>> &n) { - if (std::optional oge{AnalyzeHelper(*this, n)}) { - if (std::optional ogc{oge->ConstantValue()}) { - // TODO pmk more here next - } - } - return defaultKind; - }, - [&](parser::KindParam::Kanji) { - if (kanjiKind >= 0) { - return kanjiKind; - } - Say("Kanji not allowed here"_err_en_US); - return defaultKind; }}, kindParam->u); + return std::visit( + common::visitors{ + [](std::uint64_t k) { return static_cast(k); }, + [&](const parser::Scalar< + parser::Integer>> &n) { + if (std::optional oge{ + AnalyzeHelper(*this, n)}) { + if (std::optional ogc{ + oge->ConstantValue()}) { + // TODO pmk more here next + } + } + return defaultKind; + }, + [&](parser::KindParam::Kanji) { + if (kanjiKind >= 0) { + return kanjiKind; + } + Say("Kanji not allowed here"_err_en_US); + return defaultKind; + }}, + kindParam->u); } -template<> std::optional AnalyzeHelper(ExpressionAnalyzer &ea, - const parser::IntLiteralConstant &x) { +template<> +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const parser::IntLiteralConstant &x) { auto kind{ea.Analyze(std::get>(x.t), - ea.defaultIntegerKind())}; + ea.defaultIntegerKind())}; std::uint64_t value{std::get(x.t)}; switch (kind) { -#define CASE(k) case k: return {evaluate::GenericExpr{evaluate::GenericIntegerExpr{evaluate::IntegerExpr{value}}}}; - FOR_EACH_INTEGER_KIND(CASE,) +#define CASE(k) \ + case k: \ + return {evaluate::GenericExpr{ \ + evaluate::GenericIntegerExpr{evaluate::IntegerExpr{value}}}}; + FOR_EACH_INTEGER_KIND(CASE, ) #undef CASE default: ea.Say(parser::MessageFormattedText{ - "unimplemented INTEGER kind (%ju)"_err_en_US, - static_cast(kind)}); + "unimplemented INTEGER kind (%ju)"_err_en_US, + static_cast(kind)}); return {}; } } -template<> std::optional AnalyzeHelper(ExpressionAnalyzer &ea, - const parser::LiteralConstant &x) { +template<> +std::optional AnalyzeHelper( + ExpressionAnalyzer &ea, const parser::LiteralConstant &x) { return std::visit( - common::visitors{ - [&](const parser::IntLiteralConstant &c) { return AnalyzeHelper(ea, c); }, - // TODO next [&](const parser::RealLiteralConstant &c) { return AnalyzeHelper(ea, c); }, + common::visitors{[&](const parser::IntLiteralConstant &c) { + return AnalyzeHelper(ea, c); + }, + // TODO next [&](const parser::RealLiteralConstant &c) { return + // AnalyzeHelper(ea, c); }, // TODO: remaining cases [&](const auto &) { return std::optional{}; }}, x.u); @@ -122,8 +139,9 @@ template<> std::optional AnalyzeHelper(ExpressionAnalyzer std::optional ExpressionAnalyzer::Analyze( const parser::Expr &x) { return std::visit( - common::visitors{ - [&](const parser::LiteralConstant &c) { return AnalyzeHelper(*this, c); }, + common::visitors{[&](const parser::LiteralConstant &c) { + return AnalyzeHelper(*this, c); + }, // TODO: remaining cases [&](const auto &) { return std::optional{}; }}, x.u); diff --git a/flang/lib/semantics/expression.h b/flang/lib/semantics/expression.h index 48c751987dd8..35fd72df4853 100644 --- a/flang/lib/semantics/expression.h +++ b/flang/lib/semantics/expression.h @@ -32,8 +32,7 @@ public: evaluate::FoldingContext &context() { return context_; } KindParam defaultIntegerKind() const { return defaultIntegerKind_; } - template - void Say(const M &msg) { + template void Say(const M &msg) { if (context_.messages != nullptr) { context_.messages->Say(context_.at, msg); } @@ -42,7 +41,8 @@ public: // Performs semantic checking on an expression. If successful, // returns its typed expression representation. std::optional Analyze(const parser::Expr &); - KindParam Analyze(const std::optional &, KindParam defaultKind, KindParam kanjiKind = -1 /* not allowed here */); + KindParam Analyze(const std::optional &, + KindParam defaultKind, KindParam kanjiKind = -1 /* not allowed here */); private: evaluate::FoldingContext context_;