mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-28 07:11:52 +00:00
ZoneCodeGenerator: Add reusable statement for commands to be able to tell the generator that a member can be a fastfile offset and not nessecarly a following pointer
This commit is contained in:
@ -11,6 +11,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
||||
public Variable Member { get; set; }
|
||||
public bool IsString { get; set; }
|
||||
public bool IsScriptString { get; set; }
|
||||
public bool IsReusable { get; set; }
|
||||
public IEvaluation Condition { get; set; }
|
||||
|
||||
public MemberComputations Computations => new MemberComputations(this);
|
||||
@ -21,6 +22,7 @@ namespace ZoneCodeGenerator.Domain.Information
|
||||
StructureType = structureType;
|
||||
IsString = false;
|
||||
IsScriptString = false;
|
||||
IsReusable = false;
|
||||
Condition = null;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl
|
||||
new TestCount(),
|
||||
new TestGame(),
|
||||
new TestReorder(),
|
||||
new TestReusable(),
|
||||
new TestScriptString(),
|
||||
new TestString(),
|
||||
new TestUse()
|
||||
|
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZoneCodeGenerator.Domain;
|
||||
using ZoneCodeGenerator.Parsing.Matching;
|
||||
using ZoneCodeGenerator.Parsing.Matching.Matchers;
|
||||
using ZoneCodeGenerator.Parsing.Testing;
|
||||
|
||||
namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
|
||||
{
|
||||
class TestReusable : AbstractTokenTest<ICommandParserState>
|
||||
{
|
||||
private const string MemberTypeNameToken = "name";
|
||||
|
||||
private static readonly TokenMatcher[] matchers = {
|
||||
new MatcherLiteral("set"),
|
||||
new MatcherLiteral("reusable"),
|
||||
new MatcherTypename().WithName(MemberTypeNameToken),
|
||||
new MatcherLiteral(";")
|
||||
};
|
||||
|
||||
public TestReusable() : base(matchers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void ProcessMatch(ICommandParserState state)
|
||||
{
|
||||
var typeName = NextMatch(MemberTypeNameToken);
|
||||
var typeNameParts = typeName.Split(new[] { "::" }, StringSplitOptions.None);
|
||||
|
||||
if (state.DataTypeInUse != null &&
|
||||
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList))
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out _, out memberList))
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new TestFailedException($"Could not find type '{typeName}'.");
|
||||
}
|
||||
|
||||
if (memberList == null || !memberList.Any())
|
||||
{
|
||||
throw new TestFailedException("Need to specify a member when trying to set to a string.");
|
||||
}
|
||||
|
||||
var lastMember = memberList.Last();
|
||||
|
||||
if (!lastMember.Computations.IsNonEmbeddedReference)
|
||||
{
|
||||
throw new TestFailedException($"Specified member '{lastMember.Member.Name}' is not a pointer reference and therefore cannot be reusable.");
|
||||
}
|
||||
|
||||
lastMember.IsReusable = true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user