@@ -155,15 +155,6 @@ static bool isLabelChar(char C) {
155
155
C == ' .' || C == ' _' ;
156
156
}
157
157
158
- // / isLabelTail - Return true if this pointer points to a valid end of a label.
159
- static const char *isLabelTail (const char *CurPtr) {
160
- while (true ) {
161
- if (CurPtr[0 ] == ' :' ) return CurPtr+1 ;
162
- if (!isLabelChar (CurPtr[0 ])) return nullptr ;
163
- ++CurPtr;
164
- }
165
- }
166
-
167
158
// ===----------------------------------------------------------------------===//
168
159
// Lexer definition.
169
160
// ===----------------------------------------------------------------------===//
@@ -174,28 +165,27 @@ LLLexer::LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &Err,
174
165
CurPtr = CurBuf.begin ();
175
166
}
176
167
168
+ const char *LLLexer::getLabelTail (const char *Ptr) {
169
+ while (Ptr != CurBuf.end ()) {
170
+ if (Ptr[0 ] == ' :' )
171
+ return Ptr + 1 ;
172
+ if (!isLabelChar (Ptr[0 ]))
173
+ return nullptr ;
174
+ ++Ptr;
175
+ }
176
+ return nullptr ;
177
+ }
178
+
177
179
int LLLexer::getNextChar () {
178
- char CurChar = *CurPtr++;
180
+ if (CurPtr == CurBuf.end ())
181
+ return EOF;
179
182
// Increment line number if this is the first character after a newline
180
- // CurPtr points to the char after CurChar, so two positions before that
181
- if ((CurPtr - 2 ) >= CurBuf.begin () && *(CurPtr - 2 ) == ' \n ' ) {
183
+ if (CurPtr > CurBuf.begin () && *(CurPtr-1 ) == ' \n ' ){
182
184
CurLineNum++;
183
185
CurColNum = 0 ;
184
186
} else
185
187
CurColNum++;
186
-
187
- switch (CurChar) {
188
- default : return (unsigned char )CurChar;
189
- case 0 :
190
- // A nul character in the stream is either the end of the current buffer or
191
- // a random nul in the file. Disambiguate that here.
192
- if (CurPtr-1 != CurBuf.end ())
193
- return 0 ; // Just whitespace.
194
-
195
- // Otherwise, return end of file.
196
- --CurPtr; // Another call to lex will return EOF again.
197
- return EOF;
198
- }
188
+ return *CurPtr++;
199
189
}
200
190
201
191
const char *LLLexer::skipNChars (unsigned N) {
@@ -210,7 +200,7 @@ void LLLexer::advancePositionTo(const char *Ptr) {
210
200
if (CurPtr > Ptr) {
211
201
--CurPtr;
212
202
--CurColNum;
213
- // Since CurPtr is one char ahead of the stored position, chech if the
203
+ // Since CurPtr is one char ahead of the stored position, check if the
214
204
// previous char is not a newline
215
205
if (CurPtr != CurBuf.begin () && *(CurPtr - 1 ) == ' \n ' ) {
216
206
--CurLineNum;
@@ -264,7 +254,7 @@ lltok::Kind LLLexer::LexToken() {
264
254
case ' %' : return LexPercent ();
265
255
case ' "' : return LexQuote ();
266
256
case ' .' :
267
- if (const char *Ptr = isLabelTail (CurPtr)) {
257
+ if (const char *Ptr = getLabelTail (CurPtr)) {
268
258
advancePositionTo (Ptr);
269
259
StrVal.assign (TokStart, CurPtr-1 );
270
260
return lltok::LabelStr;
@@ -347,7 +337,7 @@ lltok::Kind LLLexer::LexAt() {
347
337
}
348
338
349
339
lltok::Kind LLLexer::LexDollar () {
350
- if (const char *Ptr = isLabelTail (TokStart)) {
340
+ if (const char *Ptr = getLabelTail (TokStart)) {
351
341
advancePositionTo (Ptr);
352
342
StrVal.assign (TokStart, CurPtr - 1 );
353
343
return lltok::LabelStr;
@@ -1198,7 +1188,7 @@ lltok::Kind LLLexer::LexDigitOrNegative() {
1198
1188
if (!isdigit (static_cast <unsigned char >(TokStart[0 ])) &&
1199
1189
!isdigit (static_cast <unsigned char >(CurPtr[0 ]))) {
1200
1190
// Okay, this is not a number after the -, it's probably a label.
1201
- if (const char *End = isLabelTail (CurPtr)) {
1191
+ if (const char *End = getLabelTail (CurPtr)) {
1202
1192
StrVal.assign (TokStart, End-1 );
1203
1193
advancePositionTo (End);
1204
1194
return lltok::LabelStr;
@@ -1225,7 +1215,7 @@ lltok::Kind LLLexer::LexDigitOrNegative() {
1225
1215
1226
1216
// Check to see if this really is a string label, e.g. "-1:".
1227
1217
if (isLabelChar (CurPtr[0 ]) || CurPtr[0 ] == ' :' ) {
1228
- if (const char *End = isLabelTail (CurPtr)) {
1218
+ if (const char *End = getLabelTail (CurPtr)) {
1229
1219
StrVal.assign (TokStart, End-1 );
1230
1220
advancePositionTo (End);
1231
1221
return lltok::LabelStr;
0 commit comments