mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Support for expression-bodied properties with mut
This commit is contained in:
parent
60b6437f69
commit
c0fe1d1c1b
7 changed files with 47 additions and 11 deletions
|
@ -3111,6 +3111,7 @@ class BfPropertyBodyExpression : public BfAstNode
|
|||
{
|
||||
public:
|
||||
BF_AST_TYPE(BfPropertyBodyExpression, BfAstNode);
|
||||
BfTokenNode* mMutSpecifier;
|
||||
BfTokenNode* mFatTokenArrow;
|
||||
}; BF_AST_DECL(BfPropertyBodyExpression, BfAstNode);
|
||||
|
||||
|
|
|
@ -1067,6 +1067,9 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
|
|||
{
|
||||
methodName = "get";
|
||||
ParseAttributes(propertyDeclaration->mAttributes, methodDef);
|
||||
if (propExprBody->mMutSpecifier != NULL)
|
||||
methodDef->mIsMutating = true;
|
||||
HashNode(*mSignatureHashCtx, propExprBody->mMutSpecifier);
|
||||
}
|
||||
else if ((methodDeclaration != NULL) && (methodDeclaration->mNameNode != NULL))
|
||||
methodName = methodDeclaration->mNameNode->ToString();
|
||||
|
|
|
@ -1061,6 +1061,7 @@ void BfElementVisitor::Visit(BfPropertyBodyExpression* propertyBodyExpression)
|
|||
{
|
||||
Visit(propertyBodyExpression->ToBase());
|
||||
|
||||
VisitChild(propertyBodyExpression->mMutSpecifier);
|
||||
VisitChild(propertyBodyExpression->mFatTokenArrow);
|
||||
}
|
||||
|
||||
|
|
|
@ -22952,7 +22952,18 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
|||
if (methodDeclaration != NULL)
|
||||
mutSpecifier = methodDeclaration->mMutSpecifier;
|
||||
else if (methodDef->GetPropertyMethodDeclaration() != NULL)
|
||||
{
|
||||
mutSpecifier = methodDef->GetPropertyMethodDeclaration()->mMutSpecifier;
|
||||
if (mutSpecifier == NULL)
|
||||
{
|
||||
auto propertyDeclaration = methodDef->GetPropertyDeclaration();
|
||||
if (propertyDeclaration != NULL)
|
||||
{
|
||||
if (auto propExprBody = BfNodeDynCast<BfPropertyBodyExpression>(propertyDeclaration->mDefinitionBlock))
|
||||
mutSpecifier = propExprBody->mMutSpecifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((mutSpecifier != NULL) && (!mCurTypeInstance->IsBoxed()) && (!methodInstance->mIsForeignMethodDef))
|
||||
{
|
||||
|
|
|
@ -2584,6 +2584,13 @@ void BfPrinter::Visit(BfPropertyMethodDeclaration* propertyMethodDeclaration)
|
|||
QueueVisitChild(propertyMethodDeclaration->mEndSemicolon);
|
||||
}
|
||||
|
||||
void BfPrinter::Visit(BfPropertyBodyExpression* propertyBodyExpression)
|
||||
{
|
||||
VisitChild(propertyBodyExpression->mMutSpecifier);
|
||||
ExpectSpace();
|
||||
VisitChild(propertyBodyExpression->mFatTokenArrow);
|
||||
}
|
||||
|
||||
void BfPrinter::Visit(BfPropertyDeclaration* propertyDeclaration)
|
||||
{
|
||||
auto indexerDeclaration = BfNodeDynCast<BfIndexerDeclaration>(propertyDeclaration);
|
||||
|
|
|
@ -215,6 +215,7 @@ public:
|
|||
virtual void Visit(BfMethodDeclaration* methodDeclaration) override;
|
||||
virtual void Visit(BfOperatorDeclaration* opreratorDeclaration) override;
|
||||
virtual void Visit(BfPropertyMethodDeclaration* propertyDeclaration) override;
|
||||
virtual void Visit(BfPropertyBodyExpression* propertyBodyExpression) override;
|
||||
virtual void Visit(BfPropertyDeclaration* propertyDeclaration) override;
|
||||
virtual void Visit(BfIndexerDeclaration* indexerDeclaration) override;
|
||||
virtual void Visit(BfFieldDeclaration* fieldDeclaration) override;
|
||||
|
|
|
@ -6966,7 +6966,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept
|
|||
auto block = BfNodeDynCast<BfBlock>(nextNode);
|
||||
auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNode);
|
||||
|
||||
bool isExprBodyProp = (tokenNode != NULL) && (tokenNode->mToken == BfToken_FatArrow);
|
||||
bool isExprBodyProp = (tokenNode != NULL) && ((tokenNode->mToken == BfToken_FatArrow) || (tokenNode->mToken == BfToken_Mut));
|
||||
// Property.
|
||||
// If we don't have a token afterwards then still treat it as a property for autocomplete purposes
|
||||
if ((typeRef != NULL) &&
|
||||
|
@ -7050,6 +7050,17 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept
|
|||
|
||||
auto propertyBodyExpr = mAlloc->Alloc<BfPropertyBodyExpression>();
|
||||
ReplaceNode(tokenNode, propertyBodyExpr);
|
||||
|
||||
BfTokenNode* mutSpecifier = NULL;
|
||||
|
||||
if (tokenNode->mToken == BfToken_Mut)
|
||||
{
|
||||
MEMBER_SET(propertyBodyExpr, mMutSpecifier, tokenNode);
|
||||
tokenNode = ExpectTokenAfter(tokenNode, BfToken_FatArrow);
|
||||
}
|
||||
|
||||
if (tokenNode != NULL)
|
||||
{
|
||||
MEMBER_SET(propertyBodyExpr, mFatTokenArrow, tokenNode);
|
||||
|
||||
auto method = mAlloc->Alloc<BfPropertyMethodDeclaration>();
|
||||
|
@ -7064,6 +7075,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept
|
|||
}
|
||||
|
||||
methods.Add(method);
|
||||
}
|
||||
|
||||
MEMBER_SET(propertyDeclaration, mDefinitionBlock, propertyBodyExpr);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue