Skip to content

Commit

Permalink
Make SourceClonedParameterSymbol abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jun 25, 2021
1 parent 5f44ff6 commit 55b6ebe
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#nullable disable

using System;
using System.Collections.Immutable;
using System.Diagnostics;

Expand All @@ -15,18 +14,17 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// For example, parameters on a property symbol are cloned to generate parameters on accessors.
/// Similarly parameters on delegate invoke method are cloned to delegate begin/end invoke methods.
/// </summary>
internal sealed class SourceClonedParameterSymbol : SourceParameterSymbolBase
internal abstract class SourceClonedParameterSymbol : SourceParameterSymbolBase
{
// if true suppresses params-array and default value:
private readonly bool _suppressOptional;

private readonly SourceParameterSymbol _originalParam;
protected readonly SourceParameterSymbol _originalParam;

internal SourceClonedParameterSymbol(SourceParameterSymbol originalParam, Symbol newOwner, int newOrdinal, bool suppressOptional)
: base(newOwner, newOrdinal)
{
Debug.Assert((object)originalParam != null);

_suppressOptional = suppressOptional;
_originalParam = originalParam;
}
Expand Down Expand Up @@ -73,15 +71,6 @@ internal override ConstantValue DefaultValueFromAttributes
get { return _originalParam.DefaultValueFromAttributes; }
}

internal override ParameterSymbol WithCustomModifiersAndParams(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams)
{
return new SourceClonedParameterSymbol(
_originalParam.WithCustomModifiersAndParamsCore(newType, newCustomModifiers, newRefCustomModifiers, newIsParams),
this.ContainingSymbol,
this.Ordinal,
_suppressOptional);
}

#region Forwarded

public override TypeWithAnnotations TypeWithAnnotations
Expand Down Expand Up @@ -139,26 +128,6 @@ internal override bool IsIUnknownConstant
get { return _originalParam.IsIUnknownConstant; }
}

internal override bool IsCallerFilePath
{
get { return _originalParam.IsCallerFilePath; }
}

internal override bool IsCallerLineNumber
{
get { return _originalParam.IsCallerLineNumber; }
}

internal override bool IsCallerMemberName
{
get { return _originalParam.IsCallerMemberName; }
}

internal override int CallerArgumentExpressionParameterIndex
{
get { return _originalParam.CallerArgumentExpressionParameterIndex; }
}

internal override FlowAnalysisAnnotations FlowAnalysisAnnotations
{
get { return FlowAnalysisAnnotations.None; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal sealed class SourceDelegateClonedParameterSymbolForBeginAndEndInvoke : SourceClonedParameterSymbol
{
internal SourceDelegateClonedParameterSymbolForBeginAndEndInvoke(SourceParameterSymbol originalParam, Symbol newOwner, int newOrdinal)
: base(originalParam, newOwner, newOrdinal, suppressOptional: true)
{
}

internal override bool IsCallerFilePath => _originalParam.IsCallerFilePath;

internal override bool IsCallerLineNumber => _originalParam.IsCallerLineNumber;

internal override bool IsCallerMemberName => _originalParam.IsCallerMemberName;

internal override int CallerArgumentExpressionParameterIndex => throw ExceptionUtilities.Unreachable;

internal override ParameterSymbol WithCustomModifiersAndParams(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams)
{
return new SourceDelegateClonedParameterSymbolForBeginAndEndInvoke(
_originalParam.WithCustomModifiersAndParamsCore(newType, newCustomModifiers, newRefCustomModifiers, newIsParams),
ContainingSymbol,
Ordinal);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ internal BeginInvokeMethod(
var parameters = ArrayBuilder<ParameterSymbol>.GetInstance();
foreach (SourceParameterSymbol p in invoke.Parameters)
{
var synthesizedParam = new SourceClonedParameterSymbol(originalParam: p, newOwner: this, newOrdinal: p.Ordinal, suppressOptional: true);
var synthesizedParam = new SourceDelegateClonedParameterSymbolForBeginAndEndInvoke(originalParam: p, newOwner: this, newOrdinal: p.Ordinal);
parameters.Add(synthesizedParam);
}

Expand Down Expand Up @@ -402,7 +402,7 @@ internal EndInvokeMethod(
{
if (p.RefKind != RefKind.None)
{
var synthesizedParam = new SourceClonedParameterSymbol(originalParam: p, newOwner: this, newOrdinal: ordinal++, suppressOptional: true);
var synthesizedParam = new SourceDelegateClonedParameterSymbolForBeginAndEndInvoke(originalParam: p, newOwner: this, newOrdinal: ordinal++);
parameters.Add(synthesizedParam);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ private ImmutableArray<ParameterSymbol> ComputeParameters(BindingDiagnosticBag d
// since the ContainingSymbol needs to be set to the accessor.
foreach (SourceParameterSymbol propertyParam in propertyParameters)
{
parameters.Add(new SourceClonedParameterSymbol(propertyParam, this, propertyParam.Ordinal, suppressOptional: false));
parameters.Add(new SourcePropertyClonedParameterSymbolForAccessors(propertyParam, this));
}

if (!isGetMethod)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Immutable;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
internal sealed class SourcePropertyClonedParameterSymbolForAccessors : SourceClonedParameterSymbol
{
internal SourcePropertyClonedParameterSymbolForAccessors(SourceParameterSymbol originalParam, Symbol newOwner)
: base(originalParam, newOwner, originalParam.Ordinal, suppressOptional: false)
{
}

internal override bool IsCallerFilePath => _originalParam.IsCallerFilePath;

internal override bool IsCallerLineNumber => _originalParam.IsCallerLineNumber;

internal override bool IsCallerMemberName => _originalParam.IsCallerMemberName;

internal override int CallerArgumentExpressionParameterIndex => _originalParam.CallerArgumentExpressionParameterIndex;

internal override ParameterSymbol WithCustomModifiersAndParams(TypeSymbol newType, ImmutableArray<CustomModifier> newCustomModifiers, ImmutableArray<CustomModifier> newRefCustomModifiers, bool newIsParams)
{
return new SourcePropertyClonedParameterSymbolForAccessors(
_originalParam.WithCustomModifiersAndParamsCore(newType, newCustomModifiers, newRefCustomModifiers, newIsParams),
this.ContainingSymbol);
}
}
}

0 comments on commit 55b6ebe

Please sign in to comment.