Improve incompatible type error message
This commit is contained in:
parent
f7d6b52074
commit
6cb15fd7d9
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue