2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-03 17:51:54 +00:00

ZoneCodeGenerator: Move usages postprocessor to be post commandfile instead of post headerfile

This commit is contained in:
Jan
2019-09-28 13:14:23 +02:00
parent 03a6c4020c
commit 3ba1f6d5f9
3 changed files with 4 additions and 7 deletions

View File

@ -14,6 +14,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
private static readonly IDataPostProcessor[] postProcessors =
{
new PostProcessorDefaultBlock(),
new PostProcessorUsages(),
};
public static bool ReadFile(string path, CUISession session, bool verbose = false)

View File

@ -0,0 +1,54 @@
using System.Linq;
using ZoneCodeGenerator.Domain;
using ZoneCodeGenerator.Persistence;
namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
{
class PostProcessorUsages : IDataPostProcessor
{
public bool PostProcess(IDataRepository repository)
{
foreach (var dataTypeWithMembers in repository.GetAllStructs()
.AsEnumerable<DataTypeWithMembers>()
.Concat(repository.GetAllUnions()))
{
var information = repository.GetInformationFor(dataTypeWithMembers);
foreach (var memberInformation in information.OrderedMembers)
{
if (memberInformation.StructureType == null) continue;
memberInformation.StructureType.Usages.Add(information);
if (IsNonEmbeddedReference(memberInformation.Member))
memberInformation.StructureType.NonEmbeddedReferenceExists = true;
if (IsPointerReference(memberInformation.Member))
memberInformation.StructureType.PointerReferenceExists = true;
if (IsArrayReference(memberInformation.Member))
memberInformation.StructureType.PointerReferenceExists = true;
}
}
return true;
}
private static bool IsNonEmbeddedReference(Variable var)
{
return var.VariableType.References.Any();
}
private static bool IsPointerReference(Variable var)
{
return var.VariableType.References.Any()
&& var.VariableType.References.Last() is ReferenceTypePointer;
}
private static bool IsArrayReference(Variable var)
{
return var.VariableType.References.Any()
&& var.VariableType.References.Last() is ReferenceTypeArray;
}
}
}