1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Added support for attributes on enum case members

This commit is contained in:
Brian Fiete 2020-11-09 06:53:47 -08:00
parent 330eb037e8
commit 6cb13900b0
3 changed files with 56 additions and 10 deletions

View file

@ -347,19 +347,12 @@ namespace System
}
}
[AttributeUsage(.Field | .Method | .Property /*2*/)]
[AttributeUsage(.Field | .StaticField | .Method | .Property /*2*/)]
public struct NoShowAttribute : Attribute
{
}
[AttributeUsage(.Field | .Method | .Property /*2*/)]
public struct HideAttribute : Attribute
{
}
[AttributeUsage(.Parameter)]
public struct HideNameAttribute : Attribute
{

View file

@ -1087,8 +1087,11 @@ void BfDefBuilder::Visit(BfFieldDeclaration* fieldDeclaration)
}
void BfDefBuilder::Visit(BfEnumCaseDeclaration* enumCaseDeclaration)
{
if (!WantsNode(enumCaseDeclaration, enumCaseDeclaration->mCaseToken, 0))
{
// Using `enumCaseDeclaration->mCaseToken` breaks attribute autocompletion
//if (!WantsNode(enumCaseDeclaration, enumCaseDeclaration->mCaseToken, 0))
if (!WantsNode(enumCaseDeclaration))
{
return;
}

View file

@ -5726,6 +5726,18 @@ BfAstNode* BfReducer::ReadTypeMember(BfTokenNode* tokenNode, int depth, BfAstNod
auto memberNode = ReadTypeMember(nextNode, 0, (deferredHeadNode != NULL) ? deferredHeadNode : attributes);
if (memberNode == NULL)
return NULL;
if (auto enumCaseDecl = BfNodeDynCast<BfEnumCaseDeclaration>(memberNode))
{
if (!enumCaseDecl->mEntries.IsEmpty())
{
enumCaseDecl->mSrcStart = attributes->mSrcStart;
enumCaseDecl->mEntries[0]->mAttributes = attributes;
enumCaseDecl->mEntries[0]->mSrcStart = attributes->mSrcStart;
return enumCaseDecl;
}
}
auto member = BfNodeDynCast<BfMemberDeclaration>(memberNode);
if (member == NULL)
{
@ -7855,6 +7867,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
bool hadIllegal = false;
bool inAssignment = false;
int bracketDepth = 0;
int checkIdx = 0;
while (true)
@ -7878,6 +7891,18 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
{
inAssignment = true;
}
else if (tokenNode->mToken == BfToken_LBracket)
{
bracketDepth++;
}
else if (tokenNode->mToken == BfToken_RBracket)
{
bracketDepth--;
}
else if (bracketDepth != 0)
{
// Allow
}
else if (tokenNode->mToken == BfToken_Semicolon)
{
hadIllegal = true;
@ -7892,6 +7917,10 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
}
}
}
else if (bracketDepth != 0)
{
// Allow
}
else
{
if (!inAssignment)
@ -8438,10 +8467,31 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
if (child == NULL)
break;
auto fieldDecl = mAlloc->Alloc<BfEnumEntryDeclaration>();
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(child))
{
if (tokenNode->mToken == BfToken_LBracket)
{
BfAttributeDirective* attribute = CreateAttributeDirective(tokenNode);
if (attribute != NULL)
{
mVisitorPos.MoveNext();
child = mVisitorPos.GetCurrent();
fieldDecl->mAttributes = attribute;
if (child == NULL)
break;
}
}
}
mVisitorPos.MoveNext();
mVisitorPos.Write(fieldDecl);
ReplaceNode(child, fieldDecl);
if (fieldDecl->mAttributes != NULL)
fieldDecl->mSrcStart = fieldDecl->mAttributes->mSrcStart;
auto valueName = BfNodeDynCast<BfIdentifierNode>(child);
if (valueName == NULL)
{