Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/Cython/Compiler/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/Cython/Compiler/__pycache__/Code.cpython-35.pyc



Z��Z�n�*@sddlmZddlZejdedededededed	ed
ededed
ededededede�ddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZyddlZWnek
r>ddlZYnXddlmZddlmZddlmZddlmZddlmZddlmZddlmZdd lmZydd!l m!Z!Wn"ek
r�dd"l"m#Z!YnXej$dd#fkZ%d$d%d&fd'd(d&fdd(d&fd)d(d*fd+d(d,fiZ&d-d.iZ'd/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHgZ(e)dIdJdKdLdMdNdOdPdQdRdSdTdUg
�Z*dVdWij+Z,ej-dX�j.Z/GdYdZ�dZe�Z0d[d\�Z1Gd]d^�d^e�Z2Gd_d`�d`e2�Z3dddadb�Z4Gdcdd�dde3�Z5Gdedf�dfe2�Z6Gdgdh�dhe�Z7Gdidj�dje�Z8Gdkdl�dle�Z9ejdmednedoedpe�ej-dqj:dE�ej;�j.Z<ej-drj=ds��j.Z>ej-dt�j?Z@ej-du�jAZBGdvdw�dwe�ZCGdxdy�dye�ZDGdzd{�d{e�ZEd|d}�ZFGd~d�de�ZGGd�d��d�e�ZHGd�d��d�e�ZIGd�d��d�e�ZJGd�d��d�e�ZKdS)��)�absolute_importN�os�re�operator�textwrap�Template�Naming�Options�StringEncoding�Utils�SourceDescriptor�StringIOTree�
DebugFlags�
basestring�defaultdict�closing�partial)r)r)r)r�)r)r	)r)r
)�Version�)r)r)r
)r)�str��byteszPY_MAJOR_VERSION < 3r�unicodezPY_MAJOR_VERSION >= 3�xrange�rangeZ	raw_input�inputZPyTypeObjectZPyHeapTypeObjectZ
breakpoint�
__loader__�__spec__�BlockingIOError�BrokenPipeError�ChildProcessError�ConnectionAbortedError�ConnectionError�ConnectionRefusedError�ConnectionResetError�FileExistsError�FileNotFoundError�InterruptedError�IsADirectoryErrorZModuleNotFoundError�NotADirectoryError�PermissionError�ProcessLookupError�RecursionError�ResourceWarning�TimeoutError�__build_class__�ascii�
memoryviewZWindowsError�_Z	__cinit__Z__dealloc__Z__richcmp__�__next__�	__await__�	__aiter__�	__anext__Z__getreadbuffer__Z__getwritebuffer__Z__getsegcount__Z__getcharbuffer__Z
__getbuffer__Z__releasebuffer__�inlineZ
CYTHON_INLINEz *(\w+) = (\1);\s*$c@sveZdZdZdZdZdZdZdddddd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�IncludeCodez]
    An include file and/or verbatim C code to be included in the
    generated sources.
    rrrNTFcCs�|j|_t|�jd7_i|_|r�|ddkro|ddkrodj|�|jd<d}ndj|�|jd<|r�||j|j<|r�|j|_n!|r�|j|_n|j|_dS)	Nrr�<�>z#include {0}Fz#include "{0}"���)	�counter�order�type�pieces�format�INITIAL�location�LATE�EARLY)�self�includeZverbatimZlate�initial�rI�G/opt/alt/python35/lib64/python3.5/site-packages/Cython/Compiler/Code.py�__init__�s	 	zIncludeCode.__init__cCsR||krD||}t|j|j�|_|jj|j�n
|||<dS)z�
        Insert `self` in dict `d` with key `key`. If that key already
        exists, update the attributes of the existing value with `self`.
        N)�minrCr@�update)rF�d�key�otherrIrIrJ�dict_update�s

zIncludeCode.dict_updatecCs|jS)N)r>)rFrIrIrJ�sortkey�szIncludeCode.sortkeycCs|jjd�S)z�
        Return the main piece of C code, corresponding to the include
        file. If there was no include file, return None.
        r)r@�get)rFrIrIrJ�	mainpiece�szIncludeCode.mainpiececCs2x+t|j�D]}|j|j|�qWdS)N)�sortedr@�putln)rF�code�krIrIrJ�write�szIncludeCode.write)
�__name__�
__module__�__qualname__�__doc__rBrErDr=rKrQrRrTrYrIrIrIrJr9ssr9cCs=tjjtjjtjjt���}tjj|d�S)NZUtility)r�path�dirname�abspath�__file__�join)Z
Cython_dirrIrIrJ�get_utility_dir�s*rcc@s�eZdZdZdZiZeddd��Zedd��Zeddd	��Z	edid
d��Z
eddd
��Zej
d�jdd�Zdd�Zdd�ZdS)�UtilityCodeBasea�
    Support for loading utility code from a file.

    Code sections in the file can be specified as follows:

        ##### MyUtility.proto #####

        [proto declarations]

        ##### MyUtility.init #####

        [code run at module initialization]

        ##### MyUtility #####
        #@requires: MyOtherUtility
        #@substitute: naming

        [definitions]

    for prototypes and implementation respectively.  For non-python or
    -cython files backslashes should be used instead.  5 to 30 comment
    characters may be used on either side.

    If the @cname decorator is not used and this is a CythonUtilityCode,
    one should pass in the 'name' keyword argument to be used for name
    mangling of such entries.
    FNcCs�|dkrdSdj|�}|r�d|kr�|dtdg�kr�|d=yt|�jtt��}WnDttfk
r�}ztd|||f��WYdd}~XnXd||}|dkr�||d<nB|dkr�||d<n)|d	}t	r|j
d
�}|||<|r~|d	}xK|j�D]=\}	}
t	r^|	j
d
�}	|j|	t��j
|
�q=WdS)N�
�
substituteZnamingz@Error parsing templated utility code of type '%s' at line %d: %s�protor�implrr�ASCII)rb�setrrf�varsr�KeyError�
ValueError�RuntimeError�KEYWORDS_MUST_BE_BYTES�encode�items�
setdefaultrM)�cls�utilityr?�lines�begin_lineno�tagsrW�eZall_tags�name�valuesrIrIrJ�_add_utility�s2+&




zUtilityCodeBase._add_utilitycCs�|jj|�}|r|Stjjt�|�}tjj|�\}}|dkr�d}ttj	d�j
d�}tjj
}n<d}ttj	d	�j
d�}ttj	d
�j
d�}tj	dd
|i�j}	tj	d�j}
ttj|dd���}|j�}WdQRXtdd��}g}
tt�}d}}d}x
t|�D]�\}}|	|�}|rG|jd�r|j|||
||�|d}|
dd�=|j�|jd�}|
|�}|r|j�\}}nd}||}q`||jd�j|jd��|
jd�qd|
j|||���qdW|dkr|td��|j|||
||�t|�}||j|<|S)N�.pyx�.py�.pxd�.pxi�#z^\s*#.*��/z^\s*//.*|/\*[^*]*\*/z	\s+(\\?)$z\1zd^%(C)s{5,30}\s*(?P<name>(?:\w|\.)+)\s*%(C)s{5,30}|^%(C)s+@(?P<tag>\w+)\s*:\s*(?P<value>(?:\w|[.:])+)�Cz,(.+)[.](proto(?:[.]\S+)?|impl|init|cleanup)$�encodingzUTF-8cSs
ddigS)NrIrIrIrIrJ�<lambda>!sz:UtilityCodeBase.load_utilities_from_file.<locals>.<lambda>rryrrh�tag�valuezEmpty utility code file)r|r}r~r)�_utility_cacherSrr^rbrc�splitextrr�compile�subr
Z_unicode�rstrip�matchrrZopen_source_file�	readlinesrrj�	enumerate�groupr{�clear�groups�add�appendrm�dict)rsr^�	utilities�filenamer3�ext�comment�strip_commentsr�Z
match_specialZ
match_type�fZ	all_linesrurwrtr?rv�lineno�line�mry�mtyperIrIrJ�load_utilities_from_files\




#
z(UtilityCodeBase.load_utilities_from_filecs~d|kr$|jdd�\�}�st��|d�ytj��}Wnntk
r�ddl}t}|j�t|j	����)}��fdd�|j
�D�}WdQRXYnX�fdd�|D�}|s�td	|��t|�dkrtd
|��|d��j
��}	|	|\}
}}|r|j��x�|j�D]�\}
}|
|krxq]|
dkr��r����fdd�t|�D�}q��fd
d�t|�D�}n1|s�d}n"t|�dkrt|�d}|||
<q]W|
dk	r,|
|d<|dk	rB||d<d|krX||d<d|krt�rt�|d<�|�S)a
        Load utility code from a file specified by from_file (relative to
        Cython/Utility) and name util_code_name.  If from_file is not given,
        load it from the file util_code_name.*.  There should be only one
        file matched by this pattern.
        z::r�.rNcs@g|]6}tjj�|�j��rtjj|��qSrI)rr^rb�
startswith�basename)�.0ry)�archive�utility_dirrIrJ�
<listcomp>_s	z(UtilityCodeBase.load.<locals>.<listcomp>cs%g|]}|j��r|�qSrI)r�)r�r�)�prefixrIrJr�bs	z No match found for utility code z4More than one filename match found for utility code �requirescs%g|]}�j|����qSrI)�load)r��dep)rs�	from_file�orig_kwargsrIrJr�us	cs"g|]}�j|���qSrI)�load_cached)r�r�)rsr�rIrJr�ys	rgrhry�file)�rsplitrcr�listdir�OSError�zipfilerr�r�ZipFile�namelistrm�lenr��copyrqrU�list)rs�util_code_namer��kwargsZlistingr��loader�fileobj�filesr�rgrhrwryrzrI)r�rsr�r�r�r�rJr�Hs^	

	
	



zUtilityCodeBase.loadcCsN|||f}y||SWntk
r/YnX|j||�}||<|S)z`
        Calls .load(), but using a per-type cache based on utility name and file name.
        )rlr�)rs�utility_code_namer�Z_UtilityCodeBase__cacherOrWrIrIrJr��s
