diff --git a/chibild/chibild.core/Generating/ArchivedObjectInputFragment.cs b/chibild/chibild.core/Generating/ArchivedObjectInputFragment.cs index de5243e..c754b1e 100644 --- a/chibild/chibild.core/Generating/ArchivedObjectInputFragment.cs +++ b/chibild/chibild.core/Generating/ArchivedObjectInputFragment.cs @@ -40,6 +40,7 @@ private enum RequiredStates Loaded, } + private readonly ArchiveReader archiveReader; private readonly string archivedObjectName; private readonly Dictionary typeSymbols; @@ -58,12 +59,14 @@ private enum RequiredStates private ArchivedObjectInputFragment( string baseInputPath, string relativePath, + ArchiveReader archiveReader, string archivedObjectName, Dictionary typeSymbols, Dictionary variableSymbols, Dictionary functionSymbols) : base(baseInputPath, relativePath) { + this.archiveReader = archiveReader; this.archivedObjectName = archivedObjectName; this.ObjectName = Path.GetFileNameWithoutExtension(this.archivedObjectName); this.ObjectPath = $"{this.archivedObjectName}@{base.ObjectPath}"; @@ -181,19 +184,18 @@ public LoadObjectResults LoadObjectIfRequired( { logger.Information($"Loading: {this.ObjectPath}"); - if (!ArchiverUtilities.TryOpenArchivedObject( - Path.Combine(this.BaseInputPath, this.RelativePath), + if (!this.archiveReader.TryOpenObjectStream( this.archivedObjectName, true, - out var stream)) + out var objectStream)) { logger.Error( $"Unable find an object on archive: ObjectName={this.archivedObjectName}, ArchiveFile={this.RelativePath}"); return LoadObjectResults.CaughtError; } - using var _s = stream; - var tr = StreamUtilities.CreateTextReader(stream); + using var _ = objectStream; + var tr = StreamUtilities.CreateTextReader(objectStream); var parser = new CilParser(logger); var declarations = parser.Parse( @@ -238,8 +240,10 @@ public static ArchivedObjectInputFragment[] Load( { logger.Information($"Loading symbol table: {relativePath}"); - var symbolLists = ArchiverUtilities.EnumerateSymbolListFromArchive( + var archiveReader = new ArchiveReader( Path.Combine(baseInputPath, relativePath)); + + var symbolLists = archiveReader.EnumerateSymbolListFromArchive(); return symbolLists.Select(symbolList => { @@ -271,6 +275,7 @@ public static ArchivedObjectInputFragment[] Load( return new ArchivedObjectInputFragment( baseInputPath, relativePath, + archiveReader, symbolList.ObjectName, symbols.TryGetValue("type", out var types) ? types : empty, symbols.TryGetValue("variable", out var variableNames) ? variableNames : empty, diff --git a/toolchain.common/Archiving/ArchiverUtilities.cs b/toolchain.common/Archiving/ArchiverUtilities.cs index fb8ff4a..c51a370 100644 --- a/toolchain.common/Archiving/ArchiverUtilities.cs +++ b/toolchain.common/Archiving/ArchiverUtilities.cs @@ -324,11 +324,8 @@ public static IObjectItemDescriptor[] LoadArchivedObjectItemDescriptors( //////////////////////////////////////////////////////////////////// public static IEnumerable EnumerateSymbolListFromArchive( - string archiveFilePath) + this ArchiveReader archiveReader) { - var archiveReader = new ArchiveReader( - archiveFilePath, [ SymbolTableFileName ]); - if (archiveReader.TryOpenObjectStream( SymbolTableFileName, true, out var symbolTableStream)) { @@ -383,16 +380,4 @@ tokens[2] is (TokenTypes.Identity, var name): } } } - - public static bool TryOpenArchivedObject( - string archiveFilePath, - string objectName, - bool decodedBody, - out Stream stream) - { - var archiveReader = new ArchiveReader( - archiveFilePath, [ objectName ]); - return archiveReader.TryOpenObjectStream( - objectName, decodedBody, out stream); - } }