This commit is contained in:
nub31
2026-02-15 03:46:16 +01:00
parent 4d0f7c715f
commit cbe27c0ae8
3 changed files with 39 additions and 22 deletions

View File

@@ -85,7 +85,7 @@ public class ModuleGraph
switch (type)
{
case Manifest.Module.TypeInfoStruct s:
var info = new Module.TypeInfoStruct(true, s.Packed, true);
var info = new Module.TypeInfoStruct(Module.DefinitionKind.External, s.Packed);
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(true, identifier.Type, identifier.MangledName, true));
module.AddIdentifier(name, new Module.IdentifierInfo(Module.DefinitionKind.External, identifier.Type, identifier.MangledName));
}
}
}
@@ -108,7 +108,8 @@ public class ModuleGraph
foreach (var structDef in ast.Definitions.OfType<NodeDefinitionStruct>())
{
module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(structDef.Exported, structDef.Packed, false));
var kind = structDef.Exported ? Module.DefinitionKind.Exported : Module.DefinitionKind.Internal;
module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(kind, structDef.Packed));
}
}
@@ -138,14 +139,16 @@ public class ModuleGraph
var parameters = funcDef.Parameters.Select(x => ResolveType(x.Type, module.Name)).ToList();
var returnType = ResolveType(funcDef.ReturnType, module.Name);
var funcType = NubTypeFunc.Get(parameters, returnType);
var info = new Module.IdentifierInfo(funcDef.Exported, funcType, NameMangler.Mangle(module.Name, funcDef.Name.Ident, funcType), false);
var kind = funcDef.Exported ? Module.DefinitionKind.Exported : Module.DefinitionKind.Internal;
var info = new Module.IdentifierInfo(kind, funcType, NameMangler.Mangle(module.Name, funcDef.Name.Ident, funcType));
module.AddIdentifier(funcDef.Name.Ident, info);
}
foreach (var globalVariable in ast.Definitions.OfType<NodeDefinitionGlobalVariable>())
{
var type = ResolveType(globalVariable.Type, module.Name);
var info = new Module.IdentifierInfo(globalVariable.Exported, type, NameMangler.Mangle(module.Name, globalVariable.Name.Ident, type), false);
var kind = globalVariable.Exported ? Module.DefinitionKind.Exported : Module.DefinitionKind.Internal;
var info = new Module.IdentifierInfo(kind, type, NameMangler.Mangle(module.Name, globalVariable.Name.Ident, type));
module.AddIdentifier(globalVariable.Name.Ident, info);
}
}
@@ -222,7 +225,7 @@ public class Module(string name)
return false;
}
if (info.Exported || searchPrivate)
if (searchPrivate || info.Kind is DefinitionKind.External or DefinitionKind.Exported)
{
customType = info;
return true;
@@ -241,7 +244,7 @@ public class Module(string name)
return false;
}
if (info.Exported || searchPrivate)
if (searchPrivate || info.Kind is DefinitionKind.External or DefinitionKind.Exported)
{
identifierType = info;
return true;
@@ -261,21 +264,26 @@ public class Module(string name)
identifiers.Add(name, info);
}
public class IdentifierInfo(bool exported, NubType type, string mangledName, bool external)
public enum DefinitionKind
{
public bool Exported { get; } = exported;
Internal,
Exported,
External,
}
public class IdentifierInfo(DefinitionKind kind, NubType type, string mangledName)
{
public DefinitionKind Kind { get; } = kind;
public NubType Type { get; } = type;
public string MangledName { get; } = mangledName;
public bool External { get; } = external;
}
public abstract class TypeInfo(bool exported, bool external)
public abstract class TypeInfo(DefinitionKind kind)
{
public bool Exported { get; } = exported;
public bool External { get; } = external;
public DefinitionKind Kind { get; } = kind;
}
public class TypeInfoStruct(bool exported, bool packed, bool external) : TypeInfo(exported, external)
public class TypeInfoStruct(DefinitionKind kind, bool packed) : TypeInfo(kind)
{
private IReadOnlyList<Field>? fields;