zUtilityCodeBase.load_cachedcKsD|j|||�}|j|j}}|j|�|j|�fS)zR
        Load a utility code as a string. Returns (proto, implementation)
        )r�rgrh�format_code)rsr�r�r��utilrgrhrIrIrJ�load_as_string�szUtilityCodeBase.load_as_stringz\n\n+cCs#|r|d|j��d}|S)z3
        Format a code section for output.
        rez

)�strip)rFZcode_stringZreplace_empty_linesrIrIrJr��szUtilityCodeBase.format_codecCsdt|�j|jfS)Nz<%s(%s)>)r?rZry)rFrIrIrJ�__str__�szUtilityCodeBase.__str__cKsdS)NrI)rFr�rIrIrJ�get_tree�szUtilityCodeBase.get_tree)rZr[r\r]Zis_cython_utilityr��classmethodr{r�r�r�r�rr�r�r�r�r�rIrIrIrJrd�s!@Drdc
@s�eZdZdZdddddddddd�Zdd�Zdd	�Zd
d�Zddd
�Zdd�Z	dd�Z
dd�Zdd�ZdS)�UtilityCodeaF
    Stores utility code to add during code generation.

    See GlobalState.put_utility_code.

    hashes/equals by instance

    proto           C prototypes
    impl            implementation code
    init            code to call on module initialization
    requires        utility code dependencies
    proto_block     the place in the resulting file where the prototype should
                    end up
    name            name of the utility code (or None)
    file            filename of the utility code file this utility was loaded
                    from (or None)
    N�utility_code_protoc		Cs^||_||_||_||_||_i|_g|_||_||_||_	dS)N)
rgrh�init�cleanupr��_cache�specialize_list�proto_blockryr�)	rFrgrhr�r�r�r�ryr�rIrIrJrK�s									zUtilityCode.__init__cCst|j|jf�S)N)�hashrgrh)rFrIrIrJ�__hash__�szUtilityCode.__hash__cCs�||krdSt|�t|�}}||k	rXt||�pPt||�rXdSt|dd�}t|dd�}||jf||jfkS)NTFrg)r?�
isinstance�getattrrh)rFrPZ	self_typeZ
other_typeZ
self_protoZother_protorIrIrJ�__eq__�s+zUtilityCode.__eq__cCs|dkrdS||S)zY
        Format a string in this utility code with context. If None, do nothing.
        NrI)rF�s�contextrIrIrJ�none_or_sub�szUtilityCode.none_or_subc
s|dk	r,|j��d<|j��d<tt�j���}y|j|SWn�tk
r|jdkr{d}n�fdd�|jD�}t|j	|j
��|j	|j��|j	|j��|j	|j
��||j�}|j|<|jj|�|SYnXdS)Nr?Z	type_namecsg|]}|j���qSrI)�
specialize)r��r)�datarIrJr��s	z*UtilityCode.specialize.<locals>.<listcomp>)Zempty_declaration_codeZspecialization_name�tuplerUrqr�rlr�r�r�rgrhr�r�r�r�r�)rFZ
pyrex_typer�rOr�r�rI)r�rJr��s&
	zUtilityCode.specializecs�d|kr"d|kr"d|fSi���fdd�}tjd||�}d|krjd|kspt�t��|fS)zHReplace 'PYIDENT("xyz")' by a constant Python identifier cname.
        zPYIDENT(z
PYUNICODE(Fcsn|j�}y�|}WnMtk
ri|\}}�jtj|�d|dk�j}�|<YnX|S)N�
identifierZIDENT)r�rl�get_py_string_constr
�
EncodedString�cname)�matchobjrOr�Zstr_typery)�output�replacementsrIrJ�externalise	s
.z8UtilityCode.inject_string_constants.<locals>.externalisezPY(IDENT|UNICODE)\("([^"]+)"\))rr��AssertionError�bool)rFrhr�r�rI)r�r�rJ�inject_string_constantss

z#UtilityCode.inject_string_constantscs�d|krd|fSt�}�fdd�}tjd||�}d|ksXt�x-t|�D]}�jtj|d��qeWt|�|fS)zVReplace 'UNBOUND_METHOD(type, "name")' by a constant Python identifier cname.
        zCALL_UNBOUND_METHOD(Fcs�|j�\}}}}|rDdd�|dd�jd�D�ng}t|�dksrtdt|����j||||�S)NcSsg|]}|j��qSrI)r�)r��argrIrIrJr� s	zKUtilityCode.inject_unbound_methods.<locals>.externalise.<locals>.<listcomp>r�,�z8CALL_UNBOUND_METHOD() does not support %d call arguments)r��splitr�r��cached_unbound_method_call_code)r��
type_cname�method_name�	obj_cname�args)r�rIrJr�s2(z7UtilityCode.inject_unbound_methods.<locals>.externalisezMCALL_UNBOUND_METHOD\(([a-zA-Z_]+),\s*"([^"]+)",\s*([^),]+)((?:,\s*[^),]+)*)\)zObjectHandling.c)	rjrr�r�rU�use_utility_coder�r�r�)rFrhr��utility_coder��helperrI)r�rJ�inject_unbound_methodss
	z"UtilityCode.inject_unbound_methodscCsGd|kr|Sdd�}tjd||�}d|ksCt�|S)z<Replace CSTRING('''xyz''') by a C compatible string
        zCSTRING(cSs;|jd�jdd�}djdd�|j�D��S)Nr�"r�cssL|]B}|jd�s(|jd�r2d|nd|dd�VqdS)�\z\\z"%s\n"
z"%s"
Nrr<)�endswith)r�r�rIrIrJ�	<genexpr>:szCUtilityCode.wrap_c_strings.<locals>.split_string.<locals>.<genexpr>)r��replacerb�
splitlines)r��contentrIrIrJ�split_string7s	z0UtilityCode.wrap_c_strings.<locals>.split_stringz)CSTRING\(\s*"""([^"]*(?:"[^"]+)*)"""\s*\))rr�r�)rFrhr�rIrIrJ�wrap_c_strings1szUtilityCode.wrap_c_stringscCs&|jr*x|jD]}|j|�qW|jrw||j}|jd|j�|j|j|j�d|j�|jr|j|j	|j��}|j
||�\}}|j||�\}}|d}|jd|j�|p�|s|j|d|j�n
|j|�|j
r�|d}|jd|j�t|j
t�rq|j|j|j
��n|j
||j�|j|j|j��|j�|jr"tjr"|d}|jd	|j�t|jt�r|j|j|j�d
|j�n|j||j�dS)Nz/* %s.proto */z%s_proto�utility_code_defz/* %s */z%s_impl�init_globalsz
/* %s.init */�cleanup_globalsz/* %s.cleanup */z
%s_cleanup)r�r�rgr�rVry�put_or_includer�rhr�r�r��putr�r�r�
module_pos�error_goto_if_PyErrr�r	�generate_cleanup_code)rFr�Z
dependency�writerrhZis_specialised1Zis_specialised2rIrIrJ�put_codeAsB		
	

	


zUtilityCode.put_code)
rZr[r\r]rKr�r�r�r�r�r�r�rrIrIrIrJr��s
r�cCsT|s
dS|r'd||f|d<n|r7||d<ddlm}|||�S)z+Run tempita on string s with given context.Nz%s:%sZ__namer)r�)�Tempitar�)r�r�r�ryr�rIrIrJ�sub_tempitais
rc	s[eZdZdddddd�fdd�Zeddidd��Zdd�Z�S)�TempitaUtilityCodeNc
s�|dkri}t||||�}t||||�}t||||�}tt|�j||d|d|d||�dS)Nr�ryr�)r�superrrK)rFryrgrhr�r�r�r�)�	__class__rIrJrKxszTempitaUtilityCode.__init__c
Cs�|rtt|j���nd}t|�dk	s<t�||||f}y||SWntk
rnYnX|j||d|�}||<|S)Nr�)r�rUrqr�r�rlr�)rsr�r�r�Z_TempitaUtilityCode__cacheZcontext_keyrOrWrIrIrJr��s$
 zTempitaUtilityCode.load_cachedcCs)|dkrdSt|||j|j�S)zY
        Format a string in this utility code with context. If None, do nothing.
        N)rr�ry)rFr�r�rIrIrJr��szTempitaUtilityCode.none_or_sub)rZr[r\rKr�r�r�rIrI)rrJrws$	rc@s:eZdZdZdZdZdd�Zdd�ZdS)�LazyUtilityCodez�
    Utility code that calls a callback with the root code writer when
    available. Useful when you only have 'env' but not 'code'.
    z<lazy>NcCs
||_dS)N)�callback)rFr
rIrIrJrK�szLazyUtilityCode.__init__cCs#|j|j�}|j|�dS)N)r
�
rootwriterr�)rF�globalstatertrIrIrJr�szLazyUtilityCode.put_code)rZr[r\r]r�rKrrIrIrIrJr	�s
r	c@seZdZe�ddd�Zddd�Zddd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zddd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS).�
FunctionStateNcCs�||_||_||_d|_d|_t�|_|j�|_|j	�d|_
d|_g|_d|_
d|_d|_d|_d|_g|_i|_i|_d|_d|_g|_d|_d|_dS)NrFT)�names_taken�owner�scope�error_label�
label_counterrj�labels_used�	new_label�return_label�new_error_label�continue_label�break_label�yield_labelsZin_try_finallyZexc_varsZcurrent_except�	can_trace�	gil_owned�temps_allocated�
temps_free�temps_used_type�temp_counter�
closure_temps�collect_temps_stack�should_declare_error_indicator�uses_error_indicator)rFrrrrIrIrJrK�s0					
															zFunctionState.__init__cCsG|j}|d|_dtj|f}|dk	rC|d|7}|S)Nrz%s%dr3)rrZlabel_prefix)rFry�n�labelrIrIrJr�s	
