-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57135 from RikkiGibson/delegate-type-args
Support 'ref' type arguments in delegates
- Loading branch information
Showing
17 changed files
with
635 additions
and
4 deletions.
There are no files selected for viewing
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
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
157 changes: 157 additions & 0 deletions
157
src/Compilers/CSharp/Portable/Emitter/Model/RefTypeSymbolAdapter.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,157 @@ | ||
// 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. | ||
|
||
#nullable disable | ||
|
||
using System.Collections.Immutable; | ||
using System.Reflection.Metadata; | ||
using Microsoft.CodeAnalysis.CSharp.Emit; | ||
using Microsoft.CodeAnalysis.Emit; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
{ | ||
internal partial class | ||
#if DEBUG | ||
RefTypeSymbolAdapter : SymbolAdapter, | ||
#else | ||
RefTypeSymbol : | ||
#endif | ||
Cci.IRefTypeReference | ||
{ | ||
Cci.ITypeReference Cci.IRefTypeReference.GetReferencedType(EmitContext context) | ||
{ | ||
var type = ((PEModuleBuilder)context.Module).Translate(AdaptedRefTypeSymbol.ReferencedTypeWithAnnotations.Type, syntaxNodeOpt: (CSharpSyntaxNode)context.SyntaxNode, diagnostics: context.Diagnostics); | ||
|
||
if (AdaptedRefTypeSymbol.ReferencedTypeWithAnnotations.CustomModifiers.Length == 0) | ||
{ | ||
return type; | ||
} | ||
else | ||
{ | ||
return new Cci.ModifiedTypeReference(type, ImmutableArray<Cci.ICustomModifier>.CastUp(AdaptedRefTypeSymbol.ReferencedTypeWithAnnotations.CustomModifiers)); | ||
} | ||
} | ||
|
||
bool Cci.ITypeReference.IsEnum | ||
{ | ||
get { return false; } | ||
} | ||
|
||
bool Cci.ITypeReference.IsValueType | ||
{ | ||
get { return false; } | ||
} | ||
|
||
Cci.ITypeDefinition Cci.ITypeReference.GetResolvedType(EmitContext context) | ||
{ | ||
return null; | ||
} | ||
|
||
Cci.PrimitiveTypeCode Cci.ITypeReference.TypeCode | ||
{ | ||
get { return Cci.PrimitiveTypeCode.Reference; } | ||
} | ||
|
||
TypeDefinitionHandle Cci.ITypeReference.TypeDef | ||
{ | ||
get { return default(TypeDefinitionHandle); } | ||
} | ||
|
||
Cci.IGenericMethodParameterReference Cci.ITypeReference.AsGenericMethodParameterReference | ||
{ | ||
get { return null; } | ||
} | ||
|
||
Cci.IGenericTypeInstanceReference Cci.ITypeReference.AsGenericTypeInstanceReference | ||
{ | ||
get { return null; } | ||
} | ||
|
||
Cci.IGenericTypeParameterReference Cci.ITypeReference.AsGenericTypeParameterReference | ||
{ | ||
get { return null; } | ||
} | ||
|
||
Cci.INamespaceTypeDefinition Cci.ITypeReference.AsNamespaceTypeDefinition(EmitContext context) | ||
{ | ||
return null; | ||
} | ||
|
||
Cci.INamespaceTypeReference Cci.ITypeReference.AsNamespaceTypeReference | ||
{ | ||
get { return null; } | ||
} | ||
|
||
Cci.INestedTypeDefinition Cci.ITypeReference.AsNestedTypeDefinition(EmitContext context) | ||
{ | ||
return null; | ||
} | ||
|
||
Cci.INestedTypeReference Cci.ITypeReference.AsNestedTypeReference | ||
{ | ||
get { return null; } | ||
} | ||
|
||
Cci.ISpecializedNestedTypeReference Cci.ITypeReference.AsSpecializedNestedTypeReference | ||
{ | ||
get { return null; } | ||
} | ||
|
||
Cci.ITypeDefinition Cci.ITypeReference.AsTypeDefinition(EmitContext context) | ||
{ | ||
return null; | ||
} | ||
|
||
void Cci.IReference.Dispatch(Cci.MetadataVisitor visitor) | ||
{ | ||
visitor.Visit((Cci.IPointerTypeReference)this); | ||
} | ||
|
||
Cci.IDefinition Cci.IReference.AsDefinition(EmitContext context) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
internal partial class RefTypeSymbol | ||
{ | ||
|
||
#if DEBUG | ||
private RefTypeSymbolAdapter _lazyAdapter; | ||
|
||
protected sealed override SymbolAdapter GetCciAdapterImpl() => GetCciAdapter(); | ||
|
||
internal new RefTypeSymbolAdapter GetCciAdapter() | ||
{ | ||
if (_lazyAdapter is null) | ||
{ | ||
return InterlockedOperations.Initialize(ref _lazyAdapter, new RefTypeSymbolAdapter(this)); | ||
} | ||
|
||
return _lazyAdapter; | ||
} | ||
#else | ||
internal RefTypeSymbol AdaptedRefTypeSymbol => this; | ||
|
||
internal new RefTypeSymbol GetCciAdapter() | ||
{ | ||
return this; | ||
} | ||
#endif | ||
} | ||
|
||
#if DEBUG | ||
internal partial class RefTypeSymbolAdapter | ||
{ | ||
internal RefTypeSymbolAdapter(RefTypeSymbol underlyingRefTypeSymbol) | ||
{ | ||
AdaptedRefTypeSymbol = underlyingRefTypeSymbol; | ||
} | ||
|
||
internal sealed override Symbol AdaptedSymbol => AdaptedRefTypeSymbol; | ||
internal RefTypeSymbol AdaptedRefTypeSymbol { get; } | ||
} | ||
#endif | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/Compilers/CSharp/Portable/Symbols/PublicModel/RefTypeSymbol.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,34 @@ | ||
// 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.Diagnostics; | ||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel | ||
{ | ||
// PROTOTYPE(delegate-type-arg): public model? | ||
// internal sealed class RefTypeSymbol : TypeSymbol | ||
// { | ||
// private readonly Symbols.RefTypeSymbol _underlying; | ||
|
||
// internal override Symbols.TypeSymbol UnderlyingTypeSymbol => _underlying; | ||
// internal override Symbols.NamespaceOrTypeSymbol UnderlyingNamespaceOrTypeSymbol => _underlying; | ||
// internal override CSharp.Symbol UnderlyingSymbol => _underlying; | ||
|
||
// protected override void Accept(SymbolVisitor visitor) | ||
// { | ||
// _underlying.ReferencedTypeWithAnnotations.Accept | ||
// } | ||
|
||
// protected override TResult Accept<TResult>(SymbolVisitor<TResult> visitor) | ||
// { | ||
// throw new System.NotImplementedException(); | ||
// } | ||
|
||
// protected override ITypeSymbol WithNullableAnnotation(CodeAnalysis.NullableAnnotation nullableAnnotation) | ||
// { | ||
// throw new System.NotImplementedException(); | ||
// } | ||
// } | ||
} |
Oops, something went wrong.