c2c/Clang/SourceManager.cpp
/// FindNearestLineEntry - Find the line entry nearest to FID that is before
/// it.  If there is no line entry before Offset in FID, return null.
Find the line entry nearest to FID that is before
it.  If there is no line entry before Offset in FID, return null.
Find the line entry nearest to FID that is before it . If there is no line entry before Offset in FID return null .
const LineEntry *LineTableInfo::FindNearestLineEntry(FileID FID,
                                                     unsigned Offset) {
  const std::vector<LineEntry> &Entries = LineEntries[FID];
  assert(!Entries.empty() && "No #line entries for this FID after all!");
  if (Entries.back().FileOffset <= Offset)
    return &Entries.back();
  std::vector<LineEntry>::const_iterator I =
    std::upper_bound(Entries.begin(), Entries.end(), Offset);
  if (I == Entries.begin()) return nullptr;
  return &*--I;
}
const LineEntry * LineTableInfo :: FindNearestLineEntry ( FileID FID , unsigned Offset ) { const std :: vector < LineEntry > & Entries = LineEntries [ FID ] ; assert ( ! Entries . empty ( ) && " " ) ; if ( Entries . back ( ) . FileOffset <= Offset ) return & Entries . back ( ) ; std :: vector < LineEntry > :: const_iterator I = std :: upper_bound ( Entries . begin ( ) , Entries . end ( ) , Offset ) ; if ( I == Entries . begin ( ) ) return nullptr ; return & * -- I ; }
FindNearestLineEntry - Find the line entry nearest to FID that is before
it.
FindNearestLineEntry - Find the line entry nearest to FID that is before it .
// It is very common for the query to be after the last #line, check this // first. // Do a binary search to find the maximal element that is still before Offset.