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);
209 references to SafeContext
Microsoft.CodeAnalysis.CSharp (209)
Binder\Binder_Operators.cs (2)
6032SafeContext whenTrueEscape = GetValEscape(trueExpr); 6033SafeContext 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)
1357private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1514private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1521private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1525{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1526{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1527_ => SafeContext.CallingMethod 1534private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1538{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1539{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1540{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1541{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1542_ => SafeContext.ReturnOnly 1549private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1567private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1569var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1773private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess) 1780return SafeContext.CallingMethod; 1796private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1820private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2229internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2240SafeContext escapeScope = GetValEscape(data.Construction); 2261private SafeContext GetInvocationEscapeScope( 2279SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape) 2293SafeContext escapeScope = SafeContext.CallingMethod; 2313SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2343private SafeContext GetInvocationEscapeWithUpdatedRules( 2348SafeContext escapeScope = SafeContext.CallingMethod; 2369SafeContext argEscape = isArgumentRefEscape ? 2386private SafeContext GetInvocationEscapeToReceiver( 2390SafeContext escapeScope = SafeContext.CallingMethod; 2397SafeContext argEscape = isArgumentRefEscape 2475SafeContext escapeTo, 2494bool checkingReceiver, SafeContext escapeTo, 2571SafeContext escapeTo, 2624SafeContext escapeTo, 3183SafeContext escapeTo = _localScopeDepth; 3217var inferredDestinationValEscape = SafeContext.CallingMethod; 3265var toArgEscape = GetValEscape(mixableArg.Argument); 3304var inferredDestinationValEscape = SafeContext.CallingMethod; 3583private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3667internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3690internal SafeContext GetRefEscape(BoundExpression expr) 3699return SafeContext.CallingMethod; 3705return SafeContext.CallingMethod; 3722return SafeContext.CallingMethod; 3728return SafeContext.CurrentMethod; 3789return SafeContext.CallingMethod; 3801return SafeContext.CallingMethod; 3856return SafeContext.CallingMethod; 3861return SafeContext.CallingMethod; 3971internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4312internal SafeContext GetBroadestValEscape(BoundTupleExpression expr) 4314SafeContext broadest = _localScopeDepth; 4317SafeContext valEscape; 4338internal SafeContext GetValEscape(BoundExpression expr) 4347return SafeContext.CallingMethod; 4353return SafeContext.CallingMethod; 4359return SafeContext.CallingMethod; 4374return SafeContext.CallingMethod; 4382return SafeContext.CallingMethod; 4394return SafeContext.CallingMethod; 4397return SafeContext.CallingMethod; 4421return SafeContext.CurrentMethod; 4426var consEscape = GetValEscape(conditional.Consequence); 4451return SafeContext.CallingMethod; 4463return SafeContext.CallingMethod; 4510return SafeContext.CallingMethod; 4547var escape = GetInvocationEscapeScope( 4564var escape = SafeContext.CallingMethod; 4697return (range.LeftOperandOpt is { } left ? GetValEscape(left) : SafeContext.CallingMethod) 4698.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) : SafeContext.CallingMethod); 4743return SafeContext.CallingMethod; 4772private SafeContext GetCollectionExpressionSafeContext(BoundCollectionExpression expr) 4776return SafeContext.CallingMethod; 4782return SafeContext.CallingMethod; 4795? SafeContext.CallingMethod 4814var receiverScope = expr.CollectionCreation is { } collectionCreation 4817var scope = receiverScope; 4820if (TryGetCollectionExpressionElementValEscape(element, out var elementSafeContext)) 4832private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out SafeContext safeContext) 4868private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements) 4870SafeContext narrowestScope = _localScopeDepth; 4879private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr) 4881var result = SafeContext.CallingMethod; 4898private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr) 4900var result = SafeContext.CallingMethod; 4903var exprResult = GetValEscapeOfObjectMemberInitializer(expr); 4910private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr) 4912SafeContext result; 4916var rightEscape = assignment.IsRef 4941SafeContext getIndexerEscape( 4944SafeContext rightEscapeScope) 4950return SafeContext.CallingMethod; 4957return SafeContext.CallingMethod; 4978SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4988SafeContext escapeScope = escapeValue.IsRefEscape 4998SafeContext getPropertyEscape( 5000SafeContext rightEscapeScope) 5006return SafeContext.CallingMethod; 5015private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions) 5017var result = SafeContext.CallingMethod; 5031internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5124if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5382var safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand); 5803private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5818private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5843private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5859private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5886private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression) 5888SafeContext scope = SafeContext.CallingMethod; 5907SafeContext getPartsScope(BoundInterpolatedString interpolatedString) 5909SafeContext scope = SafeContext.CallingMethod; 5927private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5950bool checkParts(BoundInterpolatedString interpolatedString, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\RefSafetyAnalysis.cs (61)
65private SafeContext _localScopeDepth; 66private Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>? _localEscapeScopes; 68private SafeContext _patternInputValEscape; 88_localScopeDepth = SafeContext.CurrentMethod; 108_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope: SafeContext.CallingMethod); 145private readonly SafeContext _previousInputValEscape; 147public PatternInput(RefSafetyAnalysis analysis, SafeContext patternInputValEscape) 187public static SafeContextAndLocation Create(SafeContext context 200public readonly SafeContext Context; 206private SafeContextAndLocation(SafeContext context 220private (SafeContext RefEscapeScope, SafeContext ValEscapeScope) GetLocalScopes(LocalSymbol local) 226: (SafeContext.CurrentMethod, SafeContext.CallingMethod); 229private void SetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 263private SafeContext GetPlaceholderScope(BoundValuePlaceholderBase placeholder) 269: SafeContext.CallingMethod; 411SafeContext valEscapeScope = node.ExpressionOpt is { } expr 497private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 513SafeContext.CurrentMethod; 516SafeContext.CallingMethod; 524private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 526_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 547(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 585ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 595ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 664static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 669return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 719static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 723: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 732static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 736return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 899SafeContext valEscapeScope; 910valEscapeScope = SafeContext.CallingMethod; 937SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 939SafeContext valEscapeScope; 947valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 1004var escapeFrom = GetValEscape(node.InitializerExpressionOpt); 1009private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo, SafeContext initializerEscape) 1123private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1197SafeContext valEscape = nestedVariables is null 1238internal readonly SafeContext ValEscape; 1241internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1262? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1289SafeContext collectionEscape; 1350SafeContext receiverScope; 1361var safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type) 1362? SafeContext.CallingMethod 1385var elementsScope = SafeContext.CallingMethod; 1410if (TryGetCollectionExpressionElementValEscape(element, out var spreadEscape)) 1440if (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)