[flang] reformat
authorpeter klausler <pklausler@nvidia.com>
Thu, 19 Jul 2018 17:12:25 +0000 (10:12 -0700)
committerpeter klausler <pklausler@nvidia.com>
Tue, 24 Jul 2018 21:33:53 +0000 (14:33 -0700)
Original-commit: flang-compiler/f18@3c93a9edbc66206b9d18211d7ffa13b29ffa85c3
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false

flang/lib/evaluate/expression.cc
flang/lib/evaluate/expression.h
flang/lib/evaluate/type.h
flang/lib/semantics/expression.cc
flang/lib/semantics/expression.h

index f2032eca7039f149bf0b13656f4ddcf3fc88d005..68491e849e58cca1b9da529cc400c44fe617cc06 100644 (file)
@@ -432,29 +432,34 @@ void LogicalExpr::Fold(FoldingContext &context) {
 }
 
 std::optional<GenericConstant> GenericExpr::ConstantValue() const {
-  return std::visit([](const auto &x) -> std::optional<GenericConstant> {
-    if (auto c{x.ConstantValue()}) {
-      return {GenericConstant{std::move(*c)}};
-    }
-    return {};
-  }, u);
+  return std::visit(
+      [](const auto &x) -> std::optional<GenericConstant> {
+        if (auto c{x.ConstantValue()}) {
+          return {GenericConstant{std::move(*c)}};
+        }
+        return {};
+      },
+      u);
 }
 
