Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 7b917f9

Browse files
committed
Add utility functions for getting FunctionInputs and FunctionOutputs.
1 parent 397282f commit 7b917f9

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

ql/src/semmle/go/dataflow/FunctionInputsAndOutputs.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class FunctionInput extends TFunctionInput {
5151
abstract string toString();
5252
}
5353

54+
module FunctionInput {
55+
/** Gets a `FunctionInput` representing the `i`th parameter. */
56+
FunctionInput parameter(int i) { result.isParameter(i) }
57+
58+
/** Gets a `FunctionInput` representing the receiver. */
59+
FunctionInput receiver() { result.isReceiver() }
60+
61+
/** Gets a `FunctionInput` representing the result of a single-result function. */
62+
FunctionInput functionResult() { result.isResult() }
63+
64+
/** Gets a `FunctionInput` representing the `i`th result. */
65+
FunctionInput functionResult(int i) { result.isParameter(i) }
66+
}
67+
5468
/** A parameter position of a function, viewed as a source of input. */
5569
private class ParameterInput extends FunctionInput, TInParameter {
5670
int index;
@@ -172,6 +186,20 @@ class FunctionOutput extends TFunctionOutput {
172186
abstract string toString();
173187
}
174188

189+
module FunctionOutput {
190+
/** Gets a `FunctionOutput` representing the result of a single-result function. */
191+
FunctionOutput functionResult() { result.isResult() }
192+
193+
/** Gets a `FunctionOutput` representing the `i`th result. */
194+
FunctionOutput functionResult(int i) { result.isParameter(i) }
195+
196+
/** Gets a `FunctionOutput` representing the receiver after a function returns. */
197+
FunctionOutput receiver() { result.isReceiver() }
198+
199+
/** Gets a `FunctionOutput` representing the `i`th parameter after a function returns. */
200+
FunctionOutput parameter(int i) { result.isParameter(i) }
201+
}
202+
175203
/** A result position of a function, viewed as an output. */
176204
private class OutResult extends FunctionOutput, TOutResult {
177205
int index;

ql/src/semmle/go/frameworks/Echo.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private module Echo {
6868
exists(DataFlow::MethodCallNode call |
6969
call.getTarget().hasQualifiedName(packagePath(), "Context", "Bind")
7070
|
71-
this = any(FunctionOutput output | output.isParameter(0)).getExitNode(call)
71+
this = FunctionOutput::parameter(0).getExitNode(call)
7272
)
7373
}
7474
}

ql/src/semmle/go/frameworks/Gin.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private module Gin {
128128
methodName = "ShouldBindYAML"
129129
)
130130
|
131-
this = any(FunctionOutput output | output.isParameter(0)).getExitNode(call)
131+
this = FunctionOutput::parameter(0).getExitNode(call)
132132
)
133133
)
134134
}

ql/src/semmle/go/frameworks/HTTP.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private module GoRestfulHttp {
3737
.getTarget()
3838
.hasQualifiedName(package("github.com/emicklei/go-restful", ""), "Request", "ReadEntity")
3939
|
40-
this = any(FunctionOutput output | output.isParameter(0)).getExitNode(call)
40+
this = FunctionOutput::parameter(0).getExitNode(call)
4141
)
4242
}
4343
}

0 commit comments

Comments
 (0)