TmpStr = RegExStr;
unsigned InsertOffset = 0;
- for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
+ for (const auto &VariableUse : VariableUses) {
std::string Value;
- if (VariableUses[i].first[0] == '@') {
- if (!EvaluateExpression(VariableUses[i].first, Value))
+ if (VariableUse.first[0] == '@') {
+ if (!EvaluateExpression(VariableUse.first, Value))
return StringRef::npos;
} else {
StringMap<StringRef>::iterator it =
- VariableTable.find(VariableUses[i].first);
+ VariableTable.find(VariableUse.first);
// If the variable is undefined, return an error.
if (it == VariableTable.end())
return StringRef::npos;
}
// Plop it into the regex at the adjusted offset.
- TmpStr.insert(TmpStr.begin()+VariableUses[i].second+InsertOffset,
+ TmpStr.insert(TmpStr.begin() + VariableUse.second + InsertOffset,
Value.begin(), Value.end());
InsertOffset += Value.size();
}
StringRef FullMatch = MatchInfo[0];
// If this defines any variables, remember their values.
- for (std::map<StringRef, unsigned>::const_iterator I = VariableDefs.begin(),
- E = VariableDefs.end();
- I != E; ++I) {
- assert(I->second < MatchInfo.size() && "Internal paren error");
- VariableTable[I->first] = MatchInfo[I->second];
+ for (const auto &VariableDef : VariableDefs) {
+ assert(VariableDef.second < MatchInfo.size() && "Internal paren error");
+ VariableTable[VariableDef.first] = MatchInfo[VariableDef.second];
}
MatchLen = FullMatch.size();
// If this was a regular expression using variables, print the current
// variable values.
if (!VariableUses.empty()) {
- for (unsigned i = 0, e = VariableUses.size(); i != e; ++i) {
+ for (const auto &VariableUse : VariableUses) {
SmallString<256> Msg;
raw_svector_ostream OS(Msg);
- StringRef Var = VariableUses[i].first;
+ StringRef Var = VariableUse.first;
if (Var[0] == '@') {
std::string Value;
if (EvaluateExpression(Var, Value)) {
CheckTy = Check::CheckNone;
CheckLoc = StringRef::npos;
- for (prefix_iterator I = CheckPrefixes.begin(), E = CheckPrefixes.end();
- I != E; ++I) {
- StringRef Prefix(*I);
+ for (StringRef Prefix : CheckPrefixes) {
size_t PrefixLoc = Buffer.find(Prefix);
if (PrefixLoc == StringRef::npos)
for (const auto &PatternString : ImplicitCheckNot) {
// Create a buffer with fake command line content in order to display the
// command line option responsible for the specific implicit CHECK-NOT.
- std::string Prefix = std::string("-") + ImplicitCheckNot.ArgStr + "='";
+ std::string Prefix = (Twine("-") + ImplicitCheckNot.ArgStr + "='").str();
std::string Suffix = "'";
std::unique_ptr<MemoryBuffer> CmdLine = MemoryBuffer::getMemBufferCopy(
Prefix + PatternString + Suffix, "command line");
}
// Okay, add the string we captured to the output vector and move on.
- CheckStrings.push_back(CheckString(P,
- UsedPrefix,
- PatternLoc,
- CheckTy));
+ CheckStrings.emplace_back(P, UsedPrefix, PatternLoc, CheckTy);
std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
DagNotMatches = ImplicitNegativeChecks;
}
// Add an EOF pattern for any trailing CHECK-DAG/-NOTs, and use the first
// prefix as a filler for the error message.
if (!DagNotMatches.empty()) {
- CheckStrings.push_back(CheckString(Pattern(Check::CheckEOF),
- CheckPrefixes[0],
- SMLoc::getFromPointer(Buffer.data()),
- Check::CheckEOF));
+ CheckStrings.emplace_back(Pattern(Check::CheckEOF), *CheckPrefixes.begin(),
+ SMLoc::getFromPointer(Buffer.data()),
+ Check::CheckEOF);
std::swap(DagNotMatches, CheckStrings.back().DagNotStrings);
}
if (CheckStrings.empty()) {
errs() << "error: no check strings found with prefix"
<< (CheckPrefixes.size() > 1 ? "es " : " ");
- for (size_t I = 0, N = CheckPrefixes.size(); I != N; ++I) {
- StringRef Prefix(CheckPrefixes[I]);
- errs() << '\'' << Prefix << ":'";
- if (I != N - 1)
- errs() << ", ";
+ prefix_iterator I = CheckPrefixes.begin();
+ prefix_iterator E = CheckPrefixes.end();
+ if (I != E) {
+ errs() << "\'" << *I << ":'";
+ ++I;
}
+ for (; I != E; ++I)
+ errs() << ", \'" << *I << ":'";
errs() << '\n';
return true;
return false;
}
-static void PrintCheckFailed(const SourceMgr &SM, const SMLoc &Loc,
+static void PrintCheckFailed(const SourceMgr &SM, SMLoc Loc,
const Pattern &Pat, StringRef Buffer,
StringMap<StringRef> &VariableTable) {
// Otherwise, we have an error, emit an error message.
PrintCheckFailed(SM, *this, MatchBuffer, VariableTable);
return StringRef::npos;
}
- MatchPos += LastPos;
// Similar to the above, in "label-scan mode" we can't yet handle CHECK-NEXT
// or CHECK-NOT
return StringRef::npos;
}
- return MatchPos;
+ return LastPos + MatchPos;
}
bool CheckString::CheckNext(const SourceMgr &SM, StringRef Buffer) const {
bool CheckString::CheckNot(const SourceMgr &SM, StringRef Buffer,
const std::vector<const Pattern *> &NotStrings,
StringMap<StringRef> &VariableTable) const {
- for (unsigned ChunkNo = 0, e = NotStrings.size();
- ChunkNo != e; ++ChunkNo) {
- const Pattern *Pat = NotStrings[ChunkNo];
+ for (const Pattern *Pat : NotStrings) {
assert((Pat->getCheckTy() == Check::CheckNot) && "Expect CHECK-NOT!");
size_t MatchLen = 0;
size_t LastPos = 0;
size_t StartPos = LastPos;
- for (unsigned ChunkNo = 0, e = DagNotStrings.size();
- ChunkNo != e; ++ChunkNo) {
- const Pattern &Pat = DagNotStrings[ChunkNo];
-
+ for (const Pattern &Pat : DagNotStrings) {
assert((Pat.getCheckTy() == Check::CheckDAG ||
Pat.getCheckTy() == Check::CheckNot) &&
"Invalid CHECK-DAG or CHECK-NOT!");
static bool ValidateCheckPrefixes() {
StringSet<> PrefixSet;
- for (prefix_iterator I = CheckPrefixes.begin(), E = CheckPrefixes.end();
- I != E; ++I) {
- StringRef Prefix(*I);
-
+ for (StringRef Prefix : CheckPrefixes) {
// Reject empty prefixes.
if (Prefix == "")
return false;