ZoneCodeGenerator: Add all used membertypes to a list in context

This commit is contained in:
Jan 2019-11-14 14:58:50 +01:00
parent d7f05b97c9
commit 8c303d394d
2 changed files with 16 additions and 19 deletions

View File

@ -7,21 +7,8 @@ namespace ZoneCodeGenerator.Domain
{
private const int PointerSize = 4;
private DataType type;
public DataType Type
{
get
{
if (type is DataTypeTypedef typedef)
{
return typedef.TypeDefinition.Type;
}
public DataType Type { get; set; }
return type;
}
set => type = value;
}
public int? CustomBitSize { get; set; }
@ -32,7 +19,7 @@ namespace ZoneCodeGenerator.Domain
private readonly List<ReferenceType> references;
public IReadOnlyList<ReferenceType> References => references.AsReadOnly();
public int Alignment => references.OfType<ReferenceTypePointer>().Any() ? PointerSize : type.Alignment;
public int Alignment => references.OfType<ReferenceTypePointer>().Any() ? PointerSize : Type.Alignment;
public int Size
{
@ -59,7 +46,7 @@ namespace ZoneCodeGenerator.Domain
public TypeDeclaration(DataType type, List<ReferenceType> references)
{
this.type = type;
Type = type;
this.references = references ?? new List<ReferenceType>();
CustomBitSize = null;
}

View File

@ -13,10 +13,13 @@ namespace ZoneCodeGenerator.Generating
{
public string Game { get; set; }
public StructureInformation Asset { get; set; }
public HashSet<StructureInformation> Structures { get; }
public ISet<StructureInformation> Structures { get; }
public ISet<DataType> MemberTypes { get; }
public IEnumerable<StructureInformation> ReferencedAssets => Structures.Where(inf => inf.IsAsset && inf != Asset);
public List<FastFileBlock> Blocks { get; private set; }
public IList<FastFileBlock> Blocks { get; private set; }
public FastFileBlock DefaultNormalBlock => Blocks.FirstOrDefault(block => block.IsDefault && block.IsNormal) ??
Blocks.FirstOrDefault(block => block.IsNormal);
@ -24,6 +27,7 @@ namespace ZoneCodeGenerator.Generating
private RenderingContext()
{
Structures = new HashSet<StructureInformation>();
MemberTypes = new HashSet<DataType>();
}
private void AddToContext(StructureInformation structureInformation)
@ -51,6 +55,12 @@ namespace ZoneCodeGenerator.Generating
};
context.AddToContext(asset);
context.MemberTypes.UnionWith(context.Structures.Where(information => !information.IsAsset || information == asset)
.SelectMany(information => information.OrderedMembers)
.Select(information => information.Member.VariableType.Type)
.Where(type => !(type is DataTypeBaseType) && type != asset.Type)
.Distinct());
return context;
}