Fix struct volatile cast

This commit is contained in:
drmortalwombat 2024-01-08 20:41:48 +01:00
parent 4ea3633b5a
commit a6b3533e61
3 changed files with 67 additions and 2 deletions

View File

@ -979,7 +979,7 @@ Declaration::Declaration(const Location& loc, DecType type)
: mLocation(loc), mEndLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mQualIdent(nullptr), mMangleIdent(nullptr),
mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0), mNumVars(0),
mBase(nullptr), mParams(nullptr), mParamPack(nullptr), mValue(nullptr), mReturn(nullptr), mNext(nullptr), mPrev(nullptr),
mConst(nullptr), mMutable(nullptr),
mConst(nullptr), mMutable(nullptr), mVolatile(nullptr),
mDefaultConstructor(nullptr), mDestructor(nullptr), mCopyConstructor(nullptr), mCopyAssignment(nullptr), mMoveConstructor(nullptr), mMoveAssignment(nullptr),
mVectorConstructor(nullptr), mVectorDestructor(nullptr), mVectorCopyConstructor(nullptr), mVectorCopyAssignment(nullptr),
mVTable(nullptr), mTemplate(nullptr), mForwardParam(nullptr), mForwardCall(nullptr),
@ -1859,6 +1859,59 @@ Declaration* Declaration::ToStriped(int stripe)
return ndec;
}
Declaration* Declaration::ToVolatileType(void)
{
if (mFlags & DTF_VOLATILE)
return this;
if (!mVolatile)
{
Declaration* ndec = new Declaration(mLocation, mType);
ndec->mSize = mSize;
ndec->mStride = mStride;
ndec->mBase = mBase;
ndec->mFlags = mFlags | DTF_VOLATILE;
ndec->mScope = mScope;
ndec->mParams = mParams;
ndec->mIdent = mIdent;
ndec->mQualIdent = mQualIdent;
ndec->mTemplate = mTemplate;
if (mType == DT_TYPE_STRUCT)
{
ndec->mScope = new DeclarationScope(nullptr, mScope->mLevel);
Declaration* p = mParams;
Declaration* prev = nullptr;
while (p)
{
Declaration* pnec = p->Clone();
pnec->mBase = pnec->mBase->ToVolatileType();
ndec->mScope->Insert(pnec->mIdent, pnec);
if (prev)
prev->mNext = pnec;
else
ndec->mParams = pnec;
prev = pnec;
p = p->mNext;
}
}
ndec->mDestructor = mDestructor;
ndec->mDefaultConstructor = mDefaultConstructor;
ndec->mCopyConstructor = mCopyConstructor;
ndec->mMoveConstructor = mMoveConstructor;
ndec->mVectorConstructor = mVectorConstructor;
ndec->mVectorCopyConstructor = mVectorCopyConstructor;
ndec->mVTable = mVTable;
mVolatile = ndec;
}
return mVolatile;
}
Declaration* Declaration::ToConstType(void)
{
if (mFlags & DTF_CONST)

View File

@ -267,7 +267,7 @@ public:
Location mLocation, mEndLocation;
DecType mType;
Token mToken;
Declaration * mBase, * mParams, * mParamPack, * mNext, * mPrev, * mConst, * mMutable;
Declaration * mBase, * mParams, * mParamPack, * mNext, * mPrev, * mConst, * mMutable, * mVolatile;
Declaration * mDefaultConstructor, * mDestructor, * mCopyConstructor, * mCopyAssignment, * mMoveConstructor, * mMoveAssignment;
Declaration * mVectorConstructor, * mVectorDestructor, * mVectorCopyConstructor, * mVectorCopyAssignment;
Declaration * mVTable, * mClass, * mTemplate;
@ -315,6 +315,7 @@ public:
Declaration* ToConstType(void);
Declaration* ToMutableType(void);
Declaration* ToVolatileType(void);
Declaration* ToStriped(int stripe);
Declaration* ToStriped(Errors* errors);

View File

@ -648,6 +648,13 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt, Declaratio
mScope = oscope;
}
else
{
if ((flags & ~dec->mFlags) == DTF_CONST)
dec = dec->ToConstType();
else if ((flags & ~dec->mFlags) == DTF_VOLATILE)
dec = dec->ToVolatileType();
}
return dec;
}
@ -820,6 +827,8 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint64 flags, bool qualified, Decl
{
if ((flags & ~dec->mFlags) == DTF_CONST)
dec = dec->ToConstType();
else if ((flags & ~dec->mFlags) == DTF_VOLATILE)
dec = dec->ToVolatileType();
else if (dec->IsSimpleType() && (flags & ~dec->mFlags))
{
Declaration* ndec = new Declaration(dec->mLocation, dec->mType);
@ -832,6 +841,8 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint64 flags, bool qualified, Decl
{
if ((flags & ~dec->mFlags) == DTF_CONST)
dec = dec->ToConstType();
else if ((flags & ~dec->mFlags) == DTF_VOLATILE)
dec = dec->ToVolatileType();
else
{
Declaration* ndec = new Declaration(dec->mLocation, dec->mType);