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);
216 references to SafeContext
Microsoft.CodeAnalysis.CSharp (216)
Binder\Binder.ValueChecks.cs (128)
1090private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1247private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1254private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1258{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1259{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1260_ => SafeContext.CallingMethod 1267private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1271{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1272{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1273{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1274{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1275_ => SafeContext.ReturnOnly 1282private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1300private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1302var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1506private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1513return SafeContext.CallingMethod; 1529private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1553private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1951internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 1953SafeContext localScopeDepth) 1963SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 1973SafeContext argEscape = GetValEscape(argument, localScopeDepth); 1991private SafeContext GetInvocationEscapeScope( 1999SafeContext localScopeDepth, 2016SafeContext getInvocationEscapeWithOldRules(MethodInfo methodInfo, ImmutableArray<ParameterSymbol> parameters, BoundExpression? receiver, ImmutableArray<BoundExpression> argsOpt, ImmutableArray<RefKind> argRefKindsOpt, ImmutableArray<int> argsToParamsOpt, SafeContext localScopeDepth, bool isRefEscape) 2030SafeContext escapeScope = SafeContext.CallingMethod; 2057SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2087private SafeContext GetInvocationEscapeWithUpdatedRules( 2095SafeContext localScopeDepth, 2099SafeContext escapeScope = SafeContext.CallingMethod; 2126SafeContext argEscape = isArgumentRefEscape ? 2205SafeContext escapeFrom, 2206SafeContext escapeTo, 2227bool checkingReceiver, SafeContext escapeFrom, SafeContext escapeTo, 2309SafeContext escapeFrom, 2310SafeContext escapeTo, 2873SafeContext localScopeDepth, 2888SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 2903SafeContext escapeTo = localScopeDepth; 2943var inferredDestinationValEscape = SafeContext.CallingMethod; 2983SafeContext localScopeDepth, 3004var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3039void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt, SafeContext localScopeDepth, ArrayBuilder<EscapeValue> escapeValues) 3043var inferredDestinationValEscape = SafeContext.CallingMethod; 3317private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3401internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3424internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3433return SafeContext.CallingMethod; 3439return SafeContext.CallingMethod; 3456return SafeContext.CallingMethod; 3462return SafeContext.CurrentMethod; 3519return SafeContext.CallingMethod; 3609return SafeContext.CallingMethod; 3739internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4115internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4117SafeContext broadest = localScopeDepth; 4120SafeContext valEscape; 4141internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4150return SafeContext.CallingMethod; 4156return SafeContext.CallingMethod; 4162return SafeContext.CallingMethod; 4177return SafeContext.CallingMethod; 4185return SafeContext.CallingMethod; 4197return SafeContext.CallingMethod; 4200return SafeContext.CallingMethod; 4217return SafeContext.CurrentMethod; 4222var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4247return SafeContext.CallingMethod; 4382var escape = GetInvocationEscapeScope( 4406var escape = SafeContext.CallingMethod; 4453SafeContext.CurrentMethod : 4454SafeContext.CallingMethod; 4584return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4585.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4644return SafeContext.CallingMethod; 4718private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4720SafeContext narrowestScope = localScopeDepth; 4735private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4737var result = SafeContext.CallingMethod; 4740var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4747private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4749SafeContext result; 4753var rightEscape = assignment.IsRef 4778SafeContext getIndexerEscape( 4781SafeContext rightEscapeScope) 4787return SafeContext.CallingMethod; 4794return SafeContext.CallingMethod; 4811SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4821SafeContext escapeScope = escapeValue.IsRefEscape 4831SafeContext getPropertyEscape( 4833SafeContext rightEscapeScope) 4839return SafeContext.CallingMethod; 4848private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4850var result = SafeContext.CallingMethod; 4864internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4954if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5263if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5731private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5746private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5762private bool CheckValEscape(ImmutableArray<BoundExpression> expressions, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5775private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
5804var currentScope = _localScopeDepth; 5807SafeContext whenTrueEscape = GetValEscape(trueExpr, currentScope); 5808SafeContext 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; 660static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 664: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 673static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 677return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 707var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 738ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, 749SafeContext valEscapeScope; 757valEscapeScope = SafeContext.CallingMethod; 779valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 853var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 948var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 955private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1009var placeholders = ArrayBuilder<(BoundValuePlaceholderBase, SafeContext)>.GetInstance(); 1022SafeContext valEscape = nestedVariables is null 1058internal readonly SafeContext ValEscape; 1061internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1082? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1109SafeContext collectionEscape; 1145var 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)
481public BoundCapturedReceiverPlaceholder(SyntaxNode syntax, BoundExpression receiver, SafeContext localScopeDepth, TypeSymbol? type, bool hasErrors = false) 492public SafeContext LocalScopeDepth { get; } 497public BoundCapturedReceiverPlaceholder Update(BoundExpression receiver, SafeContext localScopeDepth, TypeSymbol? type)