Skip to content

Commit 50210a9

Browse files
committed
Go: ParameterPosition and ArgumentPosition
Corresponds to #7260, though some of those changes had already been made.
1 parent 83a3af2 commit 50210a9

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowDispatch.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,18 @@ predicate mayBenefitFromCallContext(DataFlowCall call, DataFlowCallable f) { non
109109
*/
110110
DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) { none() }
111111

112-
/** Holds if `i` is a valid parameter position. */
113-
predicate parameterPosition(int i) {
114-
i = [-1 .. any(DataFlowCallable c).getType().getNumParameter()]
112+
private int parameterPosition() {
113+
result = [-1 .. any(DataFlowCallable c).getType().getNumParameter()]
115114
}
116115

117-
/** Gets the parameter position of the instance parameter. */
118-
int instanceParameterPosition() { result = -1 }
119-
120116
/** A parameter position represented by an integer. */
121117
class ParameterPosition extends int {
122-
ParameterPosition() { parameterPosition(this) }
118+
ParameterPosition() { this = parameterPosition() }
123119
}
124120

125121
/** An argument position represented by an integer. */
126122
class ArgumentPosition extends int {
127-
ArgumentPosition() { parameterPosition(this) }
123+
ArgumentPosition() { this = parameterPosition() }
128124
}
129125

130126
/** Holds if arguments at position `apos` match parameters at position `ppos`. */

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ private newtype TNode =
2525

2626
/** Nodes intended for only use inside the data-flow libraries. */
2727
module Private {
28+
private import DataFlowDispatch
29+
2830
/** Gets the callable in which this node occurs. */
2931
DataFlowCallable nodeGetEnclosingCallable(Node n) {
3032
result.asCallable() = n.getEnclosingCallable()
@@ -33,10 +35,15 @@ module Private {
3335
}
3436

3537
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
36-
predicate isParameterNode(ParameterNode p, DataFlowCallable c, int pos) {
38+
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {
3739
p.isParameterOf(c.asCallable(), pos)
3840
}
3941

42+
/** Holds if `arg` is an `ArgumentNode` of `c` with position `pos`. */
43+
predicate isArgumentNode(ArgumentNode arg, DataFlowCall c, ArgumentPosition pos) {
44+
arg.argumentOf(c, pos)
45+
}
46+
4047
/** A data flow node that represents returning a value from a function. */
4148
class ReturnNode extends Node {
4249
ReturnKind kind;

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImplSpecific.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class SummarizedCallableBase = Callable;
1919

2020
DataFlowCallable inject(SummarizedCallable c) { result.asCallable() = c }
2121

22+
/** Gets the parameter position of the instance parameter. */
23+
ArgumentPosition instanceParameterPosition() { result = -1 }
24+
2225
/** Gets the textual representation of a parameter position in the format used for flow summaries. */
2326
string getParameterPositionCsv(ParameterPosition pos) { result = pos.toString() }
2427

@@ -245,7 +248,10 @@ predicate interpretInputSpecific(string c, InterpretNode mid, InterpretNode n) {
245248
)
246249
}
247250

248-
/** Holds if specification component `c` parses as return value `n`. */
251+
/**
252+
* Holds if specification component `c` parses as return value `n` or a range
253+
* containing `n`.
254+
*/
249255
predicate parseReturn(AccessPathToken c, int n) {
250256
(
251257
c = "ReturnValue" and n = 0
@@ -266,8 +272,10 @@ private int parseConstantOrRange(string arg) {
266272
)
267273
}
268274

275+
/** Gets the argument position obtained by parsing `X` in `Parameter[X]`. */
269276
bindingset[arg]
270277
ArgumentPosition parseParamBody(string arg) { result = parseConstantOrRange(arg) }
271278

279+
/** Gets the parameter position obtained by parsing `X` in `Argument[X]`. */
272280
bindingset[arg]
273281
ParameterPosition parseArgBody(string arg) { result = parseConstantOrRange(arg) }

0 commit comments

Comments
 (0)