src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (78)
63public static bool HasNullConstantValue(this IOperation operation)
68public static bool TryGetBoolConstantValue(this IOperation operation, out bool constantValue)
80public static bool HasConstantValue(this IOperation operation, long comparand)
85public static bool HasConstantValue(this IOperation operation, ulong comparand)
132public static ImmutableArray<IOperation> WithoutFullyImplicitOperations(this ImmutableArray<IOperation> operations)
134ImmutableArray<IOperation>.Builder? builder = null;
137var operation = operations[i];
144builder = ImmutableArray.CreateBuilder<IOperation>();
162public static ImmutableArray<IOperation> GetTopmostExplicitDescendants(this IOperation operation)
169var builder = ImmutableArray.CreateBuilder<IOperation>();
170var operationsToProcess = new Queue<IOperation>();
182foreach (var child in operation.Children)
197public static bool IsOperationNoneRoot(this IOperation operation)
205public static IBlockOperation? GetTopmostParentBlock(this IOperation? operation)
207IOperation? currentOperation = operation;
225public static IBlockOperation? GetFirstParentBlock(this IOperation? operation)
227IOperation? currentOperation = operation;
247public static TOperation? GetAncestor<TOperation>(this IOperation root, OperationKind ancestorKind, Func<TOperation, bool>? predicate = null)
248where TOperation : class, IOperation
255var ancestor = root;
282public static IOperation? GetAncestor(this IOperation root, ImmutableArray<OperationKind> ancestorKinds, Func<IOperation, bool>? predicate = null)
289var ancestor = root;
324public static IOperation? GetInstance(this IInstanceReferenceOperation operation, bool isInsideAnonymousObjectInitializer)
331for (IOperation? current = operation; current != null && current.Kind != OperationKind.Block; current = current.Parent)
355public static bool HasAnyOperationDescendant(this ImmutableArray<IOperation> operationBlocks, Func<IOperation, bool> predicate)
357foreach (var operationBlock in operationBlocks)
368public static bool HasAnyOperationDescendant(this IOperation operationBlock, Func<IOperation, bool> predicate)
373public static bool HasAnyOperationDescendant(this IOperation operationBlock, Func<IOperation, bool> predicate, [NotNullWhen(returnValue: true)] out IOperation? foundOperation)
375foreach (var descendant in operationBlock.DescendantsAndSelf())
388public static bool HasAnyOperationDescendant(this ImmutableArray<IOperation> operationBlocks, OperationKind kind)
431public static IOperation GetRoot(this IOperation operation)
446private static readonly BoundedCache<Compilation, ConcurrentDictionary<IOperation, ControlFlowGraph?>> s_operationToCfgCache
449public static bool TryGetEnclosingControlFlowGraph(this IOperation operation, [NotNullWhen(returnValue: true)] out ControlFlowGraph? cfg)
466private static ControlFlowGraph? CreateControlFlowGraph(IOperation operation)
503public static PooledHashSet<ISymbol> GetCaptures(this IOperation operation, IMethodSymbol lambdaOrLocalFunction)
514foreach (var child in operation.Descendants())
556public static bool IsWithinLambdaOrLocalFunction(this IOperation operation, [NotNullWhen(true)] out IOperation? containingLambdaOrLocalFunctionOperation)
562public static bool IsWithinExpressionTree(this IOperation operation, [NotNullWhen(true)] INamedTypeSymbol? linqExpressionTreeType)
598[NotNullWhen(returnValue: true)] out IOperation? elementOfParentTupleContainingTuple)
603IOperation previousOperation = tupleOperation;
604var currentOperation = tupleOperation.Parent;
636public static IOperation? GetInstance(this IInvocationOperation invocationOperation)
642public static ITypeSymbol? GetInstanceType(this IOperation operation)
644IOperation? instance = operation switch
656public static ISymbol? GetReferencedMemberOrLocalOrParameter(this IOperation? operation)
679public static IOperation WalkDownParentheses(this IOperation operation)
690public static IOperation? WalkUpParentheses(this IOperation? operation)
708public static IOperation WalkDownConversion(this IOperation operation)
725public static IOperation WalkDownConversion(this IOperation operation, Func<IConversionOperation, bool> predicate)
736public static IOperation? WalkUpConversion(this IOperation? operation)
749public static IOperation? GetThrownException(this IThrowOperation operation)
751var thrownObject = operation.Exception;
783where TOperation : class, IOperation
799public static bool HasAnyExplicitDescendant(this IOperation operation, Func<IOperation, bool>? descendIntoOperation = null)
801using var stack = ArrayBuilder<IEnumerator<IOperation>>.GetInstance();
810var current = enumerator.Current;
839IOperation potentialLeftSide = operation;
912public static ValueUsageInfo GetValueUsageInfo(this IOperation operation, ISymbol containingSymbol)
1087public static bool IsInLeftOfDeconstructionAssignment([DisallowNull] this IOperation? operation, out IDeconstructionAssignmentOperation? deconstructionAssignment)
1091var previousOperation = operation;
1123public static IMethodSymbol? TryGetContainingAnonymousFunctionOrLocalFunction(this IOperation? operation)
1149public static bool IsAnyCompoundAssignment(this IOperation operation)
src\RoslynAnalyzers\Utilities\Compiler\Lightup\IFunctionPointerInvocationOperationWrapper.cs (15)
23private static readonly Func<IOperation, ImmutableArray<IArgumentOperation>> ArgumentsAccessor = LightupHelpers.CreateOperationPropertyAccessor<IOperation, ImmutableArray<IArgumentOperation>>(WrappedType, nameof(Arguments), fallbackResult: ImmutableArray<IArgumentOperation>.Empty);
24private static readonly Func<IOperation, IOperation> TargetAccessor = LightupHelpers.CreateOperationPropertyAccessor<IOperation, IOperation>(WrappedType, nameof(Target), fallbackResult: null!);
26private static readonly Func<IOperation, IMethodSymbol> GetFunctionPointerSignatureAccessor = CreateFunctionPointerSignatureAccessor(WrappedType);
28private static Func<IOperation, IMethodSymbol> CreateFunctionPointerSignatureAccessor(Type? wrappedType)
42var operation = Expression.Variable(typeof(IOperation));
44return Expression.Lambda<Func<IOperation, IMethodSymbol>>(Expression.Call(targetMethod, Expression.Convert(operation, wrappedType)), operation).Compile();
47private IFunctionPointerInvocationOperationWrapper(IOperation operation)
52public IOperation WrappedOperation { get; }
55public IOperation Target => TargetAccessor(WrappedOperation);
59public static IFunctionPointerInvocationOperationWrapper FromOperation(IOperation operation)
74public static bool IsInstance(IOperation operation)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\CopyAnalysis\CopyAnalysis.CopyDataFlowOperationVisitor.cs (9)
40public override CopyAnalysisData Flow(IOperation statement, BasicBlock block, CopyAnalysisData input)
95protected override CopyAbstractValue GetCopyAbstractValue(IOperation operation) => base.GetCachedAbstractValue(operation);
107protected override void SetAbstractValueForAssignment(AnalysisEntity targetAnalysisEntity, IOperation? assignedValueOperation, CopyAbstractValue assignedValue)
119protected override void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, CopyAbstractValue assignedValue)
306protected override CopyAbstractValue ComputeAnalysisValueForReferenceOperation(IOperation operation, CopyAbstractValue defaultValue)
328IOperation leftOperand,
329IOperation rightOperand,
381protected override PredicateValueKind SetValueForIsNullComparisonOperator(IOperation leftOperand, bool equals, CopyAnalysisData targetAnalysisData) => PredicateValueKind.Unknown;
595public override CopyAbstractValue DefaultVisit(IOperation operation, object? argument)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\DisposeAnalysis\DisposeAnalysis.DisposeDataFlowOperationVisitor.cs (14)
79protected override DisposeAbstractValue HandleInstanceCreation(IOperation creation, PointsToAbstractValue instanceLocation, DisposeAbstractValue defaultValue)
106private void HandleDisposingOperation(IOperation disposingOperation, IOperation? disposedInstance)
124private void HandlePossibleInvalidatingOperation(IOperation invalidatedInstance)
137private void HandlePossibleEscapingOperation(IOperation escapingOperation, ImmutableHashSet<AbstractLocation> escapedLocations)
150protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, DisposeAbstractValue value)
156protected override void SetAbstractValueForAssignment(IOperation target, IOperation? assignedValueOperation, DisposeAbstractValue assignedValue, bool mayBeAssignment = false)
162protected override void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, DisposeAbstractValue assignedValue)
218public override DisposeAbstractValue DefaultVisit(IOperation operation, object? argument)
224public override DisposeAbstractValue Visit(IOperation? operation, object? argument)
234protected override void HandlePossibleThrowingOperation(IOperation operation)
257IOperation? visitedInstance,
260IOperation originalOperation,
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ParameterValidationAnalysis\ParameterValidationAnalysis.ParameterValidationDataFlowOperationVisitor.cs (15)
96protected override void SetAbstractValueForAssignment(IOperation target, IOperation? assignedValueOperation, ParameterValidationAbstractValue assignedValue, bool mayBeAssignment = false)
105protected override void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, ParameterValidationAbstractValue assignedValue)
110protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, ParameterValidationAbstractValue value)
145private void MarkValidatedLocations(IOperation operation)
148private IEnumerable<AbstractLocation> GetNotValidatedLocations(IOperation operation)
154private static bool IsHazardousIfNull(IOperation operation)
173private void HandlePotentiallyHazardousOperation(IOperation operation, IEnumerable<AbstractLocation> nonValidatedLocations)
219public override ParameterValidationAbstractValue Visit(IOperation? operation, object? argument)
251IOperation? visitedInstance,
254IOperation originalOperation,
265IOperation originalOperation,
276IOperation originalOperation,
284private void ProcessRegularInvocationOrCreation(IMethodSymbol? targetMethod, ImmutableArray<IArgumentOperation> arguments, IOperation operation)
355private void ProcessLambdaOrLocalFunctionInvocation(IMethodSymbol targetMethod, IOperation invocation)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysis.PointsToDataFlowOperationVisitor.cs (44)
28private readonly PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder> _escapedOperationLocationsBuilder;
29private readonly PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder> _escapedReturnValueLocationsBuilder;
42_escapedOperationLocationsBuilder = PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder>.GetInstance();
43_escapedReturnValueLocationsBuilder = PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder>.GetInstance();
51public ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> GetEscapedLocationsThroughOperationsMap()
54public ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> GetEscapedLocationsThroughReturnValuesMap()
97public override PointsToAnalysisData Flow(IOperation statement, BasicBlock block, PointsToAnalysisData input)
167protected override PointsToAbstractValue GetPointsToAbstractValue(IOperation operation) => base.GetCachedAbstractValue(operation);
193protected override CopyAbstractValue GetCopyAbstractValue(IOperation operation)
210protected override void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, PointsToAbstractValue assignedValue)
271protected override PointsToAbstractValue ComputeAnalysisValueForReferenceOperation(IOperation operation, PointsToAbstractValue defaultValue)
330protected override void ProcessReturnValue(IOperation? returnValue)
342private protected override PointsToAbstractValue GetAbstractValueForImplicitWrappingTaskCreation(IOperation returnValueOperation, PointsToAbstractValue returnValue, PointsToAbstractValue implicitTaskPointsToValue)
359IOperation leftOperand,
360IOperation rightOperand,
378protected override PredicateValueKind SetValueForIsNullComparisonOperator(IOperation leftOperand, bool equals, PointsToAnalysisData targetAnalysisData)
386IOperation target,
387IOperation assignedValueOperation,
397IOperation target,
625private void HandleEscapingOperation(IOperation escapingOperation, IOperation escapedInstance)
630private void HandleEscapingOperation(IOperation escapingOperation, IOperation escapedInstance, PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder> builder)
635foreach (var capturedOperation in escapedInstancePointsToValue.LValueCapturedOperations)
716private void HandlePossibleEscapingForAssignment(IOperation target, IOperation value, IOperation operation)
728protected override void SetAbstractValueForAssignment(IOperation target, IOperation? assignedValueOperation, PointsToAbstractValue assignedValue, bool mayBeAssignment = false)
738protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, PointsToAbstractValue value)
749public override PointsToAbstractValue DefaultVisit(IOperation operation, object? argument)
785IOperation? currentInstanceOperation = operation.GetInstance(IsInsideAnonymousObjectInitializer);
797where TOperation : IOperation
919private PointsToAbstractValue VisitInvocationCommon(IOperation operation, IOperation? instance)
940IOperation? visitedInstance,
943IOperation originalOperation,
1027IOperation originalOperation,
1037IOperation originalOperation,
1050private NullAbstractValue GetNullStateBasedOnInstanceOrReferenceValue(IOperation? referenceOrInstance, ITypeSymbol? operationType, NullAbstractValue defaultValue)
1066private PointsToAbstractValue GetValueBasedOnInstanceOrReferenceValue(IOperation? referenceOrInstance, IOperation operation, PointsToAbstractValue defaultValue)
1207IOperation operation,
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PropertySetAnalysis\PropertySetAnalysis.PropertySetDataFlowOperationVisitor.cs (20)
133protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, PropertySetAbstractValue value)
137protected override void SetAbstractValueForAssignment(IOperation target, IOperation? assignedValueOperation, PropertySetAbstractValue assignedValue, bool mayBeAssignment = false)
141protected override void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, PropertySetAbstractValue assignedValue)
198out IOperation? propertySetInstance))
230if (this.TryUnwrapFlowCaptureReference(operation.Target, out IOperation? lValueOperation, OperationKind.PropertyReference, OperationKind.FieldReference))
277this.TryUnwrapFlowCaptureReference(operation.Target, out IOperation? lValue, OperationKind.PropertyReference);
454public override PropertySetAbstractValue VisitInvocation_NonLambdaOrDelegateOrLocalFunction(IMethodSymbol method, IOperation? visitedInstance, ImmutableArray<IArgumentOperation> visitedArguments, bool invokedAsDelegate, IOperation originalOperation, PropertySetAbstractValue defaultValue)
476IOperation? propertySetInstance = visitedInstance;
514[NotNullWhen(returnValue: true)] out IOperation? instance)
530IOperation value = argumentOperation.Value;
595IOperation propertySetInstance,
633public override PropertySetAbstractValue VisitInvocation_LocalFunction(IMethodSymbol localFunction, ImmutableArray<IArgumentOperation> visitedArguments, IOperation originalOperation, PropertySetAbstractValue defaultValue)
641public override PropertySetAbstractValue VisitInvocation_Lambda(IFlowAnonymousFunctionOperation lambda, ImmutableArray<IArgumentOperation> visitedArguments, IOperation originalOperation, PropertySetAbstractValue defaultValue)
649protected override void ProcessReturnValue(IOperation? returnValue)
666private void MergeInterproceduralResults(IOperation originalOperation)
703private bool TryUnwrapFlowCaptureReference(IOperation flowCaptureReferenceOperation, [NotNullWhen(returnValue: true)] out IOperation? unwrappedOperation, params OperationKind[] kinds)
711IOperation lValueOperation = lValuePointsToAbstractValue.LValueCapturedOperations.First();
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\TaintedDataAnalysis\TaintedDataAnalysis.TaintedDataOperationVisitor.cs (12)
175public override TaintedDataAbstractValue DefaultVisit(IOperation operation, object? argument)
184foreach (IOperation childOperation in operation.Children)
230protected override TaintedDataAbstractValue ComputeAnalysisValueForReferenceOperation(IOperation operation, TaintedDataAbstractValue defaultValue)
262IOperation? visitedInstance,
265IOperation originalOperation,
351IOperation? thenTaintedTargetOperation = visitedInstance != null && thenTaintedTarget == TaintedTargetValue.This
356var operation = visitedInstance != null && ifTaintedParameter == TaintedTargetValue.This
422public override TaintedDataAbstractValue VisitInvocation_LocalFunction(IMethodSymbol localFunction, ImmutableArray<IArgumentOperation> visitedArguments, IOperation originalOperation, TaintedDataAbstractValue defaultValue)
436public override TaintedDataAbstractValue VisitInvocation_Lambda(IFlowAnonymousFunctionOperation lambda, ImmutableArray<IArgumentOperation> visitedArguments, IOperation originalOperation, TaintedDataAbstractValue defaultValue)
490.Select<IOperation, TaintedDataAbstractValue>(this.GetCachedAbstractValue)
560IOperation originalOperation)
762private void SetTaintedForEntity(IOperation operation, TaintedDataAbstractValue value)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ValueContentAnalysis\ValueContentAnalysis.ValueContentDataFlowOperationVisitor.cs (9)
78protected override CopyAbstractValue GetCopyAbstractValue(IOperation operation)
93protected override PredicateValueKind SetValueForIsNullComparisonOperator(IOperation leftOperand, bool equals, ValueContentAnalysisData targetAnalysisData)
97IOperation leftOperand,
98IOperation rightOperand,
114private void SetValueForComparisonOperator(IOperation target, IOperation assignedValue, bool equals, ref PredicateValueKind predicateValueKind, ValueContentAnalysisData targetAnalysisData)
184public override ValueContentAbstractValue DefaultVisit(IOperation operation, object? argument)
272IOperation? visitedInstance,
275IOperation originalOperation,
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AbstractLocation.cs (23)
22/// 1. An allocation or an object creation operation (<see cref="CreateAllocationLocation(IOperation, ITypeSymbol, PointsToAnalysisContext)"/>).
23/// 2. Location for the implicit 'this' or 'Me' instance being analyzed (<see cref="CreateThisOrMeLocation(INamedTypeSymbol, ImmutableStack{IOperation})"/>).
24/// 3. Location created for certain symbols which do not have a declaration in executable code, i.e. no <see cref="IOperation"/> for declaration (such as parameter symbols, member symbols, etc. - <see cref="CreateSymbolLocation(ISymbol, ImmutableStack{IOperation})"/>/>).
26/// See <see cref="CreateFlowCaptureLocation(InterproceduralCaptureId, ITypeSymbol, ImmutableStack{IOperation})"/>
35private AbstractLocation(IOperation? creation, ImmutableStack<IOperation>? creationCallStack, AnalysisEntity? analysisEntity, ISymbol? symbol, InterproceduralCaptureId? captureId, ITypeSymbol? locationType, bool isSpecialSingleton)
40CreationCallStack = creationCallStack ?? ImmutableStack<IOperation>.Empty;
48private static AbstractLocation Create(IOperation? creation, ImmutableStack<IOperation>? creationCallStack, AnalysisEntity? analysisEntity, ISymbol? symbol, InterproceduralCaptureId? captureId, ITypeSymbol? locationType)
56public static AbstractLocation CreateAllocationLocation(IOperation creation, ITypeSymbol locationType, PointsToAnalysisContext analysisContext)
58internal static AbstractLocation CreateAllocationLocation(IOperation creation, ITypeSymbol locationType, ImmutableStack<IOperation>? callStack)
62public static AbstractLocation CreateThisOrMeLocation(INamedTypeSymbol namedTypeSymbol, ImmutableStack<IOperation>? creationCallStack)
64public static AbstractLocation CreateSymbolLocation(ISymbol symbol, ImmutableStack<IOperation>? creationCallStack)
66public static AbstractLocation CreateFlowCaptureLocation(InterproceduralCaptureId captureId, ITypeSymbol locationType, ImmutableStack<IOperation>? creationCallStack)
69public IOperation? Creation { get; }
70public ImmutableStack<IOperation> CreationCallStack { get; }
76public IOperation? GetTopOfCreationCallStackOrCreation()
134foreach (var creation in CreationCallStack)
154SyntaxNode? TryGetSyntaxNodeToReportDiagnostic(IOperation creation, PointsToAnalysisResult pointsToAnalysisResult)
177SyntaxNode? TryGetSyntaxNodeToReportDiagnosticCore(IOperation operation)
182SyntaxNode? TryGetSyntaxNodeToReportDiagnosticForPointsValue(PointsToAbstractValue pointsToValue, IOperation operation)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AnalysisEntityDataFlowOperationVisitor.cs (11)
47protected override TAbstractAnalysisValue ComputeAnalysisValueForReferenceOperation(IOperation operation, TAbstractAnalysisValue defaultValue)
191protected override TAnalysisData GetMergedAnalysisDataForPossibleThrowingOperation(TAnalysisData? existingData, IOperation operation)
210protected override void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, TAbstractAnalysisValue value)
218protected override void SetAbstractValueForAssignment(IOperation target, IOperation? assignedValueOperation, TAbstractAnalysisValue assignedValue, bool mayBeAssignment = false)
238protected override void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, TAbstractAnalysisValue assignedValue)
252protected virtual void SetAbstractValueForAssignment(AnalysisEntity targetAnalysisEntity, IOperation? assignedValueOperation, TAbstractAnalysisValue assignedValue)
264private void SetAbstractValueForAssignment(AnalysisEntity targetAnalysisEntity, AnalysisEntity? assignedValueEntity, IOperation? assignedValueOperation, TAbstractAnalysisValue assignedValue)
360private void TransferValueTypeInstanceAnalysisDataForAssignment(AnalysisEntity targetAnalysisEntity, AnalysisEntity? valueAnalysisEntity, IOperation? assignedValueOperation)
759private void HandleDeconstructionAssignment(IOperation target, ImmutableHashSet<AnalysisEntity> childEntities)
772var element = tupleOperation.Elements[i];
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AnalysisEntityFactory.cs (21)
29private readonly Dictionary<IOperation, AnalysisEntity?> _analysisEntityMap;
34private readonly Func<IOperation, PointsToAbstractValue>? _getPointsToAbstractValue;
38private readonly ImmutableStack<IOperation>? _interproceduralCallStack;
39private readonly Func<IOperation, AnalysisEntity?>? _interproceduralGetAnalysisEntityForFlowCapture;
40private readonly Func<ISymbol, ImmutableStack<IOperation>?> _getInterproceduralCallStackForOwningSymbol;
45Func<IOperation, PointsToAbstractValue>? getPointsToAbstractValue,
51ImmutableStack<IOperation>? interproceduralCallStack,
53Func<IOperation, AnalysisEntity?>? interproceduralGetAnalysisEntityForFlowCapture,
54Func<ISymbol, ImmutableStack<IOperation>?> getInterproceduralCallStackForOwningSymbol)
66_analysisEntityMap = new Dictionary<IOperation, AnalysisEntity?>();
92where T : IOperation
108private static AbstractIndex CreateAbstractIndex(IOperation operation)
124public bool TryCreate(IOperation operation, [NotNullWhen(returnValue: true)] out AnalysisEntity? analysisEntity)
134IOperation? instance = null;
315IOperation? instance = null;
348if (tupleOperation.TryGetParentTupleOperation(out var parentTupleOperationOpt, out var elementOfParentTupleContainingTuple) &&
409public bool TryGetForInterproceduralAnalysis(IOperation operation, out AnalysisEntity? analysisEntity)
412private AnalysisEntity GetOrCreateForFlowCapture(CaptureId captureId, ITypeSymbol? type, IOperation flowCaptureOrReference, bool isLValueFlowCapture)
439ITypeSymbol type, IOperation? instance, [NotNullWhen(returnValue: true)] out AnalysisEntity? analysisEntity)
531ImmutableStack<IOperation>? interproceduralCallStackForSymbolDeclaration;
539interproceduralCallStackForSymbolDeclaration = ImmutableStack<IOperation>.Empty;
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\DataFlowAnalysisResult.cs (11)
26private readonly ImmutableDictionary<IOperation, TAbstractAnalysisValue> _operationStateMap;
27private readonly ImmutableDictionary<IOperation, PredicateValueKind> _predicateValueKindMap;
28private readonly ImmutableDictionary<IOperation, IDataFlowAnalysisResult<TAbstractAnalysisValue>> _interproceduralResultsMap;
35ImmutableDictionary<IOperation, TAbstractAnalysisValue> operationStateMap,
36ImmutableDictionary<IOperation, PredicateValueKind> predicateValueKindMap,
38ImmutableDictionary<IOperation, IDataFlowAnalysisResult<TAbstractAnalysisValue>> interproceduralResultsMap,
87internal DataFlowAnalysisResult<TBlockAnalysisResult, TAbstractAnalysisValue> With(ImmutableDictionary<IOperation, TAbstractAnalysisValue> operationStateMap)
98public TAbstractAnalysisValue this[IOperation operation]
147internal DataFlowAnalysisResult<TBlockAnalysisResult, TAbstractAnalysisValue>? TryGetInterproceduralResult(IOperation operation)
168internal IEnumerable<DataFlowAnalysisResult<TBlockAnalysisResult, TAbstractAnalysisValue>> TryGetLambdaOrLocalFunctionResults(IOperation lambdaOrLocalFunctionOperation)
222public PredicateValueKind GetPredicateKind(IOperation operation) => _predicateValueKindMap.TryGetValue(operation, out var valueKind) ? valueKind : PredicateValueKind.Unknown;
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\DataFlowOperationVisitor.cs (92)
45private readonly ImmutableDictionary<IOperation, TAbstractAnalysisValue>.Builder _valueCacheBuilder;
46private readonly ImmutableDictionary<IOperation, PredicateValueKind>.Builder _predicateValueKindCacheBuilder;
49private readonly HashSet<IOperation> _visitedFlowBranchConditions;
51private readonly HashSet<IOperation>? _returnValueOperations;
111private readonly Stack<IOperation> _interproceduralCallStack;
116private readonly ImmutableDictionary<IOperation, IDataFlowAnalysisResult<TAbstractAnalysisValue>>.Builder _interproceduralResultsBuilder;
150public ImmutableDictionary<IOperation, IDataFlowAnalysisResult<TAbstractAnalysisValue>> InterproceduralResultsMap => _interproceduralResultsBuilder.ToImmutable();
273_valueCacheBuilder = ImmutableDictionary.CreateBuilder<IOperation, TAbstractAnalysisValue>();
274_predicateValueKindCacheBuilder = ImmutableDictionary.CreateBuilder<IOperation, PredicateValueKind>();
277_visitedFlowBranchConditions = new HashSet<IOperation>();
279_returnValueOperations = OwningSymbol is IMethodSymbol method && !method.ReturnsVoid ? new HashSet<IOperation>() : null;
280_interproceduralResultsBuilder = ImmutableDictionary.CreateBuilder<IOperation, IDataFlowAnalysisResult<TAbstractAnalysisValue>>();
287_interproceduralCallStack = new Stack<IOperation>();
296foreach (var operation in analysisContext.InterproceduralAnalysisData.CallStack)
375foreach (var operation in _returnValueOperations)
417public virtual TAnalysisData Flow(IOperation statement, BasicBlock block, TAnalysisData input)
426private void AfterVisitRoot(IOperation operation)
432foreach (var descendant in operation.DescendantsAndSelf())
804IOperation returnValueOperation,
812protected virtual void ProcessReturnValue(IOperation? returnValue)
827private TAbstractAnalysisValue GetAbstractValueForReturnOperation(IOperation returnValueOperation, out PointsToAbstractValue? implicitTaskPointsToValue)
848protected virtual void HandlePossibleThrowingOperation(IOperation operation)
867IOperation? instance = null;
868IOperation? invocation = null;
928protected virtual TAnalysisData GetMergedAnalysisDataForPossibleThrowingOperation(TAnalysisData? existingData, IOperation operation)
1017internal ImmutableDictionary<IOperation, TAbstractAnalysisValue> GetStateMap() => _valueCacheBuilder.ToImmutable();
1019internal ImmutableDictionary<IOperation, PredicateValueKind> GetPredicateValueKindMap() => _predicateValueKindCacheBuilder.ToImmutable();
1043public TAbstractAnalysisValue GetCachedAbstractValue(IOperation operation)
1077protected void CacheAbstractValue(IOperation operation, TAbstractAnalysisValue value)
1087protected NullAbstractValue GetNullAbstractValue(IOperation operation) => GetPointsToAbstractValue(operation).NullState;
1089protected virtual CopyAbstractValue GetCopyAbstractValue(IOperation operation)
1101protected virtual PointsToAbstractValue GetPointsToAbstractValue(IOperation operation)
1113protected virtual ValueContentAbstractValue GetValueContentAbstractValue(IOperation operation)
1125protected ImmutableHashSet<AbstractLocation> GetEscapedLocations(IOperation operation)
1209protected virtual TAbstractAnalysisValue ComputeAnalysisValueForReferenceOperation(IOperation operation, TAbstractAnalysisValue defaultValue)
1245IOperation sourceOperand,
1248IOperation operation,
1384private void PerformPredicateAnalysis(IOperation operation)
1493var current = operation.Parent;
1513var current = operation.Parent;
1542private void PerformPredicateAnalysisCore(IOperation operation, TAnalysisData targetAnalysisData)
1713IOperation? leftOperand = null;
1714IOperation? rightOperand = null;
1786bool IsNotNullWhenFalse(IOperation operation)
1804bool IsNotNullWhenTrue(IOperation operation)
1823protected virtual void SetPredicateValueKind(IOperation operation, TAnalysisData analysisData, PredicateValueKind predicateValueKind)
1892protected virtual PredicateValueKind SetValueForEqualsOrNotEqualsComparisonOperator(IOperation leftOperand, IOperation rightOperand, bool equals, bool isReferenceEquality, TAnalysisData targetAnalysisData)
1898protected virtual PredicateValueKind SetValueForIsNullComparisonOperator(IOperation leftOperand, bool equals, TAnalysisData targetAnalysisData)
1937protected virtual void ProcessThrowValue(IOperation? thrownValue)
1944protected abstract void SetAbstractValueForArrayElementInitializer(IArrayCreationOperation arrayCreation, ImmutableArray<AbstractIndex> indices, ITypeSymbol elementType, IOperation initializer, TAbstractAnalysisValue value);
1945protected abstract void SetAbstractValueForAssignment(IOperation target, IOperation? assignedValueOperation, TAbstractAnalysisValue assignedValue, bool mayBeAssignment = false);
1946protected abstract void SetAbstractValueForTupleElementAssignment(AnalysisEntity tupleElementEntity, IOperation assignedValueOperation, TAbstractAnalysisValue assignedValue);
1947private void HandleFlowCaptureReferenceAssignment(IFlowCaptureReferenceOperation flowCaptureReference, IOperation assignedValueOperation, TAbstractAnalysisValue assignedValue)
1960var target = pointsToValue.LValueCapturedOperations.First();
1971foreach (var capturedOperation in pointsToValue.LValueCapturedOperations)
1982foreach (var capturedOperation in pointsToValue.LValueCapturedOperations)
2022private void ResetValueTypeInstanceAnalysisData(IOperation operation)
2041private void ResetReferenceTypeInstanceAnalysisData(IOperation operation)
2059private void ResetInstanceAnalysisData(IOperation? operation)
2187protected bool TryGetInterproceduralAnalysisResult(IOperation operation, [NotNullWhen(returnValue: true)] out TAnalysisResult? analysisResult)
2202IOperation? instanceReceiver,
2204IOperation originalOperation,
2345var popped = _interproceduralCallStack.Pop();
2572AnalysisEntity? GetAnalysisEntityForFlowCapture(IOperation operation)
2758protected TAbstractAnalysisValue VisitArray(IEnumerable<IOperation> operations, object? argument)
2760foreach (var operation in operations)
2768public override TAbstractAnalysisValue Visit(IOperation? operation, object? argument)
2803private TAbstractAnalysisValue VisitCore(IOperation operation, object? argument)
2822public override TAbstractAnalysisValue DefaultVisit(IOperation operation, object? argument)
2903IOperation elementInitializer = operation.ElementValues[index];
3285using var methodTargetsOptBuilder = PooledHashSet<(IMethodSymbol method, IOperation? instance)>.GetInstance();
3310PooledHashSet<(IMethodSymbol method, IOperation? instance)> methodTargetsOptBuilder,
3315IOperation operation,
3316PooledHashSet<(IMethodSymbol method, IOperation? instance)> methodTargetsOptBuilder,
3321IOperation? operation,
3323PooledHashSet<(IMethodSymbol method, IOperation? instance)> methodTargetsOptBuilder,
3329IOperation? instance;
3377void AddMethodTarget(IMethodSymbol method, IOperation? instance)
3391bool HandleCreationOpt(IOperation? creation)
3436out ImmutableHashSet<(IMethodSymbol method, IOperation? instance)>? resolvedMethodTargets)
3440using var methodTargetsOptBuilder = PooledHashSet<(IMethodSymbol method, IOperation? instance)>.GetInstance();
3533IOperation? visitedInstance,
3536IOperation originalOperation,
3564private ImmutableStack<IOperation>? GetInterproceduralCallStackForOwningSymbol(ISymbol forOwningSymbol)
3577IOperation originalOperation,
3595IOperation originalOperation,
3635public virtual void HandleEnterLockOperation(IOperation lockedObject)
3667foreach (var element in operation.Elements)
3685var assignedValueOperation = operation.Elements[i];
3693foreach (var element in operation.Elements)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\InterproceduralAnalysisConfiguration.cs (1)
95IOperation operation,
src\Analyzers\Core\Analyzers\RemoveUnnecessarySuppressions\SuppressMessageAttributeState.cs (9)
48out ImmutableArray<(string name, IOperation value)> namedAttributeArguments)
50var operation = (model.GetOperation(attributeSyntax, cancellationToken) as IAttributeOperation)?.Operation;
57using var _ = ArrayBuilder<(string name, IOperation value)>.GetInstance(out var builder);
58foreach (var initializer in initializerOperation.Initializers)
72public static bool HasValidScope(ImmutableArray<(string name, IOperation value)> namedAttributeArguments, out TargetScope targetScope)
90ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
94out IOperation? targetValueOperation,
130ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
133[NotNullWhen(returnValue: true)] out IOperation? argumentValueOperation)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (17)
32/// We use this value in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/> to determine whether to bail from analysis or not.
45/// We use this value in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/> to determine whether to bail from analysis or not.
51/// We use this value in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/> to determine whether to bail from analysis or not.
98var firstBlock = context.OperationBlocks[0];
138foreach (var operationBlock in context.OperationBlocks)
149foreach (var operationBlock in context.OperationBlocks)
170var value = expressionStatement.Operation;
253/// delegate escape, and corresponding bail out from flow analysis in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/>.
257private static bool IsHandledDelegateCreationOrAnonymousFunctionTreeShape(IOperation operation)
301/// delegate escape, and corresponding bail out from flow analysis in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/>.
306private static bool IsHandledLocalOrParameterReferenceTreeShape(IOperation operation)
366private bool ShouldAnalyze(IOperation operationBlock, ISymbol owningSymbol, ref bool hasUnknownOperationNoneDescendant)
377foreach (var operation in operationBlock.Descendants())
490foreach (var operationBlock in context.OperationBlocks)
590IOperation unreadWriteOperation,
633bool IsRemovableAssignmentWithoutSideEffects(IOperation unusedSymbolWriteOperation)
657static bool IsRemovableAssignmentValueWithoutSideEffects(IOperation assignmentValue)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (32)
18public static bool IsTargetOfObjectMemberInitializer(this IOperation operation)
34public static ValueUsageInfo GetValueUsageInfo(this IOperation operation, ISymbol containingSymbol)
239public static IMethodSymbol? TryGetContainingAnonymousFunctionOrLocalFunction(this IOperation? operation)
259public static bool IsInLeftOfDeconstructionAssignment(this IOperation operation, [NotNullWhen(true)] out IDeconstructionAssignmentOperation? deconstructionAssignment)
263var previousOperation = operation;
264var current = operation.Parent;
295public static bool IsAnyCompoundAssignment(this IOperation operation)
308public static bool IsInsideCatchRegion(this IOperation operation, ControlFlowGraph cfg)
328foreach (var descendant in block.DescendantOperations())
341public static bool HasAnyOperationDescendant(this ImmutableArray<IOperation> operationBlocks, Func<IOperation, bool> predicate)
343foreach (var operationBlock in operationBlocks)
354public static bool HasAnyOperationDescendant(this IOperation operationBlock, Func<IOperation, bool> predicate)
357public static bool HasAnyOperationDescendant(this IOperation operationBlock, Func<IOperation, bool> predicate, [NotNullWhen(true)] out IOperation? foundOperation)
361foreach (var descendant in operationBlock.DescendantsAndSelf())
374public static bool HasAnyOperationDescendant(this ImmutableArray<IOperation> operationBlocks, OperationKind kind)
377public static bool IsNumericLiteral(this IOperation operation)
380public static bool IsNullLiteral(this IOperation operand)
389public static IOperation? WalkDownConversion(this IOperation? operation)
399public static bool IsSingleThrowNotImplementedOperation([NotNullWhen(true)] this IOperation? firstBlock)
415var firstOp = block.Operations.Length == 1
437static IOperation? TryGetSingleExplicitStatement(ImmutableArray<IOperation> operations)
439IOperation? firstOp = null;
440foreach (var operation in operations)
454static bool IsThrowNotImplementedOperation(INamedTypeSymbol notImplementedExceptionType, IOperation? operation)
461public static IOperation? UnwrapImplicitConversion(this IOperation? value)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.AnalysisData.cs (14)
61protected abstract PooledDictionary<(ISymbol symbol, IOperation operation), bool> SymbolsWriteBuilder { get; }
132public abstract void OnLValueCaptureFound(ISymbol symbol, IOperation operation, CaptureId captureId);
137public abstract void SetTargetsFromSymbolForDelegate(IOperation write, ISymbol symbol);
138public abstract void SetLambdaTargetForDelegate(IOperation write, IFlowAnonymousFunctionOperation lambdaTarget);
139public abstract void SetLocalFunctionTargetForDelegate(IOperation write, IMethodReferenceOperation localFunctionTarget);
140public abstract void SetEmptyInvocationTargetsForDelegate(IOperation write);
141public abstract bool TryGetDelegateInvocationTargets(IOperation write, out ImmutableHashSet<IOperation> targets);
143protected static PooledDictionary<(ISymbol Symbol, IOperation Write), bool> CreateSymbolsWriteMap(
146var symbolsWriteMap = PooledDictionary<(ISymbol Symbol, IOperation Write), bool>.GetInstance();
150protected static PooledDictionary<(ISymbol Symbol, IOperation Write), bool> UpdateSymbolsWriteMap(
151PooledDictionary<(ISymbol Symbol, IOperation Write), bool> symbolsWriteMap,
158(ISymbol, IOperation) key = (parameter, null);
201public void OnWriteReferenceFound(ISymbol symbol, IOperation operation, bool maybeWritten, bool isRef)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.BasicBlockAnalysisData.cs (9)
28private readonly Dictionary<ISymbol, PooledHashSet<IOperation>> _reachingWrites;
74public void ForEachCurrentWrite<TArg>(ISymbol symbol, Action<IOperation, TArg> action, TArg arg)
86public bool ForEachCurrentWrite<TArg>(ISymbol symbol, Func<IOperation, TArg, bool> action, TArg arg)
90foreach (var value in values)
104public void OnWriteReferenceFound(ISymbol symbol, IOperation operation, bool maybeWritten)
108values = PooledHashSet<IOperation>.GetInstance();
223private static void AddEntries(Dictionary<ISymbol, PooledHashSet<IOperation>> result, BasicBlockAnalysisData source)
231values = PooledHashSet<IOperation>.GetInstance();
240foreach (var operation in operations)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.DataFlowAnalyzer.FlowGraphAnalysisData.cs (33)
41private readonly PooledDictionary<CaptureId, PooledHashSet<(ISymbol, IOperation)>> _lValueFlowCapturesMap;
48private readonly PooledDictionary<IOperation, PooledHashSet<IOperation>> _reachingDelegateCreationTargets;
69private readonly PooledDictionary<(int firstBlockOrdinal, int lastBlockOrdinal), PooledHashSet<(ISymbol, IOperation)>> _symbolWritesInsideBlockRangeMap;
77PooledDictionary<(ISymbol symbol, IOperation operation), bool> symbolsWriteMap,
81PooledDictionary<IOperation, PooledHashSet<IOperation>> reachingDelegateCreationTargets,
99_lValueFlowCapturesMap = PooledDictionary<CaptureId, PooledHashSet<(ISymbol, IOperation)>>.GetInstance();
103_symbolWritesInsideBlockRangeMap = PooledDictionary<(int firstBlockOrdinal, int lastBlockOrdinal), PooledHashSet<(ISymbol, IOperation)>>.GetInstance();
110protected override PooledDictionary<(ISymbol symbol, IOperation operation), bool> SymbolsWriteBuilder { get; }
134reachingDelegateCreationTargets: PooledDictionary<IOperation, PooledHashSet<IOperation>>.GetInstance(),
189foreach (var operation in cfg.OriginalOperation.Descendants())
215private PooledHashSet<(ISymbol, IOperation)> GetOrCreateSymbolWritesInBlockRange(int firstBlockOrdinal, int lastBlockOrdinal, CancellationToken cancellationToken)
220var operations = PooledHashSet<IOperation>.GetInstance();
224writesInBlockRange = PooledHashSet<(ISymbol, IOperation)>.GetInstance();
241PooledHashSet<IOperation> operationsBuilder,
248foreach (var operation in cfg.Blocks[i].DescendantOperations())
273void AddDescendantOperationsFromDelegateCreationTargets(PooledHashSet<IOperation> targets)
275foreach (var target in targets)
462public override void OnLValueCaptureFound(ISymbol symbol, IOperation operation, CaptureId captureId)
466captures = PooledHashSet<(ISymbol, IOperation)>.GetInstance();
514public override void SetTargetsFromSymbolForDelegate(IOperation write, ISymbol symbol)
522var targetsBuilder = PooledHashSet<IOperation>.GetInstance();
544foreach (var target in targetsBuilderForSymbolWrite)
561public override void SetLambdaTargetForDelegate(IOperation write, IFlowAnonymousFunctionOperation lambdaTarget)
571public override void SetLocalFunctionTargetForDelegate(IOperation write, IMethodReferenceOperation localFunctionTarget)
583public override void SetEmptyInvocationTargetsForDelegate(IOperation write)
586private void SetReachingDelegateTargetCore(IOperation write, IOperation targetOpt)
588var targetsBuilder = PooledHashSet<IOperation>.GetInstance();
597public override bool TryGetDelegateInvocationTargets(IOperation write, out ImmutableHashSet<IOperation> targets)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.OperationTreeAnalysisData.cs (9)
21PooledDictionary<(ISymbol symbol, IOperation operation), bool> symbolsWriteMap,
34protected override PooledDictionary<(ISymbol symbol, IOperation operation), bool> SymbolsWriteBuilder { get; }
63public override void OnLValueCaptureFound(ISymbol symbol, IOperation operation, CaptureId captureId)
69public override void SetLambdaTargetForDelegate(IOperation write, IFlowAnonymousFunctionOperation lambdaTarget)
71public override void SetLocalFunctionTargetForDelegate(IOperation write, IMethodReferenceOperation localFunctionTarget)
73public override void SetEmptyInvocationTargetsForDelegate(IOperation write)
75public override void SetTargetsFromSymbolForDelegate(IOperation write, ISymbol symbol)
77public override bool TryGetDelegateInvocationTargets(IOperation write, out ImmutableHashSet<IOperation> targets)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (20)
27private IOperation _currentRootOperation;
29private PooledDictionary<IAssignmentOperation, PooledHashSet<(ISymbol, IOperation)>> _pendingWritesMap;
36IEnumerable<IOperation> operations,
51private void Visit(ISymbol containingSymbol, IEnumerable<IOperation> operations, AnalysisData analysisData, CancellationToken cancellationToken)
58_pendingWritesMap = PooledDictionary<IAssignmentOperation, PooledHashSet<(ISymbol, IOperation)>>.GetInstance();
65foreach (var operation in operations)
93private void OnWriteReferenceFound(ISymbol symbol, IOperation operation, ValueUsageInfo valueUsageInfo)
101private void OnLValueCaptureFound(ISymbol symbol, IOperation operation, CaptureId captureId)
107private void OnReferenceFound(ISymbol symbol, IOperation operation)
159private bool MakePendingWrite(IOperation operation, ISymbol symbolOpt)
166var set = PooledHashSet<(ISymbol, IOperation)>.GetInstance();
175set = PooledHashSet<(ISymbol, IOperation)>.GetInstance();
407private void ProcessPossibleDelegateCreationAssignment(ISymbol symbol, IOperation write)
415IOperation initializerValue = null;
431private void ProcessPossibleDelegateCreation(IOperation creation, IOperation write)
433var currentOperation = creation;
497private void AnalyzePossibleDelegateInvocation(IOperation operation)
534foreach (var target in targets)
549void AnalyzeDelegateInvocation(IOperation target)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (44)
46Arguments: [IArgumentOperation { Value: IOperation arg }]
117Operations: [IReturnOperation { ReturnedValue: IOperation returnedValue }]
140Operand: IOperation operand
159LeftOperand: IOperation leftOperand,
160RightOperand: IOperation rightOperand,
380foreach (var assignment in initializer.Initializers)
385Value: IOperation { Syntax: ExpressionSyntax syntax }
421Func<IOperation, T?> captureAssignedSymbol)
433foreach (var operation in body.Operations)
439Target: IOperation assignee,
440Value: IOperation assignment
476private static bool IsSafeAssignment(IOperation operation)
507IEnumerable<IOperation>? statementsToCheck = null;
530if (bodyOps is [IReturnOperation { ReturnedValue: IOperation value }] &&
567IOperation? operation,
606private static IParameterSymbol? GetParamFromArgument(IOperation operation)
609private static ISymbol? GetReferencedSymbolObject(IOperation reference)
625private static bool IsDotEqualsInvocation(IOperation operation)
631Instance: IOperation instance,
632Arguments: [IArgumentOperation { Value: IOperation arg }]
655IOperation operation,
699private static bool ReturnsFalseImmediately(IEnumerable<IOperation> operation)
724IOperation condition,
734(_, IUnaryOperation { OperatorKind: UnaryOperatorKind.Not, Operand: IOperation newCondition })
783IOperation condition,
788IEnumerable<IOperation>? additionalConditions = null)
794(_, IUnaryOperation { OperatorKind: UnaryOperatorKind.Not, Operand: IOperation newCondition })
805LeftOperand: IOperation leftOperation,
806RightOperand: IOperation rightOperation,
817LeftOperand: IOperation leftOperation,
818RightOperand: IOperation rightOperation,
879IEnumerable<IOperation> statementsToCheck,
895IReturnOperation { ReturnedValue: IOperation value } => TryAddEqualizedFieldsForCondition(
899Condition: IOperation condition,
900WhenTrue: IOperation whenTrue,
956ImmutableArray<IOperation> bodyOps,
961[NotNullWhen(true)] out IEnumerable<IOperation>? statementsToCheck)
969Condition: IOperation condition,
970WhenTrue: IOperation whenTrue,
1050IOperation whenTrue,
1051IOperation? whenFalse,
1052IEnumerable<IOperation> otherOps,
1054out IEnumerable<IOperation> remainingStatements)
1069: ImmutableArray<IOperation>.Empty))
ConvertIfToSwitch\AbstractConvertIfToSwitchCodeRefactoringProvider.Analyzer.cs (20)
50public abstract bool HasUnreachableEndPoint(IOperation operation);
71public (ImmutableArray<AnalyzedSwitchSection>, SyntaxNode TargetExpression) AnalyzeIfStatementSequence(ReadOnlySpan<IOperation> operations)
74if (!ParseIfStatementSequence(operations, sections, topLevel: true, out var defaultBodyOpt))
96ReadOnlySpan<IOperation> operations,
99out IOperation? defaultBodyOpt)
132var nextStatement = operations[current];
152private bool ParseIfStatement(IOperation operation, ArrayBuilder<AnalyzedSwitchSection> sections, out IOperation? defaultBodyOpt)
181private bool ParseIfStatementOrBlock(IOperation op, ArrayBuilder<AnalyzedSwitchSection> sections, out IOperation? defaultBodyOpt)
205private bool ParseSwitchLabels(IOperation operation, ArrayBuilder<AnalyzedSwitchLabel> labels)
227private AnalyzedSwitchLabel? ParseSwitchLabel(IOperation operation)
276private AnalyzedPattern? ParsePattern(IOperation operation, ArrayBuilder<TExpressionSyntax> guards)
391bool CheckTargetExpression(IOperation left, IOperation right)
395private static (BoundKind Kind, IOperation Expression, IOperation Value) GetRangeBound(IBinaryOperation op)
441private static bool IsConstant(IOperation operation)
449private bool CheckTargetExpression(IOperation operation)
468private bool CheckConstantType(IOperation operation)
src\Analyzers\Core\Analyzers\RemoveUnnecessarySuppressions\SuppressMessageAttributeState.cs (9)
48out ImmutableArray<(string name, IOperation value)> namedAttributeArguments)
50var operation = (model.GetOperation(attributeSyntax, cancellationToken) as IAttributeOperation)?.Operation;
57using var _ = ArrayBuilder<(string name, IOperation value)>.GetInstance(out var builder);
58foreach (var initializer in initializerOperation.Initializers)
72public static bool HasValidScope(ImmutableArray<(string name, IOperation value)> namedAttributeArguments, out TargetScope targetScope)
90ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
94out IOperation? targetValueOperation,
130ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
133[NotNullWhen(returnValue: true)] out IOperation? argumentValueOperation)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (17)
32/// We use this value in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/> to determine whether to bail from analysis or not.
45/// We use this value in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/> to determine whether to bail from analysis or not.
51/// We use this value in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/> to determine whether to bail from analysis or not.
98var firstBlock = context.OperationBlocks[0];
138foreach (var operationBlock in context.OperationBlocks)
149foreach (var operationBlock in context.OperationBlocks)
170var value = expressionStatement.Operation;
253/// delegate escape, and corresponding bail out from flow analysis in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/>.
257private static bool IsHandledDelegateCreationOrAnonymousFunctionTreeShape(IOperation operation)
301/// delegate escape, and corresponding bail out from flow analysis in <see cref="ShouldAnalyze(IOperation, ISymbol, ref bool)"/>.
306private static bool IsHandledLocalOrParameterReferenceTreeShape(IOperation operation)
366private bool ShouldAnalyze(IOperation operationBlock, ISymbol owningSymbol, ref bool hasUnknownOperationNoneDescendant)
377foreach (var operation in operationBlock.Descendants())
490foreach (var operationBlock in context.OperationBlocks)
590IOperation unreadWriteOperation,
633bool IsRemovableAssignmentWithoutSideEffects(IOperation unusedSymbolWriteOperation)
657static bool IsRemovableAssignmentValueWithoutSideEffects(IOperation assignmentValue)
ValueTracking\ValueTracker.OperationCollector.cs (13)
24public Task VisitAsync(IOperation operation, CancellationToken cancellationToken)
45private async Task VisitReturnDescendentsAsync(IOperation operation, bool allowImplicit, CancellationToken cancellationToken)
48foreach (var returnOperation in returnOperations)
55private async Task VisitDefaultAsync(IOperation operation, CancellationToken cancellationToken)
88private async Task<bool> TryVisitChildrenAsync(IOperation operation, CancellationToken cancellationToken)
90foreach (var child in operation.ChildOperations)
110private Task VisitReferenceAsync(IOperation operation, CancellationToken cancellationToken)
141Task AddReferenceAsync(IOperation operation, CancellationToken cancellationToken)
172private async Task AddOperationAsync(IOperation operation, ISymbol symbol, CancellationToken cancellationToken)
276private static bool IsContainedIn<TContainingOperation>(IOperation? operation) where TContainingOperation : IOperation
279private static bool IsContainedIn<TContainingOperation>(IOperation? operation, [NotNullWhen(returnValue: true)] out TContainingOperation? containingOperation) where TContainingOperation : IOperation