1
0
mirror of https://github.com/MoleskiCoder/EightBitNet.git synced 2025-04-27 14:37:13 +00:00

Take some analysis suggestions

This commit is contained in:
Adrian Conlon 2025-02-23 12:14:30 +00:00
parent 4676ea669a
commit 21770b2460
2 changed files with 20 additions and 15 deletions

@ -1,6 +1,7 @@
namespace M6502.Symbols
{
using System.Collections;
using System.Collections.ObjectModel;
using System.Diagnostics;
public class IdentifiableSection : Section
@ -14,8 +15,8 @@
private bool MaybeExtractFromParsed(string key, out string? value)
{
Debug.Assert(this._parsed is not null);
var found = this._parsed.TryGetValue(key, out var extracted);
Debug.Assert(this.Parsed is not null);
var found = this.Parsed.TryGetValue(key, out var extracted);
value = extracted;
return found;
}
@ -27,10 +28,10 @@
return available;
}
protected bool MaybeExtractCompoundInteger(string key, out List<int> value)
protected bool MaybeExtractCompoundInteger(string key, out ReadOnlyCollection<int> value)
{
var available = this.MaybeExtractFromParsed(key, out var extracted);
value = extracted is null ? [] : ExtractCompoundInteger(extracted);
value = extracted is null ? new ReadOnlyCollection<int>([]) : ExtractCompoundInteger(extracted);
return available;
}
@ -70,11 +71,11 @@
var referencingContainer = referenceClassAttribute.Referencing;
// Get the parent container field
var containerType = this._container.GetType();
var containerType = this.Container.GetType();
Debug.Assert(referencingContainer is not null);
var containerField = containerType.GetField(referencingContainer);
Debug.Assert(containerField is not null);
var fieldValue = containerField.GetValue(this._container);
var fieldValue = containerField.GetValue(this.Container);
var fieldList = fieldValue as IList;
// Now get the referenced object from the parent container field (via ID as an index)
@ -100,7 +101,7 @@
}
}
private void ExtractReferencesProperty(List<int> ids, string name, System.Type type)
private void ExtractReferencesProperty(ReadOnlyCollection<int> ids, string name, System.Type type)
{
// The reference container in the parent class
//var referenceSectionProperties = GetSectionProperties(type);

@ -1,6 +1,7 @@
namespace M6502.Symbols
{
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
@ -11,13 +12,15 @@
protected static readonly Dictionary<System.Type, ReflectedSectionProperties> SectionPropertiesCache = [];
protected static readonly DateTime UnixEpoch = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
protected readonly Parser _container;
private readonly Parser _container;
// Needed to evaluate references on a second pass
protected readonly Dictionary<string, int> _references = [];
protected readonly Dictionary<string, List<int>> _multipleReferences = [];
private readonly Dictionary<string, int> _references = [];
private readonly Dictionary<string, List<int>> _multipleReferences = [];
protected Dictionary<string, string>? _parsed;
protected Parser Container => this._container;
protected Dictionary<string, string>? Parsed { get; private set; }
protected ReflectedSectionProperties SectionProperties => GetSectionProperties(this.GetType());
@ -48,7 +51,7 @@
public virtual void Parse(Dictionary<string, string>? entries)
{
ArgumentNullException.ThrowIfNull(entries);
this._parsed = entries;
this.Parsed = entries;
this._container.SectionEntries.Add(this);
this.ProcessAttributesOfProperties();
foreach (var entry in entries)
@ -84,7 +87,8 @@
}
else if (references)
{
this._multipleReferences.Add(key, ExtractCompoundInteger(value));
var multiple = ExtractCompoundInteger(value);
this._multipleReferences.Add(key, [.. multiple]);
}
else
{
@ -154,7 +158,7 @@
return value.Split('+');
}
protected static List<int> ExtractCompoundInteger(string value)
protected static ReadOnlyCollection<int> ExtractCompoundInteger(string value)
{
var elements = ExtractCompoundString(value);
var returned = new List<int>(elements.Length);
@ -162,7 +166,7 @@
{
returned.Add(ExtractInteger(element));
}
return returned;
return returned.AsReadOnly();
}
}
}