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);
233 references to SafeContext
Microsoft.CodeAnalysis.CSharp (233)
Binder\Binder.ValueChecks.cs (154)
1313private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1470private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1477private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1481{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1482{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1483_ => SafeContext.CallingMethod 1490private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1494{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1495{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1496{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1497{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1498_ => SafeContext.ReturnOnly 1505private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1523private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1525var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1729private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1736return SafeContext.CallingMethod; 1752private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1776private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2174internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2176SafeContext localScopeDepth) 2186SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 2207private SafeContext GetInvocationEscapeScope( 2209SafeContext localScopeDepth, 2226SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, SafeContext localScopeDepth, bool isRefEscape) 2240SafeContext escapeScope = SafeContext.CallingMethod; 2260SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2290private SafeContext GetInvocationEscapeWithUpdatedRules( 2292SafeContext localScopeDepth, 2296SafeContext escapeScope = SafeContext.CallingMethod; 2317SafeContext argEscape = isArgumentRefEscape ? 2334private SafeContext GetInvocationEscapeToReceiver( 2336SafeContext localScopeDepth) 2339SafeContext escapeScope = SafeContext.CallingMethod; 2346SafeContext argEscape = isArgumentRefEscape 2424SafeContext escapeFrom, 2425SafeContext escapeTo, 2444bool checkingReceiver, SafeContext escapeFrom, SafeContext escapeTo, 2521SafeContext escapeFrom, 2522SafeContext escapeTo, 2575SafeContext escapeFrom, 2576SafeContext escapeTo, 3134SafeContext localScopeDepth, 3146SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 3162SafeContext escapeTo = localScopeDepth; 3196var inferredDestinationValEscape = SafeContext.CallingMethod; 3230SafeContext localScopeDepth, 3245var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3280void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt, SafeContext localScopeDepth, ArrayBuilder<EscapeValue> escapeValues) 3284var inferredDestinationValEscape = SafeContext.CallingMethod; 3560private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3644internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3667internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3676return SafeContext.CallingMethod; 3682return SafeContext.CallingMethod; 3699return SafeContext.CallingMethod; 3705return SafeContext.CurrentMethod; 3762return SafeContext.CallingMethod; 3774return SafeContext.CallingMethod; 3833return SafeContext.CallingMethod; 3838return SafeContext.CallingMethod; 3950internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4294internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4296SafeContext broadest = localScopeDepth; 4299SafeContext valEscape; 4320internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4329return SafeContext.CallingMethod; 4335return SafeContext.CallingMethod; 4341return SafeContext.CallingMethod; 4356return SafeContext.CallingMethod; 4364return SafeContext.CallingMethod; 4376return SafeContext.CallingMethod; 4379return SafeContext.CallingMethod; 4396return SafeContext.CurrentMethod; 4401var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4426return SafeContext.CallingMethod; 4438return SafeContext.CallingMethod; 4489return SafeContext.CallingMethod; 4529var escape = GetInvocationEscapeScope( 4547var escape = SafeContext.CallingMethod; 4588SafeContext.CurrentMethod : 4589SafeContext.CallingMethod; 4689return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4690.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4739return SafeContext.CallingMethod; 4817private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4819SafeContext narrowestScope = localScopeDepth; 4828private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext localScopeDepth) 4830var result = SafeContext.CallingMethod; 4848private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4850var result = SafeContext.CallingMethod; 4853var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4860private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4862SafeContext result; 4866var rightEscape = assignment.IsRef 4891SafeContext getIndexerEscape( 4894SafeContext rightEscapeScope) 4900return SafeContext.CallingMethod; 4907return SafeContext.CallingMethod; 4928SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4938SafeContext escapeScope = escapeValue.IsRefEscape 4948SafeContext getPropertyEscape( 4950SafeContext rightEscapeScope) 4956return SafeContext.CallingMethod; 4965private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4967var result = SafeContext.CallingMethod; 4981internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5071if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5336if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5760private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5775private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5801private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5817private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5844private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext localScopeDepth) 5846SafeContext scope = SafeContext.CallingMethod; 5865SafeContext getPartsScope(BoundInterpolatedString interpolatedString, SafeContext localScopeDepth) 5867SafeContext scope = SafeContext.CallingMethod; 5886private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5909bool checkParts(BoundInterpolatedString interpolatedString, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (3)
5836var currentScope = _localScopeDepth; 5839SafeContext whenTrueEscape = GetValEscape(trueExpr, currentScope); 5840SafeContext whenFalseEscape = GetValEscape(falseExpr, currentScope);
Binder\Binder_Statements.cs (3)
1564var leftEscape = GetRefEscape(op1, _localScopeDepth); 1565var rightEscape = GetRefEscape(op2, _localScopeDepth); 1624var leftEscape = GetValEscape(op1, _localScopeDepth);
Binder\RefSafetyAnalysis.cs (53)
63private SafeContext _localScopeDepth; 64private Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>? _localEscapeScopes; 66private SafeContext _patternInputValEscape; 87_localScopeDepth = SafeContext.CurrentMethod.Wider(); 102_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope: SafeContext.CallingMethod); 137private readonly SafeContext _previousInputValEscape; 139public PatternInput(RefSafetyAnalysis analysis, SafeContext patternInputValEscape) 179public static SafeContextAndLocation Create(SafeContext context 192public readonly SafeContext Context; 198private SafeContextAndLocation(SafeContext context 212private (SafeContext RefEscapeScope, SafeContext ValEscapeScope) GetLocalScopes(LocalSymbol local) 218: (SafeContext.CurrentMethod, SafeContext.CallingMethod); 221private void SetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 255private SafeContext GetPlaceholderScope(BoundValuePlaceholderBase placeholder) 261: SafeContext.CallingMethod; 390SafeContext valEscapeScope = node.ExpressionOpt is { } expr 476private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 492SafeContext.CurrentMethod; 495SafeContext.CallingMethod; 503private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 505_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 526(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 564ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 574ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 629static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 634return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 684static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 688: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 697static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 701return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 864SafeContext valEscapeScope; 875valEscapeScope = SafeContext.CallingMethod; 902SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 904SafeContext valEscapeScope; 912valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 985var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 1071private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1145SafeContext valEscape = nestedVariables is null 1187internal readonly SafeContext ValEscape; 1190internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1211? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1238SafeContext collectionEscape;
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)