| 177 | } |
| 178 | |
| 179 | std::pair<unsigned, unsigned> |
| 180 | SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const { |
| 181 | if (!BufferID) |
| 182 | BufferID = FindBufferContainingLoc(Loc); |
| 183 | assert(BufferID && "Invalid Location!"); |
| 184 | |
| 185 | auto &SB = getBufferInfo(BufferID); |
| 186 | const char *Ptr = Loc.getPointer(); |
| 187 | |
| 188 | unsigned LineNo = SB.getLineNumber(Ptr); |
| 189 | const char *BufStart = SB.Buffer->getBufferStart(); |
| 190 | size_t NewlineOffs = StringRef(BufStart, Ptr - BufStart).find_last_of("\n\r"); |
| 191 | if (NewlineOffs == StringRef::npos) |
| 192 | NewlineOffs = ~(size_t)0; |
| 193 | return std::make_pair(LineNo, Ptr - BufStart - NewlineOffs); |
| 194 | } |
| 195 | |
| 196 | /// Given a line and column number in a mapped buffer, turn it into an SMLoc. |
| 197 | /// This will return a null SMLoc if the line/column location is invalid. |
nothing calls this directly
no test coverage detected