mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-09 22:38:06 -05:00
ZoneCodeGenerator: Add computations for single references to be able to correctly handle arrays
This commit is contained in:
@ -10,40 +10,59 @@ namespace ZoneCodeGenerator.Generating.Computations
|
||||
{
|
||||
private readonly MemberInformation information;
|
||||
|
||||
public bool ShouldIgnore => information.Condition != null
|
||||
&& information.Condition.IsStatic
|
||||
public bool ShouldIgnore => information.Condition != null
|
||||
&& information.Condition.IsStatic
|
||||
&& information.Condition.EvaluateNumeric() == 0;
|
||||
|
||||
public bool IsEmbeddedReference => !information.Member.VariableType.References.OfType<ReferenceTypePointer>().Any();
|
||||
public bool ContainsNonEmbeddedReference =>
|
||||
information.Member.VariableType.References.OfType<ReferenceTypePointer>().Any();
|
||||
|
||||
public bool IsNonEmbeddedReference => !IsEmbeddedReference;
|
||||
public bool ContainsSinglePointerReference => information.Member.VariableType.References.Any()
|
||||
&& information.Member.VariableType.References.Last() is
|
||||
ReferenceTypePointer pointerReference
|
||||
&& !pointerReference.IsArray;
|
||||
|
||||
public bool IsSinglePointerReference => information.Member.VariableType.References.Any()
|
||||
&& information.Member.VariableType.References.Last() is ReferenceTypePointer
|
||||
pointerReference
|
||||
&& !pointerReference.IsArray;
|
||||
public bool ContainsArrayPointerReference => information.Member.VariableType.References.Any()
|
||||
&& information.Member.VariableType.References.Last() is
|
||||
ReferenceTypePointer pointerReference
|
||||
&& pointerReference.IsArray;
|
||||
|
||||
public bool ContainsPointerArrayReference => ContainsSinglePointerReference
|
||||
&& (IsArray && PointerDepthIsOne || !IsArray && PointerDepthIsTwo);
|
||||
|
||||
public bool ContainsArrayReference => information.Member.VariableType.References.Any()
|
||||
&& information.Member.VariableType.References
|
||||
.Last() is ReferenceTypeArray;
|
||||
|
||||
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 bool IsArray => information.Member.VariableType.References
|
||||
.OfType<ReferenceTypeArray>()
|
||||
.TakeWhile(type => type is ReferenceTypeArray)
|
||||
.Any();
|
||||
|
||||
public IEnumerable<int> ArraySizes => information.Member.VariableType.References
|
||||
.TakeWhile(type => type is ReferenceTypeArray)
|
||||
.OfType<ReferenceTypeArray>()
|
||||
.Select(array => array.ArraySize);
|
||||
|
||||
public int ArrayDimension => information.Member.VariableType.References
|
||||
.TakeWhile(type => type is ReferenceTypeArray)
|
||||
.Count();
|
||||
|
||||
public bool IsPointerToArray => information.Member.VariableType.References.OfType<ReferenceTypePointer>().Any()
|
||||
&& information.Member.VariableType.References.Last() is ReferenceTypeArray;
|
||||
|
||||
public IEnumerable<int> PointerToArraySizes => information.Member.VariableType.References
|
||||
.Reverse()
|
||||
.TakeWhile(type => type is ReferenceTypeArray)
|
||||
.OfType<ReferenceTypeArray>()
|
||||
.Reverse()
|
||||
.Select(array => array.ArraySize);
|
||||
|
||||
public int PointerDepth => information.Member.VariableType.References
|
||||
.OfType<ReferenceTypePointer>()
|
||||
.Count();
|
||||
@ -51,6 +70,8 @@ namespace ZoneCodeGenerator.Generating.Computations
|
||||
public bool PointerDepthIsOne => PointerDepth == 1;
|
||||
public bool PointerDepthIsTwo => PointerDepth == 2;
|
||||
|
||||
public MemberReferenceComputations References => new MemberReferenceComputations(information);
|
||||
|
||||
public MemberComputations(MemberInformation information)
|
||||
{
|
||||
this.information = information;
|
||||
|
@ -0,0 +1,67 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ZoneCodeGenerator.Domain;
|
||||
using ZoneCodeGenerator.Domain.Evaluation;
|
||||
using ZoneCodeGenerator.Domain.Information;
|
||||
|
||||
namespace ZoneCodeGenerator.Generating.Computations
|
||||
{
|
||||
class MemberReferenceComputations
|
||||
{
|
||||
private readonly MemberInformation information;
|
||||
private readonly List<int> referenceIndices;
|
||||
|
||||
public ReferenceType Reference => referenceIndices.Count < information.Member.VariableType.References.Count
|
||||
? information.Member.VariableType.References[referenceIndices.Count]
|
||||
: null;
|
||||
|
||||
public ReferenceType NextReference =>
|
||||
referenceIndices.Count + 1 < information.Member.VariableType.References.Count
|
||||
? information.Member.VariableType.References[referenceIndices.Count + 1]
|
||||
: null;
|
||||
|
||||
public IEnumerable<ReferenceType> FollowingReferences =>
|
||||
information.Member.VariableType.References.Skip(referenceIndices.Count + 1);
|
||||
|
||||
public IEnumerable<int> ArrayIndices => referenceIndices;
|
||||
|
||||
public bool IsArray => Reference is ReferenceTypeArray;
|
||||
public int ArraySize => Reference is ReferenceTypeArray array ? array.ArraySize : 0;
|
||||
|
||||
public IEnumerable<MemberReferenceComputations> ArrayEntries => Enumerable.Range(0, ArraySize)
|
||||
.Select(i => new MemberReferenceComputations(information, referenceIndices.Concat(new[] {i})));
|
||||
|
||||
public bool IsSinglePointer => Reference is ReferenceTypePointer referenceTypePointer
|
||||
&& !referenceTypePointer.IsArray
|
||||
&& !FollowingReferences.OfType<ReferenceTypePointer>().Any();
|
||||
|
||||
public bool IsArrayPointer => Reference is ReferenceTypePointer referenceTypePointer
|
||||
&& referenceTypePointer.IsArray
|
||||
&& !FollowingReferences.OfType<ReferenceTypePointer>().Any();
|
||||
|
||||
public IEvaluation ArrayPointerCountEvaluation => Reference is ReferenceTypePointer referenceTypePointer
|
||||
? referenceTypePointer.Count
|
||||
: null;
|
||||
|
||||
public bool IsPointerArray =>
|
||||
(Reference is ReferenceTypePointer referenceTypePointer && referenceTypePointer.IsArray ||
|
||||
Reference is ReferenceTypeArray)
|
||||
&& NextReference is ReferenceTypePointer nextReferencePointer && !nextReferencePointer.IsArray;
|
||||
|
||||
public IEvaluation PointerArrayCountEvaluation => NextReference is ReferenceTypePointer referenceTypePointer
|
||||
? referenceTypePointer.Count
|
||||
: null;
|
||||
|
||||
public MemberReferenceComputations(MemberInformation information)
|
||||
{
|
||||
this.information = information;
|
||||
referenceIndices = new List<int>();
|
||||
}
|
||||
|
||||
private MemberReferenceComputations(MemberInformation information, IEnumerable<int> referenceIndices)
|
||||
{
|
||||
this.information = information;
|
||||
this.referenceIndices = new List<int>(referenceIndices);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user