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);
193 references to SafeContext
Microsoft.CodeAnalysis.CSharp (193)
Binder\Binder.ValueChecks.cs (118)
1315private bool CheckLocalRefEscape(SyntaxNode node, BoundLocal local, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1472private static EscapeLevel? EscapeLevelFromScope(SafeContext lifetime) => lifetime switch 1479private static SafeContext GetParameterValEscape(ParameterSymbol parameter) 1483{ EffectiveScope: ScopedKind.ScopedValue } => SafeContext.CurrentMethod, 1484{ RefKind: RefKind.Out, UseUpdatedEscapeRules: true } => SafeContext.ReturnOnly, 1485_ => SafeContext.CallingMethod 1492private static SafeContext GetParameterRefEscape(ParameterSymbol parameter) 1496{ RefKind: RefKind.None } => SafeContext.CurrentMethod, 1497{ EffectiveScope: ScopedKind.ScopedRef } => SafeContext.CurrentMethod, 1498{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, RefKind: RefKind.Out } => SafeContext.ReturnOnly, 1499{ HasUnscopedRefAttribute: true, UseUpdatedEscapeRules: true, IsThis: false } => SafeContext.CallingMethod, 1500_ => SafeContext.ReturnOnly 1507private bool CheckParameterValEscape(SyntaxNode node, ParameterSymbol parameter, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1525private bool CheckParameterRefEscape(SyntaxNode node, BoundExpression parameter, ParameterSymbol parameterSymbol, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 1527var refSafeToEscape = GetParameterRefEscape(parameterSymbol); 1731private SafeContext GetFieldRefEscape(BoundFieldAccess fieldAccess) 1738return SafeContext.CallingMethod; 1754private bool CheckFieldRefEscape(SyntaxNode node, BoundFieldAccess fieldAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 1778private bool CheckFieldLikeEventRefEscape(SyntaxNode node, BoundEventAccess eventAccess, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 2176internal SafeContext GetInterpolatedStringHandlerConversionEscapeScope( 2187SafeContext escapeScope = GetValEscape(data.Construction); 2208private SafeContext GetInvocationEscapeScope( 2226SafeContext getInvocationEscapeWithOldRules(ref readonly MethodInvocationInfo methodInvocationInfo, bool isRefEscape) 2240SafeContext escapeScope = SafeContext.CallingMethod; 2260SafeContext argumentEscape = (isRefEscape, argumentIsRefEscape) switch 2290private SafeContext GetInvocationEscapeWithUpdatedRules( 2295SafeContext escapeScope = SafeContext.CallingMethod; 2316SafeContext argEscape = isArgumentRefEscape ? 2333private SafeContext GetInvocationEscapeToReceiver( 2337SafeContext escapeScope = SafeContext.CallingMethod; 2344SafeContext argEscape = isArgumentRefEscape 2422SafeContext escapeTo, 2441bool checkingReceiver, SafeContext escapeTo, 2518SafeContext escapeTo, 2571SafeContext escapeTo, 3155SafeContext escapeTo = _localScopeDepth; 3189var inferredDestinationValEscape = SafeContext.CallingMethod; 3237var toArgEscape = GetValEscape(mixableArg.Argument); 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) 3668return SafeContext.CallingMethod; 3674return SafeContext.CallingMethod; 3691return SafeContext.CallingMethod; 3697return SafeContext.CurrentMethod; 3754return SafeContext.CallingMethod; 3766return SafeContext.CallingMethod; 3821return SafeContext.CallingMethod; 3826return SafeContext.CallingMethod; 3936internal bool CheckRefEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 4273internal SafeContext GetBroadestValEscape(BoundTupleExpression expr) 4275SafeContext broadest = _localScopeDepth; 4278SafeContext valEscape; 4299internal SafeContext GetValEscape(BoundExpression expr) 4308return SafeContext.CallingMethod; 4314return SafeContext.CallingMethod; 4320return SafeContext.CallingMethod; 4335return SafeContext.CallingMethod; 4343return SafeContext.CallingMethod; 4355return SafeContext.CallingMethod; 4358return SafeContext.CallingMethod; 4375return SafeContext.CurrentMethod; 4380var consEscape = GetValEscape(conditional.Consequence); 4405return SafeContext.CallingMethod; 4417return SafeContext.CallingMethod; 4464return SafeContext.CallingMethod; 4501var escape = GetInvocationEscapeScope( 4518var escape = SafeContext.CallingMethod; 4559SafeContext.CallingMethod; 4653return (range.LeftOperandOpt is { } left ? GetValEscape(left) : SafeContext.CallingMethod) 4654.Intersect(range.RightOperandOpt is { } right ? GetValEscape(right) : SafeContext.CallingMethod); 4702return SafeContext.CallingMethod; 4780private SafeContext GetTupleValEscape(ImmutableArray<BoundExpression> elements) 4782SafeContext narrowestScope = _localScopeDepth; 4791private SafeContext GetValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr) 4793var result = SafeContext.CallingMethod; 4810private SafeContext GetValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr) 4812var result = SafeContext.CallingMethod; 4815var exprResult = GetValEscapeOfObjectMemberInitializer(expr); 4822private SafeContext GetValEscapeOfObjectMemberInitializer(BoundExpression expr) 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) 4929var result = SafeContext.CallingMethod; 4943internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, SafeContext escapeTo, bool checkingReceiver, BindingDiagnosticBag diagnostics) 5033if (!SafeContext.CurrentMethod.IsConvertibleTo(escapeTo)) 5707private bool CheckTupleValEscape(ImmutableArray<BoundExpression> elements, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5722private bool CheckValEscapeOfCollectionInitializer(BoundCollectionInitializerExpression colExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5747private bool CheckValEscapeOfObjectInitializer(BoundObjectInitializerExpression initExpr, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5763private bool CheckInterpolatedStringHandlerConversionEscape(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5790private SafeContext GetValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression) 5792SafeContext scope = SafeContext.CallingMethod; 5811SafeContext getPartsScope(BoundInterpolatedString interpolatedString) 5813SafeContext scope = SafeContext.CallingMethod; 5831private bool CheckValEscapeOfInterpolatedStringHandlerCalls(BoundExpression expression, SafeContext escapeTo, BindingDiagnosticBag diagnostics) 5854bool checkParts(BoundInterpolatedString interpolatedString, SafeContext escapeTo, BindingDiagnosticBag diagnostics)
Binder\Binder_Operators.cs (2)
5983SafeContext whenTrueEscape = GetValEscape(trueExpr); 5984SafeContext whenFalseEscape = GetValEscape(falseExpr);
Binder\Binder_Statements.cs (3)
1569var leftEscape = GetRefEscape(op1); 1570var rightEscape = GetRefEscape(op2); 1629var leftEscape = GetValEscape(op1);
Binder\RefSafetyAnalysis.cs (53)
65private SafeContext _localScopeDepth; 66private Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>? _localEscapeScopes; 68private SafeContext _patternInputValEscape; 88_localScopeDepth = SafeContext.CurrentMethod; 108_analysis.AddLocalScopes(local, refEscapeScope: _analysis._localScopeDepth, valEscapeScope: SafeContext.CallingMethod); 145private readonly SafeContext _previousInputValEscape; 147public PatternInput(RefSafetyAnalysis analysis, SafeContext patternInputValEscape) 187public static SafeContextAndLocation Create(SafeContext context 200public readonly SafeContext Context; 206private SafeContextAndLocation(SafeContext context 220private (SafeContext RefEscapeScope, SafeContext ValEscapeScope) GetLocalScopes(LocalSymbol local) 226: (SafeContext.CurrentMethod, SafeContext.CallingMethod); 229private void SetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 263private SafeContext GetPlaceholderScope(BoundValuePlaceholderBase placeholder) 269: SafeContext.CallingMethod; 410SafeContext valEscapeScope = node.ExpressionOpt is { } expr 496private void AddLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 512SafeContext.CurrentMethod; 515SafeContext.CallingMethod; 523private void AddOrSetLocalScopes(LocalSymbol local, SafeContext refEscapeScope, SafeContext valEscapeScope) 525_localEscapeScopes ??= new Dictionary<LocalSymbol, (SafeContext RefEscapeScope, SafeContext ValEscapeScope)>(); 546(SafeContext refEscapeScope, SafeContext valEscapeScope) = GetLocalScopes(localSymbol); 584ValidateEscape(expr, SafeContext.ReturnOnly, node.RefKind != RefKind.None, _diagnostics); 594ValidateEscape(expr, SafeContext.ReturnOnly, isByRef: false, _diagnostics); 648static SafeContext getDeclarationValEscape(BoundTypeExpression typeExpression, SafeContext valEscape) 653return typeExpression.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 703static SafeContext getPositionalValEscape(Symbol? symbol, SafeContext valEscape) 707: symbol.GetTypeOrReturnType().IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 716static SafeContext getMemberValEscape(BoundPropertySubpatternMember? member, SafeContext valEscape) 720return member.Type.IsRefLikeOrAllowsRefLikeType() ? valEscape : SafeContext.CallingMethod; 882SafeContext valEscapeScope; 893valEscapeScope = SafeContext.CallingMethod; 920SafeContext getArgumentEscapeScope(int nArgumentsVisited, ImmutableArray<BoundExpression> arguments, int argIndex) 922SafeContext valEscapeScope; 930valEscapeScope = SafeContext.CallingMethod; // Consider skipping this placeholder entirely since SafeContext.CallingMethod is the fallback in GetPlaceholderScope(). 1002var escapeFrom = GetValEscape(node.InitializerExpressionOpt); 1086private void GetAwaitableInstancePlaceholders(ArrayBuilder<(BoundValuePlaceholderBase, SafeContextAndLocation)> placeholders, BoundAwaitableInfo awaitableInfo, SafeContext valEscapeScope) 1160SafeContext valEscape = nestedVariables is null 1201internal readonly SafeContext ValEscape; 1204internal DeconstructionVariable(BoundExpression expression, SafeContext valEscape, ArrayBuilder<DeconstructionVariable>? nestedVariables) 1225? new DeconstructionVariable(expr, valEscape: SafeContext.Empty, GetDeconstructionAssignmentVariables(tuple)) 1252SafeContext 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)