Skip to content

Commit 7c82c5e

Browse files
committed
QL: refactor away the ComparisonOp ast class
1 parent 1b19a3e commit 7c82c5e

File tree

7 files changed

+148
-212
lines changed

7 files changed

+148
-212
lines changed

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,23 +1153,6 @@ class Disjunction extends TDisjunction, AstNode, Formula {
11531153
}
11541154
}
11551155

1156-
/**
1157-
* A comparison operator, such as `<` or `=`.
1158-
*/
1159-
class ComparisonOp extends TComparisonOp, AstNode {
1160-
QL::Compop op;
1161-
1162-
ComparisonOp() { this = TComparisonOp(op) }
1163-
1164-
/**
1165-
* Gets a string representing the operator.
1166-
* E.g. "<" or "=".
1167-
*/
1168-
ComparisonSymbol getSymbol() { result = op.getValue() }
1169-
1170-
override string getAPrimaryQlClass() { result = "ComparisonOp" }
1171-
}
1172-
11731156
/**
11741157
* A literal expression, such as `6` or `true` or `"foo"`.
11751158
*/
@@ -1266,10 +1249,7 @@ class ComparisonFormula extends TComparisonFormula, Formula {
12661249
Expr getAnOperand() { result in [this.getLeftOperand(), this.getRightOperand()] }
12671250

12681251
/** Gets the operator of this comparison. */
1269-
ComparisonOp getOperator() { toQL(result) = comp.getChild() }
1270-
1271-
/** Gets the symbol of this comparison (as a string). */
1272-
ComparisonSymbol getSymbol() { result = this.getOperator().getSymbol() }
1252+
ComparisonSymbol getOperator() { result = comp.getChild().getValue() }
12731253

12741254
override string getAPrimaryQlClass() { result = "ComparisonFormula" }
12751255

@@ -1279,8 +1259,6 @@ class ComparisonFormula extends TComparisonFormula, Formula {
12791259
pred = directMember("getLeftOperand") and result = this.getLeftOperand()
12801260
or
12811261
pred = directMember("getRightOperand") and result = this.getRightOperand()
1282-
or
1283-
pred = directMember("getOperator") and result = this.getOperator()
12841262
}
12851263
}
12861264

ql/src/codeql_ql/ast/internal/AstNodes.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ newtype TAstNode =
2222
TDisjunction(QL::Disjunction disj) or
2323
TConjunction(QL::Conjunction conj) or
2424
TComparisonFormula(QL::CompTerm comp) or
25-
TComparisonOp(QL::Compop op) or
2625
TQuantifier(QL::Quantified quant) or
2726
TFullAggregate(QL::Aggregate agg) { agg.getChild(_) instanceof QL::FullAggregateBody } or
2827
TExprAggregate(QL::Aggregate agg) { agg.getChild(_) instanceof QL::ExprAggregateBody } or
@@ -91,7 +90,6 @@ private QL::AstNode toQLFormula(AST::AstNode n) {
9190
n = TConjunction(result) or
9291
n = TDisjunction(result) or
9392
n = TComparisonFormula(result) or
94-
n = TComparisonOp(result) or
9593
n = TQuantifier(result) or
9694
n = TFullAggregate(result) or
9795
n = TIdentifier(result) or

ql/src/queries/performance/ClassPredicateDoesntMentionThis.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ predicate usesThis(ClassPredicate pred) {
2525

2626
predicate isLiteralComparison(ComparisonFormula eq) {
2727
exists(Expr lhs, Expr rhs |
28-
eq.getSymbol() = "=" and
28+
eq.getOperator() = "=" and
2929
eq.getAnOperand() = lhs and
3030
eq.getAnOperand() = rhs and
3131
(

ql/src/queries/performance/PrefixSuffixEquality.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SuffixPredicateCall extends Call {
2929
}
3030

3131
class EqFormula extends ComparisonFormula {
32-
EqFormula() { this.getSymbol() = "=" }
32+
EqFormula() { this.getOperator() = "=" }
3333
}
3434

3535
bindingset[s]

ql/src/queries/performance/TransitiveStep.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ predicate transitivePred(Predicate p, AstNode tc) {
7878
or
7979
exists(ComparisonFormula eq, Call c |
8080
body = eq and
81-
eq.getSymbol() = "=" and
81+
eq.getOperator() = "=" and
8282
transitiveCall(c, tc) and
8383
getArg(c, _) instanceof Identifier and
8484
eq.getAnOperand() = c and
@@ -141,7 +141,7 @@ predicate valueStep(Expr e1, Expr e2) {
141141
)
142142
or
143143
exists(ComparisonFormula eq |
144-
eq.getSymbol() = "=" and
144+
eq.getOperator() = "=" and
145145
eq.getAnOperand() = e1 and
146146
eq.getAnOperand() = e2 and
147147
e1 != e2

ql/src/queries/style/ToStringInQueryLogic.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ module DataFlow {
227227
)
228228
or
229229
exists(ComparisonFormula eq |
230-
eq.getSymbol() = "=" and
230+
eq.getOperator() = "=" and
231231
eq.getAnOperand() = e1 and
232232
eq.getAnOperand() = e2 and
233233
e1 != e2

0 commit comments

Comments
 (0)