File tree Expand file tree Collapse file tree 7 files changed +18
-39
lines changed
Expand file tree Collapse file tree 7 files changed +18
-39
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,6 @@ module Impl {
1919 /** Gets the number of positional arguments of this expression. */
2020 int getNumberOfArguments ( ) { result = count ( Expr arg | arg = this .getArgument ( _) ) }
2121
22- /**
23- * Gets the receiver of this expression, if any.
24- *
25- * This is either an actual receiver of a method call, the first operand of an operation,
26- * or the base expression of an index expression.
27- */
28- Expr getReceiver ( ) { none ( ) }
29-
3022 /** Gets the resolved target (function or tuple struct/variant) of this call, if any. */
3123 Addressable getResolvedTarget ( ) { result = TypeInference:: resolveCallTarget ( this ) }
3224 }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ private import rust
33module Impl {
44 private import codeql.rust.internal.TypeInference as TypeInference
55 private import codeql.rust.elements.internal.ExprImpl:: Impl as ExprImpl
6+ private import codeql.rust.elements.internal.ArgsExprImpl:: Impl as ArgsExprImpl
67
78 /**
89 * A call.
@@ -14,19 +15,10 @@ module Impl {
1415 * - an `Operation` that targets an overloadable opeator, or
1516 * - an `IndexExpr`.
1617 */
17- abstract class Call extends ExprImpl:: Expr {
18- /** Gets the `i`th positional argument of this call, if any. */
19- Expr getArgument ( int i ) { none ( ) }
20-
18+ abstract class Call extends ArgsExprImpl:: ArgsExpr {
2119 // todo: remove once internal query has been updated
2220 Expr getArg ( int i ) { result = this .getArgument ( i ) }
2321
24- /** Gets a positional argument of this call, if any. */
25- Expr getAnArgument ( ) { result = this .getArgument ( _) }
26-
27- /** Gets the number of positional arguments of this call. */
28- int getNumberOfArguments ( ) { result = count ( Expr arg | arg = this .getArgument ( _) ) }
29-
3022 // todo: remove once internal query has been updated
3123 int getNumberOfArgs ( ) { result = this .getNumberOfArguments ( ) }
3224
Original file line number Diff line number Diff line change @@ -32,10 +32,4 @@ module Impl {
3232
3333 override Expr getReceiver ( ) { result = this .getBase ( ) }
3434 }
35-
36- private class IndexArgsExpr extends ArgsExprImpl:: ArgsExpr instanceof IndexExpr {
37- override Expr getArgument ( int i ) { result = IndexExpr .super .getArgument ( i ) }
38-
39- override Expr getReceiver ( ) { result = IndexExpr .super .getReceiver ( ) }
40- }
4135}
Original file line number Diff line number Diff line change @@ -49,10 +49,4 @@ module Impl {
4949
5050 override Expr getReceiver ( ) { result = Generated:: MethodCallExpr .super .getReceiver ( ) }
5151 }
52-
53- private class MethodCallArgsExpr extends ArgsExprImpl:: ArgsExpr instanceof MethodCallExpr {
54- override Expr getArgument ( int i ) { result = MethodCallExpr .super .getArgument ( i ) }
55-
56- override Expr getReceiver ( ) { result = MethodCallExpr .super .getReceiver ( ) }
57- }
5852}
Original file line number Diff line number Diff line change @@ -115,9 +115,10 @@ module Impl {
115115 /** Gets the `n`th operand of this operation, if any. */
116116 abstract Expr getOperand ( int n ) ;
117117
118- override Expr getArgument ( int i ) { result = this .getOperand ( i + 1 ) and i >= 0 }
119-
120- override Expr getReceiver ( ) { result = this .getOperand ( 0 ) }
118+ override Expr getArgument ( int i ) {
119+ not this .isOverloaded ( _, _, _) and
120+ result = this .getOperand ( i )
121+ }
121122
122123 /**
123124 * Gets the number of operands of this operation.
@@ -142,8 +143,8 @@ module Impl {
142143 private class CallOperation extends CallImpl:: Call instanceof Operation {
143144 CallOperation ( ) { super .isOverloaded ( _, _, _) }
144145
145- override Expr getArgument ( int i ) { result = Operation . super .getArgument ( i ) }
146+ override Expr getArgument ( int i ) { result = super .getOperand ( i + 1 ) and i >= 0 }
146147
147- override Expr getReceiver ( ) { result = Operation . super .getReceiver ( ) }
148+ override Expr getReceiver ( ) { result = super .getOperand ( 0 ) }
148149 }
149150}
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ module Impl {
1515 private import codeql.rust.elements.internal.CallImpl:: Impl as CallImpl
1616 private import codeql.rust.elements.internal.ArgsExprImpl:: Impl as ArgsExprImpl
1717 private import codeql.rust.internal.PathResolution as PathResolution
18+ private import codeql.rust.internal.TypeInference as TypeInference
1819
1920 pragma [ nomagic]
2021 Path getBasePath ( ParenArgsExpr pae ) { result = pae .getBase ( ) .( PathExpr ) .getPath ( ) }
@@ -69,10 +70,15 @@ module Impl {
6970
7071 private class ParenArgsCallExpr extends CallImpl:: Call instanceof ParenArgsExpr {
7172 ParenArgsCallExpr ( ) {
72- forall ( Addressable target | target = super .getResolvedTarget ( ) | target instanceof Callable )
73+ forall ( Addressable target |
74+ // Cannot use `this.getResolvedTarget()` as that results in non-monotonic recursion
75+ target = TypeInference:: resolveCallTarget ( this )
76+ |
77+ target instanceof Callable
78+ )
7379 }
7480
75- private predicate isMethodCall ( ) { super .getResolvedTarget ( ) instanceof Method }
81+ private predicate isMethodCall ( ) { this .getResolvedTarget ( ) instanceof Method }
7682
7783 override Expr getArgument ( int i ) {
7884 if this .isMethodCall ( )
Original file line number Diff line number Diff line change @@ -1361,7 +1361,7 @@ private module MethodResolution {
13611361 *
13621362 * [1]: https://doc.rust-lang.org/std/ops/trait.Index.html
13631363 */
1364- abstract class MethodCall extends ArgsExpr {
1364+ abstract class MethodCall extends Expr {
13651365 abstract predicate hasNameAndArity ( string name , int arity ) ;
13661366
13671367 abstract Expr getArg ( ArgumentPosition pos ) ;
@@ -3483,7 +3483,7 @@ private module Cached {
34833483
34843484 /** Gets an item (function or tuple struct/variant) that `call` resolves to, if any. */
34853485 cached
3486- Addressable resolveCallTarget ( ArgsExpr call ) {
3486+ Addressable resolveCallTarget ( Expr call ) {
34873487 result = call .( MethodResolution:: MethodCall ) .resolveCallTarget ( _, _, _)
34883488 or
34893489 result = call .( NonMethodResolution:: NonMethodCall ) .resolveCallTarget ( )
You can’t perform that action at this time.
0 commit comments