aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-17 09:09:03 +0000
committer_ov4 <ov4@ov4.org>2026-10-17 09:09:03 +0000
commitdc645a36aaade7087ade574cefe69ce7bb29753e (patch)
treed10a4f3ab8947c014f79b940d4658e9ff9730e9d /lib/CodeGen
parent5097edca0619007eb4237e52fcc07f0e0b4b99e2 (diff)
refactor(diag): file-qualified diagnostic locations
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/ArithmeticHandler.cc9
-rw-r--r--lib/CodeGen/CodeGen.cc3
-rw-r--r--lib/CodeGen/ConstantGen.cc3
-rw-r--r--lib/CodeGen/FunctionGen.cc9
4 files changed, 14 insertions, 10 deletions
diff --git a/lib/CodeGen/ArithmeticHandler.cc b/lib/CodeGen/ArithmeticHandler.cc
index cd4e7b3..255da57 100644
--- a/lib/CodeGen/ArithmeticHandler.cc
+++ b/lib/CodeGen/ArithmeticHandler.cc
@@ -1,3 +1,4 @@
+#include "cps/Diagnostics.h"
#include "cps/ArithmeticHandler.h"
#include "cps/Lexer.h"
#include "cps/RuntimeCheck.h"
@@ -28,7 +29,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line)
if (LVal->getType()->isIntegerTy(64)) LVal = Builder.CreateSIToFP(LVal, Type::getDoubleTy(Context));
if (RVal->getType()->isIntegerTy(64)) RVal = Builder.CreateSIToFP(RVal, Type::getDoubleTy(Context));
if (!LVal->getType()->isDoubleTy() || !RVal->getType()->isDoubleTy()) {
- fprintf(stderr, "error: '/' requires numeric operands (line %d).\n", Line);
+ cps::sourceDiagnostic(Line, "error: '/' requires numeric operands (line %d).\n", Line);
HadError = true;
return nullptr;
}
@@ -39,7 +40,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line)
if (Op == tok_div || Op == tok_mod) {
if (!LIsInt || !RIsInt) {
- fprintf(stderr, "error: DIV and MOD operators require INTEGER operands (line %d).\n", Line);
+ cps::sourceDiagnostic(Line, "error: DIV and MOD operators require INTEGER operands (line %d).\n", Line);
HadError = true;
return nullptr;
}
@@ -96,7 +97,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line)
R = widenSmallInt(Builder, Context, R);
}
if (L->getType() != R->getType()) {
- fprintf(stderr, "error: Mismatched operand types for binary operator (line %d).\n", Line);
+ cps::sourceDiagnostic(Line, "error: Mismatched operand types for binary operator (line %d).\n", Line);
HadError = true;
return nullptr;
}
@@ -114,7 +115,7 @@ Value *ArithmeticHandler::emitBinaryOp(int Op, Value *LHS, Value *RHS, int Line)
}
}
- fprintf(stderr, "error: Unsupported operand types for binary operator (line %d).\n", Line);
+ cps::sourceDiagnostic(Line, "error: Unsupported operand types for binary operator (line %d).\n", Line);
HadError = true;
return nullptr;
}
diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc
index 0107910..d3459ef 100644
--- a/lib/CodeGen/CodeGen.cc
+++ b/lib/CodeGen/CodeGen.cc
@@ -1,3 +1,4 @@
+#include "cps/Diagnostics.h"
#include "cps/CodeGen.h"
#include "cps/ArrayHandler.h"
#include "cps/FileHandler.h"
@@ -25,7 +26,7 @@ void CodeGen::reportError(const char *Fmt, ...) {
va_start(Args, Fmt);
fprintf(stderr, "error: ");
vfprintf(stderr, Fmt, Args);
- if (DiagnosticLine) fprintf(stderr, " at line %d", DiagnosticLine);
+ if (DiagnosticLine) fprintf(stderr, "%s", lineSuffix(DiagnosticLine).c_str());
fprintf(stderr, "\n");
va_end(Args);
HadError = true;
diff --git a/lib/CodeGen/ConstantGen.cc b/lib/CodeGen/ConstantGen.cc
index 58913e4..632502d 100644
--- a/lib/CodeGen/ConstantGen.cc
+++ b/lib/CodeGen/ConstantGen.cc
@@ -1,3 +1,4 @@
+#include "cps/Diagnostics.h"
#include "cps/CodeGen.h"
#include <cstdio>
@@ -21,7 +22,7 @@ void CodeGen::warnMemberShadow(const std::string &Name, int Line) const {
const TypeInfo *Class = resolveType(CurrentClass);
const RecordPayload *Record = Class ? Class->asRecord() : nullptr;
if (Record && Record->findField(Name)) {
- fprintf(stderr, "warning: Declaration of %s shadows a field of class %s at line %d\n",
+ cps::sourceDiagnostic(Line, "warning: Declaration of %s shadows a field of class %s at line %d\n",
Name.c_str(), CurrentClass.c_str(), Line);
}
}
diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc
index 59e9bbe..b66b55a 100644
--- a/lib/CodeGen/FunctionGen.cc
+++ b/lib/CodeGen/FunctionGen.cc
@@ -1,3 +1,4 @@
+#include "cps/Diagnostics.h"
#include "cps/FunctionGen.h"
#include "cps/CodeGen.h"
#include "cps/ExceptionHandler.h"
@@ -30,7 +31,7 @@ void FunctionGen::reportError(const char *Fmt, ...) {
va_start(Args, Fmt);
fprintf(stderr, "error: ");
vfprintf(stderr, Fmt, Args);
- if (DiagnosticLine) fprintf(stderr, " at line %d", DiagnosticLine);
+ if (DiagnosticLine) fprintf(stderr, "%s", lineSuffix(DiagnosticLine).c_str());
fprintf(stderr, "\n");
va_end(Args);
HadError = true;
@@ -258,10 +259,10 @@ static Value *GenerateCall(llvm::Module &Module,
ExceptionHandler &Exceptions,
const std::string &CalleeName,
const std::vector<llvm::Value*> &Args,
- bool &HadError) {
+ bool &HadError, int DiagnosticLine) {
Function *CalleeF = Module.getFunction(CalleeName);
if (!CalleeF) {
- fprintf(stderr, "error: Call to undefined function %s\n", CalleeName.c_str());
+ sourceDiagnostic(DiagnosticLine, "error: Call to undefined function %s\n", CalleeName.c_str());
HadError = true;
return nullptr;
}
@@ -275,7 +276,7 @@ static Value *GenerateCall(llvm::Module &Module,
llvm::Value *FunctionGen::emitCall(const std::string &Callee, const std::vector<llvm::Value*> &Args) {
const FuncSig *Sig = getSignature(Callee);
- return GenerateCall(Module, Exceptions, Sig ? Sig->Name : Callee, Args, HadError);
+ return GenerateCall(Module, Exceptions, Sig ? Sig->Name : Callee, Args, HadError, DiagnosticLine);
}
void FunctionGen::emitReturn(ReturnStmtAST *Ret, llvm::Value *RetVal) {