mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Allow ref property setter specifier
This commit is contained in:
parent
0d837d23cb
commit
40b0d78d16
6 changed files with 38 additions and 9 deletions
|
@ -3099,6 +3099,7 @@ public:
|
||||||
BfPropertyDeclaration* mPropertyDeclaration;
|
BfPropertyDeclaration* mPropertyDeclaration;
|
||||||
BfAttributeDirective* mAttributes;
|
BfAttributeDirective* mAttributes;
|
||||||
BfAstNode* mProtectionSpecifier;
|
BfAstNode* mProtectionSpecifier;
|
||||||
|
BfTokenNode* mSetRefSpecifier;
|
||||||
BfTokenNode* mMutSpecifier;
|
BfTokenNode* mMutSpecifier;
|
||||||
BfIdentifierNode* mNameNode;
|
BfIdentifierNode* mNameNode;
|
||||||
BfTokenNode* mFatArrowToken;
|
BfTokenNode* mFatArrowToken;
|
||||||
|
|
|
@ -1080,10 +1080,17 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
|
||||||
|
|
||||||
auto paramDef = new BfParameterDef();
|
auto paramDef = new BfParameterDef();
|
||||||
paramDef->mName = "value";
|
paramDef->mName = "value";
|
||||||
if (auto refTypeRef = BfNodeDynCast<BfRefTypeRef>(propertyDeclaration->mTypeRef))
|
|
||||||
paramDef->mTypeRef = refTypeRef->mElementType;
|
|
||||||
else
|
|
||||||
paramDef->mTypeRef = propertyDeclaration->mTypeRef;
|
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);
|
methodDef->mParams.Insert(0, paramDef);
|
||||||
propertyDef->mMethods.Add(methodDef);
|
propertyDef->mMethods.Add(methodDef);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1050,6 +1050,7 @@ void BfElementVisitor::Visit(BfPropertyMethodDeclaration* propertyDeclaration)
|
||||||
VisitChild(propertyDeclaration->mAttributes);
|
VisitChild(propertyDeclaration->mAttributes);
|
||||||
VisitChild(propertyDeclaration->mProtectionSpecifier);
|
VisitChild(propertyDeclaration->mProtectionSpecifier);
|
||||||
VisitChild(propertyDeclaration->mNameNode);
|
VisitChild(propertyDeclaration->mNameNode);
|
||||||
|
VisitChild(propertyDeclaration->mSetRefSpecifier);
|
||||||
VisitChild(propertyDeclaration->mMutSpecifier);
|
VisitChild(propertyDeclaration->mMutSpecifier);
|
||||||
VisitChild(propertyDeclaration->mFatArrowToken);
|
VisitChild(propertyDeclaration->mFatArrowToken);
|
||||||
VisitChild(propertyDeclaration->mBody);
|
VisitChild(propertyDeclaration->mBody);
|
||||||
|
|
|
@ -18128,7 +18128,10 @@ void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool
|
||||||
mModule->AssertErrorState();
|
mModule->AssertErrorState();
|
||||||
return;
|
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)
|
if (!convVal)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2545,6 +2545,8 @@ void BfPrinter::Visit(BfPropertyMethodDeclaration* propertyMethodDeclaration)
|
||||||
ExpectSpace();
|
ExpectSpace();
|
||||||
QueueVisitChild(propertyMethodDeclaration->mNameNode);
|
QueueVisitChild(propertyMethodDeclaration->mNameNode);
|
||||||
ExpectSpace();
|
ExpectSpace();
|
||||||
|
QueueVisitChild(propertyMethodDeclaration->mSetRefSpecifier);
|
||||||
|
ExpectSpace();
|
||||||
QueueVisitChild(propertyMethodDeclaration->mMutSpecifier);
|
QueueVisitChild(propertyMethodDeclaration->mMutSpecifier);
|
||||||
ExpectSpace();
|
ExpectSpace();
|
||||||
QueueVisitChild(propertyMethodDeclaration->mFatArrowToken);
|
QueueVisitChild(propertyMethodDeclaration->mFatArrowToken);
|
||||||
|
|
|
@ -6392,6 +6392,7 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
|
||||||
|
|
||||||
String accessorName;
|
String accessorName;
|
||||||
BfTokenNode* mutSpecifier = NULL;
|
BfTokenNode* mutSpecifier = NULL;
|
||||||
|
BfTokenNode* refSpecifier = NULL;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -6461,6 +6462,16 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
|
||||||
BfAstNode* body = NULL;
|
BfAstNode* body = NULL;
|
||||||
|
|
||||||
auto tokenNode = BfNodeDynCast<BfTokenNode>(child);
|
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 ((tokenNode != NULL) && (tokenNode->GetToken() == BfToken_Mut))
|
||||||
{
|
{
|
||||||
if (mutSpecifier != NULL)
|
if (mutSpecifier != NULL)
|
||||||
|
@ -6543,6 +6554,8 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
|
||||||
AddErrorNode(accessorIdentifier);
|
AddErrorNode(accessorIdentifier);
|
||||||
if (mutSpecifier != NULL)
|
if (mutSpecifier != NULL)
|
||||||
AddErrorNode(mutSpecifier);
|
AddErrorNode(mutSpecifier);
|
||||||
|
if (refSpecifier != NULL)
|
||||||
|
AddErrorNode(refSpecifier);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6561,6 +6574,8 @@ void BfReducer::ReadPropertyBlock(BfPropertyDeclaration* propertyDeclaration, Bf
|
||||||
{
|
{
|
||||||
MEMBER_SET(method, mBody, body);
|
MEMBER_SET(method, mBody, body);
|
||||||
}
|
}
|
||||||
|
if (refSpecifier != NULL)
|
||||||
|
MEMBER_SET(method, mSetRefSpecifier, refSpecifier);
|
||||||
if (mutSpecifier != NULL)
|
if (mutSpecifier != NULL)
|
||||||
MEMBER_SET(method, mMutSpecifier, mutSpecifier);
|
MEMBER_SET(method, mMutSpecifier, mutSpecifier);
|
||||||
// if ((accessorBlock != NULL) && (IsNodeRelevant(propertyDeclaration)))
|
// if ((accessorBlock != NULL) && (IsNodeRelevant(propertyDeclaration)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue