diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 628e02b..e873432 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -452,6 +452,44 @@ Expression* Expression::LogicInvertExpression(void) } } +Expression* Expression::ConstantDereference(void) +{ + if (mType == EX_VARIABLE) + { + if (mDecValue->mType == DT_VARIABLE && (mDecValue->mFlags & DTF_CONST) && mDecValue->mValue) + return mDecValue->mValue; + else if (mDecValue->mType == DT_VARIABLE_REF && (mDecValue->mFlags & DTF_CONST) && mDecValue->mBase->mValue && mDecValue->mBase->mValue->mType == EX_CONSTANT && mDecValue->mBase->mValue->mDecValue->mType == DT_CONST_STRUCT) + { + Declaration* mdec = mDecValue->mBase->mValue->mDecValue->mParams; + int coffset = mDecValue->mOffset; + while (mdec) + { + if (mdec->mType == DT_CONST_STRUCT) + { + if (mdec->mOffset > coffset || mdec->mOffset + mdec->mSize <= coffset) + mdec = mdec->mNext; + else + { + coffset -= mdec->mOffset; + mdec = mdec->mParams; + } + } + else if (mdec->mOffset != coffset) + mdec = mdec->mNext; + else + { + Expression* ex = new Expression(mLocation, EX_CONSTANT); + ex->mDecValue = mdec; + ex->mDecType = mDecType; + return ex; + } + } + } + } + + return this; +} + Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSection, Linker* linker) { if (mType == EX_PREFIX && mToken == TK_BANKOF && linker) @@ -925,21 +963,6 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio { int offset = int(mDecType->mSize * mRight->mDecValue->mInteger); - if (mDecType->IsSimpleType() && (mLeft->mDecValue->mFlags & DTF_CONST) && mLeft->mDecValue->mValue && mLeft->mDecValue->mValue->mType == EX_CONSTANT && mLeft->mDecValue->mValue->mDecValue->mType == DT_CONST_STRUCT) - { - Declaration* mdec = mLeft->mDecValue->mValue->mDecValue->mParams; - while (mdec && mdec->mOffset != offset) - mdec = mdec->mNext; - - if (mdec) - { - Expression* ex = new Expression(mLocation, EX_CONSTANT); - ex->mDecValue = mdec; - ex->mDecType = mDecType; - return ex; - } - } - Expression* ex = new Expression(mLocation, EX_VARIABLE); Declaration* dec = new Declaration(mLocation, DT_VARIABLE_REF); dec->mFlags = mLeft->mDecValue->mFlags; @@ -956,35 +979,6 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio { int offset = mLeft->mDecValue->mOffset + int(mDecType->mSize * mRight->mDecValue->mInteger); - if (mDecType->IsSimpleType() && (mLeft->mDecValue->mFlags & DTF_CONST) && mLeft->mDecValue->mBase->mValue && mLeft->mDecValue->mBase->mValue->mType == EX_CONSTANT && mLeft->mDecValue->mBase->mValue->mDecValue->mType == DT_CONST_STRUCT) - { - Declaration* mdec = mLeft->mDecValue->mBase->mValue->mDecValue->mParams; - - int coffset = offset; - while (mdec) - { - if (mdec->mType == DT_CONST_STRUCT) - { - if (mdec->mOffset > coffset || mdec->mOffset + mdec->mSize <= coffset) - mdec = mdec->mNext; - else - { - coffset -= mdec->mOffset; - mdec = mdec->mParams; - } - } - else if (mdec->mOffset != coffset) - mdec = mdec->mNext; - else - { - Expression* ex = new Expression(mLocation, EX_CONSTANT); - ex->mDecValue = mdec; - ex->mDecType = mDecType; - return ex; - } - } - } - Expression* ex = new Expression(mLocation, EX_VARIABLE); Declaration* dec = new Declaration(mLocation, DT_VARIABLE_REF); dec->mFlags = mLeft->mDecValue->mFlags; diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 734a3c0..a28071b 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -248,6 +248,7 @@ public: Expression* LogicInvertExpression(void); Expression* ConstantFold(Errors * errors, LinkerSection* dataSection, Linker * linker = nullptr); + Expression* ConstantDereference(void); bool HasSideEffects(void) const; bool IsSame(const Expression* exp) const; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 4623aa3..6d00d42 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -1405,6 +1405,8 @@ Declaration* Parser::ReverseDeclaration(Declaration* odec, Declaration* bdec) Declaration * Parser::CopyConstantInitializer(int offset, Declaration* dtype, Expression* exp) { + exp = exp->ConstantDereference(); + Declaration* dec = exp->mDecValue; if (exp->mType == EX_CONSTANT) diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index a75b734..79d3d1f 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -75,7 +75,7 @@ int main2(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.27.241"); + strcpy(strProductVersion, "1.27.242"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 2ca4089..f369f92 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,27,241,0 - PRODUCTVERSION 1,27,241,0 + FILEVERSION 1,27,242,0 + PRODUCTVERSION 1,27,242,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.27.241.0" + VALUE "FileVersion", "1.27.242.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.27.241.0" + VALUE "ProductVersion", "1.27.242.0" END END BLOCK "VarFileInfo"