ZoneCodeGenerator: Make pointer counts be able to differ by array index

This commit is contained in:
Jan
2019-12-18 15:30:47 +01:00
parent a7936c9eaa
commit be17ae6a48
6 changed files with 123 additions and 22 deletions

View File

@ -20,12 +20,12 @@ namespace ZoneCodeGenerator.Generating.Computations
public bool ContainsSinglePointerReference => information.Member.VariableType.References.Any()
&& information.Member.VariableType.References.Last() is
ReferenceTypePointer pointerReference
&& !pointerReference.IsArray;
&& !pointerReference.AnyIsArray;
public bool ContainsArrayPointerReference => information.Member.VariableType.References.Any()
&& information.Member.VariableType.References.Last() is
ReferenceTypePointer pointerReference
&& pointerReference.IsArray;
&& pointerReference.AnyIsArray;
public bool ContainsPointerArrayReference => ContainsSinglePointerReference
&& (IsArray && PointerDepthIsOne || !IsArray && PointerDepthIsTwo);
@ -73,11 +73,16 @@ namespace ZoneCodeGenerator.Generating.Computations
public bool IsNotDefaultNormalBlock =>
information.Block != null && !(information.Block.IsNormal && information.Block.IsDefault);
public bool IsTempBlock => information.Block != null && information.Block.IsTemp;
public bool IsRuntimeBlock => information.Block != null && information.Block.IsRuntime;
public bool IsFirstMember =>
information.Parent.OrderedMembers.FirstOrDefault(member => !member.IsLeaf && !member.Computations.ShouldIgnore) == information;
information.Parent.OrderedMembers.FirstOrDefault(member =>
!member.IsLeaf && !member.Computations.ShouldIgnore) == information;
public bool IsLastMember =>
information.Parent.OrderedMembers.LastOrDefault(member => !member.IsLeaf && !member.Computations.ShouldIgnore) == information;
information.Parent.OrderedMembers.LastOrDefault(member =>
!member.IsLeaf && !member.Computations.ShouldIgnore) == information;
public MemberReferenceComputations References => new MemberReferenceComputations(information);

View File

@ -10,6 +10,7 @@ namespace ZoneCodeGenerator.Generating.Computations
{
private readonly MemberInformation information;
private readonly List<int> referenceIndices;
private readonly int combinedIndex;
public ReferenceType Reference => referenceIndices.Count < information.Member.VariableType.References.Count
? information.Member.VariableType.References[referenceIndices.Count]
@ -32,21 +33,29 @@ namespace ZoneCodeGenerator.Generating.Computations
.Select(i => new MemberReferenceComputations(information, referenceIndices.Concat(new[] {i})));
public bool IsSinglePointer => Reference is ReferenceTypePointer referenceTypePointer
&& !referenceTypePointer.IsArray
&& !referenceTypePointer.IsArray(combinedIndex)
&& !FollowingReferences.OfType<ReferenceTypePointer>().Any();
public bool IsArrayPointer => Reference is ReferenceTypePointer referenceTypePointer
&& referenceTypePointer.IsArray
&& referenceTypePointer.IsArray(combinedIndex)
&& !FollowingReferences.OfType<ReferenceTypePointer>().Any();
public IEvaluation ArrayPointerCountEvaluation => Reference is ReferenceTypePointer referenceTypePointer
? referenceTypePointer.Count
: null;
public IEvaluation ArrayPointerCountEvaluation
{
get
{
if (!(Reference is ReferenceTypePointer pointer))
return null;
return pointer.HasCountByArrayIndex ? pointer.CountByArrayIndex[combinedIndex] : pointer.Count;
}
}
public bool IsPointerArray =>
(Reference is ReferenceTypePointer referenceTypePointer && referenceTypePointer.IsArray ||
(Reference is ReferenceTypePointer referenceTypePointer && referenceTypePointer.IsArray(combinedIndex) ||
Reference is ReferenceTypeArray)
&& NextReference is ReferenceTypePointer nextReferencePointer && !nextReferencePointer.IsArray;
&& NextReference is ReferenceTypePointer nextReferencePointer &&
!nextReferencePointer.IsArray(combinedIndex);
public IEvaluation PointerArrayCountEvaluation => NextReference is ReferenceTypePointer referenceTypePointer
? referenceTypePointer.Count
@ -56,12 +65,29 @@ namespace ZoneCodeGenerator.Generating.Computations
{
this.information = information;
referenceIndices = new List<int>();
combinedIndex = 0;
}
private MemberReferenceComputations(MemberInformation information, IEnumerable<int> referenceIndices)
{
this.information = information;
this.referenceIndices = new List<int>(referenceIndices);
var arraySizes = information.Member.VariableType.References
.OfType<ReferenceTypeArray>()
.Select(array => array.ArraySize)
.ToList();
var indexDepth = 0;
combinedIndex = 0;
foreach (var referenceIndex in this.referenceIndices)
{
var sizePerIndexInCurrentDepth = arraySizes.Count <= indexDepth + 1
? 1
: arraySizes.Skip(indexDepth + 1).Aggregate((i1, i2) => i1 * i2);
combinedIndex += referenceIndex * sizePerIndexInCurrentDepth;
indexDepth++;
}
}
}
}