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);
229 references to SafeContext
Microsoft.CodeAnalysis.CSharp (229)
Binder\Binder.ValueChecks.cs (150)
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,
3126
SafeContext
localScopeDepth,
3138
SafeContext
localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting)
3154
SafeContext
escapeTo = localScopeDepth;
3188
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3222
SafeContext
localScopeDepth,
3237
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
3272
void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt,
SafeContext
localScopeDepth, ArrayBuilder<EscapeValue> escapeValues)
3276
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3552
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3636
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3659
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3668
return
SafeContext
.CallingMethod;
3674
return
SafeContext
.CallingMethod;
3691
return
SafeContext
.CallingMethod;
3697
return
SafeContext
.CurrentMethod;
3754
return
SafeContext
.CallingMethod;
3820
return
SafeContext
.CallingMethod;
3932
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4266
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
4268
SafeContext
broadest = localScopeDepth;
4271
SafeContext
valEscape;
4292
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4301
return
SafeContext
.CallingMethod;
4307
return
SafeContext
.CallingMethod;
4313
return
SafeContext
.CallingMethod;
4328
return
SafeContext
.CallingMethod;
4336
return
SafeContext
.CallingMethod;
4348
return
SafeContext
.CallingMethod;
4351
return
SafeContext
.CallingMethod;
4368
return
SafeContext
.CurrentMethod;
4373
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4398
return
SafeContext
.CallingMethod;
4491
var
escape = GetInvocationEscapeScope(
4509
var
escape =
SafeContext
.CallingMethod;
4550
SafeContext
.CurrentMethod :
4551
SafeContext
.CallingMethod;
4651
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4652
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4701
return
SafeContext
.CallingMethod;
4779
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4781
SafeContext
narrowestScope = localScopeDepth;
4790
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
localScopeDepth)
4792
var
result =
SafeContext
.CallingMethod;
4810
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4812
var
result =
SafeContext
.CallingMethod;
4815
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4822
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4824
SafeContext
result;
4828
var
rightEscape = assignment.IsRef
4853
SafeContext
getIndexerEscape(
4856
SafeContext
rightEscapeScope)
4862
return
SafeContext
.CallingMethod;
4869
return
SafeContext
.CallingMethod;
4890
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4900
SafeContext
escapeScope = escapeValue.IsRefEscape
4910
SafeContext
getPropertyEscape(
4912
SafeContext
rightEscapeScope)
4918
return
SafeContext
.CallingMethod;
4927
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4929
var
result =
SafeContext
.CallingMethod;
4943
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5033
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5288
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5712
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5727
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5753
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5769
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5796
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
localScopeDepth)
5798
SafeContext
scope =
SafeContext
.CallingMethod;
5817
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString,
SafeContext
localScopeDepth)
5819
SafeContext
scope =
SafeContext
.CallingMethod;
5838
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5861
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;
835
SafeContext
valEscapeScope;
846
valEscapeScope =
SafeContext
.CallingMethod;
873
SafeContext
getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex)
875
SafeContext
valEscapeScope;
883
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
956
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth);
1042
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1116
SafeContext
valEscape = nestedVariables is null
1147
internal readonly
SafeContext
ValEscape;
1150
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1171
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1198
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)