From 6cb15fd7d9bfccaefde52dca55d35540f1974b86 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:27:09 +0200 Subject: [PATCH] Improve incompatible type error message --- oscar64/Declaration.cpp | 3 +++ oscar64/Errors.cpp | 21 +++++++++++++-------- oscar64/Errors.h | 4 ++-- oscar64/InterCodeGenerator.cpp | 14 +++++++------- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 1e19268..19ab071 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -1153,6 +1153,9 @@ Declaration* Declaration::Last(void) const Ident* Declaration::MangleIdent(void) { + if (!this) + return Ident::Unique("null"); + if (!mMangleIdent) { if (mType == DT_CONST_INTEGER) diff --git a/oscar64/Errors.cpp b/oscar64/Errors.cpp index 5522e47..dc8c13d 100644 --- a/oscar64/Errors.cpp +++ b/oscar64/Errors.cpp @@ -9,15 +9,18 @@ Errors::Errors(void) } -void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const Ident* info) +void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const Ident* info1, const Ident* info2) { - if (info) - this->Error(loc, eid, msg, info->mString); - else + if (!info1) this->Error(loc, eid, msg); + else if (!info2) + this->Error(loc, eid, msg, info1->mString); + else + this->Error(loc, eid, msg, info1->mString, info2->mString); } -void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const char* info) + +void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const char* info1, const char * info2) { const char* level = "info"; if (eid >= EERR_GENERIC) @@ -30,10 +33,12 @@ void Errors::Error(const Location& loc, ErrorID eid, const char* msg, const char level = "warning"; } - if (info) - fprintf(stderr, "%s(%d, %d) : %s %d: %s '%s'\n", loc.mFileName, loc.mLine, loc.mColumn, level ,eid, msg, info); - else + if (!info1) fprintf(stderr, "%s(%d, %d) : %s %d: %s\n", loc.mFileName, loc.mLine, loc.mColumn, level, eid, msg); + else if (!info2) + fprintf(stderr, "%s(%d, %d) : %s %d: %s '%s'\n", loc.mFileName, loc.mLine, loc.mColumn, level ,eid, msg, info1); + else + fprintf(stderr, "%s(%d, %d) : %s %d: %s '%s' != '%s'\n", loc.mFileName, loc.mLine, loc.mColumn, level, eid, msg, info1, info2); if (mErrorCount > 10 || eid >= EFATAL_GENERIC) exit(20); diff --git a/oscar64/Errors.h b/oscar64/Errors.h index f26cefd..e2b734f 100644 --- a/oscar64/Errors.h +++ b/oscar64/Errors.h @@ -110,6 +110,6 @@ public: int mErrorCount; - void Error(const Location& loc, ErrorID eid, const char* msg, const Ident * info); - void Error(const Location& loc, ErrorID eid, const char* msg, const char* info = nullptr); + void Error(const Location& loc, ErrorID eid, const char* msg, const Ident* info1, const Ident* info2 = nullptr); + void Error(const Location& loc, ErrorID eid, const char* msg, const char* info1 = nullptr, const char* info2 = nullptr); }; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 79c9bdc..907fc73 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -1244,7 +1244,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro if (!(pdec && pdec->mBase->IsReference()) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION)) { if (pdec && !pdec->mBase->CanAssign(vr.mType)) - mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); + mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types", pdec->mBase->MangleIdent(), vr.mType->MangleIdent()); vr = Dereference(proc, texp, block, vr, 1); @@ -1273,7 +1273,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateInline(Declaration* pro if (!pdec->mBase->CanAssign(vr.mType)) { pdec->mBase->CanAssign(vr.mType); - mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); + mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types", pdec->mBase->MangleIdent(), vr.mType->MangleIdent()); } vr = CoerceType(proc, texp, block, vr, pdec->mBase); } @@ -2076,7 +2076,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (!vl.mType->CanAssign(vr.mType)) { vl.mType->CanAssign(vr.mType); - mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types", vl.mType->MangleIdent(), vr.mType->MangleIdent()); } } @@ -2178,7 +2178,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Invalid pointer assignment"); if (!vr.mType->IsIntegerType()) - mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Invalid argument for pointer inc/dec"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Invalid argument for pointer inc/dec", vr.mType->MangleIdent()); cins->mDst.mType = IT_INT16; cins->mDst.mTemp = proc->AddTemporary(cins->mDst.mType); @@ -2997,7 +2997,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* else if ((mCompilerOptions & COPT_CPLUSPLUS) && (vl.mType->mBase->IsSubType(vr.mType->mBase) || vr.mType->mBase->IsSubType(vl.mType->mBase))) ; else if (!vl.mType->mBase->IsConstSame(vr.mType->mBase)) - mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible pointer types"); + mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible pointer types", vl.mType->mBase->MangleIdent(), vr.mType->mBase->MangleIdent()); } else mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible pointer types"); @@ -3514,7 +3514,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (!(pdec && pdec->mBase->IsReference()) && (vr.mType->mType == DT_TYPE_STRUCT || vr.mType->mType == DT_TYPE_UNION)) { if (pdec && !pdec->mBase->CanAssign(vr.mType)) - mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); + mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types", pdec->mBase->MangleIdent(), vr.mType->MangleIdent()); vr = Dereference(proc, texp, block, vr, 1); @@ -3569,7 +3569,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* if (!(pdec->mFlags & DTF_FPARAM_UNUSED) && !pdec->mBase->CanAssign(vr.mType)) { pdec->mBase->CanAssign(vr.mType); - mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types"); + mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types", pdec->mBase->MangleIdent(), vr.mType->MangleIdent()); } vr = CoerceType(proc, texp, block, vr, pdec->mBase); }