mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
Add a few useful shortcuts.
This commit is contained in:
@@ -124,9 +124,7 @@ class FuncDef extends @funcdef, StmtParent, ExprParent {
|
||||
*/
|
||||
Parameter getParameter(int i) { result.isParameterOf(this, i) }
|
||||
|
||||
/**
|
||||
* Gets a parameter of this function.
|
||||
*/
|
||||
/** Gets a parameter of this function. */
|
||||
Parameter getAParameter() { result.getFunction() = this }
|
||||
|
||||
/**
|
||||
|
||||
@@ -412,13 +412,19 @@ class Function extends ValueEntity, @functionobject {
|
||||
Type getResultType(int i) { result = getType().(SignatureType).getResultType(i) }
|
||||
|
||||
/** Gets the body of this function, if any. */
|
||||
BlockStmt getBody() { none() }
|
||||
BlockStmt getBody() { result = getFuncDecl().getBody() }
|
||||
|
||||
/** Gets the `i`th parameter of this function. */
|
||||
Parameter getParameter(int i) { none() }
|
||||
Parameter getParameter(int i) { result.isParameterOf(getFuncDecl(), i) }
|
||||
|
||||
/** Gets a parameter of this function. */
|
||||
Parameter getAParameter() { result = getParameter(_) }
|
||||
|
||||
/** Gets the `i`th reslt variable of this function. */
|
||||
ResultVariable getResult(int i) { result.isResultOf(getFuncDecl(), i) }
|
||||
|
||||
/** Gets a result variable of this function. */
|
||||
ResultVariable getAResult() { result = getResult(_) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,10 +534,6 @@ class Method extends Function {
|
||||
class DeclaredFunction extends Function, DeclaredEntity, @declfunctionobject {
|
||||
override FuncDecl getFuncDecl() { result.getNameExpr() = this.getDeclaration() }
|
||||
|
||||
override BlockStmt getBody() { result = getFuncDecl().getBody() }
|
||||
|
||||
override Parameter getParameter(int i) { result = getFuncDecl().getParameter(i) }
|
||||
|
||||
override predicate mayHaveSideEffects() {
|
||||
not exists(getBody())
|
||||
or
|
||||
|
||||
@@ -245,6 +245,13 @@ abstract class FunctionNode extends Node {
|
||||
* Gets the data-flow node corresponding to the `i`th result of this function.
|
||||
*/
|
||||
ResultNode getResult(int i) { result = getAResult() and result.getIndex() = i }
|
||||
|
||||
/**
|
||||
* Gets the function entity this node corresponds to.
|
||||
*
|
||||
* Note that this predicate has no result for function literals.
|
||||
*/
|
||||
Function getFunction() { none() }
|
||||
}
|
||||
|
||||
/** A representation of a function that is declared in the module scope. */
|
||||
@@ -257,8 +264,7 @@ class GlobalFunctionNode extends FunctionNode, MkGlobalFunctionNode {
|
||||
|
||||
override string getName() { result = func.getName() }
|
||||
|
||||
/** Gets the function this node corresponds to. */
|
||||
Function getFunction() { result = func }
|
||||
override Function getFunction() { result = func }
|
||||
|
||||
override ReceiverNode getReceiver() { result = receiverNode(func.(Method).getReceiver()) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user