Only add exported and not external functions and types to manifest

This commit is contained in:
nub31
2026-02-15 03:14:09 +01:00
parent c342b2e102
commit 4d0f7c715f
3 changed files with 34 additions and 11 deletions

View File

@@ -85,7 +85,7 @@ public class ModuleGraph
switch (type)
{
case Manifest.Module.TypeInfoStruct s:
var info = new Module.TypeInfoStruct(s.Exported, s.Packed);
var info = new Module.TypeInfoStruct(true, s.Packed, true);
var fields = s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList();
info.SetFields(fields);
module.AddType(name, info);
@@ -97,7 +97,7 @@ public class ModuleGraph
foreach (var (name, identifier) in manifestModule.Identifiers)
{
module.AddIdentifier(name, new Module.IdentifierInfo(identifier.Exported, identifier.Type, identifier.MangledName, true));
module.AddIdentifier(name, new Module.IdentifierInfo(true, identifier.Type, identifier.MangledName, true));
}
}
}
@@ -108,7 +108,7 @@ public class ModuleGraph
foreach (var structDef in ast.Definitions.OfType<NodeDefinitionStruct>())
{
module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(structDef.Exported, structDef.Packed));
module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(structDef.Exported, structDef.Packed, false));
}
}
@@ -269,12 +269,13 @@ public class Module(string name)
public bool External { get; } = external;
}
public abstract class TypeInfo(bool exported)
public abstract class TypeInfo(bool exported, bool external)
{
public bool Exported { get; } = exported;
public bool External { get; } = external;
}
public class TypeInfoStruct(bool exported, bool packed) : TypeInfo(exported)
public class TypeInfoStruct(bool exported, bool packed, bool external) : TypeInfo(exported, external)
{
private IReadOnlyList<Field>? fields;

View File

@@ -70,8 +70,25 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
foreach (var module in moduleGraph.GetModules())
{
var types = module.GetTypes().ToDictionary(x => x.Key, x => ConvertType(x.Value));
var identifiers = module.GetIdentifiers().ToDictionary(x => x.Key, x => new Module.IdentifierInfo(x.Value.Exported, x.Value.Type, x.Value.MangledName));
var types = new Dictionary<string, Module.TypeInfo>();
var identifiers = new Dictionary<string, Module.IdentifierInfo>();
foreach (var (name, typeInfo) in module.GetTypes())
{
if (typeInfo.Exported && !typeInfo.External)
{
types.Add(name, ConvertType(typeInfo));
}
}
foreach (var (name, identifierInfo) in module.GetIdentifiers())
{
if (identifierInfo.Exported && !identifierInfo.External)
{
identifiers.Add(name, new Module.IdentifierInfo(identifierInfo.Type, identifierInfo.MangledName));
}
}
modules[module.Name] = new Module(types, identifiers);
}
@@ -81,7 +98,7 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
{
return typeInfo switch
{
Compiler.Module.TypeInfoStruct s => new Module.TypeInfoStruct(s.Exported, s.Packed, s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList()),
Compiler.Module.TypeInfoStruct s => new Module.TypeInfoStruct(s.Packed, s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList()),
_ => throw new ArgumentOutOfRangeException(nameof(typeInfo))
};
}
@@ -90,12 +107,12 @@ public record Manifest(Dictionary<string, Manifest.Module> Modules)
public record Module(Dictionary<string, Module.TypeInfo> Types, Dictionary<string, Module.IdentifierInfo> Identifiers)
{
public record IdentifierInfo(bool Exported, NubType Type, string MangledName);
public record IdentifierInfo(NubType Type, string MangledName);
[JsonDerivedType(typeof(TypeInfoStruct), "struct")]
public abstract record TypeInfo(bool Exported);
public abstract record TypeInfo;
public record TypeInfoStruct(bool Exported, bool Packed, IReadOnlyList<TypeInfoStruct.Field> Fields) : TypeInfo(Exported)
public record TypeInfoStruct(bool Packed, IReadOnlyList<TypeInfoStruct.Field> Fields) : TypeInfo
{
public record Field(string Name, NubType Type);
}