Merge pull request #2558 from MathiasVP/ast-classes-should-not-be-abstract

C++: Ast classes should not be abstract
This commit is contained in:
Jonas Jensen
2020-01-17 08:47:55 +01:00
committed by GitHub
11 changed files with 7565 additions and 3513 deletions

View File

@@ -2,10 +2,8 @@ import semmle.code.cpp.exprs.Expr
/**
* A C/C++ unary arithmetic operation.
*
* This is an abstract base QL class.
*/
abstract class UnaryArithmeticOperation extends UnaryOperation { }
class UnaryArithmeticOperation extends UnaryOperation, @un_arith_op_expr { }
/**
* A C/C++ unary minus expression.
@@ -53,12 +51,12 @@ class ConjugationExpr extends UnaryArithmeticOperation, @conjugation {
/**
* A C/C++ `++` or `--` expression (either prefix or postfix).
*
* This is the abstract base QL class for increment and decrement operations.
* This is the base QL class for increment and decrement operations.
*
* Note that this does not include calls to user-defined `operator++`
* or `operator--`.
*/
abstract class CrementOperation extends UnaryArithmeticOperation {
class CrementOperation extends UnaryArithmeticOperation, @crement_expr {
override predicate mayBeImpure() { any() }
override predicate mayBeGloballyImpure() {
@@ -75,28 +73,28 @@ abstract class CrementOperation extends UnaryArithmeticOperation {
*
* Note that this does not include calls to user-defined `operator++`.
*/
abstract class IncrementOperation extends CrementOperation { }
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--`.
*/
abstract class DecrementOperation extends CrementOperation { }
class DecrementOperation extends CrementOperation, @decrement_expr { }
/**
* A C/C++ `++` or `--` prefix expression.
*
* Note that this does not include calls to user-defined operators.
*/
abstract class PrefixCrementOperation extends CrementOperation { }
class PrefixCrementOperation extends CrementOperation, @prefix_crement_expr { }
/**
* A C/C++ `++` or `--` postfix expression.
*
* Note that this does not include calls to user-defined operators.
*/
abstract class PostfixCrementOperation extends CrementOperation { }
class PostfixCrementOperation extends CrementOperation, @postfix_crement_expr { }
/**
* A C/C++ prefix increment expression, as in `++x`.
@@ -199,7 +197,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 +402,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 a QL base 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.
*/
abstract class UnaryBitwiseOperation extends UnaryOperation { }
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,11 +461,11 @@ 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. */
abstract string getOperator();
string getOperator() { none() }
/** Gets an operand of this operation. */
Expr getAnOperand() { result = this.getAChild() }
@@ -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.
*/
abstract class UnaryLogicalOperation extends UnaryOperation { }
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

@@ -1190,6 +1190,109 @@ funbind(
| @delete_expr
| @delete_array_expr;
@prefix_crement_expr = @preincrexpr | @predecrexpr;
@postfix_crement_expr = @postincrexpr | @postdecrexpr;
@increment_expr = @preincrexpr | @postincrexpr;
@decrement_expr = @predecrexpr | @postdecrexpr;
@crement_expr = @increment_expr | @decrement_expr;
@un_arith_op_expr = @arithnegexpr
| @unaryplusexpr
| @conjugation
| @realpartexpr
| @imagpartexpr
| @crement_expr
;
@un_bitwise_op_expr = @complementexpr;
@un_log_op_expr = @notexpr;
@un_op_expr = @address_of
| @indirect
| @un_arith_op_expr
| @un_bitwise_op_expr
| @builtinaddressof
| @vec_fill
| @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

File diff suppressed because it is too large Load Diff