@@ -117,6 +117,19 @@ module Unified {
117117 class Argument extends G:: Argument {
118118 /** Gets the name of this argument. */
119119 string getName ( ) { result = this .getNameNode ( ) .getValue ( ) }
120+
121+ /** Holds if this is a positional argument. */
122+ predicate isPositional ( ) { not exists ( this .getName ( ) ) }
123+
124+ /** Gets the 0-based index of this argument among the positional arguments in the surrounding call or tuple. */
125+ int getPositionalIndex ( ) {
126+ this =
127+ rank [ result + 1 ] ( Argument a |
128+ a .getParent ( ) = this .getParent ( ) and a .isPositional ( )
129+ |
130+ a order by a .getParentIndex ( )
131+ )
132+ }
120133 }
121134
122135 class AssociatedTypeDeclaration extends G:: AssociatedTypeDeclaration {
@@ -172,8 +185,28 @@ module Unified {
172185 }
173186
174187 class Parameter extends G:: Parameter {
175- /** Gets the external name of this parameter. */
176- string getExternalName ( ) { result = this .getExternalNameNode ( ) .getValue ( ) }
188+ /**
189+ * Gets the external name of this parameter.
190+ *
191+ * Has no result for pseudo-names like `_` that indicate that this is actually a positional parameter.
192+ */
193+ string getExternalName ( ) { result = this .getExternalNameNode ( ) .getValue ( ) and not result = "_" }
194+
195+ /** Gets the callable on which this parameter appears. */
196+ Callable getDeclaringCallable ( ) { result = this .getParent ( ) }
197+
198+ /** Holds if this is a positional parameter. */
199+ predicate isPositional ( ) { not exists ( this .getExternalName ( ) ) }
200+
201+ /** Gets the 0-based index of this parameter among the positional parameters of the declaring callable. */
202+ int getPositionalIndex ( ) {
203+ this =
204+ rank [ result + 1 ] ( Parameter p |
205+ p .getDeclaringCallable ( ) = this .getDeclaringCallable ( ) and p .isPositional ( )
206+ |
207+ p order by p .getParentIndex ( )
208+ )
209+ }
177210 }
178211
179212 class TypeAliasDeclaration extends G:: TypeAliasDeclaration {
0 commit comments