Skip to content

Commit

Permalink
Tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Nov 19, 2024
1 parent 670c6d4 commit 0bbfb53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/Draco.Compiler/Internal/Codegen/MetadataCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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
Expand All @@ -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++);
}

Expand All @@ -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
Expand Down Expand Up @@ -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++);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttributeInstance> Attributes => this.Symbol.Attributes;
Expand Down
13 changes: 4 additions & 9 deletions src/Draco.Compiler/Internal/Symbols/FunctionSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,15 +141,6 @@ public delegate IOperand CodegenDelegate(
/// </summary>
public virtual CodegenDelegate? Codegen => null;

/// <summary>
/// Retrieves the nested name of this function, which prepends the containing function names.
/// </summary>
public string NestedName => this.ContainingSymbol switch
{
FunctionSymbol f => $"{f.NestedName}.{this.Name}",
_ => this.Name,
};

public override string ToString()
{
var result = new StringBuilder();
Expand Down

0 comments on commit 0bbfb53

Please sign in to comment.