-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Python: Move min/maxParameter methods to Function
class
#18871
base: main
Are you sure you want to change the base?
Python: Move min/maxParameter methods to Function
class
#18871
Conversation
These seem generally useful outside of points-to, and so it might be better to add them to the `Function` class instead. I took the liberty of renaming these to say `Arguments` rather than `Parameters`, as this is more in line with the nomenclature that we're using elsewhere. (The internal points-to methods retain the old names.) I'm somewhat ambivalent about the behaviour of `getMaxParameters` on functions with `*varargs`. The hard-coded `INT_MAX` return value is somewhat awkward, but the alternative (to only have the predicate defined when a specific maximum exists) seems like it would potentially cause a lot of headaches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This PR moves the min/max parameter methods to the Function class and renames them to use “Arguments” for consistency with the rest of the codebase.
- Moved methods from a points-to context into the Function class.
- Renamed the methods to getMinArguments and getMaxArguments, and updated the corresponding change notes.
Reviewed Changes
File | Description |
---|---|
python/ql/lib/change-notes/2025-02-26-add-get-min-max-parameters-to-function-class.md | Added change notes documenting the new Function class methods |
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, stylistic questions only.
@@ -163,6 +163,18 @@ class Function extends Function_, Scope, AstNode { | |||
ret.getValue() = result.getNode() | |||
) | |||
} | |||
|
|||
/** Gets the minimum number of positional arguments that can be correctly passed to this function. */ | |||
int getMinArguments() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: Should these be getMinPositionalArguments
, something like that?
/** Gets the maximum number of positional arguments that can be correctly passed to this function. */ | ||
int getMaxArguments() { | ||
if exists(this.getVararg()) | ||
then result = 2147483647 // INT_MAX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh this is an interesting trap. I suggest at least putting it in the QLDoc, i.e. if the function doesn't take varargs, the result is INT_MAX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
These seem generally useful outside of points-to, and so it might be better to add them to the
Function
class instead.I took the liberty of renaming these to say
Arguments
rather thanParameters
, as this is more in line with the nomenclature that we're using elsewhere. (The internal points-to methods retain the old names.)I'm somewhat ambivalent about the behaviour of
getMaxParameters
on functions with*varargs
. The hard-codedINT_MAX
return value is somewhat awkward, but the alternative (to only have the predicate defined when a specific maximum exists) seems like it would potentially cause a lot of headaches.