- FunctionCall - Represents a function invocation
- Argument - Represents arguments passed to a function
- Parameter - Represents parameters in a function definition
See Migrating APIs for relevant tutorials and
applications.
Navigating Function Calls
Codegen provides two main ways to navigate function calls:- From a function to its call sites using call_sites
- From a function to the calls it makes (within it’s CodeBlock) using function_calls
- Find heavily used functions
- Analyze call patterns
- Map dependencies between functions
Arguments and Parameters
The Argument class represents values passed to a function, while Parameter represents the receiving variables in the function definition: Consider the following code:Finding Arguments
The primary APIs for finding arguments are:Modifying Arguments
There are two ways to modify function call arguments:- Using FunctionCall.set_kwarg(…) to add or modify keyword arguments:
- Using FuncionCall.args.append(…) to add new arguments:
FunctionCall.args is a Collection of Argument objects, so it supports .append(…), .insert(…) and other collection methods.
set_kwarg
method provides intelligent argument manipulation:
- If the argument exists and is positional, it converts it to a keyword argument
- If the argument exists and is already a keyword, it updates its value (if override_existing=True)
- If the argument doesn’t exist, it creates it (if create_on_missing=True)
- When creating new arguments, it intelligently places them based on parameter order