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)
1094
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1251
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1258
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1262
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1263
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1264
_ =>
SafeContext
.CallingMethod
1271
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1275
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1276
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1277
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1278
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1279
_ =>
SafeContext
.ReturnOnly
1286
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1304
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1306
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1502
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess,
SafeContext
localScopeDepth)
1509
return
SafeContext
.CallingMethod;
1525
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1549
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1947
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
1949
SafeContext
localScopeDepth)
1959
SafeContext
escapeScope = GetValEscape(data.Construction, localScopeDepth);
1969
SafeContext
argEscape = GetValEscape(argument, localScopeDepth);
1987
private
SafeContext
GetInvocationEscapeScope(
1995
SafeContext
localScopeDepth,
2012
SafeContext
getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt,
SafeContext
localScopeDepth, bool isRefEscape)
2026
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2053
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2083
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2091
SafeContext
localScopeDepth,
2095
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2122
SafeContext
argEscape = isArgumentRefEscape ?
2201
SafeContext
escapeFrom,
2202
SafeContext
escapeTo,
2223
bool checkingReceiver,
SafeContext
escapeFrom,
SafeContext
escapeTo,
2305
SafeContext
escapeFrom,
2306
SafeContext
escapeTo,
2869
SafeContext
localScopeDepth,
2884
SafeContext
localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting)
2899
SafeContext
escapeTo = localScopeDepth;
2939
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
2979
SafeContext
localScopeDepth,
3000
var
toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth);
3039
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3313
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3397
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3420
internal
SafeContext
GetRefEscape(BoundExpression expr,
SafeContext
localScopeDepth)
3429
return
SafeContext
.CallingMethod;
3435
return
SafeContext
.CallingMethod;
3452
return
SafeContext
.CallingMethod;
3458
return
SafeContext
.CurrentMethod;
3515
return
SafeContext
.CallingMethod;
3605
return
SafeContext
.CallingMethod;
3728
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4097
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr,
SafeContext
localScopeDepth)
4099
SafeContext
broadest = localScopeDepth;
4102
SafeContext
valEscape;
4123
internal
SafeContext
GetValEscape(BoundExpression expr,
SafeContext
localScopeDepth)
4132
return
SafeContext
.CallingMethod;
4138
return
SafeContext
.CallingMethod;
4144
return
SafeContext
.CallingMethod;
4159
return
SafeContext
.CallingMethod;
4167
return
SafeContext
.CallingMethod;
4179
return
SafeContext
.CallingMethod;
4182
return
SafeContext
.CallingMethod;
4199
return
SafeContext
.CurrentMethod;
4204
var
consEscape = GetValEscape(conditional.Consequence, localScopeDepth);
4229
return
SafeContext
.CallingMethod;
4364
var
escape = GetInvocationEscapeScope(
4388
var
escape =
SafeContext
.CallingMethod;
4435
SafeContext
.CurrentMethod :
4436
SafeContext
.CallingMethod;
4532
return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) :
SafeContext
.CallingMethod)
4533
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) :
SafeContext
.CallingMethod);
4592
return
SafeContext
.CallingMethod;
4666
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
localScopeDepth)
4668
SafeContext
narrowestScope = localScopeDepth;
4683
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
localScopeDepth)
4685
var
result =
SafeContext
.CallingMethod;
4688
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth);
4695
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr,
SafeContext
localScopeDepth)
4697
SafeContext
result;
4701
var
rightEscape = assignment.IsRef
4726
SafeContext
getIndexerEscape(
4729
SafeContext
rightEscapeScope)
4735
return
SafeContext
.CallingMethod;
4742
return
SafeContext
.CallingMethod;
4759
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4769
SafeContext
escapeScope = escapeValue.IsRefEscape
4779
SafeContext
getPropertyEscape(
4781
SafeContext
rightEscapeScope)
4787
return
SafeContext
.CallingMethod;
4796
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
localScopeDepth)
4798
var
result =
SafeContext
.CallingMethod;
4812
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeFrom,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4902
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5211
if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5644
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5659
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5675
private bool CheckValEscape(ImmutableArray<BoundExpression> expressions,
SafeContext
escapeFrom,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5688
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)
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);
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)