@@ -51,31 +51,64 @@ class ArgumentNode extends Node {
5151 DataFlowCall getCall ( ) { this .argumentOf ( result , _) }
5252}
5353
54- private newtype TReturnKind = TNormalReturnKind ( )
54+ private newtype TReturnKind =
55+ TNormalReturnKind ( ) or
56+ TRefReturnKind ( int i ) { exists ( Parameter parameter | i = parameter .getIndex ( ) ) }
5557
5658/**
5759 * A return kind. A return kind describes how a value can be returned
5860 * from a callable. For C++, this is simply a function return.
5961 */
6062class ReturnKind extends TReturnKind {
6163 /** Gets a textual representation of this return kind. */
62- string toString ( ) { result = "return" }
64+ string toString ( ) {
65+ this instanceof TNormalReturnKind and
66+ result = "return"
67+ or
68+ this instanceof TRefReturnKind and
69+ result = "ref"
70+ }
71+ }
72+
73+ /** A data flow node that represents a returned value in the called function. */
74+ abstract class ReturnNode extends Node {
75+ /** Gets the kind of this returned value. */
76+ abstract ReturnKind getKind ( ) ;
6377}
6478
65- /** A data flow node that occurs as the result of a `ReturnStmt`. */
66- class ReturnNode extends ExprNode {
67- ReturnNode ( ) { exists ( ReturnStmt ret | this .getExpr ( ) = ret .getExpr ( ) ) }
79+ /** A `ReturnNode` that occurs as the result of a `ReturnStmt`. */
80+ private class NormalReturnNode extends ReturnNode , ExprNode {
81+ NormalReturnNode ( ) { exists ( ReturnStmt ret | this .getExpr ( ) = ret .getExpr ( ) ) }
6882
6983 /** Gets the kind of this returned value. */
70- ReturnKind getKind ( ) { result = TNormalReturnKind ( ) }
84+ override ReturnKind getKind ( ) { result = TNormalReturnKind ( ) }
85+ }
86+
87+ /**
88+ * A `ReturnNode` that occurs as a result of a definition of a reference
89+ * parameter reaching the end of a function body.
90+ */
91+ private class RefReturnNode extends ReturnNode , RefParameterFinalValueNode {
92+ /** Gets the kind of this returned value. */
93+ override ReturnKind getKind ( ) { result = TRefReturnKind ( this .getParameter ( ) .getIndex ( ) ) }
7194}
7295
73- /** A data flow node that represents the output of a call. */
74- class OutNode extends ExprNode {
75- OutNode ( ) { this .getExpr ( ) instanceof Call }
96+ /** A data flow node that represents the output of a call at the call site. */
97+ abstract class OutNode extends Node {
98+ /** Gets the underlying call. */
99+ abstract DataFlowCall getCall ( ) ;
100+ }
101+
102+ private class ExprOutNode extends OutNode , ExprNode {
103+ ExprOutNode ( ) { this .getExpr ( ) instanceof Call }
76104
77105 /** Gets the underlying call. */
78- DataFlowCall getCall ( ) { result = this .getExpr ( ) }
106+ override DataFlowCall getCall ( ) { result = this .getExpr ( ) }
107+ }
108+
109+ private class RefOutNode extends OutNode , DefinitionByReferenceNode {
110+ /** Gets the underlying call. */
111+ override DataFlowCall getCall ( ) { result = this .getArgument ( ) .getParent ( ) }
79112}
80113
81114/**
@@ -85,6 +118,11 @@ class OutNode extends ExprNode {
85118OutNode getAnOutNode ( DataFlowCall call , ReturnKind kind ) {
86119 result = call .getNode ( ) and
87120 kind = TNormalReturnKind ( )
121+ or
122+ exists ( int i |
123+ result .asDefiningArgument ( ) = call .getArgument ( i ) and
124+ kind = TRefReturnKind ( i )
125+ )
88126}
89127
90128/**
0 commit comments