6 instantiations of SafeContext
Microsoft.CodeAnalysis.CSharp (6)
Binder\SafeContext.cs (6)
41
public static readonly SafeContext CallingMethod = new
SafeContext
(CallingMethodRaw);
47
public static readonly SafeContext ReturnOnly = new
SafeContext
(ReturnOnlyRaw);
53
public static readonly SafeContext CurrentMethod = new
SafeContext
(CurrentMethodRaw);
58
public static readonly SafeContext Empty = new
SafeContext
(uint.MaxValue);
67
return new
SafeContext
(_value + 1);
77
return new
SafeContext
(_value - 1);
210 references to SafeContext
Microsoft.CodeAnalysis.CSharp (210)
Binder\Binder.ValueChecks.cs (122)
1064
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1221
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1228
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1232
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1233
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1234
_ =>
SafeContext
.CallingMethod
1241
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1245
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1246
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1247
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1248
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1249
_ =>
SafeContext
.ReturnOnly
1256
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1274
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1276
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1472
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess,
SafeContext
localScopeDepth)
1479
return
SafeContext
.CallingMethod;
1495
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1519
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1917
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
1919
SafeContext
localScopeDepth)
1929
SafeContext
escapeScope = GetValEscape(data.Construction, localScopeDepth);
1939
SafeContext
argEscape = GetValEscape(argument, localScopeDepth);
1957
private
SafeContext
GetInvocationEscapeScope(
1965
SafeContext
localScopeDepth,
1990
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2017
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2046
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2054
SafeContext
localScopeDepth,
2058
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2085
SafeContext
argEscape = isArgumentRefEscape ?
2120
SafeContext
escapeFrom,
2121
SafeContext
escapeTo,
2213
SafeContext
escapeFrom,
2214
SafeContext
escapeTo,
2777
SafeContext
localScopeDepth,
2798
SafeContext
escapeTo = localScopeDepth;
2838
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
2877
SafeContext
localScopeDepth,
2897
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
2936
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3210
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3294
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3317
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3326
return
SafeContext
.CallingMethod;
3332
return
SafeContext
.CallingMethod;
3349
return
SafeContext
.CallingMethod;
3355
return
SafeContext
.CurrentMethod;
3412
return
SafeContext
.CallingMethod;
3502
return
SafeContext
.CallingMethod;
3625
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
3994
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
3996
SafeContext
broadest = localScopeDepth;
3999
SafeContext
valEscape;
4020
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4029
return
SafeContext
.CallingMethod;
4035
return
SafeContext
.CallingMethod;
4041
return
SafeContext
.CallingMethod;
4056
return
SafeContext
.CallingMethod;
4064
return
SafeContext
.CallingMethod;
4076
return
SafeContext
.CallingMethod;
4079
return
SafeContext
.CallingMethod;
4096
return
SafeContext
.CurrentMethod;
4101
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4126
return
SafeContext
.CallingMethod;
4261
var
escape = GetInvocationEscapeScope(
4285
var
escape =
SafeContext
.CallingMethod;
4332
SafeContext
.CurrentMethod :
4333
SafeContext
.CallingMethod;
4429
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4430
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4489
return
SafeContext
.CallingMethod;
4563
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4565
SafeContext
narrowestScope = localScopeDepth;
4580
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4582
var
result =
SafeContext
.CallingMethod;
4585
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4592
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4594
SafeContext
result;
4598
var
rightEscape = assignment.IsRef
4623
SafeContext
getIndexerEscape(
4626
SafeContext
rightEscapeScope)
4632
return
SafeContext
.CallingMethod;
4639
return
SafeContext
.CallingMethod;
4656
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4666
SafeContext
escapeScope = escapeValue.IsRefEscape
4676
SafeContext
getPropertyEscape(
4678
SafeContext
rightEscapeScope)
4684
return
SafeContext
.CallingMethod;
4693
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4695
var
result =
SafeContext
.CallingMethod;
4709
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4799
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5108
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5541
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5556
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5572
private bool CheckValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5585
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
4382
var
currentScope = _localScopeDepth;
4385
SafeContext
whenTrueEscape = GetValEscape(trueExpr, currentScope);
4386
SafeContext
whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1552
var
leftEscape = GetRefEscape(op1, _localScopeDepth);
1553
var
rightEscape = GetRefEscape(op2, _localScopeDepth);
1597
var
leftEscape = GetValEscape(op1, _localScopeDepth);
Binder\RefSafetyAnalysis.cs (62)
62
private
SafeContext
_localScopeDepth;
63
private Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>? _localEscapeScopes;
64
private Dictionary<BoundValuePlaceholderBase,
SafeContext
>? _placeholderScopes;
65
private
SafeContext
_patternInputValEscape;
86
_localScopeDepth =
SafeContext
.CurrentMethod.Wider();
101
_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope:
SafeContext
.CallingMethod);
136
private readonly
SafeContext
_previousInputValEscape;
138
public PatternInput(RefSafetyAnalysis analysis,
SafeContext
patternInputValEscape)
154
private readonly ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> _placeholders;
156
public PlaceholderRegion(RefSafetyAnalysis analysis, ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders)
176
private (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope) GetLocalScopes(LocalSymbol local)
182
: (
SafeContext
.CurrentMethod,
SafeContext
.CallingMethod);
185
private void SetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
192
private void AddPlaceholderScope(BoundValuePlaceholderBase placeholder,
SafeContext
valEscapeScope)
199
_placeholderScopes ??= new Dictionary<BoundValuePlaceholderBase,
SafeContext
>();
214
private
SafeContext
GetPlaceholderScope(BoundValuePlaceholderBase placeholder)
218
return _placeholderScopes?.TryGetValue(placeholder, out
var
scope) == true
220
:
SafeContext
.CallingMethod;
346
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
349
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
363
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
435
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
451
SafeContext
.CurrentMethod;
454
SafeContext
.CallingMethod;
462
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
464
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
485
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
523
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
533
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
570
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
575
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
621
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
625
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
634
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
638
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
668
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
699
ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders,
710
SafeContext
valEscapeScope;
718
valEscapeScope =
SafeContext
.CallingMethod;
740
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
814
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth);
909
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
916
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
970
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
983
SafeContext
valEscape = nestedVariables is null
1019
internal readonly
SafeContext
ValEscape;
1022
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1043
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1070
SafeContext
collectionEscape;
1106
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
Binder\SafeContext.cs (17)
41
public static readonly
SafeContext
CallingMethod = new SafeContext(CallingMethodRaw);
47
public static readonly
SafeContext
ReturnOnly = new SafeContext(ReturnOnlyRaw);
53
public static readonly
SafeContext
CurrentMethod = new SafeContext(CurrentMethodRaw);
58
public static readonly
SafeContext
Empty = new SafeContext(uint.MaxValue);
64
public
SafeContext
Narrower()
74
public
SafeContext
Wider()
86
public bool IsConvertibleTo(
SafeContext
other)
97
public
SafeContext
Intersect(
SafeContext
other)
104
public
SafeContext
Union(
SafeContext
other)
108
public bool Equals(
SafeContext
other)
112
=> obj is
SafeContext
other && this.Equals(other);
117
public static bool operator ==(
SafeContext
lhs,
SafeContext
rhs)
120
public static bool operator !=(
SafeContext
lhs,
SafeContext
rhs)
Generated\BoundNodes.xml.Generated.cs (3)
500
public BoundCapturedReceiverPlaceholder(SyntaxNode syntax, BoundExpression receiver,
SafeContext
localScopeDepth, TypeSymbol? type, bool hasErrors = false)
511
public
SafeContext
LocalScopeDepth { get; }
516
public BoundCapturedReceiverPlaceholder Update(BoundExpression receiver,
SafeContext
localScopeDepth, TypeSymbol? type)