From dc645a36aaade7087ade574cefe69ce7bb29753e Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 09:09:03 +0000 Subject: refactor(diag): file-qualified diagnostic locations Co-Authored-By: Claude Opus 5.5 --- lib/Lexer/Lexer.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/Lexer') diff --git a/lib/Lexer/Lexer.cc b/lib/Lexer/Lexer.cc index 61785c7..acdedd0 100644 --- a/lib/Lexer/Lexer.cc +++ b/lib/Lexer/Lexer.cc @@ -1,3 +1,4 @@ +#include "cps/Diagnostics.h" #include "cps/Lexer.h" #include #include @@ -29,7 +30,7 @@ int Lexer::readToken() { if (LastChar == '"') { LastChar = Input.get(); } else { - fprintf(stderr, "error: Unterminated string literal at line %d\n", CurrentLine); + cps::sourceDiagnostic(CurrentLine, "error: Unterminated string literal at line %d\n", CurrentLine); HadError = true; } @@ -39,7 +40,7 @@ int Lexer::readToken() { if (LastChar == '\'') { int CharCode = Input.get(); if (CharCode == EOF || CharCode == '\n') { - fprintf(stderr, "error: Unterminated char literal at line %d\n", CurrentLine); + cps::sourceDiagnostic(CurrentLine, "error: Unterminated char literal at line %d\n", CurrentLine); HadError = true; CharVal = '?'; StringVal.assign(1, CharVal); @@ -50,7 +51,7 @@ int Lexer::readToken() { int ClosingQuote = Input.get(); if (ClosingQuote != '\'') { - fprintf(stderr, "error: CHAR literal must contain exactly one character (line %d)\n", CurrentLine); + cps::sourceDiagnostic(CurrentLine, "error: CHAR literal must contain exactly one character (line %d)\n", CurrentLine); HadError = true; while (ClosingQuote != EOF && ClosingQuote != '\n' && ClosingQuote != '\'') { ClosingQuote = Input.get(); @@ -181,7 +182,7 @@ int Lexer::readToken() { auto Parsed = std::from_chars(NumStr.data(), NumStr.data() + NumStr.size(), NumVal); if (Parsed.ec != std::errc{} || NumVal > uint64_t(std::numeric_limits::max()) + 1) { - fprintf(stderr, "error: Integer literal is outside the i64 range at line %d\n", TokenLine); + cps::sourceDiagnostic(CurrentLine, "error: Integer literal is outside the i64 range at line %d\n", TokenLine); HadError = true; NumVal = 0; } -- cgit v1.3.1-4-g156e