Skip to content

Commit

Permalink
Update SourceThisParameterSymbol.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Nov 2, 2024
1 parent fbbffa9 commit 0cd287e
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Draco.Compiler.Api.Syntax;
using Draco.Compiler.Internal.Binding;

namespace Draco.Compiler.Internal.Symbols.Source;

internal sealed class SourceThisParameterSymbol(FunctionSymbol containingSymbol, ThisParameterSyntax syntax) : ParameterSymbol, ISourceSymbol
/// <summary>
/// The 'this' parameter of a function defined in-source.
/// </summary>
internal sealed class SourceThisParameterSymbol : ParameterSymbol, ISourceSymbol
{
public override string Name => "this";
public override FunctionSymbol ContainingSymbol { get; } = containingSymbol;
public override FunctionSymbol ContainingSymbol { get; }
public override bool IsVariadic => false;
public override bool IsThis => true;
public override ThisParameterSyntax DeclaringSyntax { get; } = syntax;
public override ThisParameterSyntax DeclaringSyntax { get; }

public override ImmutableArray<AttributeInstance> Attributes => [];
public override TypeSymbol Type { get; } = (containingSymbol.ContainingSymbol as TypeSymbol)!;
public override TypeSymbol Type { get; }

public SourceThisParameterSymbol(FunctionSymbol containingSymbol, ThisParameterSyntax syntax)
{
var containingType = containingSymbol.ContainingSymbol?.AncestorChain
.OfType<TypeSymbol>()
.FirstOrDefault()
?? throw new ArgumentException("the containing symbol of a source this parameter must be a function within a type");

this.ContainingSymbol = containingSymbol;
this.DeclaringSyntax = syntax;
this.Type = containingType;
}

public void Bind(IBinderProvider binderProvider) { }
}

0 comments on commit 0cd287e

Please sign in to comment.