src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (36)
27internal static readonly ComputationalComplexityMetrics Default = new(0, 0, 0, 0, 0, ImmutableHashSet<OperationKind>.Empty,
28ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty);
32private readonly ImmutableHashSet<OperationKind> _distinctOperatorKinds;
33private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds;
34private readonly ImmutableHashSet<UnaryOperatorKind> _distinctUnaryOperatorKinds;
35private readonly ImmutableHashSet<CaseKind> _distinctCaseKinds;
36private readonly ImmutableHashSet<ISymbol> _distinctReferencedSymbols;
37private readonly ImmutableHashSet<object> _distinctReferencedConstants;
45ImmutableHashSet<OperationKind> distinctOperatorKinds,
46ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds,
47ImmutableHashSet<UnaryOperatorKind> distinctUnaryOperatorKinds,
48ImmutableHashSet<CaseKind> distinctCaseKinds,
49ImmutableHashSet<ISymbol> distinctReferencedSymbols,
50ImmutableHashSet<object> distinctReferencedConstants)
71ImmutableHashSet<OperationKind> distinctOperatorKinds,
72ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds,
73ImmutableHashSet<UnaryOperatorKind> distinctUnaryOperatorKinds,
74ImmutableHashSet<CaseKind> distinctCaseKinds,
75ImmutableHashSet<ISymbol> distinctReferencedSymbols,
76ImmutableHashSet<object> distinctReferencedConstants)
97ImmutableHashSet<OperationKind>.Builder? distinctOperatorKindsBuilder = null;
98ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null;
99ImmutableHashSet<UnaryOperatorKind>.Builder? distinctUnaryOperatorKindsBuilder = null;
100ImmutableHashSet<CaseKind>.Builder? distinctCaseKindsBuilder = null;
101ImmutableHashSet<ISymbol>.Builder? distinctReferencedSymbolsBuilder = null;
102ImmutableHashSet<object>.Builder? distinctReferencedConstantsBuilder = null;
292distinctOperatorKindsBuilder != null ? distinctOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<OperationKind>.Empty,
293distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty,
294distinctUnaryOperatorKindsBuilder != null ? distinctUnaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<UnaryOperatorKind>.Empty,
295distinctCaseKindsBuilder != null ? distinctCaseKindsBuilder.ToImmutable() : ImmutableHashSet<CaseKind>.Empty,
296distinctReferencedSymbolsBuilder != null ? distinctReferencedSymbolsBuilder.ToImmutable() : ImmutableHashSet<ISymbol>.Empty,
297distinctReferencedConstantsBuilder != null ? distinctReferencedConstantsBuilder.ToImmutable() : ImmutableHashSet<object>.Empty);
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (7)
42internal static void AddCoupledNamedTypes(ImmutableHashSet<INamedTypeSymbol>.Builder builder, WellKnownTypeProvider wellKnownTypeProvider,
43ImmutableHashSet<INamedTypeSymbol> coupledTypes)
51internal static void AddCoupledNamedTypes(ImmutableHashSet<INamedTypeSymbol>.Builder builder, WellKnownTypeProvider wellKnownTypeProvider,
57internal static void AddCoupledNamedTypes(ImmutableHashSet<INamedTypeSymbol>.Builder builder, WellKnownTypeProvider wellKnownTypeProvider,
198ImmutableHashSet<INamedTypeSymbol>.Builder builder,
352private static void AddCoupledNamedTypesCore(ImmutableHashSet<INamedTypeSymbol>.Builder builder, ITypeSymbol typeOpt,
403internal static void RemoveContainingTypes(ISymbol symbol, ImmutableHashSet<INamedTypeSymbol>.Builder coupledTypesBuilder)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\GlobalFlowStateAnalysis\GlobalFlowStateAnalysisValueSet.cs (16)
20ImmutableHashSet<IAbstractAnalysisValue>.Empty, ImmutableHashSet<GlobalFlowStateAnalysisValueSet>.Empty, 0, GlobalFlowStateAnalysisValueSetKind.Unset);
22ImmutableHashSet<IAbstractAnalysisValue>.Empty, ImmutableHashSet<GlobalFlowStateAnalysisValueSet>.Empty, 0, GlobalFlowStateAnalysisValueSetKind.Empty);
24ImmutableHashSet<IAbstractAnalysisValue>.Empty, ImmutableHashSet<GlobalFlowStateAnalysisValueSet>.Empty, 0, GlobalFlowStateAnalysisValueSetKind.Unknown);
27ImmutableHashSet<IAbstractAnalysisValue> analysisValues,
28ImmutableHashSet<GlobalFlowStateAnalysisValueSet> parents,
46ImmutableHashSet<IAbstractAnalysisValue> analysisValues,
47ImmutableHashSet<GlobalFlowStateAnalysisValueSet> parents,
55=> new(ImmutableHashSet.Create(analysisValue), ImmutableHashSet<GlobalFlowStateAnalysisValueSet>.Empty, height: 0, GlobalFlowStateAnalysisValueSetKind.Known);
57public ImmutableHashSet<IAbstractAnalysisValue> AnalysisValues { get; }
58public ImmutableHashSet<GlobalFlowStateAnalysisValueSet> Parents { get; }
110var negatedAnalysisValues = ImmutableHashSet.Create(AnalysisValues.Single().GetNegatedValue());
139return GlobalFlowStateAnalysisValueSet.Create(ImmutableHashSet<IAbstractAnalysisValue>.Empty, parentsBuilder.ToImmutable(), height);
142static GlobalFlowStateAnalysisValueSet GetNegateValueFromParents(ImmutableHashSet<GlobalFlowStateAnalysisValueSet> parents)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysis.PointsToDataFlowOperationVisitor.cs (17)
28private readonly PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder> _escapedOperationLocationsBuilder;
29private readonly PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder> _escapedReturnValueLocationsBuilder;
30private readonly PooledDictionary<AnalysisEntity, ImmutableHashSet<AbstractLocation>.Builder> _escapedEntityLocationsBuilder;
42_escapedOperationLocationsBuilder = PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder>.GetInstance();
43_escapedReturnValueLocationsBuilder = PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder>.GetInstance();
44_escapedEntityLocationsBuilder = PooledDictionary<AnalysisEntity, ImmutableHashSet<AbstractLocation>.Builder>.GetInstance();
51public ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> GetEscapedLocationsThroughOperationsMap()
54public ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> GetEscapedLocationsThroughReturnValuesMap()
57public ImmutableDictionary<AnalysisEntity, ImmutableHashSet<AbstractLocation>> GetEscapedLocationsThroughEntitiesMap()
60private static ImmutableDictionary<T, ImmutableHashSet<AbstractLocation>> GetEscapedAbstractLocationsMapAndFreeBuilder<T>(
61PooledDictionary<T, ImmutableHashSet<AbstractLocation>.Builder> escapedLocationsBuilder)
68return ImmutableDictionary<T, ImmutableHashSet<AbstractLocation>>.Empty;
71var builder = ImmutableDictionary.CreateBuilder<T, ImmutableHashSet<AbstractLocation>>();
630private void HandleEscapingOperation(IOperation escapingOperation, IOperation escapedInstance, PooledDictionary<IOperation, ImmutableHashSet<AbstractLocation>.Builder> builder)
649PooledDictionary<TKey, ImmutableHashSet<AbstractLocation>.Builder> escapedLocationsBuilder,
671PooledDictionary<TKey, ImmutableHashSet<AbstractLocation>.Builder> escapedLocationsBuilder,
701private void HandleEscapingLocations(PointsToAbstractValue pointsToValueOfEscapedInstance, ImmutableHashSet<AbstractLocation>.Builder builder)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysisResult.cs (14)
14private readonly ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> _escapedLocationsThroughOperationsMap;
15private readonly ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> _escapedLocationsThroughReturnValuesMap;
16private readonly ImmutableDictionary<AnalysisEntity, ImmutableHashSet<AbstractLocation>> _escapedLocationsThroughEntitiesMap;
17private readonly ImmutableHashSet<AnalysisEntity> _trackedEntities;
18private readonly ImmutableHashSet<PointsToAbstractValue> _trackedPointsToValues;
22ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> escapedLocationsThroughOperationsMap,
23ImmutableDictionary<IOperation, ImmutableHashSet<AbstractLocation>> escapedLocationsThroughReturnValuesMap,
24ImmutableDictionary<AnalysisEntity, ImmutableHashSet<AbstractLocation>> escapedLocationsThroughEntitiesMap,
37public ImmutableHashSet<AbstractLocation> GetEscapedAbstractLocations(IOperation operation)
42public ImmutableHashSet<AbstractLocation> GetEscapedAbstractLocations(AnalysisEntity analysisEntity)
45private static ImmutableHashSet<AbstractLocation> GetEscapedAbstractLocations<TKey>(
47ImmutableDictionary<TKey, ImmutableHashSet<AbstractLocation>> map)
50if (map.TryGetValue(key, out var escapedLocations))
55return ImmutableHashSet<AbstractLocation>.Empty;
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\TaintedDataAnalysis\PooledHashSetExtensions.cs (72)
50?? ImmutableHashSet<string>.Empty,
53?.Select(o => new KeyValuePair<string, ImmutableHashSet<string>>(o.Method, o.Parameters.ToImmutableHashSet()))
55?? ImmutableDictionary<string, ImmutableHashSet<string>>.Empty);
67taintedProperties: ImmutableHashSet<string>.Empty,
68transferProperties: ImmutableHashSet<string>.Empty,
72ImmutableHashSet<(MethodMatcher, ImmutableHashSet<string>)>.Empty,
74ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(PointsToCheck, string)>)>.Empty,
76ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(ValueContentCheck, string)>)>.Empty,
78ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
94taintedProperties: ImmutableHashSet<string>.Empty,
95transferProperties: ImmutableHashSet<string>.Empty,
99ImmutableHashSet<(MethodMatcher, ImmutableHashSet<string>)>.Empty,
101ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(PointsToCheck, string)>)>.Empty,
103ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(ValueContentCheck, string)>)>.Empty,
105ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
123?? ImmutableHashSet<string>.Empty,
124transferProperties: ImmutableHashSet<string>.Empty,
126ImmutableHashSet<ParameterMatcher>.Empty,
129?.Select<string, (MethodMatcher, ImmutableHashSet<string>)>(o =>
132ImmutableHashSet<string>.Empty.Add(TaintedTargetValue.Return)
135?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<string>)>.Empty,
137ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(PointsToCheck, string)>)>.Empty,
139ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(ValueContentCheck, string)>)>.Empty,
141ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
173?? ImmutableHashSet<string>.Empty,
175?? ImmutableHashSet<string>.Empty,
177ImmutableHashSet<ParameterMatcher>.Empty,
179ImmutableHashSet<(MethodMatcher, ImmutableHashSet<string>)>.Empty,
185?? ImmutableHashSet<(PointsToCheck, string)>.Empty
188?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(PointsToCheck, string)>)>.Empty,
194?? ImmutableHashSet<(ValueContentCheck, string)>.Empty
197?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(ValueContentCheck, string)>)>.Empty,
205?? ImmutableHashSet<(string, string)>.Empty))
207?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
230?? ImmutableHashSet<string>.Empty,
231transferProperties: ImmutableHashSet<string>.Empty,
233ImmutableHashSet<ParameterMatcher>.Empty,
235ImmutableHashSet<(MethodMatcher, ImmutableHashSet<string>)>.Empty,
243?? ImmutableHashSet<(PointsToCheck, string)>.Empty
246?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(PointsToCheck, string)>)>.Empty,
254?? ImmutableHashSet<(ValueContentCheck, string)>.Empty
257?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(ValueContentCheck, string)>)>.Empty,
259ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
280?.Select<string, (MethodMatcher, ImmutableHashSet<(string, string)>)>(o =>
283ImmutableHashSet<(string, string)>.Empty))
285?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
287?? ImmutableHashSet<string>.Empty);
310?? ImmutableHashSet<(string, string)>.Empty))
312?? ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)>.Empty,
314?? ImmutableHashSet<string>.Empty);
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\TaintedDataAnalysis\SourceInfo.cs (22)
42ImmutableHashSet<string> taintedProperties,
43ImmutableHashSet<ParameterMatcher> taintedArguments,
44ImmutableHashSet<(MethodMatcher, ImmutableHashSet<string>)> taintedMethods,
45ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(PointsToCheck, string)>)> taintedMethodsNeedsPointsToAnalysis,
46ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(ValueContentCheck, string)>)> taintedMethodsNeedsValueContentAnalysis,
47ImmutableHashSet<string> transferProperties,
48ImmutableHashSet<(MethodMatcher, ImmutableHashSet<(string, string)>)> transferMethods,
90public ImmutableHashSet<string> TransferProperties { get; }
95public ImmutableHashSet<string> TaintedProperties { get; }
101public ImmutableHashSet<(MethodMatcher MethodMatcher, ImmutableHashSet<string> TaintedTargets)> TaintedMethods { get; }
106public ImmutableHashSet<ParameterMatcher> TaintedArguments { get; }
129public ImmutableHashSet<(MethodMatcher MethodMatcher, ImmutableHashSet<(PointsToCheck PointsToCheck, string TaintedTarget)>)> TaintedMethodsNeedsPointsToAnalysis { get; }
152public ImmutableHashSet<(MethodMatcher MethodMatcher, ImmutableHashSet<(ValueContentCheck ValueContentCheck, string TaintedTarget)>)> TaintedMethodsNeedsValueContentAnalysis { get; }
171public ImmutableHashSet<(MethodMatcher MethodMatcher, ImmutableHashSet<(string IfTaintedParameter, string ThenTaintedTarget)>)> TransferMethods { get; }
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\TaintedDataAnalysis\TaintedDataAnalysis.TaintedDataOperationVisitor.cs (10)
34private Dictionary<SymbolAccess, (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SymbolAccess>.Builder SourceOrigins)> TaintedSourcesBySink { get; }
46foreach (KeyValuePair<SymbolAccess, (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SymbolAccess>.Builder SourceOrigins)> kvp in this.TaintedSourcesBySink)
541if (!this.TaintedSourcesBySink.TryGetValue(sink, out (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SymbolAccess>.Builder SourceOrigins) data))
585out (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SymbolAccess>.Builder SourceOrigins) data))
644foreach ((MethodMatcher methodMatcher, ImmutableHashSet<(string source, string end)> sourceToEnds) in sanitizerInfo.SanitizingMethods)
700else if (sinkInfo.SinkMethodParameters.TryGetValue(method.MetadataName, out var sinkParameters)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\TaintedDataAnalysis\TaintedDataConfig.cs (28)
33private static ImmutableDictionary<SinkKind, ImmutableHashSet<SourceInfo>> s_sinkKindToSourceInfo
34= ImmutableDictionary.Create<SinkKind, ImmutableHashSet<SourceInfo>>();
39private static ImmutableDictionary<SinkKind, ImmutableHashSet<SanitizerInfo>> s_sinkKindToSanitizerInfo
40= ImmutableDictionary.Create<SinkKind, ImmutableHashSet<SanitizerInfo>>();
105PooledDictionary<ImmutableHashSet<SourceInfo>, Lazy<TaintedDataSymbolMap<SourceInfo>>>.GetInstance(out var sourcesToSymbolMap);
107PooledDictionary<ImmutableHashSet<SanitizerInfo>, Lazy<TaintedDataSymbolMap<SanitizerInfo>>>.GetInstance(out var sanitizersToSymbolMap);
111PooledDictionary<(ImmutableHashSet<SourceInfo> SourceInfos, ImmutableHashSet<SanitizerInfo> SanitizerInfos), (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SinkInfo>.Builder SinkInfos)>.GetInstance(out var sourceSanitizersToSinks);
116ImmutableHashSet<SourceInfo> sources = GetSourceInfos(sinkKind);
127ImmutableHashSet<SanitizerInfo> sanitizers = GetSanitizerInfos(sinkKind);
138ImmutableHashSet<SinkInfo> sinks = GetSinkInfos(sinkKind);
139if (!sourceSanitizersToSinks.TryGetValue((sources, sanitizers), out (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SinkInfo>.Builder SinkInfos) sinksPair))
149foreach (KeyValuePair<(ImmutableHashSet<SourceInfo> SourceInfos, ImmutableHashSet<SanitizerInfo> SanitizerInfos), (ImmutableHashSet<SinkKind>.Builder SinkKinds, ImmutableHashSet<SinkInfo>.Builder SinkInfos)> kvp in sourceSanitizersToSinks)
151ImmutableHashSet<SinkInfo> sinks = kvp.Value.SinkInfos.ToImmutable();
205private static ImmutableHashSet<SourceInfo> GetSourceInfos(SinkKind sinkKind)
207if (s_sinkKindToSourceInfo.TryGetValue(sinkKind, out var sourceInfo))
252return ImmutableHashSet<SourceInfo>.Empty;
258private static ImmutableHashSet<SanitizerInfo> GetSanitizerInfos(SinkKind sinkKind)
260if (s_sinkKindToSanitizerInfo.TryGetValue(sinkKind, out var sanitizerInfo))
308return ImmutableHashSet<SanitizerInfo>.Empty;
314private static ImmutableHashSet<SinkInfo> GetSinkInfos(SinkKind sinkKind)
363return ImmutableHashSet<SinkInfo>.Empty;
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\SetAbstractDomain.cs (14)
11public class SetAbstractDomain<T> : AbstractDomain<ImmutableHashSet<T>>
17public override ImmutableHashSet<T> Bottom => ImmutableHashSet<T>.Empty;
19public override int Compare(ImmutableHashSet<T> oldValue, ImmutableHashSet<T> newValue, bool assertMonotonicity)
51public override ImmutableHashSet<T> Merge(ImmutableHashSet<T> value1, ImmutableHashSet<T> value2) => MergeOrIntersect(value1, value2, merge: true);
53public ImmutableHashSet<T> Intersect(ImmutableHashSet<T> value1, ImmutableHashSet<T> value2) => MergeOrIntersect(value1, value2, merge: false);
55private static ImmutableHashSet<T> MergeOrIntersect(ImmutableHashSet<T> value1, ImmutableHashSet<T> value2, bool merge)
Diagnostics\IDiagnosticAnalyzerService.cs (2)
53Task<ImmutableArray<DiagnosticData>> GetDiagnosticsForIdsAsync(Project project, DocumentId? documentId, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeLocalDocumentDiagnostics, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken);
70Task<ImmutableArray<DiagnosticData>> GetProjectDiagnosticsForIdsAsync(Project project, ImmutableHashSet<string>? diagnosticIds, Func<DiagnosticAnalyzer, bool>? shouldIncludeAnalyzer, bool includeNonLocalDocumentDiagnostics, CancellationToken cancellationToken);
src\Analyzers\Core\Analyzers\IDEDiagnosticIdToOptionMappingHelper.cs (8)
22private static readonly ConcurrentDictionary<string, ImmutableHashSet<IOption2>> s_diagnosticIdToOptionMap = new();
23private static readonly ConcurrentDictionary<string, ConcurrentDictionary<string, ImmutableHashSet<IOption2>>> s_diagnosticIdToLanguageSpecificOptionsMap = new();
26public static bool TryGetMappedOptions(string diagnosticId, string language, [NotNullWhen(true)] out ImmutableHashSet<IOption2>? options)
38public static void AddOptionMapping(string diagnosticId, ImmutableHashSet<IOption2> options)
70var map = s_diagnosticIdToLanguageSpecificOptionsMap.GetOrAdd(language, _ => new ConcurrentDictionary<string, ImmutableHashSet<IOption2>>());
83private static void AddOptionMapping(ConcurrentDictionary<string, ImmutableHashSet<IOption2>> map, string diagnosticId, ImmutableHashSet<IOption2> options)
87Debug.Assert(!map.TryGetValue(diagnosticId, out var existingOptions) || options.SetEquals(existingOptions));