Skip to content

Commit

Permalink
Rust: Include self parameters in the CFG
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Nov 20, 2024
1 parent 55121d8 commit 24adbb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ import CfgImpl
class CallableScopeTree extends StandardTree, PreOrderTree, PostOrderTree, Scope::CallableScope {
override predicate propagatesAbnormal(AstNode child) { none() }

private int getNumberOfSelfParams() {
if this.getParamList().hasSelfParam() then result = 1 else result = 0
}

override AstNode getChildNode(int i) {
result = this.getParamList().getParam(i)
i = 0 and
result = this.getParamList().getSelfParam()
or
result = this.getParamList().getParam(i - this.getNumberOfSelfParams())
or
i = this.getParamList().getNumberOfParams() and
i = this.getParamList().getNumberOfParams() + this.getNumberOfSelfParams() and
result = this.getBody()
}
}
Expand Down Expand Up @@ -191,6 +198,10 @@ class NameTree extends LeafTree, Name { }

class NameRefTree extends LeafTree, NameRef { }

class SelfParamTree extends StandardPostOrderTree, SelfParam {
override AstNode getChildNode(int i) { i = 0 and result = this.getName() }
}

class TypeRefTree extends LeafTree instanceof TypeRef { }

/**
Expand Down
8 changes: 6 additions & 2 deletions rust/ql/test/library-tests/controlflow/Cfg.expected
Original file line number Diff line number Diff line change
Expand Up @@ -1051,14 +1051,18 @@ edges
| test.rs:502:28:504:5 | BlockExpr | test.rs:502:5:504:5 | exit new (normal) | |
| test.rs:503:9:503:25 | RecordExpr | test.rs:502:28:504:5 | BlockExpr | |
| test.rs:503:23:503:23 | a | test.rs:503:9:503:25 | RecordExpr | |
| test.rs:506:5:508:5 | enter negated | test.rs:507:23:507:26 | self | |
| test.rs:506:5:508:5 | enter negated | test.rs:506:16:506:19 | self | |
| test.rs:506:5:508:5 | exit negated (normal) | test.rs:506:5:508:5 | exit negated | |
| test.rs:506:16:506:19 | SelfParam | test.rs:507:23:507:26 | self | |
| test.rs:506:16:506:19 | self | test.rs:506:16:506:19 | SelfParam | |
| test.rs:506:30:508:5 | BlockExpr | test.rs:506:5:508:5 | exit negated (normal) | |
| test.rs:507:9:507:30 | RecordExpr | test.rs:506:30:508:5 | BlockExpr | |
| test.rs:507:23:507:26 | self | test.rs:507:23:507:28 | FieldExpr | |
| test.rs:507:23:507:28 | FieldExpr | test.rs:507:9:507:30 | RecordExpr | |
| test.rs:510:5:512:5 | enter multifly_add | test.rs:510:32:510:32 | a | |
| test.rs:510:5:512:5 | enter multifly_add | test.rs:510:26:510:29 | self | |
| test.rs:510:5:512:5 | exit multifly_add (normal) | test.rs:510:5:512:5 | exit multifly_add | |
| test.rs:510:21:510:29 | SelfParam | test.rs:510:32:510:32 | a | |
| test.rs:510:26:510:29 | self | test.rs:510:21:510:29 | SelfParam | |
| test.rs:510:32:510:32 | a | test.rs:510:32:510:37 | Param | match |
| test.rs:510:32:510:37 | Param | test.rs:510:40:510:40 | b | |
| test.rs:510:40:510:40 | b | test.rs:510:40:510:45 | Param | match |
Expand Down

0 comments on commit 24adbb8

Please sign in to comment.