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:
parent
5b8d2ffee2
commit
965e2e2930
4 changed files with 79 additions and 0 deletions
|
@ -228,5 +228,63 @@ namespace IDETest
|
||||||
int c = b; //FAIL
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6561,6 +6561,13 @@ BfTypedValue BfExprEvaluator::ResolveArgValue(BfResolvedArg& resolvedArg, BfType
|
||||||
CheckVariableDeclaration(resolvedArg.mExpression, false, false, false);
|
CheckVariableDeclaration(resolvedArg.mExpression, false, false, false);
|
||||||
|
|
||||||
argValue = BfTypedValue(localVar->mAddr, mModule->CreateRefType(variableType, BfRefType::RefKind_Out));
|
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;
|
return argValue;
|
||||||
}
|
}
|
||||||
|
@ -18589,6 +18596,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfExpression* leftExpression, BfExp
|
||||||
{
|
{
|
||||||
if (mModule->mCurMethodState->mDeferredLocalAssignData != NULL)
|
if (mModule->mCurMethodState->mDeferredLocalAssignData != NULL)
|
||||||
mModule->mCurMethodState->mDeferredLocalAssignData->BreakExtendChain();
|
mModule->mCurMethodState->mDeferredLocalAssignData->BreakExtendChain();
|
||||||
|
if (mModule->mCurMethodState->mCurScope->mScopeKind == BfScopeKind_StatementTarget)
|
||||||
|
mModule->mCurMethodState->mCurScope->mScopeKind = BfScopeKind_StatementTarget_Conditional;
|
||||||
|
|
||||||
bool isAnd = binaryOp == BfBinaryOp_ConditionalAnd;
|
bool isAnd = binaryOp == BfBinaryOp_ConditionalAnd;
|
||||||
|
|
||||||
|
|
|
@ -357,12 +357,20 @@ public:
|
||||||
void SetUnion(const BfDeferredLocalAssignData& otherLocalAssignData);
|
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" 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.
|
// Looped and Conditional are mutually exclusive. "Dyn" means Looped OR Conditional.
|
||||||
class BfScopeData
|
class BfScopeData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BfScopeData* mPrevScope;
|
BfScopeData* mPrevScope;
|
||||||
|
BfScopeKind mScopeKind;
|
||||||
BfIRMDNode mDIScope;
|
BfIRMDNode mDIScope;
|
||||||
BfIRMDNode mDIInlinedAt;
|
BfIRMDNode mDIInlinedAt;
|
||||||
String mLabel;
|
String mLabel;
|
||||||
|
@ -399,6 +407,7 @@ public:
|
||||||
public:
|
public:
|
||||||
BfScopeData()
|
BfScopeData()
|
||||||
{
|
{
|
||||||
|
mScopeKind = BfScopeKind_Normal;
|
||||||
mPrevScope = NULL;
|
mPrevScope = NULL;
|
||||||
mLocalVarStart = 0;
|
mLocalVarStart = 0;
|
||||||
mLabelNode = NULL;
|
mLabelNode = NULL;
|
||||||
|
|
|
@ -3527,6 +3527,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
|
||||||
|
|
||||||
BfScopeData newScope;
|
BfScopeData newScope;
|
||||||
newScope.mOuterIsConditional = true;
|
newScope.mOuterIsConditional = true;
|
||||||
|
newScope.mScopeKind = BfScopeKind_StatementTarget;
|
||||||
if (ifStmt->mLabelNode != NULL)
|
if (ifStmt->mLabelNode != NULL)
|
||||||
newScope.mLabelNode = ifStmt->mLabelNode->mLabel;
|
newScope.mLabelNode = ifStmt->mLabelNode->mLabel;
|
||||||
mCurMethodState->AddScope(&newScope);
|
mCurMethodState->AddScope(&newScope);
|
||||||
|
@ -3548,6 +3549,8 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
|
||||||
BfAutoParentNodeEntry autoParentNodeEntry(this, ifStmt);
|
BfAutoParentNodeEntry autoParentNodeEntry(this, ifStmt);
|
||||||
BfTypedValue condValue = CreateValueFromExpression(ifStmt->mCondition, boolType);
|
BfTypedValue condValue = CreateValueFromExpression(ifStmt->mCondition, boolType);
|
||||||
|
|
||||||
|
newScope.mScopeKind = BfScopeKind_Normal;
|
||||||
|
|
||||||
deferredLocalAssignData.mIsIfCondition = false;
|
deferredLocalAssignData.mIsIfCondition = false;
|
||||||
|
|
||||||
// The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and
|
// The "extend chain" is only valid for the conditional -- since that expression may contain unconditionally executed and
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue