From da5326cc5f23e551afabdecc9b2d91fa2500181c Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:01:30 +0200 Subject: [PATCH] Fix local multi dim array init --- oscar64/InterCodeGenerator.cpp | 2 +- oscar64/Parser.cpp | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index e520776..2dd0e6d 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -2890,7 +2890,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Not a pointer type"); else if (vl.mType->mStride != 1) vl = Dereference(proc, exp, block, vl, 0); - return ExValue(vl.mType->mBase, vl.mTemp, vl.mReference + 1); + return ExValue(vl.mType->mBase, vl.mTemp, 1); case TK_BINARY_AND: { if (vl.mReference < 1 || vl.mBits) diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 0653df8..64fc32e 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -3092,6 +3092,17 @@ void Parser::AppendMemberDestructor(Declaration* pthis) } else { + qexp->mDecType = dec->mBase->mBase; + + while (qexp->mDecType->mType == DT_TYPE_ARRAY) + { + Expression* iexp = new Expression(pthis->mLocation, EX_PREFIX); + iexp->mToken = TK_MUL; + iexp->mLeft = qexp; + iexp->mDecType = qexp->mDecType->mBase; + qexp = iexp; + } + qexp->mDecType = new Declaration(pthis->mLocation, DT_TYPE_POINTER); qexp->mDecType->mFlags |= DTF_CONST | DTF_DEFINED; qexp->mDecType->mBase = bdec; @@ -4504,6 +4515,19 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex } else { + Expression* texp = vexp; + + while (texp->mDecType->mBase->mType == DT_TYPE_ARRAY) + { + Expression* iexp = new Expression(vexp->mLocation, EX_PREFIX); + iexp->mToken = TK_MUL; + iexp->mLeft = texp; + iexp->mDecType = texp->mDecType->mBase; + texp = iexp; + } + + //texp->mDecType = bdec->BuildPointer(vexp->mLocation); + Declaration* ncdec = new Declaration(mScanner->mLocation, DT_CONST_INTEGER); ncdec->mBase = TheUnsignedIntTypeDeclaration; ncdec->mInteger = ndec->mSize / bdec->mSize; @@ -4520,11 +4544,11 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex fexp->mLeft = cexp; fexp->mRight = new Expression(mScanner->mLocation, EX_LIST); - fexp->mRight->mLeft = vexp; + fexp->mRight->mLeft = texp; fexp->mRight->mRight = new Expression(mScanner->mLocation, EX_BINARY); fexp->mRight->mRight->mToken = TK_ADD; - fexp->mRight->mRight->mLeft = vexp; - fexp->mRight->mRight->mDecType = vexp->mDecType; + fexp->mRight->mRight->mLeft = texp; + fexp->mRight->mRight->mDecType = texp->mDecType; fexp->mRight->mRight->mRight = new Expression(mScanner->mLocation, EX_CONSTANT); fexp->mRight->mRight->mRight->mDecType = ncdec->mBase; fexp->mRight->mRight->mRight->mDecValue = ncdec;