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);
199 references to SafeContext
Microsoft.CodeAnalysis.CSharp (199)
Binder\Binder.ValueChecks.cs (122)
1360private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1517private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1524private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1528{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1529{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1530_ => SafeContext.CallingMethod 1537private 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 1552private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1570private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1572var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1776private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess) 1783return SafeContext.CallingMethod; 1799private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1823private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2231internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2242SafeContext escapeScope = GetValEscape(data.Construction); 2263private SafeContext GetInvocationEscapeScope( 2281SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape) 2295SafeContext escapeScope = SafeContext.CallingMethod; 2315SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2345private SafeContext GetInvocationEscapeWithUpdatedRules( 2350SafeContext escapeScope = SafeContext.CallingMethod; 2371SafeContext argEscape = isArgumentRefEscape ? 2388private SafeContext GetInvocationEscapeToReceiver( 2392SafeContext escapeScope = SafeContext.CallingMethod; 2399SafeContext argEscape = isArgumentRefEscape 2477SafeContext escapeTo, 2496bool checkingReceiver, SafeContext escapeTo, 2573SafeContext escapeTo, 2626SafeContext escapeTo, 3210SafeContext escapeTo = _localScopeDepth; 3244var inferredDestinationValEscape = SafeContext.CallingMethod; 3292var toArgEscape = GetValEscape(mixableArg.Argument); 3331var inferredDestinationValEscape = SafeContext.CallingMethod; 3607private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3691internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3714internal SafeContext GetRefEscape(BoundExpression expr) 3723return SafeContext.CallingMethod; 3729return SafeContext.CallingMethod; 3746return SafeContext.CallingMethod; 3752return SafeContext.CurrentMethod; 3809return SafeContext.CallingMethod; 3821return SafeContext.CallingMethod; 3876return SafeContext.CallingMethod; 3881return SafeContext.CallingMethod; 3991internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4328internal SafeContext GetBroadestValEscape(BoundTupleExpression expr) 4330SafeContext broadest = _localScopeDepth; 4333SafeContext valEscape; 4354internal SafeContext GetValEscape(BoundExpression expr) 4363return SafeContext.CallingMethod; 4369return SafeContext.CallingMethod; 4375return SafeContext.CallingMethod; 4390return SafeContext.CallingMethod; 4398return SafeContext.CallingMethod; 4410return SafeContext.CallingMethod; 4413return SafeContext.CallingMethod; 4432return SafeContext.CurrentMethod; 4437var consEscape = GetValEscape(conditional.Consequence); 4462return SafeContext.CallingMethod; 4474return SafeContext.CallingMethod; 4521return SafeContext.CallingMethod; 4558var escape = GetInvocationEscapeScope( 4575var escape = SafeContext.CallingMethod; 4708return (range.LeftOperandOpt is { } left ? GetValEscape(left) : SafeContext.CallingMethod) 4709.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) : SafeContext.CallingMethod); 4757return SafeContext.CallingMethod; 4786private SafeContext GetCollectionExpressionSafeContext(BoundCollectionExpression expr) 4790return SafeContext.CallingMethod; 4796return SafeContext.CallingMethod; 4809? SafeContext.CallingMethod 4843private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements) 4845SafeContext narrowestScope = _localScopeDepth; 4854private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr) 4856var result = SafeContext.CallingMethod; 4873private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr) 4875var result = SafeContext.CallingMethod; 4878var exprResult = GetValEscapeOfObjectMemberInitializer(expr); 4885private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr) 4887SafeContext result; 4891var rightEscape = assignment.IsRef 4916SafeContext getIndexerEscape( 4919SafeContext rightEscapeScope) 4925return SafeContext.CallingMethod; 4932return SafeContext.CallingMethod; 4953SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4963SafeContext escapeScope = escapeValue.IsRefEscape 4973SafeContext getPropertyEscape( 4975SafeContext rightEscapeScope) 4981return SafeContext.CallingMethod; 4990private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions) 4992var result = SafeContext.CallingMethod; 5006internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5098if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5352var safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand); 5773private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5788private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5813private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5829private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5856private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression) 5858SafeContext scope = SafeContext.CallingMethod; 5877SafeContext getPartsScope(BoundInterpolatedString interpolatedString) 5879SafeContext scope = SafeContext.CallingMethod; 5897private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5920bool checkParts(BoundInterpolatedString interpolatedString, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (2)
6029SafeContext whenTrueEscape = GetValEscape(trueExpr); 6030SafeContext whenFalseEscape = GetValEscape(falseExpr);
Binder\Binder_Statements.cs (3)
1570var leftEscape = GetRefEscape(op1); 1571var rightEscape = GetRefEscape(op2); 1630var leftEscape = GetValEscape(op1);
Binder\RefSafetyAnalysis.cs (55)
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; 410SafeContext valEscapeScope = node.ExpressionOpt is { } expr 496private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 512SafeContext.CurrentMethod; 515SafeContext.CallingMethod; 523private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 525_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 546(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 584ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 594ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 648static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 653return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 703static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 707: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 716static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 720return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 882SafeContext valEscapeScope; 893valEscapeScope = SafeContext.CallingMethod; 920SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 922SafeContext valEscapeScope; 930valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 1002var escapeFrom = GetValEscape(node.InitializerExpressionOpt); 1086private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1160SafeContext valEscape = nestedVariables is null 1201internal readonly SafeContext ValEscape; 1204internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1225? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1252SafeContext collectionEscape; 1322var safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type) 1323? SafeContext.CallingMethod
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)