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);
215 references to SafeContext
Microsoft.CodeAnalysis.CSharp (215)
Binder\Binder.ValueChecks.cs (127)
1090
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1247
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1254
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1258
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1259
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1260
_ =>
SafeContext
.CallingMethod
1267
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1271
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1272
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1273
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1274
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1275
_ =>
SafeContext
.ReturnOnly
1282
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1300
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1302
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1506
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess,
SafeContext
localScopeDepth)
1513
return
SafeContext
.CallingMethod;
1529
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1553
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1951
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
1953
SafeContext
localScopeDepth)
1963
SafeContext
escapeScope = GetValEscape(data.Construction, localScopeDepth);
1973
SafeContext
argEscape = GetValEscape(argument, localScopeDepth);
1991
private
SafeContext
GetInvocationEscapeScope(
1999
SafeContext
localScopeDepth,
2016
SafeContext
getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt,
SafeContext
localScopeDepth, bool isRefEscape)
2030
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2057
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2087
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2095
SafeContext
localScopeDepth,
2099
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2126
SafeContext
argEscape = isArgumentRefEscape ?
2205
SafeContext
escapeFrom,
2206
SafeContext
escapeTo,
2227
bool checkingReceiver,
SafeContext
escapeFrom,
SafeContext
escapeTo,
2309
SafeContext
escapeFrom,
2310
SafeContext
escapeTo,
2873
SafeContext
localScopeDepth,
2888
SafeContext
localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting)
2903
SafeContext
escapeTo = localScopeDepth;
2943
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
2983
SafeContext
localScopeDepth,
3004
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
3043
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3317
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3401
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3424
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3433
return
SafeContext
.CallingMethod;
3439
return
SafeContext
.CallingMethod;
3456
return
SafeContext
.CallingMethod;
3462
return
SafeContext
.CurrentMethod;
3519
return
SafeContext
.CallingMethod;
3609
return
SafeContext
.CallingMethod;
3732
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4101
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
4103
SafeContext
broadest = localScopeDepth;
4106
SafeContext
valEscape;
4127
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4136
return
SafeContext
.CallingMethod;
4142
return
SafeContext
.CallingMethod;
4148
return
SafeContext
.CallingMethod;
4163
return
SafeContext
.CallingMethod;
4171
return
SafeContext
.CallingMethod;
4183
return
SafeContext
.CallingMethod;
4186
return
SafeContext
.CallingMethod;
4203
return
SafeContext
.CurrentMethod;
4208
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4233
return
SafeContext
.CallingMethod;
4368
var
escape = GetInvocationEscapeScope(
4392
var
escape =
SafeContext
.CallingMethod;
4439
SafeContext
.CurrentMethod :
4440
SafeContext
.CallingMethod;
4545
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4546
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4605
return
SafeContext
.CallingMethod;
4679
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4681
SafeContext
narrowestScope = localScopeDepth;
4696
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4698
var
result =
SafeContext
.CallingMethod;
4701
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4708
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4710
SafeContext
result;
4714
var
rightEscape = assignment.IsRef
4739
SafeContext
getIndexerEscape(
4742
SafeContext
rightEscapeScope)
4748
return
SafeContext
.CallingMethod;
4755
return
SafeContext
.CallingMethod;
4772
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4782
SafeContext
escapeScope = escapeValue.IsRefEscape
4792
SafeContext
getPropertyEscape(
4794
SafeContext
rightEscapeScope)
4800
return
SafeContext
.CallingMethod;
4809
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4811
var
result =
SafeContext
.CallingMethod;
4825
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4915
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5224
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5664
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5679
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5695
private bool CheckValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5708
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
4818
var
currentScope = _localScopeDepth;
4821
SafeContext
whenTrueEscape = GetValEscape(trueExpr, currentScope);
4822
SafeContext
whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1564
var
leftEscape = GetRefEscape(op1, _localScopeDepth);
1565
var
rightEscape = GetRefEscape(op2, _localScopeDepth);
1609
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);
605
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
610
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
660
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
664
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
673
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
677
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
707
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
738
ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders,
749
SafeContext
valEscapeScope;
757
valEscapeScope =
SafeContext
.CallingMethod;
779
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
853
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth);
948
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
955
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1009
var placeholders = ArrayBuilder<(BoundValuePlaceholderBase,
SafeContext
)>.GetInstance();
1022
SafeContext
valEscape = nestedVariables is null
1058
internal readonly
SafeContext
ValEscape;
1061
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1082
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1109
SafeContext
collectionEscape;
1145
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)