From c86dc364b1ccc4c7ee345ef6d59baf7aac040496 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 18 May 2025 11:35:13 +0200 Subject: [PATCH] Fixed array size template parameter --- oscar64/Declaration.cpp | 15 +++++++++++++++ oscar64/Parser.cpp | 16 +++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 8aafe25..971e7bb 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -2083,6 +2083,21 @@ bool Declaration::ResolveTemplate(Declaration* fdec, Declaration* tdec, bool sam } return true; + } + else if (tdec->mType == DT_TYPE_ARRAY && fdec->mType == DT_TYPE_ARRAY && tdec->mTemplate && tdec->mBase->IsConstSame(fdec->mBase)) + { + Declaration* ifdec = new Declaration(fdec->mLocation, DT_CONST_INTEGER); + ifdec->mBase = TheSignedIntTypeDeclaration; + ifdec->mSize = 2; + ifdec->mInteger = fdec->mSize / fdec->mBase->mSize; + + Declaration * ipdec = mScope->Insert(tdec->mTemplate->mIdent, ifdec); + if (ipdec && !ipdec->IsSame(ifdec)) + return false; + + return true; + + } else if (tdec->mType == DT_TYPE_STRUCT && fdec->mType == DT_TYPE_STRUCT && tdec->mTemplate) { diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 4b33bbb..3df4c5d 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -1367,8 +1367,18 @@ Declaration* Parser::ParsePostfixDeclaration(void) if (mScanner->mToken != TK_CLOSE_BRACKET) { Expression* exp = ParseRExpression(); - if (exp->mType == EX_CONSTANT && exp->mDecType->IsIntegerType() && exp->mDecValue->mType == DT_CONST_INTEGER) - ndec->mSize = int(exp->mDecValue->mInteger); + if (exp->mType == EX_CONSTANT && exp->mDecType->IsIntegerType()) + { + if (exp->mDecValue->mType == DT_CONST_INTEGER) + ndec->mSize = int(exp->mDecValue->mInteger); + else if (exp->mDecValue->mType == DT_CONST_TEMPLATE) + { + ndec->mSize = 0; + ndec->mTemplate = exp->mDecValue; + } + else + mErrors->Error(exp->mLocation, EERR_CONSTANT_TYPE, "Constant integer expression expected"); + } else mErrors->Error(exp->mLocation, EERR_CONSTANT_TYPE, "Constant integer expression expected"); ndec->mFlags |= DTF_DEFINED; @@ -1505,7 +1515,7 @@ Declaration * Parser::ParseFunctionDeclaration(Declaration* bdec) adec->mType = DT_ARGUMENT; adec->mVarIndex = vi; adec->mOffset = 0; - if (adec->mBase->mType == DT_TYPE_ARRAY) + if (adec->mBase->mType == DT_TYPE_ARRAY && !adec->mBase->mTemplate) { Declaration* ndec = new Declaration(adec->mBase->mLocation, DT_TYPE_POINTER); ndec->mBase = adec->mBase->mBase;