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)
1311
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1468
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1475
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1479
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1480
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1481
_ =>
SafeContext
.CallingMethod
1488
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1492
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1493
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1494
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1495
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1496
_ =>
SafeContext
.ReturnOnly
1503
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1521
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1523
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1727
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess,
SafeContext
localScopeDepth)
1734
return
SafeContext
.CallingMethod;
1750
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1774
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
2172
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
2174
SafeContext
localScopeDepth)
2184
SafeContext
escapeScope = GetValEscape(data.Construction, localScopeDepth);
2205
private
SafeContext
GetInvocationEscapeScope(
2207
SafeContext
localScopeDepth,
2224
SafeContext
getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo,
SafeContext
localScopeDepth, bool isRefEscape)
2238
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2258
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2288
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2290
SafeContext
localScopeDepth,
2294
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2315
SafeContext
argEscape = isArgumentRefEscape ?
2332
private
SafeContext
GetInvocationEscapeToReceiver(
2334
SafeContext
localScopeDepth)
2337
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2344
SafeContext
argEscape = isArgumentRefEscape
2422
SafeContext
escapeFrom,
2423
SafeContext
escapeTo,
2442
bool checkingReceiver,
SafeContext
escapeFrom,
SafeContext
escapeTo,
2519
SafeContext
escapeFrom,
2520
SafeContext
escapeTo,
2573
SafeContext
escapeFrom,
2574
SafeContext
escapeTo,
3132
SafeContext
localScopeDepth,
3144
SafeContext
localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting)
3160
SafeContext
escapeTo = localScopeDepth;
3194
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3228
SafeContext
localScopeDepth,
3243
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
3278
void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt,
SafeContext
localScopeDepth, ArrayBuilder<EscapeValue> escapeValues)
3282
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3558
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3642
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3665
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3674
return
SafeContext
.CallingMethod;
3680
return
SafeContext
.CallingMethod;
3697
return
SafeContext
.CallingMethod;
3703
return
SafeContext
.CurrentMethod;
3760
return
SafeContext
.CallingMethod;
3772
return
SafeContext
.CallingMethod;
3831
return
SafeContext
.CallingMethod;
3836
return
SafeContext
.CallingMethod;
3948
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4292
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
4294
SafeContext
broadest = localScopeDepth;
4297
SafeContext
valEscape;
4318
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4327
return
SafeContext
.CallingMethod;
4333
return
SafeContext
.CallingMethod;
4339
return
SafeContext
.CallingMethod;
4354
return
SafeContext
.CallingMethod;
4362
return
SafeContext
.CallingMethod;
4374
return
SafeContext
.CallingMethod;
4377
return
SafeContext
.CallingMethod;
4394
return
SafeContext
.CurrentMethod;
4399
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4424
return
SafeContext
.CallingMethod;
4436
return
SafeContext
.CallingMethod;
4487
return
SafeContext
.CallingMethod;
4527
var
escape = GetInvocationEscapeScope(
4545
var
escape =
SafeContext
.CallingMethod;
4586
SafeContext
.CurrentMethod :
4587
SafeContext
.CallingMethod;
4687
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4688
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4737
return
SafeContext
.CallingMethod;
4815
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4817
SafeContext
narrowestScope = localScopeDepth;
4826
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
localScopeDepth)
4828
var
result =
SafeContext
.CallingMethod;
4846
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4848
var
result =
SafeContext
.CallingMethod;
4851
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4858
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4860
SafeContext
result;
4864
var
rightEscape = assignment.IsRef
4889
SafeContext
getIndexerEscape(
4892
SafeContext
rightEscapeScope)
4898
return
SafeContext
.CallingMethod;
4905
return
SafeContext
.CallingMethod;
4926
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4936
SafeContext
escapeScope = escapeValue.IsRefEscape
4946
SafeContext
getPropertyEscape(
4948
SafeContext
rightEscapeScope)
4954
return
SafeContext
.CallingMethod;
4963
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4965
var
result =
SafeContext
.CallingMethod;
4979
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5069
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5334
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5758
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5773
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5799
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5815
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5842
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
localScopeDepth)
5844
SafeContext
scope =
SafeContext
.CallingMethod;
5863
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString,
SafeContext
localScopeDepth)
5865
SafeContext
scope =
SafeContext
.CallingMethod;
5884
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5907
bool checkParts(BoundInterpolatedString interpolatedString,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
5804
var
currentScope = _localScopeDepth;
5807
SafeContext
whenTrueEscape = GetValEscape(trueExpr, currentScope);
5808
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)