11private import codeql_ruby.AST
22private import internal.AST
3+ private import internal.Call
34private import internal.TreeSitter
45
56/**
@@ -20,7 +21,7 @@ class Call extends Expr, TCall {
2021 * yield 0, bar: 1
2122 * ```
2223 */
23- Expr getArgument ( int n ) { none ( ) }
24+ final Expr getArgument ( int n ) { result = this . ( CallImpl ) . getArgumentImpl ( n ) }
2425
2526 /**
2627 * Gets an argument of this method call.
@@ -46,24 +47,11 @@ class Call extends Expr, TCall {
4647 /**
4748 * Gets the number of arguments of this method call.
4849 */
49- final int getNumberOfArguments ( ) { result = count ( this .getAnArgument ( ) ) }
50+ final int getNumberOfArguments ( ) { result = this .( CallImpl ) . getNumberOfArgumentsImpl ( ) }
5051
5152 override AstNode getAChild ( string pred ) { pred = "getArgument" and result = this .getArgument ( _) }
5253}
5354
54- bindingset [ s]
55- private string getMethodName ( MethodCall mc , string s ) {
56- (
57- not mc instanceof LhsExpr
58- or
59- mc .getParent ( ) instanceof AssignOperation
60- ) and
61- result = s
62- or
63- mc instanceof LhsExpr and
64- result = s + "="
65- }
66-
6755/**
6856 * A method call.
6957 */
@@ -83,22 +71,7 @@ class MethodCall extends Call, TMethodCall {
8371 * the call to `qux` is the `Expr` for `Baz`; for the call to `corge` there
8472 * is no result.
8573 */
86- Expr getReceiver ( ) { none ( ) }
87-
88- /**
89- * Holds if the receiver is `self` or there is no receiver, which has the same
90- * meaning as an explict `self`. For example:
91- *
92- * ```rb
93- * self.foo
94- * foo
95- * ```
96- */
97- predicate receiverIsSelf ( ) {
98- this .getReceiver ( ) instanceof Self
99- or
100- not exists ( this .getReceiver ( ) )
101- }
74+ final Expr getReceiver ( ) { result = this .( MethodCallImpl ) .getReceiverImpl ( ) }
10275
10376 /**
10477 * Gets the name of the method being called. For example, in:
@@ -109,7 +82,7 @@ class MethodCall extends Call, TMethodCall {
10982 *
11083 * the result is `"bar"`.
11184 */
112- string getMethodName ( ) { none ( ) }
85+ final string getMethodName ( ) { result = this . ( MethodCallImpl ) . getMethodNameImpl ( ) }
11386
11487 /**
11588 * Gets the block of this method call, if any.
@@ -119,79 +92,27 @@ class MethodCall extends Call, TMethodCall {
11992 */
12093 Block getBlock ( ) { none ( ) }
12194
122- override string toString ( ) { result = "call to " + concat ( this .getMethodName ( ) , "/" ) }
95+ override string toString ( ) { result = "call to " + this .getMethodName ( ) }
12396
124- final override AstNode getAChild ( string pred ) {
125- result = Call . super .getAChild ( pred )
97+ override AstNode getAChild ( string pred ) {
98+ result = super .getAChild ( pred )
12699 or
127100 pred = "getReceiver" and result = this .getReceiver ( )
128101 or
129102 pred = "getBlock" and result = this .getBlock ( )
130103 }
131104}
132105
133- private class IdentifierMethodCall extends MethodCall , TIdentifierMethodCall {
134- private Generated:: Identifier g ;
135-
136- IdentifierMethodCall ( ) { this = TIdentifierMethodCall ( g ) }
137-
138- final override string getMethodName ( ) { result = getMethodName ( this , g .getValue ( ) ) }
139-
140- final override Self getReceiver ( ) { result = TSelfSynth ( this , 0 ) }
141- }
142-
143- private class ScopeResolutionMethodCall extends MethodCall , TScopeResolutionMethodCall {
144- private Generated:: ScopeResolution g ;
145- private Generated:: Identifier i ;
146-
147- ScopeResolutionMethodCall ( ) { this = TScopeResolutionMethodCall ( g , i ) }
148-
149- final override Expr getReceiver ( ) { toGenerated ( result ) = g .getScope ( ) }
150-
151- final override string getMethodName ( ) { result = getMethodName ( this , i .getValue ( ) ) }
152- }
153-
154- private class RegularMethodCall extends MethodCall , TRegularMethodCall {
155- private Generated:: Call g ;
156-
157- RegularMethodCall ( ) { this = TRegularMethodCall ( g ) }
158-
159- final override Expr getReceiver ( ) {
160- toGenerated ( result ) = g .getReceiver ( )
161- or
162- not exists ( g .getReceiver ( ) ) and
163- toGenerated ( result ) = g .getMethod ( ) .( Generated:: ScopeResolution ) .getScope ( )
164- or
165- result = TSelfSynth ( this , 0 )
166- }
167-
168- final override string getMethodName ( ) {
169- exists ( string res | result = getMethodName ( this , res ) |
170- res = "call" and g .getMethod ( ) instanceof Generated:: ArgumentList
171- or
172- res = g .getMethod ( ) .( Generated:: Token ) .getValue ( )
173- or
174- res = g .getMethod ( ) .( Generated:: ScopeResolution ) .getName ( ) .( Generated:: Token ) .getValue ( )
175- )
176- }
177-
178- final override Expr getArgument ( int n ) {
179- toGenerated ( result ) = g .getArguments ( ) .getChild ( n )
180- or
181- toGenerated ( result ) = g .getMethod ( ) .( Generated:: ArgumentList ) .getChild ( n )
182- }
183-
184- final override Block getBlock ( ) { toGenerated ( result ) = g .getBlock ( ) }
185- }
186-
187106/**
188107 * A call to a setter method.
189108 * ```rb
190109 * self.foo = 10
191110 * a[0] = 10
192111 * ```
193112 */
194- class SetterMethodCall extends MethodCall , LhsExpr {
113+ class SetterMethodCall extends MethodCall {
114+ SetterMethodCall ( ) { this = TMethodCallSynth ( _, _, _, true , _) }
115+
195116 final override string getAPrimaryQlClass ( ) { result = "SetterMethodCall" }
196117}
197118
@@ -202,18 +123,8 @@ class SetterMethodCall extends MethodCall, LhsExpr {
202123 * ```
203124 */
204125class ElementReference extends MethodCall , TElementReference {
205- private Generated:: ElementReference g ;
206-
207- ElementReference ( ) { this = TElementReference ( g ) }
208-
209126 final override string getAPrimaryQlClass ( ) { result = "ElementReference" }
210127
211- final override Expr getReceiver ( ) { toGenerated ( result ) = g .getObject ( ) }
212-
213- final override string getMethodName ( ) { result = getMethodName ( this , "[]" ) }
214-
215- final override Expr getArgument ( int n ) { toGenerated ( result ) = g .getChild ( n ) }
216-
217128 final override string toString ( ) { result = "...[...]" }
218129}
219130
@@ -224,14 +135,12 @@ class ElementReference extends MethodCall, TElementReference {
224135 * ```
225136 */
226137class YieldCall extends Call , TYieldCall {
227- private Generated:: Yield g ;
138+ Generated:: Yield g ;
228139
229140 YieldCall ( ) { this = TYieldCall ( g ) }
230141
231142 final override string getAPrimaryQlClass ( ) { result = "YieldCall" }
232143
233- final override Expr getArgument ( int n ) { toGenerated ( result ) = g .getChild ( ) .getChild ( n ) }
234-
235144 final override string toString ( ) { result = "yield ..." }
236145}
237146
@@ -249,28 +158,6 @@ class SuperCall extends MethodCall, TSuperCall {
249158 final override string getAPrimaryQlClass ( ) { result = "SuperCall" }
250159}
251160
252- private class TokenSuperCall extends SuperCall , TTokenSuperCall {
253- private Generated:: Super g ;
254-
255- TokenSuperCall ( ) { this = TTokenSuperCall ( g ) }
256-
257- final override string getMethodName ( ) { result = getMethodName ( this , g .getValue ( ) ) }
258- }
259-
260- private class RegularSuperCall extends SuperCall , TRegularSuperCall {
261- private Generated:: Call g ;
262-
263- RegularSuperCall ( ) { this = TRegularSuperCall ( g ) }
264-
265- final override string getMethodName ( ) {
266- result = getMethodName ( this , g .getMethod ( ) .( Generated:: Super ) .getValue ( ) )
267- }
268-
269- final override Expr getArgument ( int n ) { toGenerated ( result ) = g .getArguments ( ) .getChild ( n ) }
270-
271- final override Block getBlock ( ) { toGenerated ( result ) = g .getBlock ( ) }
272- }
273-
274161/**
275162 * A block argument in a method call.
276163 * ```rb
0 commit comments