Skip to content

Commit 5d08a0e

Browse files
authored
Merge pull request #2558 from MathiasVP/ast-classes-should-not-be-abstract
C++: Ast classes should not be abstract
2 parents 8dff8e7 + 603b1c2 commit 5d08a0e

File tree

11 files changed

+7548
-3496
lines changed

11 files changed

+7548
-3496
lines changed

cpp/ql/src/semmle/code/cpp/exprs/ArithmeticOperation.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import semmle.code.cpp.exprs.Expr
22

33
/**
44
* A C/C++ unary arithmetic operation.
5-
*
6-
* This is an abstract base QL class.
75
*/
8-
abstract class UnaryArithmeticOperation extends UnaryOperation { }
6+
class UnaryArithmeticOperation extends UnaryOperation, @un_arith_op_expr { }
97

108
/**
119
* A C/C++ unary minus expression.
@@ -53,12 +51,12 @@ class ConjugationExpr extends UnaryArithmeticOperation, @conjugation {
5351
/**
5452
* A C/C++ `++` or `--` expression (either prefix or postfix).
5553
*
56-
* This is the abstract base QL class for increment and decrement operations.
54+
* This is the base QL class for increment and decrement operations.
5755
*
5856
* Note that this does not include calls to user-defined `operator++`
5957
* or `operator--`.
6058
*/
61-
abstract class CrementOperation extends UnaryArithmeticOperation {
59+
class CrementOperation extends UnaryArithmeticOperation, @crement_expr {
6260
override predicate mayBeImpure() { any() }
6361

6462
override predicate mayBeGloballyImpure() {
@@ -75,28 +73,28 @@ abstract class CrementOperation extends UnaryArithmeticOperation {
7573
*
7674
* Note that this does not include calls to user-defined `operator++`.
7775
*/
78-
abstract class IncrementOperation extends CrementOperation { }
76+
class IncrementOperation extends CrementOperation, @increment_expr { }
7977

8078
/**
8179
* A C/C++ `--` expression (either prefix or postfix).
8280
*
8381
* Note that this does not include calls to user-defined `operator--`.
8482
*/
85-
abstract class DecrementOperation extends CrementOperation { }
83+
class DecrementOperation extends CrementOperation, @decrement_expr { }
8684

8785
/**
8886
* A C/C++ `++` or `--` prefix expression.
8987
*
9088
* Note that this does not include calls to user-defined operators.
9189
*/
92-
abstract class PrefixCrementOperation extends CrementOperation { }
90+
class PrefixCrementOperation extends CrementOperation, @prefix_crement_expr { }
9391

9492
/**
9593
* A C/C++ `++` or `--` postfix expression.
9694
*
9795
* Note that this does not include calls to user-defined operators.
9896
*/
99-
abstract class PostfixCrementOperation extends CrementOperation { }
97+
class PostfixCrementOperation extends CrementOperation, @postfix_crement_expr { }
10098

10199
/**
102100
* A C/C++ prefix increment expression, as in `++x`.
@@ -199,7 +197,7 @@ class ImaginaryPartExpr extends UnaryArithmeticOperation, @imagpartexpr {
199197
*
200198
* This is an abstract base QL class for all binary arithmetic operations.
201199
*/
202-
abstract class BinaryArithmeticOperation extends BinaryOperation { }
200+
class BinaryArithmeticOperation extends BinaryOperation, @bin_arith_op_expr { }
203201

204202
/**
205203
* A C/C++ add expression.
@@ -404,7 +402,7 @@ class MaxExpr extends BinaryArithmeticOperation, @maxexpr {
404402
/**
405403
* A C/C++ pointer arithmetic operation.
406404
*/
407-
abstract class PointerArithmeticOperation extends BinaryArithmeticOperation { }
405+
class PointerArithmeticOperation extends BinaryArithmeticOperation, @p_arith_op_expr { }
408406

409407
/**
410408
* A C/C++ pointer add expression.

cpp/ql/src/semmle/code/cpp/exprs/Assignment.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import semmle.code.cpp.exprs.BitwiseOperation
77
* etc. A C++ overloaded assignment operation looks syntactically identical but is instead
88
* a `FunctionCall`.
99
*
10-
* This is an abstract root QL class for all (non-overloaded) assignments.
10+
* This is a QL base class for all (non-overloaded) assignments.
1111
*/
12-
abstract class Assignment extends Operation {
12+
class Assignment extends Operation, @assign_expr {
1313
/** Gets the _lvalue_ of this assignment. */
1414
Expr getLValue() { this.hasChild(result, 0) }
1515

@@ -47,15 +47,15 @@ class AssignExpr extends Assignment, @assignexpr {
4747
/**
4848
* A non-overloaded binary assignment operation other than `=`.
4949
*/
50-
abstract class AssignOperation extends Assignment {
50+
class AssignOperation extends Assignment, @assign_op_expr {
5151
override string toString() { result = "... " + this.getOperator() + " ..." }
5252
}
5353

5454
/**
5555
* A non-overloaded arithmetic assignment operation on a non-pointer _lvalue_:
5656
* `+=`, `-=`, `*=`, `/=` and `%=`.
5757
*/
58-
abstract class AssignArithmeticOperation extends AssignOperation { }
58+
class AssignArithmeticOperation extends AssignOperation, @assign_arith_expr { }
5959

6060
/**
6161
* A non-overloaded `+=` assignment expression on a non-pointer _lvalue_.
@@ -121,7 +121,7 @@ class AssignRemExpr extends AssignArithmeticOperation, @assignremexpr {
121121
* A non-overloaded bitwise assignment operation:
122122
* `&=`, `|=`, `^=`, `<<=`, and `>>=`.
123123
*/
124-
abstract class AssignBitwiseOperation extends AssignOperation { }
124+
class AssignBitwiseOperation extends AssignOperation, @assign_bitwise_expr { }
125125

126126
/**
127127
* A non-overloaded AND (`&=`) assignment expression.

cpp/ql/src/semmle/code/cpp/exprs/BitwiseOperation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import semmle.code.cpp.exprs.Expr
33
/**
44
* A C/C++ unary bitwise operation.
55
*/
6-
abstract class UnaryBitwiseOperation extends UnaryOperation { }
6+
class UnaryBitwiseOperation extends UnaryOperation, @un_bitwise_op_expr { }
77

88
/**
99
* A C/C++ complement expression.
@@ -22,7 +22,7 @@ class ComplementExpr extends UnaryBitwiseOperation, @complementexpr {
2222
/**
2323
* A C/C++ binary bitwise operation.
2424
*/
25-
abstract class BinaryBitwiseOperation extends BinaryOperation { }
25+
class BinaryBitwiseOperation extends BinaryOperation, @bin_bitwise_op_expr { }
2626

2727
/**
2828
* A C/C++ left shift expression.

cpp/ql/src/semmle/code/cpp/exprs/ComparisonOperation.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import semmle.code.cpp.exprs.Expr
33
/**
44
* A C/C++ comparison operation, that is, either an equality operation or a relational operation.
55
*
6-
* This is a QL abstract base class for all comparisons.
6+
* This is a QL base class for all comparisons.
77
*/
8-
abstract class ComparisonOperation extends BinaryOperation { }
8+
class ComparisonOperation extends BinaryOperation, @cmp_op_expr { }
99

1010
/**
1111
* A C/C++ equality operation, that is, either "==" or "!=".
1212
*/
13-
abstract class EqualityOperation extends ComparisonOperation {
13+
class EqualityOperation extends ComparisonOperation, @eq_op_expr {
1414
override int getPrecedence() { result = 9 }
1515
}
1616

@@ -41,7 +41,7 @@ class NEExpr extends EqualityOperation, @neexpr {
4141
/**
4242
* A C/C++ relational operation, that is, one of `<=`, `<`, `>`, or `>=`.
4343
*/
44-
abstract class RelationalOperation extends ComparisonOperation {
44+
class RelationalOperation extends ComparisonOperation, @rel_op_expr {
4545
override int getPrecedence() { result = 10 }
4646

4747
/**

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,11 @@ class Expr extends StmtParent, @expr {
461461
/**
462462
* A C/C++ operation.
463463
*
464-
* This is the QL abstract root class for all operations.
464+
* This is the QL root class for all operations.
465465
*/
466-
abstract class Operation extends Expr {
466+
class Operation extends Expr, @op_expr {
467467
/** Gets the operator of this operation. */
468-
abstract string getOperator();
468+
string getOperator() { none() }
469469

470470
/** Gets an operand of this operation. */
471471
Expr getAnOperand() { result = this.getAChild() }
@@ -474,7 +474,7 @@ abstract class Operation extends Expr {
474474
/**
475475
* A C/C++ unary operation.
476476
*/
477-
abstract class UnaryOperation extends Operation {
477+
class UnaryOperation extends Operation, @un_op_expr {
478478
/** Gets the operand of this unary operation. */
479479
Expr getOperand() { this.hasChild(result, 0) }
480480

@@ -488,7 +488,7 @@ abstract class UnaryOperation extends Operation {
488488
/**
489489
* A C/C++ binary operation.
490490
*/
491-
abstract class BinaryOperation extends Operation {
491+
class BinaryOperation extends Operation, @bin_op_expr {
492492
/** Gets the left operand of this binary operation. */
493493
Expr getLeftOperand() { this.hasChild(result, 0) }
494494

cpp/ql/src/semmle/code/cpp/exprs/LogicalOperation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import semmle.code.cpp.exprs.Expr
33
/**
44
* A C/C++ unary logical operation.
55
*/
6-
abstract class UnaryLogicalOperation extends UnaryOperation { }
6+
class UnaryLogicalOperation extends UnaryOperation, @un_log_op_expr { }
77

88
/**
99
* A C/C++ logical not expression.
@@ -22,7 +22,7 @@ class NotExpr extends UnaryLogicalOperation, @notexpr {
2222
/**
2323
* A C/C++ binary logical operation.
2424
*/
25-
abstract class BinaryLogicalOperation extends BinaryOperation {
25+
class BinaryLogicalOperation extends BinaryOperation, @bin_log_op_expr {
2626
/**
2727
* Holds if the truth of this binary logical expression having value `wholeIsTrue`
2828
* implies that the truth of the child expression `part` has truth value `partIsTrue`.

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,109 @@ funbind(
11901190
| @delete_expr
11911191
| @delete_array_expr;
11921192

1193+
@prefix_crement_expr = @preincrexpr | @predecrexpr;
1194+
1195+
@postfix_crement_expr = @postincrexpr | @postdecrexpr;
1196+
1197+
@increment_expr = @preincrexpr | @postincrexpr;
1198+
1199+
@decrement_expr = @predecrexpr | @postdecrexpr;
1200+
1201+
@crement_expr = @increment_expr | @decrement_expr;
1202+
1203+
@un_arith_op_expr = @arithnegexpr
1204+
| @unaryplusexpr
1205+
| @conjugation
1206+
| @realpartexpr
1207+
| @imagpartexpr
1208+
| @crement_expr
1209+
;
1210+
1211+
@un_bitwise_op_expr = @complementexpr;
1212+
1213+
@un_log_op_expr = @notexpr;
1214+
1215+
@un_op_expr = @address_of
1216+
| @indirect
1217+
| @un_arith_op_expr
1218+
| @un_bitwise_op_expr
1219+
| @builtinaddressof
1220+
| @vec_fill
1221+
| @un_log_op_expr
1222+
;
1223+
1224+
@bin_log_op_expr = @andlogicalexpr | @orlogicalexpr;
1225+
1226+
@cmp_op_expr = @eq_op_expr | @rel_op_expr;
1227+
1228+
@eq_op_expr = @eqexpr | @neexpr;
1229+
1230+
@rel_op_expr = @gtexpr
1231+
| @ltexpr
1232+
| @geexpr
1233+
| @leexpr
1234+
;
1235+
1236+
@bin_bitwise_op_expr = @lshiftexpr
1237+
| @rshiftexpr
1238+
| @andexpr
1239+
| @orexpr
1240+
| @xorexpr
1241+
;
1242+
1243+
@p_arith_op_expr = @paddexpr
1244+
| @psubexpr
1245+
| @pdiffexpr
1246+
;
1247+
1248+
@bin_arith_op_expr = @addexpr
1249+
| @subexpr
1250+
| @mulexpr
1251+
| @divexpr
1252+
| @remexpr
1253+
| @jmulexpr
1254+
| @jdivexpr
1255+
| @fjaddexpr
1256+
| @jfaddexpr
1257+
| @fjsubexpr
1258+
| @jfsubexpr
1259+
| @minexpr
1260+
| @maxexpr
1261+
| @p_arith_op_expr
1262+
;
1263+
1264+
@bin_op_expr = @bin_arith_op_expr
1265+
| @bin_bitwise_op_expr
1266+
| @cmp_op_expr
1267+
| @bin_log_op_expr
1268+
;
1269+
1270+
@op_expr = @un_op_expr
1271+
| @bin_op_expr
1272+
| @assign_expr
1273+
| @conditionalexpr
1274+
;
1275+
1276+
@assign_arith_expr = @assignaddexpr
1277+
| @assignsubexpr
1278+
| @assignmulexpr
1279+
| @assigndivexpr
1280+
| @assignremexpr
1281+
;
1282+
1283+
@assign_bitwise_expr = @assignandexpr
1284+
| @assignorexpr
1285+
| @assignxorexpr
1286+
| @assignlshiftexpr
1287+
| @assignrshiftexpr
1288+
| @assignpaddexpr
1289+
| @assignpsubexpr
1290+
;
1291+
1292+
@assign_op_expr = @assign_arith_expr | @assign_bitwise_expr
1293+
1294+
@assign_expr = @assignexpr | @assign_op_expr
1295+
11931296
/*
11941297
case @allocator.form of
11951298
0 = plain

0 commit comments

Comments
 (0)