Skip to content

Commit

Permalink
Merge pull request #17626 from hvitved/rust/more-cfg-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved authored Sep 30, 2024
2 parents c3311e5 + 2e7e26b commit 3a210b7
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ predicate trivialPat(Pat p) { p instanceof WildcardPat or p instanceof IdentPat
class AsmExprTree extends LeafTree instanceof AsmExpr { }

class AwaitExprTree extends StandardPostOrderTree instanceof AwaitExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

// NOTE: `become` is a reserved but unused keyword.
class BecomeExprTree extends StandardPostOrderTree instanceof BecomeExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

class BinaryOpExprTree extends StandardPostOrderTree instanceof BinaryExpr {
BinaryOpExprTree() { not this instanceof BinaryLogicalOperation }

override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
i = 0 and result = super.getLhs()
or
i = 1 and result = super.getRhs()
Expand Down Expand Up @@ -133,7 +133,7 @@ class LogicalAndBinaryOpExprTree extends PreOrderTree, LogicalAndExpr {
}

class BlockExprBaseTree extends StandardPostOrderTree instanceof BlockExpr {
override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
result = super.getStmtList().getStatement(i)
or
not exists(super.getStmtList().getStatement(i)) and
Expand All @@ -157,27 +157,27 @@ class BreakExprTree extends PostOrderTree instanceof BreakExpr {
}

class CallExprTree extends StandardPostOrderTree instanceof CallExpr {
override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
i = 0 and result = super.getExpr()
or
result = super.getArgList().getArg(i - 1)
}
}

class CastExprTree extends StandardPostOrderTree instanceof CastExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

class ClosureExprTree extends LeafTree instanceof ClosureExpr { }

class ContinueExprTree extends LeafTree instanceof ContinueExpr { }

class ExprStmtTree extends StandardPreOrderTree instanceof ExprStmt {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

class FieldExprTree extends StandardPostOrderTree instanceof FieldExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

class FunctionTree extends LeafTree instanceof Function { }
Expand Down Expand Up @@ -219,7 +219,7 @@ class IfExprTree extends PostOrderTree instanceof IfExpr {
}

class IndexExprTree extends StandardPostOrderTree instanceof IndexExpr {
override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
i = 0 and result = super.getBase()
or
i = 1 and result = super.getIndex()
Expand All @@ -230,7 +230,7 @@ class IndexExprTree extends StandardPostOrderTree instanceof IndexExpr {
// dominating successors in the graph in the same way that patterns do in
// `match` expressions.
class LetExprTree extends StandardPreOrderTree instanceof LetExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getPat() }
override AstNode getChildNode(int i) { i = 0 and result = super.getPat() }
}

// We handle `let` statements with trivial patterns separately as they don't
Expand All @@ -239,7 +239,7 @@ class LetExprTree extends StandardPreOrderTree instanceof LetExpr {
class LetStmtTreeTrivialPat extends StandardPreOrderTree instanceof LetStmt {
LetStmtTreeTrivialPat() { trivialPat(super.getPat()) }

override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
i = 0 and result = super.getInitializer()
or
i = 1 and result = super.getPat()
Expand Down Expand Up @@ -370,7 +370,7 @@ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
}

class MethodCallExprTree extends StandardPostOrderTree instanceof MethodCallExpr {
override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
result = super.getReceiver() and
result = super.getArgList().getArg(i + 1)
}
Expand All @@ -379,7 +379,7 @@ class MethodCallExprTree extends StandardPostOrderTree instanceof MethodCallExpr
class OffsetOfExprTree extends LeafTree instanceof OffsetOfExpr { }

class ParenExprTree extends StandardPostOrderTree, ParenExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

// This covers all patterns as they all extend `Pat`
Expand All @@ -388,25 +388,25 @@ class PatExprTree extends LeafTree instanceof Pat { }
class PathExprTree extends LeafTree instanceof PathExpr { }

class PrefixExprTree extends StandardPostOrderTree instanceof PrefixExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

class RangeExprTree extends StandardPostOrderTree instanceof RangeExpr {
override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
i = 0 and result = super.getStart()
or
i = 1 and result = super.getEnd()
}
}

class RecordExprTree extends StandardPostOrderTree instanceof RecordExpr {
override ControlFlowTree getChildNode(int i) {
override AstNode getChildNode(int i) {
result = super.getRecordExprFieldList().getField(i).getExpr()
}
}

class RefExprTree extends StandardPostOrderTree instanceof RefExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

class ReturnExprTree extends PostOrderTree instanceof ReturnExpr {
Expand All @@ -424,7 +424,7 @@ class ReturnExprTree extends PostOrderTree instanceof ReturnExpr {
}

class TupleExprTree extends StandardPostOrderTree instanceof TupleExpr {
override ControlFlowTree getChildNode(int i) { result = super.getField(i) }
override AstNode getChildNode(int i) { result = super.getField(i) }
}

class TypeRefTree extends LeafTree instanceof TypeRef { }
Expand All @@ -433,10 +433,10 @@ class UnderscoreExprTree extends LeafTree instanceof UnderscoreExpr { }

// NOTE: `yield` is a reserved but unused keyword.
class YieldExprTree extends StandardPostOrderTree instanceof YieldExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}

// NOTE: `yeet` is experimental and not a part of Rust.
class YeetExprTree extends StandardPostOrderTree instanceof YeetExpr {
override ControlFlowTree getChildNode(int i) { i = 0 and result = super.getExpr() }
override AstNode getChildNode(int i) { i = 0 and result = super.getExpr() }
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
deadEnd
| test.rs:125:28:125:33 | ... < ... |
| test.rs:140:30:140:48 | BlockExpr |
| test.rs:55:13:55:17 | IdentPat |
| test.rs:224:28:224:33 | ... < ... |
| test.rs:239:30:239:48 | BlockExpr |
scopeNoFirst
| test.rs:62:5:66:5 | test_for |
Loading

0 comments on commit 3a210b7

Please sign in to comment.