@@ -274,12 +274,28 @@ class ReceiverVariable extends Parameter {
274
274
275
275
/** A (named) function result variable. */
276
276
class ResultVariable extends DeclaredVariable {
277
- FuncDef fn ;
277
+ FuncDef f ;
278
+ int index ;
278
279
279
- ResultVariable ( ) { fn .getTypeExpr ( ) .getAResultDecl ( ) .getNameExpr ( _) = this .getDeclaration ( ) }
280
+ ResultVariable ( ) {
281
+ exists ( FuncTypeExpr tp | tp = f .getTypeExpr ( ) |
282
+ this =
283
+ rank [ index + 1 ] ( DeclaredVariable parm , int j , int k |
284
+ parm .getDeclaration ( ) = tp .getResultDecl ( j ) .getNameExpr ( k )
285
+ |
286
+ parm order by j , k
287
+ )
288
+ )
289
+ }
280
290
281
291
/** Gets the function to which this result variable belongs. */
282
- FuncDef getFunction ( ) { result = fn }
292
+ FuncDef getFunction ( ) { result = f }
293
+
294
+ /** Gets the index of this result among all results of the function. */
295
+ int getIndex ( ) { result = index }
296
+
297
+ /** Holds if this is the `i`th result of function `fd`. */
298
+ predicate isResultOf ( FuncDef fd , int i ) { fd = f and i = index }
283
299
}
284
300
285
301
/**
@@ -396,13 +412,19 @@ class Function extends ValueEntity, @functionobject {
396
412
Type getResultType ( int i ) { result = getType ( ) .( SignatureType ) .getResultType ( i ) }
397
413
398
414
/** Gets the body of this function, if any. */
399
- BlockStmt getBody ( ) { none ( ) }
415
+ BlockStmt getBody ( ) { result = getFuncDecl ( ) . getBody ( ) }
400
416
401
417
/** Gets the `i`th parameter of this function. */
402
- Parameter getParameter ( int i ) { none ( ) }
418
+ Parameter getParameter ( int i ) { result . isParameterOf ( getFuncDecl ( ) , i ) }
403
419
404
420
/** Gets a parameter of this function. */
405
421
Parameter getAParameter ( ) { result = getParameter ( _) }
422
+
423
+ /** Gets the `i`th reslt variable of this function. */
424
+ ResultVariable getResult ( int i ) { result .isResultOf ( getFuncDecl ( ) , i ) }
425
+
426
+ /** Gets a result variable of this function. */
427
+ ResultVariable getAResult ( ) { result = getResult ( _) }
406
428
}
407
429
408
430
/**
@@ -512,10 +534,6 @@ class Method extends Function {
512
534
class DeclaredFunction extends Function , DeclaredEntity , @declfunctionobject {
513
535
override FuncDecl getFuncDecl ( ) { result .getNameExpr ( ) = this .getDeclaration ( ) }
514
536
515
- override BlockStmt getBody ( ) { result = getFuncDecl ( ) .getBody ( ) }
516
-
517
- override Parameter getParameter ( int i ) { result = getFuncDecl ( ) .getParameter ( i ) }
518
-
519
537
override predicate mayHaveSideEffects ( ) {
520
538
not exists ( getBody ( ) )
521
539
or
0 commit comments