zFunctionState.new_label�yieldcCs@|jd|�}t|j�d|f}|jj|�|S)Nzresume_from_%sr)rr�rr�)rFZ	expr_typer%Z
num_and_labelrIrIrJ�new_yield_label�szFunctionState.new_yield_labelcCs|j}|jd�|_|S)N�error)rr)rFZold_err_lblrIrIrJr�s	zFunctionState.new_error_labelcCs|j|jfS)N)rr)rFrIrIrJ�get_loop_labels�szFunctionState.get_loop_labelscCs|\|_|_dS)N)rr)rF�labelsrIrIrJ�set_loop_labels�szFunctionState.set_loop_labelscCs5|j�}|j|jd�|jd�f�|S)N�continue�break)r)r+r)rF�
old_labelsrIrIrJ�new_loop_labels�s
zFunctionState.new_loop_labelscCs|j|j|j|jfS)N)rrrr)rFrIrIrJ�get_all_labels�szFunctionState.get_all_labelscCs"|\|_|_|_|_dS)N)rrrr)rFr*rIrIrJ�set_all_labelsszFunctionState.set_all_labelscCs{|j�}g}xUt|ddddg�D]8\}}|rY|j|j|��q.|j|�q.W|j|�|S)Nr,r-�returnr()r0�zipr�rr1)rFr.Z
new_labelsZ	old_labelryrIrIrJ�all_new_labels
s(
zFunctionState.all_new_labelscCs|jj|�dS)N)rr�)rF�lblrIrIrJ�	use_labelszFunctionState.use_labelcCs
||jkS)N)r)rFr5rIrIrJ�
label_usedszFunctionState.label_usedFcCs\|jr|jr|j}n|jr;|jr;|j}|jrU|jrUd}|jj||f�}|dk	r�|dr�|dj	�}|dj
|�nXx9|jd7_dtj
|jf}||jkr�Pq�W|jj||||f�||f|j|<tjr5|jjd||f�|jrX|jdj||f�|S)a�
        Allocates a temporary (which may create a new one or get a previously
        allocated and released one of the same type). Type is simply registered
        and handed back, but will usually be a PyrexType.

        If type.is_pyobject, manage_ref comes into play. If manage_ref is set to
        True, the temp will be decref-ed on return statements and in exception
        handling clauses. Otherwise the caller has to deal with any reference
        counting of the variable.

        If not type.is_pyobject, then manage_ref will be ignored, but it
        still has to be passed. It is recommended to pass False by convention
        if it is known that type will never be a Python object.

        static=True marks the temporary declaration with "static".
        This is only used when allocating backing store for a module-level
        C array literals.

        A C string referring to the variable is returned.
        FNrrz%s%dz/* %s allocated (%s) */r<)�is_constZis_referenceZconst_base_typeZis_fake_referenceZ
ref_base_type�is_pyobject�is_memoryviewslicerrS�pop�removerr�codewriter_temp_prefixrrr�rr�debug_temp_code_commentsrrVr!r�)rFr?�
manage_ref�static�freelist�resultrIrIrJ�
allocate_temps,			zFunctionState.allocate_tempcCs�|j|\}}|jj||f�}|dkrYgt�f}||j||f<||dkrytd|��|dj|�|dj|�tjr�|j	j
d|�dS)zv
        Releases a temporary so that it can be reused by other code needing
        a temp of the same type.
        NrzTemp %s freed twice!rz/* %s released */)rrrSrjrnr�r�rr>rrV)rFryr?r?rArIrIrJ�release_tempNs	zFunctionState.release_tempcCs}g}xp|jD]e\}}}}|jj||f�}|dksV||dkr|j|||on|jf�qW|S)zxReturn a list of (cname,type,manage_ref) tuples of temp names and their type
        that are currently in use.
        Nr)rrrSr�r9)rF�usedryr?r?r@rArIrIrJ�temps_in_use_s#zFunctionState.temps_in_usecCsdd�|j�D�S)z�Return a list of (cname,type) tuples of temp names and their type
        that are currently in use. This includes only temps of a
        Python object type which owns its reference.
        cSs4g|]*\}}}|r|jr||f�qSrI)r9)r�ryr?r?rIrIrJr�os	z9FunctionState.temps_holding_reference.<locals>.<listcomp>)rF)rFrIrIrJ�temps_holding_referencejs	z%FunctionState.temps_holding_referencecCsdd�|jD�S)zRReturn a list of (cname, type) tuples of refcount-managed Python objects.
        cSs.g|]$\}}}}|r||f�qSrIrI)r�r�r?r?r@rIrIrJr�vs	z3FunctionState.all_managed_temps.<locals>.<listcomp>)r)rFrIrIrJ�all_managed_tempsss	zFunctionState.all_managed_tempscCsdd�|jj�D�S)z�Return a list of (cname, type) tuples of refcount-managed Python
        objects that are not currently in use.  This is used by
        try-except and try-finally blocks to clean up temps in the
        error case.
        cSs?g|]5\\}}}|r|dD]}||f�q&qS)rrI)r�r?r?rAr�rIrIrJr��s	z8FunctionState.all_free_managed_temps.<locals>.<listcomp>)rrq)rFrIrIrJ�all_free_managed_tempszs	z$FunctionState.all_free_managed_tempscCs|jjt��dS)zJ
        Useful to find out which temps were used in a code block
        N)r!r�rj)rFrIrIrJ�start_collecting_temps�sz$FunctionState.start_collecting_tempscCs
|jj�S)N)r!r;)rFrIrIrJ�stop_collecting_temps�sz#FunctionState.stop_collecting_tempscCst|�|_dS)N)�ClosureTempAllocatorr )rFrrIrIrJ�init_closure_temps�sz FunctionState.init_closure_temps)rZr[r\rjrKrr'rr)r+r/r0r1r4r6r7rCrDrFrGrHrIrJrKrMrIrIrIrJr
�s*
'1	
r
c@s%eZdZdZddd�ZdS)�NumConstz�Global info about a Python number constant held by GlobalState.

    cname       string
    value       string
    py_type     string     int, long, float
    value_code  string     evaluation code if different from value
    NcCs.||_||_||_|p$||_dS)N)r�r��py_type�
value_code)rFr�r�rOrPrIrIrJrK�s			zNumConst.__init__)rZr[r\r]rKrIrIrIrJrN�srNc@s"eZdZdZdd�ZdS)�
PyObjectConstz>Global info about a generic constant held by GlobalState.
    cCs||_||_dS)N)r�r?)rFr�r?rIrIrJrK�s	zPyObjectConst.__init__N)rZr[r\r]rKrIrIrIrJrQ�srQ�possible_unicode_identifier�possible_bytes_identifier�replace_identifier�find_alphanumss
(?![0-9])\w+$z
(?![0-9])\w+$riz[^a-zA-Z0-9_]+z([a-zA-Z0-9]+)c@sCeZdZdZdd�Zdd�Zddddd	�ZdS)
�StringConstz?Global info about a C string constant held by GlobalState.
    cCs:||_||_tj|�|_d|_g|_dS)N)r��textr
Zescape_byte_string�
escaped_value�
py_strings�py_versions)rFr�rW�byte_stringrIrIrJrK�s
			zStringConst.__init__cCs;|sddg|_n||jkr7|jj|�dS)Nrr�)rZr�)rF�versionrIrIrJ�add_py_version�szStringConst.add_py_versionNFcCs�|j}|j}t|p|�}|dko4|}|dkrLd}n<|j�}|dkrsd}d}ndjt|��}||||f}	|dk	r�y||	SWq�tk
