[llvm] Use range-based for loops (NFC)

This commit is contained in:
Kazu Hirata 2021-12-02 09:27:47 -08:00
parent 22d82949b0
commit 262dd1e42d
10 changed files with 26 additions and 32 deletions

View File

@ -353,12 +353,11 @@ void llvm::printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name) {
// Scan the name to see if it needs quotes first.
bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
if (!NeedsQuotes) {
for (unsigned i = 0, e = Name.size(); i != e; ++i) {
for (unsigned char C : Name) {
// By making this unsigned, the value passed in to isalnum will always be
// in the range 0-255. This is important when building with MSVC because
// its implementation will assert. This situation can arise when dealing
// with UTF-8 multibyte characters.
unsigned char C = Name[i];
if (!isalnum(static_cast<unsigned char>(C)) && C != '-' && C != '.' &&
C != '_') {
NeedsQuotes = true;

View File

@ -1069,16 +1069,14 @@ void MCAsmStreamer::PrintQuotedString(StringRef Data, raw_ostream &OS) const {
OS << '"';
if (MAI->hasPairedDoubleQuoteStringConstants()) {
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
unsigned char C = Data[i];
for (unsigned char C : Data) {
if (C == '"')
OS << "\"\"";
else
OS << (char)C;
}
} else {
for (unsigned i = 0, e = Data.size(); i != e; ++i) {
unsigned char C = Data[i];
for (unsigned char C : Data) {
if (C == '"' || C == '\\') {
OS << '\\' << (char)C;
continue;

View File

@ -150,10 +150,9 @@ OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
E = PrefixesUnion.end(); I != E; ++I) {
StringRef Prefix = I->getKey();
for (StringRef::const_iterator C = Prefix.begin(), CE = Prefix.end();
C != CE; ++C)
if (!is_contained(PrefixChars, *C))
PrefixChars.push_back(*C);
for (char C : Prefix)
if (!is_contained(PrefixChars, C))
PrefixChars.push_back(C);
}
}

View File

@ -218,10 +218,10 @@ bool Regex::isLiteralERE(StringRef Str) {
std::string Regex::escape(StringRef String) {
std::string RegexStr;
for (unsigned i = 0, e = String.size(); i != e; ++i) {
if (strchr(RegexMetachars, String[i]))
for (char C : String) {
if (strchr(RegexMetachars, C))
RegexStr += '\\';
RegexStr += String[i];
RegexStr += C;
}
return RegexStr;

View File

@ -60,8 +60,7 @@ void llvm::SplitString(StringRef Source,
}
void llvm::printEscapedString(StringRef Name, raw_ostream &Out) {
for (unsigned i = 0, e = Name.size(); i != e; ++i) {
unsigned char C = Name[i];
for (unsigned char C : Name) {
if (C == '\\')
Out << '\\' << C;
else if (isPrint(C) && C != '"')

View File

@ -227,8 +227,8 @@ size_t StringRef::rfind_insensitive(StringRef Str) const {
StringRef::size_type StringRef::find_first_of(StringRef Chars,
size_t From) const {
std::bitset<1 << CHAR_BIT> CharBits;
for (size_type i = 0; i != Chars.size(); ++i)
CharBits.set((unsigned char)Chars[i]);
for (char C : Chars)
CharBits.set((unsigned char)C);
for (size_type i = std::min(From, Length), e = Length; i != e; ++i)
if (CharBits.test((unsigned char)Data[i]))
@ -252,8 +252,8 @@ StringRef::size_type StringRef::find_first_not_of(char C, size_t From) const {
StringRef::size_type StringRef::find_first_not_of(StringRef Chars,
size_t From) const {
std::bitset<1 << CHAR_BIT> CharBits;
for (size_type i = 0; i != Chars.size(); ++i)
CharBits.set((unsigned char)Chars[i]);
for (char C : Chars)
CharBits.set((unsigned char)C);
for (size_type i = std::min(From, Length), e = Length; i != e; ++i)
if (!CharBits.test((unsigned char)Data[i]))
@ -268,8 +268,8 @@ StringRef::size_type StringRef::find_first_not_of(StringRef Chars,
StringRef::size_type StringRef::find_last_of(StringRef Chars,
size_t From) const {
std::bitset<1 << CHAR_BIT> CharBits;
for (size_type i = 0; i != Chars.size(); ++i)
CharBits.set((unsigned char)Chars[i]);
for (char C : Chars)
CharBits.set((unsigned char)C);
for (size_type i = std::min(From, Length) - 1, e = -1; i != e; --i)
if (CharBits.test((unsigned char)Data[i]))
@ -293,8 +293,8 @@ StringRef::size_type StringRef::find_last_not_of(char C, size_t From) const {
StringRef::size_type StringRef::find_last_not_of(StringRef Chars,
size_t From) const {
std::bitset<1 << CHAR_BIT> CharBits;
for (size_type i = 0, e = Chars.size(); i != e; ++i)
CharBits.set((unsigned char)Chars[i]);
for (char C : Chars)
CharBits.set((unsigned char)C);
for (size_type i = std::min(From, Length) - 1, e = -1; i != e; --i)
if (!CharBits.test((unsigned char)Data[i]))

View File

@ -177,8 +177,8 @@ public:
// We can't just use EmitIntValue here, as that will emit a data mapping
// symbol, and swap the endianness on big-endian systems (instructions are
// always little-endian).
for (unsigned I = 0; I < 4; ++I) {
Buffer[I] = uint8_t(Inst);
for (char &C : Buffer) {
C = uint8_t(Inst);
Inst >>= 8;
}

View File

@ -101,8 +101,8 @@ void AArch64TargetStreamer::emitInst(uint32_t Inst) {
// We can't just use EmitIntValue here, as that will swap the
// endianness on big-endian systems (instructions are always
// little-endian).
for (unsigned I = 0; I < 4; ++I) {
Buffer[I] = uint8_t(Inst);
for (char &C : Buffer) {
C = uint8_t(Inst);
Inst >>= 8;
}

View File

@ -280,10 +280,10 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
}
LLVM_DEBUG(dbgs() << "Printf format string in source = " << Str.str()
<< '\n');
for (size_t I = 0; I < Str.size(); ++I) {
for (char C : Str) {
// Rest of the C escape sequences (e.g. \') are handled correctly
// by the MDParser
switch (Str[I]) {
switch (C) {
case '\a':
Sizes << "\\a";
break;
@ -308,7 +308,7 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
Sizes << "\\72";
break;
default:
Sizes << Str[I];
Sizes << C;
break;
}
}

View File

@ -72,8 +72,7 @@ bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) {
std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) {
std::string ValidName;
raw_string_ostream ValidNameStream(ValidName);
for (unsigned I = 0, E = Name.size(); I != E; ++I) {
char C = Name[I];
for (char C : Name) {
if (C == '.' || C == '@') {
ValidNameStream << "_$_";
} else {