aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-21 14:03:31 +0000
committer_ov4 <ov4@ov4.org>2026-10-21 14:03:31 +0000
commitb4ffb2d9498560557821714e2d4651279dd6817c (patch)
tree995ad02bdb8cc461f48a53683c4fd7f2ddd8656b /tools
parentf1f5fa394a67a789914ccf2b24d534a0e466ae1b (diff)
feat(diagnostics): print source diagnostics in gcc file:line: layout
Lexer, parser, driver and codegen diagnostics now read "<path>:<line>: error: <message>" instead of "error: <message> at line N in <path>". 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 <noreply@anthropic.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/driver/main.cc28
1 files changed, 14 insertions, 14 deletions
diff --git a/tools/driver/main.cc b/tools/driver/main.cc
index a55d1af..b705843 100644
--- a/tools/driver/main.cc
+++ b/tools/driver/main.cc
@@ -159,7 +159,7 @@ int main(int argc, char **argv) {
llvm::errs() << "cpsc: fatal error: cannot open source file '" << InputPath << "'\n";
return compilationTerminated();
}
- cps::DiagnosticSource = InputPaths.size() > 1 ? InputPath : "";
+ cps::DiagnosticSource = InputPath;
cps::Lexer Lex(Input);
cps::Parser Parser(Lex);
Programs[I] = Parser.Parse();
@@ -176,7 +176,7 @@ int main(int argc, char **argv) {
Units.back().Visible[J] = true;
}
for (size_t I = 0; I < Units.size(); ++I) {
- cps::DiagnosticSource = Units.size() > 1 ? Units[I].Path : "";
+ cps::DiagnosticSource = Units[I].Path;
for (const auto &Stmt : Units[I].Statements) {
auto *Include = dynamic_cast<cps::IncludeStmtAST*>(Stmt.get());
if (!Include) continue;
@@ -193,9 +193,9 @@ int main(int argc, char **argv) {
}
}
if (!Found) {
- cps::sourceDiagnostic(Stmt->getLine(),
- "error: cannot INCLUDE '%s': not given on the command line at line %d\n",
- Include->getPath().c_str(), Stmt->getLine());
+ cps::sourceError(Stmt->getLine(),
+ "cannot INCLUDE '%s': not given on the command line",
+ Include->getPath().c_str());
return compilationTerminated();
}
}
@@ -212,7 +212,7 @@ int main(int argc, char **argv) {
llvm::StringSet<> ExternSymbols;
bool LibcLoaded = false;
for (size_t I = 0; I < Units.size(); ++I) {
- cps::DiagnosticSource = Units.size() > 1 ? Units[I].Path : "";
+ cps::DiagnosticSource = Units[I].Path;
for (const auto &Stmt : Units[I].Statements) {
auto *Object = dynamic_cast<cps::IncludeObjStmtAST*>(Stmt.get());
if (!Object) continue;
@@ -227,9 +227,9 @@ int main(int argc, char **argv) {
llvm::sys::path::append(Path, Object->getPath());
}
if (llvm::sys::path::extension(Path) != ".o") {
- cps::sourceDiagnostic(Stmt->getLine(),
- "error: INCLUDE_OBJ '%s' must name a .o object file or \"__libc\" at line %d\n",
- Object->getPath().c_str(), Stmt->getLine());
+ cps::sourceError(Stmt->getLine(),
+ "INCLUDE_OBJ '%s' must name a .o object file or \"__libc\"",
+ Object->getPath().c_str());
return compilationTerminated();
}
bool Seen = false;
@@ -238,8 +238,8 @@ int main(int argc, char **argv) {
if (Seen) continue;
std::string Error;
if (!collectObjectSymbols(Path, ExternSymbols, Error)) {
- cps::sourceDiagnostic(Stmt->getLine(), "error: cannot INCLUDE_OBJ '%s': %s at line %d\n",
- Object->getPath().c_str(), Error.c_str(), Stmt->getLine());
+ cps::sourceError(Stmt->getLine(), "cannot INCLUDE_OBJ '%s': %s",
+ Object->getPath().c_str(), Error.c_str());
return compilationTerminated();
}
Objects.push_back(std::string(Path));
@@ -247,12 +247,12 @@ int main(int argc, char **argv) {
}
bool MissingSymbol = false;
for (size_t I = 0; I < Units.size(); ++I) {
- cps::DiagnosticSource = Units.size() > 1 ? Units[I].Path : "";
+ cps::DiagnosticSource = Units[I].Path;
for (const auto &Stmt : Units[I].Statements) {
auto *Extern = dynamic_cast<cps::ExternDeclAST*>(Stmt.get());
if (!Extern || ExternSymbols.contains(Extern->getProto()->getName())) continue;
- cps::sourceDiagnostic(Stmt->getLine(), "error: C symbol '%s' not found in any INCLUDE_OBJ at line %d\n",
- Extern->getProto()->getName().c_str(), Stmt->getLine());
+ cps::sourceError(Stmt->getLine(), "C symbol '%s' not found in any INCLUDE_OBJ",
+ Extern->getProto()->getName().c_str());
MissingSymbol = true;
}
}