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

Commit 56f295f

Browse files
author
Max Schaefer
committed
Add a few useful shortcuts.
1 parent 8667b64 commit 56f295f

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

ql/src/semmle/go/Decls.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ class FuncDef extends @funcdef, StmtParent, ExprParent {
124124
*/
125125
Parameter getParameter(int i) { result.isParameterOf(this, i) }
126126

127-
/**
128-
* Gets a parameter of this function.
129-
*/
127+
/** Gets a parameter of this function. */
130128
Parameter getAParameter() { result.getFunction() = this }
131129

132130
/**

ql/src/semmle/go/Scopes.qll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,19 @@ class Function extends ValueEntity, @functionobject {
412412
Type getResultType(int i) { result = getType().(SignatureType).getResultType(i) }
413413

414414
/** Gets the body of this function, if any. */
415-
BlockStmt getBody() { none() }
415+
BlockStmt getBody() { result = getFuncDecl().getBody() }
416416

417417
/** Gets the `i`th parameter of this function. */
418-
Parameter getParameter(int i) { none() }
418+
Parameter getParameter(int i) { result.isParameterOf(getFuncDecl(), i) }
419419

420420
/** Gets a parameter of this function. */
421421
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(_) }
422428
}
423429

424430
/**
@@ -528,10 +534,6 @@ class Method extends Function {
528534
class DeclaredFunction extends Function, DeclaredEntity, @declfunctionobject {
529535
override FuncDecl getFuncDecl() { result.getNameExpr() = this.getDeclaration() }
530536

531-
override BlockStmt getBody() { result = getFuncDecl().getBody() }
532-
533-
override Parameter getParameter(int i) { result = getFuncDecl().getParameter(i) }
534-
535537
override predicate mayHaveSideEffects() {
536538
not exists(getBody())
537539
or

ql/src/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ abstract class FunctionNode extends Node {
245245
* Gets the data-flow node corresponding to the `i`th result of this function.
246246
*/
247247
ResultNode getResult(int i) { result = getAResult() and result.getIndex() = i }
248+
249+
/**
250+
* Gets the function entity this node corresponds to.
251+
*
252+
* Note that this predicate has no result for function literals.
253+
*/
254+
Function getFunction() { none() }
248255
}
249256

250257
/** A representation of a function that is declared in the module scope. */
@@ -257,8 +264,7 @@ class GlobalFunctionNode extends FunctionNode, MkGlobalFunctionNode {
257264

258265
override string getName() { result = func.getName() }
259266

260-
/** Gets the function this node corresponds to. */
261-
Function getFunction() { result = func }
267+
override Function getFunction() { result = func }
262268

263269
override ReceiverNode getReceiver() { result = receiverNode(func.(Method).getReceiver()) }
264270

0 commit comments

Comments
 (0)