Skip to content

Commit f834419

Browse files
committed
unified: Add union type and update CFG
1 parent 04666e0 commit f834419

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/AstExtra.qll‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,36 @@ private import unified
66
private import codeql.unified.internal.NameBindingPlugin
77

88
module Public {
9+
/** An assignment, possibly a compound assignment. */
10+
abstract class AssignmentImpl extends BinaryExpr {
11+
/** Gets the target of this assignment. */
12+
abstract Expr getTarget();
13+
14+
/** Gets the value assigned by this assignment. */
15+
abstract Expr getValue();
16+
}
17+
18+
final class Assignment = AssignmentImpl;
19+
920
/** A plain assignment expression. */
10-
class AssignExpr extends BinaryExpr {
21+
final class AssignExpr extends BinaryExpr, AssignmentImpl {
1122
AssignExpr() { this.getOperator().getValue() = "=" }
1223

13-
/** Gets the target of this assignment. */
14-
Expr getTarget() { result = this.getLeft() }
24+
override Expr getTarget() { result = this.getLeft() }
1525

16-
/** Gets the value assigned by this assignment. */
17-
Expr getValue() { result = this.getRight() }
26+
override Expr getValue() { result = this.getRight() }
1827
}
1928

2029
/** A compound assignment expression. */
21-
class CompoundAssignExpr extends BinaryExpr {
30+
final class CompoundAssignExpr extends BinaryExpr, AssignmentImpl {
2231
CompoundAssignExpr() {
2332
this.getOperator().getValue() =
2433
["+=", "-=", "*=", "/=", "%=", "<<=", ">>=", "&=", "|=", "^=", "&+=", "&-=", "&*="]
2534
}
2635

27-
/** Gets the target of this assignment. */
28-
Expr getTarget() { result = this.getLeft() }
36+
override Expr getTarget() { result = this.getLeft() }
2937

30-
/** Gets the value assigned by this assignment. */
31-
Expr getValue() { result = this.getRight() }
38+
override Expr getValue() { result = this.getRight() }
3239
}
3340

3441
/** A short-circuiting logical AND expression. */

‎unified/ql/lib/codeql/unified/internal/ControlFlowGraph.qll‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,23 @@ private module Ast implements AstSig<Location> {
196196

197197
class LogicalNotExpr = U::LogicalNotExpr;
198198

199-
// TODO
200-
class Assignment extends BinaryExpr {
201-
Assignment() { none() }
202-
}
199+
class Assignment extends BinaryExpr, U::Assignment { }
203200

204-
class AssignExpr extends Assignment { }
201+
class AssignExpr extends Assignment, U::AssignExpr { }
205202

206-
class CompoundAssignment extends Assignment { }
203+
class CompoundAssignment extends Assignment, U::CompoundAssignExpr { }
207204

208-
class AssignLogicalAndExpr extends CompoundAssignment { }
205+
class AssignLogicalAndExpr extends CompoundAssignment {
206+
AssignLogicalAndExpr() { this.getOperator().getValue() = "&&=" }
207+
}
209208

210-
class AssignLogicalOrExpr extends CompoundAssignment { }
209+
class AssignLogicalOrExpr extends CompoundAssignment {
210+
AssignLogicalOrExpr() { this.getOperator().getValue() = "||=" }
211+
}
211212

212-
class AssignNullCoalescingExpr extends CompoundAssignment { }
213+
class AssignNullCoalescingExpr extends CompoundAssignment {
214+
AssignNullCoalescingExpr() { this.getOperator().getValue() = "??=" }
215+
}
213216

214217
class BooleanLiteral extends U::BooleanLiteral {
215218
boolean getValue() { result.toString() = super.getValue() }

0 commit comments

Comments
 (0)