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);
199 references to SafeContext
Microsoft.CodeAnalysis.CSharp (199)
Binder\Binder.ValueChecks.cs (122)
1360
private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1517
private static EscapeLevel? EscapeLevelFromScope(
SafeContext
lifetime) => lifetime switch
1524
private static
SafeContext
GetParameterValEscape(ParameterSymbol parameter)
1528
{ EffectiveScope: ScopedKind.ScopedValue } =>
SafeContext
.CurrentMethod,
1529
{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } =>
SafeContext
.ReturnOnly,
1530
_ =>
SafeContext
.CallingMethod
1537
private static
SafeContext
GetParameterRefEscape(ParameterSymbol parameter)
1541
{ RefKind: RefKind.None } =>
SafeContext
.CurrentMethod,
1542
{ EffectiveScope: ScopedKind.ScopedRef } =>
SafeContext
.CurrentMethod,
1543
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } =>
SafeContext
.ReturnOnly,
1544
{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } =>
SafeContext
.CallingMethod,
1545
_ =>
SafeContext
.ReturnOnly
1552
private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1570
private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
1572
var
refSafeToEscape = GetParameterRefEscape(parameterSymbol);
1776
private
SafeContext
GetFieldRefEscape(BoundFieldAccess fieldAccess)
1783
return
SafeContext
.CallingMethod;
1799
private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
1823
private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
2221
internal
SafeContext
GetInterpolatedStringHandlerConversionEscapeScope(
2232
SafeContext
escapeScope = GetValEscape(data.Construction);
2253
private
SafeContext
GetInvocationEscapeScope(
2271
SafeContext
getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape)
2285
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2305
SafeContext
argumentEscape = (isRefEscape, argumentIsRefEscape) switch
2335
private
SafeContext
GetInvocationEscapeWithUpdatedRules(
2340
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2361
SafeContext
argEscape = isArgumentRefEscape ?
2378
private
SafeContext
GetInvocationEscapeToReceiver(
2382
SafeContext
escapeScope =
SafeContext
.CallingMethod;
2389
SafeContext
argEscape = isArgumentRefEscape
2467
SafeContext
escapeTo,
2486
bool checkingReceiver,
SafeContext
escapeTo,
2563
SafeContext
escapeTo,
2616
SafeContext
escapeTo,
3200
SafeContext
escapeTo = _localScopeDepth;
3234
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3282
var
toArgEscape = GetValEscape(mixableArg.Argument);
3321
var
inferredDestinationValEscape =
SafeContext
.CallingMethod;
3597
private static ErrorCode GetStandardRValueRefEscapeError(
SafeContext
escapeTo)
3681
internal void ValidateEscape(BoundExpression expr,
SafeContext
escapeTo, bool isByRef, BindingDiagnosticBag diagnostics)
3704
internal
SafeContext
GetRefEscape(BoundExpression expr)
3713
return
SafeContext
.CallingMethod;
3719
return
SafeContext
.CallingMethod;
3736
return
SafeContext
.CallingMethod;
3742
return
SafeContext
.CurrentMethod;
3799
return
SafeContext
.CallingMethod;
3811
return
SafeContext
.CallingMethod;
3866
return
SafeContext
.CallingMethod;
3871
return
SafeContext
.CallingMethod;
3981
internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
4318
internal
SafeContext
GetBroadestValEscape(BoundTupleExpression expr)
4320
SafeContext
broadest = _localScopeDepth;
4323
SafeContext
valEscape;
4344
internal
SafeContext
GetValEscape(BoundExpression expr)
4353
return
SafeContext
.CallingMethod;
4359
return
SafeContext
.CallingMethod;
4365
return
SafeContext
.CallingMethod;
4380
return
SafeContext
.CallingMethod;
4388
return
SafeContext
.CallingMethod;
4400
return
SafeContext
.CallingMethod;
4403
return
SafeContext
.CallingMethod;
4422
return
SafeContext
.CurrentMethod;
4427
var
consEscape = GetValEscape(conditional.Consequence);
4452
return
SafeContext
.CallingMethod;
4464
return
SafeContext
.CallingMethod;
4511
return
SafeContext
.CallingMethod;
4548
var
escape = GetInvocationEscapeScope(
4565
var
escape =
SafeContext
.CallingMethod;
4698
return (range.LeftOperandOpt is { } left ? GetValEscape(left) :
SafeContext
.CallingMethod)
4699
.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) :
SafeContext
.CallingMethod);
4747
return
SafeContext
.CallingMethod;
4776
private
SafeContext
GetCollectionExpressionSafeContext(BoundCollectionExpression expr)
4780
return
SafeContext
.CallingMethod;
4786
return
SafeContext
.CallingMethod;
4799
?
SafeContext
.CallingMethod
4833
private
SafeContext
GetTupleValEscape(ImmutableArray<BoundExpression> elements)
4835
SafeContext
narrowestScope = _localScopeDepth;
4844
private
SafeContext
GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr)
4846
var
result =
SafeContext
.CallingMethod;
4863
private
SafeContext
GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr)
4865
var
result =
SafeContext
.CallingMethod;
4868
var
exprResult = GetValEscapeOfObjectMemberInitializer(expr);
4875
private
SafeContext
GetValEscapeOfObjectMemberInitializer(BoundExpression expr)
4877
SafeContext
result;
4881
var
rightEscape = assignment.IsRef
4906
SafeContext
getIndexerEscape(
4909
SafeContext
rightEscapeScope)
4915
return
SafeContext
.CallingMethod;
4922
return
SafeContext
.CallingMethod;
4943
SafeContext
receiverEscapeScope =
SafeContext
.CallingMethod;
4953
SafeContext
escapeScope = escapeValue.IsRefEscape
4963
SafeContext
getPropertyEscape(
4965
SafeContext
rightEscapeScope)
4971
return
SafeContext
.CallingMethod;
4980
private
SafeContext
GetValEscape(ImmutableArray<BoundExpression> expressions)
4982
var
result =
SafeContext
.CallingMethod;
4996
internal bool CheckValEscape(SyntaxNode node, BoundExpression expr,
SafeContext
escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics)
5088
if (!
SafeContext
.CurrentMethod.IsConvertibleTo(escapeTo))
5342
var
safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand);
5763
private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5778
private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5803
private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5819
private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5846
private
SafeContext
GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression)
5848
SafeContext
scope =
SafeContext
.CallingMethod;
5867
SafeContext
getPartsScope(BoundInterpolatedString interpolatedString)
5869
SafeContext
scope =
SafeContext
.CallingMethod;
5887
private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
5910
bool checkParts(BoundInterpolatedString interpolatedString,
SafeContext
escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (2)
5980
SafeContext
whenTrueEscape = GetValEscape(trueExpr);
5981
SafeContext
whenFalseEscape = GetValEscape(falseExpr);
Binder\Binder_Statements.cs (3)
1570
var
leftEscape = GetRefEscape(op1);
1571
var
rightEscape = GetRefEscape(op2);
1630
var
leftEscape = GetValEscape(op1);
Binder\RefSafetyAnalysis.cs (55)
65
private
SafeContext
_localScopeDepth;
66
private Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>? _localEscapeScopes;
68
private
SafeContext
_patternInputValEscape;
88
_localScopeDepth =
SafeContext
.CurrentMethod;
108
_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope:
SafeContext
.CallingMethod);
145
private readonly
SafeContext
_previousInputValEscape;
147
public PatternInput(RefSafetyAnalysis analysis,
SafeContext
patternInputValEscape)
187
public static SafeContextAndLocation Create(
SafeContext
context
200
public readonly
SafeContext
Context;
206
private SafeContextAndLocation(
SafeContext
context
220
private (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope) GetLocalScopes(LocalSymbol local)
226
: (
SafeContext
.CurrentMethod,
SafeContext
.CallingMethod);
229
private void SetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
263
private
SafeContext
GetPlaceholderScope(BoundValuePlaceholderBase placeholder)
269
:
SafeContext
.CallingMethod;
410
SafeContext
valEscapeScope = node.ExpressionOpt is { } expr
496
private void AddLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
512
SafeContext
.CurrentMethod;
515
SafeContext
.CallingMethod;
523
private void AddOrSetLocalScopes(LocalSymbol local,
SafeContext
refEscapeScope,
SafeContext
valEscapeScope)
525
_localEscapeScopes ??= new Dictionary<LocalSymbol, (
SafeContext
RefEscapeScope,
SafeContext
ValEscapeScope)>();
546
(
SafeContext
refEscapeScope,
SafeContext
valEscapeScope) = GetLocalScopes(localSymbol);
584
ValidateEscape(expr,
SafeContext
.ReturnOnly, node.RefKind != RefKind.None, _diagnostics);
594
ValidateEscape(expr,
SafeContext
.ReturnOnly, isByRef: false, _diagnostics);
648
static
SafeContext
getDeclarationValEscape(BoundTypeExpression typeExpression,
SafeContext
valEscape)
653
return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
703
static
SafeContext
getPositionalValEscape(Symbol? symbol,
SafeContext
valEscape)
707
: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
716
static
SafeContext
getMemberValEscape(BoundPropertySubpatternMember? member,
SafeContext
valEscape)
720
return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape :
SafeContext
.CallingMethod;
882
SafeContext
valEscapeScope;
893
valEscapeScope =
SafeContext
.CallingMethod;
920
SafeContext
getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex)
922
SafeContext
valEscapeScope;
930
valEscapeScope =
SafeContext
.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope().
1002
var
escapeFrom = GetValEscape(node.InitializerExpressionOpt);
1086
private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo,
SafeContext
valEscapeScope)
1160
SafeContext
valEscape = nestedVariables is null
1201
internal readonly
SafeContext
ValEscape;
1204
internal DeconstructionVariable(BoundExpression expression,
SafeContext
valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables)
1225
? new DeconstructionVariable(expr, valEscape:
SafeContext
.Empty, GetDeconstructionAssignmentVariables(tuple))
1252
SafeContext
collectionEscape;
1322
var
safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type)
1323
?
SafeContext
.CallingMethod
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)