Class 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. Expressions) that are instance of NamedParameterExpression.
    See Also:
    Python Language Reference: calls
    • 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 given Call, assuming that the state when the call is executed (after the evaluation of the parameters) is callState, and each parameter to the call is represented by an element of parameters. 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 interface ParameterAssigningStrategy
        Type Parameters:
        A - the type of AbstractState
        Parameters:
        call - the call to be prepared
        callState - the analysis state where the call is to be executed
        interprocedural - the interprocedural analysis of the program to analyze
        expressions - the cache where analysis states of intermediate expressions must be stored
        formals - the expressions representing the formal parameters of the call
        parameters - 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