[clang] e6bafbe - [TableGen] Use StringRef::consume_{front, back} (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 25 18:17:35 PST 2024


Author: Kazu Hirata
Date: 2024-01-25T18:17:24-08:00
New Revision: e6bafbe72623b3f6fd974bd7f59f38c59f1e9df3

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

LOG: [TableGen] Use StringRef::consume_{front,back} (NFC)

Added: 
    

Modified: 
    clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
    clang/utils/TableGen/NeonEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 480c7c83f5f8ef6..4512acfd19a1b9d 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -873,16 +873,12 @@ struct DiagTextDocPrinter : DiagTextVisitor<DiagTextDocPrinter> {
     auto &S = RST.back();
 
     StringRef T = P->Text;
-    while (!T.empty() && T.front() == ' ') {
+    while (T.consume_front(" "))
       RST.back() += " |nbsp| ";
-      T = T.drop_front();
-    }
 
     std::string Suffix;
-    while (!T.empty() && T.back() == ' ') {
+    while (T.consume_back(" "))
       Suffix += " |nbsp| ";
-      T = T.drop_back();
-    }
 
     if (!T.empty()) {
       S += ':';
@@ -1121,9 +1117,8 @@ Piece *DiagnosticTextBuilder::DiagText::parseDiagText(StringRef &Text,
           if (!isdigit(Text[0]))
             break;
           Sub->Modifiers.push_back(parseModifier(Text));
-          if (Text.empty() || Text[0] != ',')
+          if (!Text.consume_front(","))
             break;
-          Text = Text.drop_front(); // ','
           assert(!Text.empty() && isdigit(Text[0]) &&
                  "expected another modifier");
         }

diff  --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp
index 53334016c180a12..04e1acc27050044 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -735,20 +735,15 @@ Type Type::fromTypedefName(StringRef Name) {
   Type T;
   T.Kind = SInt;
 
-  if (Name.front() == 'u') {
+  if (Name.consume_front("u"))
     T.Kind = UInt;
-    Name = Name.drop_front();
-  }
 
-  if (Name.starts_with("float")) {
+  if (Name.consume_front("float")) {
     T.Kind = Float;
-    Name = Name.drop_front(5);
-  } else if (Name.starts_with("poly")) {
+  } else if (Name.consume_front("poly")) {
     T.Kind = Poly;
-    Name = Name.drop_front(4);
-  } else if (Name.starts_with("bfloat")) {
+  } else if (Name.consume_front("bfloat")) {
     T.Kind = BFloat16;
-    Name = Name.drop_front(6);
   } else {
     assert(Name.starts_with("int"));
     Name = Name.drop_front(3);
@@ -765,8 +760,7 @@ Type Type::fromTypedefName(StringRef Name) {
   T.Bitwidth = T.ElementBitwidth;
   T.NumVectors = 1;
 
-  if (Name.front() == 'x') {
-    Name = Name.drop_front();
+  if (Name.consume_front("x")) {
     unsigned I = 0;
     for (I = 0; I < Name.size(); ++I) {
       if (!isdigit(Name[I]))
@@ -780,8 +774,7 @@ Type Type::fromTypedefName(StringRef Name) {
     // Was scalar.
     T.NumVectors = 0;
   }
-  if (Name.front() == 'x') {
-    Name = Name.drop_front();
+  if (Name.consume_front("x")) {
     unsigned I = 0;
     for (I = 0; I < Name.size(); ++I) {
       if (!isdigit(Name[I]))


        


More information about the cfe-commits mailing list