Class PythonLikeAssigningStrategy
- java.lang.Object
-
- it.unive.lisa.program.language.parameterassignment.PythonLikeAssigningStrategy
-
- All Implemented Interfaces:
ParameterAssigningStrategy
public class PythonLikeAssigningStrategy extends java.lang.Object implements ParameterAssigningStrategy
A Python-like assigning strategy. Specifically:
If keyword arguments are present, they are first converted to positional arguments, as follows. First, a list of unfilled slots is created for the formal parameters. If there are N positional arguments, they are placed in the first N slots. Next, for each keyword argument, the identifier is used to determine the corresponding slot (if the identifier is the same as the first formal parameter name, the first slot is used, and so on). If the slot is already filled, a TypeError exception is raised. Otherwise, the value of the argument is placed in the slot, filling it (even if the expression is None, it fills the slot). When all arguments have been processed, the slots that are still unfilled are filled with the corresponding default value from the function definition. [...] If there are any unfilled slots for which no default value is specified, a TypeError exception is raised. Otherwise, the list of filled slots is used as the argument list for the call. [...] If there are more positional arguments than there are formal parameter slots, a TypeError exception is raised [...]. If any keyword argument does not correspond to a formal parameter name, a TypeError exception is raised [...].
The only difference w.r.t. this specification is that whenever a TypeError exception should be raised, this strategy returns the bottom state without throwing errors.
Keyword parameters are identified by actuals (i.e.Expression
s) that are instance ofNamedParameterExpression
.- See Also:
- Python Language Reference: calls
-
-
Field Summary
Fields Modifier and Type Field Description static PythonLikeAssigningStrategy
INSTANCE
The singleton instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends AbstractState<A>>
org.apache.commons.lang3.tuple.Pair<AnalysisState<A>,ExpressionSet[]>prepare(Call call, AnalysisState<A> callState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions, Parameter[] formals, ExpressionSet[] parameters)
Prepares the entryState for the targets of the givenCall
, assuming that the state when the call is executed (after the evaluation of the parameters) iscallState
, and each parameter to the call is represented by an element ofparameters
.
-
-
-
Field Detail
-
INSTANCE
public static final PythonLikeAssigningStrategy INSTANCE
The singleton instance of this class.
-
-
Method Detail
-
prepare
public <A extends AbstractState<A>> org.apache.commons.lang3.tuple.Pair<AnalysisState<A>,ExpressionSet[]> prepare(Call call, AnalysisState<A> callState, InterproceduralAnalysis<A> interprocedural, StatementStore<A> expressions, Parameter[] formals, ExpressionSet[] parameters) throws SemanticException
Description copied from interface:ParameterAssigningStrategy
Prepares the entryState for the targets of the givenCall
, assuming that the state when the call is executed (after the evaluation of the parameters) iscallState
, and each parameter to the call is represented by an element ofparameters
. Here, no restrictions on the order of the parameters is made: they can be passed as-is, preserving their evaluation order (Java-like), or they may be passed by-name (Python-like).- Specified by:
prepare
in interfaceParameterAssigningStrategy
- Type Parameters:
A
- the type ofAbstractState
- Parameters:
call
- the call to be preparedcallState
- the analysis state where the call is to be executedinterprocedural
- the interprocedural analysis of the program to analyzeexpressions
- the cache where analysis states of intermediate expressions must be storedformals
- the expressions representing the formal parameters of the callparameters
- the expressions representing the actual parameters of the call- Returns:
- the prepared state, ready to be used as entry-state for the targets, and the expressions to use as parameters of the call
- Throws:
SemanticException
- if something goes wrong while preparing the entry-state
-
-