Skip to content

Commit ac33449

Browse files
committed
wip
1 parent 755671d commit ac33449

File tree

6 files changed

+26
-39
lines changed

6 files changed

+26
-39
lines changed

rust/ql/lib/codeql/rust/elements/Call.qll

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,7 @@ private import internal.CallExprImpl::Impl as CallExprImpl
88

99
final class Call = Impl::Call;
1010

11-
private predicate isGuaranteedMethodCall(ArgsExpr call) {
12-
call instanceof MethodCallExpr
13-
or
14-
call.(Operation).isOverloaded(_, _, _)
15-
or
16-
call instanceof IndexExpr
17-
}
18-
19-
/**
20-
* A call expression that targets a method.
21-
*
22-
* Either
23-
*
24-
* - a `CallExpr` where we can resolve the target as a method,
25-
* - a `MethodCallExpr`,
26-
* - an `Operation` that targets an overloadable operator, or
27-
* - an `IndexExpr`.
28-
*/
29-
final class MethodCall extends Call {
30-
MethodCall() {
31-
this.getStaticTarget() instanceof Method
32-
or
33-
isGuaranteedMethodCall(this)
34-
}
35-
36-
/** Gets the static target of this method call, if any. */
37-
Method getStaticTarget() { result = super.getStaticTarget() }
38-
}
11+
final class MethodCall = Impl::MethodCall;
3912

4013
/**
4114
* A call expression that targets a closure.

rust/ql/lib/codeql/rust/elements/internal/CallExprImpl.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ module Impl {
7272
)
7373
}
7474

75-
private predicate isMethodCall() { this.getResolvedTarget() instanceof Method }
75+
override Expr getPositionalArgument(int i) { result = super.getSyntacticArgument(i) }
76+
}
7677

77-
override Expr getPositionalArgument(int i) {
78-
if this.isMethodCall()
79-
then result = this.getSyntacticArgument(i + 1)
80-
else result = super.getSyntacticArgument(i)
81-
}
78+
class CallExprMethodCall extends CallExprCall, CallImpl::MethodCall {
79+
CallExprMethodCall() { this.getResolvedTarget() instanceof Method }
80+
81+
override Expr getPositionalArgument(int i) { result = this.getSyntacticArgument(i + 1) }
8282

83-
override Expr getReceiver() { this.isMethodCall() and result = super.getSyntacticArgument(0) }
83+
override Expr getReceiver() { result = super.getSyntacticArgument(0) }
8484
}
8585

8686
/**

rust/ql/lib/codeql/rust/elements/internal/CallImpl.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,18 @@ module Impl {
6969
)
7070
}
7171
}
72+
73+
/**
74+
* A call expression that targets a method.
75+
*
76+
* Either
77+
*
78+
* - a `CallExpr` where we can resolve the target as a method,
79+
* - a `MethodCallExpr`,
80+
* - an `Operation` that targets an overloadable operator, or
81+
* - an `IndexExpr`.
82+
*/
83+
abstract class MethodCall extends Call {
84+
override Method getStaticTarget() { result = super.getStaticTarget() }
85+
}
7286
}

rust/ql/lib/codeql/rust/elements/internal/IndexExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Impl {
2222
* list[42] = 1;
2323
* ```
2424
*/
25-
class IndexExpr extends Generated::IndexExpr, CallImpl::Call {
25+
class IndexExpr extends Generated::IndexExpr, CallImpl::MethodCall {
2626
override string toStringImpl() {
2727
result =
2828
this.getBase().toAbbreviatedString() + "[" + this.getIndex().toAbbreviatedString() + "]"

rust/ql/lib/codeql/rust/elements/internal/MethodCallExprImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module Impl {
2727
* x.foo::<u32, u64>(42);
2828
* ```
2929
*/
30-
class MethodCallExpr extends Generated::MethodCallExpr, CallImpl::Call {
30+
class MethodCallExpr extends Generated::MethodCallExpr, CallImpl::MethodCall {
3131
private string toStringPart(int index) {
3232
index = 0 and
3333
result = this.getReceiver().toAbbreviatedString()

rust/ql/lib/codeql/rust/elements/internal/OperationImpl.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ module Impl {
137137
}
138138
}
139139

140-
private class CallOperation extends CallImpl::Call instanceof Operation {
141-
CallOperation() { super.isOverloaded(_, _, _) }
140+
private class OperationMethodCall extends CallImpl::MethodCall instanceof Operation {
141+
OperationMethodCall() { super.isOverloaded(_, _, _) }
142142

143143
override Expr getPositionalArgument(int i) { result = super.getOperand(i + 1) and i >= 0 }
144144

0 commit comments

Comments
 (0)