mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
ZoneCodeGenerator: Make members have a block they are being loaded into instead of structures
This commit is contained in:
parent
8a99a49486
commit
f4a2639e30
@ -13,6 +13,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
public bool IsScriptString { get; set; }
|
public bool IsScriptString { get; set; }
|
||||||
public bool IsReusable { get; set; }
|
public bool IsReusable { get; set; }
|
||||||
public IEvaluation Condition { get; set; }
|
public IEvaluation Condition { get; set; }
|
||||||
|
public FastFileBlock Block { get; set; }
|
||||||
|
|
||||||
public MemberComputations Computations => new MemberComputations(this);
|
public MemberComputations Computations => new MemberComputations(this);
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
IsScriptString = false;
|
IsScriptString = false;
|
||||||
IsReusable = false;
|
IsReusable = false;
|
||||||
Condition = null;
|
Condition = null;
|
||||||
|
Block = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
@ -11,7 +11,6 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
{
|
{
|
||||||
public DataTypeWithMembers Type { get; }
|
public DataTypeWithMembers Type { get; }
|
||||||
public bool IsUnion => Type is DataTypeUnion;
|
public bool IsUnion => Type is DataTypeUnion;
|
||||||
public FastFileBlock Block { get; set; }
|
|
||||||
|
|
||||||
public EnumMember AssetEnumEntry { get; set; }
|
public EnumMember AssetEnumEntry { get; set; }
|
||||||
public bool IsAsset => AssetEnumEntry != null;
|
public bool IsAsset => AssetEnumEntry != null;
|
||||||
@ -30,6 +29,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
public bool SinglePointerReferenceExists { get; set; }
|
public bool SinglePointerReferenceExists { get; set; }
|
||||||
public bool ArrayPointerReferenceExists { get; set; }
|
public bool ArrayPointerReferenceExists { get; set; }
|
||||||
public bool ArrayReferenceExists { get; set; }
|
public bool ArrayReferenceExists { get; set; }
|
||||||
|
public bool ReferenceFromNonDefaultNormalBlockExists { get; set; }
|
||||||
|
|
||||||
public bool IsLeaf { get; set; }
|
public bool IsLeaf { get; set; }
|
||||||
|
|
||||||
@ -44,6 +44,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
|||||||
NonEmbeddedReferenceExists = false;
|
NonEmbeddedReferenceExists = false;
|
||||||
SinglePointerReferenceExists = false;
|
SinglePointerReferenceExists = false;
|
||||||
ArrayReferenceExists = false;
|
ArrayReferenceExists = false;
|
||||||
|
ReferenceFromNonDefaultNormalBlockExists = false;
|
||||||
Usages = new List<StructureInformation>();
|
Usages = new List<StructureInformation>();
|
||||||
OrderedMembers = new List<MemberInformation>();
|
OrderedMembers = new List<MemberInformation>();
|
||||||
IsLeaf = true;
|
IsLeaf = true;
|
||||||
|
@ -70,6 +70,9 @@ namespace ZoneCodeGenerator.Generating.Computations
|
|||||||
public bool PointerDepthIsOne => PointerDepth == 1;
|
public bool PointerDepthIsOne => PointerDepth == 1;
|
||||||
public bool PointerDepthIsTwo => PointerDepth == 2;
|
public bool PointerDepthIsTwo => PointerDepth == 2;
|
||||||
|
|
||||||
|
public bool IsNotDefaultNormalBlock =>
|
||||||
|
information.Block != null && !(information.Block.IsNormal && information.Block.IsDefault);
|
||||||
|
|
||||||
public MemberReferenceComputations References => new MemberReferenceComputations(information);
|
public MemberReferenceComputations References => new MemberReferenceComputations(information);
|
||||||
|
|
||||||
public MemberComputations(MemberInformation information)
|
public MemberComputations(MemberInformation information)
|
||||||
|
@ -50,6 +50,9 @@ namespace ZoneCodeGenerator.Generating
|
|||||||
public FastFileBlock DefaultNormalBlock => Blocks.FirstOrDefault(block => block.IsDefault && block.IsNormal) ??
|
public FastFileBlock DefaultNormalBlock => Blocks.FirstOrDefault(block => block.IsDefault && block.IsNormal) ??
|
||||||
Blocks.FirstOrDefault(block => block.IsNormal);
|
Blocks.FirstOrDefault(block => block.IsNormal);
|
||||||
|
|
||||||
|
public FastFileBlock DefaultTempBlock => Blocks.FirstOrDefault(block => block.IsDefault && block.IsTemp) ??
|
||||||
|
Blocks.FirstOrDefault(block => block.IsTemp);
|
||||||
|
|
||||||
private RenderingContext()
|
private RenderingContext()
|
||||||
{
|
{
|
||||||
usedTypes = new Dictionary<DataType, UsedType>();
|
usedTypes = new Dictionary<DataType, UsedType>();
|
||||||
|
@ -55,9 +55,43 @@ if ($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(refere
|
|||||||
}
|
}
|
||||||
>>
|
>>
|
||||||
|
|
||||||
LoadArrayPointer_Condition(context, structure, member, reference) ::= <<
|
LoadArrayPointer_Block(context, structure, member, reference) ::= <%
|
||||||
$if(member.Condition)$$\\$
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
if($PrintEvaluation(member.Condition)$)
|
m_stream->PushBlock($member.Block.Name$);$\n$
|
||||||
|
$endif$
|
||||||
|
|
||||||
|
$LoadArrayPointer_PointerCheck(context, structure, member, reference)$
|
||||||
|
|
||||||
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
|
$\n$m_stream->PopBlock();
|
||||||
|
$endif$
|
||||||
|
%>
|
||||||
|
|
||||||
|
LoadArrayPointer(context, structure, member, reference) ::= <%
|
||||||
|
$LoadArrayPointer_Block(context, structure, member, reference)$
|
||||||
|
%>
|
||||||
|
|
||||||
|
LoadPointerArrayMethod_Loading(context, type, structure) ::= <%
|
||||||
|
*$TypePtrVarName(type)$ = m_stream->Alloc<$type.FullName$>(alignof($type.FullName$));
|
||||||
|
// $type.Alignment$
|
||||||
|
$\n$
|
||||||
|
|
||||||
|
$if(structure && !structure.IsLeaf)$
|
||||||
|
|
||||||
|
$TypeVarName(structure.Type)$ = *$TypePtrVarName(type)$;$\n$
|
||||||
|
Load_$type.Name$(true);
|
||||||
|
|
||||||
|
$else$
|
||||||
|
|
||||||
|
m_stream->Load<$type.FullName$>(*$TypePtrVarName(type)$);
|
||||||
|
|
||||||
|
$endif$
|
||||||
|
%>
|
||||||
|
|
||||||
|
LoadPointerArrayMethod_Asset(context, type, structure) ::= <<
|
||||||
|
$LoaderClassName(structure)$ loader(m_script_string_provider, m_zone, m_stream);
|
||||||
|
loader.Load($TypePtrVarName(type)$);
|
||||||
|
>>
|
||||||
|
|
||||||
LoadPointerArrayMethod_PointerCheck(context, type, structure, reusable) ::= <<
|
LoadPointerArrayMethod_PointerCheck(context, type, structure, reusable) ::= <<
|
||||||
if (*$TypePtrVarName(type)$)
|
if (*$TypePtrVarName(type)$)
|
||||||
|
@ -15,22 +15,20 @@ $LoadEmbedded_Load(context, structure, member, reference)$
|
|||||||
$endif$
|
$endif$
|
||||||
%>
|
%>
|
||||||
|
|
||||||
LoadEmbedded_Condition(context, structure, member, reference) ::= <<
|
LoadEmbedded_Block(context, structure, member, reference) ::= <%
|
||||||
$if(member.Condition)$
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
if($PrintEvaluation(member.Condition)$)
|
m_stream->PushBlock($member.Block.Name$);$\n$
|
||||||
{
|
|
||||||
$LoadEmbedded_TypeCheck(context, structure, member, reference)$
|
|
||||||
$if(structure.IsUnion)$
|
|
||||||
return;
|
|
||||||
$endif$
|
|
||||||
}
|
|
||||||
$else$$\\$
|
|
||||||
$LoadEmbedded_TypeCheck(context, structure, member, reference)$$\\$
|
|
||||||
$endif$
|
$endif$
|
||||||
>>
|
|
||||||
|
$LoadEmbedded_TypeCheck(context, structure, member, reference)$
|
||||||
|
|
||||||
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
|
$\n$m_stream->PopBlock();
|
||||||
|
$endif$
|
||||||
|
%>
|
||||||
|
|
||||||
LoadEmbedded(context, structure, member, reference) ::= <%
|
LoadEmbedded(context, structure, member, reference) ::= <%
|
||||||
$LoadEmbedded_Condition(context, structure, member, reference)$
|
$LoadEmbedded_Block(context, structure, member, reference)$
|
||||||
%>
|
%>
|
||||||
|
|
||||||
LoadEmbeddedArray_TypeCheck(context, structure, member, reference) ::= <%
|
LoadEmbeddedArray_TypeCheck(context, structure, member, reference) ::= <%
|
||||||
|
@ -31,17 +31,18 @@ $LoadPointerArray_Loading(context, structure, member, reference)$
|
|||||||
$endif$
|
$endif$
|
||||||
%>
|
%>
|
||||||
|
|
||||||
LoadPointerArray_Condition(context, structure, member, reference) ::= <<
|
LoadPointerArray_Block(context, structure, member, reference) ::= <%
|
||||||
$if(member.Condition)$$\\$
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
if($PrintEvaluation(member.Condition)$)
|
m_stream->PushBlock($member.Block.Name$);$\n$
|
||||||
{
|
|
||||||
$LoadPointerArray_TypeCheck(context, structure, member, reference)$
|
|
||||||
}
|
|
||||||
$else$$\\$
|
|
||||||
$LoadPointerArray_TypeCheck(context, structure, member, reference)$$\\$
|
|
||||||
$endif$
|
$endif$
|
||||||
>>
|
|
||||||
|
$LoadPointerArray_TypeCheck(context, structure, member, reference)$
|
||||||
|
|
||||||
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
|
$\n$m_stream->PopBlock();
|
||||||
|
$endif$
|
||||||
|
%>
|
||||||
|
|
||||||
LoadPointerArray(context, structure, member, reference) ::= <%
|
LoadPointerArray(context, structure, member, reference) ::= <%
|
||||||
$LoadPointerArray_Condition(context, structure, member, reference)$
|
$LoadPointerArray_Block(context, structure, member, reference)$
|
||||||
%>
|
%>
|
@ -65,20 +65,18 @@ $LoadSinglePointer_PointerCheck(context, structure, member, reference)$
|
|||||||
$endif$
|
$endif$
|
||||||
%>
|
%>
|
||||||
|
|
||||||
LoadSinglePointer_Condition(context, structure, member, reference) ::= <<
|
LoadSinglePointer_Block(context, structure, member, reference) ::= <%
|
||||||
$if(member.Condition)$
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
if($PrintEvaluation(member.Condition)$)
|
m_stream->PushBlock($member.Block.Name$);$\n$
|
||||||
{
|
|
||||||
$LoadSinglePointer_TypeCheck(context, structure, member, reference)$
|
|
||||||
}
|
|
||||||
$if(structure.IsUnion)$
|
|
||||||
return;
|
|
||||||
$endif$
|
$endif$
|
||||||
$else$$\\$
|
|
||||||
$LoadSinglePointer_TypeCheck(context, structure, member, reference)$$\\$
|
$LoadSinglePointer_TypeCheck(context, structure, member, reference)$
|
||||||
|
|
||||||
|
$if(member.Computations.IsNotDefaultNormalBlock)$
|
||||||
|
$\n$m_stream->PopBlock();
|
||||||
$endif$
|
$endif$
|
||||||
>>
|
%>
|
||||||
|
|
||||||
LoadSinglePointer(context, structure, member, reference) ::= <%
|
LoadSinglePointer(context, structure, member, reference) ::= <%
|
||||||
$LoadSinglePointer_Condition(context, structure, member, reference)$
|
$LoadSinglePointer_Block(context, structure, member, reference)$
|
||||||
%>
|
%>
|
@ -13,7 +13,7 @@ LoaderClassName(asset) ::= "Loader_$asset.Type.Name$"
|
|||||||
|
|
||||||
HeaderConstructor(context) ::= "$LoaderClassName(context.Asset)$(IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream);"
|
HeaderConstructor(context) ::= "$LoaderClassName(context.Asset)$(IZoneScriptStringProvider* scriptStringProvider, Zone* zone, IZoneInputStream* stream);"
|
||||||
|
|
||||||
HeaderSinglePtrLoadMethodDeclaration(structure) ::= "void LoadPtr_$structure.Type.Name$(bool atStreamStart);"
|
HeaderTempPtrLoadMethodDeclaration(structure) ::= "void LoadPtr_$structure.Type.Name$(bool atStreamStart);"
|
||||||
HeaderArrayLoadMethodDeclaration(type) ::= "void LoadArray_$SafeTypeName(type)$(bool atStreamStart, size_t count);"
|
HeaderArrayLoadMethodDeclaration(type) ::= "void LoadArray_$SafeTypeName(type)$(bool atStreamStart, size_t count);"
|
||||||
HeaderPtrArrayLoadMethodDeclaration(type) ::= "void LoadPtrArray_$SafeTypeName(type)$(bool atStreamStart, size_t count);"
|
HeaderPtrArrayLoadMethodDeclaration(type) ::= "void LoadPtrArray_$SafeTypeName(type)$(bool atStreamStart, size_t count);"
|
||||||
HeaderLoadMethodDeclaration(structure) ::= "void Load_$structure.Type.Name$(bool atStreamStart);"
|
HeaderLoadMethodDeclaration(structure) ::= "void Load_$structure.Type.Name$(bool atStreamStart);"
|
||||||
@ -62,7 +62,7 @@ namespace $context.Game$
|
|||||||
$context.UsedTypes:{usedType | $if(usedType.ArrayReferenceExists && usedType.Information && !usedType.Information.IsLeaf)$$HeaderArrayLoadMethodDeclaration(usedType.Type)$$\n$$endif$}$
|
$context.UsedTypes:{usedType | $if(usedType.ArrayReferenceExists && usedType.Information && !usedType.Information.IsLeaf)$$HeaderArrayLoadMethodDeclaration(usedType.Type)$$\n$$endif$}$
|
||||||
$context.UsedStructures:{usedStructure | $if(!usedStructure.IsLeaf && !usedStructure.IsAsset)$$HeaderLoadMethodDeclaration(usedStructure)$$\n$$endif$}$
|
$context.UsedStructures:{usedStructure | $if(!usedStructure.IsLeaf && !usedStructure.IsAsset)$$HeaderLoadMethodDeclaration(usedStructure)$$\n$$endif$}$
|
||||||
$HeaderLoadMethodDeclaration(context.Asset)$
|
$HeaderLoadMethodDeclaration(context.Asset)$
|
||||||
$HeaderSinglePtrLoadMethodDeclaration(context.Asset)$
|
$HeaderTempPtrLoadMethodDeclaration(context.Asset)$
|
||||||
$HeaderAssetLoadMethodDeclaration(context.Asset)$
|
$HeaderAssetLoadMethodDeclaration(context.Asset)$
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -113,7 +113,7 @@ $endif$
|
|||||||
$endif$
|
$endif$
|
||||||
%>
|
%>
|
||||||
|
|
||||||
LoadSinglePtrMethod(context, structure) ::= <<
|
LoadTempPtrMethod(context, structure) ::= <<
|
||||||
void $LoaderClassName(context.Asset)$::LoadPtr_$structure.Type.Name$(const bool atStreamStart)
|
void $LoaderClassName(context.Asset)$::LoadPtr_$structure.Type.Name$(const bool atStreamStart)
|
||||||
{
|
{
|
||||||
assert($TypePtrVarName(structure.Type)$ != nullptr);
|
assert($TypePtrVarName(structure.Type)$ != nullptr);
|
||||||
@ -121,7 +121,7 @@ void $LoaderClassName(context.Asset)$::LoadPtr_$structure.Type.Name$(const bool
|
|||||||
if(atStreamStart)
|
if(atStreamStart)
|
||||||
m_stream->Load<$structure.Type.FullName$*>($TypePtrVarName(structure.Type)$);
|
m_stream->Load<$structure.Type.FullName$*>($TypePtrVarName(structure.Type)$);
|
||||||
|
|
||||||
m_stream->PushBlock($structure.Block.Name$);
|
m_stream->PushBlock($context.DefaultTempBlock.Name$);
|
||||||
|
|
||||||
if(*$TypePtrVarName(structure.Type)$ != nullptr)
|
if(*$TypePtrVarName(structure.Type)$ != nullptr)
|
||||||
{
|
{
|
||||||
@ -131,12 +131,10 @@ void $LoaderClassName(context.Asset)$::LoadPtr_$structure.Type.Name$(const bool
|
|||||||
if(*$TypePtrVarName(structure.Type)$ == PTR_FOLLOWING)
|
if(*$TypePtrVarName(structure.Type)$ == PTR_FOLLOWING)
|
||||||
$endif$
|
$endif$
|
||||||
{
|
{
|
||||||
$if(structure.Block.IsTemp)$
|
|
||||||
$structure.Type.FullName$** toInsert = nullptr;
|
$structure.Type.FullName$** toInsert = nullptr;
|
||||||
if(*$TypePtrVarName(structure.Type)$ == PTR_INSERT)
|
if(*$TypePtrVarName(structure.Type)$ == PTR_INSERT)
|
||||||
toInsert = m_stream->InsertPointer<$structure.Type.FullName$>();
|
toInsert = m_stream->InsertPointer<$structure.Type.FullName$>();
|
||||||
|
|
||||||
$endif$
|
|
||||||
*$TypePtrVarName(structure.Type)$ = m_stream->Alloc<$structure.Type.FullName$>(alignof($structure.Type.FullName$));
|
*$TypePtrVarName(structure.Type)$ = m_stream->Alloc<$structure.Type.FullName$>(alignof($structure.Type.FullName$));
|
||||||
|
|
||||||
$if(!structure.IsLeaf)$
|
$if(!structure.IsLeaf)$
|
||||||
@ -147,11 +145,9 @@ void $LoaderClassName(context.Asset)$::LoadPtr_$structure.Type.Name$(const bool
|
|||||||
$if(structure.IsAsset)$
|
$if(structure.IsAsset)$
|
||||||
LoadAsset_$structure.Type.Name$($TypePtrVarName(structure.Type)$);
|
LoadAsset_$structure.Type.Name$($TypePtrVarName(structure.Type)$);
|
||||||
$endif$
|
$endif$
|
||||||
$if(structure.Block.IsTemp)$
|
|
||||||
|
|
||||||
if(toInsert != nullptr)
|
if(toInsert != nullptr)
|
||||||
*toInsert = *$TypePtrVarName(structure.Type)$;
|
*toInsert = *$TypePtrVarName(structure.Type)$;
|
||||||
$endif$
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -286,7 +282,7 @@ $context.UsedTypes:{usedType | $if(usedType.ArrayReferenceExists && usedType.Inf
|
|||||||
$context.UsedStructures:{usedStructure | $if(!usedStructure.IsLeaf && !usedStructure.IsAsset)$$LoadMethod(context, usedStructure)$$\n$$\n$$endif$}$
|
$context.UsedStructures:{usedStructure | $if(!usedStructure.IsLeaf && !usedStructure.IsAsset)$$LoadMethod(context, usedStructure)$$\n$$\n$$endif$}$
|
||||||
$LoadMethod(context, context.Asset)$
|
$LoadMethod(context, context.Asset)$
|
||||||
|
|
||||||
$LoadSinglePtrMethod(context, context.Asset)$
|
$LoadTempPtrMethod(context, context.Asset)$
|
||||||
|
|
||||||
$LoadAssetMethod(context, context.Asset)$
|
$LoadAssetMethod(context, context.Asset)$
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
|
|||||||
{
|
{
|
||||||
private static readonly IDataPostProcessor[] postProcessors =
|
private static readonly IDataPostProcessor[] postProcessors =
|
||||||
{
|
{
|
||||||
new PostProcessorDefaultBlock(),
|
|
||||||
new PostProcessorUsages(),
|
new PostProcessorUsages(),
|
||||||
new PostProcessorLeafs()
|
new PostProcessorLeafs()
|
||||||
};
|
};
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using ZoneCodeGenerator.Domain;
|
|
||||||
using ZoneCodeGenerator.Domain.FastFileStructure;
|
|
||||||
using ZoneCodeGenerator.Persistence;
|
|
||||||
|
|
||||||
namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
|
|
||||||
{
|
|
||||||
class PostProcessorDefaultBlock : IDataPostProcessor
|
|
||||||
{
|
|
||||||
public bool PostProcess(IDataRepository repository)
|
|
||||||
{
|
|
||||||
var memberDataTypes =
|
|
||||||
repository.GetAllStructs()
|
|
||||||
.AsEnumerable<DataTypeWithMembers>()
|
|
||||||
.Concat(repository.GetAllUnions());
|
|
||||||
|
|
||||||
var defaultTemp = repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Temp && block.IsDefault) ??
|
|
||||||
repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Temp);
|
|
||||||
|
|
||||||
var defaultNormal = repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Normal && block.IsDefault) ??
|
|
||||||
repository.GetAllFastFileBlocks().First(block => block.BlockType == FastFileBlock.Type.Normal);
|
|
||||||
|
|
||||||
foreach (var memberType in memberDataTypes)
|
|
||||||
{
|
|
||||||
var info = repository.GetInformationFor(memberType);
|
|
||||||
|
|
||||||
info.Block = info.IsAsset ? defaultTemp : defaultNormal;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -39,6 +39,9 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
|
|||||||
if (member.Computations.ContainsArrayReference)
|
if (member.Computations.ContainsArrayReference)
|
||||||
member.StructureType.ArrayReferenceExists = true;
|
member.StructureType.ArrayReferenceExists = true;
|
||||||
|
|
||||||
|
if (member.Computations.IsNotDefaultNormalBlock)
|
||||||
|
member.StructureType.ReferenceFromNonDefaultNormalBlockExists = true;
|
||||||
|
|
||||||
member.StructureType.Usages.Add(currentStructure);
|
member.StructureType.Usages.Add(currentStructure);
|
||||||
processingQueue.Enqueue(member.StructureType);
|
processingQueue.Enqueue(member.StructureType);
|
||||||
}
|
}
|
||||||
|
@ -34,14 +34,13 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
|||||||
{
|
{
|
||||||
var typeName = NextMatch(TokenTypeName);
|
var typeName = NextMatch(TokenTypeName);
|
||||||
var typeNameParts = typeName.Split(new[] {"::"}, StringSplitOptions.None);
|
var typeNameParts = typeName.Split(new[] {"::"}, StringSplitOptions.None);
|
||||||
StructureInformation structure;
|
|
||||||
|
|
||||||
if (state.DataTypeInUse != null &&
|
if (state.DataTypeInUse != null &&
|
||||||
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList))
|
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList))
|
||||||
{
|
{
|
||||||
structure = state.DataTypeInUse;
|
// Do nothing
|
||||||
}
|
}
|
||||||
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out structure, out memberList))
|
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out _, out memberList))
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
@ -50,19 +49,18 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
|||||||
throw new TestFailedException($"Could not find type '{typeName}'.");
|
throw new TestFailedException($"Could not find type '{typeName}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberList.Any())
|
if (!memberList.Any())
|
||||||
{
|
{
|
||||||
var lastMember = memberList.Last();
|
throw new TestFailedException("Must specify a member and not a type when setting a block.");
|
||||||
|
|
||||||
structure = lastMember.StructureType ?? throw new TestFailedException(
|
|
||||||
$"Specified member '{lastMember.Member.Name}' is not a structure or union and therefore cannot have its block set.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var member = memberList.Last();
|
||||||
|
|
||||||
var blockName = NextMatch(TokenBlockEnumEntry);
|
var blockName = NextMatch(TokenBlockEnumEntry);
|
||||||
var block = state.FastFileBlocks
|
var block = state.FastFileBlocks
|
||||||
.FirstOrDefault(fastFileBlock => fastFileBlock.Name.Equals(blockName));
|
.FirstOrDefault(fastFileBlock => fastFileBlock.Name.Equals(blockName));
|
||||||
|
|
||||||
structure.Block =
|
member.Block =
|
||||||
block ?? throw new TestFailedException($"Could not find fastfile block with name '{blockName}'");
|
block ?? throw new TestFailedException($"Could not find fastfile block with name '{blockName}'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user