@@ -170,34 +170,75 @@ private module Cached {
170
170
171
171
cached
172
172
newtype TArgumentPosition =
173
- TPositionalArgumentPosition ( int pos ) { exists ( Cmd c | exists ( c .getArgument ( pos ) ) ) }
173
+ TKeywordArgumentPosition ( string name ) { name = any ( CmdParameter p ) .getName ( ) } or
174
+ TPositionalArgumentPosition ( int pos , NamedSet ns ) {
175
+ exists ( Cmd cmd |
176
+ cmd = ns .getABindingCall ( ) and
177
+ exists ( cmd .getArgument ( pos ) )
178
+ )
179
+ }
174
180
175
181
cached
176
- newtype TParameterPosition = TPositionalParameterPosition ( int pos ) { none ( ) /* TODO */ }
182
+ newtype TParameterPosition =
183
+ TKeywordParameter ( string name ) { name = any ( CmdParameter p ) .getName ( ) } or
184
+ TPositionalParameter ( int pos , NamedSet ns ) {
185
+ exists ( Cmd cmd |
186
+ cmd = ns .getABindingCall ( ) and
187
+ exists ( cmd .getArgument ( pos ) )
188
+ )
189
+ }
177
190
}
178
191
179
192
import Cached
180
193
181
194
/** A parameter position. */
182
195
class ParameterPosition extends TParameterPosition {
183
- /** Holds if this position represents a positional parameter at position `pos`. */
184
- predicate isPositional ( int pos ) { this = TPositionalParameterPosition ( pos ) }
196
+ /**
197
+ * Holds if this position represents a positional parameter at position `pos`
198
+ * with function is called with exactly the named parameters from the set `ns`
199
+ */
200
+ predicate isPositional ( int pos , NamedSet ns ) { this = TPositionalParameter ( pos , ns ) }
201
+
202
+ /** Holds if this parameter is a keyword parameter with `name`. */
203
+ predicate isKeyword ( string name ) { this = TKeywordParameter ( name ) }
185
204
186
205
/** Gets a textual representation of this position. */
187
- string toString ( ) { exists ( int pos | this .isPositional ( pos ) and result = "position " + pos ) }
206
+ string toString ( ) {
207
+ exists ( int pos , NamedSet ns |
208
+ this .isPositional ( pos , ns ) and result = "pos(" + pos + ", " + ns .toString ( ) + ")"
209
+ )
210
+ or
211
+ exists ( string name | this .isKeyword ( name ) and result = "kw(" + name + ")" )
212
+ }
188
213
}
189
214
190
215
/** An argument position. */
191
216
class ArgumentPosition extends TArgumentPosition {
192
217
/** Holds if this position represents a positional argument at position `pos`. */
193
- predicate isPositional ( int pos ) { this = TPositionalArgumentPosition ( pos ) }
218
+ predicate isPositional ( int pos , NamedSet ns ) { this = TPositionalArgumentPosition ( pos , ns ) }
219
+
220
+ predicate isKeyword ( string name ) { this = TKeywordArgumentPosition ( name ) }
194
221
195
222
/** Gets a textual representation of this position. */
196
- string toString ( ) { exists ( int pos | this .isPositional ( pos ) and result = "position " + pos ) }
223
+ string toString ( ) {
224
+ exists ( int pos , NamedSet ns |
225
+ this .isPositional ( pos , ns ) and result = "pos(" + pos + ", " + ns .toString ( ) + ")"
226
+ )
227
+ or
228
+ exists ( string name | this .isKeyword ( name ) and result = "kw(" + name + ")" )
229
+ }
197
230
}
198
231
199
232
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
200
233
pragma [ nomagic]
201
234
predicate parameterMatch ( ParameterPosition ppos , ArgumentPosition apos ) {
202
- exists ( int pos | ppos .isPositional ( pos ) and apos .isPositional ( pos ) )
235
+ exists ( string name |
236
+ ppos .isKeyword ( name ) and
237
+ apos .isKeyword ( name )
238
+ )
239
+ or
240
+ exists ( int pos , NamedSet ns |
241
+ ppos .isPositional ( pos , ns ) and
242
+ apos .isPositional ( pos , ns )
243
+ )
203
244
}
0 commit comments