From 0bbfb53616131edfe118117b0ef0a7bbfbdca23d Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Tue, 19 Nov 2024 22:30:43 +0100 Subject: [PATCH] Tests pass --- .../Internal/Codegen/MetadataCodegen.cs | 20 +++++++++---------- .../Internal/OptimizingIr/Model/Procedure.cs | 2 +- .../Internal/Symbols/FunctionSymbol.cs | 13 ++++-------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs b/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs index 4d1130a94..d7102d6c4 100644 --- a/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs +++ b/src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs @@ -265,7 +265,7 @@ Symbol GetContainingSymbol() parent: func.ContainingSymbol is null ? (EntityHandle)this.ModuleDefinitionHandle : this.GetEntityHandle(GetContainingSymbol()), - name: func.NestedName, + name: func.MetadataName, signature: this.EncodeBlob(e => { // In generic instances we still need to reference the generic types @@ -298,9 +298,9 @@ Symbol GetContainingSymbol() ? (EntityHandle)this.ModuleDefinitionHandle // We take its parent module : this.GetEntityHandle(parent); - var name = string.IsNullOrEmpty(moduleSymbol.Name) + var name = string.IsNullOrEmpty(moduleSymbol.MetadataName) ? CompilerConstants.DefaultModuleName - : moduleSymbol.Name; + : moduleSymbol.MetadataName; return this.GetOrAddTypeReference( parent: resolutionScope, @namespace: null, @@ -328,7 +328,7 @@ Symbol GetContainingSymbol() } return this.AddMemberReference( parent: parentHandle, - name: field.Name, + name: field.MetadataName, signature: this.EncodeBlob(e => { var encoder = e.Field(); @@ -410,7 +410,7 @@ private EntityHandle GetMultidimensionalArrayTypeHandle(TypeSymbol elementType, private AssemblyReferenceHandle AddAssemblyReference(MetadataAssemblySymbol module) => this.GetOrAddAssemblyReference( - name: module.Name, + name: module.MetadataName, version: module.Version); private static string? GetNamespaceForSymbol(Symbol? symbol) => symbol switch @@ -552,7 +552,7 @@ private FieldDefinitionHandle EncodeField(FieldSymbol field) // Definition return this.AddFieldDefinition( attributes: attributes, - name: field.Name, + name: field.MetadataName, signature: this.EncodeFieldSignature(field)); } @@ -592,7 +592,7 @@ private MethodDefinitionHandle EncodeProcedure(IProcedure procedure, string? spe { var paramHandle = this.AddParameterDefinition( attributes: ParameterAttributes.None, - name: param.Name, + name: param.MetadataName, index: procedure.GetParameterIndex(param)); // Add attributes @@ -619,7 +619,7 @@ private MethodDefinitionHandle EncodeProcedure(IProcedure procedure, string? spe this.MetadataBuilder.AddGenericParameter( parent: definitionHandle, attributes: GenericParameterAttributes.None, - name: this.GetOrAddString(typeParam.Name), + name: this.GetOrAddString(typeParam.MetadataName), index: genericIndex++); } @@ -633,7 +633,7 @@ private PropertyDefinitionHandle EncodeProperty( TypeDefinitionHandle declaringType, PropertySymbol prop) => this.MetadataBuilder.AddProperty( attributes: PropertyAttributes.None, - name: this.GetOrAddString(prop.Name), + name: this.GetOrAddString(prop.MetadataName), signature: this.EncodeBlob(e => { e @@ -709,7 +709,7 @@ private TypeDefinitionHandle EncodeClass(IClass @class, TypeDefinitionHandle? pa this.MetadataBuilder.AddGenericParameter( parent: definitionHandle, attributes: GenericParameterAttributes.None, - name: this.GetOrAddString(typeParam.Name), + name: this.GetOrAddString(typeParam.MetadataName), index: genericIndex++); } diff --git a/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs b/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs index a610d293d..6366b0d89 100644 --- a/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs +++ b/src/Draco.Compiler/Internal/OptimizingIr/Model/Procedure.cs @@ -14,7 +14,7 @@ namespace Draco.Compiler.Internal.OptimizingIr.Model; internal sealed class Procedure : IProcedure { public FunctionSymbol Symbol { get; } - public string Name => this.Symbol.NestedName; + public string Name => this.Symbol.Name; public BasicBlock Entry { get; } IBasicBlock IProcedure.Entry => this.Entry; public IReadOnlyList Attributes => this.Symbol.Attributes; diff --git a/src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs b/src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs index 37e9ddc22..d572ad244 100644 --- a/src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs +++ b/src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs @@ -110,6 +110,10 @@ public delegate IOperand CodegenDelegate( public override bool IsSpecialName => this.IsConstructor; + // TODO: Apart from exposing the metadata name here, we need to take care of nested names for local methods for example + // The name should include the parent functions too, like func foo() { func bar() { ... } } + // the inner method should be called foo.bar in metadata + // NOTE: It seems like the backtick is only for types // TODO: In that case, maybe move this logic out from Symbol and make MetadataName abstract or default to this instead? public override string MetadataName => this.Name; @@ -137,15 +141,6 @@ public delegate IOperand CodegenDelegate( /// public virtual CodegenDelegate? Codegen => null; - /// - /// Retrieves the nested name of this function, which prepends the containing function names. - /// - public string NestedName => this.ContainingSymbol switch - { - FunctionSymbol f => $"{f.NestedName}.{this.Name}", - _ => this.Name, - }; - public override string ToString() { var result = new StringBuilder();