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)
1311private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1468private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1475private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1479{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1480{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1481_ => SafeContext.CallingMethod 1488private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1492{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1493{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1494{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1495{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1496_ => SafeContext.ReturnOnly 1503private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1521private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1523var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1727private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess, SafeContext localScopeDepth) 1734return SafeContext.CallingMethod; 1750private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1774private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2172internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2174SafeContext localScopeDepth) 2184SafeContext escapeScope = GetValEscape(data.Construction, localScopeDepth); 2205private SafeContext GetInvocationEscapeScope( 2207SafeContext localScopeDepth, 2224SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, SafeContext localScopeDepth, bool isRefEscape) 2238SafeContext escapeScope = SafeContext.CallingMethod; 2258SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2288private SafeContext GetInvocationEscapeWithUpdatedRules( 2290SafeContext localScopeDepth, 2294SafeContext escapeScope = SafeContext.CallingMethod; 2315SafeContext argEscape = isArgumentRefEscape ? 2332private SafeContext GetInvocationEscapeToReceiver( 2334SafeContext localScopeDepth) 2337SafeContext escapeScope = SafeContext.CallingMethod; 2344SafeContext argEscape = isArgumentRefEscape 2422SafeContext escapeFrom, 2423SafeContext escapeTo, 2442bool checkingReceiver, SafeContext escapeFrom, SafeContext escapeTo, 2519SafeContext escapeFrom, 2520SafeContext escapeTo, 2573SafeContext escapeFrom, 2574SafeContext escapeTo, 3132SafeContext localScopeDepth, 3144SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 3160SafeContext escapeTo = localScopeDepth; 3194var inferredDestinationValEscape = SafeContext.CallingMethod; 3228SafeContext localScopeDepth, 3243var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3278void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt, SafeContext localScopeDepth, ArrayBuilder<EscapeValue> escapeValues) 3282var inferredDestinationValEscape = SafeContext.CallingMethod; 3558private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3642internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3665internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3674return SafeContext.CallingMethod; 3680return SafeContext.CallingMethod; 3697return SafeContext.CallingMethod; 3703return SafeContext.CurrentMethod; 3760return SafeContext.CallingMethod; 3772return SafeContext.CallingMethod; 3831return SafeContext.CallingMethod; 3836return SafeContext.CallingMethod; 3948internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4292internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4294SafeContext broadest = localScopeDepth; 4297SafeContext valEscape; 4318internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4327return SafeContext.CallingMethod; 4333return SafeContext.CallingMethod; 4339return SafeContext.CallingMethod; 4354return SafeContext.CallingMethod; 4362return SafeContext.CallingMethod; 4374return SafeContext.CallingMethod; 4377return SafeContext.CallingMethod; 4394return SafeContext.CurrentMethod; 4399var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4424return SafeContext.CallingMethod; 4436return SafeContext.CallingMethod; 4487return SafeContext.CallingMethod; 4527var escape = GetInvocationEscapeScope( 4545var escape = SafeContext.CallingMethod; 4586SafeContext.CurrentMethod : 4587SafeContext.CallingMethod; 4687return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4688.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4737return SafeContext.CallingMethod; 4815private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4817SafeContext narrowestScope = localScopeDepth; 4826private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext localScopeDepth) 4828var result = SafeContext.CallingMethod; 4846private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4848var result = SafeContext.CallingMethod; 4851var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4858private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4860SafeContext result; 4864var rightEscape = assignment.IsRef 4889SafeContext getIndexerEscape( 4892SafeContext rightEscapeScope) 4898return SafeContext.CallingMethod; 4905return SafeContext.CallingMethod; 4926SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4936SafeContext escapeScope = escapeValue.IsRefEscape 4946SafeContext getPropertyEscape( 4948SafeContext rightEscapeScope) 4954return SafeContext.CallingMethod; 4963private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4965var result = SafeContext.CallingMethod; 4979internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5069if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5334if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5758private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5773private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5799private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5815private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5842private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext localScopeDepth) 5844SafeContext scope = SafeContext.CallingMethod; 5863SafeContext getPartsScope(BoundInterpolatedString interpolatedString, SafeContext localScopeDepth) 5865SafeContext scope = SafeContext.CallingMethod; 5884private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5907bool checkParts(BoundInterpolatedString interpolatedString, 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); 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)