mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 00:31:56 +00:00
ZoneCodeGenerator: Make pointer counts be able to differ by array index
This commit is contained in:
@ -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);
|
||||
|
||||
|
@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)
|
||||
// $member.Member.VariableType.Type.Alignment$
|
||||
$\n$
|
||||
|
||||
$if(member.StructureType && !member.StructureType.IsLeaf)$
|
||||
$if(member.StructureType && !member.StructureType.IsLeaf && !member.Computations.IsRuntimeBlock)$
|
||||
|
||||
$TypeVarName(member.Member.VariableType.Type)$ = $TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(reference)$;$\n$
|
||||
LoadArray_$member.Member.VariableType.Type.Name$(true, $PrintEvaluation(reference.ArrayPointerCountEvaluation)$);
|
||||
|
@ -73,8 +73,11 @@ namespace $context.Game$
|
||||
}
|
||||
>>
|
||||
|
||||
LoadMember(context, member) ::= <<
|
||||
Loading member $member.Member.Name$
|
||||
LoadMemberReference_Array(context, structure, member, reference) ::= <<
|
||||
$first(reference.ArrayEntries):{entry | $LoadMemberReference(context, structure, member, entry)$}$
|
||||
$rest(reference.ArrayEntries):{entry |
|
||||
|
||||
$LoadMemberReference(context, structure, member, entry)$}$
|
||||
>>
|
||||
|
||||
LoadMemberReference(context, structure, member, reference) ::= <%
|
||||
@ -88,8 +91,10 @@ $elseif(reference.IsArray && !reference.NextReference)$
|
||||
$LoadEmbeddedArray(context, structure, member, reference)$
|
||||
$elseif(!reference.Reference)$
|
||||
$LoadEmbedded(context, structure, member, reference)$
|
||||
$elseif(reference.IsArray)$
|
||||
$LoadMemberReference_Array(context, structure, member, reference)$
|
||||
$else$
|
||||
// $member.Member.Name$
|
||||
// LoadMemberReference failed @ $member.Member.Name$
|
||||
$endif$
|
||||
%>
|
||||
|
||||
|
Reference in New Issue
Block a user