From d0411b7d5230d1ceed999a1c54f5720d54d7a324 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Thu, 8 May 2025 15:21:59 +0200 Subject: [PATCH] Fix more function overloads with const --- include/opp/vector.h | 4 ++-- oscar64/Declaration.cpp | 5 ++++- oscar64/Parser.cpp | 21 ++++++++++++++++++--- oscar64/Parser.h | 3 +++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/include/opp/vector.h b/include/opp/vector.h index a42b867..7503abc 100644 --- a/include/opp/vector.h +++ b/include/opp/vector.h @@ -206,7 +206,7 @@ protected: template -void vector::reserve(size_t n) +__noinline void vector::reserve(size_t n) { if (n > _capacity) { @@ -231,7 +231,7 @@ void vector::clear(void) } template -void vector::resize(size_t n) +__noinline void vector::resize(size_t n) { if (n < _size) { diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index ca49ac9..9a56d54 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -2370,7 +2370,10 @@ Declaration* Declaration::ToConstType(void) ndec->mSize = mSize; ndec->mStride = mStride; ndec->mStripe = mStripe; - ndec->mBase = mBase; + if (mType == DT_TYPE_ARRAY) + ndec->mBase = mBase->ToConstType(); + else + ndec->mBase = mBase; ndec->mBits = mBits; ndec->mShift = mShift; ndec->mFlags = mFlags | DTF_CONST; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 819c2ee..caaba2b 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -6,7 +6,7 @@ #include "NumberSet.h" Parser::Parser(Errors* errors, Scanner* scanner, CompilationUnits* compilationUnits) - : mErrors(errors), mScanner(scanner), mCompilationUnits(compilationUnits) + : mErrors(errors), mScanner(scanner), mCompilationUnits(compilationUnits), mParent(nullptr) { mGlobals = new DeclarationScope(compilationUnits->mScope, SLEVEL_STATIC); mScope = mGlobals; @@ -5295,6 +5295,9 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex if (variable) { + if (storageFlags & DTF_CONSTEXPR) + ndec->mBase = ndec->mBase->ToConstType(); + ndec->mFlags |= storageFlags; ndec->mFlags |= ndec->mBase->mFlags & (DTF_CONST | DTF_VOLATILE); @@ -7483,6 +7486,8 @@ int Parser::OverloadDistance(Declaration* fdec, Expression* pexp) { dist += 32; } + else if (ptype->IsSimpleType() && etype->IsSimpleType() && ptype->IsConstSame(etype)) + dist += 2; else if (ptype->mType == DT_TYPE_STRUCT && etype->mType == DT_TYPE_STRUCT) { int ncast = 0; @@ -7870,7 +7875,7 @@ Expression * Parser::ResolveOverloadCall(Expression* exp, Expression* exp2) fdec = fdec->mNext; } #endif - mErrors->Error(exp->mLocation, ERRO_NO_MATCHING_FUNCTION_CALL, "No matching function call", exp->mLeft->mDecValue->mQualIdent); + mErrors->Error(FullLocation(exp->mLocation), ERRO_NO_MATCHING_FUNCTION_CALL, "No matching function call", exp->mLeft->mDecValue->mQualIdent); } else if (nbest > 1) { @@ -7882,7 +7887,7 @@ Expression * Parser::ResolveOverloadCall(Expression* exp, Expression* exp2) fdec = fdec->mNext; } #endif - mErrors->Error(exp->mLocation, ERRO_AMBIGUOUS_FUNCTION_CALL, "Ambiguous function call", exp->mLeft->mDecValue->mQualIdent); + mErrors->Error(FullLocation(exp->mLocation), ERRO_AMBIGUOUS_FUNCTION_CALL, "Ambiguous function call", exp->mLeft->mDecValue->mQualIdent); } else { @@ -11160,6 +11165,7 @@ Declaration* Parser::ParseTemplateExpansion(Declaration* tmpld, Declaration* exp if (tmpld->mBase->mType == DT_TEMPLATE) { Parser* p = tmpld->mBase->mParser->Clone(); + p->mParent = this; p->mScanner->Replay(tmpld->mBase->mTokens); @@ -11450,6 +11456,7 @@ Declaration* Parser::ParseTemplateExpansion(Declaration* tmpld, Declaration* exp #endif Parser* p = tmpld->mParser->Clone(); + p->mParent = this; p->mScanner->Replay(tmpld->mTokens); @@ -14011,6 +14018,14 @@ void Parser::ParseNamespace(void) } } +Location Parser::FullLocation(const Location& loc) +{ + if (mParent) + return mParent->FullLocation(Location(loc, &mParent->mScanner->mLocation)); + else + return loc; +} + void Parser::Parse(void) { mLocalIndex = 0; diff --git a/oscar64/Parser.h b/oscar64/Parser.h index 54f0e90..13e4139 100644 --- a/oscar64/Parser.h +++ b/oscar64/Parser.h @@ -11,6 +11,7 @@ public: ~Parser(void); Parser* Clone(void); + Parser * mParent; DeclarationScope * mGlobals, * mScope, * mTemplateScope, * mCaptureScope; int mLocalIndex; @@ -24,6 +25,8 @@ public: uint64 mCompilerOptionStack[32]; int mCompilerOptionSP; + Location FullLocation(const Location& loc); + void Parse(void); protected: bool ExpectToken(Token token);