-template<Category CAT> std::optional<CategoryConstant<CAT>> CategoryExpr<CAT>::ConstantValue() const {
-  return std::visit([](const auto &x) -> std::optional<CategoryConstant<CAT>> {
-    if (auto c{x.ConstantValue()}) {
-      return {CategoryConstant<CAT>{std::move(*c)}};
-    }
-    return {};
-  }, u);
+template<Category CAT>
+std::optional<CategoryConstant<CAT>> CategoryExpr<CAT>::ConstantValue() const {
+  return std::visit(
+      [](const auto &x) -> std::optional<CategoryConstant<CAT>> {
+        if (auto c{x.ConstantValue()}) {
+          return {CategoryConstant<CAT>{std::move(*c)}};
+        }
+        return {};
+      },
+      u);
 }
 
 template<Category CAT> void CategoryExpr<CAT>::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<Category::Integer>;
index 947e1763dd3c9500a258011ec455376cfa0fab4f..435de2ba7f7eb158db45baf0da3f871ec4711655 100644 (file)
@@ -369,8 +369,7 @@ extern template struct Comparison<CharacterExpr<1>>;
 template<Category CAT> struct CategoryComparison {
   CLASS_BOILERPLATE(CategoryComparison)
   template<int KIND> using KindComparison = Comparison<Expr<CAT, KIND>>;
-  template<int KIND>
-  CategoryComparison(const KindComparison<KIND> &x) : u{x} {}
+  template<int KIND> CategoryComparison(const KindComparison<KIND> &x) : u{x} {}
   template<int KIND>
   CategoryComparison(KindComparison<KIND> &&x) : u{std::move(x)} {}
   std::optional<bool> Fold(FoldingContext &c);
@@ -445,7 +444,9 @@ template<Category CAT> struct CategoryConstant {
   CLASS_BOILERPLATE(CategoryConstant)
   template<int KIND> using KindConstant = typename Expr<CAT, KIND>::Constant;
   template<typename A> CategoryConstant(const A &x) : u{x} {}
-  template<typename A> CategoryConstant(std::enable_if_t<!std::is_reference_v<A>, A> &&x) : u{std::move(x)} {}
+  template<typename A>
+  CategoryConstant(std::enable_if_t<!std::is_reference_v<A>, A> &&x)
+    : u{std::move(x)} {}
   typename KindsVariant<CAT, KindConstant>::type u;
 };
 
@@ -453,14 +454,19 @@ template<Category CAT> struct CategoryConstant {
 struct GenericConstant {
   CLASS_BOILERPLATE(GenericConstant)
   template<Category CAT, int KIND>
-  GenericConstant(const typename Expr<CAT, KIND>::Constant &x) : u{CategoryConstant<CAT>{x}} {}
+  GenericConstant(const typename Expr<CAT, KIND>::Constant &x)
+    : u{CategoryConstant<CAT>{x}} {}
   template<Category CAT, int KIND>
-  GenericConstant(typename Expr<CAT, KIND>::Constant &&x) : u{CategoryConstant<CAT>{std::move(x)}} {}
+  GenericConstant(typename Expr<CAT, KIND>::Constant &&x)
+    : u{CategoryConstant<CAT>{std::move(x)}} {}
   template<typename A> GenericConstant(const A &x) : u{x} {}
   template<typename A>
   GenericConstant(std::enable_if_t<!std::is_reference_v<A>, A> &&x)
     : u{std::move(x)} {}
-  std::variant<CategoryConstant<Category::Integer>, CategoryConstant<Category::Real>, CategoryConstant<Category::Complex>, CategoryConstant<Category::Character>, bool> u;
+  std::variant<CategoryConstant<Category::Integer>,
+      CategoryConstant<Category::Real>, CategoryConstant<Category::Complex>,
+      CategoryConstant<Category::Character>, bool>
+      u;
 };
 
 // Dynamically polymorphic expressions that can hold any supported kind
index 809be00bd5f19c5afba143208ea8c7a2f14d3ac2..d16eadf145e01732929fe0044a0ac56a63fde544 100644 (file)
@@ -120,11 +120,11 @@ using SubscriptInteger = Type<Category::Integer, 8>;
 // 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<Category::Integer, 8>;
 #define TKIND(K) T<K>
 template<Category CAT, template<int> class T> struct KindsVariant;
 template<template<int> class T> struct KindsVariant<Category::Integer, T> {
-  using type = std::variant<FOR_EACH_INTEGER_KIND(TKIND,COMMA)>;
+  using type = std::variant<FOR_EACH_INTEGER_KIND(TKIND, COMMA)>;
 };
 // TODO use FOR_EACH...
 template<template<int> class T> struct KindsVariant<Category::Real, T> {
index 297ec280c3ec961ac6c7f918a4a5c794338ba0ef..d0ed4628b2e81200accd53d00735a621d4514bf9 100644 (file)
@@ -20,13 +20,14 @@ using namespace Fortran::parser::literals;
 namespace Fortran::semantics {
 
 template<typename A>
-std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea, const A &tree) {
+std::optional<evaluate::GenericExpr> AnalyzeHelper(
+    ExpressionAnalyzer &ea, const A &tree) {
   return ea.Analyze(tree);
 }
 
 template<typename A>
-std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
-  const parser::Scalar<A> &tree) {
+std::optional<evaluate::GenericExpr> AnalyzeHelper(
+    ExpressionAnalyzer &ea, const parser::Scalar<A> &tree) {
   std::optional<evaluate::GenericExpr> result{AnalyzeHelper(ea, tree.thing)};
   if (result.has_value()) {
     if (result->Rank() > 1) {
@@ -38,8 +39,8 @@ std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
 }
 
 template<typename A>
-std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
-  const parser::Constant<A> &tree) {
+std::optional<evaluate::GenericExpr> AnalyzeHelper(
+    ExpressionAnalyzer &ea, const parser::Constant<A> &tree) {
   std::optional<evaluate::GenericExpr> result{AnalyzeHelper(ea, tree.thing)};
   if (result.has_value()) {
     result->Fold(ea.context());
@@ -52,68 +53,84 @@ std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
 }
 
 template<typename A>
-std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
-  const parser::Integer<A> &tree) {
+std::optional<evaluate::GenericExpr> AnalyzeHelper(
+    ExpressionAnalyzer &ea, const parser::Integer<A> &tree) {
   std::optional<evaluate::GenericExpr> result{AnalyzeHelper(ea, tree.thing)};
-  if (result.has_value() && !std::holds_alternative<evaluate::GenericIntegerExpr>(result->u)) {
+  if (result.has_value() &&
+      !std::holds_alternative<evaluate::GenericIntegerExpr>(result->u)) {
     ea.Say("must be integer"_err_en_US);
     return {};
   }
   return result;
 }
 
-template<> std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
-  const parser::Name &n) {
+template<>
+std::optional<evaluate::GenericExpr> AnalyzeHelper(
+    ExpressionAnalyzer &ea, const parser::Name &n) {
   // TODO
   return {};
 }
 
-ExpressionAnalyzer::KindParam
-ExpressionAnalyzer::Analyze(const std::optional<parser::KindParam> &kindParam,
-                            KindParam defaultKind, KindParam kanjiKind) {
+ExpressionAnalyzer::KindParam ExpressionAnalyzer::Analyze(
+    const std::optional<parser::KindParam> &kindParam, KindParam defaultKind,
+    KindParam kanjiKind) {
   if (!kindParam.has_value()) {
     return defaultKind;
   }
-  return std::visit(common::visitors{[](std::uint64_t k) { return static_cast<KindParam>(k); },
-    [&](const parser::Scalar<parser::Integer<parser::Constant<parser::Name>>> &n) {
-      if (std::optional<evaluate::GenericExpr> oge{AnalyzeHelper(*this, n)}) {
-        if (std::optional<evaluate::GenericConstant> 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<KindParam>(k); },
+          [&](const parser::Scalar<
+              parser::Integer<parser::Constant<parser::Name>>> &n) {
+            if (std::optional<evaluate::GenericExpr> oge{
+                    AnalyzeHelper(*this, n)}) {
+              if (std::optional<evaluate::GenericConstant> 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<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
-    const parser::IntLiteralConstant &x) {
+template<>
+std::optional<evaluate::GenericExpr> AnalyzeHelper(
+    ExpressionAnalyzer &ea, const parser::IntLiteralConstant &x) {
   auto kind{ea.Analyze(std::get<std::optional<parser::KindParam>>(x.t),
-                       ea.defaultIntegerKind())};
+      ea.defaultIntegerKind())};
   std::uint64_t value{std::get<std::uint64_t>(x.t)};
   switch (kind) {
-#define CASE(k) case k: return {evaluate::GenericExpr{evaluate::GenericIntegerExpr{evaluate::IntegerExpr<k>{value}}}};
-  FOR_EACH_INTEGER_KIND(CASE,)
+#define CASE(k) \
+  case k: \
+    return {evaluate::GenericExpr{ \
+        evaluate::GenericIntegerExpr{evaluate::IntegerExpr<k>{value}}}};
+    FOR_EACH_INTEGER_KIND(CASE, )
 #undef CASE
   default:
     ea.Say(parser::MessageFormattedText{
-            "unimplemented INTEGER kind (%ju)"_err_en_US,
-            static_cast<std::uintmax_t>(kind)});
+        "unimplemented INTEGER kind (%ju)"_err_en_US,
+        static_cast<std::uintmax_t>(kind)});
     return {};
   }
 }
 
-template<> std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer &ea,
-    const parser::LiteralConstant &x) {
+template<>
+std::optional<evaluate::GenericExpr> 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<evaluate::GenericExpr>{}; }},
       x.u);
@@ -122,8 +139,9 @@ template<> std::optional<evaluate::GenericExpr> AnalyzeHelper(ExpressionAnalyzer
 std::optional<evaluate::GenericExpr> 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<evaluate::GenericExpr>{}; }},
       x.u);
index 48c751987dd83b06d4078db5afb49ed0ed7946d4..35fd72df4853371aaddf3207a7fe302953d0bdb8 100644 (file)
@@ -32,8 +32,7 @@ public:
   evaluate::FoldingContext &context() { return context_; }
   KindParam defaultIntegerKind() const { return defaultIntegerKind_; }
 
-  template<typename M>
-  void Say(const M &msg) {
+  template<typename M> 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<evaluate::GenericExpr> Analyze(const parser::Expr &);
-  KindParam Analyze(const std::optional<parser::KindParam> &, KindParam defaultKind, KindParam kanjiKind = -1 /* not allowed here */);
+  KindParam Analyze(const std::optional<parser::KindParam> &,
+      KindParam defaultKind, KindParam kanjiKind = -1 /* not allowed here */);
 
 private:
   evaluate::FoldingContext context_;