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);
215 references to SafeContext
Microsoft.CodeAnalysis.CSharp (215)
Binder\Binder.ValueChecks.cs (127)
1094private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1251private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1258private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1262{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1263{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1264_ => SafeContext.CallingMethod 1271private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1275{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1276{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1277{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1278{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1279_ => SafeContext.ReturnOnly 1286private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1304private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1306var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1502private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1509return SafeContext.CallingMethod; 1525private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1549private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1947internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 1949SafeContext localScopeDepth) 1959SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 1969SafeContext argEscape = GetValEscape(argument, localScopeDepth); 1987private SafeContext GetInvocationEscapeScope( 1995SafeContext localScopeDepth, 2012SafeContext getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt, SafeContext localScopeDepth, bool isRefEscape) 2026SafeContext escapeScope = SafeContext.CallingMethod; 2053SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2083private SafeContext GetInvocationEscapeWithUpdatedRules( 2091SafeContext localScopeDepth, 2095SafeContext escapeScope = SafeContext.CallingMethod; 2122SafeContext argEscape = isArgumentRefEscape ? 2201SafeContext escapeFrom, 2202SafeContext escapeTo, 2223bool checkingReceiver, SafeContext escapeFrom, SafeContext escapeTo, 2305SafeContext escapeFrom, 2306SafeContext escapeTo, 2869SafeContext localScopeDepth, 2884SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 2899SafeContext escapeTo = localScopeDepth; 2939var inferredDestinationValEscape = SafeContext.CallingMethod; 2979SafeContext localScopeDepth, 3000var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3039var inferredDestinationValEscape = SafeContext.CallingMethod; 3313private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3397internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3420internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3429return SafeContext.CallingMethod; 3435return SafeContext.CallingMethod; 3452return SafeContext.CallingMethod; 3458return SafeContext.CurrentMethod; 3515return SafeContext.CallingMethod; 3605return SafeContext.CallingMethod; 3728internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4097internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4099SafeContext broadest = localScopeDepth; 4102SafeContext valEscape; 4123internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4132return SafeContext.CallingMethod; 4138return SafeContext.CallingMethod; 4144return SafeContext.CallingMethod; 4159return SafeContext.CallingMethod; 4167return SafeContext.CallingMethod; 4179return SafeContext.CallingMethod; 4182return SafeContext.CallingMethod; 4199return SafeContext.CurrentMethod; 4204var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4229return SafeContext.CallingMethod; 4364var escape = GetInvocationEscapeScope( 4388var escape = SafeContext.CallingMethod; 4435SafeContext.CurrentMethod : 4436SafeContext.CallingMethod; 4541return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4542.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4601return SafeContext.CallingMethod; 4675private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4677SafeContext narrowestScope = localScopeDepth; 4692private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4694var result = SafeContext.CallingMethod; 4697var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4704private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4706SafeContext result; 4710var rightEscape = assignment.IsRef 4735SafeContext getIndexerEscape( 4738SafeContext rightEscapeScope) 4744return SafeContext.CallingMethod; 4751return SafeContext.CallingMethod; 4768SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4778SafeContext escapeScope = escapeValue.IsRefEscape 4788SafeContext getPropertyEscape( 4790SafeContext rightEscapeScope) 4796return SafeContext.CallingMethod; 4805private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4807var result = SafeContext.CallingMethod; 4821internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4911if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5220if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5660private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5675private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5691private bool CheckValEscape(ImmutableArray<BoundExpression> expressions, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5704private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
4772var currentScope = _localScopeDepth; 4775SafeContext whenTrueEscape = GetValEscape(trueExpr, currentScope); 4776SafeContext whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1564var leftEscape = GetRefEscape(op1, _localScopeDepth); 1565var rightEscape = GetRefEscape(op2, _localScopeDepth); 1609var leftEscape = GetValEscape(op1, _localScopeDepth);
Binder\RefSafetyAnalysis.cs (62)
62private SafeContext _localScopeDepth; 63private Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>? _localEscapeScopes; 64private Dictionary<BoundValuePlaceholderBase, SafeContext>? _placeholderScopes; 65private SafeContext _patternInputValEscape; 86_localScopeDepth = SafeContext.CurrentMethod.Wider(); 101_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope: SafeContext.CallingMethod); 136private readonly SafeContext _previousInputValEscape; 138public PatternInput(RefSafetyAnalysis analysis, SafeContext patternInputValEscape) 154private readonly ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> _placeholders; 156public PlaceholderRegion(RefSafetyAnalysis analysis, ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders) 176private (SafeContext RefEscapeScope, SafeContext ValEscapeScope) GetLocalScopes(LocalSymbol local) 182: (SafeContext.CurrentMethod, SafeContext.CallingMethod); 185private void SetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 192private void AddPlaceholderScope(BoundValuePlaceholderBase placeholder, SafeContext valEscapeScope) 199_placeholderScopes ??= new Dictionary<BoundValuePlaceholderBase, SafeContext>(); 214private SafeContext GetPlaceholderScope(BoundValuePlaceholderBase placeholder) 218return _placeholderScopes?.TryGetValue(placeholder, out var scope) == true 220: SafeContext.CallingMethod; 346var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 349SafeContext valEscapeScope = node.ExpressionOpt is { } expr 363var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 435private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 451SafeContext.CurrentMethod; 454SafeContext.CallingMethod; 462private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 464_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 485(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 523ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 533ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 605static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 610return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 656static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 660: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 669static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 673return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 703var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 734ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, 745SafeContext valEscapeScope; 753valEscapeScope = SafeContext.CallingMethod; 775valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 849var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 944var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 951private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1005var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 1018SafeContext valEscape = nestedVariables is null 1054internal readonly SafeContext ValEscape; 1057internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1078? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1105SafeContext collectionEscape; 1141var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance();
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)
Generated\BoundNodes.xml.Generated.cs (3)
500public BoundCapturedReceiverPlaceholder(SyntaxNode syntax, BoundExpression receiver, SafeContext localScopeDepth, TypeSymbol? type, bool hasErrors = false) 511public SafeContext LocalScopeDepth { get; } 516public BoundCapturedReceiverPlaceholder Update(BoundExpression receiver, SafeContext localScopeDepth, TypeSymbol? type)