Skip to content

Commit

Permalink
Type => Class, + ran namespace simplification.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuinox committed Oct 27, 2024
1 parent fb297e0 commit 56fd7f4
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 38 deletions.
16 changes: 8 additions & 8 deletions src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ private BlobHandle EncodeAttributeSignature(AttributeInstance attribute)
}

private TypeDefinitionHandle EncodeClass(
IType type,
IClass @class,
TypeDefinitionHandle? parent,
ref int fieldIndex,
ref int procIndex
Expand All @@ -664,7 +664,7 @@ ref int procIndex
var startFieldIndex = fieldIndex;
var startProcIndex = procIndex;

var visibility = (type.Symbol.Visibility, parent) switch
var visibility = (@class.Symbol.Visibility, parent) switch
{
(Api.Semantics.Visibility.Public, not null) => TypeAttributes.NestedPublic,
(Api.Semantics.Visibility.Public, null) => TypeAttributes.Public,
Expand All @@ -674,19 +674,19 @@ ref int procIndex

var attributes = visibility | TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit | TypeAttributes.Sealed;

if (type.Symbol.IsValueType) attributes |= TypeAttributes.SequentialLayout; // AutoLayout = 0.
if (@class.Symbol.IsValueType) attributes |= TypeAttributes.SequentialLayout; // AutoLayout = 0.

var createdClass = this.AddTypeDefinition(
attributes,
null,
type.Name,
type.Symbol.IsValueType ? this.systemValueTypeReference : this.systemObjectReference,
@class.Name,
@class.Symbol.IsValueType ? this.systemValueTypeReference : this.systemObjectReference,
fieldList: MetadataTokens.FieldDefinitionHandle(startFieldIndex),
methodList: MetadataTokens.MethodDefinitionHandle(startProcIndex)
);

// Procedures
foreach (var proc in type.Methods.Values)
foreach (var proc in @class.Methods.Values)
{
if (proc.Symbol is DefaultConstructorSymbol ctor)
{
Expand All @@ -703,14 +703,14 @@ ref int procIndex
}

// Fields
foreach (var field in type.Fields)
foreach (var field in @class.Fields)
{
this.EncodeField(field);
++fieldIndex;
}

// If this is a valuetype without fields, we add .pack 0 and .size 1
if (type.Symbol.IsValueType && type.Fields.Count == 0)
if (@class.Symbol.IsValueType && @class.Fields.Count == 0)
{
this.MetadataBuilder.AddTypeLayout(
type: createdClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Draco.Compiler.Internal.OptimizingIr.Codegen;
/// <summary>
/// Generates IR code for a class.
/// </summary>
internal sealed class ClassCodegen(ModuleCodegen moduleCodegen, Type @class) : SymbolVisitor
internal sealed class ClassCodegen(ModuleCodegen moduleCodegen, Class @class) : SymbolVisitor
{
private Compilation Compilation => moduleCodegen.Compilation;
private bool EmitSequencePoints => moduleCodegen.EmitSequencePoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
using Draco.Compiler.Internal.Utilities;

namespace Draco.Compiler.Internal.OptimizingIr.Model;
internal class Type(Module declaringModule, TypeSymbol symbol) : IType
internal class Class(Module declaringModule, TypeSymbol symbol) : IClass
{

public TypeSymbol Symbol { get; } = symbol;
public string Name => this.Symbol.Name;

public Module DeclaringModule { get; } = declaringModule;
IModule IType.DeclaringModule => this.DeclaringModule;
IModule IClass.DeclaringModule => this.DeclaringModule;
public Assembly Assembly => this.DeclaringModule.Assembly;
IAssembly IType.Assembly => this.Assembly;
IAssembly IClass.Assembly => this.Assembly;

public IReadOnlyList<TypeParameterSymbol> Generics => this.Symbol.GenericParameters;
public IReadOnlyDictionary<FunctionSymbol, IProcedure> Methods => this.methods;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Draco.Compiler.Internal.OptimizingIr.Model;

internal interface IType
internal interface IClass
{
/// <summary>
/// The symbol of this type.
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/OptimizingIr/Model/IModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal interface IModule
/// <summary>
/// The compiled types within this module.
/// </summary>
public IReadOnlyDictionary<TypeSymbol, IType> Types { get; }
public IReadOnlyDictionary<TypeSymbol, IClass> Types { get; }

/// <summary>
/// The procedure performing global initialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal interface IProcedure
/// The type this procedure is defined in.
/// When <see langword="null"/>, this procedure is a free function.
/// </summary>
public IType? DeclaringType { get; }
public IClass? DeclaringType { get; }

/// <summary>
/// The module this procedure is defined in.
Expand Down
12 changes: 6 additions & 6 deletions src/Draco.Compiler/Internal/OptimizingIr/Model/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal sealed class Module : IModule
public IDictionary<ModuleSymbol, IModule> Submodules => this.submodules;
IReadOnlyDictionary<ModuleSymbol, IModule> IModule.Submodules => this.submodules;

public IDictionary<TypeSymbol, IType> Types => this.types;
IReadOnlyDictionary<TypeSymbol, IType> IModule.Types => this.types;
public IDictionary<TypeSymbol, IClass> Types => this.types;
IReadOnlyDictionary<TypeSymbol, IClass> IModule.Types => this.types;

public IReadOnlySet<FieldSymbol> Fields => this.fields;

Expand All @@ -38,7 +38,7 @@ internal sealed class Module : IModule
private readonly HashSet<FieldSymbol> fields = [];
private readonly Dictionary<FunctionSymbol, IProcedure> procedures = [];
private readonly Dictionary<ModuleSymbol, IModule> submodules = [];
private readonly Dictionary<TypeSymbol, IType> types = [];
private readonly Dictionary<TypeSymbol, IClass> types = [];

public Module(ModuleSymbol symbol, Assembly assembly, Module? Parent)
{
Expand Down Expand Up @@ -84,14 +84,14 @@ public Module DefineModule(ModuleSymbol moduleSymbol)
return (Module)result;
}

public Type DefineType(TypeSymbol typeSymbol)
public Class DefineType(TypeSymbol typeSymbol)
{
if (!this.types.TryGetValue(typeSymbol, out var result))
{
result = new Type(this, typeSymbol);
result = new Class(this, typeSymbol);
this.types.Add(typeSymbol, result);
}
return (Type)result;
return (Class)result;
}

public override string ToString()
Expand Down
6 changes: 3 additions & 3 deletions src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal sealed class Procedure : IProcedure
public TypeSymbol? TypeSymbol => this.Symbol.Type;
public Module DeclaringModule { get; }
IModule IProcedure.DeclaringModule => this.DeclaringModule;
public Type? DeclaringType { get; }
IType? IProcedure.DeclaringType => this.DeclaringType;
public Class? DeclaringType { get; }
IClass? IProcedure.DeclaringType => this.DeclaringType;
public Assembly Assembly => this.DeclaringModule.Assembly;
IAssembly IProcedure.Assembly => this.Assembly;
public BasicBlock Entry { get; }
Expand All @@ -40,7 +40,7 @@ internal sealed class Procedure : IProcedure
private readonly List<LocalSymbol> locals = [];
private readonly List<Register> registers = [];

public Procedure(Module declaringModule, Type? declaringType, FunctionSymbol symbol)
public Procedure(Module declaringModule, Class? declaringType, FunctionSymbol symbol)
{
this.DeclaringModule = declaringModule;
this.DeclaringType = declaringType;
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override FunctionSymbol GenericInstantiate(Symbol? containingSymbol, Immu
public override FunctionSymbol GenericInstantiate(Symbol? containingSymbol, GenericContext context) =>
new FunctionInstanceSymbol(containingSymbol, this, context);

public override Api.Semantics.IFunctionSymbol ToApiSymbol() => new Api.Semantics.FunctionSymbol(this);
public override IFunctionSymbol ToApiSymbol() => new Api.Semantics.FunctionSymbol(this);

public override void Accept(SymbolVisitor visitor) => visitor.VisitFunction(this);
public override TResult Accept<TResult>(SymbolVisitor<TResult> visitor) => visitor.VisitFunction(this);
Expand Down
10 changes: 5 additions & 5 deletions src/Draco.Compiler/Internal/Symbols/Symbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public virtual string MetadataFullName
/// <summary>
/// The visibility of this symbol.
/// </summary>
public virtual Api.Semantics.Visibility Visibility => Api.Semantics.Visibility.Internal;
public virtual Visibility Visibility => Visibility.Internal;

/// <summary>
/// The syntax declaring this symbol.
Expand Down Expand Up @@ -323,11 +323,11 @@ private protected string GenericsToString()
return string.Empty;
}

private protected static Api.Semantics.Visibility GetVisibilityFromTokenKind(TokenKind? kind) => kind switch
private protected static Visibility GetVisibilityFromTokenKind(TokenKind? kind) => kind switch
{
null => Api.Semantics.Visibility.Private,
TokenKind.KeywordInternal => Api.Semantics.Visibility.Internal,
TokenKind.KeywordPublic => Api.Semantics.Visibility.Public,
null => Visibility.Private,
TokenKind.KeywordInternal => Visibility.Internal,
TokenKind.KeywordPublic => Visibility.Public,
_ => throw new InvalidOperationException($"illegal visibility modifier token {kind}"),
};

Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Symbols/TypeParameterSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override TypeSymbol GenericInstantiate(Symbol? containingSymbol, GenericC
? type
: this;

public override Api.Semantics.ITypeSymbol ToApiSymbol() => new Api.Semantics.TypeParameterSymbol(this);
public override ITypeSymbol ToApiSymbol() => new Api.Semantics.TypeParameterSymbol(this);

public override string ToString() => this.Name;

Expand Down
2 changes: 1 addition & 1 deletion src/Draco.Compiler/Internal/Symbols/TypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public override TypeSymbol GenericInstantiate(Symbol? containingSymbol, GenericC
return new TypeInstanceSymbol(containingSymbol, this, context);
}

public override Api.Semantics.ITypeSymbol ToApiSymbol() => new Api.Semantics.TypeSymbol(this);
public override ITypeSymbol ToApiSymbol() => new Api.Semantics.TypeSymbol(this);

public override void Accept(SymbolVisitor visitor) => visitor.VisitType(this);
public override TResult Accept<TResult>(SymbolVisitor<TResult> visitor) => visitor.VisitType(this);
Expand Down
4 changes: 2 additions & 2 deletions src/Draco.Compiler/Internal/Symbols/WellKnownTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public IEnumerable<Symbol> GetEnumEqualityMembers(TypeSymbol type)
/// </summary>
/// <param name="type">The reflected type to translate.</param>
/// <returns>The translated type symbol, or <see langword="null"/> if it's not a translatable primitive type.</returns>
public TypeSymbol? TranslatePrimitive(System.Type type)
public TypeSymbol? TranslatePrimitive(Type type)
{
if (type == typeof(byte)) return this.SystemByte;
if (type == typeof(ushort)) return this.SystemUInt16;
Expand All @@ -225,7 +225,7 @@ public IEnumerable<Symbol> GetEnumEqualityMembers(TypeSymbol type)
if (type == typeof(string)) return this.SystemString;
if (type == typeof(object)) return this.SystemObject;

if (type == typeof(System.Type)) return this.SystemType;
if (type == typeof(Type)) return this.SystemType;

return null;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Draco.DebugAdapter/DracoDebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public Task<SetBreakpointsResponse> SetBreakpointsAsync(SetBreakpointsArguments
return Task.FromResult(new SetBreakpointsResponse()
{
Breakpoints = args.Breakpoints?
.Select(bp => new Dap.Model.Breakpoint()
.Select(bp => new Breakpoint()
{
Verified = false,
Id = this.translator.AllocateId(bp),
Expand All @@ -235,11 +235,11 @@ public Task<SetBreakpointsResponse> SetBreakpointsAsync(SetBreakpointsArguments
});
}

private List<Dap.Model.Breakpoint> SetBreakpointsImpl(SetBreakpointsArguments args)
private List<Breakpoint> SetBreakpointsImpl(SetBreakpointsArguments args)
{
if (this.debugger is null) throw new InvalidOperationException("cannot set up breakpoints without a running debugger");

var result = new List<Dap.Model.Breakpoint>();
var result = new List<Breakpoint>();
var source = this.debugger.MainModule.SourceFiles
.FirstOrDefault(s => PathEqualityComparer.Instance.Equals(s.Uri.AbsolutePath, args.Source.Path));
if (args.Breakpoints is not null && source is not null)
Expand Down
2 changes: 1 addition & 1 deletion src/Draco.SourceGeneration/Lsp/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class Translator(Ts.MetaModel sourceModel)
/// </summary>
/// <param name="name">The name of the type.</param>
/// <param name="type">The reflected type.</param>
public void AddBuiltinType(string name, System.Type type) =>
public void AddBuiltinType(string name, Type type) =>
this.AddBuiltinType(name, type.FullName);

/// <summary>
Expand Down

0 comments on commit 56fd7f4

Please sign in to comment.