From 2479ec5dd8535d0340aba779f91500ae408c8323 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 15 Mar 2023 22:53:19 +0100 Subject: [PATCH] Fix const void pointer assignment check --- oscar64/Declaration.cpp | 14 +++++++++++--- oscar64/Declaration.h | 4 ++-- oscar64/InterCodeGenerator.cpp | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 0841cc4..0e96563 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -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; diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 080e422..2a55b8a 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -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; diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index da4e7f7..392273e 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -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);