-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbbffa9
commit 0cd287e
Showing
1 changed file
with
21 additions
and
4 deletions.
There are no files selected for viewing
25 changes: 21 additions & 4 deletions
25
src/Draco.Compiler/Internal/Symbols/Source/SourceThisParameterSymbol.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { } | ||
} |