r�Yq�Xn	i|_|r�d}
nK|dkr't|t�rtt	|��}
q-tt
|��}
nd}
|
rCtjd	}n	tj
}|r_d
|}nd}d||rwdp�|r�d
p�d||jttj�d�f}
t|
|||||
�}||j|	<|S)N�utf8�utf-8r1�usascii�us-asciir�TFrz_%sz	%s%s%s_%sr��u�b)r^r_r1r`ra)rYrWr��lowerrbrUrlr�rrSrRr�interned_prefixesZpy_const_prefixr�r��const_prefix�
PyStringConst)rFr�r��is_str�py3str_cstringrYrW�
is_unicodeZencoding_keyrO�internr�Zencoding_prefixZpystring_cname�	py_stringrIrIrJr��sP				
			
 
zStringConst.get_py_string_const)rZr[r\r]rKr]r�rIrIrIrJrV�s
rVc@s7eZdZdZddddd�Zdd�ZdS)rgzDGlobal info about a Python string constant held by GlobalState.
    FNcCs:||_||_||_||_||_||_dS)N)r�rir�rhrjrk)rFr�r�rjrhrirkrIrIrJrKs					zPyStringConst.__init__cCs|j|jkS)N)r�)rFrPrIrIrJ�__lt__szPyStringConst.__lt__)rZr[r\r]rKrmrIrIrIrJrgsrgc@s#eZdZiZddddddddd	d
ddd
ddddddddddddgZddd�Zdd�Zdd �Zd!d"�Zd#d$�Z	d%d&�Z
d'd(�Zd)d*d+�Zd,d-�Z
d.dd/d0�Zdd1d2�Zd3d4�Zdd)dd5d6�Zd7d8�Zd9d:�Zdd;d<�Zd.d=d>�Zd?d@�ZdAdB�Zd.d.dCdD�ZdEdF�ZdGdH�ZdIdJ�ZdKdL�ZdMdN�ZdOdP�ZdQdR�ZdSdT�Z dUdV�Z!dWdX�Z"dYdZ�Z#d[d\�Z$d]d^�Z%d_d`�Z&dS)a�GlobalStateZh_code�filename_tableZutility_code_proto_before_typesZnumeric_typedefsZcomplex_type_declarationsZtype_declarationsr�Zmodule_declarationsZtypeinfoZbefore_global_var�
global_var�string_decls�declsZ
late_includesZall_the_rest�pystring_table�cached_builtins�cached_constantsr�Zinit_moduler��cleanup_moduleZmain_methodr��endNcCs�i|_g|_i|_t�|_i|_d|_||_||_i|_	||_
i|_i|_i|_
i|_g|_i|_|j|�||_dS)NF)ro�
filename_list�input_file_contentsrj�
utility_codes�declared_cnamesZin_utility_code_generation�code_config�common_utility_include_dir�parts�module_node�const_cnames_used�string_const_index�pyunicode_ptr_const_index�num_const_index�py_constants�cached_cmethods�set_global_stater)rFrrr|r}rIrIrJrKUs$															
zGlobalState.__init__cCs�|j}x$|jD]}|j�|j|<qWtjsF|jd=n$|jd}|j�|jd�|jd}|j�|jd�|jd�|j�|j	d�|jd}|j�|jd�|jd�tj
s�|jd	=n1|jd	}|j�|jd�|jd
�|jd}|jd�|jd�|jd
}|jjrw|j
d�|jd�|jd�dS)Nrtz+static int __Pyx_InitCachedBuiltins(void) {rur�z,static int __Pyx_InitCachedConstants(void) {Z__Pyx_InitCachedConstantsr�z$static int __Pyx_InitGlobals(void) {r�z(static void __Pyx_CleanupGlobals(void) {r�z)/* --- Runtime support code (head) --- */r�z
#line 1 "cython_utility"
z"/* --- Runtime support code --- */)r�code_layout�insertion_pointr~r	�cache_builtins�enter_cfunc_scoperV�put_declare_refcount_context�put_setup_refcount_contextrr|�
emit_linenumsrY)rFr�part�wrWrIrIrJ�initialize_main_c_codels@		













	










z"GlobalState.initialize_main_c_codecCsS|j�|jd}tjdd�}|j|j|j��|jd�dS)Nr�ZTypeConversionszTypeConversion.cr�)�close_global_declsr~rr�r�r�rhrV)rFrWr�rIrIrJ�finalize_main_c_code�s


z GlobalState.finalize_main_c_codecCs|j|S)N)r~)rFrOrIrIrJ�__getitem__�szGlobalState.__getitem__cCs�|j�tjrs|jd}|jd�|j|j�r\|j|j�|jd�|jd�|j�|jd}|j	�|jd�|j|j�r�|j|j�|j	�|jd�|jd�|j�|jd}|jd�|j|j�r0|j|j�|jd�|jd�|j�tj
rt|jd}|jd�|j�tj
r�|jd}|jd�|j�dS)	Nrtz	return 0;z
return -1;�}rur�r�rv)�generate_const_declarationsr	r�r~rVr7r�	put_label�exit_cfunc_scope�put_finish_refcount_contextr)rFr�rIrIrJr��sB
	
















	


	

zGlobalState.close_global_declscCs|djd|j�dS)Nrpzstatic PyObject *%s;)rVr�)rF�entryrIrIrJ�put_pyobject_decl�szGlobalState.put_pyobject_declcCs|jdS)Nru)r~)rFrIrIrJ�get_cached_constants_writer�sz'GlobalState.get_cached_constants_writerFcCsT|rdpd}y|j||f}Wn$tk
rO|j||�}YnX|S)N�long�int)r�rl�
new_num_const)rF�	str_value�longnessrO�crIrIrJ�
get_int_const�s
zGlobalState.get_int_constcCsEy|j|df}Wn'tk
r@|j|d|�}YnX|S)N�float)r�rlr�)rFr�rPr�rIrIrJ�get_float_const�s

zGlobalState.get_float_constr�cCsR|j||�}|dk	rN|tjkrN|jd}|jd|j�|S)Nr�z
Py_CLEAR(%s);)�new_py_constr	rr~rVr�)rFr?r��
cleanup_level�constZcleanup_writerrIrIrJ�get_py_const�s
zGlobalState.get_py_constcCsm|jr|j�}n|j�}y|j|}Wn$tk
r[|j||�}YnX|j|�|S)N)rj�
utf8encode�
byteencoder�rl�new_string_constr])rFrW�
py_versionr[r�rIrIrJ�get_string_const�s	

zGlobalState.get_string_constcCsP|jst�y|j|}Wn)tk
rK|j�}|j|<YnX|S)N)rjr�r�rl�new_const_cname)rFrWr�rIrIrJ�get_pyunicode_ptr_const�s
z#GlobalState.get_pyunicode_ptr_constcCs�d}|r]|dk	r]|j�|j�kr]|j|dd�}|j|dd�}n|j|�}|j|j|||�}|S)Nr�r�r)r�r�r�r�r�)rFrWr�rh�
unicode_valueriZc_stringrlrIrIrJr�szGlobalState.get_py_string_constcCs|j|dd�S)Nr�T)r�)rFrWrIrIrJ�get_interned_identifiersz#GlobalState.get_interned_identifiercCs2|j|�}t|||�}||j|<|S)N)�new_string_const_cnamerVr�)rFrWr[r�r�rIrIrJr�s
zGlobalState.new_string_constcCs>|j||�}t||||�}||j||f<|S)N)�new_num_const_cnamerNr�)rFr�rOrPr�r�rIrIrJr�szGlobalState.new_num_constcCs2|j|�}t||�}|jj|�|S)N)r�rQr�r�)rFr?r�r�r�rIrIrJr�#szGlobalState.new_py_constcCs"|jdd�}|jd|�S)Nri�ignorer�)�decoder�)rFZbytes_valuer�rIrIrJr�)sz"GlobalState.new_string_const_cnamecCsg|dkr|d7}d}tj|}d||f}|jdd�jdd�jd	d�}|S)
Nr��Lr�z%s%s�+r3�-Zneg_r�)rrer�)rFr�rOr�r�rIrIrJr�.s

*zGlobalState.new_num_const_cnamecCs�td|�dd�jd�}|j}|}x6||kri||d}||<d||f}q4Wd||<|r�tj|}n	tj}d||fS)Nr3� rz%s_%dz%s%s)rTr�r�rrerf)rFr�r�rEZname_suffixr=rIrIrJr�7s"	
	zGlobalState.new_const_cnamecCs]||f}y|j|}Wn9tk
rX|jdd||f�}|j|<YnX|S)NZumethodz%s_%s)r�rlr�)rFr�r�rOr�rIrIrJ�get_cached_unbound_methodEs
&z%GlobalState.get_cached_unbound_methodcCsbdt|�}|jtj|d��|j||�}|g|}d||dj|�fS)NzCallUnboundCMethod%dzObjectHandling.cz__Pyx_%s(&%s, %s)z, )r�r�r�r�r�rb)rFr�r�r�Z
arg_cnamesr�Zcache_cnamer�rIrIrJr�Ns
z+GlobalState.cached_unbound_method_call_codecCs�|jr�|jr�|j|j|�r�|j|�|jd}d}|jtkr�t|j\}}|jd|�|j	|j
tj|�|j�|jd�|j	|j
tj|j�|j�|r�|jd�dS)Nrtz#if %sz#elsez#endif)
�
is_builtinr8�should_declarer�r�r~ry�non_portable_builtins_maprV�put_cached_builtin_init�posr
r�)rFr�r�Z	condition�replacementrIrIrJ�add_cached_builtin_declZs"




z#GlobalState.add_cached_builtin_declcCsb|jd}|j|�j}|jtjdd��|jd||||j|�f�dS)NrtZGetBuiltinNamezObjectHandling.cz*%s = __Pyx_GetBuiltinName(%s); if (!%s) %s)r~r�r�r�r�r�rV�
error_goto)rFr�ryr�r�Zinterned_cnamerIrIrJr�ms
	z#GlobalState.put_cached_builtin_initcCs,|j�|j�|j�|j�dS)N)�generate_cached_methods_decls�generate_string_constants�generate_num_constants�generate_object_constant_decls)rFrIrIrJr�xs


z'GlobalState.generate_const_declarationscCshdd�|jD�}|j�|jd}x4|D],\}}}|jd|jj|��q4WdS)NcSs+g|]!}t|j�|j|f�qSrI)r�r�)r�r�rIrIrJr�s	z>GlobalState.generate_object_constant_decls.<locals>.<listcomp>rrz
static %s;)r��sortr~rVr?�declaration_code)rF�consts�decls_writerr3r�r�rIrIrJr�~s	


z*GlobalState.generate_object_constant_declsc	Cs�|js
dS|jd}|jd}g}xt|jj��D]h\\}}}|j|�|jtj|��j}|j	d||f�|j	d||f�qCWt
jr�|jd}x|D]}|j	d|�q�WdS)Nrrr�z4static __Pyx_CachedCFunction %s = {0, &%s, 0, 0, 0};z%s.type = (PyObject*)&%s;r�zPy_CLEAR(%s.method);)r�r~rUrqr�r�r
r�r�rVr	r)	rF�declr��cnamesr�r�r�Zmethod_name_cnamer�rIrIrJr��s 	

