mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
ZoneCodeGenerator: Move computed conditions to sub class for MemberInformation since the template engine does not support computations and there will be a decent amount probably. So they are now moved to a different class to not cludder the main class too much
This commit is contained in:
parent
60565da607
commit
63722e220d
@ -1,5 +1,7 @@
|
|||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using ZoneCodeGenerator.Domain.Evaluation;
|
using ZoneCodeGenerator.Domain.Evaluation;
|
||||||
|
using ZoneCodeGenerator.Generating.Computations;
|
||||||
|
|
||||||
namespace ZoneCodeGenerator.Domain.Information
|
namespace ZoneCodeGenerator.Domain.Information
|
||||||
{
|
{
|
||||||
@ -11,20 +13,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
public bool IsScriptString { get; set; }
|
public bool IsScriptString { get; set; }
|
||||||
public IEvaluation Condition { get; set; }
|
public IEvaluation Condition { get; set; }
|
||||||
|
|
||||||
public bool IsNonEmbeddedReference => Member.VariableType.References.Any();
|
public MemberComputations Computations => new MemberComputations(this);
|
||||||
|
|
||||||
public bool IsSinglePointerReference => Member.VariableType.References.Any()
|
|
||||||
&& Member.VariableType.References.Last() is ReferenceTypePointer
|
|
||||||
pointerReference
|
|
||||||
&& !pointerReference.IsArray;
|
|
||||||
|
|
||||||
public bool IsArrayPointerReference => Member.VariableType.References.Any()
|
|
||||||
&& Member.VariableType.References.Last() is ReferenceTypePointer
|
|
||||||
pointerReference
|
|
||||||
&& pointerReference.IsArray;
|
|
||||||
|
|
||||||
public bool IsArrayReference => Member.VariableType.References.Any()
|
|
||||||
&& Member.VariableType.References.Last() is ReferenceTypeArray;
|
|
||||||
|
|
||||||
public MemberInformation(Variable member, StructureInformation structureType)
|
public MemberInformation(Variable member, StructureInformation structureType)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using ZoneCodeGenerator.Domain;
|
||||||
|
using ZoneCodeGenerator.Domain.Evaluation;
|
||||||
|
using ZoneCodeGenerator.Domain.Information;
|
||||||
|
|
||||||
|
namespace ZoneCodeGenerator.Generating.Computations
|
||||||
|
{
|
||||||
|
class MemberComputations
|
||||||
|
{
|
||||||
|
private readonly MemberInformation information;
|
||||||
|
|
||||||
|
public bool IsNonEmbeddedReference => information.Member.VariableType.References.OfType<ReferenceTypePointer>().Any();
|
||||||
|
|
||||||
|
public bool IsSinglePointerReference => information.Member.VariableType.References.Any()
|
||||||
|
&& information.Member.VariableType.References.Last() is ReferenceTypePointer
|
||||||
|
pointerReference
|
||||||
|
&& !pointerReference.IsArray;
|
||||||
|
|
||||||
|
public bool IsArrayPointerReference => information.Member.VariableType.References.Any()
|
||||||
|
&& information.Member.VariableType.References.Last() is ReferenceTypePointer
|
||||||
|
pointerReference
|
||||||
|
&& pointerReference.IsArray;
|
||||||
|
|
||||||
|
public IEvaluation ArrayPointerCountEvaluation =>
|
||||||
|
information.Member.VariableType.References.Last() is ReferenceTypePointer pointerReference
|
||||||
|
? pointerReference.Count
|
||||||
|
: null;
|
||||||
|
|
||||||
|
public bool IsArrayReference => information.Member.VariableType.References.Any()
|
||||||
|
&& information.Member.VariableType.References.Last() is ReferenceTypeArray;
|
||||||
|
|
||||||
|
public IEnumerable<int> ArraySizes => information.Member.VariableType.References
|
||||||
|
.OfType<ReferenceTypeArray>()
|
||||||
|
.Select(array => array.ArraySize);
|
||||||
|
|
||||||
|
public int PointerDepth => information.Member.VariableType.References
|
||||||
|
.OfType<ReferenceTypePointer>()
|
||||||
|
.Count();
|
||||||
|
|
||||||
|
public bool IsSinglePointer => PointerDepth == 1;
|
||||||
|
public bool IsDoublePointer => PointerDepth == 2;
|
||||||
|
|
||||||
|
public MemberComputations(MemberInformation information)
|
||||||
|
{
|
||||||
|
this.information = information;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,16 +20,16 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
|
|||||||
|
|
||||||
memberInformation.StructureType.Usages.Add(information);
|
memberInformation.StructureType.Usages.Add(information);
|
||||||
|
|
||||||
if (memberInformation.IsNonEmbeddedReference)
|
if (memberInformation.Computations.IsNonEmbeddedReference)
|
||||||
memberInformation.StructureType.NonEmbeddedReferenceExists = true;
|
memberInformation.StructureType.NonEmbeddedReferenceExists = true;
|
||||||
|
|
||||||
if (memberInformation.IsSinglePointerReference)
|
if (memberInformation.Computations.IsSinglePointerReference)
|
||||||
memberInformation.StructureType.SinglePointerReferenceExists = true;
|
memberInformation.StructureType.SinglePointerReferenceExists = true;
|
||||||
|
|
||||||
if (memberInformation.IsArrayPointerReference)
|
if (memberInformation.Computations.IsArrayPointerReference)
|
||||||
memberInformation.StructureType.ArrayPointerReferenceExists = true;
|
memberInformation.StructureType.ArrayPointerReferenceExists = true;
|
||||||
|
|
||||||
if (memberInformation.IsArrayReference)
|
if (memberInformation.Computations.IsArrayReference)
|
||||||
memberInformation.StructureType.ArrayReferenceExists = true;
|
memberInformation.StructureType.ArrayReferenceExists = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
|||||||
throw new TestFailedException($"Specified member '{lastMember.Member.Name}' is not char type and therefore cannot be a string.");
|
throw new TestFailedException($"Specified member '{lastMember.Member.Name}' is not char type and therefore cannot be a string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lastMember.IsSinglePointerReference)
|
if (!lastMember.Computations.IsSinglePointerReference)
|
||||||
{
|
{
|
||||||
throw new TestFailedException($"Specified member '{lastMember.Member.Name}' is a single pointer reference and therefore cannot be a string.");
|
throw new TestFailedException($"Specified member '{lastMember.Member.Name}' is a single pointer reference and therefore cannot be a string.");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user