Skip to content

Commit

Permalink
[TableGen] Use StringRef::consume_{front,back} (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Jan 26, 2024
1 parent eeb0e9f commit e6bafbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
11 changes: 3 additions & 8 deletions clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 += ':';
Expand Down Expand Up @@ -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");
}
Expand Down
19 changes: 6 additions & 13 deletions clang/utils/TableGen/NeonEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]))
Expand All @@ -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]))
Expand Down

0 comments on commit e6bafbe

Please sign in to comment.