(
			

z)GlobalState.generate_cached_methods_declsc
Cs�dd�|jj�D�}|j�g}|jd}x�|D]�\}}}d}|jr�d|jks|d|jkr�d}|jdd|jkr�d	p�d
�|jd|tj|j�f�|r�|jd�|j	dk	r@x9|j	j�D](}|j
|jt|j�|f�q�Wq@Wx�t
|jj��D]�\}}tj|�\}	}
|	rw|jd
�|jd||
f�|	rC|jd�|jd||	f�|jd�qCW|r}|jtjdd��|j�|jd}|jd�|jdtj�x
|D]\}}}|jsY|jsY|jd%krbd}
nd|jj�}
|jd|j�|jr�|jd�|jd|j|jj|jjddd |jf�|jd�|jd|j|||
|j|j|jf�|jr'|jd�q'W|jd!�|jd"�|jd#}|jd$tj|j|j�f�dS)&NcSs+g|]!}t|j�|j|f�qSrI)r�r�)r�r�rIrIrJr��s	z9GlobalState.generate_string_constants.<locals>.<listcomp>rqFrr�Tz#if PY_MAJOR_VERSION %s 3r:z>=zstatic const char %s[] = "%s";z#endifz#ifdef Py_UNICODE_WIDEz static Py_UNICODE %s[] = { %s };z#elseZInitStringsz
StringTools.crsr�z$static __Pyx_StringTabEntry %s[] = {ri�USASCII�US-ASCII�UTF8�UTF-8�0z"%s"zstatic PyObject *%s;z#if PY_MAJOR_VERSION >= 3z&{&%s, %s, sizeof(%s), %s, %d, %d, %d},rrz{0, 0, 0, 0, 0, 0, 0}z};r�z"if (__Pyx_InitStrings(%s) < 0) %s;)rir�r�r�r�)r�rzr�r~rZrVr
Zsplit_string_literalrXrYr�r�r�rUr�rqZencode_pyunicode_stringr�r�r�rZstringtab_cnamerhr�rdrirkrjr�r�)rFZc_constsrYr�r3r�r�ZconditionalrlZutf16_arrayZutf32_arrayr�Zc_cnamer�r�rIrIrJr��s�

'		
*"




			
				
		


z%GlobalState.generate_string_constantscCsdd�|jj�D�}|j�|jd}|jd}x�|D]�\}}}}}}|j}	|jd|	�|dkr�d}
nW|dkr�d	}
nBtj|�r�d
}
n*t|j	d��dkr�d
}
nd}
|jd|	|
||j
|	|j�f�qGWdS)NcSsGg|]=}|j|jddkt|j�|j|j|f�qS)rr�)rOr�r�rP)r�r�rIrIrJr��s	z6GlobalState.generate_num_constants.<locals>.<listcomp>rrr�zstatic PyObject *%s;r�zPyFloat_FromDouble(%s)r�z%PyLong_FromString((char *)"%s", 0, 0)z$PyInt_FromString((char *)"%s", 0, 0)r��zPyInt_FromLong(%sL)zPyInt_FromLong(%s)z%s = %s; %s)r�rzr�r~r�rVrZlong_literalr��lstrip�error_goto_if_nullr�)rFr�r�r�rOr3r�rPr�r��functionrIrIrJr��s(	


						
z"GlobalState.generate_num_constantscCsq||jkr\|j|}t|j�t|j�ks@t�|j|jksXt�dS||j|<dSdS)NFT)r{rr?r�r�)rFr�r�rPrIrIrJr�s
$
zGlobalState.should_declarecCsb|j�}y|j|}Wn>tk
r]t|j�}|jj|�||j|<YnX|S)N)Zget_filenametable_entryrorlr�rxr�)rF�source_descr��indexrIrIrJ�lookup_filenames
zGlobalState.lookup_filenamecCs�y|j|SWntk
r#YnX|jdddd�}zdd�|D�}Wdt|d�ro|j�X|s�|jd�||j|<|S)	Nr�riZerror_handlingr�cSs8g|].}d|j�jdd�jdd��qS)z * z*/z.*[inserted by cython to avoid comment closer]/z/*z-/[inserted by cython to avoid comment start]*)r�r�)r�r�rIrIrJr�%s	z7GlobalState.commented_file_contents.<locals>.<listcomp>�closer�)ryrl�	get_lines�hasattrr�r�)rFr��source_file�FrIrIrJ�commented_file_contentss
		

z#GlobalState.commented_file_contentscCs6|r2||jkr2|jj|�|j|�dS)a
        Adds code to the C file. utility_code should
        a) implement __eq__/__hash__ for the purpose of knowing whether the same
           code has already been included
        b) implement put_code, which takes a globalstate instance

        See UtilityCode.
        N)rzr�r)rFr�rIrIrJr�6s	zGlobalState.use_utility_codecCsF|dkrdS|jr)|j|j�|jrB|j|j�dS)N)r�r�Zutility_code_definition)rFr�rIrIrJ�use_entry_utility_codeCs		z"GlobalState.use_entry_utility_code)'rZr[r\�
directivesr�rKr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rIrIrIrJrnsz	*)	
	
			M

rncs@tj����fdd�}�fdd�}t||�S)Ncs
�|j�S)N)�	funcstate)rF)�attribute_ofrIrJrSNsz!funccontext_property.<locals>.getcst|j�|�dS)N)�setattrr�)rFr�)ryrIrJrjPsz!funccontext_property.<locals>.set)r�
attrgetter�property)ryrSrjrI)r�ryrJ�funccontext_propertyLsr�c@s%eZdZddddd�ZdS)�CCodeConfigTcCs||_||_||_dS)N)�emit_code_commentsr��c_line_in_traceback)rFr�r�r�rIrIrJrKZs		zCCodeConfig.__init__N)rZr[r\rKrIrIrIrJr�Usr�c@s�eZdZdZdZZddddd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zddd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"dd4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d<dd=d>�Z'd?d@�Z(dAdB�Z)ddddCdD�Z*dEdF�Z+dGdH�Z,dIdJ�Z-dKdL�Z.d<ddMdN�Z/dOdPdQ�Z0dRdS�Z1dTdU�Z2dVdW�Z3dXdY�Z4dZd[�Z5d\d]�Z6d^d_�Z7d`da�Z8dbdc�Z9ddde�Z:dfdg�Z;dhdi�Z<djdk�Z=dldm�Z>dndo�Z?d<ddOdpdq�Z@drds�ZAdtdu�ZBdvdw�ZCdxdy�ZDeEdzd{�ZFd|d}�ZGd~d�ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLdOd�d��ZMdOd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRdOd�d��ZSd�d��ZTdOdd�d��ZUdOdOd�d��ZVdOdd�d��ZWdOddOddd�d��ZXd�d��ZYd�d��ZZd�d��Z[dOd�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d�d��Z`d�d��Zad�d��Zbdd�d��Zcdd�d��Zdd�d��ZedOd�d��Zfd�dOd�d��ZgdOd�d��ZhdOdd�d��Zidd�d��Zjdd�d��Zkdd�d��Zld�d��Zmd�d��Zndd�d��Zodd�d��Zpd�d��Zqd�d��Zrd�d��Zsd�d��Ztd�d��Zud�d��Zvd�d��Zwdd�d��Zxd�d��ZydOd�d��Zzdd�d��Z{d�d��Z|dd�d��Z}dd�d��Z~d�d��Zdd�d��Z�d�d��Z�d�d��Z�d�d��Z�dS)��CCodeWritera�
    Utility class to output C code.

    When creating an insertion point one must care about the state that is
    kept:
    - formatting state (level, bol) is cloned and used in insertion points
      as well
    - labels, temps, exc_vars: One must construct a scope in which these can
      exist by calling enter_cfunc_scope/exit_cfunc_scope (these are for
      sanity checking and forward compatibility). Created insertion points
      looses this scope and cannot access it.
    - marker: Not copied to insertion point
    - filename_table, filename_list, input_file_contents: All codewriters
      coming from the same root share the same instances simultaneously.
    NFcCs�|dkrt�}||_d|_d|_g|_d|_d|_d|_d|_|dk	r�|j	|j
�|j|_|r�|j|_|j|_|j|_|j|_|j|_dS)Nrr)r
�buffer�last_pos�last_marked_posZ
pyclass_stackr��levelZ
call_level�bolr�r)rF�create_fromr��copy_formattingrIrIrJrK�s&									zCCodeWriter.__init__cCst|||�}|S)N)r�)rFr�r�r�rBrIrIrJ�
create_new�szCCodeWriter.create_newcCs.|jdkst�||_|j|_dS)N)rr�r|)rFZglobal_staterIrIrJr��s	zCCodeWriter.set_global_statecCs|jj|�dS)N)r��copyto)rFr�rIrIrJr��szCCodeWriter.copytocCs
|jj�S)N)r��getvalue)rFrIrIrJr��szCCodeWriter.getvaluecCsS|jr|jdnd}|jjj|g|jd��|jj|�dS)Nrrre)r�r��markers�extend�countrY)rFr�Z
cython_linenorIrIrJrY�s#zCCodeWriter.writecCs+|jd|d|jj�dd�}|S)Nr�r�r�T)r�r�r�)rFrPrIrIrJr��s'zCCodeWriter.insertion_pointcCs
td|�S)z�
        Creates a new CCodeWriter connected to the same global state, which
        can later be inserted using insert.
        r�)r�)rFrIrIrJ�
new_writer�szCCodeWriter.new_writercCs/|j|jkst�|jj|j�dS)z�
        Inserts the contents of another code writer (created with
        the same global state) in the current location.

        It is ok to write to the inserted writer also after insertion.
        N)rr�r��insert)rFrrIrIrJr��szCCodeWriter.insertrrrrrr�return_from_error_cleanup_labelrcCs|jj|�S)N)r�r)rFryrIrIrJr�szCCodeWriter.new_labelcCs
