Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help in implementing a predicate in a query #17153

Closed
aaaayush-n opened this issue Aug 6, 2024 · 5 comments
Closed

Need help in implementing a predicate in a query #17153

aaaayush-n opened this issue Aug 6, 2024 · 5 comments
Labels
awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. question Further information is requested Stale

Comments

@aaaayush-n
Copy link

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).

@aaaayush-n aaaayush-n added the question Further information is requested label Aug 6, 2024
@smowton
Copy link
Contributor

smowton commented Aug 6, 2024

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.

@github github deleted a comment from hac425xxx Aug 6, 2024
@aaaayush-n
Copy link
Author

aaaayush-n commented Aug 7, 2024

@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

@smowton
Copy link
Contributor

smowton commented Aug 7, 2024

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?

@rvermeulen rvermeulen added the awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. label Aug 27, 2024
Copy link
Contributor

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.

@github-actions github-actions bot added the Stale label Sep 11, 2024
Copy link
Contributor

This issue was closed because it has been inactive for 7 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response The CodeQL team is awaiting further input or clarification from the original reporter of this issue. question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants