-bool LLLexer::Error(LocTy ErrorLoc, const std::string &Msg) const {
- // Scan backward to find the start of the line.
- const char *LineStart = ErrorLoc;
- while (LineStart != CurBuf->getBufferStart() &&
- LineStart[-1] != '\n' && LineStart[-1] != '\r')
- --LineStart;
- // Get the end of the line.
- const char *LineEnd = ErrorLoc;
- while (LineEnd != CurBuf->getBufferEnd() &&
- LineEnd[0] != '\n' && LineEnd[0] != '\r')
- ++LineEnd;
-
- unsigned LineNo = 1;
- for (const char *FP = CurBuf->getBufferStart(); FP != ErrorLoc; ++FP)
- if (*FP == '\n') ++LineNo;
-
- std::string LineContents(LineStart, LineEnd);
- ErrorInfo.setError(Msg, LineNo, ErrorLoc-LineStart, LineContents);
+bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
+ ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");