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);
229 references to SafeContext
Microsoft.CodeAnalysis.CSharp (229)
Binder\Binder.ValueChecks.cs (150)
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, 3126SafeContext localScopeDepth, 3138SafeContext localScopeDepth, BindingDiagnosticBag diagnostics, Symbol symbolForReporting) 3154SafeContext escapeTo = localScopeDepth; 3188var inferredDestinationValEscape = SafeContext.CallingMethod; 3222SafeContext localScopeDepth, 3237var toArgEscape = GetValEscape(mixableArg.Argument, localScopeDepth); 3272void inferDeclarationExpressionValEscape(ImmutableArray<BoundExpression> argsOpt, SafeContext localScopeDepth, ArrayBuilder<EscapeValue> escapeValues) 3276var inferredDestinationValEscape = SafeContext.CallingMethod; 3552private static ErrorCode GetStandardRValueRefEscapeError(SafeContext escapeTo) 3636internal void ValidateEscape(BoundExpression expr, SafeContext escapeTo, bool isByRef, BindingDiagnosticBag diagnostics) 3659internal SafeContext GetRefEscape(BoundExpression expr, SafeContext localScopeDepth) 3668return SafeContext.CallingMethod; 3674return SafeContext.CallingMethod; 3691return SafeContext.CallingMethod; 3697return SafeContext.CurrentMethod; 3754return SafeContext.CallingMethod; 3820return SafeContext.CallingMethod; 3932internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4266internal SafeContext GetBroadestValEscape(BoundTupleExpression expr, SafeContext localScopeDepth) 4268SafeContext broadest = localScopeDepth; 4271SafeContext valEscape; 4292internal SafeContext GetValEscape(BoundExpression expr, SafeContext localScopeDepth) 4301return SafeContext.CallingMethod; 4307return SafeContext.CallingMethod; 4313return SafeContext.CallingMethod; 4328return SafeContext.CallingMethod; 4336return SafeContext.CallingMethod; 4348return SafeContext.CallingMethod; 4351return SafeContext.CallingMethod; 4368return SafeContext.CurrentMethod; 4373var consEscape = GetValEscape(conditional.Consequence, localScopeDepth); 4398return SafeContext.CallingMethod; 4491var escape = GetInvocationEscapeScope( 4509var escape = SafeContext.CallingMethod; 4550SafeContext.CurrentMethod : 4551SafeContext.CallingMethod; 4651return (range.LeftOperandOpt is { } left ? GetValEscape(left, localScopeDepth) : SafeContext.CallingMethod) 4652.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right, localScopeDepth) : SafeContext.CallingMethod); 4701return SafeContext.CallingMethod; 4779private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext localScopeDepth) 4781SafeContext narrowestScope = localScopeDepth; 4790private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext localScopeDepth) 4792var result = SafeContext.CallingMethod; 4810private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext localScopeDepth) 4812var result = SafeContext.CallingMethod; 4815var exprResult = GetValEscapeOfObjectMemberInitializer(expr, localScopeDepth); 4822private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr, SafeContext localScopeDepth) 4824SafeContext result; 4828var rightEscape = assignment.IsRef 4853SafeContext getIndexerEscape( 4856SafeContext rightEscapeScope) 4862return SafeContext.CallingMethod; 4869return SafeContext.CallingMethod; 4890SafeContext receiverEscapeScope = SafeContext.CallingMethod; 4900SafeContext escapeScope = escapeValue.IsRefEscape 4910SafeContext getPropertyEscape( 4912SafeContext rightEscapeScope) 4918return SafeContext.CallingMethod; 4927private SafeContext GetValEscape(ImmutableArray<BoundExpression> expressions, SafeContext localScopeDepth) 4929var result = SafeContext.CallingMethod; 4943internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeFrom, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5033if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5288if (HasLocalScope((BoundCollectionExpression)conversion.Operand) && !SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5712private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5727private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5753private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5769private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5796private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext localScopeDepth) 5798SafeContext scope = SafeContext.CallingMethod; 5817SafeContext getPartsScope(BoundInterpolatedString interpolatedString, SafeContext localScopeDepth) 5819SafeContext scope = SafeContext.CallingMethod; 5838private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeFrom, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5861bool 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; 835SafeContext valEscapeScope; 846valEscapeScope = SafeContext.CallingMethod; 873SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 875SafeContext valEscapeScope; 883valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 956var escapeFrom = GetValEscape(node.InitializerExpressionOpt, _localScopeDepth); 1042private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1116SafeContext valEscape = nestedVariables is null 1147internal readonly SafeContext ValEscape; 1150internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1171? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1198SafeContext 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)