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);
233 references to SafeContext
Microsoft.CodeAnalysis.CSharp (233)
Binder\Binder.ValueChecks.cs (154)
1313
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1470
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1477
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1481
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1482
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1483
_ =>
SafeContext
.CallingMethod
1490
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1494
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1495
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1496
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1497
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1498
_ =>
SafeContext
.ReturnOnly
1505
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1523
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1525
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1729
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess,
SafeContext
localScopeDepth)
1736
return
SafeContext
.CallingMethod;
1752
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1776
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
2174
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
2176
SafeContext
localScopeDepth)
2186
SafeContext
escapeScope = GetValEscape(data.Construction, localScopeDepth);
2207
private
SafeContext
GetInvocationEscapeScope(
2209
SafeContext
localScopeDepth,
2226
SafeContext
getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo,
SafeContext
localScopeDepth, bool isRefEscape)
2240
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2260
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2290
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2292
SafeContext
localScopeDepth,
2296
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2317
SafeContext
argEscape = isArgumentRefEscape ?
2334
private
SafeContext
GetInvocationEscapeToReceiver(
2336
SafeContext
localScopeDepth)
2339
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2346
SafeContext
argEscape = isArgumentRefEscape
2424
SafeContext
escapeFrom,
2425
SafeContext
escapeTo,
2444
bool checkingReceiver,
SafeContext
escapeFrom,
SafeContext
escapeTo,
2521
SafeContext
escapeFrom,
2522
SafeContext
escapeTo,
2575
SafeContext
escapeFrom,
2576
SafeContext
escapeTo,
3134
SafeContext
localScopeDepth,
3146
SafeContext
localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting)
3162
SafeContext
escapeTo = localScopeDepth;
3196
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3230
SafeContext
localScopeDepth,
3245
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
3280
void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt,
SafeContext
localScopeDepth, ArrayBuilder<EscapeValue> escapeValues)
3284
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3560
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3644
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3667
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3676
return
SafeContext
.CallingMethod;
3682
return
SafeContext
.CallingMethod;
3699
return
SafeContext
.CallingMethod;
3705
return
SafeContext
.CurrentMethod;
3762
return
SafeContext
.CallingMethod;
3774
return
SafeContext
.CallingMethod;
3833
return
SafeContext
.CallingMethod;
3838
return
SafeContext
.CallingMethod;
3950
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4294
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
4296
SafeContext
broadest = localScopeDepth;
4299
SafeContext
valEscape;
4320
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4329
return
SafeContext
.CallingMethod;
4335
return
SafeContext
.CallingMethod;
4341
return
SafeContext
.CallingMethod;
4356
return
SafeContext
.CallingMethod;
4364
return
SafeContext
.CallingMethod;
4376
return
SafeContext
.CallingMethod;
4379
return
SafeContext
.CallingMethod;
4396
return
SafeContext
.CurrentMethod;
4401
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4426
return
SafeContext
.CallingMethod;
4438
return
SafeContext
.CallingMethod;
4489
return
SafeContext
.CallingMethod;
4529
var
escape = GetInvocationEscapeScope(
4547
var
escape =
SafeContext
.CallingMethod;
4588
SafeContext
.CurrentMethod :
4589
SafeContext
.CallingMethod;
4689
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4690
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4739
return
SafeContext
.CallingMethod;
4817
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4819
SafeContext
narrowestScope = localScopeDepth;
4828
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
localScopeDepth)
4830
var
result =
SafeContext
.CallingMethod;
4848
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4850
var
result =
SafeContext
.CallingMethod;
4853
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4860
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4862
SafeContext
result;
4866
var
rightEscape = assignment.IsRef
4891
SafeContext
getIndexerEscape(
4894
SafeContext
rightEscapeScope)
4900
return
SafeContext
.CallingMethod;
4907
return
SafeContext
.CallingMethod;
4928
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4938
SafeContext
escapeScope = escapeValue.IsRefEscape
4948
SafeContext
getPropertyEscape(
4950
SafeContext
rightEscapeScope)
4956
return
SafeContext
.CallingMethod;
4965
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4967
var
result =
SafeContext
.CallingMethod;
4981
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5071
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5336
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5760
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5775
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5801
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5817
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5844
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
localScopeDepth)
5846
SafeContext
scope =
SafeContext
.CallingMethod;
5865
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString,
SafeContext
localScopeDepth)
5867
SafeContext
scope =
SafeContext
.CallingMethod;
5886
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5909
bool checkParts(BoundInterpolatedString interpolatedString,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
5836
var
currentScope = _localScopeDepth;
5839
SafeContext
whenTrueEscape = GetValEscape(trueExpr, currentScope);
5840
SafeContext
whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1564
var
leftEscape = GetRefEscape(op1, _localScopeDepth);
1565
var
rightEscape = GetRefEscape(op2, _localScopeDepth);
1624
var
leftEscape = GetValEscape(op1, _localScopeDepth);
Binder\RefSafetyAnalysis.cs (53)
63
private
SafeContext
_localScopeDepth;
64
private Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>? _localEscapeScopes;
66
private
SafeContext
_patternInputValEscape;
87
_localScopeDepth =
SafeContext
.CurrentMethod.Wider();
102
_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope:
SafeContext
.CallingMethod);
137
private readonly
SafeContext
_previousInputValEscape;
139
public PatternInput(RefSafetyAnalysis analysis,
SafeContext
patternInputValEscape)
179
public static SafeContextAndLocation Create(
SafeContext
context
192
public readonly
SafeContext
Context;
198
private SafeContextAndLocation(
SafeContext
context
212
private (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope) GetLocalScopes(LocalSymbol local)
218
: (
SafeContext
.CurrentMethod,
SafeContext
.CallingMethod);
221
private void SetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
255
private
SafeContext
GetPlaceholderScope(BoundValuePlaceholderBase placeholder)
261
:
SafeContext
.CallingMethod;
390
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
476
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
492
SafeContext
.CurrentMethod;
495
SafeContext
.CallingMethod;
503
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
505
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
526
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
564
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
574
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
629
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
634
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
684
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
688
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
697
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
701
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
864
SafeContext
valEscapeScope;
875
valEscapeScope =
SafeContext
.CallingMethod;
902
SafeContext
getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex)
904
SafeContext
valEscapeScope;
912
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
985
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth);
1071
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1145
SafeContext
valEscape = nestedVariables is null
1187
internal readonly
SafeContext
ValEscape;
1190
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1211
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1238
SafeContext
collectionEscape;
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)
481
public BoundCapturedReceiverPlaceholder(SyntaxNode syntax, BoundExpression receiver,
SafeContext
localScopeDepth, TypeSymbol? type, bool hasErrors = false)
492
public
SafeContext
LocalScopeDepth { get; }
497
public BoundCapturedReceiverPlaceholder Update(BoundExpression receiver,
SafeContext
localScopeDepth, TypeSymbol? type)