From b4ffb2d9498560557821714e2d4651279dd6817c Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 14:03:31 +0000 Subject: feat(diagnostics): print source diagnostics in gcc file:line: layout Lexer, parser, driver and codegen diagnostics now read ":: error: " instead of "error: at line N in ". The path is always printed as given on the command line. Call sites pass the bare message to cps::sourceError/sourceWarning, which carry printf format checking; reportError routes through the same helper. The suite iii harness parses the new layout and matches the reason against the message only. iii/template-class-pack-field passed only because its reason regex matched the case path, so it is now case-insensitive. Co-Authored-By: Claude Opus 5.5 --- lib/Lexer/Lexer.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/Lexer') diff --git a/lib/Lexer/Lexer.cc b/lib/Lexer/Lexer.cc index 91ce88a..437aed4 100644 --- a/lib/Lexer/Lexer.cc +++ b/lib/Lexer/Lexer.cc @@ -12,7 +12,7 @@ using namespace cps; std::string Lexer::readEscape(bool IsChar) { auto Error = [&](const char *Reason) { - cps::sourceDiagnostic(TokenLine, "error: %s at line %d\n", Reason, TokenLine); + cps::sourceError(TokenLine, "%s", Reason); HadError = true; return std::string("?"); }; @@ -106,7 +106,7 @@ int Lexer::readToken() { Directive.pop_back(); if (Directive == "#LIB") Library = true; else { - cps::sourceDiagnostic(TokenLine, "error: Unknown compiler directive at line %d\n", TokenLine); + cps::sourceError(TokenLine, "Unknown compiler directive"); HadError = true; } return readToken(); @@ -127,12 +127,12 @@ int Lexer::readToken() { } if (LastChar == Quote) LastChar = Input.get(); else { - cps::sourceDiagnostic(TokenLine, "error: Unterminated %s literal at line %d\n", IsChar ? "char" : "string", TokenLine); + cps::sourceError(TokenLine, "Unterminated %s literal", IsChar ? "char" : "string"); HadError = true; } if (IsChar) { if (StringVal.size() != 1) { - cps::sourceDiagnostic(TokenLine, "error: CHAR literal must contain exactly one character at line %d\n", TokenLine); + cps::sourceError(TokenLine, "CHAR literal must contain exactly one character"); HadError = true; } CharVal = StringVal.size() == 1 ? StringVal[0] : '?'; @@ -154,7 +154,7 @@ int Lexer::readToken() { std::transform(Prefix.begin(), Prefix.end(), Prefix.begin(), [](unsigned char C) { return std::tolower(C); }); if (Prefix == "__cps_") { - cps::sourceDiagnostic(TokenLine, "error: Reserved runtime identifier at line %d\n", TokenLine); + cps::sourceError(TokenLine, "Reserved runtime identifier"); HadError = true; } } @@ -277,7 +277,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) { - cps::sourceDiagnostic(CurrentLine, "error: Integer literal is outside the i64 range at line %d\n", TokenLine); + cps::sourceError(TokenLine, "Integer literal is outside the i64 range"); HadError = true; NumVal = 0; } @@ -327,7 +327,7 @@ int Lexer::readToken() { LastChar = Input.get(); return tok_ellipsis; } - cps::sourceDiagnostic(CurrentLine, "error: Expected '...' at line %d\n", CurrentLine); + cps::sourceError(CurrentLine, "Expected '...'"); HadError = true; LastChar = Input.get(); return tok_ellipsis; -- cgit v1.3.1-4-g156e