Save mangled name in module graph
This commit is contained in:
@@ -19,6 +19,34 @@ public class ModuleGraph
|
||||
return modules.Values.ToList();
|
||||
}
|
||||
|
||||
public bool TryResolveIdentifier(string moduleName, string identifierName, bool searchPrivate, [NotNullWhen(true)] out Module.IdentifierInfo? info)
|
||||
{
|
||||
if (!TryResolveModule(moduleName, out var module))
|
||||
{
|
||||
info = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!module.TryResolveIdentifier(identifierName, searchPrivate, out info))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryResolveType(string moduleName, string typeName, bool searchPrivate, [NotNullWhen(true)] out Module.TypeInfo? info)
|
||||
{
|
||||
if (!TryResolveModule(moduleName, out var module))
|
||||
{
|
||||
info = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!module.TryResolveType(typeName, searchPrivate, out info))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryResolveModule(string moduleName, [NotNullWhen(true)] out Module? module)
|
||||
{
|
||||
module = modules.GetValueOrDefault(moduleName);
|
||||
@@ -69,7 +97,7 @@ public class ModuleGraph
|
||||
|
||||
foreach (var (name, identifier) in manifestModule.Identifiers)
|
||||
{
|
||||
module.AddIdentifier(name, new Module.IdentifierInfo(identifier.Exported, identifier.Type));
|
||||
module.AddIdentifier(name, new Module.IdentifierInfo(identifier.Exported, identifier.Type, identifier.MangledName, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,14 +138,14 @@ 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);
|
||||
var info = new Module.IdentifierInfo(funcDef.Exported, funcType, NameMangler.Mangle(module.Name, funcDef.Name.Ident, funcType), false);
|
||||
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);
|
||||
var info = new Module.IdentifierInfo(globalVariable.Exported, type, NameMangler.Mangle(module.Name, globalVariable.Name.Ident, type), false);
|
||||
module.AddIdentifier(globalVariable.Name.Ident, info);
|
||||
}
|
||||
}
|
||||
@@ -233,19 +261,19 @@ public class Module(string name)
|
||||
identifiers.Add(name, info);
|
||||
}
|
||||
|
||||
public class IdentifierInfo(bool exported, NubType type)
|
||||
public class IdentifierInfo(bool exported, NubType type, string mangledName, bool external)
|
||||
{
|
||||
public bool Exported { get; } = exported;
|
||||
public NubType Type { get; } = type;
|
||||
public string MangledName { get; } = mangledName;
|
||||
public bool External { get; } = external;
|
||||
}
|
||||
|
||||
|
||||
public abstract class TypeInfo(bool exported)
|
||||
{
|
||||
public bool Exported { get; } = exported;
|
||||
}
|
||||
|
||||
|
||||
public class TypeInfoStruct(bool exported, bool packed) : TypeInfo(exported)
|
||||
{
|
||||
private IReadOnlyList<Field>? fields;
|
||||
|
||||
Reference in New Issue
Block a user