
V]c           @@  s   d  d l  m Z d  d l Z d d l m Z m Z m Z m Z m Z m	 Z	 d d l m
 Z
 m Z m Z d d l m Z m Z m Z m Z d d l m Z d	 e f d
     YZ d S(   i    (   t   absolute_importNi   (   t	   ExprNodest
   PyrexTypest
   MemoryViewt   ParseTreeTransformst   StringEncodingt   Errors(   t	   CloneNodet	   ProxyNodet	   TupleNode(   t   FuncDefNodet   CFuncDefNodet   StatListNodet   DefNodei   (   t
   OrderedSett   FusedCFuncDefNodec           B@  s8  e  Z d  Z d  Z d  Z d  Z d  Z d  Z e	 j
 d d d g Z
 d   Z d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d Z d Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& RS(!   s  
    This node replaces a function with fused arguments. It deep-copies the
    function for every permutation of fused types, and allocates a new local
    scope for it. It keeps track of the original function in self.node, and
    the entry of the original function in the symbol table is given the
    'fused_cfunction' attribute which points back to us.
    Then when a function lookup occurs (to e.g. call it), the call can be
    dispatched to the right function.

    node    FuncDefNode    the original function
    nodes   [FuncDefNode]  list of copies of node with different specific types
    py_func DefNode        the fused python function subscriptable from
                           Python space
    __signatures__         A DictNode mapping signature specialization strings
                           to PyCFunction nodes
    resulting_fused_function  PyCFunction for the fused DefNode that delegates
                              to specializations
    fused_func_assignment   Assignment of the fused function to the function name
    defaults_tuple          TupleNode of defaults (letting PyCFunctionNode build
                            defaults would result in many different tuples)
    specialized_pycfuncs    List of synthesized pycfunction nodes for the
                            specializations
    code_object             CodeObjectNode shared by all specializations and the
                            fused function

    fused_compound_types    All fused (compound) types (e.g. floating[:])
    t   __signatures__t   resulting_fused_functiont   fused_func_assignmentc         C@  s  t  t |   j | j  g  |  _ | |  _ t |  j t  } | rS |  j |  n |  j	 |  x |  j D]| } | j
 j j s t  | j j j s t  | j j r | j j s t  n  | rj | j j rj | j j s t  qj qj W|  | j
 _ |  j |  _ d  S(   N(   t   superR   t   __init__t   post   nodest   nodet
   isinstanceR   t   copy_deft	   copy_cdeft   entryt   typet   is_fusedt   AssertionErrort   local_scopet   return_typet   cfunc_declaratort   optional_arg_countt   op_arg_structt   fused_cfunctiont   stats(   t   selfR   t   envt   is_deft   n(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR   2   s     		c   	      C@  s  t  j g  |  j j D] } | j j r | j ^ q  } |  j |  } t  j |  } | |  _ |  j j	 | j
 k r | j
 j |  j j	  n  x | D] \ } } t j |  j  } |  j j	 j | j	 _ |  j | j |  |  j j j |  | _ | j |  |  j | | |  |  j | | |  j j	 | |  t  j | j	 |  t | j	 _ | j	 | j | j	 j <|  j |  s Pq q W|  j |  _ |  j |  j | d t |  _ d S(   sh   
        Create a copy of the original def or lambda function for specialized
        versions.
        R(   N(   R   t   uniqueR   t   argsR   R   t   _get_fused_base_typest    get_all_specialized_permutationst   fused_compound_typesR   t   pyfunc_entriest   removet   copyt   deepcopyt	   signaturet   _specialize_function_argsR    t
   specializet   analyse_declarationst   create_new_local_scopet   specialize_copied_deft   specialize_entryt   Truet   usedt   entriest   namet   replace_fused_typecheckst   orig_py_funct   make_fused_cpdeft   py_func(	   R&   R'   t   argR.   t   fused_typest   permutationst   cnamet   fused_to_specifict   copied_node(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR   O   s0    1	
c         C@  s  |  j  j j   } |  j  j |  _ } d |  j  _ | rM | j j | j  n  |  j  j j	   } | |  _
 g  } x| D]\ } } t j |  j   } | j j |  }	 | j }
 |	 j |
 |  x t | j  D]t \ } } |
 j | j k r |	 j | j  r | j | | _ | j j s,|
 j | j _ n  | j }
 |
 j }	 Pq q W| j |
  |	 | _ |	 |
 |
 _ |	 _ |
 j p|  j  j j p| j p|
 j |
 _ |  j  j j r|  j  j j |	 | d | n  |	 j | _ |  j | | |  |  j | j j |  | j  |  | j rS| j j | j j  |  j! | j | |  j  j j" | |  n  |  j# |  su Pqu qu Wy | j j$ |  j  j  } Wn! t% k
 r| j j& |  n X| | j | | d +| r|  j' | | d t( |  _ n	 | |  _ d S(   sf   
        Create a copy of the original c(p)def function for all specialized
        versions.
        t   fused_cnamei   R(   N()   R   R   R-   RA   R?   t   NoneR/   R0   R   t   get_fused_typesR.   R1   R2   R5   R9   t	   enumeratet   cfunc_entriesRE   t   same_as_resolved_typet
   func_cnamet   appendR;   t   defined_in_pxdt   is_c_class_scopet
   is_cmethodR!   R"   t   declare_optional_arg_structR    R7   R4   R+   t   declare_cpdef_wrapperR8   t   as_variableR>   t   indext
   ValueErrort   extendR@   t   False(   R&   R'   RD   R?   RC   t   new_cfunc_entriesRE   RF   RG   R   R   t   it
   orig_entryt   cindex(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR   x   sh    		$						c         C@  s:   g  } t    } x$ | D] } | j d | d |  q W| S(   sq   
        Get a list of unique basic fused types, from a list of
        (possibly) compound fused types.
        t   resultt   seen(   t   setRJ   (   R&   R.   t
   base_typesR_   t
   fused_type(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR,      s
    	c         C@  s[   xT | D]L } | j  j r | j  j |  | _  | j  j rS | j  j | j  qS q q Wd  S(   N(   R   R   R5   t   is_memoryviewslicet   validate_memslice_dtypeR   (   R&   R+   RF   RB   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR4      s
    c         C@  s6   | j  |  | | j _ t | _ |  j j |  d S(   s  
        Create a new local scope for the copied node and append it to
        self.nodes. A new local scope is needed because the arguments with the
        fused types are already in the local scope, and we need the specialized
        entries created after analyse_declarations on each specialized version
        of the (CFunc)DefNode.
        f2s is a dict mapping each fused type to its specialized version
        N(   t   create_local_scopeR   RF   RY   t   has_fused_argumentsR   RO   (   R&   R   R'   t   f2s(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR7      s    		c   	      C@  s   |  j  |  } g  | D] } t j | |  ^ q } d j |  | _ t j | | j j  | j _ | j | j _ | j	 | j _	 d S(   sw   Specialize the copy of a DefNode given the copied node,
        the specialization cname and the original DefNode entryt   |N(
   R,   R   t   specialization_signature_stringt   joint   specialized_signature_stringt   get_fused_cnameR   t   pymethdef_cnamet   doct	   doc_cname(	   R&   R   RE   t   py_entryRg   R.   RC   Rb   t   type_strings(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR8      s    "c         C@  s<   t  j } t j | j  } | |  t  j | k r8 t St S(   s   
        Branch-prune fused type checks like

            if fused_t is int:
                ...

        Returns whether an error was issued and whether we should stop in
        in order to prevent a flood of errors.
        (   R   t
   num_errorsR   t   ReplaceFusedTypeChecksR   RY   R:   (   R&   RG   Rr   t	   transform(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR>     s    
	
c         C@  sD   x= | D]5 } | j  j d | j   d | j  | j d  q Wd S(   sl   
        Generate Cython code for instance checks, matching an object to
        specialized types.
        t   py_type_namet   specialized_type_nameu   
                    if isinstance(arg, {{py_type_name}}):
                        dest_sig[{{dest_sig_idx}}] = '{{specialized_type_name}}'; break
                N(   t   contextt   updateRu   t   specialization_stringt	   put_chunk(   R&   t   normal_typest   pyx_codeR'   t   specialized_type(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _fused_instance_checks  s    
c         C@  s'   | j  r d | St |  j d d  S(   Ns	   ___pyx_%st    t   _(   t
   is_typedeft   strt   replace(   R&   t   dtype(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _dtype_name&  s    	c         C@  s    | j  r |  j |  St |  S(   N(   R   R   R   (   R&   R   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _dtype_type+  s    	c         C@  s"   | j  r d Sd |  j |  Sd  S(   Ns   sizeof(void *)s
   sizeof(%s)(   t   is_pyobjectR   (   R&   R   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _sizeof_dtype0  s    	c         C@  s   | j  d  r6 | j d  | j d  | j   n  | j  d  rl | j d  | j d  | j   n  | j  d  r | j d  | j d  | j   n  | j  d  r | j d  | j d	  | j   n  d
 S(   s?   Setup some common cases to match dtypes against specializationss   if kind in b'iu':t   passt	   dtype_ints   elif kind == b'f':t   dtype_floats   elif kind == b'c':t   dtype_complexs   elif kind == b'O':t   dtype_objectN(   t   indentert   putlnt   named_insertion_pointt   dedent(   R&   R|   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt%   _buffer_check_numpy_dtype_setup_cases6  s     s8   dest_sig[{{dest_sig_idx}}] = '{{specialized_type_name}}'s!   dest_sig[{{dest_sig_idx}}] = Nonec      
   C@  sX  |  j  |  xD| | D]8} | } | j r9 | j } n  | j } | j j d |  j |  d d d |  j |  d | d | j  | j	 | j
 f | j | j f | j | j f g } x | D] \ } }	 | r d | j f }
 | j	 r |
 d 7}
 n  | j r|
 d	 7}
 n  |	 j d
 |
  rL|	 j |  j  |	 j d  |	 j   qLq q Wq Wd S(   sO   
        Match a numpy dtype object to the individual specializations.
        t   itemsize_matchs    == itemsizet   signed_matchs!   not (%s_is_signed ^ dtype_signed)R   Rv   s3   {{itemsize_match}} and (<Py_ssize_t>arg.ndim) == %ds    and {{signed_match}}s    and arg_is_pythran_compatibles   if %s:t   breakN(   R   t   is_pythran_exprt
   org_bufferR   Rw   Rx   R   R   Ry   t   is_intR   t   is_floatR   t
   is_complexR   t   ndimR   R   t   matchR   (   R&   R|   t   specialized_buffer_typest   pythran_typesR}   t
   final_typeR   t   dtypest   dtype_categoryt
   codewritert   cond(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _buffer_check_numpy_dtypeN  s4    		
		c         C@  s   | j  } | j r% d
 g | j } n	 | j } t j | |  } | j |  | j j d | j	 d |  | j
 d  | j j d | j d |  j |   | j d |  j  d	 S(   s   
        For each specialized type, try to coerce the object to a memoryview
        slice of that type. This means obtaining a buffer and parsing the
        format string.
        TODO: separate buffer acquisition from format parsing
        t   directt   stridedt   coerce_from_py_funcR   s;   {{memviewslice_cname}} {{coerce_from_py_func}}(object, int)Rv   t   sizeof_dtypeu  
                # try {{dtype}}
                if itemsize == -1 or itemsize == {{sizeof_dtype}}:
                    memslice = {{coerce_from_py_func}}(arg, 0)
                    if memslice.memview:
                        __PYX_XDEC_MEMVIEW(&memslice, 1)
                        # print 'found a match for the buffer through format parsing'
                        %s
                        break
                    else:
                        __pyx_PyErr_Clear()
            N(   R   R   (   R   t	   is_bufferR   t   axesR   t   MemoryViewSliceTypet   create_from_py_utility_codeRw   Rx   t   from_py_functionR   Ry   R   Rz   R   (   R&   R|   t	   decl_codeR}   R'   R   R   t   memslice_type(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt!   _buffer_parse_format_string_checku  s     					c         C@  s   | j  d | r d n d d | r) d n d d  | j d  | rX | j  d  n  | j d	  |  j | | |  | j d  x$ | D] } |  j | | | |  q Wd
 S(   s^  
        Generate Cython code to match objects to buffer specializations.
        First try to get a numpy dtype object and match it against the individual
        specializations. If that fails, try naively to coerce the object
        to each specialization, which obtains the buffer each time and tries
        to match the format string.
        u   
                u!   arg_is_pythran_compatible = Falseu    u   
                if ndarray is not None:
                    if isinstance(arg, ndarray):
                        dtype = arg.dtype
                        u    arg_is_pythran_compatible = TrueuC  
                    elif __pyx_memoryview_check(arg):
                        arg_base = arg.base
                        if isinstance(arg_base, ndarray):
                            dtype = arg_base.dtype
                        else:
                            dtype = None
                    else:
                        dtype = None

                    itemsize = -1
                    if dtype is not None:
                        itemsize = dtype.itemsize
                        kind = ord(dtype.kind)
                        dtype_signed = kind == 'i'
            i   uS  
                        # Pythran only supports the endianness of the current compiler
                        byteorder = dtype.byteorder
                        if byteorder == "<" and not __Pyx_Is_Little_Endian():
                            arg_is_pythran_compatible = False
                        elif byteorder == ">" and __Pyx_Is_Little_Endian():
                            arg_is_pythran_compatible = False
                        if arg_is_pythran_compatible:
                            cur_stride = itemsize
                            shape = arg.shape
                            strides = arg.strides
                            for i in range(arg.ndim-1, -1, -1):
                                if (<Py_ssize_t>strides[i]) != cur_stride:
                                    arg_is_pythran_compatible = False
                                    break
                                cur_stride *= <Py_ssize_t> shape[i]
                            else:
                                arg_is_pythran_compatible = not (arg.flags.f_contiguous and (<Py_ssize_t>arg.ndim) > 1)
                t   numpy_dtype_checksN(   Rz   t   indentR   R   R   R   (   R&   t   buffer_typesR   R|   R   R'   R}   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _buffer_checks  s    	'
c         C@  s  | j  d  | j j  d  | r6 | j j  d  n  | j j  d  t   } x | D] } | j } | j r | j d | j   |  j |  | j	   f  n  | j j
 rV t |  | k r| j t |   | j j d |  j |  d |  j |   | j j  d  qqV qV Wd	 S(
   sr   
        If we have any buffer specializations, write out some variable
        declarations and imports.
        u   
                ctypedef struct {{memviewslice_cname}}:
                    void *memview

                void __PYX_XDEC_MEMVIEW({{memviewslice_cname}} *, int have_gil)
                bint __pyx_memoryview_check(object)
            u   
                cdef {{memviewslice_cname}} memslice
                cdef Py_ssize_t itemsize
                cdef bint dtype_signed
                cdef char kind

                itemsize = -1
            ul   
                cdef bint arg_is_pythran_compatible
                cdef Py_ssize_t cur_stride
            uq   
                cdef type ndarray
                ndarray = __Pyx_ImportNumPyArrayTypeIfAvailable()
            s   ctypedef %s %s "%s"t
   dtype_namet
   dtype_typeu   
                            cdef bint {{dtype_name}}_is_signed
                            {{dtype_name}}_is_signed = not (<{{dtype_type}}> -1 > 0)
                        N(   Rz   t   local_variable_declarationst   importsR`   R   R   R   t   resolveR   t   empty_declaration_codeR   R   t   addRw   Rx   R   (   R&   R|   R   t   all_buffer_typesR   t   seen_int_dtypest   buffer_typeR   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _buffer_declarations  s.    		
					c   
      C@  s   t  j | j  } | j   t   } g  g  g  } } } t } x | D] } | j   }	 |	 r |	 | k rp qF n  | j |	  |	 d k r t } q | j	 |  qF | j
 r | j	 |  qF | j s | j rF | j	 |  qF qF W| | | | f S(   sV   
        Specialize fused types and split into normal types and buffer types.
        t   object(   R   t   get_specialized_typesR   t   sortR`   RY   Ru   R   R:   RO   R   R   Rc   (
   R&   RB   t   specialized_typest   seen_py_type_namesR{   R   R   t   has_object_fallbackR}   Ru   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _split_fused_types  s&    
			c         C@  s   | j  d  d  S(   Nu  
                # PROCESSING ARGUMENT {{arg_tuple_idx}}
                if {{arg_tuple_idx}} < len(<tuple>args):
                    arg = (<tuple>args)[{{arg_tuple_idx}}]
                elif kwargs is not None and '{{arg.name}}' in <dict>kwargs:
                    arg = (<dict>kwargs)['{{arg.name}}']
                else:
                {{if arg.default}}
                    arg = (<tuple>defaults)[{{default_idx}}]
                {{else}}
                    {{if arg_tuple_idx < min_positional_args}}
                        raise TypeError("Expected at least %d argument%s, got %d" % (
                            {{min_positional_args}}, {{'"s"' if min_positional_args != 1 else '""'}}, len(<tuple>args)))
                    {{else}}
                        raise TypeError("Missing keyword-only argument: '%s'" % "{{arg.default}}")
                    {{endif}}
                {{endif}}
            (   Rz   (   R&   R|   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   _unpack_argument0  s    c      
   C@  s  d d l  m } m } m } |  j g  |  j j D] } | j j r/ | j ^ q/  } i t	 j
 d 6|  j j d 6t |  d 6| r |  j j |  j j n t d   |  j j D  d 6| j j d 6}	 | j d	 |	  }
 | j d	 |	  } | j d
  | j   |
 j d  |
 j   |
 j d  |
 j d  |
 j d  d } d } t   } t   } xt |  j j  D]\ } } | j j r| j j   } t |  d k rt d   n  | d } n  | j j r'| | k r'| j |  |	 j d | d | d | d |  |  j |  \ } } } } |  j |
  |
 j d  r| r\|  j | |
 |  n  | sh| r| j  | j j! d d   |  j" | | |
 | |  n  | r|
 j# j d d  |
 j$ |  j%  n |
 j$ |  j&  |
 j$ d  |
 j'   n  | d 7} | j |  | j d   | D  n  | j( rm| d 7} qmqmW| r|  j) |
 | | |  | j  | j j! d d   | j  | j j! d d   n  |
 j d  |
 j*   } d d  l+ m, } | j | d! d" d# |   g } | j- |  j j.  | j/  } | j0 | j*   | j1    | | _2 | j3 |  | j4 d$ } | j2 |  _5 t6 |  j t7  rm|  j8 | _9 n" g  |  j8 D] } | j: ^ qw| _9 | S(%   s!  
        This creates the function that is indexable from Python and does
        runtime dispatch based on the argument types. The function gets the
        arg tuple and kwargs dict (or None) and the defaults tuple
        as arguments from the Binding Fused Function's tp_call.
        i   (   t   TreeFragmentt   Codet   UtilityCodet   memviewslice_cnamet	   func_argst   n_fusedc         s@  s$   |  ] } | j  d k r d  Vq d S(   i   N(   t   defaultRI   (   t   .0RB   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pys	   <genexpr>X  s    t   min_positional_argsR=   Rw   u   
                cdef extern from *:
                    void __pyx_PyErr_Clear "PyErr_Clear" ()
                    type __Pyx_ImportNumPyArrayTypeIfAvailable()
                    int __Pyx_Is_Little_Endian()
            u  
                def __pyx_fused_cpdef(signatures, args, kwargs, defaults):
                    # FIXME: use a typed signature - currently fails badly because
                    #        default arguments inherit the types we specify here!

                    dest_sig = [None] * {{n_fused}}

                    if kwargs is not None and not kwargs:
                        kwargs = None

                    cdef Py_ssize_t i

                    # instance check body
            R   t	   func_defsR   i    sO   Determination of more than one fused base type per argument is not implemented.t   arg_tuple_idxRB   t   dest_sig_idxt   default_idxs   while 1:t   IsLittleEndians   ModuleSetupCode.cRv   R   R   c         s@  s   |  ] } | j  Vq d  S(   N(   R   (   R   t   ty(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pys	   <genexpr>  s    t   Imports   ImportExport.ct   ImportNumPyArrayu  
                candidates = []
                for sig in <dict>signatures:
                    match_found = False
                    src_sig = sig.strip('()').split('|')
                    for i in range(len(dest_sig)):
                        dst_type = dest_sig[i]
                        if dst_type is not None:
                            if src_sig[i] == dst_type:
                                match_found = True
                            else:
                                match_found = False
                                break

                    if match_found:
                        candidates.append(sig)

                if not candidates:
                    raise TypeError("No matching signature found")
                elif len(candidates) > 1:
                    raise TypeError("Function call with ambiguous argument types")
                else:
                    return (<dict>signatures)[candidates[0]]
            (   t   ConstantFoldingt   levelt   modulet   pipelinei(;   t    R   R   R   R,   R   R+   R   R   R   R   t   lent   num_required_argst   num_required_kw_argst   sumR   R=   t   PyxCodeWriterRz   R   R   R   R`   RK   RJ   t   NotImplementedErrorR   Rx   R   R   R   R~   t   use_utility_codet   load_cachedR   Rw   R   R   t   no_matchR   R   R   t   getvaluet   OptimizeR   t   SetPosTransformR   t   roott   declare_declarations_in_scopet   global_scopet   scopeR6   R%   t   fragment_scopeR   R   R   t   specialized_cpdefsRA   (   R&   R?   R'   R(   R   R   R   RB   RC   Rw   R|   R   t   fused_indexR   R   t   seen_fused_typesR[   t   arg_fused_typesRb   R{   R   R   R   t   fragment_codeR   t   fragmentt   astRA   R)   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR@   E  s    1


			
		"c      
   C@  sA  d } |  j  j } x- | D]% } t | | t |  j j |   q W|  j j |  j  _ |  j j |  j  _ | j j d d   t
 |  j t  r | | j | j <n | | j | j _ | j j |  |  |  j  j _ xM |  j D]B } t
 |  j t  r|  j  | _ q |  j  | j  _ | | j _ q W|  j   |  j j |  j  d  S(   NR=   R   RE   RN   t   pyfunc_cnameRm   Rn   Ro   t	   is_memberR   t   __pyx_fused_cpdef(
   R=   R   RE   RN   R   Rm   Rn   Ro   R   R   (   RA   R   t   setattrt   getattrR?   R=   Rn   R<   t   popRI   R   R   R   RU   R/   RO   R$   R   t   fused_py_funct   synthesize_defnodesR%   R   (   R&   R'   t   copy_attributesR   t   attrR   (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   update_fused_defnode_entry  s,      	
c         C@  s  xU |  j  D]J } xA | j   D]3 } x* | j D] } | j r- | j |  q- q- Wq Wq
 W|  j r |  j j |  |  _ |  j j |  |  _ |  j j |  |  _ |  j	 j |  |  _	 n  g  |  _
 } xX |  j j D]J } | j r| j j |  | _ | j t | j   q | j d  q Wx t |  j  D] \ } } | j |  } |  j | <t | t  r0xP t | j |  D]9 \ } }	 |	 d k	 rxt |	  j | j |  | _ qxqxWq0q0W|  j rg  | D] }	 |	 rt |	  ^ q}
 t |  j d |
 |  _ |  j j | d t j |  |  _ t |  j  |  _ t |  j d j   |  _  |  j j! } t |  j  | _ t |  j   | _  x^ t |  j  D]J \ } } t |  j   | _  | j |  } |  j | <t |  j  | _ qWn  |  S(   s   
        Analyse the expressions. Take care to only evaluate default arguments
        once and clone the result for all specializations
        R+   t   skip_childreni    N("   R.   RJ   t   typesR   t   create_declaration_utility_codeRA   R   t   analyse_expressionsR   R   t   defaultsR   R+   R   RO   R   RI   RK   R%   R   R
   t   zipR   t	   coerce_toR   R	   R   t   defaults_tuplet   analyse_typesR:   t   coerce_to_pyobjectt   specialized_pycfuncst   code_objectRB   (   R&   R'   t   fused_compound_typeRb   t   specialization_typeR  RB   R[   t   statR   R+   t
   fused_funct   pycfunc(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR    sH    			,	%$c         C@  s  t  |  j d t  r8 g  |  j D] } | j ^ q  } n	 |  j } g  | D] } t j | j  ^ qH } g  t | |  D]$ \ } } t j	 | j
 d | ^ qv } g  | D] } t j j | d t ^ q } t j j |  j
 t | |   |  _ | |  _ x | D] } t | _ q Wd S(   sT   
        Create the __signatures__ dict of PyCFunctionNode specializations.
        i    t   valuet   bindingN(   R   R   R   RA   R   t   EncodedStringRk   R  R   t
   StringNodeR   t   PyCFunctionNodet   from_defnodeR:   t   DictNodet
   from_pairsR   R  t   is_specialization(   R&   R   R   t
   signaturest   sigt   keyst   valuest   pycfuncnode(    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR   5  s    "	"7($	c         C@  s   |  j  r+ t |  j  _ |  j j | |  n  xO |  j D]D } t | t  r5 | j j	 r5 | j
 | j  | j | |  q5 q5 Wd  S(   N(   RA   R:   t   pymethdef_requiredR   t   generate_function_definitionsR%   R   R
   R   R;   t   mark_posR   (   R&   R'   t   codeR  (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR!  K  s    	c         C@  s~  x- |  j  D]" } | d  k	 r
 | j |  q
 q
 W|  j r\ |  j j |  |  j j |  n  xP |  j D]E } | j | j  t	 | t
 j  r | j |  qf | j |  qf W|  j rJ|  j j |  | j d |  j j   |  j j   f  | j |  j j    |  j j |  |  j j |  |  j j |  |  j j |  n  x- |  j  D]" } | d  k	 rT| j |  qTqTWd  S(   Ns8   ((__pyx_FusedFunctionObject *) %s)->__signatures__ = %s;(   R  RI   t   generate_evaluation_codeRA   R  R  R%   R"  R   R   R   t   ExprNodet   generate_execution_codeR   R   R   R^   t   put_giverefR   t   generate_disposal_code(   R&   R#  R   R  (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR&  U  s2    		c         C@  s%   x |  j  D] } | j |  q
 Wd  S(   N(   R%   t   annotate(   R&   R#  R  (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR)  {  s    N('   t   __name__t
   __module__t   __doc__RI   R   R   R   R  t
   decoratorsR   t   child_attrsR   R   R   R,   R4   R7   R8   R>   R~   R   R   R   R   R   R   R   R   R   R   R   R   R@   R   R  R   R!  R&  R)  (    (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyR      sH   		)	V											'	(	=	9				#	2		
	&(   t
   __future__R    R1   R   R   R   R   R   R   R   R   R   R	   t   NodesR
   R   R   R   t   UtilsR   R   (    (    (    s8   lib/python2.7/site-packages/Cython/Compiler/FusedNode.pyt   <module>   s   ."