@@ -274,12 +274,28 @@ class ReceiverVariable extends Parameter {
274274
275275/** A (named) function result variable. */
276276class ResultVariable extends DeclaredVariable {
277- FuncDef fn ;
277+ FuncDef f ;
278+ int index ;
278279
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+ }
280290
281291 /** 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 }
283299}
284300
285301/**
@@ -396,13 +412,19 @@ class Function extends ValueEntity, @functionobject {
396412 Type getResultType ( int i ) { result = getType ( ) .( SignatureType ) .getResultType ( i ) }
397413
398414 /** Gets the body of this function, if any. */
399- BlockStmt getBody ( ) { none ( ) }
415+ BlockStmt getBody ( ) { result = getFuncDecl ( ) . getBody ( ) }
400416
401417 /** Gets the `i`th parameter of this function. */
402- Parameter getParameter ( int i ) { none ( ) }
418+ Parameter getParameter ( int i ) { result . isParameterOf ( getFuncDecl ( ) , i ) }
403419
404420 /** Gets a parameter of this function. */
405421 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 ( _) }
406428}
407429
408430/**
@@ -512,10 +534,6 @@ class Method extends Function {
512534class DeclaredFunction extends Function , DeclaredEntity , @declfunctionobject {
513535 override FuncDecl getFuncDecl ( ) { result .getNameExpr ( ) = this .getDeclaration ( ) }
514536
515- override BlockStmt getBody ( ) { result = getFuncDecl ( ) .getBody ( ) }
516-
517- override Parameter getParameter ( int i ) { result = getFuncDecl ( ) .getParameter ( i ) }
518-
519537 override predicate mayHaveSideEffects ( ) {
520538 not exists ( getBody ( ) )
521539 or
0 commit comments