C++: Removed abstract classes from binary and assignment operations

This commit is contained in:
Mathias Vorreiter Pedersen
2019-12-23 11:52:12 +01:00
parent 6998336fb9
commit 11a545e08e
7 changed files with 95 additions and 23 deletions

View File

@@ -5,7 +5,7 @@ import semmle.code.cpp.exprs.Expr
*
* This is an base QL class.
*/
class UnaryArithmeticOperation extends UnaryOperation, @un_arith_op_expr { }
class UnaryArithmeticOperation extends UnaryOperation, @un_arith_op_expr { }
/**
* A C/C++ unary minus expression.
@@ -58,7 +58,7 @@ class ConjugationExpr extends UnaryArithmeticOperation, @conjugation {
* Note that this does not include calls to user-defined `operator++`
* or `operator--`.
*/
class CrementOperation extends UnaryArithmeticOperation, @crement_expr {
class CrementOperation extends UnaryArithmeticOperation, @crement_expr {
override predicate mayBeImpure() { any() }
override predicate mayBeGloballyImpure() {
@@ -75,14 +75,14 @@ class ConjugationExpr extends UnaryArithmeticOperation, @conjugation {
*
* Note that this does not include calls to user-defined `operator++`.
*/
class IncrementOperation extends CrementOperation, @increment_expr { }
class IncrementOperation extends CrementOperation, @increment_expr { }
/**
* A C/C++ `--` expression (either prefix or postfix).
*
* Note that this does not include calls to user-defined `operator--`.
*/
class DecrementOperation extends CrementOperation, @decrement_expr { }
class DecrementOperation extends CrementOperation, @decrement_expr { }
/**
* A C/C++ `++` or `--` prefix expression.
@@ -199,7 +199,7 @@ class ImaginaryPartExpr extends UnaryArithmeticOperation, @imagpartexpr {
*
* This is an abstract base QL class for all binary arithmetic operations.
*/
abstract class BinaryArithmeticOperation extends BinaryOperation { }
class BinaryArithmeticOperation extends BinaryOperation, @bin_arith_op_expr { }
/**
* A C/C++ add expression.
@@ -404,7 +404,7 @@ class MaxExpr extends BinaryArithmeticOperation, @maxexpr {
/**
* A C/C++ pointer arithmetic operation.
*/
abstract class PointerArithmeticOperation extends BinaryArithmeticOperation { }
class PointerArithmeticOperation extends BinaryArithmeticOperation, @p_arith_op_expr { }
/**
* A C/C++ pointer add expression.

View File

@@ -7,9 +7,9 @@ import semmle.code.cpp.exprs.BitwiseOperation
* etc. A C++ overloaded assignment operation looks syntactically identical but is instead
* a `FunctionCall`.
*
* This is an abstract root QL class for all (non-overloaded) assignments.
* This is an root QL class for all (non-overloaded) assignments.
*/
abstract class Assignment extends Operation {
class Assignment extends Operation, @assign_expr {
/** Gets the _lvalue_ of this assignment. */
Expr getLValue() { this.hasChild(result, 0) }
@@ -47,7 +47,7 @@ class AssignExpr extends Assignment, @assignexpr {
/**
* A non-overloaded binary assignment operation other than `=`.
*/
abstract class AssignOperation extends Assignment {
class AssignOperation extends Assignment, @assign_op_expr {
override string toString() { result = "... " + this.getOperator() + " ..." }
}
@@ -55,7 +55,7 @@ abstract class AssignOperation extends Assignment {
* A non-overloaded arithmetic assignment operation on a non-pointer _lvalue_:
* `+=`, `-=`, `*=`, `/=` and `%=`.
*/
abstract class AssignArithmeticOperation extends AssignOperation { }
class AssignArithmeticOperation extends AssignOperation, @assign_arith_expr { }
/**
* A non-overloaded `+=` assignment expression on a non-pointer _lvalue_.
@@ -121,7 +121,7 @@ class AssignRemExpr extends AssignArithmeticOperation, @assignremexpr {
* A non-overloaded bitwise assignment operation:
* `&=`, `|=`, `^=`, `<<=`, and `>>=`.
*/
abstract class AssignBitwiseOperation extends AssignOperation { }
class AssignBitwiseOperation extends AssignOperation, @assign_bitwise_expr { }
/**
* A non-overloaded AND (`&=`) assignment expression.

View File

@@ -3,7 +3,7 @@ import semmle.code.cpp.exprs.Expr
/**
* A C/C++ unary bitwise operation.
*/
class UnaryBitwiseOperation extends UnaryOperation, @un_bitwise_op_expr { }
class UnaryBitwiseOperation extends UnaryOperation, @un_bitwise_op_expr { }
/**
* A C/C++ complement expression.
@@ -22,7 +22,7 @@ class ComplementExpr extends UnaryBitwiseOperation, @complementexpr {
/**
* A C/C++ binary bitwise operation.
*/
abstract class BinaryBitwiseOperation extends BinaryOperation { }
class BinaryBitwiseOperation extends BinaryOperation, @bin_bitwise_op_expr { }
/**
* A C/C++ left shift expression.

View File

@@ -3,14 +3,14 @@ import semmle.code.cpp.exprs.Expr
/**
* A C/C++ comparison operation, that is, either an equality operation or a relational operation.
*
* This is a QL abstract base class for all comparisons.
* This is a QL base class for all comparisons.
*/
abstract class ComparisonOperation extends BinaryOperation { }
class ComparisonOperation extends BinaryOperation, @cmp_op_expr { }
/**
* A C/C++ equality operation, that is, either "==" or "!=".
*/
abstract class EqualityOperation extends ComparisonOperation {
class EqualityOperation extends ComparisonOperation, @eq_op_expr {
override int getPrecedence() { result = 9 }
}
@@ -41,7 +41,7 @@ class NEExpr extends EqualityOperation, @neexpr {
/**
* A C/C++ relational operation, that is, one of `<=`, `<`, `>`, or `>=`.
*/
abstract class RelationalOperation extends ComparisonOperation {
class RelationalOperation extends ComparisonOperation, @rel_op_expr {
override int getPrecedence() { result = 10 }
/**

View File

@@ -461,9 +461,9 @@ class Expr extends StmtParent, @expr {
/**
* A C/C++ operation.
*
* This is the QL abstract root class for all operations.
* This is the QL root class for all operations.
*/
abstract class Operation extends Expr {
class Operation extends Expr, @op_expr {
/** Gets the operator of this operation. */
string getOperator() { none() }
@@ -474,7 +474,7 @@ abstract class Operation extends Expr {
/**
* A C/C++ unary operation.
*/
abstract class UnaryOperation extends Operation {
class UnaryOperation extends Operation, @un_op_expr {
/** Gets the operand of this unary operation. */
Expr getOperand() { this.hasChild(result, 0) }
@@ -488,7 +488,7 @@ abstract class UnaryOperation extends Operation {
/**
* A C/C++ binary operation.
*/
abstract class BinaryOperation extends Operation {
class BinaryOperation extends Operation, @bin_op_expr {
/** Gets the left operand of this binary operation. */
Expr getLeftOperand() { this.hasChild(result, 0) }

View File

@@ -3,7 +3,7 @@ import semmle.code.cpp.exprs.Expr
/**
* A C/C++ unary logical operation.
*/
class UnaryLogicalOperation extends UnaryOperation, @un_log_op_expr { }
class UnaryLogicalOperation extends UnaryOperation, @un_log_op_expr { }
/**
* A C/C++ logical not expression.
@@ -22,7 +22,7 @@ class NotExpr extends UnaryLogicalOperation, @notexpr {
/**
* A C/C++ binary logical operation.
*/
abstract class BinaryLogicalOperation extends BinaryOperation {
class BinaryLogicalOperation extends BinaryOperation, @bin_log_op_expr {
/**
* Holds if the truth of this binary logical expression having value `wholeIsTrue`
* implies that the truth of the child expression `part` has truth value `partIsTrue`.

View File

@@ -1221,6 +1221,78 @@ funbind(
| @un_log_op_expr
;
@bin_log_op_expr = @andlogicalexpr | @orlogicalexpr;
@cmp_op_expr = @eq_op_expr | @rel_op_expr;
@eq_op_expr = @eqexpr | @neexpr;
@rel_op_expr = @gtexpr
| @ltexpr
| @geexpr
| @leexpr
;
@bin_bitwise_op_expr = @lshiftexpr
| @rshiftexpr
| @andexpr
| @orexpr
| @xorexpr
;
@p_arith_op_expr = @paddexpr
| @psubexpr
| @pdiffexpr
;
@bin_arith_op_expr = @addexpr
| @subexpr
| @mulexpr
| @divexpr
| @remexpr
| @jmulexpr
| @jdivexpr
| @fjaddexpr
| @jfaddexpr
| @fjsubexpr
| @jfsubexpr
| @minexpr
| @maxexpr
| @p_arith_op_expr
;
@bin_op_expr = @bin_arith_op_expr
| @bin_bitwise_op_expr
| @cmp_op_expr
| @bin_log_op_expr
;
@op_expr = @un_op_expr
| @bin_op_expr
| @assign_expr
| @conditionalexpr
;
@assign_arith_expr = @assignaddexpr
| @assignsubexpr
| @assignmulexpr
| @assigndivexpr
| @assignremexpr
;
@assign_bitwise_expr = @assignandexpr
| @assignorexpr
| @assignxorexpr
| @assignlshiftexpr
| @assignrshiftexpr
| @assignpaddexpr
| @assignpsubexpr
;
@assign_op_expr = @assign_arith_expr | @assign_bitwise_expr
@assign_expr = @assignexpr | @assign_op_expr
/*
case @allocator.form of
0 = plain