|jj�S)N)r�r)rFrIrIrJr�szCCodeWriter.new_error_labelcGs|jj|�S)N)r�r')rFr�rIrIrJr'�szCCodeWriter.new_yield_labelcCs
|jj�S)N)r�r))rFrIrIrJr)�szCCodeWriter.get_loop_labelscCs|jj|�S)N)r�r+)rFr*rIrIrJr+�szCCodeWriter.set_loop_labelscCs
|jj�S)N)r�r/)rFrIrIrJr/�szCCodeWriter.new_loop_labelscCs
|jj�S)N)r�r0)rFrIrIrJr0�szCCodeWriter.get_all_labelscCs|jj|�S)N)r�r1)rFr*rIrIrJr1�szCCodeWriter.set_all_labelscCs
|jj�S)N)r�r4)rFrIrIrJr4�szCCodeWriter.all_new_labelscCs|jj|�S)N)r�r6)rFr5rIrIrJr6�szCCodeWriter.use_labelcCs|jj|�S)N)r�r7)rFr5rIrIrJr7�szCCodeWriter.label_usedcCst|d|�|_dS)Nr)r
r�)rFrrIrIrJr��szCCodeWriter.enter_cfunc_scopecCs
d|_dS)N)r�)rFrIrIrJr��szCCodeWriter.exit_cfunc_scopecCs|jj||�jS)N)rr�r�)rFr�r�rIrIrJ�
get_py_int�szCCodeWriter.get_py_intcCs|jj||�jS)N)rr�r�)rFr�rPrIrIrJ�get_py_float�szCCodeWriter.get_py_floatr�cCs|jj|||�jS)N)rr�r�)rFr?r�r�rIrIrJr��szCCodeWriter.get_py_constcCs|jj|�jS)N)rr�r�)rFrWrIrIrJr��szCCodeWriter.get_string_constcCs|jj|�S)N)rr�)rFrWrIrIrJr��sz#CCodeWriter.get_pyunicode_ptr_constcCs|jj||||�jS)N)rr�r�)rFrWr�rhr�rIrIrJr��s	zCCodeWriter.get_py_string_constcCs|jj|�jS)N)rr�r�)rFr?rIrIrJ�get_argument_default_const�sz&CCodeWriter.get_argument_default_constcCs
|j|�S)N)r�)rFrWrIrIrJrk�szCCodeWriter.interncCs|j|dd�S)Nr�T)r�)rFrWrIrIrJ�intern_identifierszCCodeWriter.intern_identifiercCs
|jj�S)N)rr�)rFrIrIrJr�sz'CCodeWriter.get_cached_constants_writercCs�|jr|jr|j�|jjr`|jr`|j\}}}|jd||j�f�|r�|r||j|�n
|j	|�|jd�d|_dS)Nz
#line %s "%s"
rer)
r�r��emit_markerr|r�r�rY�get_escaped_description�put_safer�)rFrW�safer�r�r3rIrIrJrVs


zCCodeWriter.putlnTcCsS|dkrdS|jr@|jdd�|dd�kr@dS||f|_dS)Nr)r�r�)rFr��tracerIrIrJ�mark_poss
,zCCodeWriter.mark_poscCs�|j\}}||_d|_|jd�|jjr^|j�|jd|j|��|r�|jr�|jjr�|j	j
dr�|j�|jd|d|jj|j|�f�dS)Nrez	/* %s */
�	linetracez__Pyx_TraceLine(%d,%d,%s)
r)
r�r�rYr|r��indent�
_build_markerr�rrr�rr�)rFr�rrIrIrJr�s		

+
	zCCodeWriter.emit_markercCs�|\}}}t|t�s$t�|jj|�}|td|d�|�}|dd7<||||d�7}d|j�|dj|�fS)	Nrr�rz             # <<<<<<<<<<<<<<rz"%s":%d
%s
rer<)r�rr�rr��maxrrb)rFr�r�r��col�contentsrurIrIrJr*szCCodeWriter._build_markercCs|j|�d|_dS)Nr)rYr�)rFrWrIrIrJr3s
zCCodeWriter.put_safec
Cs�|jj}|r�t|�dkr�d|tj|jd��j�f}tjj	||�}tjj
|�s�d|tj�f}tt
j|���}|j|�WdQRXtj||�d|}|j|�dS)Niz%s_%s.hr^z%s.tmp%sz#include "%s"
)rr}r��hashlib�md5rp�	hexdigestrr^rb�exists�getpidrr�
open_new_filerY�shutil�mover�)rFrWryZinclude_dirZinclude_filer^Ztmp_pathr�rIrIrJr�8s%
zCCodeWriter.put_or_includecCst|�rdSd}d|kr4|jd�}nd}d|kr�||jd�8}|dkrw|j|7_n1|dkr�|ddkr�d}|jd8_|jr�|j�|j|�d|_|dkr�|j|7_n|r|jd7_dS)NF�{rr�Tr)�is_self_assignmentr�r�r�rrY)rFrWZ
fix_indentZdlrIrIrJr�Fs*	

	zCCodeWriter.putcKs*ddlm}|j|||��dS)Nr)r�)rr�rV)rFrWr�r�rIrIrJ�
putln_tempita_szCCodeWriter.putln_tempitacKs*ddlm}|j|||��dS)Nr)r�)rr�r�)rFrWr�r�rIrIrJ�put_tempitacszCCodeWriter.put_tempitacCs|jd7_dS)Nr)r�)rFrIrIrJ�increase_indentgszCCodeWriter.increase_indentcCs|jd8_dS)Nr)r�)rFrIrIrJ�decrease_indentjszCCodeWriter.decrease_indentcCs|jd�|j�dS)Nr)rVr)rFrIrIrJ�begin_blockms
zCCodeWriter.begin_blockcCs|j�|jd�dS)Nr�)rrV)rFrIrIrJ�	end_blockqs
zCCodeWriter.end_blockcCs|jd|j�dS)Nz  )rYr�)rFrIrIrJruszCCodeWriter.indentcCsdt|�ddd�S)Nz0x%02X%02X%02X%02Xrr�)rrrr)r�)rFZ	pyversionrIrIrJ�get_py_version_hexxszCCodeWriter.get_py_version_hexcCs'||jjkr#|jd|�dS)Nz%s:;)r�rrV)rFr5rIrIrJr�{szCCodeWriter.put_labelcCs%|jj|�|jd|�dS)Nzgoto %s;)r�r6rV)rFr5rIrIrJ�put_gotoszCCodeWriter.put_gotocCs�|jdkr#|p|jr#dS|jdkr@|jr@dS|rW|jd|�|jsm|jd�|j|jj|jd|��|jdk	r�|j	d|jj
|j��n|jjr�|jd�|jd�dS)NZprivatez%s zCYTHON_UNUSED �dll_linkagez = %sz = NULL�;)
Z
visibilityZdefined_in_pxdrEr�Zcf_usedr?r�r�r�rZliteral_coder9rV)rFr�Z
storage_classrZ
definitionrIrIrJ�put_var_declaration�s	
#
zCCodeWriter.put_var_declarationc	Csx�|jD]�\}}}}|j|�}|jrH|jd|�q
|jr~ddlm}|jd||jf�q
|jd|r�dp�d|f�q
W|jr|j	j
r�d}nd}|jd	|tjf�|jd
|tj
f�|jd	|tjf�dS)Nz
%s = NULL;r)�
MemoryViewz%s = %s;z%s%s;zstatic r�zCYTHON_UNUSED z
%sint %s = 0;z%sconst char *%s = NULL;)rr�r9rVr:r�r Zmemslice_entry_initr"r�r#r�lineno_cname�filename_cname�
clineno_cname)	rFZfunc_contextryr?r?r@r�r ZunusedrIrIrJ�put_temp_declarations�s		'		z!CCodeWriter.put_temp_declarationscCs%|jdtj�|jd�dS)Nz/* Generated by Cython %s */r�)rVrZ	watermark)rFrIrIrJ�put_generated_by�szCCodeWriter.put_generated_bycCs&|jd|�|jd|�dS)Nz
#ifndef %sz
#define %s)rV)rFZguardrIrIrJ�put_h_guard�szCCodeWriter.put_h_guardcCstjrd|S|SdS)Nzunlikely(%s))r	Zgcc_branch_hints)rF�condrIrIrJ�unlikely�s	zCCodeWriter.unlikelycs.|s
dSddj�fdd�|D��S)Nr�z%s � csg|]}�||��qSrIrI)r�r�)�mapperrIrJr��s	z8CCodeWriter.build_function_modifiers.<locals>.<listcomp>)rb)rF�	modifiersr*rI)r*rJ�build_function_modifiers�sz$CCodeWriter.build_function_modifierscCsE|j}|jr#|jj�s/|jjr:d|jS|jSdS)Nz(PyObject *))r?Zis_self_argZis_completeZis_extension_typer�)rFr�r?rIrIrJ�entry_as_pyobject�s
	zCCodeWriter.entry_as_pyobjectcCs&ddlm}m}||||�S)Nr)�py_object_type�typecast)�
