mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Allow method attributes on properties with expression bodies
This commit is contained in:
parent
4369e07a55
commit
535045c48a
6 changed files with 39 additions and 19 deletions
|
@ -4149,7 +4149,10 @@ void BfCompiler::ProcessAutocompleteTempType()
|
|||
{
|
||||
if ((propDef->mFieldDeclaration != NULL) && (propDef->mFieldDeclaration->mAttributes != NULL))
|
||||
{
|
||||
auto customAttrs = module->GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, BfAttributeTargets_Property);
|
||||
BfAttributeTargets target = BfAttributeTargets_Property;
|
||||
if (propDef->IsExpressionBodied())
|
||||
target = (BfAttributeTargets)(target | BfAttributeTargets_Method);
|
||||
auto customAttrs = module->GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, target);
|
||||
delete customAttrs;
|
||||
}
|
||||
|
||||
|
|
|
@ -949,7 +949,10 @@ void BfDefBuilder::Visit(BfPropertyDeclaration* propertyDeclaration)
|
|||
|
||||
String methodName;
|
||||
if (auto propExprBody = BfNodeDynCast<BfPropertyBodyExpression>(propertyDeclaration->mDefinitionBlock))
|
||||
{
|
||||
methodName = "get";
|
||||
ParseAttributes(propertyDeclaration->mAttributes, methodDef);
|
||||
}
|
||||
else if ((methodDeclaration != NULL) && (methodDeclaration->mNameNode != NULL))
|
||||
methodName = methodDeclaration->mNameNode->ToString();
|
||||
|
||||
|
|
|
@ -19512,18 +19512,25 @@ void BfModule::GetMethodCustomAttributes(BfMethodInstance* methodInstance)
|
|||
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance, typeInstance);
|
||||
SetAndRestoreValue<BfMethodInstance*> prevMethodInstance(mCurMethodInstance, methodInstance);
|
||||
|
||||
if ((methodDeclaration != NULL) && (methodDeclaration->mAttributes != NULL))
|
||||
BfAttributeTargets attrTarget = ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_CtorCalcAppend)) ? BfAttributeTargets_Constructor : BfAttributeTargets_Method;
|
||||
BfAttributeDirective* attributeDirective = NULL;
|
||||
if (methodDeclaration != NULL)
|
||||
attributeDirective = methodDeclaration->mAttributes;
|
||||
else if (propertyMethodDeclaration != NULL)
|
||||
{
|
||||
if (methodInstance->GetMethodInfoEx()->mMethodCustomAttributes == NULL)
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes = new BfMethodCustomAttributes();
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(methodDeclaration->mAttributes,
|
||||
((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_CtorCalcAppend)) ? BfAttributeTargets_Constructor : BfAttributeTargets_Method);
|
||||
attributeDirective = propertyMethodDeclaration->mAttributes;
|
||||
if (auto exprBody = BfNodeDynCast<BfPropertyBodyExpression>(propertyMethodDeclaration->mPropertyDeclaration->mDefinitionBlock))
|
||||
{
|
||||
attributeDirective = propertyMethodDeclaration->mPropertyDeclaration->mAttributes;
|
||||
attrTarget = (BfAttributeTargets)(BfAttributeTargets_Property | BfAttributeTargets_Method);
|
||||
}
|
||||
else if ((propertyMethodDeclaration != NULL) && (propertyMethodDeclaration->mAttributes != NULL))
|
||||
}
|
||||
|
||||
if (attributeDirective != NULL)
|
||||
{
|
||||
if (methodInstance->GetMethodInfoEx()->mMethodCustomAttributes == NULL)
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes = new BfMethodCustomAttributes();
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(propertyMethodDeclaration->mAttributes, BfAttributeTargets_Method);
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(attributeDirective, attrTarget);
|
||||
}
|
||||
|
||||
customAttributes = methodInstance->GetCustomAttributes();
|
||||
|
|
|
@ -2887,15 +2887,13 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
typeState.mTypeInstance = typeInstance;
|
||||
SetAndRestoreValue<BfTypeState*> prevTypeState(mContext->mCurTypeState, &typeState);
|
||||
|
||||
if (propDef->mFieldDeclaration->mAttributes != NULL)
|
||||
{
|
||||
auto customAttrs = GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, BfAttributeTargets_Property);
|
||||
delete customAttrs;
|
||||
}
|
||||
BfAttributeTargets target = BfAttributeTargets_Property;
|
||||
if (propDef->IsExpressionBodied())
|
||||
target = (BfAttributeTargets)(target | BfAttributeTargets_Method);
|
||||
|
||||
if (propDef->mFieldDeclaration->mAttributes != NULL)
|
||||
{
|
||||
auto customAttrs = GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, BfAttributeTargets_Property);
|
||||
auto customAttrs = GetCustomAttributes(propDef->mFieldDeclaration->mAttributes, target);
|
||||
delete customAttrs;
|
||||
}
|
||||
|
||||
|
|
|
@ -398,6 +398,14 @@ bool BfPropertyDef::HasExplicitInterface()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool BfPropertyDef::IsExpressionBodied()
|
||||
{
|
||||
auto propertyDeclaration = (BfPropertyDeclaration*)mFieldDeclaration;
|
||||
if (auto expr = BfNodeDynCast<BfPropertyBodyExpression>(propertyDeclaration->mDefinitionBlock))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
BfAstNode * BfPropertyDef::GetRefNode()
|
||||
{
|
||||
BfPropertyDeclaration* propDecl = (BfPropertyDeclaration*)mFieldDeclaration;
|
||||
|
|
|
@ -580,6 +580,7 @@ public:
|
|||
|
||||
bool IsVirtual();
|
||||
bool HasExplicitInterface();
|
||||
bool IsExpressionBodied();
|
||||
BfAstNode* GetRefNode();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue