@@ -180,11 +180,6 @@ int LLLexer::getNextChar() {
180
180
if (CurPtr == CurBuf.end ())
181
181
return EOF;
182
182
// Increment line number if this is the first character after a newline
183
- if (CurPtr > CurBuf.begin () && *(CurPtr - 1 ) == ' \n ' ) {
184
- CurLineNum++;
185
- CurColNum = 0 ;
186
- } else
187
- CurColNum++;
188
183
return *CurPtr++;
189
184
}
190
185
@@ -195,44 +190,28 @@ const char *LLLexer::skipNChars(unsigned N) {
195
190
}
196
191
197
192
void LLLexer::advancePositionTo (const char *Ptr) {
198
- bool RecalculateColumn = false ;
199
- while (CurPtr != Ptr) {
200
- if (CurPtr > Ptr) {
201
- --CurPtr;
202
- --CurColNum;
203
- // Since CurPtr is one char ahead of the stored position, check if the
204
- // previous char is not a newline
205
- if (CurPtr != CurBuf.begin () && *(CurPtr - 1 ) == ' \n ' ) {
206
- --CurLineNum;
207
- RecalculateColumn = true ;
208
- }
209
- } else
210
- getNextChar ();
193
+ if (CurBuf.begin () > Ptr) {
194
+ CurPtr = CurBuf.begin ();
195
+ return ;
211
196
}
212
- if (RecalculateColumn) {
213
- CurColNum = 0 ;
214
- // Count the number of chars to the previous newline or start of buffer
215
- for (const char *Ptr = CurPtr; Ptr != CurBuf.begin () && *(Ptr - 1 ) != ' \n ' ;
216
- --Ptr, ++CurColNum)
217
- ;
197
+ if (CurBuf.end () < Ptr) {
198
+ CurPtr = CurBuf.end ();
199
+ return ;
218
200
}
201
+
202
+ CurPtr = Ptr;
219
203
}
220
204
221
205
lltok::Kind LLLexer::LexToken () {
222
206
// Set token end to next location, since the end is
223
207
// exclusive
224
- if (CurPtr != CurBuf.begin () && *(CurPtr - 1 ) == ' \n ' ) {
225
- PrevTokEndLineNum = CurLineNum + 1 ;
226
- PrevTokEndColNum = 0 ;
227
- } else {
228
- PrevTokEndLineNum = CurLineNum;
229
- PrevTokEndColNum = CurColNum + 1 ;
230
- }
208
+ std::tie (PrevTokEndLineNum, PrevTokEndColNum) =
209
+ SM.getLineAndColumn (SMLoc::getFromPointer (CurPtr));
231
210
while (true ) {
232
211
TokStart = CurPtr;
212
+ std::tie (CurTokLineNum, CurTokColNum) =
213
+ SM.getLineAndColumn (SMLoc::getFromPointer (CurPtr));
233
214
int CurChar = getNextChar ();
234
- CurTokColNum = CurColNum;
235
- CurTokLineNum = CurLineNum;
236
215
237
216
switch (CurChar) {
238
217
default :
0 commit comments