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)
6053SafeContext whenTrueEscape = GetValEscape(trueExpr); 6054SafeContext 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)
1358private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1515private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1522private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1526{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1527{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1528_ => SafeContext.CallingMethod 1535private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1539{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1540{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1541{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1542{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1543_ => SafeContext.ReturnOnly 1550private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1568private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1570var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1774private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess) 1781return SafeContext.CallingMethod; 1797private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1821private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2230internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2241SafeContext escapeScope = GetValEscape(data.Construction); 2262private SafeContext GetInvocationEscapeScope( 2280SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape) 2294SafeContext escapeScope = SafeContext.CallingMethod; 2314SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2344private SafeContext GetInvocationEscapeWithUpdatedRules( 2349SafeContext escapeScope = SafeContext.CallingMethod; 2370SafeContext argEscape = isArgumentRefEscape ? 2387private SafeContext GetInvocationEscapeToReceiver( 2391SafeContext escapeScope = SafeContext.CallingMethod; 2398SafeContext argEscape = isArgumentRefEscape 2476SafeContext escapeTo, 2495bool checkingReceiver, SafeContext escapeTo, 2572SafeContext escapeTo, 2625SafeContext escapeTo, 3184SafeContext escapeTo = _localScopeDepth; 3218var inferredDestinationValEscape = SafeContext.CallingMethod; 3266var toArgEscape = GetValEscape(mixableArg.Argument); 3305var inferredDestinationValEscape = SafeContext.CallingMethod; 3584private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3668internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3691internal SafeContext GetRefEscape(BoundExpression expr) 3700return SafeContext.CallingMethod; 3706return SafeContext.CallingMethod; 3723return SafeContext.CallingMethod; 3729return SafeContext.CurrentMethod; 3790return SafeContext.CallingMethod; 3802return SafeContext.CallingMethod; 3857return SafeContext.CallingMethod; 3862return SafeContext.CallingMethod; 3972internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4313internal SafeContext GetBroadestValEscape(BoundTupleExpression expr) 4315SafeContext broadest = _localScopeDepth; 4318SafeContext valEscape; 4339internal SafeContext GetValEscape(BoundExpression expr) 4348return SafeContext.CallingMethod; 4354return SafeContext.CallingMethod; 4360return SafeContext.CallingMethod; 4375return SafeContext.CallingMethod; 4383return SafeContext.CallingMethod; 4395return SafeContext.CallingMethod; 4398return SafeContext.CallingMethod; 4422return SafeContext.CurrentMethod; 4427var consEscape = GetValEscape(conditional.Consequence); 4452return SafeContext.CallingMethod; 4464return SafeContext.CallingMethod; 4511return SafeContext.CallingMethod; 4548var escape = GetInvocationEscapeScope( 4565var escape = SafeContext.CallingMethod; 4698return (range.LeftOperandOpt is { } left ? GetValEscape(left) : SafeContext.CallingMethod) 4699.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) : SafeContext.CallingMethod); 4744return SafeContext.CallingMethod; 4773private SafeContext GetCollectionExpressionSafeContext(BoundCollectionExpression expr) 4777return SafeContext.CallingMethod; 4783return SafeContext.CallingMethod; 4796? SafeContext.CallingMethod 4815var receiverScope = expr.CollectionCreation is { } collectionCreation 4818var scope = receiverScope; 4821if (TryGetCollectionExpressionElementValEscape(element, out var elementSafeContext)) 4833private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out SafeContext safeContext) 4869private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements) 4871SafeContext narrowestScope = _localScopeDepth; 4880private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr) 4882var result = SafeContext.CallingMethod; 4899private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr) 4901var result = SafeContext.CallingMethod; 4904var exprResult = GetValEscapeOfObjectMemberInitializer(expr); 4911private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr) 4913SafeContext result; 4917var rightEscape = assignment.IsRef 4942SafeContext getIndexerEscape( 4945SafeContext rightEscapeScope) 4951return SafeContext.CallingMethod; 4958return SafeContext.CallingMethod; 4979SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4989SafeContext escapeScope = escapeValue.IsRefEscape 4999SafeContext getPropertyEscape( 5001SafeContext rightEscapeScope) 5007return SafeContext.CallingMethod; 5016private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions) 5018var result = SafeContext.CallingMethod; 5032internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5125if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5383var safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand); 5804private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5819private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5844private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5860private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5887private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression) 5889SafeContext scope = SafeContext.CallingMethod; 5908SafeContext getPartsScope(BoundInterpolatedString interpolatedString) 5910SafeContext scope = SafeContext.CallingMethod; 5928private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5951bool checkParts(BoundInterpolatedString interpolatedString, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\RefSafetyAnalysis.cs (61)
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; 416SafeContext valEscapeScope = node.ExpressionOpt is { } expr 502private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 518SafeContext.CurrentMethod; 521SafeContext.CallingMethod; 529private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 531_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 552(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 590ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 600ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 669static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 674return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 724static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 728: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 737static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 741return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 904SafeContext valEscapeScope; 915valEscapeScope = SafeContext.CallingMethod; 942SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 944SafeContext valEscapeScope; 952valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 1009var escapeFrom = GetValEscape(node.InitializerExpressionOpt); 1014private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo, SafeContext initializerEscape) 1128private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1202SafeContext valEscape = nestedVariables is null 1243internal readonly SafeContext ValEscape; 1246internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1267? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1294SafeContext collectionEscape; 1355SafeContext receiverScope; 1366var safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type) 1367? SafeContext.CallingMethod 1390var elementsScope = SafeContext.CallingMethod; 1415if (TryGetCollectionExpressionElementValEscape(element, out var spreadEscape)) 1445if (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)