extern
This commit is contained in:
@@ -86,7 +86,7 @@ public class ModuleGraph
|
||||
{
|
||||
case Manifest.Module.TypeInfoStruct s:
|
||||
{
|
||||
var info = new Module.TypeInfoStruct(Module.DefinitionKind.External, s.Packed);
|
||||
var info = new Module.TypeInfoStruct(Module.DefinitionSource.Imported, true, s.Packed);
|
||||
var fields = s.Fields.Select(x => new Module.TypeInfoStruct.Field(x.Name, x.Type)).ToList();
|
||||
info.SetFields(fields);
|
||||
module.AddType(name, info);
|
||||
@@ -94,7 +94,7 @@ public class ModuleGraph
|
||||
}
|
||||
case Manifest.Module.TypeInfoEnum s:
|
||||
{
|
||||
var info = new Module.TypeInfoEnum(Module.DefinitionKind.External);
|
||||
var info = new Module.TypeInfoEnum(Module.DefinitionSource.Imported, true);
|
||||
var variants = s.Variants.Select(v => new Module.TypeInfoEnum.Variant(v.Name, v.Type)).ToList();
|
||||
info.SetVariants(variants);
|
||||
module.AddType(name, info);
|
||||
@@ -107,7 +107,7 @@ public class ModuleGraph
|
||||
|
||||
foreach (var (name, identifier) in manifestModule.Identifiers)
|
||||
{
|
||||
module.AddIdentifier(name, new Module.IdentifierInfo(Module.DefinitionKind.External, identifier.Type, identifier.MangledName));
|
||||
module.AddIdentifier(name, new Module.IdentifierInfo(Module.DefinitionSource.Imported, true, true, identifier.Type, identifier.MangledName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,14 +118,12 @@ public class ModuleGraph
|
||||
|
||||
foreach (var structDef in ast.Definitions.OfType<NodeDefinitionStruct>())
|
||||
{
|
||||
var kind = structDef.Exported ? Module.DefinitionKind.Exported : Module.DefinitionKind.Internal;
|
||||
module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(kind, structDef.Packed));
|
||||
module.AddType(structDef.Name.Ident, new Module.TypeInfoStruct(Module.DefinitionSource.Internal, structDef.Exported, structDef.Packed));
|
||||
}
|
||||
|
||||
foreach (var enumDef in ast.Definitions.OfType<NodeDefinitionEnum>())
|
||||
{
|
||||
var kind = enumDef.Exported ? Module.DefinitionKind.Exported : Module.DefinitionKind.Internal;
|
||||
module.AddType(enumDef.Name.Ident, new Module.TypeInfoEnum(kind));
|
||||
module.AddType(enumDef.Name.Ident, new Module.TypeInfoEnum(Module.DefinitionSource.Internal, enumDef.Exported));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,18 +163,32 @@ public class ModuleGraph
|
||||
foreach (var funcDef in ast.Definitions.OfType<NodeDefinitionFunc>())
|
||||
{
|
||||
var parameters = funcDef.Parameters.Select(x => ResolveType(x.Type, module.Name)).ToList();
|
||||
var returnType = ResolveType(funcDef.ReturnType, module.Name);
|
||||
var returnType = funcDef.ReturnType == null ? NubTypeVoid.Instance : ResolveType(funcDef.ReturnType, module.Name);
|
||||
var funcType = NubTypeFunc.Get(parameters, returnType);
|
||||
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));
|
||||
var info = new Module.IdentifierInfo(Module.DefinitionSource.Internal, funcDef.Exported, false, funcType, NameMangler.Mangle(module.Name, funcDef.Name.Ident, funcType));
|
||||
module.AddIdentifier(funcDef.Name.Ident, info);
|
||||
}
|
||||
|
||||
foreach (var funcDef in ast.Definitions.OfType<NodeDefinitionExternFunc>())
|
||||
{
|
||||
var parameters = funcDef.Parameters.Select(x => ResolveType(x.Type, module.Name)).ToList();
|
||||
var returnType = funcDef.ReturnType == null ? NubTypeVoid.Instance : ResolveType(funcDef.ReturnType, module.Name);
|
||||
var funcType = NubTypeFunc.Get(parameters, returnType);
|
||||
var info = new Module.IdentifierInfo(Module.DefinitionSource.Internal, funcDef.Exported, true, funcType, funcDef.Name.Ident);
|
||||
module.AddIdentifier(funcDef.Name.Ident, info);
|
||||
}
|
||||
|
||||
foreach (var globalVariable in ast.Definitions.OfType<NodeDefinitionGlobalVariable>())
|
||||
{
|
||||
var type = ResolveType(globalVariable.Type, module.Name);
|
||||
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));
|
||||
var info = new Module.IdentifierInfo(Module.DefinitionSource.Internal, globalVariable.Exported, false, type, NameMangler.Mangle(module.Name, globalVariable.Name.Ident, type));
|
||||
module.AddIdentifier(globalVariable.Name.Ident, info);
|
||||
}
|
||||
|
||||
foreach (var globalVariable in ast.Definitions.OfType<NodeDefinitionExternGlobalVariable>())
|
||||
{
|
||||
var type = ResolveType(globalVariable.Type, module.Name);
|
||||
var info = new Module.IdentifierInfo(Module.DefinitionSource.Internal, globalVariable.Exported, true, type, NameMangler.Mangle(module.Name, globalVariable.Name.Ident, type));
|
||||
module.AddIdentifier(globalVariable.Name.Ident, info);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +345,7 @@ public class Module(string name)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (searchPrivate || info.Kind is DefinitionKind.External or DefinitionKind.Exported)
|
||||
if (searchPrivate || info.Source == DefinitionSource.Internal)
|
||||
{
|
||||
customType = info;
|
||||
return true;
|
||||
@@ -352,7 +364,7 @@ public class Module(string name)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (searchPrivate || info.Kind is DefinitionKind.External or DefinitionKind.Exported)
|
||||
if (searchPrivate || info.Source == DefinitionSource.Internal)
|
||||
{
|
||||
identifierType = info;
|
||||
return true;
|
||||
@@ -372,26 +384,28 @@ public class Module(string name)
|
||||
identifiers.Add(name, info);
|
||||
}
|
||||
|
||||
public enum DefinitionKind
|
||||
public enum DefinitionSource
|
||||
{
|
||||
Internal,
|
||||
Exported,
|
||||
External,
|
||||
Imported,
|
||||
}
|
||||
|
||||
public class IdentifierInfo(DefinitionKind kind, NubType type, string mangledName)
|
||||
public class IdentifierInfo(DefinitionSource source, bool exported, bool @extern, NubType type, string mangledName)
|
||||
{
|
||||
public DefinitionKind Kind { get; } = kind;
|
||||
public DefinitionSource Source { get; } = source;
|
||||
public bool Exported { get; } = exported;
|
||||
public bool Extern { get; } = @extern;
|
||||
public NubType Type { get; } = type;
|
||||
public string MangledName { get; } = mangledName;
|
||||
}
|
||||
|
||||
public abstract class TypeInfo(DefinitionKind kind)
|
||||
public abstract class TypeInfo(DefinitionSource source, bool exported)
|
||||
{
|
||||
public DefinitionKind Kind { get; } = kind;
|
||||
public DefinitionSource Source { get; } = source;
|
||||
public bool Exported { get; } = exported;
|
||||
}
|
||||
|
||||
public class TypeInfoStruct(DefinitionKind kind, bool packed) : TypeInfo(kind)
|
||||
public class TypeInfoStruct(DefinitionSource source, bool exported, bool packed) : TypeInfo(source, exported)
|
||||
{
|
||||
private IReadOnlyList<Field>? fields;
|
||||
|
||||
@@ -410,7 +424,7 @@ public class Module(string name)
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeInfoEnum(DefinitionKind kind) : TypeInfo(kind)
|
||||
public class TypeInfoEnum(DefinitionSource source, bool exported) : TypeInfo(source, exported)
|
||||
{
|
||||
private IReadOnlyList<Variant>? variants;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user