PyrexTypesr.r/)rFr�r?r.r/rIrIrJ�as_pyobject�szCCodeWriter.as_pyobjectcCs|jd|�dS)Nz__Pyx_GOTREF(%s);)rV)rFr�rIrIrJ�
put_gotref�szCCodeWriter.put_gotrefcCs|jd|�dS)Nz__Pyx_GIVEREF(%s);)rV)rFr�rIrIrJ�put_giveref�szCCodeWriter.put_giverefcCs|jd|�dS)Nz__Pyx_XGIVEREF(%s);)rV)rFr�rIrIrJ�put_xgiveref�szCCodeWriter.put_xgiverefcCs|jd|�dS)Nz__Pyx_XGOTREF(%s);)rV)rFr�rIrIrJ�put_xgotref�szCCodeWriter.put_xgotrefcCsG|r&|jd|j||��n|jd|j||��dS)Nz__Pyx_INCREF(%s);zPy_INCREF(%s);)rVr1)rFr�r?�nannyrIrIrJ�
put_incref�s zCCodeWriter.put_increfcCs#|j|||dddd�dS)N�
null_checkFr�)�_put_decref)rFr�r?r6rIrIrJ�
put_decref�szCCodeWriter.put_decrefcCs*|jjr&|jd|j|��dS)Nz__Pyx_GOTREF(%s);)r?r9rVr-)rFr�rIrIrJ�put_var_gotref�szCCodeWriter.put_var_gotrefcCs*|jjr&|jd|j|��dS)Nz__Pyx_GIVEREF(%s);)r?r9rVr-)rFr�rIrIrJ�put_var_giveref�szCCodeWriter.put_var_giverefcCs*|jjr&|jd|j|��dS)Nz__Pyx_XGOTREF(%s);)r?r9rVr-)rFr�rIrIrJ�put_var_xgotref�szCCodeWriter.put_var_xgotrefcCs*|jjr&|jd|j|��dS)Nz__Pyx_XGIVEREF(%s);)r?r9rVr-)rFr�rIrIrJ�put_var_xgiveref�szCCodeWriter.put_var_xgiverefcCsM|jjrI|r/|jd|j|��n|jd|j|��dS)Nz__Pyx_INCREF(%s);zPy_INCREF(%s);)r?r9rVr-)rFr�r6rIrIrJ�put_var_incref�szCCodeWriter.put_var_increfcCs*|jjr&|jd|j|��dS)Nz__Pyx_XINCREF(%s);)r?r9rVr-)rFr�rIrIrJ�put_var_xincref�szCCodeWriter.put_var_xincrefc
Cs)|j|||ddddd|�dS)Nr8Fr�T�clear_before_decref)r9)rFr�r?r6rArIrIrJ�put_decref_clear�szCCodeWriter.put_decref_clearc
Cs)|j|||ddd|dd�dS)Nr8T�have_gilr�F)r9)rFr�r?r6rCrIrIrJ�put_xdecrefszCCodeWriter.put_xdecrefc
Cs)|j|||ddddd|�dS)Nr8Tr�rA)r9)rFr�r?r6rArIrIrJ�put_xdecref_clearszCCodeWriter.put_xdecref_clearc
Cs�|jr |j|d|�dS|r,dnd}|r>dnd}	|r�|ry|s\d}	|jd||	|f�q�|jd||	|j||�|f�n&|jd||	|j||�f�dS)	NrCZ__PyxZPy�Xr�z%s_%sCLEAR(%s);z%s_%sDECREF(%s); %s = 0;z%s_%sDECREF(%s);)r:�put_xdecref_memoryviewslicerVr1)
rFr�r?r6r8rCr�rAr�rFrIrIrJr9
s		#	zCCodeWriter._put_decrefcCs|jd||f�dS)Nz__Pyx_DECREF_SET(%s, %s);)rV)rFr��	rhs_cnamerIrIrJ�put_decref_setszCCodeWriter.put_decref_setcCs|jd||f�dS)Nz__Pyx_XDECREF_SET(%s, %s);)rV)rFr�rHrIrIrJ�put_xdecref_set"szCCodeWriter.put_xdecref_setcCs*|jjr&|jd|j|��dS)Nz__Pyx_XDECREF(%s);)r?r9rVr-)rFr�rIrIrJ�put_var_decref%szCCodeWriter.put_var_decrefcCsM|jjrI|r/|jd|j|��n|jd|j|��dS)Nz__Pyx_XDECREF(%s);zPy_XDECREF(%s);)r?r9rVr-)rFr�r6rIrIrJ�put_var_xdecref)szCCodeWriter.put_var_xdecrefcCs|j|dd�dS)Nr8F)�_put_var_decref_clear)rFr�rIrIrJ�put_var_decref_clear0sz CCodeWriter.put_var_decref_clearcCs|j|dd�dS)Nr8T)rM)rFr�rIrIrJ�put_var_xdecref_clear3sz!CCodeWriter.put_var_xdecref_clearcCst|jjrp|jr>|jd|r*dp-d|jf�n2|jd|rSdpVd|j|�|jf�dS)Nz__Pyx_%sCLEAR(%s);rFr�z__Pyx_%sDECREF(%s); %s = 0;)r?r9�
in_closurerVr�r-)rFr�r8rIrIrJrM6s			z!CCodeWriter._put_var_decref_clearrcCsKxD|D]<}|s|jr|jr6|j|�q|j|�qWdS)N)rEZxdecref_cleanuprLrK)rF�entriesZ	used_onlyr�rIrIrJ�put_var_decrefsDs

	zCCodeWriter.put_var_decrefscCs"x|D]}|j|�qWdS)N)rL)rFrQr�rIrIrJ�put_var_xdecrefsLs
zCCodeWriter.put_var_xdecrefscCs"x|D]}|j|�qWdS)N)rO)rFrQr�rIrIrJ�put_var_xdecrefs_clearPs
z"CCodeWriter.put_var_xdecrefs_clearcCsDddlm}|jj|j�|jd|t|�f�dS)Nr)r z__PYX_INC_MEMVIEW(&%s, %d);)r�r rr��memviewslice_init_coderVr�)rF�slice_cnamerCr rIrIrJ�put_incref_memoryviewsliceTsz&CCodeWriter.put_incref_memoryviewslicecCsDddlm}|jj|j�|jd|t|�f�dS)Nr)r z__PYX_XDEC_MEMVIEW(&%s, %d);)r�r rr�rUrVr�)rFrVrCr rIrIrJrGYsz'CCodeWriter.put_xdecref_memoryviewslicecCs|jd|�dS)Nz
%s.memview)r4)rFrVrIrIrJ�put_xgiveref_memoryviewslice^sz(CCodeWriter.put_xgiveref_memoryviewslicecCscddlm}m}|||d�}|rH|jd||f�n|jd||f�dS)Nr)r.r/�Py_Nonez%s = %s; __Pyx_INCREF(Py_None);z%s = %s; Py_INCREF(Py_None);)r0r.r/rV)rFr�r?r6r.r/Zpy_nonerIrIrJ�put_init_to_py_noneas
zCCodeWriter.put_init_to_py_nonez%scCs=||j}|j||j|�|jr9|jd�dS)NrY)r�rZr?rPr3)rFr��templater6rWrIrIrJ�put_init_var_to_py_noneis
	z#CCodeWriter.put_init_var_to_py_nonecCs�|js|jdkrT|jtkrT|jdkrJ|jjdrJn
|rTdSddlm}|jry|j}nd}|j	j
�}|r�|jr�||g7}|jd|j|jdj
|�||f�dS)	N�__getattribute__�__getattr__Zfast_getattrr)�method_coexistrz!{"%s", (PyCFunction)%s, %s, %s}%s�|)Z
is_specialry�special_py_methodsrr�Z	TypeSlotsr_�docZ	doc_cname�	signature�method_flagsrVZ
func_cnamerb)rFr�ZtermZ
allow_skipr_Zdoc_coderdrIrIrJ�put_pymethoddefqs* 		
zCCodeWriter.put_pymethoddefcCs�|jjtjdd��|jjdrK|jjtjdd��n|jjtjdd��|jd�|s�d}|r�|jd�|jd	|�|jd
�dS)a
        Acquire the GIL. The generated code is safe even when no PyThreadState
        has been allocated for this thread (for threads not initialized by
        using the Python API). Additionally, the code generated by this method
        may be called recursively.
        �ForceInitThreadszModuleSetupCode.c�fast_gil�FastGil�	NoFastGilz#ifdef WITH_THREAD�__pyx_gilstate_savezPyGILState_STATE z%s = __Pyx_PyGILState_Ensure();z#endifN)rr�r�r�r�rVr�)rF�declare_gilstate�variablerIrIrJ�put_ensure_gil�s	

zCCodeWriter.put_ensure_gilcCs�|jjdr/|jjtjdd��n|jjtjdd��|sWd}|jd�|jd|�|jd�d	S)
zD
        Releases the GIL, corresponds to `put_ensure_gil`.
        rgrhzModuleSetupCode.crirjz#ifdef WITH_THREADz__Pyx_PyGILState_Release(%s);z#endifN)rr�r�r�r�rV)rFrlrIrIrJ�put_release_ensured_gil�s
z#CCodeWriter.put_release_ensured_gilcCs�|jjdr/|jjtjdd��n|jjtjdd��|jd�|jd�|r||jd|�|jd�|jd	�d
S)z
        Acquire the GIL. The thread's thread state must have been initialized
        by a previous `put_release_gil`
        rgrhzModuleSetupCode.criz#ifdef WITH_THREADz__Pyx_FastGIL_Forget();z_save = %s;ZPy_BLOCK_THREADSz#endifN)rr�r�r�r�rV)rFrlrIrIrJ�put_acquire_gil�s


zCCodeWriter.put_acquire_gilcCs�|jjdr/|jjtjdd��n|jjtjdd��|jd�|jd�|jd�|r�|jd|�|jd	�|jd
�dS)z2Release the GIL, corresponds to `put_acquire_gil`.rgrhzModuleSetupCode.criz#ifdef WITH_THREADzPyThreadState *_save;ZPy_UNBLOCK_THREADSz%s = _save;z__Pyx_FastGIL_Remember();z#endifN)rr�r�r�r�rV)rFrlrIrIrJ�put_release_gil�s



zCCodeWriter.put_release_gilcCs+|jd�|jd�|jd�dS)Nz#ifdef WITH_THREADz%PyGILState_STATE __pyx_gilstate_save;z#endif)rV)rFrIrIrJrk�s

zCCodeWriter.declare_gilstatecCs |jd||j|�f�S)Nzif (%s < 0) %s)rVr�)rFr�r�rIrIrJ�put_error_if_neg�szCCodeWriter.put_error_if_negcCs�ddlm}|jr5d}|jj|j�nG|jjrc|rcd}|jj|j�nd}|jj|j	�|j
d|jj|j�||j
|j|�f�dS)Nr)�	ExprNodesZ__Pyx_RaiseClosureNameErrorZ&__Pyx_RaiseUnboundMemoryviewSliceNogilZ__Pyx_RaiseUnboundLocalErrorz#if (unlikely(!%s)) { %s("%s"); %s })r�rrZfrom_closurerr�Z%raise_closure_name_error_utility_coder?r:Z+raise_unbound_memoryview_utility_code_nogilZ&raise_unbound_local_error_utility_coderVZcheck_for_null_coder�ryr�)rFr�r�Zin_nogil_contextrr�funcrIrIrJ�put_error_if_unbound�s"		
	
	
	z CCodeWriter.put_error_if_unboundcCs}d|j_|rd|j_|jjrCdtjtjf}nd}dtjtj	|j
