From 6a30a384153523ebf0d1426a19a1d10c9618f241 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Tue, 10 Oct 2023 09:02:30 +0200 Subject: [PATCH] Fix multi instantiation of inline constructors --- autotest/autotest.bat | 3 +++ autotest/opp_part1.cpp | 2 ++ autotest/opp_part1.h | 40 ++++++++++++++++++++++++++++++++++++++++ autotest/opp_part2.cpp | 13 +++++++++++++ autotest/opp_part2.h | 16 ++++++++++++++++ autotest/opp_parts.cpp | 25 +++++++++++++++++++++++++ oscar64/InterCode.cpp | 4 ++-- oscar64/Parser.cpp | 21 +++++++++++++++++++-- 8 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 autotest/opp_part1.cpp create mode 100644 autotest/opp_part1.h create mode 100644 autotest/opp_part2.cpp create mode 100644 autotest/opp_part2.h create mode 100644 autotest/opp_parts.cpp diff --git a/autotest/autotest.bat b/autotest/autotest.bat index a5eaf07..567bea6 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -21,6 +21,9 @@ rem @echo off @call :test opp_pairtest.cpp @if %errorlevel% neq 0 goto :error +@call :test opp_parts.cpp +@if %errorlevel% neq 0 goto :error + @call :test operatoroverload.cpp @if %errorlevel% neq 0 goto :error diff --git a/autotest/opp_part1.cpp b/autotest/opp_part1.cpp new file mode 100644 index 0000000..8fc18fb --- /dev/null +++ b/autotest/opp_part1.cpp @@ -0,0 +1,2 @@ +#include "opp_part1.h" + diff --git a/autotest/opp_part1.h b/autotest/opp_part1.h new file mode 100644 index 0000000..7b227ff --- /dev/null +++ b/autotest/opp_part1.h @@ -0,0 +1,40 @@ +#pragma once + +#include + +class A +{ +protected: + int a, b; + +public: + A(int a_, int b_) + : a(a_), b(b_) + {} + + int sum(void) const + { + return a * b; + } +}; + +class AS +{ +protected: + opp::vector va; +public: + AS(const opp::vector & v) + : va(v) + {} + + int sum(void) + { + int s = 0; + for(const auto & a : va) + s += a.sum(); + return s; + } +}; + +#pragma compile("opp_part1.cpp") + diff --git a/autotest/opp_part2.cpp b/autotest/opp_part2.cpp new file mode 100644 index 0000000..f30400c --- /dev/null +++ b/autotest/opp_part2.cpp @@ -0,0 +1,13 @@ +#include "opp_part2.h" + +BS::BS(const opp::vector & v) + : va(v) + {} + +int BS::sum(void) +{ + int s = 0; + for(const auto & a : va) + s += a.sum(); + return s; +} diff --git a/autotest/opp_part2.h b/autotest/opp_part2.h new file mode 100644 index 0000000..5606e0e --- /dev/null +++ b/autotest/opp_part2.h @@ -0,0 +1,16 @@ +#pragma once + +#include "opp_part1.h" + +class BS +{ +protected: + opp::vector va; +public: + BS(const opp::vector & v); + int sum(void); +}; + + + +#pragma compile("opp_part2.cpp") diff --git a/autotest/opp_parts.cpp b/autotest/opp_parts.cpp new file mode 100644 index 0000000..364753e --- /dev/null +++ b/autotest/opp_parts.cpp @@ -0,0 +1,25 @@ +#include + +#include "opp_part1.h" +#include "opp_part2.h" + + +int main(void) +{ + opp::vector va; + va.push_back(A(1, 2)); + va.push_back(A(3, 4)); + va.push_back(A(6, 4)); + va.push_back(A(0, 9)); + + AS as(va); + + va.push_back(A(7, 1)); + + BS bs(va); + + assert(bs.sum() == 2 + 12 + 24 + 7); + assert(as.sum() == 2 + 12 + 24); + + return 0; +} diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 90771e6..98b702b 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -15997,7 +15997,7 @@ void InterCodeBasicBlock::PeepholeOptimization(const GrowingVariableArray& stati while (i < mInstructions.Size()) { InterInstruction* ins(mInstructions[i]); - if ((ins->mCode == IC_CALL || ins->mCode == IC_CALL_NATIVE) && ins->mSrc[0].mTemp < 0) + if (ins->mCode == IC_CALL || ins->mCode == IC_CALL_NATIVE) { int j = i; while (j > 0 && CanSwapInstructions(ins, mInstructions[j - 1]) && TempUseDelta(mInstructions[j - 1]) >= 0) @@ -17434,7 +17434,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "tile_row"); + CheckFunc = !strcmp(mIdent->mString, "mod"); mEntryBlock = mBlocks[0]; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 7657234..5005ce4 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -3879,6 +3879,8 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex pdec = pdec->mNext; } + Declaration* dec = cdec; + if (pdec) { if (!cdec->mBase->IsSame(pdec->mBase)) @@ -3903,7 +3905,9 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex } } - cdec = pdec; + dec = pdec; + if (!(pdec->mFlags & DTF_DEFINED)) + cdec = pdec; } cdec->mIdent = pthis->mBase->mIdent->PreMangle("+"); @@ -3931,7 +3935,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex cdec->mNumVars = mLocalIndex; } - return cdec; + return dec; } if (bdec && bdec->mType == DT_TYPE_STRUCT && ConsumeTokenIf(TK_COLCOLON)) @@ -6097,6 +6101,19 @@ Expression* Parser::CoerceExpression(Expression* exp, Declaration* type) return nexp; } } + + if (type->mType == DT_TYPE_POINTER && type->mBase->mType == DT_TYPE_FUNCTION) + { + Declaration* fr = tdec->mScope->Lookup(Ident::Unique("operator()")); + if (fr && !(fr->mBase->mFlags & DTF_FUNC_THIS)) + { + Expression* nexp = new Expression(exp->mLocation, EX_CONSTANT); + nexp->mDecType = fr->mBase; + nexp->mDecValue = fr; + + return nexp; + } + } } if (type->mType == DT_TYPE_STRUCT)