mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Anonymous type improvements
This commit is contained in:
parent
97c119cbc7
commit
01c2c35fc3
2 changed files with 19 additions and 8 deletions
|
@ -404,7 +404,7 @@ bool BfReducer::IsTypeReference(BfAstNode* checkNode, BfToken successToken, int
|
||||||
mVisitorPos.mReadPos = startNode;
|
mVisitorPos.mReadPos = startNode;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if ((checkToken == BfToken_Struct) || (checkToken == BfToken_Class) || (checkToken == BfToken_Interface) || (checkToken == BfToken_Enum))
|
else if (BfTokenIsTypeDecl(checkToken))
|
||||||
{
|
{
|
||||||
checkIdx++;
|
checkIdx++;
|
||||||
auto nextNode = mVisitorPos.Get(checkIdx);
|
auto nextNode = mVisitorPos.Get(checkIdx);
|
||||||
|
@ -5188,7 +5188,7 @@ BfTypeReference* BfReducer::DoCreateTypeRef(BfAstNode* firstNode, CreateTypeRefF
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
auto parserData = typeDecl->GetParserData();
|
auto parserData = typeDecl->GetParserData();
|
||||||
name = "Anon_";
|
name = "_Anon_";
|
||||||
|
|
||||||
auto parseFileData = parserData->mParseFileData;
|
auto parseFileData = parserData->mParseFileData;
|
||||||
int uniqueId = parseFileData->GetUniqueId(mCurUniqueIdx++);
|
int uniqueId = parseFileData->GetUniqueId(mCurUniqueIdx++);
|
||||||
|
@ -7190,7 +7190,7 @@ BfAstNode* BfReducer::ReadTypeMember(BfAstNode* node, bool declStarted, int dept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((token == BfToken_Struct) || (token == BfToken_Class) || (token == BfToken_Interface) || (token == BfToken_Enum))
|
if (BfTokenIsTypeDecl(token))
|
||||||
{
|
{
|
||||||
int endNodeIdx = -1;
|
int endNodeIdx = -1;
|
||||||
if (IsTypeReference(node, BfToken_None, -1, &endNodeIdx))
|
if (IsTypeReference(node, BfToken_None, -1, &endNodeIdx))
|
||||||
|
@ -9310,7 +9310,6 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
|
||||||
break;
|
break;
|
||||||
|
|
||||||
BfIdentifierNode* identifierNode = NULL;
|
BfIdentifierNode* identifierNode = NULL;
|
||||||
|
|
||||||
if (!isAnonymous)
|
if (!isAnonymous)
|
||||||
{
|
{
|
||||||
identifierNode = ExpectIdentifierAfter(tokenNode);
|
identifierNode = ExpectIdentifierAfter(tokenNode);
|
||||||
|
@ -9473,9 +9472,13 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
|
||||||
|
|
||||||
if (isSimpleEnum)
|
if (isSimpleEnum)
|
||||||
{
|
{
|
||||||
auto identifierNode = ExpectIdentifierAfter(tokenNode, "enum name");
|
BfIdentifierNode* identifierNode = NULL;
|
||||||
if (identifierNode == NULL)
|
if (!isAnonymous)
|
||||||
return NULL;
|
{
|
||||||
|
identifierNode = ExpectIdentifierAfter(tokenNode, "enum name");
|
||||||
|
if (identifierNode == NULL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// We put extra effort in here to continue after failure, since 'return NULL' failure
|
// We put extra effort in here to continue after failure, since 'return NULL' failure
|
||||||
// means we don't parse members inside type (messes up colorization and such)
|
// means we don't parse members inside type (messes up colorization and such)
|
||||||
|
@ -9487,7 +9490,8 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
|
||||||
typeDeclaration->mTypeNode = tokenNode;
|
typeDeclaration->mTypeNode = tokenNode;
|
||||||
typeDeclaration->mNameNode = identifierNode;
|
typeDeclaration->mNameNode = identifierNode;
|
||||||
ReplaceNode(tokenNode, typeDeclaration);
|
ReplaceNode(tokenNode, typeDeclaration);
|
||||||
MoveNode(identifierNode, typeDeclaration);
|
if (identifierNode != NULL)
|
||||||
|
MoveNode(identifierNode, typeDeclaration);
|
||||||
typeDeclaration->mDocumentation = FindDocumentation(typeDeclaration);
|
typeDeclaration->mDocumentation = FindDocumentation(typeDeclaration);
|
||||||
|
|
||||||
auto nextNode = mVisitorPos.GetNext();
|
auto nextNode = mVisitorPos.GetNext();
|
||||||
|
|
|
@ -14,6 +14,10 @@ class Anonymous
|
||||||
retVals.mB = 2;
|
retVals.mB = 2;
|
||||||
return retVals;
|
return retVals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum { Left, Right } GetDirection() => .Right;
|
||||||
|
|
||||||
|
public enum : int { A, B, C } Val => .C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct StructB
|
struct StructB
|
||||||
|
@ -37,6 +41,9 @@ class Anonymous
|
||||||
Test.Assert(val.mA == 0);
|
Test.Assert(val.mA == 0);
|
||||||
Test.Assert(val.mB == 0);
|
Test.Assert(val.mB == 0);
|
||||||
|
|
||||||
|
Test.Assert(sa.GetDirection() == .Right);
|
||||||
|
Test.Assert(sa.Val == .C);
|
||||||
|
|
||||||
StructB sb = default;
|
StructB sb = default;
|
||||||
sb.mX = 345;
|
sb.mX = 345;
|
||||||
Test.Assert(sb.mY == 345);
|
Test.Assert(sb.mY == 345);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue