llvm.org GIT mirror llvm / 207e1bc
Instead of using an std::pair, use a custom struct. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79119 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
1 changed file(s) with 21 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
3737 static cl::opt
3838 NoCanonicalizeWhiteSpace("strict-whitespace",
3939 cl::desc("Do not treat all horizontal whitespace as equivalent"));
40
41 /// CheckString - This is a check that we found in the input file.
42 struct CheckString {
43 /// Str - The string to match.
44 std::string Str;
45
46 /// Loc - The location in the match file that the check string was specified.
47 SMLoc Loc;
48
49 CheckString(const std::string &S, SMLoc L) : Str(S), Loc(L) {}
50 };
4051
4152
4253 /// FindStringInBuffer - This is basically just a strstr wrapper that differs in
6374 /// ReadCheckFile - Read the check file, which specifies the sequence of
6475 /// expected strings. The strings are added to the CheckStrings vector.
6576 static bool ReadCheckFile(SourceMgr &SM,
66 std::vector >
67 &CheckStrings) {
77 std::vector &CheckStrings) {
6878 // Open the check file, and tell SourceMgr about it.
6979 std::string ErrorStr;
7080 MemoryBuffer *F =
114124 }
115125
116126 // Okay, add the string we captured to the output vector and move on.
117 CheckStrings.push_back(std::make_pair(std::string(Ptr, CurPtr),
118 SMLoc::getFromPointer(Ptr)));
127 CheckStrings.push_back(CheckString(std::string(Ptr, CurPtr),
128 SMLoc::getFromPointer(Ptr)));
119129 }
120130
121131 if (CheckStrings.empty()) {
128138
129139 // CanonicalizeCheckStrings - Replace all sequences of horizontal whitespace in
130140 // the check strings with a single space.
131 static void CanonicalizeCheckStrings(std::vector >
132 &CheckStrings) {
141 static void CanonicalizeCheckStrings(std::vector &CheckStrings) {
133142 for (unsigned i = 0, e = CheckStrings.size(); i != e; ++i) {
134 std::string &Str = CheckStrings[i].first;
143 std::string &Str = CheckStrings[i].Str;
135144
136145 for (unsigned C = 0; C != Str.size(); ++C) {
137146 // If C is not a horizontal whitespace, skip it.
189198 SourceMgr SM;
190199
191200 // Read the expected strings from the check file.
192 std::vector<std::pair > CheckStrings;
201 std::vector<CheckString> CheckStrings;
193202 if (ReadCheckFile(SM, CheckStrings))
194203 return 2;
195204
218227 const char *CurPtr = F->getBufferStart(), *BufferEnd = F->getBufferEnd();
219228
220229 for (unsigned StrNo = 0, e = CheckStrings.size(); StrNo != e; ++StrNo) {
221 const std::pair &CheckStr = CheckStrings[StrNo];
230 const CheckString &CheckStr = CheckStrings[StrNo];
222231
223232 // Find StrNo in the file.
224 const char *Ptr = FindStringInBuffer(CheckStr.first.c_str(), CurPtr, *F);
233 const char *Ptr = FindStringInBuffer(CheckStr.Str.c_str(), CurPtr, *F);
225234
226235 // If we found a match, we're done, move on.
227236 if (Ptr != BufferEnd) {
228 CurPtr = Ptr + CheckStr.first.size();
237 CurPtr = Ptr + CheckStr.Str.size();
229238 continue;
230239 }
231240
232241 // Otherwise, we have an error, emit an error message.
233 SM.PrintMessage(CheckStr.second, "expected string not found in input",
242 SM.PrintMessage(CheckStr.Loc, "expected string not found in input",
234243 "error");
235244
236245 // Print the "scanning from here" line. If the current position is at the