Class PythonLikeMatchingStrategy

  • All Implemented Interfaces:
    ParameterMatchingStrategy

    public class PythonLikeMatchingStrategy
    extends java.lang.Object
    implements ParameterMatchingStrategy
    A Python-like matching strategy. Specifically, actual parameters are rearranged following the specification:
    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, the matching interrupts and false is returned.

    Keyword parameters are identified by actuals (i.e. Expressions) that are instance of NamedParameterExpression.

    After the reordering is completed, the type-based matching of each parameter happens by delegation to a specified FixedOrderMatchingStrategy.
    See Also:
    Python Language Reference: calls
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean matches​(Call call, Parameter[] formals, Expression[] actuals, java.util.Set<Type>[] types)
      Yields true if and only if the parameter list of a cfg is matched by the given actual parameters, according to this strategy.
      static <T,​F>
      F
      pythonLogic​(Parameter[] formals, Expression[] actuals, T[] given, java.util.Set<Type>[] givenTypes, T[] defaults, java.util.Set<Type>[] defaultTypes, T[] slots, java.util.Set<Type>[] slotTypes, F failure)
      Python logic for preparing an argument list for a method call.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PythonLikeMatchingStrategy

        public PythonLikeMatchingStrategy​(FixedOrderMatchingStrategy delegate)
        Builds the strategy.
        Parameters:
        delegate - the strategy to delegate the match after the actual parameters have been shuffled
    • Method Detail

      • matches

        public boolean matches​(Call call,
                               Parameter[] formals,
                               Expression[] actuals,
                               java.util.Set<Type>[] types)
        Description copied from interface: ParameterMatchingStrategy
        Yields true if and only if the parameter list of a cfg is matched by the given actual parameters, according to this strategy.
        Specified by:
        matches in interface ParameterMatchingStrategy
        Parameters:
        call - the call where the parameters are being matched
        formals - the parameters definition of the cfg
        actuals - the expression that are used as call parameters
        types - the runtime types of the actual parameters
        Returns:
        true if and only if that condition holds
      • pythonLogic

        public static <T,​F> F pythonLogic​(Parameter[] formals,
                                                Expression[] actuals,
                                                T[] given,
                                                java.util.Set<Type>[] givenTypes,
                                                T[] defaults,
                                                java.util.Set<Type>[] defaultTypes,
                                                T[] slots,
                                                java.util.Set<Type>[] slotTypes,
                                                F failure)
        Python logic for preparing an argument list for a method call. If the preparation fails, that is, if the signatures are incompatible, failure is returned. Otherwise, null is returned. slots is filled with the positional parameters from given first (that is, ones corresponding to an actual in actuals that is not an instance of NamedParameterExpression), then named parameters from given, and lastly with default values from defaults.
        Type Parameters:
        T - the type of elements in slots
        F - the type of the element returned if the preparation fails
        Parameters:
        formals - the formal parameters
        actuals - the actual parameters
        given - the value to use for each parameter, positional or named
        givenTypes - the types of the value to use for each parameter, positional or named
        defaults - the default values for each parameter if no explicit value is provided
        defaultTypes - the types of the default values for each parameter if no explicit value is provided
        slots - the slots that represent final values to use as parameters
        slotTypes - the types of the slots that represent final values to use as parameters
        failure - what to return in case of failure
        Returns:
        failure if the preparation fails, null otherwise
        See Also:
        Python Language Reference: calls