src\Analyzers\Core\Analyzers\RemoveUnnecessarySuppressions\SuppressMessageAttributeState.cs (9)
49out ImmutableArray<(string name, IOperation value)> namedAttributeArguments)
51var operation = (model.GetOperation(attributeSyntax, cancellationToken) as IAttributeOperation)?.Operation;
58using var _ = ArrayBuilder<(string name, IOperation value)>.GetInstance(out var builder);
59foreach (var initializer in initializerOperation.Initializers)
73public static bool HasValidScope(ImmutableArray<(string name, IOperation value)> namedAttributeArguments, out TargetScope targetScope)
91ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
95out IOperation? targetValueOperation,
131ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
134[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\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (17)
24protected abstract SyntaxNode GetPreservedInterpolationExpressionSyntax(IOperation operation);
39var expression = Unwrap(interpolation.Expression);
54private static IOperation? Unwrap(IOperation? expression, bool towardsParent = false)
76IVirtualCharService virtualCharService, ISyntaxFacts syntaxFacts, IOperation expression, out IOperation unwrapped,
82HasNonImplicitInstance(invocation, out var instance) &&
137private static bool IsInvariantCultureReference(IOperation operation)
156private static bool IsInsideFormattableStringInvariant(IOperation operation)
177private static IEnumerable<IOperation> AncestorsAndSelf(IOperation operation)
179for (var current = operation; current is not null; current = current.Parent)
192IOperation expression, out IOperation unwrapped,
197HasNonImplicitInstance(invocation, out var instance))
208var alignmentOp = invocation.Arguments[0].Value;
235private static bool HasNonImplicitInstance(IInvocationOperation invocation, [NotNullWhen(true)] out IOperation? instance)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (32)
18public static bool IsTargetOfObjectMemberInitializer(this IOperation operation)
27public static ValueUsageInfo GetValueUsageInfo(this IOperation operation, ISymbol containingSymbol)
236public static IMethodSymbol? TryGetContainingAnonymousFunctionOrLocalFunction(this IOperation? operation)
256public static bool IsInLeftOfDeconstructionAssignment(this IOperation operation, [NotNullWhen(true)] out IDeconstructionAssignmentOperation? deconstructionAssignment)
260var previousOperation = operation;
261var current = operation.Parent;
292public static bool IsAnyCompoundAssignment(this IOperation operation)
305public static bool IsInsideCatchRegion(this IOperation operation, ControlFlowGraph cfg)
325foreach (var descendant in block.DescendantOperations())
338public static bool HasAnyOperationDescendant(this ImmutableArray<IOperation> operationBlocks, Func<IOperation, bool> predicate)
340foreach (var operationBlock in operationBlocks)
351public static bool HasAnyOperationDescendant(this IOperation operationBlock, Func<IOperation, bool> predicate)
354public static bool HasAnyOperationDescendant(this IOperation operationBlock, Func<IOperation, bool> predicate, [NotNullWhen(true)] out IOperation? foundOperation)
358foreach (var descendant in operationBlock.DescendantsAndSelf())
371public static bool HasAnyOperationDescendant(this ImmutableArray<IOperation> operationBlocks, OperationKind kind)
374public static bool IsNumericLiteral(this IOperation operation)
377public static bool IsNullLiteral(this IOperation operand)
386public static IOperation? WalkDownConversion(this IOperation? operation)
396public static bool IsSingleThrowNotImplementedOperation([NotNullWhen(true)] this IOperation? firstBlock)
412var firstOp = block.Operations.Length == 1
434static IOperation? TryGetSingleExplicitStatement(ImmutableArray<IOperation> operations)
436IOperation? firstOp = null;
437foreach (var operation in operations)
451static bool IsThrowNotImplementedOperation(INamedTypeSymbol notImplementedExceptionType, IOperation? operation)
458public 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)
30private readonly Dictionary<ISymbol, PooledHashSet<IOperation>> _reachingWrites;
76public void ForEachCurrentWrite<TArg>(ISymbol symbol, Action<IOperation, TArg> action, TArg arg)
88public bool ForEachCurrentWrite<TArg>(ISymbol symbol, Func<IOperation, TArg, bool> action, TArg arg)
92foreach (var value in values)
106public void OnWriteReferenceFound(ISymbol symbol, IOperation operation, bool maybeWritten)
110values = PooledHashSet<IOperation>.GetInstance();
225private static void AddEntries(Dictionary<ISymbol, PooledHashSet<IOperation>> result, BasicBlockAnalysisData source)
233values = PooledHashSet<IOperation>.GetInstance();
242foreach (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)
24PooledDictionary<(ISymbol symbol, IOperation operation), bool> symbolsWriteMap,
37protected override PooledDictionary<(ISymbol symbol, IOperation operation), bool> SymbolsWriteBuilder { get; }
66public override void OnLValueCaptureFound(ISymbol symbol, IOperation operation, CaptureId captureId)
72public override void SetLambdaTargetForDelegate(IOperation write, IFlowAnonymousFunctionOperation lambdaTarget)
74public override void SetLocalFunctionTargetForDelegate(IOperation write, IMethodReferenceOperation localFunctionTarget)
76public override void SetEmptyInvocationTargetsForDelegate(IOperation write)
78public override void SetTargetsFromSymbolForDelegate(IOperation write, ISymbol symbol)
80public override bool TryGetDelegateInvocationTargets(IOperation write, out ImmutableHashSet<IOperation> targets)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (20)
28private IOperation _currentRootOperation;
30private PooledDictionary<IAssignmentOperation, PooledHashSet<(ISymbol, IOperation)>> _pendingWritesMap;
37IEnumerable<IOperation> operations,
52private void Visit(ISymbol containingSymbol, IEnumerable<IOperation> operations, AnalysisData analysisData, CancellationToken cancellationToken)
59_pendingWritesMap = PooledDictionary<IAssignmentOperation, PooledHashSet<(ISymbol, IOperation)>>.GetInstance();
66foreach (var operation in operations)
94private void OnWriteReferenceFound(ISymbol symbol, IOperation operation, ValueUsageInfo valueUsageInfo)
102private void OnLValueCaptureFound(ISymbol symbol, IOperation operation, CaptureId captureId)
108private void OnReferenceFound(ISymbol symbol, IOperation operation)
160private bool MakePendingWrite(IOperation operation, ISymbol symbolOpt)
167var set = PooledHashSet<(ISymbol, IOperation)>.GetInstance();
176set = PooledHashSet<(ISymbol, IOperation)>.GetInstance();
408private void ProcessPossibleDelegateCreationAssignment(ISymbol symbol, IOperation write)
416IOperation initializerValue = null;
432private void ProcessPossibleDelegateCreation(IOperation creation, IOperation write)
434var currentOperation = creation;
498private void AnalyzePossibleDelegateInvocation(IOperation operation)
535foreach (var target in targets)
550void 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)
49out ImmutableArray<(string name, IOperation value)> namedAttributeArguments)
51var operation = (model.GetOperation(attributeSyntax, cancellationToken) as IAttributeOperation)?.Operation;
58using var _ = ArrayBuilder<(string name, IOperation value)>.GetInstance(out var builder);
59foreach (var initializer in initializerOperation.Initializers)
73public static bool HasValidScope(ImmutableArray<(string name, IOperation value)> namedAttributeArguments, out TargetScope targetScope)
91ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
95out IOperation? targetValueOperation,
131ImmutableArray<(string name, IOperation value)> namedAttributeArguments,
134[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\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (17)
24protected abstract SyntaxNode GetPreservedInterpolationExpressionSyntax(IOperation operation);
39var expression = Unwrap(interpolation.Expression);
54private static IOperation? Unwrap(IOperation? expression, bool towardsParent = false)
76IVirtualCharService virtualCharService, ISyntaxFacts syntaxFacts, IOperation expression, out IOperation unwrapped,
82HasNonImplicitInstance(invocation, out var instance) &&
137private static bool IsInvariantCultureReference(IOperation operation)
156private static bool IsInsideFormattableStringInvariant(IOperation operation)
177private static IEnumerable<IOperation> AncestorsAndSelf(IOperation operation)
179for (var current = operation; current is not null; current = current.Parent)
192IOperation expression, out IOperation unwrapped,
197HasNonImplicitInstance(invocation, out var instance))
208var alignmentOp = invocation.Arguments[0].Value;
235private static bool HasNonImplicitInstance(IInvocationOperation invocation, [NotNullWhen(true)] out IOperation? instance)
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