-
Notifications
You must be signed in to change notification settings - Fork 4k
/
RefKind.cs
88 lines (77 loc) · 2.88 KB
/
RefKind.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
/// <summary>
/// Denotes the kind of reference.
/// </summary>
public enum RefKind : byte
{
/// <summary>
/// Indicates a "value" parameter or return type.
/// </summary>
None = 0,
/// <summary>
/// Indicates a "ref" parameter or return type.
/// </summary>
Ref = 1,
/// <summary>
/// Indicates an "out" parameter.
/// </summary>
Out = 2,
/// <summary>
/// Indicates an "in" parameter.
/// </summary>
In = 3,
/// <summary>
/// Indicates a "ref readonly" return type.
/// </summary>
RefReadOnly = 3,
// NOTE: There is an additional value of this enum type - RefKindExtensions.StrictIn == RefKind.In + 1
// It is used internally during lowering.
// Consider that when adding values or changing this enum in some other way.
}
internal static class RefKindExtensions
{
internal static string ToParameterDisplayString(this RefKind kind)
{
switch (kind)
{
case RefKind.Out: return "out";
case RefKind.Ref: return "ref";
case RefKind.In: return "in";
default: throw ExceptionUtilities.UnexpectedValue(kind);
}
}
internal static string ToArgumentDisplayString(this RefKind kind)
{
switch (kind)
{
case RefKind.Out: return "out";
case RefKind.Ref: return "ref";
case RefKind.In: return "in";
default: throw ExceptionUtilities.UnexpectedValue(kind);
}
}
internal static string ToParameterPrefix(this RefKind kind)
{
switch (kind)
{
case RefKind.Out: return "out ";
case RefKind.Ref: return "ref ";
case RefKind.In: return "in ";
case RefKind.None: return string.Empty;
default: throw ExceptionUtilities.UnexpectedValue(kind);
}
}
// Used internally to track `In` arguments that were specified with `In` modifier
// as opposed to those that were specified with no modifiers and matched `In` parameter.
// There is at least one kind of analysis that cares about this distinction - hoisting
// of variables to the frame for async rewriting: a variable that was passed without the
// `In` modifier may be correctly captured by value or by reference.
internal const RefKind StrictIn = RefKind.In + 1;
}
}