1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Moved scope of 'if (Call(var X))' arguments into the if parent's scope

This commit is contained in:
Brian Fiete 2020-09-21 17:53:22 -07:00
parent 5b8d2ffee2
commit 965e2e2930
4 changed files with 79 additions and 0 deletions

View file

@ -228,5 +228,63 @@ namespace IDETest
int c = b; //FAIL
}
}
public bool GetVal(out int a)
{
a = 1;
return true;
}
public void Local1()
{
if ((GetVal(var a)) && (GetVal(var b)))
{
int c = a;
int d = b;
}
int e = a;
int f = b; //FAIL
}
public void Local2()
{
int a;
int b;
if ((GetVal(out a)) && (GetVal(out b)))
{
int c = a;
int d = b;
}
int e = a;
int f = b; //FAIL
}
public void Local3()
{
if ((GetVal(var a)) || (GetVal(var b))) //FAIL
{
int c = a;
int d = b;
}
int e = a;
int f = b; //FAIL
}
public void Local4()
{
int a;
int b;
if ((GetVal(out a)) || (GetVal(out b)))
{
int c = a;
int d = b; //FAIL
}
int e = a;
int f = b; //FAIL
}
}
}

View file

@ -6561,6 +6561,13 @@ BfTypedValue BfExprEvaluator::ResolveArgValue(BfResolvedArg& resolvedArg, BfType
CheckVariableDeclaration(resolvedArg.mExpression, false, false, false);
argValue = BfTypedValue(localVar->mAddr, mModule->CreateRefType(variableType, BfRefType::RefKind_Out));
auto curScope = mModule->mCurMethodState->mCurScope;
if (curScope->mScopeKind == BfScopeKind_StatementTarget)
{
// Move this variable into the parent scope
curScope->mLocalVarStart = (int)mModule->mCurMethodState->mLocals.size();
}
}
return argValue;
}
@ -18589,6 +18596,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfExpression* leftExpression, BfExp
{
if (mModule->mCurMethodState->mDeferredLocalAssignData != NULL)
mModule->mCurMethodState->mDeferredLocalAssignData->BreakExtendChain();
if (mModule->mCurMethodState->mCurScope->mScopeKind == BfScopeKind_StatementTarget)
mModule->mCurMethodState->mCurScope->mScopeKind = BfScopeKind_StatementTarget_Conditional;
bool isAnd = binaryOp == BfBinaryOp_ConditionalAnd;

View file

@ -357,12 +357,20 @@ public:
void SetUnion(const BfDeferredLocalAssignData& otherLocalAssignData);
};
enum BfScopeKind
{
BfScopeKind_Normal,
BfScopeKind_StatementTarget,
BfScopeKind_StatementTarget_Conditional,
};
// "Looped" means this scope will execute zero to many times, "Conditional" means zero or one.
// Looped and Conditional are mutually exclusive. "Dyn" means Looped OR Conditional.
class BfScopeData
{
public:
BfScopeData* mPrevScope;
BfScopeKind mScopeKind;
BfIRMDNode mDIScope;
BfIRMDNode mDIInlinedAt;
String mLabel;
@ -399,6 +407,7 @@ public:
public:
BfScopeData()
{
mScopeKind = BfScopeKind_Normal;
mPrevScope = NULL;
mLocalVarStart = 0;
mLabelNode = NULL;

View file

@ -3527,6 +3527,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
BfScopeData newScope;
newScope.mOuterIsConditional = true;
newScope.mScopeKind = BfScopeKind_StatementTarget;
if (ifStmt->mLabelNode != NULL)
newScope.mLabelNode = ifStmt->mLabelNode->mLabel;
mCurMethodState->AddScope(&newScope);
@ -3548,6 +3549,8 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
BfAutoParentNodeEntry autoParentNodeEntry(this, ifStmt);
BfTypedValue condValue = CreateValueFromExpression(ifStmt->mCondition, boolType);
newScope.mScopeKind = BfScopeKind_Normal;
deferredLocalAssignData.mIsIfCondition = false;
// The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and