Skip to content

Commit 0e398fe

Browse files
committed
C#: Use the DB types and replace the abstract class implementation.
1 parent 4de006e commit 0e398fe

File tree

5 files changed

+80
-131
lines changed

5 files changed

+80
-131
lines changed

csharp/ql/lib/semmle/code/csharp/exprs/ArithmeticOperation.qll

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class BinaryArithmeticOperation extends ArithmeticOperation, BinaryOperation, @b
107107
/**
108108
* An addition operation, for example `x + y`.
109109
*/
110-
class AddExpr extends BinaryArithmeticOperation, @add_expr {
110+
class AddExpr extends BinaryArithmeticOperation, AddOperation, @add_expr {
111111
override string getOperator() { result = "+" }
112112

113113
override string getAPrimaryQlClass() { result = "AddExpr" }
@@ -116,7 +116,7 @@ class AddExpr extends BinaryArithmeticOperation, @add_expr {
116116
/**
117117
* A subtraction operation, for example `x - y`.
118118
*/
119-
class SubExpr extends BinaryArithmeticOperation, @sub_expr {
119+
class SubExpr extends BinaryArithmeticOperation, SubOperation, @sub_expr {
120120
override string getOperator() { result = "-" }
121121

122122
override string getAPrimaryQlClass() { result = "SubExpr" }
@@ -125,7 +125,7 @@ class SubExpr extends BinaryArithmeticOperation, @sub_expr {
125125
/**
126126
* A multiplication operation, for example `x * y`.
127127
*/
128-
class MulExpr extends BinaryArithmeticOperation, @mul_expr {
128+
class MulExpr extends BinaryArithmeticOperation, MulOperation, @mul_expr {
129129
override string getOperator() { result = "*" }
130130

131131
override string getAPrimaryQlClass() { result = "MulExpr" }
@@ -134,22 +134,16 @@ class MulExpr extends BinaryArithmeticOperation, @mul_expr {
134134
/**
135135
* A division operation, for example `x / y`.
136136
*/
137-
class DivExpr extends BinaryArithmeticOperation, @div_expr {
137+
class DivExpr extends BinaryArithmeticOperation, DivOperation, @div_expr {
138138
override string getOperator() { result = "/" }
139139

140-
/** Gets the numerator of this division operation. */
141-
Expr getNumerator() { result = this.getLeftOperand() }
142-
143-
/** Gets the denominator of this division operation. */
144-
Expr getDenominator() { result = this.getRightOperand() }
145-
146140
override string getAPrimaryQlClass() { result = "DivExpr" }
147141
}
148142

149143
/**
150144
* A remainder operation, for example `x % y`.
151145
*/
152-
class RemExpr extends BinaryArithmeticOperation, @rem_expr {
146+
class RemExpr extends BinaryArithmeticOperation, RemOperation, @rem_expr {
153147
override string getOperator() { result = "%" }
154148

155149
override string getAPrimaryQlClass() { result = "RemExpr" }

csharp/ql/lib/semmle/code/csharp/exprs/Assignment.qll

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class AssignArithmeticOperation extends AssignCallOperation, @assign_arith_expr
9999
/**
100100
* An addition assignment operation, for example `x += y`.
101101
*/
102-
class AssignAddExpr extends AssignArithmeticOperation, @assign_add_expr {
102+
class AssignAddExpr extends AssignArithmeticOperation, AddOperation, @assign_add_expr {
103103
override string getOperator() { result = "+=" }
104104

105105
override string getAPrimaryQlClass() { result = "AssignAddExpr" }
@@ -108,7 +108,7 @@ class AssignAddExpr extends AssignArithmeticOperation, @assign_add_expr {
108108
/**
109109
* A subtraction assignment operation, for example `x -= y`.
110110
*/
111-
class AssignSubExpr extends AssignArithmeticOperation, @assign_sub_expr {
111+
class AssignSubExpr extends AssignArithmeticOperation, SubOperation, @assign_sub_expr {
112112
override string getOperator() { result = "-=" }
113113

114114
override string getAPrimaryQlClass() { result = "AssignSubExpr" }
@@ -117,7 +117,7 @@ class AssignSubExpr extends AssignArithmeticOperation, @assign_sub_expr {
117117
/**
118118
* An multiplication assignment operation, for example `x *= y`.
119119
*/
120-
class AssignMulExpr extends AssignArithmeticOperation, @assign_mul_expr {
120+
class AssignMulExpr extends AssignArithmeticOperation, MulOperation, @assign_mul_expr {
121121
override string getOperator() { result = "*=" }
122122

123123
override string getAPrimaryQlClass() { result = "AssignMulExpr" }
@@ -126,7 +126,7 @@ class AssignMulExpr extends AssignArithmeticOperation, @assign_mul_expr {
126126
/**
127127
* An division assignment operation, for example `x /= y`.
128128
*/
129-
class AssignDivExpr extends AssignArithmeticOperation, @assign_div_expr {
129+
class AssignDivExpr extends AssignArithmeticOperation, DivOperation, @assign_div_expr {
130130
override string getOperator() { result = "/=" }
131131

132132
override string getAPrimaryQlClass() { result = "AssignDivExpr" }
@@ -135,7 +135,7 @@ class AssignDivExpr extends AssignArithmeticOperation, @assign_div_expr {
135135
/**
136136
* A remainder assignment operation, for example `x %= y`.
137137
*/
138-
class AssignRemExpr extends AssignArithmeticOperation, @assign_rem_expr {
138+
class AssignRemExpr extends AssignArithmeticOperation, RemOperation, @assign_rem_expr {
139139
override string getOperator() { result = "%=" }
140140

141141
override string getAPrimaryQlClass() { result = "AssignRemExpr" }
@@ -155,7 +155,7 @@ class AssignBitwiseOperation extends AssignCallOperation, @assign_bitwise_expr {
155155
/**
156156
* A bitwise-and assignment operation, for example `x &= y`.
157157
*/
158-
class AssignAndExpr extends AssignBitwiseOperation, @assign_and_expr {
158+
class AssignAndExpr extends AssignBitwiseOperation, BitwiseAndOperation, @assign_and_expr {
159159
override string getOperator() { result = "&=" }
160160

161161
override string getAPrimaryQlClass() { result = "AssignAndExpr" }
@@ -164,7 +164,7 @@ class AssignAndExpr extends AssignBitwiseOperation, @assign_and_expr {
164164
/**
165165
* A bitwise-or assignment operation, for example `x |= y`.
166166
*/
167-
class AssignOrExpr extends AssignBitwiseOperation, @assign_or_expr {
167+
class AssignOrExpr extends AssignBitwiseOperation, BitwiseOrOperation, @assign_or_expr {
168168
override string getOperator() { result = "|=" }
169169

170170
override string getAPrimaryQlClass() { result = "AssignOrExpr" }
@@ -173,7 +173,7 @@ class AssignOrExpr extends AssignBitwiseOperation, @assign_or_expr {
173173
/**
174174
* A bitwise exclusive-or assignment operation, for example `x ^= y`.
175175
*/
176-
class AssignXorExpr extends AssignBitwiseOperation, @assign_xor_expr {
176+
class AssignXorExpr extends AssignBitwiseOperation, BitwiseXorOperation, @assign_xor_expr {
177177
override string getOperator() { result = "^=" }
178178

179179
override string getAPrimaryQlClass() { result = "AssignXorExpr" }
@@ -182,7 +182,7 @@ class AssignXorExpr extends AssignBitwiseOperation, @assign_xor_expr {
182182
/**
183183
* A left-shift assignment operation, for example `x <<= y`.
184184
*/
185-
class AssignLeftShiftExpr extends AssignBitwiseOperation, @assign_lshift_expr {
185+
class AssignLeftShiftExpr extends AssignBitwiseOperation, LeftShiftOperation, @assign_lshift_expr {
186186
override string getOperator() { result = "<<=" }
187187

188188
override string getAPrimaryQlClass() { result = "AssignLeftShiftExpr" }
@@ -191,7 +191,7 @@ class AssignLeftShiftExpr extends AssignBitwiseOperation, @assign_lshift_expr {
191191
/**
192192
* A right-shift assignment operation, for example `x >>= y`.
193193
*/
194-
class AssignRightShiftExpr extends AssignBitwiseOperation, @assign_rshift_expr {
194+
class AssignRightShiftExpr extends AssignBitwiseOperation, RightShiftOperation, @assign_rshift_expr {
195195
override string getOperator() { result = ">>=" }
196196

197197
override string getAPrimaryQlClass() { result = "AssignRightShiftExpr" }
@@ -200,7 +200,9 @@ class AssignRightShiftExpr extends AssignBitwiseOperation, @assign_rshift_expr {
200200
/**
201201
* An unsigned right-shift assignment operation, for example `x >>>= y`.
202202
*/
203-
class AssignUnsignedRightShiftExpr extends AssignBitwiseOperation, @assign_urshift_expr {
203+
class AssignUnsignedRightShiftExpr extends AssignBitwiseOperation, UnsignedRightShiftOperation,
204+
@assign_urshift_expr
205+
{
204206
override string getOperator() { result = ">>>=" }
205207

206208
override string getAPrimaryQlClass() { result = "AssignUnsignedRightShiftExpr" }
@@ -273,7 +275,7 @@ class RemoveEventExpr extends AddOrRemoveEventExpr, @remove_event_expr {
273275
/**
274276
* A null-coalescing assignment operation, for example `x ??= y`.
275277
*/
276-
class AssignCoalesceExpr extends AssignOperation, @assign_coalesce_expr {
278+
class AssignCoalesceExpr extends AssignOperation, NullCoalescingOperation, @assign_coalesce_expr {
277279
override string toString() { result = "... ??= ..." }
278280

279281
override string getAPrimaryQlClass() { result = "AssignCoalesceExpr" }

csharp/ql/lib/semmle/code/csharp/exprs/BitwiseOperation.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class BinaryBitwiseOperation extends BitwiseOperation, BinaryOperation, @bin_bit
4141
/**
4242
* A left-shift operation, for example `x << y`.
4343
*/
44-
class LeftShiftExpr extends BinaryBitwiseOperation, @lshift_expr {
44+
class LeftShiftExpr extends BinaryBitwiseOperation, LeftShiftOperation, @lshift_expr {
4545
override string getOperator() { result = "<<" }
4646

4747
override string getAPrimaryQlClass() { result = "LeftShiftExpr" }
@@ -50,7 +50,7 @@ class LeftShiftExpr extends BinaryBitwiseOperation, @lshift_expr {
5050
/**
5151
* A right-shift operation, for example `x >> y`.
5252
*/
53-
class RightShiftExpr extends BinaryBitwiseOperation, @rshift_expr {
53+
class RightShiftExpr extends BinaryBitwiseOperation, RightShiftOperation, @rshift_expr {
5454
override string getOperator() { result = ">>" }
5555

5656
override string getAPrimaryQlClass() { result = "RightShiftExpr" }
@@ -59,7 +59,9 @@ class RightShiftExpr extends BinaryBitwiseOperation, @rshift_expr {
5959
/**
6060
* An unsigned right-shift operation, for example `x >>> y`.
6161
*/
62-
class UnsignedRightShiftExpr extends BinaryBitwiseOperation, @urshift_expr {
62+
class UnsignedRightShiftExpr extends BinaryBitwiseOperation, UnsignedRightShiftOperation,
63+
@urshift_expr
64+
{
6365
override string getOperator() { result = ">>>" }
6466

6567
override string getAPrimaryQlClass() { result = "UnsignedRightShiftExpr" }
@@ -68,7 +70,7 @@ class UnsignedRightShiftExpr extends BinaryBitwiseOperation, @urshift_expr {
6870
/**
6971
* A bitwise-and operation, for example `x & y`.
7072
*/
71-
class BitwiseAndExpr extends BinaryBitwiseOperation, @bit_and_expr {
73+
class BitwiseAndExpr extends BinaryBitwiseOperation, BitwiseAndOperation, @bit_and_expr {
7274
override string getOperator() { result = "&" }
7375

7476
override string getAPrimaryQlClass() { result = "BitwiseAndExpr" }
@@ -77,7 +79,7 @@ class BitwiseAndExpr extends BinaryBitwiseOperation, @bit_and_expr {
7779
/**
7880
* A bitwise-or operation, for example `x | y`.
7981
*/
80-
class BitwiseOrExpr extends BinaryBitwiseOperation, @bit_or_expr {
82+
class BitwiseOrExpr extends BinaryBitwiseOperation, BitwiseOrOperation, @bit_or_expr {
8183
override string getOperator() { result = "|" }
8284

8385
override string getAPrimaryQlClass() { result = "BitwiseOrExpr" }
@@ -86,7 +88,7 @@ class BitwiseOrExpr extends BinaryBitwiseOperation, @bit_or_expr {
8688
/**
8789
* A bitwise exclusive-or operation, for example `x ^ y`.
8890
*/
89-
class BitwiseXorExpr extends BinaryBitwiseOperation, @bit_xor_expr {
91+
class BitwiseXorExpr extends BinaryBitwiseOperation, BitwiseXorOperation, @bit_xor_expr {
9092
override string getOperator() { result = "^" }
9193

9294
override string getAPrimaryQlClass() { result = "BitwiseXorExpr" }

csharp/ql/lib/semmle/code/csharp/exprs/LogicalOperation.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class LogicalOrExpr extends BinaryLogicalOperation, @log_or_expr {
6565
* }
6666
* ```
6767
*/
68-
class NullCoalescingExpr extends BinaryLogicalOperation, @null_coalescing_expr {
68+
class NullCoalescingExpr extends BinaryLogicalOperation, NullCoalescingOperation,
69+
@null_coalescing_expr
70+
{
6971
override string getOperator() { result = "??" }
7072

7173
override string getAPrimaryQlClass() { result = "NullCoalescingExpr" }

csharp/ql/lib/semmle/code/csharp/exprs/Operation.qll

Lines changed: 50 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,119 +4,68 @@
44

55
import Expr
66

7-
/** A binary operation that involves a null-coalescing operation. */
8-
abstract private class NullCoalescingOperationImpl extends BinaryOperation { }
9-
10-
final class NullCoalescingOperation = NullCoalescingOperationImpl;
11-
12-
private class AddNullCoalescingExpr extends NullCoalescingOperationImpl instanceof NullCoalescingExpr
13-
{ }
14-
15-
private class AddAssignCoalesceExpr extends NullCoalescingOperationImpl instanceof AssignCoalesceExpr
16-
{ }
17-
18-
/** A binary operations that involves an addition operation. */
19-
abstract private class AddOperationImpl extends BinaryOperation { }
20-
21-
final class AddOperation = AddOperationImpl;
22-
23-
private class AddAddExpr extends AddOperationImpl instanceof AddExpr { }
24-
25-
private class AddAssignExpr extends AddOperationImpl instanceof AssignAddExpr { }
26-
27-
/** A binary operation that involves a subtraction operation. */
28-
abstract private class SubOperationImpl extends BinaryOperation { }
29-
30-
final class SubOperation = SubOperationImpl;
31-
32-
private class AddSubExpr extends SubOperationImpl instanceof SubExpr { }
33-
34-
private class AddSubAssignExpr extends SubOperationImpl instanceof AssignSubExpr { }
35-
36-
/** A binary operation that involves a multiplication operation. */
37-
abstract private class MulOperationImpl extends BinaryOperation { }
7+
/**
8+
* An addition operation, either `x + y` or `x += y`.
9+
*/
10+
class AddOperation extends BinaryOperation, @add_operation { }
3811

39-
final class MulOperation = MulOperationImpl;
12+
/**
13+
* A subtraction operation, either `x - y` or `x -= y`.
14+
*/
15+
class SubOperation extends BinaryOperation, @sub_operation { }
4016

41-
private class AddMulExpr extends MulOperationImpl instanceof MulExpr { }
17+
/**
18+
* A multiplication operation, either `x * y` or `x *= y`.
19+
*/
20+
class MulOperation extends BinaryOperation, @mul_operation { }
4221

43-
private class AddMulAssignExpr extends MulOperationImpl instanceof AssignMulExpr { }
22+
/**
23+
* A division operation, either `x / y` or `x /= y`.
24+
*/
25+
class DivOperation extends BinaryOperation, @div_operation {
26+
/** Gets the numerator of this division operation. */
27+
Expr getNumerator() { result = this.getLeftOperand() }
4428

45-
/** A binary operation that involves a division operation. */
46-
abstract private class DivOperationImpl extends BinaryOperation {
4729
/** Gets the denominator of this division operation. */
4830
Expr getDenominator() { result = this.getRightOperand() }
4931
}
5032

51-
final class DivOperation = DivOperationImpl;
52-
53-
private class AddDivExpr extends DivOperationImpl instanceof DivExpr { }
54-
55-
private class AddDivAssignExpr extends DivOperationImpl instanceof AssignDivExpr { }
56-
57-
/** A binary operation that involves a remainder operation. */
58-
abstract private class RemOperationImpl extends BinaryOperation { }
59-
60-
final class RemOperation = RemOperationImpl;
61-
62-
private class AddRemExpr extends RemOperationImpl instanceof RemExpr { }
63-
64-
private class AddRemAssignExpr extends RemOperationImpl instanceof AssignRemExpr { }
65-
66-
/** A binary operation that involves a bitwise AND operation. */
67-
abstract private class BitwiseAndOperationImpl extends BinaryOperation { }
68-
69-
final class BitwiseAndOperation = BitwiseAndOperationImpl;
70-
71-
private class AddBitwiseAndExpr extends BitwiseAndOperationImpl instanceof BitwiseAndExpr { }
72-
73-
private class AddAssignBitwiseAndExpr extends BitwiseAndOperationImpl instanceof AssignAndExpr { }
74-
75-
/** A binary operation that involves a bitwise OR operation. */
76-
abstract private class BitwiseOrOperationImpl extends BinaryOperation { }
77-
78-
final class BitwiseOrOperation = BitwiseOrOperationImpl;
79-
80-
private class AddBitwiseOrExpr extends BitwiseOrOperationImpl instanceof BitwiseOrExpr { }
81-
82-
private class AddAssignBitwiseOrExpr extends BitwiseOrOperationImpl instanceof AssignOrExpr { }
83-
84-
/** A binary operation that involves a bitwise XOR operation. */
85-
abstract private class BitwiseXorOperationImpl extends BinaryOperation { }
86-
87-
final class BitwiseXorOperation = BitwiseXorOperationImpl;
88-
89-
private class AddBitwiseXorExpr extends BitwiseXorOperationImpl instanceof BitwiseXorExpr { }
90-
91-
private class AddAssignBitwiseXorExpr extends BitwiseXorOperationImpl instanceof AssignXorExpr { }
92-
93-
/** A binary operation that involves a left shift operation. */
94-
abstract private class LeftShiftOperationImpl extends BinaryOperation { }
95-
96-
final class LeftShiftOperation = LeftShiftOperationImpl;
97-
98-
private class AddLeftShiftExpr extends LeftShiftOperationImpl instanceof LeftShiftExpr { }
99-
100-
private class AddAssignLeftShiftExpr extends LeftShiftOperationImpl instanceof AssignLeftShiftExpr {
101-
}
102-
103-
/** A binary operation that involves a right shift operation. */
104-
abstract private class RightShiftOperationImpl extends BinaryOperation { }
33+
/**
34+
* A remainder operation, either `x % y` or `x %= y`.
35+
*/
36+
class RemOperation extends BinaryOperation, @rem_operation { }
10537

106-
final class RightShiftOperation = RightShiftOperationImpl;
38+
/**
39+
* A bitwise-and operation, either `x & y` or `x &= y`.
40+
*/
41+
class BitwiseAndOperation extends BinaryOperation, @and_operation { }
10742

108-
private class AddRightShiftExpr extends RightShiftOperationImpl instanceof RightShiftExpr { }
43+
/**
44+
* A bitwise-or operation, either `x | y` or `x |= y`.
45+
*/
46+
class BitwiseOrOperation extends BinaryOperation, @or_operation { }
10947

110-
private class AddAssignRightShiftExpr extends RightShiftOperationImpl instanceof AssignRightShiftExpr
111-
{ }
48+
/**
49+
* A bitwise exclusive-or operation, either `x ^ y` or `x ^= y`.
50+
*/
51+
class BitwiseXorOperation extends BinaryOperation, @xor_operation { }
11252

113-
/** A binary operation that involves a unsigned right shift operation. */
114-
abstract private class UnsignedRightShiftOperationImpl extends BinaryOperation { }
53+
/**
54+
* A left-shift operation, either `x << y` or `x <<= y`.
55+
*/
56+
class LeftShiftOperation extends BinaryOperation, @lshift_operation { }
11557

116-
final class UnsignedRightShiftOperation = UnsignedRightShiftOperationImpl;
58+
/**
59+
* A right-shift operation, either `x >> y` or `x >>= y`.
60+
*/
61+
class RightShiftOperation extends BinaryOperation, @rshift_operation { }
11762

118-
private class AddUnsignedRightShiftExpr extends UnsignedRightShiftOperationImpl instanceof UnsignedRightShiftExpr
119-
{ }
63+
/**
64+
* An unsigned right-shift operation, either `x >>> y` or `x >>>= y`.
65+
*/
66+
class UnsignedRightShiftOperation extends BinaryOperation, @urshift_operation { }
12067

121-
private class AddAssignUnsignedRightShiftExpr extends UnsignedRightShiftOperationImpl instanceof AssignUnsignedRightShiftExpr
122-
{ }
68+
/**
69+
* A null-coalescing operation, either `x ?? y` or `x ??= y`.
70+
*/
71+
class NullCoalescingOperation extends BinaryOperation, @null_coalescing_operation { }

0 commit comments

Comments
 (0)