|d�tj|d|fS)NTz	 %s = %s;r�z%s = %s[%s]; %s = %s;%srr)r�r"r#r|r�rr#Zline_c_macror"�filetable_cnamer�r!)rFr�rEZcinforIrIrJ�set_error_info�szCCodeWriter.set_error_infocCs>|jj}|jj|�d|j|d�|d|fS)Nz__PYX_ERR(%s, %s, %s)rr)r�rr6r�)rFr�r5rIrIrJr�	szCCodeWriter.error_gotocCs d|j|�|j|�fS)Nz
if (%s) %s)r(r�)rFr'r�rIrIrJ�
error_goto_if	szCCodeWriter.error_goto_ifcCs|jd||�S)Nz!%s)rw)rFr�r�rIrIrJr�	szCCodeWriter.error_goto_if_nullcCs|jd||�S)Nz%s < 0)rw)rFr�r�rIrIrJ�error_goto_if_neg	szCCodeWriter.error_goto_if_negcCs|jd|�S)NzPyErr_Occurred())rw)rFr�rIrIrJr	szCCodeWriter.error_goto_if_PyErrcCs|jj|�S)N)rr�)rFr�rIrIrJr�	szCCodeWriter.lookup_filenamecCs|jd�dS)NZ__Pyx_RefNannyDeclarations)rV)rFrIrIrJr�	sz(CCodeWriter.put_declare_refcount_contextcCsI|r"|jjtjdd��|jd||r:dp=df�dS)NrfzModuleSetupCode.cz%__Pyx_RefNannySetupContext("%s", %d);rr)rr�r�r�rV)rFryZacquire_gilrIrIrJr�	s	z&CCodeWriter.put_setup_refcount_contextcCs|jd�dS)Nz__Pyx_RefNannyFinishContext();)rV)rFrIrIrJr� 	sz'CCodeWriter.put_finish_refcount_contextcCsH||rtjndtjtjf}d|j_|jd|�dS)z�
        Build a Python traceback for propagating exceptions.

        qualified_name should be the qualified name of the function.
        rTz%__Pyx_AddTraceback("%s", %s, %s, %s);N)rr#r!r"r�r#rV)rF�qualified_nameZ
include_cline�format_tuplerIrIrJ�put_add_traceback#	szCCodeWriter.put_add_tracebackcCsh|tjtjtj|jjd|f}d|j_|jd|�|jj	t
jdd��dS)z�
        Generate code to print a Python warning for an unraisable exception.

        qualified_name should be the qualified name of the function.
        �unraisable_tracebacksTz0__Pyx_WriteUnraisable("%s", %s, %s, %s, %d, %d);ZWriteUnraisableExceptionzExceptions.cN)rr#r!r"rr�r�r#rVr�r�r�)rFry�nogilrzrIrIrJ�put_unraisable2	s
		zCCodeWriter.put_unraisablecCs|jd�dS)NZ__Pyx_TraceDeclarations)rV)rFrIrIrJ�put_trace_declarationsE	sz"CCodeWriter.put_trace_declarationscCs|r|jd|�dS)Nz__Pyx_TraceFrameInit(%s))rV)rF�codeobjrIrIrJ�put_trace_frame_initH	sz CCodeWriter.put_trace_frame_initc	CsD|jd|tj|j|d�|d||j|�f�dS)Nz*__Pyx_TraceCall("%s", %s[%s], %s, %d, %s);rr)rVrrur�r�)rFryr�r}rIrIrJ�put_trace_callL	s	zCCodeWriter.put_trace_callcCs|jd�dS)Nz__Pyx_TraceException();)rV)rFrIrIrJ�put_trace_exceptionP	szCCodeWriter.put_trace_exceptioncCs|jd||f�dS)Nz__Pyx_TraceReturn(%s, %d);)rV)rFZretvalue_cnamer}rIrIrJ�put_trace_returnS	szCCodeWriter.put_trace_returncCs+|jd�|j|�|jd�dS)Nz#ifdef _OPENMPz#endif /* _OPENMP */)rV)rF�stringrIrIrJ�putln_openmpV	s

zCCodeWriter.putln_openmpcCsV|jd|�|jd�|jd�|jd�|jd�|jd�dS)zl
        Redefine the macros likely() and unlikely to no-ops, depending on
        condition 'cond'
        z#if %sz    #undef likelyz    #undef unlikelyz    #define likely(x)   (x)z    #define unlikely(x) (x)z#endifN)rV)rFr'rIrIrJ�undef_builtin_expect[	s



z CCodeWriter.undef_builtin_expectcCsV|jd|�|jd�|jd�|jd�|jd�|jd�dS)Nz#if %sz    #undef likelyz    #undef unlikelyz2    #define likely(x)   __builtin_expect(!!(x), 1)z2    #define unlikely(x) __builtin_expect(!!(x), 0)z#endif)rV)rFr'rIrIrJ�redef_builtin_expectg	s



z CCodeWriter.redef_builtin_expect)�rZr[r\r]rr|rKr�r�r�r�rYr�r�r�r�rrrrrrr�rrrr'r)r+r/r0r1r4r6r7r�r�r�r�r�r�r�r�r�rkr�r�rVrr�rrr�r�rrrrrrrrr�rrr$r%r&r(�modifier_output_mapperr,r-r1r2r3r4r5r7r:r;r<r=r>r?r@rBrDrEr9rIrJrKrLrNrOrMrRrSrTrWrGrXrZr\rermrnrorprkrqrtrvr�rwr�rxrr�r�r�r�r{r~rr�r�r�r�r�r�r�rIrIrIrJr�`s

	r�c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�PyrexCodeWritercCstj|�|_d|_dS)Nr)rrr�r�)rFZoutfile_namerIrIrJrKt	szPyrexCodeWriter.__init__cCs%|jjdd|j|f�dS)Nz%s%s
r))r�rYr�)rFrWrIrIrJrVx	szPyrexCodeWriter.putlncCs|jd7_dS)Nr)r�)rFrIrIrJr{	szPyrexCodeWriter.indentcCs|jd8_dS)Nr)r�)rFrIrIrJ�dedent~	szPyrexCodeWriter.dedentN)rZr[r\rKrVrr�rIrIrIrJr�p	sr�c@s�eZdZdZdddddd�Zddd	�Zdd
d�Zdd
�Zdd�Zddd�Z	dd�Z
ddd�Zdd�Zdd�Z
dS)�
PyxCodeWriterz�
    Can be used for writing out some Cython code. To use the indenter
    functionality, the Cython.Compiler.Importer module will have to be used
    to load the code to support python 2.4
    Nrr1cCs1|pt�|_||_||_||_dS)N)r
r�r�r�r�)rFr��indent_levelr�r�rIrIrJrK�	s		zPyxCodeWriter.__init__rcCs|j|7_dS)NT)r�)rF�levelsrIrIrJr�	szPyxCodeWriter.indentcCs|j|8_dS)N)r�)rFr�rIrIrJr��	szPyxCodeWriter.dedentcCs|j|�|j�dS)a
        Instead of

            with pyx_code.indenter("for i in range(10):"):
                pyx_code.putln("print i")

        write

            if pyx_code.indenter("for i in range(10);"):
                pyx_code.putln("print i")
                pyx_code.dedent()
        T)rVr)rFr�rIrIrJ�indenter�	s


zPyxCodeWriter.indentercCs4|jj�}t|t�r0|j|j�}|S)N)r�r�r�rr�r�)rFrBrIrIrJr��	szPyxCodeWriter.getvaluecCs5|p|j}|r$t||�}|j|�dS)N)r�r�_putln)rFr�r�rIrIrJrV�	szPyxCodeWriter.putlncCs%|jjd|jd|f�dS)Nz%s%s
z    )r�rYr�)rFr�rIrIrJr��	szPyxCodeWriter._putlncCs[|p|j}|r$t||�}tj|�}x!|j�D]}|j|�q@WdS)N)r�rrr�r�r�)rF�chunkr�r�rIrIrJ�	put_chunk�	szPyxCodeWriter.put_chunkcCst|jj�|j|j�S)N)r�r�r�r�r�)rFrIrIrJr��	szPyxCodeWriter.insertion_pointcCst|||j��dS)N)r�r�)rFryrIrIrJ�named_insertion_point�	sz#PyxCodeWriter.named_insertion_point)rZr[r\r]rKrr�r�r�rVr�r�r�r�rIrIrIrJr��	s	r�c@s4eZdZdd�Zdd�Zdd�ZdS)rLcCs(||_i|_i|_d|_dS)Nr)�klassrr�temps_count)rFr�rIrIrJrK�	s			zClosureTempAllocator.__init__cCs7x0|jj�D]\}}t|�|j|<qWdS)N)rrqr�r)rFr?r�rIrIrJ�reset�	szClosureTempAllocator.resetcCs�||jkr,g|j|<g|j|<n!|j|rM|j|jd�Sdtj|jf}|jjddd|d|d|dd�|j|j|�|jd	7_|S)
Nrz%s%dr�ryr�r?Zis_cdefTr)	rrr;rr=r�r�Zdeclare_varr�)rFr?r�rIrIrJrC�	s

+z"ClosureTempAllocator.allocate_tempN)rZr[r\rKr�rCrIrIrIrJrL�	srL)L�
__future__r�cython�declare�objectrrr�sysrrr�r�	functoolsr�
contextlibr�collectionsrr�ImportErrorrr�rr	rr
rrZScanningrr
Z__builtin__r�builtinsr�version_inforor�Zbasicsize_builtins_mapZuncachable_builtinsrjrarSr�r�r�rr9rcrdr�rrr	r
rNrQr��UrRrprSr�rT�findallrUrVrgrnr�r�r�r�r�rLrIrIrIrJ�<module>s�!


			L���
!O��5	���E