Skip to content

Commit 8b7535a

Browse files
committed
Swift: Don't use abstract classes.
1 parent 2cf65c7 commit 8b7535a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

swift/ql/lib/codeql/swift/elements/expr/ArithmeticOperation.qll

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,23 @@ class ArithmeticOperation extends Expr {
3131
* a + b
3232
* ```
3333
*/
34-
abstract class BinaryArithmeticOperation extends BinaryExpr { }
34+
class BinaryArithmeticOperation extends BinaryExpr {
35+
BinaryArithmeticOperation() {
36+
this instanceof AddExpr or
37+
this instanceof SubExpr or
38+
this instanceof MulExpr or
39+
this instanceof DivExpr or
40+
this instanceof RemExpr
41+
}
42+
}
3543

3644
/**
3745
* An add expression.
3846
* ```
3947
* a + b
4048
* ```
4149
*/
42-
class AddExpr extends BinaryArithmeticOperation {
50+
class AddExpr extends BinaryExpr {
4351
AddExpr() { this.getFunction().(DotSyntaxCallExpr).getStaticTarget().getName() = "+(_:_:)" }
4452
}
4553

@@ -49,7 +57,7 @@ class AddExpr extends BinaryArithmeticOperation {
4957
* a - b
5058
* ```
5159
*/
52-
class SubExpr extends BinaryArithmeticOperation {
60+
class SubExpr extends BinaryExpr {
5361
SubExpr() { this.getFunction().(DotSyntaxCallExpr).getStaticTarget().getName() = "-(_:_:)" }
5462
}
5563

@@ -59,7 +67,7 @@ class SubExpr extends BinaryArithmeticOperation {
5967
* a * b
6068
* ```
6169
*/
62-
class MulExpr extends BinaryArithmeticOperation {
70+
class MulExpr extends BinaryExpr {
6371
MulExpr() { this.getFunction().(DotSyntaxCallExpr).getStaticTarget().getName() = "*(_:_:)" }
6472
}
6573

@@ -69,7 +77,7 @@ class MulExpr extends BinaryArithmeticOperation {
6977
* a / b
7078
* ```
7179
*/
72-
class DivExpr extends BinaryArithmeticOperation {
80+
class DivExpr extends BinaryExpr {
7381
DivExpr() { this.getFunction().(DotSyntaxCallExpr).getStaticTarget().getName() = "/(_:_:)" }
7482
}
7583

@@ -79,7 +87,7 @@ class DivExpr extends BinaryArithmeticOperation {
7987
* a % b
8088
* ```
8189
*/
82-
class RemExpr extends BinaryArithmeticOperation {
90+
class RemExpr extends BinaryExpr {
8391
RemExpr() { this.getFunction().(DotSyntaxCallExpr).getStaticTarget().getName() = "%(_:_:)" }
8492
}
8593

@@ -89,14 +97,16 @@ class RemExpr extends BinaryArithmeticOperation {
8997
* -a
9098
* ```
9199
*/
92-
abstract class UnaryArithmeticOperation extends PrefixUnaryExpr { }
100+
class UnaryArithmeticOperation extends PrefixUnaryExpr {
101+
UnaryArithmeticOperation() { this instanceof UnaryMinusExpr }
102+
}
93103

94104
/**
95105
* A unary minus expression.
96106
* ```
97107
* -a
98108
* ```
99109
*/
100-
class UnaryMinusExpr extends UnaryArithmeticOperation {
110+
class UnaryMinusExpr extends PrefixUnaryExpr {
101111
UnaryMinusExpr() { this.getFunction().(DotSyntaxCallExpr).getStaticTarget().getName() = "-(_:)" }
102112
}

0 commit comments

Comments
 (0)