[llvm] a7224dc - [Support] clang-format YAMLTraits.h

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 13:48:14 PDT 2025


Author: Kazu Hirata
Date: 2025-09-01T13:48:08-07:00
New Revision: a7224dc188bb131a4c51b33104e8090ccaad3250

URL: https://github.com/llvm/llvm-project/commit/a7224dc188bb131a4c51b33104e8090ccaad3250
DIFF: https://github.com/llvm/llvm-project/commit/a7224dc188bb131a4c51b33104e8090ccaad3250.diff

LOG: [Support] clang-format YAMLTraits.h

I'm planning to modify this file.

Added: 
    

Modified: 
    llvm/include/llvm/Support/YAMLTraits.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index 1b1d78ded8642..d29a0e4c3c783 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -59,8 +59,7 @@ struct EmptyContext {};
 ///         io.mapOptional("age",  s.age);
 ///       }
 ///     };
-template<class T>
-struct MappingTraits {
+template <class T> struct MappingTraits {
   // Must provide:
   // static void mapping(IO &io, T &fields);
   // Optionally may provide:
@@ -177,8 +176,7 @@ template <typename T, typename Enable = void> struct ScalarTraits {
 ///        return StringRef();
 ///      }
 ///    };
-template <typename T>
-struct BlockScalarTraits {
+template <typename T> struct BlockScalarTraits {
   // Must provide:
   //
   // Function to write the value as a string:
@@ -244,8 +242,7 @@ template <typename T> struct TaggedScalarTraits {
 ///        return seq[index];
 ///      }
 ///    };
-template<typename T, typename EnableIf = void>
-struct SequenceTraits {
+template <typename T, typename EnableIf = void> struct SequenceTraits {
   // Must provide:
   // static size_t size(IO &io, T &seq);
   // static T::value_type& element(IO &io, T &seq, size_t index);
@@ -257,16 +254,14 @@ struct SequenceTraits {
 
 /// This class should be specialized by any type for which vectors of that
 /// type need to be converted to/from a YAML sequence.
-template<typename T, typename EnableIf = void>
-struct SequenceElementTraits {
+template <typename T, typename EnableIf = void> struct SequenceElementTraits {
   // Must provide:
   // static const bool flow;
 };
 
 /// This class should be specialized by any type that needs to be converted
 /// to/from a list of YAML documents.
-template<typename T>
-struct DocumentListTraits {
+template <typename T> struct DocumentListTraits {
   // Must provide:
   // static size_t size(IO &io, T &seq);
   // static T::value_type& element(IO &io, T &seq, size_t index);
@@ -275,8 +270,7 @@ struct DocumentListTraits {
 /// This class should be specialized by any type that needs to be converted
 /// to/from a YAML mapping in the case where the names of the keys are not known
 /// in advance, e.g. a string map.
-template <typename T>
-struct CustomMappingTraits {
+template <typename T> struct CustomMappingTraits {
   // static void inputOne(IO &io, StringRef key, T &elem);
   // static void output(IO &io, T &elem);
 };
@@ -307,46 +301,37 @@ template <typename T> struct PolymorphicTraits {
 };
 
 // Only used for better diagnostics of missing traits
-template <typename T>
-struct MissingTrait;
+template <typename T> struct MissingTrait;
 
 // Test if ScalarEnumerationTraits<T> is defined on type T.
-template <class T>
-struct has_ScalarEnumerationTraits
-{
-  using Signature_enumeration = void (*)(class IO&, T&);
+template <class T> struct has_ScalarEnumerationTraits {
+  using Signature_enumeration = void (*)(class IO &, T &);
 
   template <typename U>
-  static char test(SameType<Signature_enumeration, &U::enumeration>*);
+  static char test(SameType<Signature_enumeration, &U::enumeration> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value =
-    (sizeof(test<ScalarEnumerationTraits<T>>(nullptr)) == 1);
+      (sizeof(test<ScalarEnumerationTraits<T>>(nullptr)) == 1);
 };
 
 // Test if ScalarBitSetTraits<T> is defined on type T.
-template <class T>
-struct has_ScalarBitSetTraits
-{
-  using Signature_bitset = void (*)(class IO&, T&);
+template <class T> struct has_ScalarBitSetTraits {
+  using Signature_bitset = void (*)(class IO &, T &);
 
   template <typename U>
-  static char test(SameType<Signature_bitset, &U::bitset>*);
+  static char test(SameType<Signature_bitset, &U::bitset> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value = (sizeof(test<ScalarBitSetTraits<T>>(nullptr)) == 1);
 };
 
 // Test if ScalarTraits<T> is defined on type T.
-template <class T>
-struct has_ScalarTraits
-{
-  using Signature_input = StringRef (*)(StringRef, void*, T&);
-  using Signature_output = void (*)(const T&, void*, raw_ostream&);
+template <class T> struct has_ScalarTraits {
+  using Signature_input = StringRef (*)(StringRef, void *, T &);
+  using Signature_output = void (*)(const T &, void *, raw_ostream &);
   using Signature_mustQuote = QuotingType (*)(StringRef);
 
   template <typename U>
@@ -354,17 +339,14 @@ struct has_ScalarTraits
                    SameType<Signature_output, &U::output> *,
                    SameType<Signature_mustQuote, &U::mustQuote> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value =
       (sizeof(test<ScalarTraits<T>>(nullptr, nullptr, nullptr)) == 1);
 };
 
 // Test if BlockScalarTraits<T> is defined on type T.
-template <class T>
-struct has_BlockScalarTraits
-{
+template <class T> struct has_BlockScalarTraits {
   using Signature_input = StringRef (*)(StringRef, void *, T &);
   using Signature_output = void (*)(const T &, void *, raw_ostream &);
 
@@ -372,8 +354,7 @@ struct has_BlockScalarTraits
   static char test(SameType<Signature_input, &U::input> *,
                    SameType<Signature_output, &U::output> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value =
       (sizeof(test<BlockScalarTraits<T>>(nullptr, nullptr)) == 1);
@@ -402,10 +383,9 @@ template <class T, class Context> struct has_MappingTraits {
   using Signature_mapping = void (*)(class IO &, T &, Context &);
 
   template <typename U>
-  static char test(SameType<Signature_mapping, &U::mapping>*);
+  static char test(SameType<Signature_mapping, &U::mapping> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value =
       (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
@@ -428,10 +408,9 @@ template <class T, class Context> struct has_MappingValidateTraits {
   using Signature_validate = std::string (*)(class IO &, T &, Context &);
 
   template <typename U>
-  static char test(SameType<Signature_validate, &U::validate>*);
+  static char test(SameType<Signature_validate, &U::validate> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value =
       (sizeof(test<MappingContextTraits<T, Context>>(nullptr)) == 1);
@@ -475,31 +454,24 @@ template <class T> struct has_MappingEnumInputTraits<T, EmptyContext> {
 };
 
 // Test if SequenceTraits<T> is defined on type T.
-template <class T>
-struct has_SequenceMethodTraits
-{
-  using Signature_size = size_t (*)(class IO&, T&);
+template <class T> struct has_SequenceMethodTraits {
+  using Signature_size = size_t (*)(class IO &, T &);
 
-  template <typename U>
-  static char test(SameType<Signature_size, &U::size>*);
+  template <typename U> static char test(SameType<Signature_size, &U::size> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
-  static bool const value =  (sizeof(test<SequenceTraits<T>>(nullptr)) == 1);
+  static bool const value = (sizeof(test<SequenceTraits<T>>(nullptr)) == 1);
 };
 
 // Test if CustomMappingTraits<T> is defined on type T.
-template <class T>
-struct has_CustomMappingTraits
-{
+template <class T> struct has_CustomMappingTraits {
   using Signature_input = void (*)(IO &io, StringRef key, T &v);
 
   template <typename U>
-  static char test(SameType<Signature_input, &U::inputOne>*);
+  static char test(SameType<Signature_input, &U::inputOne> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
   static bool const value =
       (sizeof(test<CustomMappingTraits<T>>(nullptr)) == 1);
@@ -510,45 +482,41 @@ struct has_CustomMappingTraits
 // real has_FlowTraits only if the template type is a class.
 template <typename T, bool Enabled = std::is_class_v<T>> class has_FlowTraits {
 public:
-   static const bool value = false;
+  static const bool value = false;
 };
 
 // Some older gcc compilers don't support straight forward tests
 // for members, so test for ambiguity cause by the base and derived
 // classes both defining the member.
-template <class T>
-struct has_FlowTraits<T, true>
-{
-  struct Fallback { bool flow; };
-  struct Derived : T, Fallback { };
+template <class T> struct has_FlowTraits<T, true> {
+  struct Fallback {
+    bool flow;
+  };
+  struct Derived : T, Fallback {};
 
-  template<typename C>
-  static char (&f(SameType<bool Fallback::*, &C::flow>*))[1];
+  template <typename C>
+  static char (&f(SameType<bool Fallback::*, &C::flow> *))[1];
 
-  template<typename C>
-  static char (&f(...))[2];
+  template <typename C> static char (&f(...))[2];
 
   static bool const value = sizeof(f<Derived>(nullptr)) == 2;
 };
 
 // Test if SequenceTraits<T> is defined on type T
-template<typename T>
-struct has_SequenceTraits : public std::integral_constant<bool,
-                                      has_SequenceMethodTraits<T>::value > { };
+template <typename T>
+struct has_SequenceTraits
+    : public std::integral_constant<bool, has_SequenceMethodTraits<T>::value> {
+};
 
 // Test if DocumentListTraits<T> is defined on type T
-template <class T>
-struct has_DocumentListTraits
-{
+template <class T> struct has_DocumentListTraits {
   using Signature_size = size_t (*)(class IO &, T &);
 
-  template <typename U>
-  static char test(SameType<Signature_size, &U::size>*);
+  template <typename U> static char test(SameType<Signature_size, &U::size> *);
 
-  template <typename U>
-  static double test(...);
+  template <typename U> static double test(...);
 
-  static bool const value = (sizeof(test<DocumentListTraits<T>>(nullptr))==1);
+  static bool const value = (sizeof(test<DocumentListTraits<T>>(nullptr)) == 1);
 };
 
 template <class T> struct has_PolymorphicTraits {
@@ -785,32 +753,32 @@ class LLVM_ABI IO {
 
   virtual unsigned beginSequence() = 0;
   virtual bool preflightElement(unsigned, void *&) = 0;
-  virtual void postflightElement(void*) = 0;
+  virtual void postflightElement(void *) = 0;
   virtual void endSequence() = 0;
   virtual bool canElideEmptySequence() = 0;
 
   virtual unsigned beginFlowSequence() = 0;
   virtual bool preflightFlowElement(unsigned, void *&) = 0;
-  virtual void postflightFlowElement(void*) = 0;
+  virtual void postflightFlowElement(void *) = 0;
   virtual void endFlowSequence() = 0;
 
-  virtual bool mapTag(StringRef Tag, bool Default=false) = 0;
+  virtual bool mapTag(StringRef Tag, bool Default = false) = 0;
   virtual void beginMapping() = 0;
   virtual void endMapping() = 0;
-  virtual bool preflightKey(const char*, bool, bool, bool &, void *&) = 0;
-  virtual void postflightKey(void*) = 0;
+  virtual bool preflightKey(const char *, bool, bool, bool &, void *&) = 0;
+  virtual void postflightKey(void *) = 0;
   virtual std::vector<StringRef> keys() = 0;
 
   virtual void beginFlowMapping() = 0;
   virtual void endFlowMapping() = 0;
 
   virtual void beginEnumScalar() = 0;
-  virtual bool matchEnumScalar(const char*, bool) = 0;
+  virtual bool matchEnumScalar(const char *, bool) = 0;
   virtual bool matchEnumFallback() = 0;
   virtual void endEnumScalar() = 0;
 
   virtual bool beginBitSetScalar(bool &) = 0;
-  virtual bool bitSetMatch(const char*, bool) = 0;
+  virtual bool bitSetMatch(const char *, bool) = 0;
   virtual void endBitSetScalar() = 0;
 
   virtual void scalarString(StringRef &, QuotingType) = 0;
@@ -824,22 +792,21 @@ class LLVM_ABI IO {
   virtual void setAllowUnknownKeys(bool Allow);
 
   template <typename T>
-  void enumCase(T &Val, const char* Str, const T ConstVal) {
-    if ( matchEnumScalar(Str, outputting() && Val == ConstVal) ) {
+  void enumCase(T &Val, const char *Str, const T ConstVal) {
+    if (matchEnumScalar(Str, outputting() && Val == ConstVal)) {
       Val = ConstVal;
     }
   }
 
   // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
   template <typename T>
-  void enumCase(T &Val, const char* Str, const uint32_t ConstVal) {
-    if ( matchEnumScalar(Str, outputting() && Val == static_cast<T>(ConstVal)) ) {
+  void enumCase(T &Val, const char *Str, const uint32_t ConstVal) {
+    if (matchEnumScalar(Str, outputting() && Val == static_cast<T>(ConstVal))) {
       Val = ConstVal;
     }
   }
 
-  template <typename FBT, typename T>
-  void enumFallback(T &Val) {
+  template <typename FBT, typename T> void enumFallback(T &Val) {
     if (matchEnumFallback()) {
       EmptyContext Context;
       // FIXME: Force integral conversion to allow strong typedefs to convert.
@@ -850,16 +817,16 @@ class LLVM_ABI IO {
   }
 
   template <typename T>
-  void bitSetCase(T &Val, const char* Str, const T ConstVal) {
-    if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
+  void bitSetCase(T &Val, const char *Str, const T ConstVal) {
+    if (bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal)) {
       Val = static_cast<T>(Val | ConstVal);
     }
   }
 
   // allow anonymous enum values to be used with LLVM_YAML_STRONG_TYPEDEF
   template <typename T>
-  void bitSetCase(T &Val, const char* Str, const uint32_t ConstVal) {
-    if ( bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal) ) {
+  void bitSetCase(T &Val, const char *Str, const uint32_t ConstVal) {
+    if (bitSetMatch(Str, outputting() && (Val & ConstVal) == ConstVal)) {
       Val = static_cast<T>(Val | ConstVal);
     }
   }
@@ -939,13 +906,12 @@ class LLVM_ABI IO {
     void *SaveInfo;
     bool UseDefault;
     const bool sameAsDefault = outputting() && Val == DefaultValue;
-    if ( this->preflightKey(Key, Required, sameAsDefault, UseDefault,
-                                                                  SaveInfo) ) {
+    if (this->preflightKey(Key, Required, sameAsDefault, UseDefault,
+                           SaveInfo)) {
       yamlize(*this, Val, Required, Ctx);
       this->postflightKey(SaveInfo);
-    }
-    else {
-      if ( UseDefault )
+    } else {
+      if (UseDefault)
         Val = DefaultValue;
     }
   }
@@ -954,7 +920,7 @@ class LLVM_ABI IO {
   void processKey(const char *Key, T &Val, bool Required, Context &Ctx) {
     void *SaveInfo;
     bool UseDefault;
-    if ( this->preflightKey(Key, Required, false, UseDefault, SaveInfo) ) {
+    if (this->preflightKey(Key, Required, false, UseDefault, SaveInfo)) {
       yamlize(*this, Val, Required, Ctx);
       this->postflightKey(SaveInfo);
     }
@@ -989,8 +955,8 @@ template <typename T>
 std::enable_if_t<has_ScalarBitSetTraits<T>::value, void>
 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
   bool DoClear;
-  if ( io.beginBitSetScalar(DoClear) ) {
-    if ( DoClear )
+  if (io.beginBitSetScalar(DoClear)) {
+    if (DoClear)
       Val = T();
     ScalarBitSetTraits<T>::bitset(io, Val);
     io.endBitSetScalar();
@@ -1000,18 +966,17 @@ yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
 template <typename T>
 std::enable_if_t<has_ScalarTraits<T>::value, void> yamlize(IO &io, T &Val, bool,
                                                            EmptyContext &Ctx) {
-  if ( io.outputting() ) {
+  if (io.outputting()) {
     SmallString<128> Storage;
     raw_svector_ostream Buffer(Storage);
     ScalarTraits<T>::output(Val, io.getContext(), Buffer);
     StringRef Str = Buffer.str();
     io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
-  }
-  else {
+  } else {
     StringRef Str;
     io.scalarString(Str, ScalarTraits<T>::mustQuote(Str));
     StringRef Result = ScalarTraits<T>::input(Str, io.getContext(), Val);
-    if ( !Result.empty() ) {
+    if (!Result.empty()) {
       io.setError(Twine(Result));
     }
   }
@@ -1134,7 +1099,7 @@ yamlize(IO &io, T &Val, bool, Context &Ctx) {
 template <typename T>
 std::enable_if_t<has_CustomMappingTraits<T>::value, void>
 yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
-  if ( io.outputting() ) {
+  if (io.outputting()) {
     io.beginMapping();
     CustomMappingTraits<T>::output(io, Val);
     io.endMapping();
@@ -1169,24 +1134,23 @@ yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) {
 template <typename T, typename Context>
 std::enable_if_t<has_SequenceTraits<T>::value, void>
 yamlize(IO &io, T &Seq, bool, Context &Ctx) {
-  if ( has_FlowTraits< SequenceTraits<T>>::value ) {
+  if (has_FlowTraits<SequenceTraits<T>>::value) {
     unsigned incnt = io.beginFlowSequence();
     unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
-    for(unsigned i=0; i < count; ++i) {
+    for (unsigned i = 0; i < count; ++i) {
       void *SaveInfo;
-      if ( io.preflightFlowElement(i, SaveInfo) ) {
+      if (io.preflightFlowElement(i, SaveInfo)) {
         yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
         io.postflightFlowElement(SaveInfo);
       }
     }
     io.endFlowSequence();
-  }
-  else {
+  } else {
     unsigned incnt = io.beginSequence();
     unsigned count = io.outputting() ? SequenceTraits<T>::size(io, Seq) : incnt;
-    for(unsigned i=0; i < count; ++i) {
+    for (unsigned i = 0; i < count; ++i) {
       void *SaveInfo;
-      if ( io.preflightElement(i, SaveInfo) ) {
+      if (io.preflightElement(i, SaveInfo)) {
         yamlize(io, SequenceTraits<T>::element(io, Seq, i), true, Ctx);
         io.postflightElement(SaveInfo);
       }
@@ -1195,92 +1159,79 @@ yamlize(IO &io, T &Seq, bool, Context &Ctx) {
   }
 }
 
-template<>
-struct ScalarTraits<bool> {
+template <> struct ScalarTraits<bool> {
   LLVM_ABI static void output(const bool &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, bool &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<StringRef> {
+template <> struct ScalarTraits<StringRef> {
   LLVM_ABI static void output(const StringRef &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, StringRef &);
   static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
 };
 
-template<>
-struct ScalarTraits<std::string> {
+template <> struct ScalarTraits<std::string> {
   LLVM_ABI static void output(const std::string &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, std::string &);
   static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
 };
 
-template<>
-struct ScalarTraits<uint8_t> {
+template <> struct ScalarTraits<uint8_t> {
   LLVM_ABI static void output(const uint8_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, uint8_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<uint16_t> {
+template <> struct ScalarTraits<uint16_t> {
   LLVM_ABI static void output(const uint16_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, uint16_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<uint32_t> {
+template <> struct ScalarTraits<uint32_t> {
   LLVM_ABI static void output(const uint32_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, uint32_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<uint64_t> {
+template <> struct ScalarTraits<uint64_t> {
   LLVM_ABI static void output(const uint64_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, uint64_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<int8_t> {
+template <> struct ScalarTraits<int8_t> {
   LLVM_ABI static void output(const int8_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, int8_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<int16_t> {
+template <> struct ScalarTraits<int16_t> {
   LLVM_ABI static void output(const int16_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, int16_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<int32_t> {
+template <> struct ScalarTraits<int32_t> {
   LLVM_ABI static void output(const int32_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, int32_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<int64_t> {
+template <> struct ScalarTraits<int64_t> {
   LLVM_ABI static void output(const int64_t &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, int64_t &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<float> {
+template <> struct ScalarTraits<float> {
   LLVM_ABI static void output(const float &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, float &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<double> {
+template <> struct ScalarTraits<double> {
   LLVM_ABI static void output(const double &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, double &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
@@ -1346,46 +1297,42 @@ struct ScalarBitSetTraits<
 
 // Utility for use within MappingTraits<>::mapping() method
 // to [de]normalize an object for use with YAML conversion.
-template <typename TNorm, typename TFinal>
-struct MappingNormalization {
+template <typename TNorm, typename TFinal> struct MappingNormalization {
   MappingNormalization(IO &i_o, TFinal &Obj)
       : io(i_o), BufPtr(nullptr), Result(Obj) {
-    if ( io.outputting() ) {
+    if (io.outputting()) {
       BufPtr = new (&Buffer) TNorm(io, Obj);
-    }
-    else {
+    } else {
       BufPtr = new (&Buffer) TNorm(io);
     }
   }
 
   ~MappingNormalization() {
-    if ( ! io.outputting() ) {
+    if (!io.outputting()) {
       Result = BufPtr->denormalize(io);
     }
     BufPtr->~TNorm();
   }
 
-  TNorm* operator->() { return BufPtr; }
+  TNorm *operator->() { return BufPtr; }
 
 private:
   using Storage = AlignedCharArrayUnion<TNorm>;
 
-  Storage       Buffer;
-  IO           &io;
-  TNorm        *BufPtr;
-  TFinal       &Result;
+  Storage Buffer;
+  IO &io;
+  TNorm *BufPtr;
+  TFinal &Result;
 };
 
 // Utility for use within MappingTraits<>::mapping() method
 // to [de]normalize an object for use with YAML conversion.
-template <typename TNorm, typename TFinal>
-struct MappingNormalizationHeap {
+template <typename TNorm, typename TFinal> struct MappingNormalizationHeap {
   MappingNormalizationHeap(IO &i_o, TFinal &Obj, BumpPtrAllocator *allocator)
-    : io(i_o), Result(Obj) {
-    if ( io.outputting() ) {
+      : io(i_o), Result(Obj) {
+    if (io.outputting()) {
       BufPtr = new (&Buffer) TNorm(io, Obj);
-    }
-    else if (allocator) {
+    } else if (allocator) {
       BufPtr = allocator->Allocate<TNorm>();
       new (BufPtr) TNorm(io);
     } else {
@@ -1394,23 +1341,22 @@ struct MappingNormalizationHeap {
   }
 
   ~MappingNormalizationHeap() {
-    if ( io.outputting() ) {
+    if (io.outputting()) {
       BufPtr->~TNorm();
-    }
-    else {
+    } else {
       Result = BufPtr->denormalize(io);
     }
   }
 
-  TNorm* operator->() { return BufPtr; }
+  TNorm *operator->() { return BufPtr; }
 
 private:
   using Storage = AlignedCharArrayUnion<TNorm>;
 
-  Storage       Buffer;
-  IO           &io;
-  TNorm        *BufPtr = nullptr;
-  TFinal       &Result;
+  Storage Buffer;
+  IO &io;
+  TNorm *BufPtr = nullptr;
+  TFinal &Result;
 };
 
 ///
@@ -1430,12 +1376,10 @@ class LLVM_ABI Input : public IO {
   // Construct a yaml Input object from a StringRef and optional
   // user-data. The DiagHandler can be specified to provide
   // alternative error reporting.
-  Input(StringRef InputContent,
-        void *Ctxt = nullptr,
+  Input(StringRef InputContent, void *Ctxt = nullptr,
         SourceMgr::DiagHandlerTy DiagHandler = nullptr,
         void *DiagHandlerCtxt = nullptr);
-  Input(MemoryBufferRef Input,
-        void *Ctxt = nullptr,
+  Input(MemoryBufferRef Input, void *Ctxt = nullptr,
         SourceMgr::DiagHandlerTy DiagHandler = nullptr,
         void *DiagHandlerCtxt = nullptr);
   ~Input() override;
@@ -1458,15 +1402,15 @@ class LLVM_ABI Input : public IO {
   bool preflightElement(unsigned index, void *&) override;
   void postflightElement(void *) override;
   unsigned beginFlowSequence() override;
-  bool preflightFlowElement(unsigned , void *&) override;
+  bool preflightFlowElement(unsigned, void *&) override;
   void postflightFlowElement(void *) override;
   void endFlowSequence() override;
   void beginEnumScalar() override;
-  bool matchEnumScalar(const char*, bool) override;
+  bool matchEnumScalar(const char *, bool) override;
   bool matchEnumFallback() override;
   void endEnumScalar() override;
   bool beginBitSetScalar(bool &) override;
-  bool bitSetMatch(const char *, bool ) override;
+  bool bitSetMatch(const char *, bool) override;
   void endBitSetScalar() override;
   void scalarString(StringRef &, QuotingType) override;
   void blockScalarString(StringRef &) override;
@@ -1486,7 +1430,7 @@ class LLVM_ABI Input : public IO {
 
   class EmptyHNode : public HNode {
   public:
-    EmptyHNode(Node *n) : HNode(n) { }
+    EmptyHNode(Node *n) : HNode(n) {}
 
     static bool classof(const HNode *n) { return NullNode::classof(n->_node); }
 
@@ -1495,7 +1439,7 @@ class LLVM_ABI Input : public IO {
 
   class ScalarHNode : public HNode {
   public:
-    ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { }
+    ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) {}
 
     StringRef value() const { return _value; }
 
@@ -1512,7 +1456,7 @@ class LLVM_ABI Input : public IO {
 
   class MapHNode : public HNode {
   public:
-    MapHNode(Node *n) : HNode(n) { }
+    MapHNode(Node *n) : HNode(n) {}
 
     static bool classof(const HNode *n) {
       return MappingNode::classof(n->_node);
@@ -1528,7 +1472,7 @@ class LLVM_ABI Input : public IO {
 
   class SequenceHNode : public HNode {
   public:
-    SequenceHNode(Node *n) : HNode(n) { }
+    SequenceHNode(Node *n) : HNode(n) {}
 
     static bool classof(const HNode *n) {
       return SequenceNode::classof(n->_node);
@@ -1563,19 +1507,19 @@ class LLVM_ABI Input : public IO {
   void setAllowUnknownKeys(bool Allow) override;
 
 private:
-  SourceMgr                           SrcMgr; // must be before Strm
+  SourceMgr SrcMgr; // must be before Strm
   std::unique_ptr<llvm::yaml::Stream> Strm;
   HNode *TopNode = nullptr;
-  std::error_code                     EC;
-  BumpPtrAllocator                    StringAllocator;
+  std::error_code EC;
+  BumpPtrAllocator StringAllocator;
   SpecificBumpPtrAllocator<EmptyHNode> EmptyHNodeAllocator;
   SpecificBumpPtrAllocator<ScalarHNode> ScalarHNodeAllocator;
   SpecificBumpPtrAllocator<MapHNode> MapHNodeAllocator;
   SpecificBumpPtrAllocator<SequenceHNode> SequenceHNodeAllocator;
-  document_iterator                   DocIterator;
-  llvm::BitVector                     BitValuesUsed;
+  document_iterator DocIterator;
+  llvm::BitVector BitValuesUsed;
   HNode *CurrentNode = nullptr;
-  bool                                ScalarMatchFound = false;
+  bool ScalarMatchFound = false;
   bool AllowUnknownKeys = false;
 };
 
@@ -1613,11 +1557,11 @@ class LLVM_ABI Output : public IO {
   void postflightFlowElement(void *) override;
   void endFlowSequence() override;
   void beginEnumScalar() override;
-  bool matchEnumScalar(const char*, bool) override;
+  bool matchEnumScalar(const char *, bool) override;
   bool matchEnumFallback() override;
   void endEnumScalar() override;
   bool beginBitSetScalar(bool &) override;
-  bool bitSetMatch(const char *, bool ) override;
+  bool bitSetMatch(const char *, bool) override;
   void endBitSetScalar() override;
   void scalarString(StringRef &, QuotingType) override;
   void blockScalarString(StringRef &) override;
@@ -1718,19 +1662,22 @@ void IO::processKeyWithDefault(const char *Key, std::optional<T> &Val,
 /// and automatic conversion operators to and from the base type.
 /// Based on BOOST_STRONG_TYPEDEF
 #define LLVM_YAML_STRONG_TYPEDEF(_base, _type)                                 \
-    struct _type {                                                             \
-        _type() = default;                                                     \
-        _type(const _base v) : value(v) {}                                     \
-        _type(const _type &v) = default;                                       \
-        _type &operator=(const _type &rhs) = default;                          \
-        _type &operator=(const _base &rhs) { value = rhs; return *this; }      \
-        operator const _base & () const { return value; }                      \
-        bool operator==(const _type &rhs) const { return value == rhs.value; } \
-        bool operator==(const _base &rhs) const { return value == rhs; }       \
-        bool operator<(const _type &rhs) const { return value < rhs.value; }   \
-        _base value;                                                           \
-        using BaseType = _base;                                                \
-    };
+  struct _type {                                                               \
+    _type() = default;                                                         \
+    _type(const _base v) : value(v) {}                                         \
+    _type(const _type &v) = default;                                           \
+    _type &operator=(const _type &rhs) = default;                              \
+    _type &operator=(const _base &rhs) {                                       \
+      value = rhs;                                                             \
+      return *this;                                                            \
+    }                                                                          \
+    operator const _base &() const { return value; }                           \
+    bool operator==(const _type &rhs) const { return value == rhs.value; }     \
+    bool operator==(const _base &rhs) const { return value == rhs; }           \
+    bool operator<(const _type &rhs) const { return value < rhs.value; }       \
+    _base value;                                                               \
+    using BaseType = _base;                                                    \
+  };
 
 ///
 /// Use these types instead of uintXX_t in any mapping to have
@@ -1741,29 +1688,25 @@ LLVM_YAML_STRONG_TYPEDEF(uint16_t, Hex16)
 LLVM_YAML_STRONG_TYPEDEF(uint32_t, Hex32)
 LLVM_YAML_STRONG_TYPEDEF(uint64_t, Hex64)
 
-template<>
-struct ScalarTraits<Hex8> {
+template <> struct ScalarTraits<Hex8> {
   LLVM_ABI static void output(const Hex8 &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, Hex8 &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<Hex16> {
+template <> struct ScalarTraits<Hex16> {
   LLVM_ABI static void output(const Hex16 &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, Hex16 &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<Hex32> {
+template <> struct ScalarTraits<Hex32> {
   LLVM_ABI static void output(const Hex32 &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, Hex32 &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
 };
 
-template<>
-struct ScalarTraits<Hex64> {
+template <> struct ScalarTraits<Hex64> {
   LLVM_ABI static void output(const Hex64 &, void *, raw_ostream &);
   LLVM_ABI static StringRef input(StringRef, void *, Hex64 &);
   static QuotingType mustQuote(StringRef) { return QuotingType::None; }
@@ -1782,9 +1725,9 @@ inline std::enable_if_t<has_DocumentListTraits<T>::value, Input &>
 operator>>(Input &yin, T &docList) {
   int i = 0;
   EmptyContext Ctx;
-  while ( yin.setCurrentDocument() ) {
+  while (yin.setCurrentDocument()) {
     yamlize(yin, DocumentListTraits<T>::element(yin, docList, i), true, Ctx);
-    if ( yin.error() )
+    if (yin.error())
       return yin;
     yin.nextDocument();
     ++i;
@@ -1858,8 +1801,8 @@ operator<<(Output &yout, T &docList) {
   EmptyContext Ctx;
   yout.beginDocuments();
   const size_t count = DocumentListTraits<T>::size(yout, docList);
-  for(size_t i=0; i < count; ++i) {
-    if ( yout.preflightDocument(i) ) {
+  for (size_t i = 0; i < count; ++i) {
+    if (yout.preflightDocument(i)) {
       yamlize(yout, DocumentListTraits<T>::element(yout, docList, i), true,
               Ctx);
       yout.postflightDocument();
@@ -1875,7 +1818,7 @@ inline std::enable_if_t<has_MappingTraits<T, EmptyContext>::value, Output &>
 operator<<(Output &yout, T &map) {
   EmptyContext Ctx;
   yout.beginDocuments();
-  if ( yout.preflightDocument(0) ) {
+  if (yout.preflightDocument(0)) {
     yamlize(yout, map, true, Ctx);
     yout.postflightDocument();
   }
@@ -1889,7 +1832,7 @@ inline std::enable_if_t<has_SequenceTraits<T>::value, Output &>
 operator<<(Output &yout, T &seq) {
   EmptyContext Ctx;
   yout.beginDocuments();
-  if ( yout.preflightDocument(0) ) {
+  if (yout.preflightDocument(0)) {
     yamlize(yout, seq, true, Ctx);
     yout.postflightDocument();
   }
@@ -1935,7 +1878,8 @@ operator<<(Output &Out, T &Val) {
   if (Out.preflightDocument(0)) {
     // FIXME: The parser does not support explicit documents terminated with a
     // plain scalar; the end-marker is included as part of the scalar token.
-    assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar && "plain scalar documents are not supported");
+    assert(PolymorphicTraits<T>::getKind(Val) != NodeKind::Scalar &&
+           "plain scalar documents are not supported");
     yamlize(Out, Val, true, Ctx);
     Out.postflightDocument();
   }
@@ -1952,7 +1896,9 @@ operator<<(Output &yout, T &seq) {
 }
 
 template <bool B> struct IsFlowSequenceBase {};
-template <> struct IsFlowSequenceBase<true> { static const bool flow = true; };
+template <> struct IsFlowSequenceBase<true> {
+  static const bool flow = true;
+};
 
 template <typename T, typename U = void>
 struct IsResizable : std::false_type {};
@@ -1985,14 +1931,16 @@ template <typename T> struct IsResizableBase<T, false> {
 };
 
 template <typename T, bool Flow>
-struct SequenceTraitsImpl
-    : IsFlowSequenceBase<Flow>, IsResizableBase<T, IsResizable<T>::value> {
+struct SequenceTraitsImpl : IsFlowSequenceBase<Flow>,
+                            IsResizableBase<T, IsResizable<T>::value> {
   static size_t size(IO &io, T &seq) { return seq.size(); }
 };
 
 // Simple helper to check an expression can be used as a bool-valued template
 // argument.
-template <bool> struct CheckIsBool { static const bool value = true; };
+template <bool> struct CheckIsBool {
+  static const bool value = true;
+};
 
 // If T has SequenceElementTraits, then vector<T> and SmallVector<T, N> have
 // SequenceTraits that do the obvious thing.
@@ -2029,13 +1977,13 @@ struct SequenceElementTraits<T, std::enable_if_t<std::is_fundamental_v<T>>> {
 };
 
 // Sequences of strings use block formatting.
-template<> struct SequenceElementTraits<std::string> {
+template <> struct SequenceElementTraits<std::string> {
   static const bool flow = false;
 };
-template<> struct SequenceElementTraits<StringRef> {
+template <> struct SequenceElementTraits<StringRef> {
   static const bool flow = false;
 };
-template<> struct SequenceElementTraits<std::pair<std::string, std::string>> {
+template <> struct SequenceElementTraits<std::pair<std::string, std::string>> {
   static const bool flow = false;
 };
 


        


More information about the llvm-commits mailing list