diff --git a/src/ZoneCodeGenerator/Domain/DataTypeWithMembers.cs b/src/ZoneCodeGenerator/Domain/DataTypeWithMembers.cs index bd3df7fc..effde128 100644 --- a/src/ZoneCodeGenerator/Domain/DataTypeWithMembers.cs +++ b/src/ZoneCodeGenerator/Domain/DataTypeWithMembers.cs @@ -16,6 +16,8 @@ namespace ZoneCodeGenerator.Domain public List Members { get; } + public bool IsAnonymous { get; set; } + private bool finalized; public void FinalizeDataType() { @@ -30,6 +32,7 @@ namespace ZoneCodeGenerator.Domain Members = new List(); Pack = pack; finalized = false; + IsAnonymous = false; } private void CalculateProperties() diff --git a/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockStruct.cs b/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockStruct.cs index 3ae4f2ff..112a61db 100644 --- a/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockStruct.cs +++ b/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockStruct.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Parsing.C_Header.Tests; using ZoneCodeGenerator.Parsing.Testing; +using ZoneCodeGenerator.Utils; namespace ZoneCodeGenerator.Parsing.C_Header.Blocks { @@ -18,6 +19,8 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks }; public string Name { get; } + public bool IsAnonymous { get; } + public string AssignedName { get; private set; } public string Namespace { get; private set; } public bool IsTypedef { get; } @@ -30,7 +33,17 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks public BlockStruct(IHeaderParserState headerParserState, string name, bool isTypedef) : base(headerParserState, BlockType.Struct) { - Name = name; + if (!string.IsNullOrEmpty(name)) + { + Name = name; + IsAnonymous = false; + } + else + { + Name = RandomName.GenerateName(); + IsAnonymous = true; + } + IsTypedef = isTypedef; Variables = new List(); AssignedName = ""; @@ -63,7 +76,8 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks _struct = new DataTypeStruct(Namespace, Name, Pack) { - AlignmentOverride = CustomAlignment + AlignmentOverride = CustomAlignment, + IsAnonymous = IsAnonymous }; _struct.Members.AddRange(Variables); diff --git a/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockUnion.cs b/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockUnion.cs index c39e1ff9..1b60ff10 100644 --- a/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockUnion.cs +++ b/src/ZoneCodeGenerator/Parsing/C_Header/Blocks/BlockUnion.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using ZoneCodeGenerator.Domain; using ZoneCodeGenerator.Parsing.C_Header.Tests; using ZoneCodeGenerator.Parsing.Testing; +using ZoneCodeGenerator.Utils; namespace ZoneCodeGenerator.Parsing.C_Header.Blocks { @@ -18,6 +19,8 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks }; public string Name { get; } + public bool IsAnonymous { get; } + public string AssignedName { get; private set; } public string Namespace { get; private set; } public bool IsTypedef { get; } @@ -30,7 +33,17 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks public BlockUnion(IHeaderParserState headerParserState, string name, bool isTypedef) : base(headerParserState, BlockType.Union) { - Name = name; + if (!string.IsNullOrEmpty(name)) + { + Name = name; + IsAnonymous = false; + } + else + { + Name = RandomName.GenerateName(); + IsAnonymous = true; + } + IsTypedef = isTypedef; Variables = new List(); CustomAlignment = null; @@ -63,7 +76,8 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks union = new DataTypeUnion(Namespace, Name, Pack) { - AlignmentOverride = CustomAlignment + AlignmentOverride = CustomAlignment, + IsAnonymous = IsAnonymous }; union.Members.AddRange(Variables); diff --git a/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestStruct.cs b/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestStruct.cs index 0ed4b12f..98834338 100644 --- a/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestStruct.cs +++ b/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestStruct.cs @@ -43,7 +43,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Tests protected override void ProcessMatch(IHeaderParserState state) { var isTypedef = HasMatcherTokens(TypedefToken); - var name = NextMatch(NameToken) ?? RandomName.GenerateName(); + var name = NextMatch(NameToken) ?? ""; var block = new BlockStruct(state, name, isTypedef); diff --git a/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestUnion.cs b/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestUnion.cs index 4ef679a3..5e698aff 100644 --- a/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestUnion.cs +++ b/src/ZoneCodeGenerator/Parsing/C_Header/Tests/TestUnion.cs @@ -43,7 +43,7 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Tests protected override void ProcessMatch(IHeaderParserState state) { var isTypedef = HasMatcherTokens(TypedefToken); - var name = NextMatch(NameToken) ?? RandomName.GenerateName(); + var name = NextMatch(NameToken) ?? ""; var block = new BlockUnion(state, name, isTypedef);