-
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
d6ef74f
commit da78448
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/Draco.Compiler/Internal/Symbols/Synthetized/AutoProperty/AutoPropertyGetterSymbol.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Draco.Compiler.Internal.BoundTree; | ||
using Draco.Compiler.Internal.Symbols.Source; | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using static Draco.Compiler.Internal.BoundTree.BoundTreeFactory; | ||
|
||
namespace Draco.Compiler.Internal.Symbols.Synthetized.AutoProperty; | ||
|
||
/// <summary> | ||
/// An auto-generated getter for an auto-property. | ||
/// </summary> | ||
internal sealed class AutoPropertyGetterSymbol( | ||
Symbol containingSymbol, | ||
SourceAutoPropertySymbol property) : FunctionSymbol, IPropertyAccessorSymbol | ||
{ | ||
public override Symbol ContainingSymbol { get; } = containingSymbol; | ||
|
||
public override string Name => $"{this.Property.Name}_Getter"; | ||
public override bool IsStatic => this.Property.IsStatic; | ||
public override Api.Semantics.Visibility Visibility => this.Property.Visibility; | ||
|
||
public override ImmutableArray<ParameterSymbol> Parameters => ImmutableArray<ParameterSymbol>.Empty; | ||
public override TypeSymbol ReturnType => this.Property.Type; | ||
|
||
public override BoundStatement Body => LazyInitializer.EnsureInitialized(ref this.body, this.BuildBody); | ||
private BoundStatement? body; | ||
|
||
PropertySymbol IPropertyAccessorSymbol.Property => this.Property; | ||
public SourceAutoPropertySymbol Property { get; } = property; | ||
|
||
private BoundStatement BuildBody() => ExpressionStatement(BlockExpression( | ||
locals: [], | ||
statements: [ExpressionStatement(ReturnExpression(FieldExpression( | ||
receiver: this.IsStatic | ||
? null | ||
: throw new NotImplementedException("TODO: for classes"), | ||
field: this.Property.BackingField)))], | ||
value: BoundUnitExpression.Default)); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/Draco.Compiler/Internal/Symbols/Synthetized/AutoProperty/AutoPropertySetterSymbol.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Draco.Compiler.Internal.BoundTree; | ||
using Draco.Compiler.Internal.Symbols.Source; | ||
using Draco.Compiler.Internal.Utilities; | ||
using System; | ||
using System.Collections.Immutable; | ||
using System.Threading; | ||
using static Draco.Compiler.Internal.BoundTree.BoundTreeFactory; | ||
|
||
namespace Draco.Compiler.Internal.Symbols.Synthetized.AutoProperty; | ||
|
||
/// <summary> | ||
/// An auto-generated setter for an auto-property. | ||
/// </summary> | ||
internal sealed class AutoPropertySetterSymbol( | ||
Symbol containingSymbol, | ||
SourceAutoPropertySymbol property) : FunctionSymbol, IPropertyAccessorSymbol | ||
{ | ||
public override Symbol ContainingSymbol { get; } = containingSymbol; | ||
|
||
public override string Name => $"{this.Property.Name}_Setter"; | ||
public override bool IsStatic => this.Property.IsStatic; | ||
public override Api.Semantics.Visibility Visibility => this.Property.Visibility; | ||
|
||
public override ImmutableArray<ParameterSymbol> Parameters => InterlockedUtils.InitializeDefault(ref this.parameters, this.BuildParameters); | ||
private ImmutableArray<ParameterSymbol> parameters; | ||
|
||
public override TypeSymbol ReturnType => WellKnownTypes.Unit; | ||
|
||
public override BoundStatement Body => LazyInitializer.EnsureInitialized(ref this.body, this.BuildBody); | ||
private BoundStatement? body; | ||
|
||
PropertySymbol IPropertyAccessorSymbol.Property => this.Property; | ||
public SourceAutoPropertySymbol Property { get; } = property; | ||
|
||
private ImmutableArray<ParameterSymbol> BuildParameters() => | ||
[new SynthetizedParameterSymbol(this, "value", this.Property.Type)]; | ||
|
||
private BoundStatement BuildBody() => ExpressionStatement(BlockExpression( | ||
locals: [], | ||
statements: [ | ||
ExpressionStatement(AssignmentExpression( | ||
compoundOperator: null, | ||
left: FieldLvalue( | ||
receiver: this.IsStatic | ||
? null | ||
: throw new NotImplementedException("TODO: classes"), | ||
field: this.Property.BackingField), | ||
right: ParameterExpression(this.Parameters[^1]))), | ||
ExpressionStatement(ReturnExpression(BoundUnitExpression.Default))], | ||
value: BoundUnitExpression.Default)); | ||
} |