6 instantiations of SafeContext
Microsoft.CodeAnalysis.CSharp (6)
Binder\SafeContext.cs (6)
41public static readonly SafeContext CallingMethod = new SafeContext(CallingMethodRaw); 47public static readonly SafeContext ReturnOnly = new SafeContext(ReturnOnlyRaw); 53public static readonly SafeContext CurrentMethod = new SafeContext(CurrentMethodRaw); 58public static readonly SafeContext Empty = new SafeContext(uint.MaxValue); 67return new SafeContext(_value + 1); 77return new SafeContext(_value - 1);
211 references to SafeContext
Microsoft.CodeAnalysis.CSharp (211)
Binder\Binder_Operators.cs (2)
6056SafeContext whenTrueEscape = GetValEscape(trueExpr); 6057SafeContext whenFalseEscape = GetValEscape(falseExpr);
Binder\Binder_Statements.cs (3)
1570var leftEscape = GetRefEscape(op1); 1571var rightEscape = GetRefEscape(op2); 1629var leftEscape = GetValEscape(op1);
Binder\Binder.ValueChecks.cs (126)
1342private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1499private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1506private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1510{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1511{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1512_ => SafeContext.CallingMethod 1519private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1523{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1524{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1525{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1526{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1527_ => SafeContext.ReturnOnly 1534private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1552private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1554var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1758private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess) 1765return SafeContext.CallingMethod; 1781private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1805private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2214internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2225SafeContext escapeScope = GetValEscape(data.Construction); 2246private SafeContext GetInvocationEscapeScope( 2264SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape) 2278SafeContext escapeScope = SafeContext.CallingMethod; 2298SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2328private SafeContext GetInvocationEscapeWithUpdatedRules( 2333SafeContext escapeScope = SafeContext.CallingMethod; 2354SafeContext argEscape = isArgumentRefEscape ? 2371private SafeContext GetInvocationEscapeToReceiver( 2375SafeContext escapeScope = SafeContext.CallingMethod; 2382SafeContext argEscape = isArgumentRefEscape 2460SafeContext escapeTo, 2479bool checkingReceiver, SafeContext escapeTo, 2556SafeContext escapeTo, 2609SafeContext escapeTo, 3168SafeContext escapeTo = _localScopeDepth; 3202var inferredDestinationValEscape = SafeContext.CallingMethod; 3250var toArgEscape = GetValEscape(mixableArg.Argument); 3289var inferredDestinationValEscape = SafeContext.CallingMethod; 3568private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3652internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3675internal SafeContext GetRefEscape(BoundExpression expr) 3684return SafeContext.CallingMethod; 3690return SafeContext.CallingMethod; 3707return SafeContext.CallingMethod; 3713return SafeContext.CurrentMethod; 3774return SafeContext.CallingMethod; 3786return SafeContext.CallingMethod; 3841return SafeContext.CallingMethod; 3846return SafeContext.CallingMethod; 3956internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4297internal SafeContext GetBroadestValEscape(BoundTupleExpression expr) 4299SafeContext broadest = _localScopeDepth; 4302SafeContext valEscape; 4323internal SafeContext GetValEscape(BoundExpression expr) 4332return SafeContext.CallingMethod; 4338return SafeContext.CallingMethod; 4344return SafeContext.CallingMethod; 4359return SafeContext.CallingMethod; 4367return SafeContext.CallingMethod; 4379return SafeContext.CallingMethod; 4382return SafeContext.CallingMethod; 4406return SafeContext.CurrentMethod; 4411var consEscape = GetValEscape(conditional.Consequence); 4436return SafeContext.CallingMethod; 4448return SafeContext.CallingMethod; 4495return SafeContext.CallingMethod; 4532var escape = GetInvocationEscapeScope( 4549var escape = SafeContext.CallingMethod; 4682return (range.LeftOperandOpt is { } left ? GetValEscape(left) : SafeContext.CallingMethod) 4683.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) : SafeContext.CallingMethod); 4728return SafeContext.CallingMethod; 4757private SafeContext GetCollectionExpressionSafeContext(BoundCollectionExpression expr) 4761return SafeContext.CallingMethod; 4767return SafeContext.CallingMethod; 4780? SafeContext.CallingMethod 4799var receiverScope = expr.CollectionCreation is { } collectionCreation 4802var scope = receiverScope; 4805if (TryGetCollectionExpressionElementValEscape(element, out var elementSafeContext)) 4817private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out SafeContext safeContext) 4853private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements) 4855SafeContext narrowestScope = _localScopeDepth; 4864private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr) 4866var result = SafeContext.CallingMethod; 4883private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr) 4885var result = SafeContext.CallingMethod; 4888var exprResult = GetValEscapeOfObjectMemberInitializer(expr); 4895private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr) 4897SafeContext result; 4901var rightEscape = assignment.IsRef 4926SafeContext getIndexerEscape( 4929SafeContext rightEscapeScope) 4935return SafeContext.CallingMethod; 4942return SafeContext.CallingMethod; 4963SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4973SafeContext escapeScope = escapeValue.IsRefEscape 4983SafeContext getPropertyEscape( 4985SafeContext rightEscapeScope) 4991return SafeContext.CallingMethod; 5000private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions) 5002var result = SafeContext.CallingMethod; 5016internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5109if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5367var safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand); 5788private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5803private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5828private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5844private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5871private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression) 5873SafeContext scope = SafeContext.CallingMethod; 5892SafeContext getPartsScope(BoundInterpolatedString interpolatedString) 5894SafeContext scope = SafeContext.CallingMethod; 5912private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5935bool checkParts(BoundInterpolatedString interpolatedString, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\RefSafetyAnalysis.cs (63)
70private SafeContext _localScopeDepth; 71private Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>? _localEscapeScopes; 73private SafeContext _patternInputValEscape; 93_localScopeDepth = SafeContext.CurrentMethod; 113_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope: SafeContext.CallingMethod); 150private readonly SafeContext _previousInputValEscape; 152public PatternInput(RefSafetyAnalysis analysis, SafeContext patternInputValEscape) 192public static SafeContextAndLocation Create(SafeContext context 205public readonly SafeContext Context; 211private SafeContextAndLocation(SafeContext context 225private (SafeContext RefEscapeScope, SafeContext ValEscapeScope) GetLocalScopes(LocalSymbol local) 231: (SafeContext.CurrentMethod, SafeContext.CallingMethod); 234private void SetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 268private SafeContext GetPlaceholderScope(BoundValuePlaceholderBase placeholder) 274: SafeContext.CallingMethod; 401var originalDepth = _localScopeDepth; 409var originalDepth = _localScopeDepth; 452SafeContext valEscapeScope = node.ExpressionOpt is { } expr 551private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 567SafeContext.CurrentMethod; 570SafeContext.CallingMethod; 578private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 580_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 601(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 639ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 649ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 718static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 723return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 773static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 777: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 786static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 790return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 953SafeContext valEscapeScope; 964valEscapeScope = SafeContext.CallingMethod; 991SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 993SafeContext valEscapeScope; 1001valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 1058var escapeFrom = GetValEscape(node.InitializerExpressionOpt); 1063private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo, SafeContext initializerEscape) 1177private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1251SafeContext valEscape = nestedVariables is null 1292internal readonly SafeContext ValEscape; 1295internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1316? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1343SafeContext collectionEscape; 1404SafeContext receiverScope; 1415var safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type) 1416? SafeContext.CallingMethod 1439var elementsScope = SafeContext.CallingMethod; 1464if (TryGetCollectionExpressionElementValEscape(element, out var spreadEscape)) 1494if (TryGetCollectionExpressionElementValEscape(element, out var elementSafeContext))
Binder\SafeContext.cs (17)
41public static readonly SafeContext CallingMethod = new SafeContext(CallingMethodRaw); 47public static readonly SafeContext ReturnOnly = new SafeContext(ReturnOnlyRaw); 53public static readonly SafeContext CurrentMethod = new SafeContext(CurrentMethodRaw); 58public static readonly SafeContext Empty = new SafeContext(uint.MaxValue); 64public SafeContext Narrower() 74public SafeContext Wider() 86public bool IsConvertibleTo(SafeContext other) 97public SafeContext Intersect(SafeContext other) 104public SafeContext Union(SafeContext other) 108public bool Equals(SafeContext other) 112=> obj is SafeContext other && this.Equals(other); 117public static bool operator ==(SafeContext lhs, SafeContext rhs) 120public static bool operator !=(SafeContext lhs, SafeContext rhs)