Fix const void pointer assignment check
This commit is contained in:
parent
485282019b
commit
2479ec5dd8
|
@ -900,7 +900,7 @@ bool Declaration::CanAssign(const Declaration* fromType) const
|
|||
if (fromType->mType == DT_TYPE_POINTER || fromType->mType == DT_TYPE_ARRAY)
|
||||
{
|
||||
if (mBase->mType == DT_TYPE_VOID || fromType->mBase->mType == DT_TYPE_VOID)
|
||||
return true;
|
||||
return (mBase->mFlags & DTF_CONST) || !(fromType->mBase->mFlags & DTF_CONST);
|
||||
else if (mBase->IsSubType(fromType->mBase))
|
||||
return true;
|
||||
}
|
||||
|
@ -937,8 +937,8 @@ bool Declaration::IsSimpleType(void) const
|
|||
}
|
||||
|
||||
|
||||
Declaration* TheVoidTypeDeclaration, * TheSignedIntTypeDeclaration, * TheUnsignedIntTypeDeclaration, * TheConstCharTypeDeclaration, * TheCharTypeDeclaration, * TheSignedCharTypeDeclaration, * TheUnsignedCharTypeDeclaration;
|
||||
Declaration* TheBoolTypeDeclaration, * TheFloatTypeDeclaration, * TheVoidPointerTypeDeclaration, * TheSignedLongTypeDeclaration, * TheUnsignedLongTypeDeclaration;
|
||||
Declaration* TheVoidTypeDeclaration, * TheConstVoidTypeDeclaration, * TheSignedIntTypeDeclaration, * TheUnsignedIntTypeDeclaration, * TheConstCharTypeDeclaration, * TheCharTypeDeclaration, * TheSignedCharTypeDeclaration, * TheUnsignedCharTypeDeclaration;
|
||||
Declaration* TheBoolTypeDeclaration, * TheFloatTypeDeclaration, * TheConstVoidPointerTypeDeclaration, * TheVoidPointerTypeDeclaration, * TheSignedLongTypeDeclaration, * TheUnsignedLongTypeDeclaration;
|
||||
Declaration* TheVoidFunctionTypeDeclaration, * TheConstVoidValueDeclaration;
|
||||
Declaration* TheCharPointerTypeDeclaration, * TheConstCharPointerTypeDeclaration;
|
||||
|
||||
|
@ -948,11 +948,19 @@ void InitDeclarations(void)
|
|||
TheVoidTypeDeclaration = new Declaration(noloc, DT_TYPE_VOID);
|
||||
TheVoidTypeDeclaration->mFlags = DTF_DEFINED;
|
||||
|
||||
TheConstVoidTypeDeclaration = new Declaration(noloc, DT_TYPE_VOID);
|
||||
TheConstVoidTypeDeclaration->mFlags = DTF_DEFINED | DTF_CONST;
|
||||
|
||||
TheVoidPointerTypeDeclaration = new Declaration(noloc, DT_TYPE_POINTER);
|
||||
TheVoidPointerTypeDeclaration->mBase = TheVoidTypeDeclaration;
|
||||
TheVoidPointerTypeDeclaration->mSize = 2;
|
||||
TheVoidPointerTypeDeclaration->mFlags = DTF_DEFINED;
|
||||
|
||||
TheConstVoidPointerTypeDeclaration = new Declaration(noloc, DT_TYPE_POINTER);
|
||||
TheConstVoidPointerTypeDeclaration->mBase = TheConstVoidTypeDeclaration;
|
||||
TheConstVoidPointerTypeDeclaration->mSize = 2;
|
||||
TheConstVoidPointerTypeDeclaration->mFlags = DTF_DEFINED;
|
||||
|
||||
TheVoidFunctionTypeDeclaration = new Declaration(noloc, DT_TYPE_FUNCTION);
|
||||
TheVoidFunctionTypeDeclaration->mBase = TheVoidTypeDeclaration;
|
||||
TheVoidFunctionTypeDeclaration->mSize = 2;
|
||||
|
|
|
@ -216,8 +216,8 @@ public:
|
|||
|
||||
void InitDeclarations(void);
|
||||
|
||||
extern Declaration* TheVoidTypeDeclaration, * TheSignedIntTypeDeclaration, * TheUnsignedIntTypeDeclaration, * TheConstCharTypeDeclaration, * TheCharTypeDeclaration, * TheSignedCharTypeDeclaration, * TheUnsignedCharTypeDeclaration;
|
||||
extern Declaration* TheBoolTypeDeclaration, * TheFloatTypeDeclaration, * TheVoidPointerTypeDeclaration, * TheSignedLongTypeDeclaration, * TheUnsignedLongTypeDeclaration;
|
||||
extern Declaration* TheVoidTypeDeclaration, * TheConstVoidTypeDeclaration, * TheSignedIntTypeDeclaration, * TheUnsignedIntTypeDeclaration, * TheConstCharTypeDeclaration, * TheCharTypeDeclaration, * TheSignedCharTypeDeclaration, * TheUnsignedCharTypeDeclaration;
|
||||
extern Declaration* TheBoolTypeDeclaration, * TheFloatTypeDeclaration, * TheVoidPointerTypeDeclaration, * TheConstVoidPointerTypeDeclaration, * TheSignedLongTypeDeclaration, * TheUnsignedLongTypeDeclaration;
|
||||
extern Declaration* TheVoidFunctionTypeDeclaration, * TheConstVoidValueDeclaration;
|
||||
extern Declaration* TheCharPointerTypeDeclaration, * TheConstCharPointerTypeDeclaration;
|
||||
|
||||
|
|
|
@ -2246,9 +2246,9 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
else
|
||||
vr = Dereference(proc, exp, block, vr);
|
||||
|
||||
if (!TheCharPointerTypeDeclaration->CanAssign(vl.mType))
|
||||
if (!TheVoidPointerTypeDeclaration->CanAssign(vl.mType))
|
||||
mErrors->Error(tex->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types");
|
||||
if (!TheConstCharPointerTypeDeclaration->CanAssign(vr.mType))
|
||||
if (!TheConstVoidPointerTypeDeclaration->CanAssign(vr.mType))
|
||||
mErrors->Error(sex->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types");
|
||||
|
||||
InterInstruction* ins = new InterInstruction(exp->mLocation, IC_COPY);
|
||||
|
|
Loading…
Reference in New Issue