mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Clear variable declarations inside deferredParamValues (ie skipCall)
This commit is contained in:
parent
2b7d0284f7
commit
c65fd5711d
5 changed files with 60 additions and 23 deletions
|
@ -6109,7 +6109,13 @@ void BfExprEvaluator::ResolveArgValues(BfResolvedArgs& resolvedArgs, BfResolveAr
|
||||||
if ((resolvedArg.mArgFlags & BfArgFlag_StringInterpolateFormat) != 0)
|
if ((resolvedArg.mArgFlags & BfArgFlag_StringInterpolateFormat) != 0)
|
||||||
exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(exprEvaluator.mBfEvalExprFlags | BfEvalExprFlags_StringInterpolateFormat);
|
exprEvaluator.mBfEvalExprFlags = (BfEvalExprFlags)(exprEvaluator.mBfEvalExprFlags | BfEvalExprFlags_StringInterpolateFormat);
|
||||||
|
|
||||||
|
int lastLocalVarIdx = mModule->mCurMethodState->mLocals.mSize;
|
||||||
exprEvaluator.Evaluate(argExpr, false, false, true);
|
exprEvaluator.Evaluate(argExpr, false, false, true);
|
||||||
|
if ((deferParamValues) && (mModule->mCurMethodState->mLocals.mSize > lastLocalVarIdx))
|
||||||
|
{
|
||||||
|
// Remove any ignored locals
|
||||||
|
mModule->RestoreScoreState_LocalVariables(lastLocalVarIdx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((mModule->mCurMethodState != NULL) && (exprEvaluator.mResultLocalVar != NULL) && (exprEvaluator.mResultLocalVarRefNode != NULL))
|
if ((mModule->mCurMethodState != NULL) && (exprEvaluator.mResultLocalVar != NULL) && (exprEvaluator.mResultLocalVarRefNode != NULL))
|
||||||
|
@ -6175,6 +6181,18 @@ void BfExprEvaluator::PerformCallChecks(BfMethodInstance* methodInstance, BfAstN
|
||||||
mModule->CheckErrorAttributes(methodInstance->GetOwner(), methodInstance, NULL, customAttributes, targetSrc);
|
mModule->CheckErrorAttributes(methodInstance->GetOwner(), methodInstance, NULL, customAttributes, targetSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BfExprEvaluator::CheckSkipCall(BfAstNode* targetSrc, SizedArrayImpl<BfResolvedArg>& argValues)
|
||||||
|
{
|
||||||
|
for (auto& argValue : argValues)
|
||||||
|
{
|
||||||
|
if (!argValue.IsDeferredValue())
|
||||||
|
{
|
||||||
|
mModule->Fail("Illegal SkipCall invocation", targetSrc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* methodInstance, BfIRValue func, bool bypassVirtual, SizedArrayImpl<BfIRValue>& irArgs, BfTypedValue* sret, BfCreateCallFlags callFlags, BfType* origTargetType)
|
BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* methodInstance, BfIRValue func, bool bypassVirtual, SizedArrayImpl<BfIRValue>& irArgs, BfTypedValue* sret, BfCreateCallFlags callFlags, BfType* origTargetType)
|
||||||
{
|
{
|
||||||
// static int sCallIdx = 0;
|
// static int sCallIdx = 0;
|
||||||
|
@ -7372,7 +7390,6 @@ void BfExprEvaluator::AddCallDependencies(BfMethodInstance* methodInstance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: delete argumentsZ
|
|
||||||
BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValue& inTarget, const BfTypedValue& origTarget, BfMethodDef* methodDef, BfModuleMethodInstance moduleMethodInstance, BfCreateCallFlags callFlags, SizedArrayImpl<BfResolvedArg>& argValues, BfTypedValue* argCascade)
|
BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValue& inTarget, const BfTypedValue& origTarget, BfMethodDef* methodDef, BfModuleMethodInstance moduleMethodInstance, BfCreateCallFlags callFlags, SizedArrayImpl<BfResolvedArg>& argValues, BfTypedValue* argCascade)
|
||||||
{
|
{
|
||||||
SetAndRestoreValue<BfEvalExprFlags> prevEvalExprFlag(mBfEvalExprFlags);
|
SetAndRestoreValue<BfEvalExprFlags> prevEvalExprFlag(mBfEvalExprFlags);
|
||||||
|
@ -7433,7 +7450,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
|
||||||
{
|
{
|
||||||
returnType = methodInstance->GetOwner();
|
returnType = methodInstance->GetOwner();
|
||||||
BF_ASSERT(returnType->IsInterface());
|
BF_ASSERT(returnType->IsInterface());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
Array<BfTypedValue> argCascades;
|
Array<BfTypedValue> argCascades;
|
||||||
BfTypedValue target = inTarget;
|
BfTypedValue target = inTarget;
|
||||||
|
@ -7543,6 +7560,7 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
|
||||||
|
|
||||||
if (isSkipCall)
|
if (isSkipCall)
|
||||||
{
|
{
|
||||||
|
CheckSkipCall(targetSrc, argValues);
|
||||||
FinishDeferredEvals(argValues);
|
FinishDeferredEvals(argValues);
|
||||||
mModule->EmitEnsureInstructionAt();
|
mModule->EmitEnsureInstructionAt();
|
||||||
return mModule->GetDefaultTypedValue(returnType);
|
return mModule->GetDefaultTypedValue(returnType);
|
||||||
|
@ -8749,7 +8767,7 @@ BfTypedValue BfExprEvaluator::MatchConstructor(BfAstNode* targetSrc, BfMethodBou
|
||||||
}
|
}
|
||||||
methodMatcher.mArguments.Insert(0, resolvedArg);
|
methodMatcher.mArguments.Insert(0, resolvedArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFailurePass)
|
if (isFailurePass)
|
||||||
mModule->Fail(StrFormat("'%s' is inaccessible due to its protection level", mModule->MethodToString(moduleMethodInstance.mMethodInstance).c_str()), targetSrc);
|
mModule->Fail(StrFormat("'%s' is inaccessible due to its protection level", mModule->MethodToString(moduleMethodInstance.mMethodInstance).c_str()), targetSrc);
|
||||||
|
@ -18643,30 +18661,38 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m
|
||||||
int methodCount = 0;
|
int methodCount = 0;
|
||||||
bool mayBeSkipCall = false;
|
bool mayBeSkipCall = false;
|
||||||
bool mayBeComptimeCall = false;
|
bool mayBeComptimeCall = false;
|
||||||
|
|
||||||
|
BfTypeInstance* checkTypeInst = NULL;
|
||||||
|
|
||||||
if (thisValue.mType != NULL)
|
if (thisValue.mType != NULL)
|
||||||
{
|
{
|
||||||
if (thisValue.mType->IsAllocType())
|
if (thisValue.mType->IsAllocType())
|
||||||
thisValue.mType = thisValue.mType->GetUnderlyingType();
|
thisValue.mType = thisValue.mType->GetUnderlyingType();
|
||||||
|
|
||||||
auto checkTypeInst = thisValue.mType->ToTypeInstance();
|
checkTypeInst = thisValue.mType->ToTypeInstance();
|
||||||
while (checkTypeInst != NULL)
|
}
|
||||||
|
else if (allowImplicitThis)
|
||||||
|
{
|
||||||
|
checkTypeInst = mModule->mCurTypeInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (checkTypeInst != NULL)
|
||||||
|
{
|
||||||
|
checkTypeInst->mTypeDef->PopulateMemberSets();
|
||||||
|
BfMemberSetEntry* memberSetEntry;
|
||||||
|
if (checkTypeInst->mTypeDef->mMethodSet.TryGetWith(targetFunctionName, &memberSetEntry))
|
||||||
{
|
{
|
||||||
checkTypeInst->mTypeDef->PopulateMemberSets();
|
BfMethodDef* methodDef = (BfMethodDef*)memberSetEntry->mMemberDef;
|
||||||
BfMemberSetEntry* memberSetEntry;
|
while (methodDef != NULL)
|
||||||
if (checkTypeInst->mTypeDef->mMethodSet.TryGetWith(targetFunctionName, &memberSetEntry))
|
|
||||||
{
|
{
|
||||||
BfMethodDef* methodDef = (BfMethodDef*)memberSetEntry->mMemberDef;
|
if (methodDef->mIsSkipCall)
|
||||||
while (methodDef != NULL)
|
mayBeSkipCall = true;
|
||||||
{
|
if (methodDef->mHasComptime)
|
||||||
if (methodDef->mIsSkipCall)
|
mayBeComptimeCall = true;
|
||||||
mayBeSkipCall = true;
|
methodDef = methodDef->mNextWithSameName;
|
||||||
if (methodDef->mHasComptime)
|
|
||||||
mayBeComptimeCall = true;
|
|
||||||
methodDef = methodDef->mNextWithSameName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
checkTypeInst = checkTypeInst->mBaseType;
|
|
||||||
}
|
}
|
||||||
|
checkTypeInst = checkTypeInst->mBaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
SizedArray<BfExpression*, 8> copiedArgs;
|
SizedArray<BfExpression*, 8> copiedArgs;
|
||||||
|
|
|
@ -83,6 +83,11 @@ public:
|
||||||
{
|
{
|
||||||
return (mArgFlags & (BfArgFlag_DelegateBindAttempt | BfArgFlag_LambdaBindAttempt | BfArgFlag_UnqualifiedDotAttempt | BfArgFlag_UntypedDefault | BfArgFlag_DeferredEval)) != 0;
|
return (mArgFlags & (BfArgFlag_DelegateBindAttempt | BfArgFlag_LambdaBindAttempt | BfArgFlag_UnqualifiedDotAttempt | BfArgFlag_UntypedDefault | BfArgFlag_DeferredEval)) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsDeferredValue()
|
||||||
|
{
|
||||||
|
return (mArgFlags & (BfArgFlag_DelegateBindAttempt | BfArgFlag_LambdaBindAttempt | BfArgFlag_UnqualifiedDotAttempt | BfArgFlag_UntypedDefault | BfArgFlag_DeferredEval | BfArgFlag_DeferredValue)) != 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BfResolvedArgs
|
struct BfResolvedArgs
|
||||||
|
@ -481,6 +486,7 @@ public:
|
||||||
BfTypedValue LookupIdentifier(BfIdentifierNode* identifierNode, bool ignoreInitialError = false, bool* hadError = NULL);
|
BfTypedValue LookupIdentifier(BfIdentifierNode* identifierNode, bool ignoreInitialError = false, bool* hadError = NULL);
|
||||||
void AddCallDependencies(BfMethodInstance* methodInstance);
|
void AddCallDependencies(BfMethodInstance* methodInstance);
|
||||||
void PerformCallChecks(BfMethodInstance* methodInstance, BfAstNode* targetSrc);
|
void PerformCallChecks(BfMethodInstance* methodInstance, BfAstNode* targetSrc);
|
||||||
|
void CheckSkipCall(BfAstNode* targetSrc, SizedArrayImpl<BfResolvedArg>& argValues);
|
||||||
BfTypedValue CreateCall(BfAstNode* targetSrc, BfMethodInstance* methodInstance, BfIRValue func, bool bypassVirtual, SizedArrayImpl<BfIRValue>& irArgs, BfTypedValue* sret = NULL, BfCreateCallFlags callFlags = BfCreateCallFlags_None, BfType* origTargetType = NULL);
|
BfTypedValue CreateCall(BfAstNode* targetSrc, BfMethodInstance* methodInstance, BfIRValue func, bool bypassVirtual, SizedArrayImpl<BfIRValue>& irArgs, BfTypedValue* sret = NULL, BfCreateCallFlags callFlags = BfCreateCallFlags_None, BfType* origTargetType = NULL);
|
||||||
BfTypedValue CreateCall(BfAstNode* targetSrc, const BfTypedValue& target, const BfTypedValue& origTarget, BfMethodDef* methodDef, BfModuleMethodInstance methodInstance, BfCreateCallFlags callFlags, SizedArrayImpl<BfResolvedArg>& argValues, BfTypedValue* argCascade = NULL);
|
BfTypedValue CreateCall(BfAstNode* targetSrc, const BfTypedValue& target, const BfTypedValue& origTarget, BfMethodDef* methodDef, BfModuleMethodInstance methodInstance, BfCreateCallFlags callFlags, SizedArrayImpl<BfResolvedArg>& argValues, BfTypedValue* argCascade = NULL);
|
||||||
BfTypedValue CreateCall(BfMethodMatcher* methodMatcher, BfTypedValue target);
|
BfTypedValue CreateCall(BfMethodMatcher* methodMatcher, BfTypedValue target);
|
||||||
|
|
|
@ -1963,9 +1963,9 @@ void BfModule::NewScopeState(bool createLexicalBlock, bool flushValueScope)
|
||||||
mCurMethodState->mCurScope->mMixinState = mCurMethodState->mMixinState;
|
mCurMethodState->mCurScope->mMixinState = mCurMethodState->mMixinState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfModule::RestoreScoreState_LocalVariables()
|
void BfModule::RestoreScoreState_LocalVariables(int localVarStart)
|
||||||
{
|
{
|
||||||
while (mCurMethodState->mCurScope->mLocalVarStart < (int)mCurMethodState->mLocals.size())
|
while (localVarStart < (int)mCurMethodState->mLocals.size())
|
||||||
{
|
{
|
||||||
auto localVar = mCurMethodState->mLocals.back();
|
auto localVar = mCurMethodState->mLocals.back();
|
||||||
LocalVariableDone(localVar, false);
|
LocalVariableDone(localVar, false);
|
||||||
|
@ -2022,7 +2022,7 @@ void BfModule::RestoreScopeState()
|
||||||
|
|
||||||
EmitDeferredCallProcessorInstances(mCurMethodState->mCurScope);
|
EmitDeferredCallProcessorInstances(mCurMethodState->mCurScope);
|
||||||
|
|
||||||
RestoreScoreState_LocalVariables();
|
RestoreScoreState_LocalVariables(mCurMethodState->mCurScope->mLocalVarStart);
|
||||||
|
|
||||||
if (mCurMethodState->mCurScope->mValueScopeStart)
|
if (mCurMethodState->mCurScope->mValueScopeStart)
|
||||||
mBfIRBuilder->CreateValueScopeHardEnd(mCurMethodState->mCurScope->mValueScopeStart);
|
mBfIRBuilder->CreateValueScopeHardEnd(mCurMethodState->mCurScope->mValueScopeStart);
|
||||||
|
@ -15498,6 +15498,11 @@ void BfModule::DoLocalVariableDebugInfo(BfLocalVariable* localVarDef, bool doAli
|
||||||
|
|
||||||
BfLocalVariable* BfModule::AddLocalVariableDef(BfLocalVariable* localVarDef, bool addDebugInfo, bool doAliasValue, BfIRValue declareBefore, BfIRInitType initType)
|
BfLocalVariable* BfModule::AddLocalVariableDef(BfLocalVariable* localVarDef, bool addDebugInfo, bool doAliasValue, BfIRValue declareBefore, BfIRInitType initType)
|
||||||
{
|
{
|
||||||
|
if (localVarDef->mName == "newSuccIndex")
|
||||||
|
{
|
||||||
|
NOP;
|
||||||
|
}
|
||||||
|
|
||||||
if ((localVarDef->mValue) && (!localVarDef->mAddr) && (IsTargetingBeefBackend()) && (!localVarDef->mResolvedType->IsValuelessType()))
|
if ((localVarDef->mValue) && (!localVarDef->mAddr) && (IsTargetingBeefBackend()) && (!localVarDef->mResolvedType->IsValuelessType()))
|
||||||
{
|
{
|
||||||
if ((!localVarDef->mValue.IsConst()) &&
|
if ((!localVarDef->mValue.IsConst()) &&
|
||||||
|
|
|
@ -1678,7 +1678,7 @@ public:
|
||||||
BfIRValue CreateAlloca(BfType* type, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue());
|
BfIRValue CreateAlloca(BfType* type, bool addLifetime = true, const char* name = NULL, BfIRValue arraySize = BfIRValue());
|
||||||
BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL);
|
BfIRValue CreateAllocaInst(BfTypeInstance* typeInst, bool addLifetime = true, const char* name = NULL);
|
||||||
BfDeferredCallEntry* AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false, BfIRBlock valBlock = BfIRBlock());
|
BfDeferredCallEntry* AddStackAlloc(BfTypedValue val, BfIRValue arraySize, BfAstNode* refNode, BfScopeData* scope, bool condAlloca = false, bool mayEscape = false, BfIRBlock valBlock = BfIRBlock());
|
||||||
void RestoreScoreState_LocalVariables();
|
void RestoreScoreState_LocalVariables(int localVarStart);
|
||||||
void RestoreScopeState();
|
void RestoreScopeState();
|
||||||
void MarkDynStack(BfScopeData* scope);
|
void MarkDynStack(BfScopeData* scope);
|
||||||
void SaveStackState(BfScopeData* scope);
|
void SaveStackState(BfScopeData* scope);
|
||||||
|
|
|
@ -3893,7 +3893,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
|
||||||
// We restore the scopeData before the False block because we don't want variables created in the if condition to
|
// We restore the scopeData before the False block because we don't want variables created in the if condition to
|
||||||
// be visible in the false section
|
// be visible in the false section
|
||||||
//RestoreScopeState();
|
//RestoreScopeState();
|
||||||
RestoreScoreState_LocalVariables();
|
RestoreScoreState_LocalVariables(mCurMethodState->mCurScope->mLocalVarStart);
|
||||||
|
|
||||||
if ((!mCurMethodState->mLeftBlockUncond) && (!ignoredLastBlock))
|
if ((!mCurMethodState->mLeftBlockUncond) && (!ignoredLastBlock))
|
||||||
mBfIRBuilder->CreateBr_NoCollapse(contBB);
|
mBfIRBuilder->CreateBr_NoCollapse(contBB);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue