147 references to RuleKind
Microsoft.CodeAnalysis.CSharp.NetAnalyzers (6)
Microsoft.CodeQuality.Analyzers\Maintainability\CSharpUseCrossPlatformIntrinsicsAnalyzer.cs (1)
18
protected override bool IsSupported(IInvocationOperation invocation,
RuleKind
ruleKind)
Microsoft.CodeQuality.Analyzers\Maintainability\CSharpUseCrossPlatformIntrinsicsFixer.cs (5)
20
protected override SyntaxNode ReplaceNode(SyntaxNode currentNode, SyntaxGenerator generator,
RuleKind
ruleKind)
24
RuleKind
.op_ExclusiveOr => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: true, generator.ExclusiveOrExpression),
25
RuleKind
.op_LeftShift => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: false, generator.LeftShiftExpression),
26
RuleKind
.op_RightShift => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: false, generator.RightShiftExpression),
27
RuleKind
.op_UnsignedRightShift => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: false, generator.UnsignedRightShiftExpression),
Microsoft.CodeAnalysis.NetAnalyzers (141)
Microsoft.CodeQuality.Analyzers\Maintainability\UseCrossPlatformIntrinsicsAnalyzer.cs (127)
29
Enumerable.Range(0, (int)
RuleKind
.Count)
30
.Select(i => CreateDiagnosticDescriptor((
RuleKind
)i))
34
Enumerable.Range(0, (int)
RuleKind
.Count)
38
builder[nameof(
RuleKind
)] = ((
RuleKind
)i).ToString();
45
private static DiagnosticDescriptor CreateDiagnosticDescriptor(
RuleKind
ruleKind) => DiagnosticDescriptorHelper.Create(
63
protected virtual bool IsSupported(IInvocationOperation invocation,
RuleKind
ruleKind)
72
RuleKind
.op_Addition or
73
RuleKind
.op_BitwiseAnd or
74
RuleKind
.op_BitwiseOr or
75
RuleKind
.op_ExclusiveOr or
76
RuleKind
.op_Multiply or
77
RuleKind
.op_Subtraction => IsValidBinaryOperatorMethodInvocation(invocation, isCommutative: true),
79
RuleKind
.op_Division => IsValidBinaryOperatorMethodInvocation(invocation, isCommutative: false),
81
RuleKind
.op_LeftShift or
82
RuleKind
.op_RightShift or
83
RuleKind
.op_UnsignedRightShift => IsValidShiftOperatorMethodInvocation(invocation),
85
RuleKind
.op_OnesComplement or
86
RuleKind
.op_UnaryNegation => IsValidUnaryOperatorMethodInvocation(invocation),
140
Dictionary<IMethodSymbol,
RuleKind
> methodSymbols = new Dictionary<IMethodSymbol,
RuleKind
>(SymbolEqualityComparer.Default);
144
AddBinaryOperatorMethods(methodSymbols, "Add", armAdvSimdTypeSymbol,
RuleKind
.op_Addition);
145
AddBinaryOperatorMethods(methodSymbols, "AddScalar", armAdvSimdTypeSymbol,
RuleKind
.op_Addition, [SpecialType.System_Int64, SpecialType.System_UInt64, SpecialType.System_Double]);
146
AddBinaryOperatorMethods(methodSymbols, "And", armAdvSimdTypeSymbol,
RuleKind
.op_BitwiseAnd);
147
AddBinaryOperatorMethods(methodSymbols, "DivideScalar", armAdvSimdTypeSymbol,
RuleKind
.op_Division, [SpecialType.System_Double]);
148
AddBinaryOperatorMethods(methodSymbols, "Multiply", armAdvSimdTypeSymbol,
RuleKind
.op_Multiply);
149
AddBinaryOperatorMethods(methodSymbols, "MultiplyScalar", armAdvSimdTypeSymbol,
RuleKind
.op_Multiply, [SpecialType.System_Double]);
150
AddBinaryOperatorMethods(methodSymbols, "Or", armAdvSimdTypeSymbol,
RuleKind
.op_BitwiseOr);
151
AddBinaryOperatorMethods(methodSymbols, "Subtract", armAdvSimdTypeSymbol,
RuleKind
.op_Subtraction);
152
AddBinaryOperatorMethods(methodSymbols, "SubtractScalar", armAdvSimdTypeSymbol,
RuleKind
.op_Subtraction, [SpecialType.System_Int64, SpecialType.System_UInt64, SpecialType.System_Double]);
153
AddBinaryOperatorMethods(methodSymbols, "Xor", armAdvSimdTypeSymbol,
RuleKind
.op_ExclusiveOr);
155
AddShiftOperatorMethods(methodSymbols, "ShiftLeftLogical", armAdvSimdTypeSymbol,
RuleKind
.op_LeftShift);
156
AddShiftOperatorMethods(methodSymbols, "ShiftLeftLogicalScalar", armAdvSimdTypeSymbol,
RuleKind
.op_LeftShift, [SpecialType.System_Int64, SpecialType.System_UInt64]);
157
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", armAdvSimdTypeSymbol,
RuleKind
.op_RightShift);
158
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmeticScalar", armAdvSimdTypeSymbol,
RuleKind
.op_RightShift, [SpecialType.System_Int64, SpecialType.System_UInt64]);
159
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogical", armAdvSimdTypeSymbol,
RuleKind
.op_UnsignedRightShift);
160
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogicalScalar", armAdvSimdTypeSymbol,
RuleKind
.op_UnsignedRightShift, [SpecialType.System_Int64, SpecialType.System_UInt64]);
162
AddUnaryOperatorMethods(methodSymbols, "Negate", armAdvSimdTypeSymbol,
RuleKind
.op_UnaryNegation);
163
AddUnaryOperatorMethods(methodSymbols, "NegateScalar", armAdvSimdTypeSymbol,
RuleKind
.op_UnaryNegation, [SpecialType.System_Double]);
164
AddUnaryOperatorMethods(methodSymbols, "Not", armAdvSimdTypeSymbol,
RuleKind
.op_OnesComplement);
169
AddBinaryOperatorMethods(methodSymbols, "Add", armAdvSimdArm64TypeSymbol,
RuleKind
.op_Addition);
170
AddBinaryOperatorMethods(methodSymbols, "Divide", armAdvSimdArm64TypeSymbol,
RuleKind
.op_Division);
171
AddBinaryOperatorMethods(methodSymbols, "Multiply", armAdvSimdArm64TypeSymbol,
RuleKind
.op_Multiply);
172
AddBinaryOperatorMethods(methodSymbols, "Subtract", armAdvSimdArm64TypeSymbol,
RuleKind
.op_Subtraction);
174
AddUnaryOperatorMethods(methodSymbols, "Negate", armAdvSimdArm64TypeSymbol,
RuleKind
.op_UnaryNegation);
175
AddUnaryOperatorMethods(methodSymbols, "NegateScalar", armAdvSimdArm64TypeSymbol,
RuleKind
.op_UnaryNegation, [SpecialType.System_Int64]);
180
AddBinaryOperatorMethods(methodSymbols, "Add", wasmPackedSimdTypeSymbol,
RuleKind
.op_Addition);
181
AddBinaryOperatorMethods(methodSymbols, "And", wasmPackedSimdTypeSymbol,
RuleKind
.op_BitwiseAnd);
182
AddBinaryOperatorMethods(methodSymbols, "Divide", wasmPackedSimdTypeSymbol,
RuleKind
.op_Division);
183
AddBinaryOperatorMethods(methodSymbols, "Multiply", wasmPackedSimdTypeSymbol,
RuleKind
.op_Multiply);
184
AddBinaryOperatorMethods(methodSymbols, "Or", wasmPackedSimdTypeSymbol,
RuleKind
.op_BitwiseOr);
185
AddBinaryOperatorMethods(methodSymbols, "Subtract", wasmPackedSimdTypeSymbol,
RuleKind
.op_Subtraction);
186
AddBinaryOperatorMethods(methodSymbols, "Xor", wasmPackedSimdTypeSymbol,
RuleKind
.op_ExclusiveOr);
188
AddShiftOperatorMethods(methodSymbols, "ShiftLeft", wasmPackedSimdTypeSymbol,
RuleKind
.op_LeftShift);
189
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", wasmPackedSimdTypeSymbol,
RuleKind
.op_RightShift);
190
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogical", wasmPackedSimdTypeSymbol,
RuleKind
.op_UnsignedRightShift);
192
AddUnaryOperatorMethods(methodSymbols, "Negate", wasmPackedSimdTypeSymbol,
RuleKind
.op_UnaryNegation);
193
AddUnaryOperatorMethods(methodSymbols, "Not", wasmPackedSimdTypeSymbol,
RuleKind
.op_OnesComplement);
198
AddBinaryOperatorMethods(methodSymbols, "Add", x86AvxTypeSymbol,
RuleKind
.op_Addition);
199
AddBinaryOperatorMethods(methodSymbols, "And", x86AvxTypeSymbol,
RuleKind
.op_BitwiseAnd);
200
AddBinaryOperatorMethods(methodSymbols, "Divide", x86AvxTypeSymbol,
RuleKind
.op_Division);
201
AddBinaryOperatorMethods(methodSymbols, "Multiply", x86AvxTypeSymbol,
RuleKind
.op_Multiply);
202
AddBinaryOperatorMethods(methodSymbols, "Or", x86AvxTypeSymbol,
RuleKind
.op_BitwiseOr);
203
AddBinaryOperatorMethods(methodSymbols, "Subtract", x86AvxTypeSymbol,
RuleKind
.op_Subtraction);
204
AddBinaryOperatorMethods(methodSymbols, "Xor", x86AvxTypeSymbol,
RuleKind
.op_ExclusiveOr);
209
AddBinaryOperatorMethods(methodSymbols, "Add", x86Avx2TypeSymbol,
RuleKind
.op_Addition);
210
AddBinaryOperatorMethods(methodSymbols, "And", x86Avx2TypeSymbol,
RuleKind
.op_BitwiseAnd);
211
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Avx2TypeSymbol,
RuleKind
.op_Multiply);
212
AddBinaryOperatorMethods(methodSymbols, "Or", x86Avx2TypeSymbol,
RuleKind
.op_BitwiseOr);
213
AddBinaryOperatorMethods(methodSymbols, "Subtract", x86Avx2TypeSymbol,
RuleKind
.op_Subtraction);
214
AddBinaryOperatorMethods(methodSymbols, "Xor", x86Avx2TypeSymbol,
RuleKind
.op_ExclusiveOr);
216
AddShiftOperatorMethods(methodSymbols, "ShiftLeftLogical", x86Avx2TypeSymbol,
RuleKind
.op_LeftShift);
217
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", x86Avx2TypeSymbol,
RuleKind
.op_RightShift);
218
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogical", x86Avx2TypeSymbol,
RuleKind
.op_UnsignedRightShift);
223
AddBinaryOperatorMethods(methodSymbols, "Add", x86Avx512BWTypeSymbol,
RuleKind
.op_Addition);
224
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Avx512BWTypeSymbol,
RuleKind
.op_Multiply);
225
AddBinaryOperatorMethods(methodSymbols, "Subtract", x86Avx512BWTypeSymbol,
RuleKind
.op_Subtraction);
227
AddShiftOperatorMethods(methodSymbols, "ShiftLeftLogical", x86Avx512BWTypeSymbol,
RuleKind
.op_LeftShift);
228
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", x86Avx512BWTypeSymbol,
RuleKind
.op_RightShift);
229
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogical", x86Avx512BWTypeSymbol,
RuleKind
.op_UnsignedRightShift);
234
AddBinaryOperatorMethods(methodSymbols, "And", x86Avx512DQTypeSymbol,
RuleKind
.op_BitwiseAnd);
235
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Avx512DQTypeSymbol,
RuleKind
.op_Multiply);
236
AddBinaryOperatorMethods(methodSymbols, "Or", x86Avx512DQTypeSymbol,
RuleKind
.op_BitwiseOr);
237
AddBinaryOperatorMethods(methodSymbols, "Xor", x86Avx512DQTypeSymbol,
RuleKind
.op_ExclusiveOr);
242
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Avx512DQVLTypeSymbol,
RuleKind
.op_Multiply);
247
AddBinaryOperatorMethods(methodSymbols, "Add", x86Avx512FTypeSymbol,
RuleKind
.op_Addition);
248
AddBinaryOperatorMethods(methodSymbols, "And", x86Avx512FTypeSymbol,
RuleKind
.op_BitwiseAnd);
249
AddBinaryOperatorMethods(methodSymbols, "Divide", x86Avx512FTypeSymbol,
RuleKind
.op_Division);
250
AddBinaryOperatorMethods(methodSymbols, "Multiply", x86Avx512FTypeSymbol,
RuleKind
.op_Multiply, [SpecialType.System_Single, SpecialType.System_Double]);
251
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Avx512FTypeSymbol,
RuleKind
.op_Multiply);
252
AddBinaryOperatorMethods(methodSymbols, "Or", x86Avx512FTypeSymbol,
RuleKind
.op_BitwiseOr);
253
AddBinaryOperatorMethods(methodSymbols, "Subtract", x86Avx512FTypeSymbol,
RuleKind
.op_Subtraction);
254
AddBinaryOperatorMethods(methodSymbols, "Xor", x86Avx512FTypeSymbol,
RuleKind
.op_ExclusiveOr);
256
AddShiftOperatorMethods(methodSymbols, "ShiftLeftLogical", x86Avx512FTypeSymbol,
RuleKind
.op_LeftShift);
257
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", x86Avx512FTypeSymbol,
RuleKind
.op_RightShift);
258
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogical", x86Avx512FTypeSymbol,
RuleKind
.op_UnsignedRightShift);
263
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", x86Avx512FVLTypeSymbol,
RuleKind
.op_RightShift);
268
AddBinaryOperatorMethods(methodSymbols, "Add", x86SseTypeSymbol,
RuleKind
.op_Addition);
269
AddBinaryOperatorMethods(methodSymbols, "And", x86SseTypeSymbol,
RuleKind
.op_BitwiseAnd);
270
AddBinaryOperatorMethods(methodSymbols, "Divide", x86SseTypeSymbol,
RuleKind
.op_Division);
271
AddBinaryOperatorMethods(methodSymbols, "Multiply", x86SseTypeSymbol,
RuleKind
.op_Multiply);
272
AddBinaryOperatorMethods(methodSymbols, "Or", x86SseTypeSymbol,
RuleKind
.op_BitwiseOr);
273
AddBinaryOperatorMethods(methodSymbols, "Subtract", x86SseTypeSymbol,
RuleKind
.op_Subtraction);
274
AddBinaryOperatorMethods(methodSymbols, "Xor", x86SseTypeSymbol,
RuleKind
.op_ExclusiveOr);
279
AddBinaryOperatorMethods(methodSymbols, "Add", x86Sse2TypeSymbol,
RuleKind
.op_Addition);
280
AddBinaryOperatorMethods(methodSymbols, "And", x86Sse2TypeSymbol,
RuleKind
.op_BitwiseAnd);
281
AddBinaryOperatorMethods(methodSymbols, "Divide", x86Sse2TypeSymbol,
RuleKind
.op_Division);
282
AddBinaryOperatorMethods(methodSymbols, "Multiply", x86Sse2TypeSymbol,
RuleKind
.op_Multiply, [SpecialType.System_Double]);
283
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Sse2TypeSymbol,
RuleKind
.op_Multiply);
284
AddBinaryOperatorMethods(methodSymbols, "Or", x86Sse2TypeSymbol,
RuleKind
.op_BitwiseOr);
285
AddBinaryOperatorMethods(methodSymbols, "Subtract", x86Sse2TypeSymbol,
RuleKind
.op_Subtraction);
286
AddBinaryOperatorMethods(methodSymbols, "Xor", x86Sse2TypeSymbol,
RuleKind
.op_ExclusiveOr);
288
AddShiftOperatorMethods(methodSymbols, "ShiftLeftLogical", x86Sse2TypeSymbol,
RuleKind
.op_LeftShift);
289
AddShiftOperatorMethods(methodSymbols, "ShiftRightArithmetic", x86Sse2TypeSymbol,
RuleKind
.op_RightShift);
290
AddShiftOperatorMethods(methodSymbols, "ShiftRightLogical", x86Sse2TypeSymbol,
RuleKind
.op_UnsignedRightShift);
295
AddBinaryOperatorMethods(methodSymbols, "MultiplyLow", x86Sse41TypeSymbol,
RuleKind
.op_Multiply);
303
static void AddBinaryOperatorMethods(Dictionary<IMethodSymbol,
RuleKind
> methodSymbols, string name, INamedTypeSymbol typeSymbol,
RuleKind
ruleKind, params SpecialType[] supportedTypes)
318
methodSymbols.AddRange(members.Select((m) => new KeyValuePair<IMethodSymbol,
RuleKind
>(m, ruleKind)));
321
static void AddShiftOperatorMethods(Dictionary<IMethodSymbol,
RuleKind
> methodSymbols, string name, INamedTypeSymbol typeSymbol,
RuleKind
ruleKind, params SpecialType[] supportedTypes)
337
methodSymbols.AddRange(members.Select((m) => new KeyValuePair<IMethodSymbol,
RuleKind
>(m, ruleKind)));
340
static void AddUnaryOperatorMethods(Dictionary<IMethodSymbol,
RuleKind
> methodSymbols, string name, INamedTypeSymbol typeSymbol,
RuleKind
ruleKind, params SpecialType[] supportedTypes)
354
methodSymbols.AddRange(members.Select((m) => new KeyValuePair<IMethodSymbol,
RuleKind
>(m, ruleKind)));
358
private void AnalyzeInvocation(OperationAnalysisContext context, Dictionary<IMethodSymbol,
RuleKind
> methodSymbols)
367
if (methodSymbols.TryGetValue(targetMethod, out
RuleKind
ruleKind) &&
Microsoft.CodeQuality.Analyzers\Maintainability\UseCrossPlatformIntrinsicsFixer.cs (14)
16
using RuleKind = UseCrossPlatformIntrinsicsAnalyzer.
RuleKind
;
32
if (!diagnostic.Properties.TryGetValue(nameof(
RuleKind
), out string? ruleKindName))
34
Debug.Fail($"Found diagnostic without an associated {nameof(
RuleKind
)} property.");
38
if (!Enum.TryParse(ruleKindName, out
RuleKind
ruleKind))
40
Debug.Fail($"Found diagnostic with an unrecognized {nameof(
RuleKind
)} property: {ruleKindName}.");
48
protected virtual SyntaxNode ReplaceNode(SyntaxNode currentNode, SyntaxGenerator generator,
RuleKind
ruleKind)
52
RuleKind
.op_Addition => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: true, generator.AddExpression),
53
RuleKind
.op_BitwiseAnd => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: true, generator.BitwiseAndExpression),
54
RuleKind
.op_BitwiseOr => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: true, generator.BitwiseOrExpression),
55
RuleKind
.op_Division => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: false, generator.DivideExpression),
56
RuleKind
.op_Multiply => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: true, generator.MultiplyExpression),
57
RuleKind
.op_OnesComplement => ReplaceWithUnaryOperator(currentNode, generator, generator.BitwiseNotExpression),
58
RuleKind
.op_Subtraction => ReplaceWithBinaryOperator(currentNode, generator, isCommutative: false, generator.SubtractExpression),
59
RuleKind
.op_UnaryNegation => ReplaceWithUnaryOperator(currentNode, generator, generator.NegateExpression),