1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Allow ref property setter specifier

This commit is contained in:
Brian Fiete 2021-11-27 09:05:23 -08:00
parent 0d837d23cb
commit 40b0d78d16
6 changed files with 38 additions and 9 deletions

View file

@ -3099,6 +3099,7 @@ public:
BfPropertyDeclaration* mPropertyDeclaration;
BfAttributeDirective* mAttributes;
BfAstNode* mProtectionSpecifier;
BfTokenNode* mSetRefSpecifier;
BfTokenNode* mMutSpecifier;
BfIdentifierNode* mNameNode;
BfTokenNode* mFatArrowToken;

View file

@ -1080,10 +1080,17 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
auto paramDef = new BfParameterDef();
paramDef->mName = "value";
if (auto refTypeRef = BfNodeDynCast<BfRefTypeRef>(propertyDeclaration->mTypeRef))
paramDef->mTypeRef = refTypeRef->mElementType;
else
paramDef->mTypeRef = propertyDeclaration->mTypeRef;
if (auto refTypeRef = BfNodeDynCast<BfRefTypeRef>(propertyDeclaration->mTypeRef))
{
if (methodDeclaration->mSetRefSpecifier == NULL)
paramDef->mTypeRef = refTypeRef->mElementType;
}
else
{
if (methodDeclaration->mSetRefSpecifier != NULL)
Fail("Property setter 'ref' can only be used with a 'ref' property type", methodDeclaration->mSetRefSpecifier);
}
methodDef->mParams.Insert(0, paramDef);
propertyDef->mMethods.Add(methodDef);
}

View file

@ -1050,6 +1050,7 @@ void BfElementVisitor::Visit(BfPropertyMethodDeclaration* propertyDeclaration)
VisitChild(propertyDeclaration->mAttributes);
VisitChild(propertyDeclaration->mProtectionSpecifier);
VisitChild(propertyDeclaration->mNameNode);
VisitChild(propertyDeclaration->mSetRefSpecifier);
VisitChild(propertyDeclaration->mMutSpecifier);
VisitChild(propertyDeclaration->mFatArrowToken);
VisitChild(propertyDeclaration->mBody);

View file

@ -18128,7 +18128,10 @@ void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool
mModule->AssertErrorState();
return;
}
convVal = mModule->CreateValueFromExpression(assignExpr->mRight, wantType, (BfEvalExprFlags)(BfEvalExprFlags_AllowSplat | BfEvalExprFlags_PendingPropSet));
BfEvalExprFlags exprFlags = (BfEvalExprFlags)(BfEvalExprFlags_AllowSplat | BfEvalExprFlags_PendingPropSet);
if (wantType->IsRef())
exprFlags = (BfEvalExprFlags)(exprFlags | BfEvalExprFlags_AllowRefExpr);
convVal = mModule->CreateValueFromExpression(assignExpr->mRight, wantType, exprFlags);
}
if (!convVal)
{

View file

@ -2545,6 +2545,8 @@ void BfPrinter::Visit(BfPropertyMethodDeclaration* propertyMethodDeclaration)
ExpectSpace();
QueueVisitChild(propertyMethodDeclaration->mNameNode);
ExpectSpace();
QueueVisitChild(propertyMethodDeclaration->mSetRefSpecifier);
ExpectSpace();
QueueVisitChild(propertyMethodDeclaration->mMutSpecifier);
ExpectSpace();
QueueVisitChild(propertyMethodDeclaration->mFatArrowToken);

View file

@ -6392,6 +6392,7 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
String accessorName;
BfTokenNode* mutSpecifier = NULL;
BfTokenNode* refSpecifier = NULL;
while (true)
{
@ -6461,6 +6462,16 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
BfAstNode* body = NULL;
auto tokenNode = BfNodeDynCast<BfTokenNode>(child);
if ((tokenNode != NULL) && (tokenNode->GetToken() == BfToken_Ref) && (accessorName == "set"))
{
refSpecifier = tokenNode;
bodyAfterNode = tokenNode;
mVisitorPos.MoveNext();
child = mVisitorPos.GetNext();
tokenNode = BfNodeDynCast<BfTokenNode>(child);
}
if ((tokenNode != NULL) && (tokenNode->GetToken() == BfToken_Mut))
{
if (mutSpecifier != NULL)
@ -6543,6 +6554,8 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
AddErrorNode(accessorIdentifier);
if (mutSpecifier != NULL)
AddErrorNode(mutSpecifier);
if (refSpecifier != NULL)
AddErrorNode(refSpecifier);
continue;
}
@ -6561,6 +6574,8 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
{
MEMBER_SET(method, mBody, body);
}
if (refSpecifier != NULL)
MEMBER_SET(method, mSetRefSpecifier, refSpecifier);
if (mutSpecifier != NULL)
MEMBER_SET(method, mMutSpecifier, mutSpecifier);
// if ((accessorBlock != NULL) && (IsNodeRelevant(propertyDeclaration)))