From 9e71acc003bd0b7a9f0004d12055ac91455fb9c4 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 28 May 2025 06:23:22 +0200 Subject: [PATCH] Improved unknown-sized array in BfInvocationExpression --- IDEHelper/Compiler/BfExprEvaluator.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index c7b26b22..073ed833 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -19704,16 +19704,23 @@ void BfExprEvaluator::DoInvocation(BfInvocationExpression* invocationExpr) typeState.mArrayInitializerSize = (int)invocationExpr->mArguments.size(); SetAndRestoreValue prevTypeState(mModule->mContext->mCurTypeState, &typeState); + BfType* undefSizeParam = NULL; + if (indexerExpr->mArguments.size() != 0) { BfConstResolver constResolver(mModule); auto arg = indexerExpr->mArguments[0]; constResolver.mExpectingType = mModule->GetPrimitiveType(BfTypeCode_IntPtr); - + constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue); + if (arg != NULL) constResolver.Resolve(arg, NULL, BfConstResolveFlag_ArrayInitSize); - if (constResolver.mResult.mValue.IsConst()) + if (constResolver.mResult.mKind == BfTypedValueKind_GenericConstValue) + { + undefSizeParam = constResolver.mResult.mType; + } + else if (constResolver.mResult.mValue.IsConst()) { auto constant = mModule->mBfIRBuilder->GetConstant(constResolver.mResult.mValue); @@ -19721,14 +19728,17 @@ void BfExprEvaluator::DoInvocation(BfInvocationExpression* invocationExpr) { arrSize = constant->mInt32; } - else if (constant->mConstType != BfConstType_Undef) - mModule->Fail("Non-negative integer expected", indexerExpr->mArguments[0]); + else if (constant->mConstType != BfConstType_Undef) + mModule->Fail("Non-negative integer expected", indexerExpr->mArguments[0]); } } else arrSize = invocationExpr->mArguments.size(); - curType = mModule->CreateSizedArrayType(curType, arrSize); + if (undefSizeParam != NULL) + curType = mModule->CreateUnknownSizedArrayType(curType, undefSizeParam); + else + curType = mModule->CreateSizedArrayType(curType, arrSize); } InitializedSizedArray((BfSizedArrayType*)curType, invocationExpr->mOpenParen, invocationExpr->mArguments, invocationExpr->mCommas, invocationExpr->mCloseParen, NULL);