mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-14 14:24:10 +02:00
Allowing capture of shadowed (@) variables
This commit is contained in:
parent
95e4c1b3ca
commit
e1958d165e
2 changed files with 57 additions and 20 deletions
|
@ -2818,11 +2818,16 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
|
||||||
}
|
}
|
||||||
|
|
||||||
int varSkipCount = 0;
|
int varSkipCount = 0;
|
||||||
StringT<128> wantName = findName;
|
StringT<128> wantName;
|
||||||
while (wantName.StartsWith("@"))
|
wantName.Reference(findName);
|
||||||
|
if (findName.StartsWith('@'))
|
||||||
{
|
{
|
||||||
varSkipCount++;
|
wantName = findName;
|
||||||
wantName.Remove(0);
|
while (wantName.StartsWith("@"))
|
||||||
|
{
|
||||||
|
varSkipCount++;
|
||||||
|
wantName.Remove(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wantName.IsEmpty())
|
if (wantName.IsEmpty())
|
||||||
|
@ -2887,12 +2892,31 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfAstNode* refNode, const StringI
|
||||||
|
|
||||||
// Check for the captured locals. It's important we do it here so we get local-first precedence still
|
// Check for the captured locals. It's important we do it here so we get local-first precedence still
|
||||||
if (closureTypeInst != NULL)
|
if (closureTypeInst != NULL)
|
||||||
{
|
{
|
||||||
|
int varSkipCount = 0;
|
||||||
|
StringT<128> wantName;
|
||||||
|
wantName.Reference(findName);
|
||||||
|
if (findName.StartsWith('@'))
|
||||||
|
{
|
||||||
|
wantName = findName;
|
||||||
|
while (wantName.StartsWith("@"))
|
||||||
|
{
|
||||||
|
varSkipCount++;
|
||||||
|
wantName.Remove(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
closureTypeInst->mTypeDef->PopulateMemberSets();
|
closureTypeInst->mTypeDef->PopulateMemberSets();
|
||||||
BfMemberSetEntry* memberSetEntry = NULL;
|
BfMemberSetEntry* memberSetEntry = NULL;
|
||||||
if (closureTypeInst->mTypeDef->mFieldSet.TryGetWith(findName, &memberSetEntry))
|
if (closureTypeInst->mTypeDef->mFieldSet.TryGetWith((StringImpl&)wantName, &memberSetEntry))
|
||||||
{
|
{
|
||||||
auto fieldDef = (BfFieldDef*)memberSetEntry->mMemberDef;
|
auto fieldDef = (BfFieldDef*)memberSetEntry->mMemberDef;
|
||||||
|
while ((varSkipCount > 0) && (fieldDef != NULL))
|
||||||
|
{
|
||||||
|
fieldDef = fieldDef->mNextWithSameName;
|
||||||
|
varSkipCount--;
|
||||||
|
}
|
||||||
|
|
||||||
auto& field = closureTypeInst->mFieldInstances[fieldDef->mIdx];
|
auto& field = closureTypeInst->mFieldInstances[fieldDef->mIdx];
|
||||||
if (!field.mResolvedType->IsValuelessType())
|
if (!field.mResolvedType->IsValuelessType())
|
||||||
{
|
{
|
||||||
|
@ -3145,7 +3169,22 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
else if (target.mType != NULL)
|
else if (target.mType != NULL)
|
||||||
{
|
{
|
||||||
startCheckType = target.mType->ToTypeInstance();
|
startCheckType = target.mType->ToTypeInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String findName;
|
||||||
|
int varSkipCount = 0;
|
||||||
|
if (fieldName.StartsWith('@'))
|
||||||
|
{
|
||||||
|
findName = fieldName;
|
||||||
|
while (findName.StartsWith('@'))
|
||||||
|
{
|
||||||
|
findName.Remove(0);
|
||||||
|
varSkipCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
findName.Reference(fieldName);
|
||||||
|
|
||||||
|
|
||||||
auto activeTypeDef = mModule->GetActiveTypeDef();
|
auto activeTypeDef = mModule->GetActiveTypeDef();
|
||||||
for (int pass = 0; pass < 2; pass++)
|
for (int pass = 0; pass < 2; pass++)
|
||||||
|
@ -3159,9 +3198,14 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
curCheckType->mTypeDef->PopulateMemberSets();
|
curCheckType->mTypeDef->PopulateMemberSets();
|
||||||
BfFieldDef* nextField = NULL;
|
BfFieldDef* nextField = NULL;
|
||||||
BfMemberSetEntry* entry;
|
BfMemberSetEntry* entry;
|
||||||
if (curCheckType->mTypeDef->mFieldSet.TryGetWith(fieldName, &entry))
|
if (curCheckType->mTypeDef->mFieldSet.TryGetWith(findName, &entry))
|
||||||
nextField = (BfFieldDef*)entry->mMemberDef;
|
nextField = (BfFieldDef*)entry->mMemberDef;
|
||||||
|
|
||||||
|
while ((varSkipCount > 0) && (nextField != NULL))
|
||||||
|
{
|
||||||
|
nextField = nextField->mNextWithSameName;
|
||||||
|
}
|
||||||
|
|
||||||
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
|
BfProtectionCheckFlags protectionCheckFlags = BfProtectionCheckFlag_None;
|
||||||
BfFieldDef* matchedField = NULL;
|
BfFieldDef* matchedField = NULL;
|
||||||
while (nextField != NULL)
|
while (nextField != NULL)
|
||||||
|
@ -3174,16 +3218,9 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//OLD:
|
|
||||||
bool isResolvingFields = curCheckType->mResolvingConstField || curCheckType->mResolvingVarField;
|
bool isResolvingFields = curCheckType->mResolvingConstField || curCheckType->mResolvingVarField;
|
||||||
|
|
||||||
// mCurMethodState is NULL when we're pre-evaluating var field expressions
|
|
||||||
// to determine their type in PopulateFields
|
|
||||||
/*if (!isResolvingFields)
|
|
||||||
{
|
|
||||||
mModule->PopulateType(curCheckType, BfPopulateType_Data);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (curCheckType->mFieldInstances.IsEmpty())
|
if (curCheckType->mFieldInstances.IsEmpty())
|
||||||
{
|
{
|
||||||
mModule->PopulateType(curCheckType, BfPopulateType_Data);
|
mModule->PopulateType(curCheckType, BfPopulateType_Data);
|
||||||
|
@ -3219,7 +3256,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchedField != NULL)
|
if (matchedField != NULL)
|
||||||
{
|
{
|
||||||
auto field = matchedField;
|
auto field = matchedField;
|
||||||
auto fieldInstance = &curCheckType->mFieldInstances[field->mIdx];
|
auto fieldInstance = &curCheckType->mFieldInstances[field->mIdx];
|
||||||
|
|
||||||
|
|
|
@ -822,7 +822,7 @@ struct BfMemberSetEntry
|
||||||
return mMemberDef->mName == other.mMemberDef->mName;
|
return mMemberDef->mName == other.mMemberDef->mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const String& other) const
|
bool operator==(const StringImpl& other) const
|
||||||
{
|
{
|
||||||
return mMemberDef->mName == other;
|
return mMemberDef->mName == other;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue