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);
210 references to SafeContext
Microsoft.CodeAnalysis.CSharp (210)
Binder\Binder.ValueChecks.cs (122)
1064private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1221private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1228private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1232{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1233{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1234_ => SafeContext.CallingMethod 1241private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1245{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1246{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1247{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1248{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1249_ => SafeContext.ReturnOnly 1256private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1274private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1276var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1472private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1479return SafeContext.CallingMethod; 1495private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1519private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1917internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 1919SafeContext localScopeDepth) 1929SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 1939SafeContext argEscape = GetValEscape(argument, localScopeDepth); 1957private SafeContext GetInvocationEscapeScope( 1965SafeContext localScopeDepth, 1990SafeContext escapeScope = SafeContext.CallingMethod; 2017SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2046private SafeContext GetInvocationEscapeWithUpdatedRules( 2054SafeContext localScopeDepth, 2058SafeContext escapeScope = SafeContext.CallingMethod; 2085SafeContext argEscape = isArgumentRefEscape ? 2120SafeContext escapeFrom, 2121SafeContext escapeTo, 2213SafeContext escapeFrom, 2214SafeContext escapeTo, 2777SafeContext localScopeDepth, 2798SafeContext escapeTo = localScopeDepth; 2838var inferredDestinationValEscape = SafeContext.CallingMethod; 2877SafeContext localScopeDepth, 2897var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 2936var inferredDestinationValEscape = SafeContext.CallingMethod; 3210private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3294internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3317internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3326return SafeContext.CallingMethod; 3332return SafeContext.CallingMethod; 3349return SafeContext.CallingMethod; 3355return SafeContext.CurrentMethod; 3412return SafeContext.CallingMethod; 3502return SafeContext.CallingMethod; 3625internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 3994internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 3996SafeContext broadest = localScopeDepth; 3999SafeContext valEscape; 4020internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4029return SafeContext.CallingMethod; 4035return SafeContext.CallingMethod; 4041return SafeContext.CallingMethod; 4056return SafeContext.CallingMethod; 4064return SafeContext.CallingMethod; 4076return SafeContext.CallingMethod; 4079return SafeContext.CallingMethod; 4096return SafeContext.CurrentMethod; 4101var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4126return SafeContext.CallingMethod; 4261var escape = GetInvocationEscapeScope( 4285var escape = SafeContext.CallingMethod; 4332SafeContext.CurrentMethod : 4333SafeContext.CallingMethod; 4429return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4430.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4489return SafeContext.CallingMethod; 4563private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4565SafeContext narrowestScope = localScopeDepth; 4580private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4582var result = SafeContext.CallingMethod; 4585var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4592private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4594SafeContext result; 4598var rightEscape = assignment.IsRef 4623SafeContext getIndexerEscape( 4626SafeContext rightEscapeScope) 4632return SafeContext.CallingMethod; 4639return SafeContext.CallingMethod; 4656SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4666SafeContext escapeScope = escapeValue.IsRefEscape 4676SafeContext getPropertyEscape( 4678SafeContext rightEscapeScope) 4684return SafeContext.CallingMethod; 4693private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4695var result = SafeContext.CallingMethod; 4709internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4799if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5108if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5541private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5556private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5572private bool CheckValEscape(ImmutableArray<BoundExpression> expressions, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5585private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
4382var currentScope = _localScopeDepth; 4385SafeContext whenTrueEscape = GetValEscape(trueExpr, currentScope); 4386SafeContext whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1552var leftEscape = GetRefEscape(op1, _localScopeDepth); 1553var rightEscape = GetRefEscape(op2, _localScopeDepth); 1597var 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); 570static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 575return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 621static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 625: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 634static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 638return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 668var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 699ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, 710SafeContext valEscapeScope; 718valEscapeScope = SafeContext.CallingMethod; 740valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 814var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 909var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 916private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 970var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 983SafeContext valEscape = nestedVariables is null 1019internal readonly SafeContext ValEscape; 1022internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1043? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1070SafeContext collectionEscape; 1106var 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)