ZoneCodeGenerator: Save whether a structure is anonymous and therefore a name has been generated or not.

This commit is contained in:
Jan 2019-11-14 14:54:36 +01:00
parent f777c049c6
commit b59ca3b261
5 changed files with 37 additions and 6 deletions

View File

@ -16,6 +16,8 @@ namespace ZoneCodeGenerator.Domain
public List<Variable> Members { get; }
public bool IsAnonymous { get; set; }
private bool finalized;
public void FinalizeDataType()
{
@ -30,6 +32,7 @@ namespace ZoneCodeGenerator.Domain
Members = new List<Variable>();
Pack = pack;
finalized = false;
IsAnonymous = false;
}
private void CalculateProperties()

View File

@ -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; }
@ -29,8 +32,18 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks
private DataTypeTypedef typedef;
public BlockStruct(IHeaderParserState headerParserState, string name, bool isTypedef) : base(headerParserState, BlockType.Struct)
{
if (!string.IsNullOrEmpty(name))
{
Name = name;
IsAnonymous = false;
}
else
{
Name = RandomName.GenerateName();
IsAnonymous = true;
}
IsTypedef = isTypedef;
Variables = new List<Variable>();
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);

View File

@ -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; }
@ -29,8 +32,18 @@ namespace ZoneCodeGenerator.Parsing.C_Header.Blocks
private DataTypeTypedef typedef;
public BlockUnion(IHeaderParserState headerParserState, string name, bool isTypedef) : base(headerParserState, BlockType.Union)
{
if (!string.IsNullOrEmpty(name))
{
Name = name;
IsAnonymous = false;
}
else
{
Name = RandomName.GenerateName();
IsAnonymous = true;
}
IsTypedef = isTypedef;
Variables = new List<Variable>();
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);

View File

@ -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);

View File

@ -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);