codeql
codeql copied to clipboard
Need help in implementing a predicate in a query
Description of the issue
I want to write a predicate similar to getEnclosingFunction() for TypeDecls and ParameterOrResultDecls.
The problem I am facing is i want to limit my search of certain entities to a particular TypeDecl but there is no convenient predicate like getEnclosingTypeDecl() that I can use.
Please
1.share the implementation of getEnclosingFunction() predicate
2. help me write some similar predicate for any type in codeql(but particularly TypeDecl and ParameterOrResultDecl).
ParameterOrResultDecl has the required predicate:
from ParameterOrResultDecl d
select d.getEnclosingFunction()
The implementation can be found in AST.qll -- try ctrl/cmd-clicking in VS Code to navigate to the definition.
/** Gets the innermost function definition to which this AST node belongs, if any. */
FuncDef getEnclosingFunction() { result = this.getParent().parentInSameFunction*() }
TypeDecl similarly inherits getEnclosingFunction from ASTNode, so the same query will work with from TypeDecl d.
@smowton I think I was not able to explain my problem, What I want to do is
from TypeVariable tv,ParameterOrResultDecl d
where tv.getEnclosingParameterDecl()=d
select tv
I want to make sure that tv is a child of d. I don't want to know or worry about which child it is... it may be nested inside any amount of selector nodes.
So for all ast node structures like
ParameterDecl>SelectorExpression>SelectorExpression>MapTypeExpression>SelectorExpression>.....>TypeVariable I only want to worry about TypeVariables being enclosed in ParameterDecl/ResultDecl
We don't have TypeVariable in Golang, and I infer from ParameterOrResultDecl that we must be talking about QL for Golang? Could you give an example of some Go source code and what you want to identify?
This issue is stale because it has been open 14 days with no activity. Comment or remove the Stale label in order to avoid having this issue closed in 7 days.
This issue was closed because it has been inactive for 7 days.