File tree Expand file tree Collapse file tree 1 file changed +16
-29
lines changed Expand file tree Collapse file tree 1 file changed +16
-29
lines changed Original file line number Diff line number Diff line change @@ -346,39 +346,26 @@ llvm::Optional<unsigned> SourceManager::resolveFromLineCol(unsigned BufferId,
346
346
if (Line == 0 ) {
347
347
return None;
348
348
}
349
- const bool LineEnd = Col == ~0u ;
350
- auto InputBuf = getLLVMSourceMgr ().getMemoryBuffer (BufferId);
351
- const char *Ptr = InputBuf->getBufferStart ();
352
- const char *End = InputBuf->getBufferEnd ();
353
- const char *LineStart = Ptr;
354
- --Line;
355
- for (; Line && (Ptr < End); ++Ptr) {
356
- if (*Ptr == ' \n ' ) {
357
- --Line;
358
- LineStart = Ptr+1 ;
359
- }
360
- }
361
- if (Line != 0 ) {
349
+ const bool LineEnd = (Col == ~0u );
350
+ if (LineEnd)
351
+ Col = 0 ;
352
+
353
+ auto loc = const_cast <SourceManager *>(this )
354
+ ->getLLVMSourceMgr ()
355
+ .FindLocForLineAndColumn (BufferId, Line, Col);
356
+ if (!loc.isValid ())
362
357
return None;
363
- }
364
- Ptr = LineStart;
365
- if (Col == 0 ) {
366
- return Ptr - InputBuf->getBufferStart ();
367
- }
368
- // The <= here is to allow for non-inclusive range end positions at EOF
369
- for (; ; ++Ptr) {
370
- --Col;
371
- if (Col == 0 )
372
- return Ptr - InputBuf->getBufferStart ();
373
- if (*Ptr == ' \n ' || Ptr == End) {
374
- if (LineEnd) {
375
- return Ptr - InputBuf->getBufferStart ();
376
- } else {
358
+
359
+ auto InputBuf = getLLVMSourceMgr ().getMemoryBuffer (BufferId);
360
+ const char *Ptr = loc.getPointer ();
361
+ if (LineEnd) {
362
+ const char *End = InputBuf->getBufferEnd ();
363
+ for (;; ++Ptr) {
364
+ if (Ptr == End || *Ptr == ' \n ' )
377
365
break ;
378
- }
379
366
}
380
367
}
381
- return None ;
368
+ return Ptr - InputBuf-> getBufferStart () ;
382
369
}
383
370
384
371
unsigned SourceManager::getExternalSourceBufferId (StringRef Path) {
You can’t perform that action at this time.
0 commit comments