diff --git a/ql/src/codeql_ruby/ast/Expr.qll b/ql/src/codeql_ruby/ast/Expr.qll index 8be48310999..6fc3bcfd5a6 100644 --- a/ql/src/codeql_ruby/ast/Expr.qll +++ b/ql/src/codeql_ruby/ast/Expr.qll @@ -22,7 +22,8 @@ class Literal extends Expr { override string toString() { result = this.getValueText() } - string getValueText() { result = range.getValueText() } + /** Gets the source text for this literal. */ + final string getValueText() { result = range.getValueText() } } /** diff --git a/ql/src/codeql_ruby/ast/Operation.qll b/ql/src/codeql_ruby/ast/Operation.qll index 107952b674a..9c0a3f7d778 100644 --- a/ql/src/codeql_ruby/ast/Operation.qll +++ b/ql/src/codeql_ruby/ast/Operation.qll @@ -10,10 +10,10 @@ class Operation extends Expr { override Operation::Range range; /** Gets the operator of this operation. */ - string getOperator() { result = range.getOperator() } + final string getOperator() { result = range.getOperator() } /** Gets an operand of this operation. */ - Expr getAnOperand() { result = range.getAnOperand() } + final Expr getAnOperand() { result = range.getAnOperand() } } /** A unary operation. */ @@ -21,7 +21,7 @@ class UnaryOperation extends Operation, @unary { override UnaryOperation::Range range; /** Gets the operand of this unary operation. */ - Expr getOperand() { result = range.getOperand() } + final Expr getOperand() { result = range.getOperand() } override string toString() { result = this.getOperator() + " ..." } } @@ -109,10 +109,10 @@ class BinaryOperation extends Operation, @binary { override string toString() { result = "... " + this.getOperator() + " ..." } /** Gets the left operand of this binary operation. */ - Expr getLeftOperand() { result = range.getLeftOperand() } + final Expr getLeftOperand() { result = range.getLeftOperand() } /** Gets the right operand of this binary operation. */ - Expr getRightOperand() { result = range.getRightOperand() } + final Expr getRightOperand() { result = range.getRightOperand() } } /** @@ -351,9 +351,9 @@ class CaseEqExpr extends EqualityOperation, @binary_equalequalequal { class RelationalOperation extends ComparisonOperation { override RelationalOperation::Range range; - Expr getGreaterOperand() { result = range.getGreaterOperand() } + final Expr getGreaterOperand() { result = range.getGreaterOperand() } - Expr getLesserOperand() { result = range.getLesserOperand() } + final Expr getLesserOperand() { result = range.getLesserOperand() } } /** @@ -451,10 +451,10 @@ class Assignment extends Operation { override string toString() { result = "... " + this.getOperator() + " ..." } /** Gets the left hand side of this assignment. */ - Expr getLhs() { result = range.getLhs() } + final Expr getLhs() { result = range.getLhs() } /** Gets the right hand side of this assignment. */ - Expr getRhs() { result = range.getRhs() } + final Expr getRhs() { result = range.getRhs() } } /** diff --git a/ql/src/codeql_ruby/ast/Variable.qll b/ql/src/codeql_ruby/ast/Variable.qll index a79080c2b2a..26cd367f32a 100644 --- a/ql/src/codeql_ruby/ast/Variable.qll +++ b/ql/src/codeql_ruby/ast/Variable.qll @@ -76,7 +76,7 @@ class LocalVariableAccess extends VariableAccess { final override LocalVariableAccess::Range range; /** Gets the variable this identifier refers to. */ - override LocalVariable getVariable() { result = range.getVariable() } + final override LocalVariable getVariable() { result = range.getVariable() } final override string getAPrimaryQlClass() { result = "LocalVariableAccess" } } diff --git a/ql/src/codeql_ruby/ast/internal/Operation.qll b/ql/src/codeql_ruby/ast/internal/Operation.qll index 02e67a0c1a8..15762d94380 100644 --- a/ql/src/codeql_ruby/ast/internal/Operation.qll +++ b/ql/src/codeql_ruby/ast/internal/Operation.qll @@ -213,9 +213,7 @@ module NoRegexMatchExpr { } module Assignment { - class DbUnion = @operator_assignment or @assignment; - - abstract class Range extends Operation::Range, DbUnion { + abstract class Range extends Operation::Range { abstract Expr getLhs(); abstract Expr getRhs(); diff --git a/ql/test/library-tests/ast/operations/assignment.ql b/ql/test/library-tests/ast/operations/assignment.ql index caa0294d8a5..83828da3ce7 100644 --- a/ql/test/library-tests/ast/operations/assignment.ql +++ b/ql/test/library-tests/ast/operations/assignment.ql @@ -19,26 +19,17 @@ query predicate assignOperations( query predicate assignArithmeticOperations( AssignArithmeticOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLhs() and - right = o.getRhs() and - pClass = o.getAPrimaryQlClass() + assignOperations(o, operator, left, right, pClass) } query predicate assignLogicalOperations( AssignLogicalOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLhs() and - right = o.getRhs() and - pClass = o.getAPrimaryQlClass() + assignOperations(o, operator, left, right, pClass) } query predicate assignBitwiseOperations( AssignBitwiseOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLhs() and - right = o.getRhs() and - pClass = o.getAPrimaryQlClass() + assignOperations(o, operator, left, right, pClass) } diff --git a/ql/test/library-tests/ast/operations/binary.expected b/ql/test/library-tests/ast/operations/binary.expected index af7a4ba3198..d1b565ef673 100644 --- a/ql/test/library-tests/ast/operations/binary.expected +++ b/ql/test/library-tests/ast/operations/binary.expected @@ -55,8 +55,8 @@ equalityOperations | operations.rb:53:1:53:8 | ... != ... | != | operations.rb:53:1:53:1 | a | operations.rb:53:6:53:8 | 123 | NEExpr | | operations.rb:54:1:54:7 | ... === ... | === | operations.rb:54:1:54:1 | m | operations.rb:54:7:54:7 | n | CaseEqExpr | relationalOperations -| operations.rb:57:1:57:5 | ... > ... | > | operations.rb:57:1:57:1 | x | operations.rb:57:5:57:5 | 0 | GTExpr | -| operations.rb:58:1:58:8 | ... >= ... | >= | operations.rb:58:1:58:1 | y | operations.rb:58:6:58:8 | 100 | GEExpr | +| operations.rb:57:1:57:5 | ... > ... | > | operations.rb:57:5:57:5 | 0 | operations.rb:57:1:57:1 | x | GTExpr | +| operations.rb:58:1:58:8 | ... >= ... | >= | operations.rb:58:6:58:8 | 100 | operations.rb:58:1:58:1 | y | GEExpr | | operations.rb:59:1:59:5 | ... < ... | < | operations.rb:59:1:59:1 | a | operations.rb:59:5:59:5 | b | LTExpr | | operations.rb:60:1:60:8 | ... <= ... | <= | operations.rb:60:1:60:1 | 7 | operations.rb:60:6:60:8 | foo | LEExpr | spaceshipExprs diff --git a/ql/test/library-tests/ast/operations/binary.ql b/ql/test/library-tests/ast/operations/binary.ql index 1f4b2f2d2fc..91048f59d04 100644 --- a/ql/test/library-tests/ast/operations/binary.ql +++ b/ql/test/library-tests/ast/operations/binary.ql @@ -12,80 +12,56 @@ query predicate binaryOperations( query predicate binaryArithmeticOperations( BinaryArithmeticOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLeftOperand() and - right = o.getRightOperand() and - pClass = o.getAPrimaryQlClass() + binaryOperations(o, operator, left, right, pClass) } query predicate binaryLogicalOperations( BinaryLogicalOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLeftOperand() and - right = o.getRightOperand() and - pClass = o.getAPrimaryQlClass() + binaryOperations(o, operator, left, right, pClass) } query predicate binaryBitwiseOperations( BinaryBitwiseOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLeftOperand() and - right = o.getRightOperand() and - pClass = o.getAPrimaryQlClass() + binaryOperations(o, operator, left, right, pClass) } query predicate comparisonOperations( ComparisonOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLeftOperand() and - right = o.getRightOperand() and - pClass = o.getAPrimaryQlClass() + binaryOperations(o, operator, left, right, pClass) } query predicate equalityOperations( EqualityOperation o, string operator, Expr left, Expr right, string pClass ) { - operator = o.getOperator() and - left = o.getLeftOperand() and - right = o.getRightOperand() and - pClass = o.getAPrimaryQlClass() + binaryOperations(o, operator, left, right, pClass) } query predicate relationalOperations( - RelationalOperation o, string operator, Expr left, Expr right, string pClass + RelationalOperation o, string operator, Expr lesser, Expr greater, string pClass ) { operator = o.getOperator() and - left = o.getLeftOperand() and - right = o.getRightOperand() and + lesser = o.getLesserOperand() and + greater = o.getGreaterOperand() and pClass = o.getAPrimaryQlClass() } query predicate spaceshipExprs( SpaceshipExpr e, string operator, Expr left, Expr right, string pClass ) { - operator = e.getOperator() and - left = e.getLeftOperand() and - right = e.getRightOperand() and - pClass = e.getAPrimaryQlClass() + binaryOperations(e, operator, left, right, pClass) } query predicate regexMatchExprs( RegexMatchExpr e, string operator, Expr left, Expr right, string pClass ) { - operator = e.getOperator() and - left = e.getLeftOperand() and - right = e.getRightOperand() and - pClass = e.getAPrimaryQlClass() + binaryOperations(e, operator, left, right, pClass) } query predicate noRegexMatchExprs( NoRegexMatchExpr e, string operator, Expr left, Expr right, string pClass ) { - operator = e.getOperator() and - left = e.getLeftOperand() and - right = e.getRightOperand() and - pClass = e.getAPrimaryQlClass() + binaryOperations(e, operator, left, right, pClass) } diff --git a/ql/test/library-tests/ast/operations/unary.ql b/ql/test/library-tests/ast/operations/unary.ql index a03bffa3a64..f94e1def2d6 100644 --- a/ql/test/library-tests/ast/operations/unary.ql +++ b/ql/test/library-tests/ast/operations/unary.ql @@ -9,23 +9,17 @@ query predicate unaryOperations(UnaryOperation o, string operator, Expr operand, query predicate unaryLogicalOperations( UnaryLogicalOperation o, string operator, Expr operand, string pClass ) { - operator = o.getOperator() and - operand = o.getOperand() and - pClass = o.getAPrimaryQlClass() + unaryOperations(o, operator, operand, pClass) } query predicate unaryArithmeticOperations( UnaryArithmeticOperation o, string operator, Expr operand, string pClass ) { - operator = o.getOperator() and - operand = o.getOperand() and - pClass = o.getAPrimaryQlClass() + unaryOperations(o, operator, operand, pClass) } query predicate unaryBitwiseOperations( UnaryBitwiseOperation o, string operator, Expr operand, string pClass ) { - operator = o.getOperator() and - operand = o.getOperand() and - pClass = o.getAPrimaryQlClass() + unaryOperations(o, operator, operand, pClass) }