mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 12:02:21 +02:00
Support for autoprop initializers
This commit is contained in:
parent
40b0d78d16
commit
041a17cf89
3 changed files with 32 additions and 8 deletions
|
@ -962,12 +962,21 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
|
||||||
fieldDef->mTypeRef = refTypeRef->mElementType;
|
fieldDef->mTypeRef = refTypeRef->mElementType;
|
||||||
fieldDef->mName = mCurTypeDef->GetAutoPropertyName(propertyDeclaration);
|
fieldDef->mName = mCurTypeDef->GetAutoPropertyName(propertyDeclaration);
|
||||||
fieldDef->mIdx = (int)mCurTypeDef->mFields.size();
|
fieldDef->mIdx = (int)mCurTypeDef->mFields.size();
|
||||||
|
fieldDef->mInitializer = propertyDeclaration->mInitializer;
|
||||||
mCurTypeDef->mFields.push_back(fieldDef);
|
mCurTypeDef->mFields.push_back(fieldDef);
|
||||||
|
|
||||||
mCurTypeDef->mSignatureHash = HashString(fieldDef->mName, mCurTypeDef->mSignatureHash);
|
mCurTypeDef->mSignatureHash = HashString(fieldDef->mName, mCurTypeDef->mSignatureHash);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (propertyDeclaration->mInitializer != NULL)
|
||||||
|
{
|
||||||
|
if (mCurTypeDef->mTypeCode == BfTypeCode_Interface)
|
||||||
|
Fail("Interface properties cannot have initializers", propertyDeclaration->mInitializer);
|
||||||
|
else
|
||||||
|
Fail("Properties with method bodies cannot have initializers", propertyDeclaration->mInitializer);
|
||||||
|
}
|
||||||
|
|
||||||
if (propertyDeclaration->mFieldDtor != NULL)
|
if (propertyDeclaration->mFieldDtor != NULL)
|
||||||
{
|
{
|
||||||
if (mCurTypeDef->mTypeCode == BfTypeCode_Interface)
|
if (mCurTypeDef->mTypeCode == BfTypeCode_Interface)
|
||||||
|
|
|
@ -2601,11 +2601,6 @@ void BfPrinter::Visit(BfPropertyDeclaration* propertyDeclaration)
|
||||||
ExpectSpace();
|
ExpectSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueVisitChild(propertyDeclaration->mEqualsNode);
|
|
||||||
ExpectSpace();
|
|
||||||
QueueVisitChild(propertyDeclaration->mInitializer);
|
|
||||||
FlushVisitChild();
|
|
||||||
|
|
||||||
if (auto block = BfNodeDynCast<BfBlock>(propertyDeclaration->mDefinitionBlock))
|
if (auto block = BfNodeDynCast<BfBlock>(propertyDeclaration->mDefinitionBlock))
|
||||||
{
|
{
|
||||||
BlockState blockState;
|
BlockState blockState;
|
||||||
|
@ -2628,6 +2623,12 @@ void BfPrinter::Visit(BfPropertyDeclaration* propertyDeclaration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExpectSpace();
|
||||||
|
QueueVisitChild(propertyDeclaration->mEqualsNode);
|
||||||
|
ExpectSpace();
|
||||||
|
QueueVisitChild(propertyDeclaration->mInitializer);
|
||||||
|
FlushVisitChild();
|
||||||
|
|
||||||
//QueueVisitChild(propertyDeclaration->mTrailingSemicolon);
|
//QueueVisitChild(propertyDeclaration->mTrailingSemicolon);
|
||||||
|
|
||||||
// ??? QueueVisitErrorNodes(propertyDeclaration);
|
// ??? QueueVisitErrorNodes(propertyDeclaration);
|
||||||
|
|
|
@ -6971,6 +6971,20 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept
|
||||||
MEMBER_SET(propertyDeclaration, mDefinitionBlock, block);
|
MEMBER_SET(propertyDeclaration, mDefinitionBlock, block);
|
||||||
ReadPropertyBlock(propertyDeclaration, block);
|
ReadPropertyBlock(propertyDeclaration, block);
|
||||||
|
|
||||||
|
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
|
||||||
|
{
|
||||||
|
if (tokenNode->mToken == BfToken_AssignEquals)
|
||||||
|
{
|
||||||
|
MEMBER_SET(propertyDeclaration, mEqualsNode, tokenNode);
|
||||||
|
mVisitorPos.MoveNext();
|
||||||
|
auto initExpr = CreateExpressionAfter(propertyDeclaration);
|
||||||
|
if (initExpr != NULL)
|
||||||
|
{
|
||||||
|
MEMBER_SET(propertyDeclaration, mInitializer, initExpr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
|
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
|
||||||
{
|
{
|
||||||
if (tokenNode->mToken == BfToken_Tilde)
|
if (tokenNode->mToken == BfToken_Tilde)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue