Rust: add Callable::getParam and CallExprBase::getArg shortcuts

This commit is contained in:
Paolo Tranquilli
2025-06-06 16:18:16 +02:00
parent c1c0a705b9
commit a405a12e93
26 changed files with 159 additions and 48 deletions

View File

@@ -1,4 +1,4 @@
| gen_call_expr.rs:5:5:5:11 | foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasFunction: | yes |
| gen_call_expr.rs:6:5:6:23 | foo::<...>(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasFunction: | yes |
| gen_call_expr.rs:7:5:7:14 | ...(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasFunction: | yes |
| gen_call_expr.rs:8:5:8:10 | foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasFunction: | yes |
| gen_call_expr.rs:5:5:5:11 | foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | getNumberOfArgs: | 1 | hasFunction: | yes |
| gen_call_expr.rs:6:5:6:23 | foo::<...>(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | getNumberOfArgs: | 1 | hasFunction: | yes |
| gen_call_expr.rs:7:5:7:14 | ...(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | getNumberOfArgs: | 1 | hasFunction: | yes |
| gen_call_expr.rs:8:5:8:10 | foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | getNumberOfArgs: | 1 | hasFunction: | yes |

View File

@@ -2,12 +2,13 @@
import codeql.rust.elements
import TestUtils
from CallExpr x, string hasArgList, int getNumberOfAttrs, string hasFunction
from CallExpr x, string hasArgList, int getNumberOfAttrs, int getNumberOfArgs, string hasFunction
where
toBeTested(x) and
not x.isUnknown() and
(if x.hasArgList() then hasArgList = "yes" else hasArgList = "no") and
getNumberOfAttrs = x.getNumberOfAttrs() and
getNumberOfArgs = x.getNumberOfArgs() and
if x.hasFunction() then hasFunction = "yes" else hasFunction = "no"
select x, "hasArgList:", hasArgList, "getNumberOfAttrs:", getNumberOfAttrs, "hasFunction:",
hasFunction
select x, "hasArgList:", hasArgList, "getNumberOfAttrs:", getNumberOfAttrs, "getNumberOfArgs:",
getNumberOfArgs, "hasFunction:", hasFunction

View File

@@ -0,0 +1,4 @@
| gen_call_expr.rs:5:5:5:11 | foo(...) | 0 | gen_call_expr.rs:5:9:5:10 | 42 |
| gen_call_expr.rs:6:5:6:23 | foo::<...>(...) | 0 | gen_call_expr.rs:6:21:6:22 | 42 |
| gen_call_expr.rs:7:5:7:14 | ...(...) | 0 | gen_call_expr.rs:7:12:7:13 | 42 |
| gen_call_expr.rs:8:5:8:10 | foo(...) | 0 | gen_call_expr.rs:8:9:8:9 | 1 |

View File

@@ -0,0 +1,7 @@
// generated by codegen, do not edit
import codeql.rust.elements
import TestUtils
from CallExpr x, int index
where toBeTested(x) and not x.isUnknown()
select x, index, x.getArg(index)

View File

@@ -1,5 +1,5 @@
| gen_closure_expr.rs:5:5:5:13 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 0 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | no | isStatic: | no | hasRetType: | no |
| gen_closure_expr.rs:6:5:6:34 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 0 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | yes | isStatic: | no | hasRetType: | yes |
| gen_closure_expr.rs:7:5:7:27 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 0 | hasBody: | yes | hasClosureBinder: | no | isAsync: | yes | isConst: | no | isGen: | no | isMove: | no | isStatic: | no | hasRetType: | no |
| gen_closure_expr.rs:8:6:9:15 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 1 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | no | isStatic: | no | hasRetType: | no |
| gen_closure_expr.rs:10:6:11:23 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 1 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | no | isStatic: | yes | hasRetType: | no |
| gen_closure_expr.rs:5:5:5:13 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 0 | getNumberOfParams: | 1 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | no | isStatic: | no | hasRetType: | no |
| gen_closure_expr.rs:6:5:6:34 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 0 | getNumberOfParams: | 1 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | yes | isStatic: | no | hasRetType: | yes |
| gen_closure_expr.rs:7:5:7:27 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 0 | getNumberOfParams: | 2 | hasBody: | yes | hasClosureBinder: | no | isAsync: | yes | isConst: | no | isGen: | no | isMove: | no | isStatic: | no | hasRetType: | no |
| gen_closure_expr.rs:8:6:9:15 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 1 | getNumberOfParams: | 1 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | no | isStatic: | no | hasRetType: | no |
| gen_closure_expr.rs:10:6:11:23 | \|...\| ... | hasParamList: | yes | getNumberOfAttrs: | 1 | getNumberOfParams: | 1 | hasBody: | yes | hasClosureBinder: | no | isAsync: | no | isConst: | no | isGen: | no | isMove: | no | isStatic: | yes | hasRetType: | no |

View File

@@ -3,13 +3,15 @@ import codeql.rust.elements
import TestUtils
from
ClosureExpr x, string hasParamList, int getNumberOfAttrs, string hasBody, string hasClosureBinder,
string isAsync, string isConst, string isGen, string isMove, string isStatic, string hasRetType
ClosureExpr x, string hasParamList, int getNumberOfAttrs, int getNumberOfParams, string hasBody,
string hasClosureBinder, string isAsync, string isConst, string isGen, string isMove,
string isStatic, string hasRetType
where
toBeTested(x) and
not x.isUnknown() and
(if x.hasParamList() then hasParamList = "yes" else hasParamList = "no") and
getNumberOfAttrs = x.getNumberOfAttrs() and
getNumberOfParams = x.getNumberOfParams() and
(if x.hasBody() then hasBody = "yes" else hasBody = "no") and
(if x.hasClosureBinder() then hasClosureBinder = "yes" else hasClosureBinder = "no") and
(if x.isAsync() then isAsync = "yes" else isAsync = "no") and
@@ -18,6 +20,7 @@ where
(if x.isMove() then isMove = "yes" else isMove = "no") and
(if x.isStatic() then isStatic = "yes" else isStatic = "no") and
if x.hasRetType() then hasRetType = "yes" else hasRetType = "no"
select x, "hasParamList:", hasParamList, "getNumberOfAttrs:", getNumberOfAttrs, "hasBody:", hasBody,
"hasClosureBinder:", hasClosureBinder, "isAsync:", isAsync, "isConst:", isConst, "isGen:", isGen,
"isMove:", isMove, "isStatic:", isStatic, "hasRetType:", hasRetType
select x, "hasParamList:", hasParamList, "getNumberOfAttrs:", getNumberOfAttrs,
"getNumberOfParams:", getNumberOfParams, "hasBody:", hasBody, "hasClosureBinder:",
hasClosureBinder, "isAsync:", isAsync, "isConst:", isConst, "isGen:", isGen, "isMove:", isMove,
"isStatic:", isStatic, "hasRetType:", hasRetType

View File

@@ -0,0 +1,6 @@
| gen_closure_expr.rs:5:5:5:13 | \|...\| ... | 0 | gen_closure_expr.rs:5:6:5:6 | ... |
| gen_closure_expr.rs:6:5:6:34 | \|...\| ... | 0 | gen_closure_expr.rs:6:11:6:16 | ...: i32 |
| gen_closure_expr.rs:7:5:7:27 | \|...\| ... | 0 | gen_closure_expr.rs:7:12:7:17 | ...: i32 |
| gen_closure_expr.rs:7:5:7:27 | \|...\| ... | 1 | gen_closure_expr.rs:7:20:7:20 | ... |
| gen_closure_expr.rs:8:6:9:15 | \|...\| ... | 0 | gen_closure_expr.rs:9:6:9:6 | ... |
| gen_closure_expr.rs:10:6:11:23 | \|...\| ... | 0 | gen_closure_expr.rs:11:14:11:14 | ... |

View File

@@ -0,0 +1,7 @@
// generated by codegen, do not edit
import codeql.rust.elements
import TestUtils
from ClosureExpr x, int index
where toBeTested(x) and not x.isUnknown()
select x, index, x.getParam(index)

View File

@@ -1,2 +1,2 @@
| gen_function.rs:3:1:4:38 | fn foo | hasParamList: | yes | getNumberOfAttrs: | 0 | hasExtendedCanonicalPath: | yes | hasCrateOrigin: | yes | hasAttributeMacroExpansion: | no | hasAbi: | no | hasBody: | yes | hasGenericParamList: | no | isAsync: | no | isConst: | no | isDefault: | no | isGen: | no | isUnsafe: | no | hasName: | yes | hasRetType: | yes | hasVisibility: | no | hasWhereClause: | no |
| gen_function.rs:7:5:7:13 | fn bar | hasParamList: | yes | getNumberOfAttrs: | 0 | hasExtendedCanonicalPath: | yes | hasCrateOrigin: | yes | hasAttributeMacroExpansion: | no | hasAbi: | no | hasBody: | no | hasGenericParamList: | no | isAsync: | no | isConst: | no | isDefault: | no | isGen: | no | isUnsafe: | no | hasName: | yes | hasRetType: | no | hasVisibility: | no | hasWhereClause: | no |
| gen_function.rs:3:1:4:38 | fn foo | hasParamList: | yes | getNumberOfAttrs: | 0 | getNumberOfParams: | 1 | hasExtendedCanonicalPath: | yes | hasCrateOrigin: | yes | hasAttributeMacroExpansion: | no | hasAbi: | no | hasBody: | yes | hasGenericParamList: | no | isAsync: | no | isConst: | no | isDefault: | no | isGen: | no | isUnsafe: | no | hasName: | yes | hasRetType: | yes | hasVisibility: | no | hasWhereClause: | no |
| gen_function.rs:7:5:7:13 | fn bar | hasParamList: | yes | getNumberOfAttrs: | 0 | getNumberOfParams: | 0 | hasExtendedCanonicalPath: | yes | hasCrateOrigin: | yes | hasAttributeMacroExpansion: | no | hasAbi: | no | hasBody: | no | hasGenericParamList: | no | isAsync: | no | isConst: | no | isDefault: | no | isGen: | no | isUnsafe: | no | hasName: | yes | hasRetType: | no | hasVisibility: | no | hasWhereClause: | no |

View File

@@ -3,15 +3,17 @@ import codeql.rust.elements
import TestUtils
from
Function x, string hasParamList, int getNumberOfAttrs, string hasExtendedCanonicalPath,
string hasCrateOrigin, string hasAttributeMacroExpansion, string hasAbi, string hasBody,
string hasGenericParamList, string isAsync, string isConst, string isDefault, string isGen,
string isUnsafe, string hasName, string hasRetType, string hasVisibility, string hasWhereClause
Function x, string hasParamList, int getNumberOfAttrs, int getNumberOfParams,
string hasExtendedCanonicalPath, string hasCrateOrigin, string hasAttributeMacroExpansion,
string hasAbi, string hasBody, string hasGenericParamList, string isAsync, string isConst,
string isDefault, string isGen, string isUnsafe, string hasName, string hasRetType,
string hasVisibility, string hasWhereClause
where
toBeTested(x) and
not x.isUnknown() and
(if x.hasParamList() then hasParamList = "yes" else hasParamList = "no") and
getNumberOfAttrs = x.getNumberOfAttrs() and
getNumberOfParams = x.getNumberOfParams() and
(
if x.hasExtendedCanonicalPath()
then hasExtendedCanonicalPath = "yes"
@@ -36,8 +38,9 @@ where
(if x.hasVisibility() then hasVisibility = "yes" else hasVisibility = "no") and
if x.hasWhereClause() then hasWhereClause = "yes" else hasWhereClause = "no"
select x, "hasParamList:", hasParamList, "getNumberOfAttrs:", getNumberOfAttrs,
"hasExtendedCanonicalPath:", hasExtendedCanonicalPath, "hasCrateOrigin:", hasCrateOrigin,
"hasAttributeMacroExpansion:", hasAttributeMacroExpansion, "hasAbi:", hasAbi, "hasBody:", hasBody,
"hasGenericParamList:", hasGenericParamList, "isAsync:", isAsync, "isConst:", isConst,
"isDefault:", isDefault, "isGen:", isGen, "isUnsafe:", isUnsafe, "hasName:", hasName,
"hasRetType:", hasRetType, "hasVisibility:", hasVisibility, "hasWhereClause:", hasWhereClause
"getNumberOfParams:", getNumberOfParams, "hasExtendedCanonicalPath:", hasExtendedCanonicalPath,
"hasCrateOrigin:", hasCrateOrigin, "hasAttributeMacroExpansion:", hasAttributeMacroExpansion,
"hasAbi:", hasAbi, "hasBody:", hasBody, "hasGenericParamList:", hasGenericParamList, "isAsync:",
isAsync, "isConst:", isConst, "isDefault:", isDefault, "isGen:", isGen, "isUnsafe:", isUnsafe,
"hasName:", hasName, "hasRetType:", hasRetType, "hasVisibility:", hasVisibility,
"hasWhereClause:", hasWhereClause

View File

@@ -0,0 +1 @@
| gen_function.rs:3:1:4:38 | fn foo | 0 | gen_function.rs:4:8:4:13 | ...: u32 |

View File

@@ -0,0 +1,7 @@
// generated by codegen, do not edit
import codeql.rust.elements
import TestUtils
from Function x, int index
where toBeTested(x) and not x.isUnknown()
select x, index, x.getParam(index)

View File

@@ -1,2 +1,2 @@
| gen_method_call_expr.rs:5:5:5:13 | x.foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | no | hasIdentifier: | yes | hasReceiver: | yes |
| gen_method_call_expr.rs:6:5:6:25 | x.foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | yes | hasIdentifier: | yes | hasReceiver: | yes |
| gen_method_call_expr.rs:5:5:5:13 | x.foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | getNumberOfArgs: | 1 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | no | hasIdentifier: | yes | hasReceiver: | yes |
| gen_method_call_expr.rs:6:5:6:25 | x.foo(...) | hasArgList: | yes | getNumberOfAttrs: | 0 | getNumberOfArgs: | 1 | hasResolvedPath: | no | hasResolvedCrateOrigin: | no | hasGenericArgList: | yes | hasIdentifier: | yes | hasReceiver: | yes |

View File

@@ -3,13 +3,15 @@ import codeql.rust.elements
import TestUtils
from
MethodCallExpr x, string hasArgList, int getNumberOfAttrs, string hasResolvedPath,
string hasResolvedCrateOrigin, string hasGenericArgList, string hasIdentifier, string hasReceiver
MethodCallExpr x, string hasArgList, int getNumberOfAttrs, int getNumberOfArgs,
string hasResolvedPath, string hasResolvedCrateOrigin, string hasGenericArgList,
string hasIdentifier, string hasReceiver
where
toBeTested(x) and
not x.isUnknown() and
(if x.hasArgList() then hasArgList = "yes" else hasArgList = "no") and
getNumberOfAttrs = x.getNumberOfAttrs() and
getNumberOfArgs = x.getNumberOfArgs() and
(if x.hasResolvedPath() then hasResolvedPath = "yes" else hasResolvedPath = "no") and
(
if x.hasResolvedCrateOrigin()
@@ -19,6 +21,7 @@ where
(if x.hasGenericArgList() then hasGenericArgList = "yes" else hasGenericArgList = "no") and
(if x.hasIdentifier() then hasIdentifier = "yes" else hasIdentifier = "no") and
if x.hasReceiver() then hasReceiver = "yes" else hasReceiver = "no"
select x, "hasArgList:", hasArgList, "getNumberOfAttrs:", getNumberOfAttrs, "hasResolvedPath:",
hasResolvedPath, "hasResolvedCrateOrigin:", hasResolvedCrateOrigin, "hasGenericArgList:",
hasGenericArgList, "hasIdentifier:", hasIdentifier, "hasReceiver:", hasReceiver
select x, "hasArgList:", hasArgList, "getNumberOfAttrs:", getNumberOfAttrs, "getNumberOfArgs:",
getNumberOfArgs, "hasResolvedPath:", hasResolvedPath, "hasResolvedCrateOrigin:",
hasResolvedCrateOrigin, "hasGenericArgList:", hasGenericArgList, "hasIdentifier:", hasIdentifier,
"hasReceiver:", hasReceiver

View File

@@ -0,0 +1,2 @@
| gen_method_call_expr.rs:5:5:5:13 | x.foo(...) | 0 | gen_method_call_expr.rs:5:11:5:12 | 42 |
| gen_method_call_expr.rs:6:5:6:25 | x.foo(...) | 0 | gen_method_call_expr.rs:6:23:6:24 | 42 |

View File

@@ -0,0 +1,7 @@
// generated by codegen, do not edit
import codeql.rust.elements
import TestUtils
from MethodCallExpr x, int index
where toBeTested(x) and not x.isUnknown()
select x, index, x.getArg(index)