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.ValueChecks.cs (126)
1361private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1518private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1525private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1529{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1530{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1531_ => SafeContext.CallingMethod 1538private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1542{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1543{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1544{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1545{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1546_ => SafeContext.ReturnOnly 1553private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1571private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1573var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1777private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess) 1784return SafeContext.CallingMethod; 1800private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1824private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2232internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2243SafeContext escapeScope = GetValEscape(data.Construction); 2264private SafeContext GetInvocationEscapeScope( 2282SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape) 2296SafeContext escapeScope = SafeContext.CallingMethod; 2316SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2346private SafeContext GetInvocationEscapeWithUpdatedRules( 2351SafeContext escapeScope = SafeContext.CallingMethod; 2372SafeContext argEscape = isArgumentRefEscape ? 2389private SafeContext GetInvocationEscapeToReceiver( 2393SafeContext escapeScope = SafeContext.CallingMethod; 2400SafeContext argEscape = isArgumentRefEscape 2478SafeContext escapeTo, 2497bool checkingReceiver, SafeContext escapeTo, 2574SafeContext escapeTo, 2627SafeContext escapeTo, 3211SafeContext escapeTo = _localScopeDepth; 3245var inferredDestinationValEscape = SafeContext.CallingMethod; 3293var toArgEscape = GetValEscape(mixableArg.Argument); 3332var inferredDestinationValEscape = SafeContext.CallingMethod; 3608private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3692internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3715internal SafeContext GetRefEscape(BoundExpression expr) 3724return SafeContext.CallingMethod; 3730return SafeContext.CallingMethod; 3747return SafeContext.CallingMethod; 3753return SafeContext.CurrentMethod; 3810return SafeContext.CallingMethod; 3822return SafeContext.CallingMethod; 3877return SafeContext.CallingMethod; 3882return SafeContext.CallingMethod; 3992internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4329internal SafeContext GetBroadestValEscape(BoundTupleExpression expr) 4331SafeContext broadest = _localScopeDepth; 4334SafeContext valEscape; 4355internal SafeContext GetValEscape(BoundExpression expr) 4364return SafeContext.CallingMethod; 4370return SafeContext.CallingMethod; 4376return SafeContext.CallingMethod; 4391return SafeContext.CallingMethod; 4399return SafeContext.CallingMethod; 4411return SafeContext.CallingMethod; 4414return SafeContext.CallingMethod; 4434return SafeContext.CurrentMethod; 4439var consEscape = GetValEscape(conditional.Consequence); 4464return SafeContext.CallingMethod; 4476return SafeContext.CallingMethod; 4523return SafeContext.CallingMethod; 4560var escape = GetInvocationEscapeScope( 4577var escape = SafeContext.CallingMethod; 4710return (range.LeftOperandOpt is { } left ? GetValEscape(left) : SafeContext.CallingMethod) 4711.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) : SafeContext.CallingMethod); 4756return SafeContext.CallingMethod; 4785private SafeContext GetCollectionExpressionSafeContext(BoundCollectionExpression expr) 4789return SafeContext.CallingMethod; 4795return SafeContext.CallingMethod; 4808? SafeContext.CallingMethod 4827var receiverScope = expr.CollectionCreation is { } collectionCreation 4830var scope = receiverScope; 4833if (TryGetCollectionExpressionElementValEscape(element, out var elementSafeContext)) 4845private bool TryGetCollectionExpressionElementValEscape(BoundNode element, out SafeContext safeContext) 4881private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements) 4883SafeContext narrowestScope = _localScopeDepth; 4892private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr) 4894var result = SafeContext.CallingMethod; 4911private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr) 4913var result = SafeContext.CallingMethod; 4916var exprResult = GetValEscapeOfObjectMemberInitializer(expr); 4923private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr) 4925SafeContext result; 4929var rightEscape = assignment.IsRef 4954SafeContext getIndexerEscape( 4957SafeContext rightEscapeScope) 4963return SafeContext.CallingMethod; 4970return SafeContext.CallingMethod; 4991SafeContext receiverEscapeScope = SafeContext.CallingMethod; 5001SafeContext escapeScope = escapeValue.IsRefEscape 5011SafeContext getPropertyEscape( 5013SafeContext rightEscapeScope) 5019return SafeContext.CallingMethod; 5028private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions) 5030var result = SafeContext.CallingMethod; 5044internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5137if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5391var safeContext = GetCollectionExpressionSafeContext((BoundCollectionExpression)conversion.Operand); 5812private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5827private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5852private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5868private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5895private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression) 5897SafeContext scope = SafeContext.CallingMethod; 5916SafeContext getPartsScope(BoundInterpolatedString interpolatedString) 5918SafeContext scope = SafeContext.CallingMethod; 5936private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5959bool 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 (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; 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(). 987var escapeFrom = GetValEscape(node.InitializerExpressionOpt); 992private void VisitObjectCreationWithInitializer(BoundObjectCreationExpressionBase node, in MethodInvocationInfo methodInvocationInfo, SafeContext initializerEscape) 1093private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1167SafeContext valEscape = nestedVariables is null 1208internal readonly SafeContext ValEscape; 1211internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1232? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1259SafeContext collectionEscape; 1320SafeContext receiverScope; 1331var safeContext = node.Elements.Length == 0 || LocalRewriter.ShouldUseRuntimeHelpersCreateSpan(node, elementType.Type) 1332? SafeContext.CallingMethod 1355var elementsScope = SafeContext.CallingMethod; 1380if (TryGetCollectionExpressionElementValEscape(element, out var spreadEscape)) 1410if (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)