Remove need to check object validity in LR35902 fuse tests.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-07-21 09:28:49 +01:00
parent 6a883a6252
commit e4a0aaedc4
6 changed files with 32 additions and 36 deletions

View File

@ -9,29 +9,27 @@
private readonly TestEvents events = new TestEvents();
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
public bool Valid => !string.IsNullOrEmpty(this.Description);
public string Description { get; private set; }
public RegisterState RegisterState { get; } = new RegisterState();
public ReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
public void Parse(Lines lines)
public bool TryParse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
while (!lines.EndOfFile && !this.Valid)
while (!lines.EndOfFile && string.IsNullOrWhiteSpace(this.Description))
{
this.Description = lines.ReadLine();
}
if (!this.Valid)
if (string.IsNullOrWhiteSpace(this.Description))
{
return;
return false;
}
this.events.Parse(lines);
@ -50,6 +48,8 @@
}
}
while (!finished);
return true;
}
}
}

View File

@ -17,8 +17,7 @@
while (!this.lines.EndOfFile)
{
var result = new Result();
result.Parse(this.lines);
if (result.Valid)
if (result.TryParse(this.lines))
{
this.Container.Add(result.Description, result);
}

View File

@ -5,9 +5,7 @@
public class Test
{
private List<MemoryDatum> memoryData = new List<MemoryDatum>();
public bool Valid => !string.IsNullOrEmpty(this.Description);
private readonly List<MemoryDatum> memoryData = new List<MemoryDatum>();
public string Description { get; private set; }
@ -15,21 +13,21 @@
public IReadOnlyCollection<MemoryDatum> MemoryData => this.memoryData.AsReadOnly();
public void Parse(Lines lines)
public bool TryParse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
while (!lines.EndOfFile && !this.Valid)
while (!lines.EndOfFile && string.IsNullOrEmpty(this.Description))
{
this.Description = lines.ReadLine();
}
if (!this.Valid)
if (string.IsNullOrEmpty(this.Description))
{
return;
return false;
}
this.RegisterState.Parse(lines);
@ -47,6 +45,8 @@
}
}
while (!finished);
return true;
}
}
}

View File

@ -7,8 +7,6 @@
{
private int cycles;
public bool Valid { get; private set; } = false;
public int Cycles => this.cycles;
public string Specifier { get; private set; }
@ -17,37 +15,37 @@
public byte Value { get; private set; } = (byte)EightBit.Mask.Mask8;
public void Parse(Lines lines)
public bool TryParse(Lines lines)
{
if (lines == null)
{
throw new ArgumentNullException(nameof(lines));
}
this.ParseLine(lines.ReadLine());
if (!this.Valid)
var returned = this.TryParseLine(lines.ReadLine());
if (!returned)
{
lines.UnreadLine();
}
return returned;
}
private void ParseLine(string line)
private bool TryParseLine(string line)
{
var split = line.Split(new char[] { ' ', '\t' });
this.ParseLine(split);
return this.TryParseLine(split);
}
private void ParseLine(string[] tokens)
private bool TryParseLine(string[] tokens)
{
this.Valid = int.TryParse(tokens[0], out this.cycles);
if (!this.Valid)
if (!int.TryParse(tokens[0], out this.cycles))
{
return;
return false;
}
this.Specifier = tokens[1];
this.Valid = true;
switch (this.Specifier)
{
case "MR":
@ -68,9 +66,10 @@
break;
default:
this.Valid = false;
break;
return false;
}
return true;
}
}
}

View File

@ -11,18 +11,17 @@
public void Parse(Lines lines)
{
var complete = false;
var success = false;
do
{
var e = new TestEvent();
e.Parse(lines);
complete = !e.Valid;
if (!complete)
success = e.TryParse(lines);
if (success)
{
this.container.Add(e);
}
}
while (!complete);
while (success);
}
}
}

View File

@ -17,8 +17,7 @@
while (!this.lines.EndOfFile)
{
var test = new Test();
test.Parse(this.lines);
if (test.Valid)
if (test.TryParse(this.lines))
{
this.Container.Add(test.Description, test);
}