Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/Cython/Compiler/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/Cython/Compiler/__pycache__/Symtab.cpython-37.pyc

B

Z��Z��%@sBddlmZddlZddlZddlZyddlZWnek
rLddlZYnXddlm	Z	m
Z
mZddlm
Z
ddlmZmZddlmZddlmZmZdd	lmZmZmZmZmZdd
lmZeddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.g$�Zd/d0�ZGd1d2�d2e�ZGd3d4�d4e�Z Gd5d6�d6e �Z!Gd7d8�d8e�Z"Gd9d:�d:e"�Z#Gd;d<�d<e"�Z$dZ%Gd=d>�d>e"�Z&Gd?d@�d@e"�Z'GdAdB�dBe"�Z(GdCdD�dDe'�Z)GdEdF�dFe"�Z*GdGdH�dHe"�Z+GdIdJ�dJe+�Z,GdKdL�dLe+�Z-GdMdN�dNe"�Z.GdOdP�dPe"�Z/GdQdR�dRe"�Z0GdSdT�dTe"�Z1dS)U�)�absolute_importN�)�warning�error�
InternalError)�
EncodedString)�Options�Naming)�
PyrexTypes)�py_object_type�unspecified_type)�pyfunction_signature�pymethod_signature�richcmp_special_methods�get_special_method_signature�get_property_accessor_signature)�Code�auto�breakZcase�char�const�continue�defaultZdo�double�else�enum�extern�float�forZgoto�if�int�long�register�return�short�signed�sizeof�static�struct�switch�typedef�unionZunsigned�voidZvolatile�whileZ_Boolz_Complex, _Imaginary�inlineZrestrictcCs:|dd�dkr$|�tj�s$|dkr,|tkr6tj|}|S)N��__)�__weakref__�__dict__)�
startswithr	�pyrex_prefix�iso_c99_keywords)�cname�r7�I/opt/alt/python37/lib64/python3.7/site-packages/Cython/Compiler/Symtab.py�c_safe_identifier$s

r9c@s eZdZdZdd�Zdd�ZdS)�	BufferAuxFcCs||_||_dS)N)�buflocal_nd_var�	rcbuf_var)�selfr;r<r7r7r8�__init__0szBufferAux.__init__cCs
d|jS)Nz<BufferAux %r>)r2)r=r7r7r8�__repr__4szBufferAux.__repr__N)�__name__�
__module__�__qualname__Zwritable_neededr>r?r7r7r7r8r:-sr:c@sNeZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&gZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDddd�ZEd	d
�ZFdd�ZGd
d�ZHdd�ZIdd�ZJdd�ZKdS)�EntryFr�N�privateTcCs@||_||_||_||_||_g|_g|_g|_g|_||_	dS)N)
�namer6�type�pos�init�overloaded_alternatives�cf_assignments�
cf_references�
inner_entries�defining_entry)r=rFr6rGrHrIr7r7r8r>�szEntry.__init__cCsdt|�jt|�|j|jfS)Nz%s(<%x>, name=%s, type=%s))rGr@�idrF)r=r7r7r8r?�szEntry.__repr__cCst|jd�dS)NzPrevious declaration is here)rrH)r=r7r7r8�already_declared_here�szEntry.already_declared_herecCst|d|j�|��dS)Nz('%s' does not match previous declaration)rrFrP)r=rHr7r7r8�
redeclared�szEntry.redeclaredcCs|g|jS)N)rJ)r=r7r7r8�all_alternatives�szEntry.all_alternativescCs|g|jS)N)rM)r=r7r7r8�all_entries�szEntry.all_entriescCs4t|t�r,t|t�r,|j|jf|j|jfkStSdS)N)�
isinstancerCrFr6�NotImplemented)�left�rightr7r7r8�__lt__�szEntry.__lt__)NN)Lr@rArBZinline_func_in_pxdZborrowedrI�
annotation�
visibility�
is_builtin�
is_cglobal�is_pyglobal�	is_member�is_pyclass_attr�is_variable�is_cfunction�
is_cmethod�is_builtin_cmethodZis_unbound_cmethod�is_final_cmethod�is_inline_cmethod�is_anonymous�is_type�	is_cclass�is_cpp_class�is_const�is_property�	doc_cnameZgetter_cnameZsetter_cnameZis_self_arg�is_arg�is_local�
in_closure�from_closure�in_subscopeZis_declared_generic�is_readonlyZpyfunc_cname�
func_cname�func_modifiers�final_func_cname�doc�as_variableZxdecref_cleanup�in_cinclude�	as_module�is_inheritedZpystring_cnameZ
is_identifierZis_interned�used�
is_special�defined_in_pxd�is_implemented�api�utility_code�is_overridableZ
buffer_aux�
prev_entryZmight_overflowZfused_cfunctionZis_fused_specialized�utility_code_definition�needs_property�in_with_gil_blockZfrom_cython_utility_codeZerror_on_uninitializedZcf_used�outer_entryr>r?rPrQrRrSrXr7r7r7r8rC8s�S
rCc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�
InnerEntryzK
    An entry in a closure scope that represents the real outer Entry.
    TcCsrt�||j|j|j|j�||_||_|}x|jr:|j}q,W||_|j	|_	|j
|_
|j|_|j|_|j	�
|�dS)N)rCr>rFr6rGrHr��scoperNrMrKrLrJ�append)r=r�r�Zoutermost_entryr7r7r8r>�s

zInnerEntry.__init__cCs|�d�rt|��t|j|�S)Nr0)r3�AttributeError�getattrrN)r=rFr7r7r8�__getattr__
s
zInnerEntry.__getattr__cCs
|j��S)N)rNrS)r=r7r7r8rSszInnerEntry.all_entriesN)r@rArB�__doc__rpr>r�rSr7r7r7r8r��s
r�c@s�eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdd�Zdd�Zdhd	d
�Zdd�Zd
d�Zdidd�Zdd�Zdd�Zdjdd�Zdd�Zdd�Zdd�Zdkdd�Zdd �Zdld"d#�Z dmd%d&�Z!dnd'd(�Z"dod*d+�Z#dpd.d/�Z$d0d1�Z%d2d3�Z&dqd4d5�Z'd6d7�Z(drd8d9�Z)d:d;�Z*dsd<d=�Z+dtd>d?�Z,d@dA�Z-dBdC�Z.dDdE�Z/dudFdG�Z0dvdHdI�Z1dJdK�Z2dLdM�Z3dNdO�Z4dPdQ�Z5dRdS�Z6dTdU�Z7dVdW�Z8dXdY�Z9dZd[�Z:d\d]�Z;d^d_�Z<d`da�Z=dbdc�Z>ddde�Z?dfdg�Z@dS)w�ScoperrDNcCs�||_||_||_dt|�|�dd�f}|��}|rP|�|�|_|j||_nt	|�|_||_i|_
t�|_g|_
g|_g|_g|_g|_g|_g|_g|_g|_i|_i|_i|_i|_i|_i|_g|_g|_i|_dS)Nz%d%s_�.Z_dot_)rF�outer_scope�parent_scope�len�replace�qualifying_scope�qualify_name�qualified_name�scope_prefixr�entries�set�	subscopes�
const_entries�type_entries�sue_entries�arg_entries�var_entries�pyfunc_entries�
cfunc_entries�c_class_entriesZdefined_c_classesZimported_c_classesZcname_to_entryZstring_to_entryZidentifier_to_entryZnum_to_entryZobj_to_entryZbuffer_entries�lambda_defs�id_counters)r=rFr�r�Zmangled_nameZ
qual_scoper7r7r8r>Bs<
zScope.__init__cCs|S)Nr7)r=�memor7r7r8�__deepcopy__eszScope.__deepcopy__Tc
Cs�g}x:|j��D],\}}|r$||kr|js.|r|�||f�qW|j�|�xZdD]R}t||�}tdd�|D��}	x0t||�D]"}|js�|r~|j|	kr~|�|�q~WqRWdS)N)r�r�r�r�r�r�r�r�css|]}|jVqdS)N)rF)�.0�er7r7r8�	<genexpr>{sz!Scope.merge_in.<locals>.<genexpr>)r��itemsr{r��updater�r�rF)
r=�otherZmerge_unusedZ	whitelistr�rF�entry�attrZself_entries�namesr7r7r8�merge_inhs


zScope.merge_incCsd|jj|jfS)Nz<%s %s>)�	__class__r@r�)r=r7r7r8�__str__�sz
Scope.__str__cCs|jS)N)r�)r=r7r7r8r��szScope.qualifying_scopecCs(|rd||j|fS|j�||j�SdS)Nz%s%s%s)r�r��manglerF)r=�prefixrFr7r7r8r��szScope.manglecCsdtj|f}|�|�S)Nz%s%s_)r	r4r�)r=rFr�r7r7r8�mangle_internal�szScope.mangle_internalcCs|jr|j�|�S|S)N)r��mangle_class_private_name)r=rFr7r7r8r��szScope.mangle_class_private_namecCs`|��j}y||d}Wntk
r2d}YnX|||<|rT|sH|Sd||fSd|SdS)Nrrz%s%dz%d)�global_scoper��KeyError)r=rFZcounters�countr7r7r8�next_id�s

z
Scope.next_idcCs
|j��S)z6 Return the module-level scope containing this scope. )r�r�)r=r7r7r8r��szScope.global_scopecCs
|j��S)z6 Return the module-level scope containing this scope. )r��
builtin_scope)r=r7r7r8r��szScope.builtin_scopeccs4|V|jr0x"t|jt�d�d�D]
}|Vq"WdS)Nr�)�key)r��sorted�operator�
attrgetter)r=r�r7r7r8�iter_local_scopes�szScope.iter_local_scopesc	Cs||jrt|t�st|d�|js@|r@t�d|�r@t|d|d�|j}	|�r||	k�r|�s|	|}
d}|j	r�|
j
j	r�|��r�x2|
��D]"}||j
kr�|dkr�|j
s�d}Pq�Wd}|r�nZ|jr�|	|jr�nH|dkr�t|d	||jr�d
nd�n$|dk�rt|d	|�|	|��t||||d
�}
|j|
_||
_|�rP|�|�|
_|�sP|
|	|<|j�rld
dlm}|j|
_||
_||
_|
S)Nz5Buffer types only allowed as function local variablesz
^_[_A-Z]+$z'%s' is a reserved name in C.���Fz<init>Trz'%s' redeclared rr�ignore)rH)�
MemoryView)Z	is_bufferrT�
LocalScoperrx�re�matchrr�rarG�is_cpprR�args�is_cpp_class_scoperzrPrC�create_wrapperr�r��is_memoryviewslicerDr�Zmemslice_entry_initrIr�rZ)r=rFr6rGrHrZ�shadowrgr�r�Z	old_entryZcpp_override_allowed�	alt_entryr�r�r7r7r8�declare�sJ


z
Scope.declarecCstd|j|f�S)Nz%s.%s)rr�)r=rFr7r7r8r��szScope.qualify_namerEc	
CsP|s*|js|dks|r|}n|�tj|�}|j||||||d�}	d|	_||	_|	S)N�public)r�r)rxr�r	Zenum_prefixr�rjZ
value_node)
r=rFrG�valuerHr6rZrr�r�r7r7r8�
declare_const�szScope.declare_constrc
	CsJ|s|}|j||||||dd�}
d|
_||
_|r<|j�|
�|	sF|
|_|
S)NT)rgr)r�rgrr�r�r�)r=rFrGrHr6rZr�definingr��templater�r7r7r8�declare_type�szScope.declare_typec
Cs�|s*|js|dks|r|}n|�tj|�}y6|jrD|j�|j�j}nd}t	�
||||dk|�}Wn8tk
r�}	zt||	j
d�t	j}Wdd}	~	XYnX|j||||||d�}
|
j|_|
S)NrErr)rZr)rxr�r	�type_prefixr�r��lookuprFrGr
Zcreate_typedef_type�
ValueErrorrr��
error_typer�r�)r=rF�	base_typerHr6rZr�	namespacerGr�r�r7r7r8�declare_typedefs$


zScope.declare_typedefFc
	Cs|s*|js|dks|r|}n|�tj|�}|�|�}
|
s|t�||||||	�}|j|||||||dk	d�}
|j�	|
�|
|_
n~|
jr�|
jj
r�|
jj|ks�t|d|d�nR|r�|
jjr�t|d|d�n4|�|
||�|�|
||�|r�||
j_|j�	|
�|j�r|j�|j�j|
j_|
S)Nr�)rZrr�z'%s' redeclared  rz2'%s' already defined  (ignoring second definition))rxr�r	r��lookup_herer
ZCStructOrUnionTyper�r�r�r�rgrGZis_struct_or_union�kindrr��check_previous_typedef_flag�check_previous_visibilityr�r�r�r�rFr�)r=rFr�r��typedef_flagrHr6rZrZpackedr�rGr7r7r8�declare_struct_or_union)s4
zScope.declare_struct_or_unionr7rc
s�|dkr*|js|dkr|}n|�tj|�}t|�}|�|�}|s|tj|||||d�}	|j||	�|||dk	d�}|j	�
|�n�|jr�|jj
s�t�d|�|��dS|r�|jjr�t�d|d�n|r�||j_|j�
|�|�r|jj�r|jj|k�rt�d�|��n||j_|�s$|jj�rD||jjk�rDt�d�|����fd	d
��|�r~�||�|jddt�|j�|jd�|j�r�|j�|j�j|j_|S)
NrE)�	templates)rZr�z'%s' redeclared z2'%s' already defined  (ignoring second definition)rz-Base type does not match previous declarationz5Template parameters do not match previous declarationcsNxH|D]@}|tjkrq|jdkr,t�d�q�||j�|jj�|�qWdS)Nz#Cannot inherit from incomplete type)r
r�r�r�base_classesrG� declare_inherited_cpp_attributes)r�r��
base_class)�declare_inherited_attributesrHr7r8r�rs


z=Scope.declare_cpp_class.<locals>.declare_inherited_attributes�this)rFr6rGrH)rxr�r	r��listr�r
ZCppClassTyper�r�r�rgrGrirrPr�rr�r�r��declare_var�CPtrTyperHr�r�r�rFr�)
r=rFr�rHr6r�rZr�r�rGr7)r�rHr8�declare_cpp_classLsJ



	
zScope.declare_cpp_classcCs,||jjkr(t|d|jd|jjf�dS)Nz#'%s' previously declared using '%s')�cdefZctypedef)rGr�rrF)r=r�r�rHr7r7r8r��sz!Scope.check_previous_typedef_flagcCs$|j|kr t|d|j|jf�dS)Nz '%s' previously declared as '%s')rZrrF)r=r�rZrHr7r7r8r��s
zScope.check_previous_visibilitycCs�|rd|s6|js"|dks"|dks"|r(|}n|�tj|�}|jrN|j�|j�j}nd}t	�
||||�}	nt	j}	|j||	||||d�}
||
_
g|
_|j�|
�|
S)Nr�r)r6rZr)rxr�r	r�r�r�r�rFrGr
Z	CEnumTypeZc_anon_enum_typer�r�Zenum_valuesr�r�)r=rFrHr6r�rZrr�r�rGr�r7r7r8�declare_enum�s"
zScope.declare_enumcCs|j�||�S)N)r��declare_tuple_type)r=rH�
componentsr7r7r8r��szScope.declare_tuple_typec	
Cs�|s$|dks|r|}n|�tj|�}|jr<|dkr<|�|�|�|||||�}	d|	_|rl|dkrld|	_d|	_|r|d|	_	d|	_|	S)NrErr)
r�r	�
var_prefixri�check_nullary_constructorr�r`r}r{r)
r=rFrGrHr6rZr�in_pxd�is_cdefr�r7r7r8r��s
zScope.declare_varcCs|j�||�S)N)r��declare_builtin)r=rFrHr7r7r8r��szScope.declare_builtincCsN|r&|jjs&t|d|�t|jd�|j|t||d�}t|_|j�	|�|S)Nz'%s' already declaredzPrevious declaration is here)rZ)
rGrarrHr�rr
�	signaturer�r�)r=rFrHrZr�r7r7r8�_declare_pyfunction�szScope._declare_pyfunctioncCs�|�|�}|s |j||||d�S|rR|jjr4t|_qd|jtk	rd|j||||d�Sn|j|t||d�|jdt||dd�}t|�|_|�|�|_	t
|_d|_|S)N)rZr�)rZrE)r6rZT)
r�r�rGZis_unspecifiedrr�rrFr�r�r
r�rf)r=rFrH�allow_redefinerZr�r7r7r8�declare_pyfunction�s 




zScope.declare_pyfunctioncCsh|�tjd|�}|�tjd|�}|�|�}|�d|t|d�}||_||_||_||_	t
|_d|_|S)NZfuncdef_Zmethdef_rET)
r�r	Zlambda_func_prefixr�r�rrFr��pymethdef_cnamersr
r�rf)r=Zlambda_namerHrsr�r�r�r7r7r8�declare_lambda_function�s
zScope.declare_lambda_functioncCs|j�|�dS)N)r�r�)r=�def_noder7r7r8�add_lambda_def�szScope.add_lambda_defcCs|j�|�dS)N)r�r�)r=r�r7r7r8�register_pyfunction�szScope.register_pyfunctioncCsp|s$|dks|r|}n|�tj|�}|�|�}|�r�|s`||jkr`|dkr`d}|j}||_||_|dkr�||jkr�t|d||j|fd�||jkr�t|d||r�dndfd�|j	�
|�r�|j	�|j�|_	n�|dk�rh|jdk�rhd	}
|�
�r�d}
n4|�r*x,|��D]}|j�r||jk�rP�qWd}
|
�rT|�||||||	�}|��|_|}nt|d
d�||_	n.|�s�|j�r�|�|j	��r�||_	n
t|d
�n |�||||||	�}||_||_|�r�|dk�r�d|_|�r�d|_|�s�|�s�|dk�r�t|d|�|�r
d|_|	�r|	|_|
�r:|j�r4td||f��|
|_|�rft||t�}d|_d|_|j|_||_||_|S)
NrErTz6Function '%s' previously declared as '%s', now as '%s'rz)Function '%s' previously declared as '%s'Zcpdefr�Fz6Function signature does not match previous declarationz3Non-extern C function '%s' declared but not definedz2duplicate utility code definition in entry %s (%s)) r�r	�func_prefixr�rZr6rsrr�rG�same_as�
with_with_gil�with_gilr�rR�
add_cfunctionrJr}�compatible_signature_withrrr~rtr��AssertionErrorrCrr`r]r�rwr�)r=rFrGrHr6rZrr�r��	modifiersr��overridabler�Zcan_overrider��temp�	var_entryr7r7r8�declare_cfunction�sx


zScope.declare_cfunctioncCs�|�|||||�}d|_|r"||_|s,|jr:|j�|�nDt|j�}	x*t|j�D]}
|
jsb|
j	jsdP|	d8}	qPW|j�
|	|�|S)Nr)r�rart�is_fusedr�r�r��reversedrzrG�insert)r=rFrGrHr6rZr�	inheritedr��iZcfunc_entryr7r7r8r?s

zScope.add_cfunctioncCs$|�|�}|r|St|d|�dS)Nz'%s' is not declared)r�r)r=rFrHr�r7r7r8�findRs
z
Scope.findcCsP|}xF|D]>}|�||�}|s"dS|jr0|j}q
t|dd�|��dSq
W|S)Nz'%s' is not a cimported moduler�)rryr�join)r=�pathrHr�rFr�r7r7r8�find_imported_moduleZs
zScope.find_imported_modulecCs |�|�p|jr|j�|�pdS)N)r�r�r�)r=rFr7r7r8r�is
zScope.lookupcCs|j�|d�S)N)r��get)r=rFr7r7r8r�pszScope.lookup_herecCs |�|�}|s|�|td�}|S)N)r�r�r)r=rFr�r7r7r8�
lookup_targetts
zScope.lookup_targetcCs:|�|�}|r6|jr6|jjr0|jr0|j�|j�S|jSdS)N)r�rgrGr
�fused_to_specific�
specialize)r=rFr�r7r7r8�lookup_type|s


zScope.lookup_typecCs�|djjrr|dj}|j�d|�}|dk	rrdd�|dd�D�}t�dd�|dd�D�|���}|dk	rr|S|�d|�}|dkr�dSt�dd�|D�|���S)Nrz
operator%scSsg|]
}|j�qSr7)rG)r��argr7r7r8�
<listcomp>�sz)Scope.lookup_operator.<locals>.<listcomp>rcSsg|]
}|j�qSr7)rG)r�rr7r7r8r�scSsg|]
}|j�qSr7)rG)r�rr7r7r8r�s)rGrir�r�r
�
best_matchrR)r=r��operandsZobj_type�method�	arg_types�res�functionr7r7r8�lookup_operator�s

zScope.lookup_operatorcs<ddlm}Gdd�d|����fdd�|D�}|�||�S)Nr)�Nodec@seZdZdS)z4Scope.lookup_operator_for_types.<locals>.FakeOperandN)r@rArBr7r7r7r8�FakeOperand�sr"csg|]}��|d��qS))rGr7)r�rG)r"rHr7r8r�sz3Scope.lookup_operator_for_types.<locals>.<listcomp>)ZNodesr!r )r=rHr��typesr!rr7)r"rHr8�lookup_operator_for_types�szScope.lookup_operator_for_typescCs|���|�dS)N)r��use_utility_code)r=�new_coder7r7r8r%�szScope.use_utility_codecCs|���|�dS)N)r��use_entry_utility_code)r=r�r7r7r8r'�szScope.use_entry_utility_codecCs x|D]}||jkrdSqWdS)Nrr)r�)r=r�rFr7r7r8�defines_any�s

zScope.defines_anycCs,x&|D]}||jkr|j|jrdSqWdS)Nrr)r�r|)r=r�rFr7r7r8�defines_any_special�s
zScope.defines_any_specialcCsddlm}|��|�dS)Nr)�get_type_inferer)�
TypeInferencer*�infer_types)r=r*r7r7r8r,�szScope.infer_typescCs|j}|dkrdS|��SdS)NF)r�r�)r=Zouterr7r7r8r��szScope.is_cppcCs|j�|�dS)N)r��add_include_file)r=�filenamer7r7r8r-�szScope.add_include_file)TN)N)N)rrr)NrErr)NrErrrr)NrEr)NrErF)Nr7rN)rErr)NrErrr)rN)Fr)NrErrrr7NF)F)Ar@rArB�is_builtin_scope�is_py_class_scope�is_c_class_scope�is_closure_scope�is_genexpr_scope�is_passthroughr��is_property_scope�is_module_scopeZis_internalr�rx�nogilr�return_typer>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	rrrr�r�rrr r$r%r'r(r)r,r�r-r7r7r7r8r�s�#



:




!
4


	

M
r�c@s"eZdZejZdd�Zdd�ZdS)�PreImportScopecCst�|tjdd�dS)N)r�r>r�
pre_import)r=r7r7r8r>�szPreImportScope.__init__cCs"|�||t|d�}d|_d|_|S)NrET)r�rr`r])r=rFrHr�r7r7r8r��szPreImportScope.declare_builtinN)r@rArBr	Zpreimport_cname�namespace_cnamer>r�r7r7r7r8r9�sr9c@s�eZdZdZdd�Zd#dd�Zdd�Zd$d	d
�Zd%dd�Zd
d�Z	de
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gd e
gd!e
gd"�ZdS)&�BuiltinScopeTcCsltjdkrt�|ddd�nt�|dt�d�i|_x2t|j���D] \}}|\}}|�	||d|�qDWdS)N�__builtin__)
rr:r�r>r9�
type_namesr��builtin_entriesr�r�)r=rFZ
definitionr6rGr7r7r8r>�s
zBuiltinScope.__init__NcCs |dkr|dkrd}t�||�S)N��str�unicode)r�r�)r=rF�language_levelr7r7r8r��szBuiltinScope.lookupcCsLtt|�sH|jdk	r"|j�||�Stjr8t|d|�nt|d|d�dS)Nzundeclared name not builtin: %sr/)�hasattr�builtinsr�r�r�error_on_unknown_namesrr)r=rFrHr7r7r8r��s

zBuiltinScope.declare_builtincCsht|�}|j||d|d|d�}|rd|dkr0|}nt|�}t||t�}d|_d|_||_|j|_||_|S)Nr)rZr��*r)	rr	rCrr`r[r�r�rw)r=rFrGr6Zpython_equivr�r�rr7r7r8�declare_builtin_cfunction�sz&BuiltinScope.declare_builtin_cfunctionc	Cs�t|�}t�|||�}t|ddd�}i|_|dkr8d|_|�|�d|j|<|j||ddd�}||_	t
|j|�d�j
|j|j
jd�}d|_d|_d|_d|_||_	||_tjr�d|_||_|S)	Nr)r�rZ�boolTr)rZrG)rFrGrHr6)rr
ZBuiltinObjectType�CClassScope�
directives�
is_final_type�	set_scoper>r�r�rCrFr�rGrH�
typeptr_cnamer`r\rrr[r�r�cache_builtinsrjrw)	r=rFr6r��objstruct_cnamerGr�r�rr7r7r8�declare_builtin_type�s0


z!BuiltinScope.declare_builtin_typecCs|S)Nr7)r=r7r7r8r�szBuiltinScope.builtin_scopez((PyObject*)&PyType_Type)z((PyObject*)&PyBool_Type)z((PyObject*)&PyInt_Type)z((PyObject*)&PyLong_Type)z((PyObject*)&PyFloat_Type)z((PyObject*)&PyComplex_Type)z((PyObject*)&PyBytes_Type)z((PyObject*)&PyByteArray_Type)z((PyObject*)&PyString_Type)z((PyObject*)&PyUnicode_Type)z((PyObject*)&PyTuple_Type)z((PyObject*)&PyList_Type)z((PyObject*)&PyDict_Type)z((PyObject*)&PySet_Type)z((PyObject*)&PyFrozenSet_Type)z((PyObject*)&PySlice_Type)ZPy_NoneZPy_FalseZPy_True)rGrIr r!r�complex�bytes�	bytearrayrArB�tupler��dictr��	frozenset�slice�None�False�True)N)NN)NN)r@rArBr/r>r�r�rHrQr�rr?r7r7r7r8r<�s4



r<c@seZdZdZdZdZdZdd�Zdd�Zdd�Z	d@d
d�Z
dd
�Zdd�ZdAdd�Z
dd�Zdd�ZdBdd�Zdd�Zdd�Zdd�Zd d!�ZdCd#d$�ZdDd&d'�Zd(d)�Zd*d+�Zd,d-�ZdEd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d	S)F�ModuleScoperrcCsddlm}||_|j}t�||||�|dkr@|j|_d|_n||_d|_t|j�|_||_	t
j|_t
j|_
t
j|_d|_t
j|_g|_i|_i|_t|j�|_d|_g|_t�|_g|_d|_g|_g|_|j|_ i|_!xdD]}|�"t|�t#d�q�W|�$t%j&d	dd
��dS)Nr)�Builtinr>TFrDr)	�__builtins__r@�__file__r��__path__�__spec__�
__loader__�__package__�
__cached__zPython.h)�initial)'rDr]�
parent_moduler�r�r>�module_name�
is_packager�contextr	Zmodule_cnameZ
moddict_cnameZmodule_dict_cnameZmethtable_cname�method_table_cnamervZmoddoc_cnamerl�utility_code_list�module_entries�
c_includesrVr>Zpxd_file_loaded�cimported_modulesr�Ztypes_importedZincluded_filesZhas_extern_class�cached_builtins�undeclared_cached_builtinsr;�_cached_tuple_typesr�r�process_includer�IncludeCode)r=rFrfrir]r��var_namer7r7r8r>[s@
zModuleScope.__init__cCs|jS)N)rf)r=r7r7r8r��szModuleScope.qualifying_scopecCs|S)Nr7)r=r7r7r8r��szModuleScope.global_scopeNcCsD|�|�}|dk	r|S|dkr4|jdk	r0|jjnd}|jj||d�S)Nr@)rC)r�rirCr�r�)r=rFrCr�r7r7r8r��s
zModuleScope.lookupc
Cs�t|�}y|j|}Wn(tk
r>t�|�}|j|<YnX|j}|�|�}|s�t|�}x(t|�D]\}}|j	d|||d�qfW|j
|dd|d||d�}	|j�|	�|	|_
|�||||�}||_|S)Nzf%s)rFrGrH�_structr(T)r�rHr6)rUrqr�r
Zc_tuple_typer6r��StructOrUnionScope�	enumerater�r�r��remove�struct_entryr�r�)
r=rHr�Zttyper6r�r��ixZ	componentryr7r7r8r��s$
zModuleScope.declare_tuple_typecCs$tt|�sx|tjkrx|tjkrx|jr6|�|t|�}|Stj	rLt
|d|�nt|d|d�|�|dt|d�}d|_
|Stjr�x|jD]}|j|kr�|Sq�W|dkr�|js�|j�d�S|�ddt|d�}tj�r|tjk�rd|_
d|_||_tj||_|j�|�|j�|�nd|_
||_|S)Nzundeclared name not builtin: %sr/rEr�globalsZ
__Pyx_Globals)rDrErZnon_portable_builtins_mapZuncachable_builtins�has_import_starr�rrrFrrr�r[rOrorF�old_style_globalsr�r�rjr	Zbuiltin_prefixr6r�rp)r=rFrHr�r7r7r8r��s:



zModuleScope.declare_builtinr�cCsld}d}|dk	r>|dkr>|}x2|dkr:|r:|j}|d8}qWn|dkrP|j}d}|��}|jj||||d�S)NFrrT)�relative_torH�absolute_fallback)rfr�ri�find_module)r=rgrHZrelative_levelr~rZmodule_scoper7r7r8r��szModuleScope.find_modulecCsXd|kr|�dd�\}}nd}|�|�}|sFt|||jd�}||j|<|rT|�|�}|S)Nr�r)rfri)�split�lookup_submoduler\rirl�find_submodule)r=rF�	submoduler�r7r7r8r��s


zModuleScope.find_submodulecCsFd|kr|�dd�\}}nd}|j�|d�}|rB|dk	rB|�|�}|S)Nr�r)r�rlrr�)r=rFr��moduler7r7r8r��s
zModuleScope.lookup_submoduleFcCstj|||d�}|�|�dS)z�
        Add `filename` as include file. Add `verbatim_include` as
        verbatim text in the C file.
        Both `filename` and `verbatim_include` can be `None` or empty.
        )�lateN)rrsrr)r=r.Zverbatim_includer��incr7r7r8r-�szModuleScope.add_include_filecCs4|��}|dkr|��}|�|j|�|j|}dS)a�
        Add `inc`, which is an instance of `IncludeCode`, to this
        `ModuleScope`. This either adds a new element to the
        `c_includes` dict or it updates an existing entry.

        In detail: the values of the dict `self.c_includes` are
        instances of `IncludeCode` containing the code to be put in the
        generated C file. The keys of the dict are needed to ensure
        uniqueness in two ways: if an include file is specified in
        multiple "cdef extern" blocks, only one `#include` statement is
        generated. Second, the same include might occur multiple times
        if we find it through multiple "cimport" paths. So we use the
        generated code (of the form `#include "header.h"`) as dict key.

        If verbatim code does not belong to any include file (i.e. it
        was put in a `cdef extern from *` block), then we use a unique
        dict key: namely, the `sortkey()`.

        One `IncludeCode` object can contain multiple pieces of C code:
        one optional "main piece" for the include file and several other
        pieces for the verbatim code. The `IncludeCode.dict_update`
        method merges the pieces of two different `IncludeCode` objects
        if needed.
        N)Z	mainpieceZsortkeyZdict_updaterm)r=r�r�r7r7r8rrs
zModuleScope.process_includecCsR||jkrNx|j��D]}|�|�qW|j�|�x|jD]}|�|�q<WdS)N)rnrm�valuesrrr��add_imported_module)r=r�r��mr7r7r8r�"s
zModuleScope.add_imported_modulecCs6|jrd|_||jkr"||j|<nt|d|d�dS)NTz'%s' redeclared  r)r]r`r�r)r=rFr�rHr7r7r8�add_imported_entry*s

zModuleScope.add_imported_entrycCs\|�|�}|r4|jr"|j|kr"|S|jr.|jrH|Sn|�|t|�}d|_||_|�|�|S)Nr)r�r]ryr�rr`r�)r=rFr�rHr�r7r7r8�declare_module3s

zModuleScope.declare_modulerEc	CsR|dkrt|d|�|s:|tkr&t}|jr2|jr:td��|sl|}	|dksX|dkr^|	r^|}n|�tj|�}|�	|�}
|
r�|
j
r�|
j�|�s�|dkr�|
j
dkr�t|d|d�||
_|
j
dkr�|�tj|�}|
j|kr�|}||
_|
js�d	|
_|
Stj|||||||||d
�	}
|�r:d|
_|
jj�r,|
jj|
_|j�|
�nd|
_tj�rNd|
_|
S)N)rEr�rz+Module-level variable cannot be declared %sz7Non-cdef global variable is not a generic Python objectrr�z6Variable '%s' type does not match previous declarationrrET)r6rZrr�r�)rrr�is_pyobject�is_extension_typerr�r	r�r�r}rGr�rZrr6r~r�r�r\�declaration_valuerIr�r�r]rZcimport_from_pyxr{)r=rFrGrHr6rZrr�r�r�r��
mangled_cnamer7r7r8r�LsN





zModuleScope.declare_varr7cCs�|sd|	krt|dd�|sD|dks0|dkr6|r6|}n|�tj|�}|dkr\|jr\t|d�|�|�}|r�|jr�|jdkr�|�tj	|�}
|j
|
kr�|}||_
||_tj
||||||||||	|
|d�}|S)	Nr.z+Declarations should not be declared inline.rrr�z6Extern functions cannot have default arguments values.rE)r6rZrr�r�rr�r)rr�r	r�Zoptional_arg_countrr�r}rZr�r6rsr�r	)r=rFrGrHr6rZrr�r�rr�rr�r�r7r7r8r	�s,




zModuleScope.declare_cfunctioncCs |�|�}|s|�|t|�dS)N)r�r�r)r=rFrHr�r7r7r8�declare_global�s
zModuleScope.declare_globalcCs|dk	r|j�|�dS)N)rkr�)r=r&r7r7r8r%�szModuleScope.use_utility_codecCs8|dkrdS|jr |j�|j�|jr4|j�|j�dS)N)r�rkr�r�)r=r�r7r7r8r'�sz"ModuleScope.use_entry_utility_codecCs�|r.|
dkr.|
dks$|s$t|dd�|}d}nd}|�|�}|r�|s�|j}|jrV|js\d}n^|j}|r~|rp|jr~|�|||�|r�|js�|r�|jr�|r�||jk	r�t	|d�|r�|js�||_|r�|�r�t
�||||
dk�}||_|
|_
|dk	r�||_|
dk�r||_n|j|_|	�r|	|_n|�tj|�|_|j||||
d|d�}d|_|�rT||_n&|j�sn|�tj|�|_nt	|jd	�|�|�|j�|�|j�s�|�s�|�r.t|||
d
�}|j��|_|�r�|j�r�|� |j�|�!|�|j"�|�n>|�r|jj�rt	|d|�n|�r.|jj#�r.t	|d|�|�r:d
|_$|�rF||_|
dk�rp|j%|
k�rpt	|d||j%f�|�r|d
|_&|�r�|j�r�|j|k�r�t	|d�||_|�r�|j'�r�|j'|k�r�t	|d�||_'|j�(d��r�d|j_)d|_*|S)Nrr�z6ctypedef only valid for 'extern' , 'public', and 'api'r/rz-Base type does not match previous declaration)rZr�r�Tz5Object name required for 'public' or 'extern' C class)rFr�rZzC class '%s' already definedz C class '%s' already implementedrrEz&Class '%s' previously declared as '%s'z4Object struct name differs from previous declarationz2Type object name differs from previous declaration�final)+rr�rGrgr�r��definedr�r�rr
ZPyExtensionTyperH�buffer_defaults�objtypedef_cnamergr�rNr�r	Ztypeptr_prefixr�rhrPrxZobjstruct_prefix�attach_var_entry_to_c_classr�r�rJrK�copy�declare_inherited_c_attributesrMr��implementedr}rZr�
typeobj_cnamerrLr{)r=rFrHr�Zimplementingrgr�rPr�rNrZr�rr�r�r�r�rGr�r7r7r8�declare_c_class�s�









zModuleScope.declare_c_classcCs�|j}|jr*|jjr*dtj|jjf|_nZ|jr�|jjr�t|jj�}|j}x0|rz|jrf|t|jj�krhP|jrrdS|j}qLWtj|_|jr�|�	tj
|j�|_|�	tj
|j�|_dS)Nz%s.%s)rGr��vtabslot_cnamer	�obj_base_cnamer�r�r��is_builtin_typer�Zvtabstruct_prefixrFZvtabstruct_cnameZvtabptr_prefixZ
vtabptr_cname)r=r�rGZentry_countr�r7r7r8�allocate_vtable_names s"
z!ModuleScope.allocate_vtable_namescCs.x(|jD]}|jjst|jd|j�qWdS)Nz(C class '%s' is declared but not defined)r�rGr�rrHrF)r=r�r7r7r8�check_c_classes_pxd=szModuleScope.check_c_classes_pxdcCs�|j}|j}|j}|js(t|jd|�|dkrF|jsF|�tj	|�|_|jr|x.|jj
D]"}|jsV|jsVt|jd|j�qVW|j
r�|�tj|j�|_dS)Nz(C class '%s' is declared but not definedrz)C method '%s' is declared but not defined)rGrFrZr�rrHr�r�r	Ztypeobj_prefixr�rzrsr�Z
vtable_prefixZvtable_cname)r=r�rGrFrZZmethod_entryr7r7r8�
check_c_classMszModuleScope.check_c_classcCsbd}|rtd|j�xF|jD]<}|rPtd|j|f�td|j�td|j�|�|�qWdS)Nrz&Scope.check_c_classes: checking scope z...entry %s %sz
......type = z......visibility = )�printr�r�rFrGrZr�)r=Zdebug_check_c_classesr�r7r7r8�check_c_classesdszModuleScope.check_c_classescCsXxR|j��D]D\}}|jr|jr|j|kr|jdkr|js|jst|j	d|�qWdS)Nrz3Non-extern C function '%s' declared but not defined)
r�r�rar}r�rZrxr~rrH)r=rFr�r7r7r8�check_c_functions|s

zModuleScope.check_c_functionscCsJddlm}t|j|j|j|jjd�}d|_d|_	d|_
|j|_||_dS)Nr)r])rFrGrHr6)
rDr]rCrFZ	type_typerHrGrNr`r\rrr�rw)r=r�r]rr7r7r8r��sz'ModuleScope.attach_var_entry_to_c_classcCs|jS)N)�cpp)r=r7r7r8r��szModuleScope.is_cppcCsddlm}|��|�dS)Nr)�PyObjectTypeInferer)r+r�r,)r=r�r7r7r8r,�szModuleScope.infer_types)N)r�)NF)NrErrr)NrErrrr7NF)rrNNNNNrErrNr)#r@rArBr6r|Zis_cython_builtinr}r>r�r�r�r�r�r�r�r�r-rrr�r�r�r�r	r�r%r'r�r�r�r�r�r�r�r�r,r7r7r7r8r\=sJ&

$

		
7

kr\c@sXeZdZdZdZddd�Zdd�Zdd�Zddd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)r�FNcCs |dkr|}t�||||�dS)N)r�r>)r=rFr�r�r7r7r8r>�szLocalScope.__init__cCs||S)Nr7)r=r�rFr7r7r8r��szLocalScope.manglecCsH|�tj|�}|�||||d�}d|_|jr2d|_d|_|j�	|�|S)NrEr�0)
r�r	r�r�r`r�rIrmr�r�)r=rFrGrHr6r�r7r7r8�declare_arg�szLocalScope.declare_argrErc	
Csb|dkrt|d|�tj|||||||||d�	}	|	jjrD|	jj|	_d|	_|j|	_|j	�
|	�|	S)N)r��readonlyz$Local variable cannot be declared %s)r6rZrr�r�r)rr�r�rGr�rIrn�_in_with_gil_blockr�r�r�)
r=rFrGrHr6rZrr�r�r�r7r7r8r��s
zLocalScope.declare_varcCs4|�|�rt|dd�n|���|�}||j|<dS)Nz'%s' redeclared  r)r�rr�rr�)r=rFrHr�r7r7r8r��s
zLocalScope.declare_globalcCs`|�|�}|r6|j|kr6|js6t|d|�|��n&|�|�}|dksN|js\t|d|�dS)Nz'%s' redeclared as nonlocalz"no binding for nonlocal '%s' found)r�r�rprrPr�)r=rFrH�
orig_entryr�r7r7r8�declare_nonlocal�s


zLocalScope.declare_nonlocalcCsvt�||�}|dk	rr|j}x|jr*|j}qW||k	rr|jrrt|jd�rNtd��d|_t	||�}d|_
||j|<|S|S)NZscope_classz#lookup() after scope class created.T)r�r�r�r3r�r2rDrror�r`r�)r=rFr�Zentry_scopeZinner_entryr7r7r8r��s


zLocalScope.lookupcCs�x�|��D]�}x�|j��D]r}|jrl|jj}|jr:||_q�|�tj	�r\|t
tj	�dd�}d||f|_q|jr|j|_dtj	|jf|_qWq
WdS)Nr/z%s->%s)
r�r�r�rpr�r6r4r3r	Zcur_scope_cnamer�roZoriginal_cname)r=Zouter_scope_cnamer�r�r6r7r7r8�mangle_closure_cnames�sz LocalScope.mangle_closure_cnames)N)NrErrr)
r@rArBZhas_with_gil_blockr�r>r�r�r�r�r�r�r�r7r7r7r8r��s


r�c@sHeZdZdZdZdd�Zdd�Zdd
d�Zdd
d�Zdd�Z	dd�Z
dS)�GeneratorExpressionScopez�Scope for generator expressions and comprehensions.  As opposed
    to generators, these can be easily inlined in some cases, so all
    we really need is a scope that holds the loop variable(s).
    TcCs�|}x|jr|j}qW|���tj�}t�||||�|j|_dtj	t
|�|f|_x|jsh|jsh|j
rp|j}qVW|j|_|j�|�dS)Nz%s%d%s)r3r�r�r�r	Zgenexpr_id_refr�r>rKr4r��
genexp_prefixr1r0r�r�r��add)r=r�r�rFr7r7r8r>
s

z!GeneratorExpressionScope.__init__cCsd|j|j�||�fS)Nz%s%s)r�r�r�)r=r�rFr7r7r8r�szGeneratorExpressionScope.mangleNrErc	Cs�|tkr$|j�|�}	|	r$|	jr$|	j}d|j|j�tj	|p>|�
��f}|�|||||�}
d|
_|jjrnd|
_
nd|
_d|
_|j�|
�|
|j|<|
S)Nz%s%sT)rr�r�r`rGr�r�r�r	r�r�r�r6r\rnrqr�r�r�)r=rFrGrHr6rZrr�r�r�r�r7r7r8r�!s
"
z$GeneratorExpressionScope.declare_varFcCs|j�|||�S)N)r�r�)r=rFrHr�r7r7r8r�7sz+GeneratorExpressionScope.declare_pyfunctioncCs|j�||�S)N)r�r�)r=rsrHr7r7r8r�;sz0GeneratorExpressionScope.declare_lambda_functioncCs|j�|�S)N)r�r�)r=r�r7r7r8r�>sz'GeneratorExpressionScope.add_lambda_def)NrErrT)F)r@rArBr�r3r>r�r�r�r�r�r7r7r7r8r�s

r�c@s$eZdZdZddd�Zd	dd�ZdS)
�ClosureScopeTNcCs$t�||||�dtj|f|_dS)Nz%s%s)r�r>r	Zclosure_scope_prefixZ
closure_cname)r=rFZ
scope_namer�r�r7r7r8r>FszClosureScope.__init__FcCstj||||dd�S)NrE)rZ)r�r�)r=rFrHr�r7r7r8r�SszClosureScope.declare_pyfunction)N)F)r@rArBr2r>r�r7r7r7r8r�Bs

r�c@s*eZdZd
dd�Zddd	�Zddd�ZdS)rv�?cCst�||dd�dS)N)r�r>)r=rFr7r7r8r>ZszStructOrUnionScope.__init__NrErFcCs�|s|}|dkrt|�}|jr(t�|�}|�|||||�}d|_|j�|�|jrb|	sbt	|d�n|j
rv|
svt	|d�|dkr�t	|d|�|S)NrErz/C struct/union member cannot be a Python objectz-C struct/union member cannot be a memory viewz+C struct/union member cannot be declared %s)r9rar
r�r�r`r�r�r�rr�)r=rFrGrHr6rZrr�r�Zallow_pyobjectZallow_memoryviewr�r7r7r8r�]s 



zStructOrUnionScope.declare_varr7cCs"|
rt|d�|j|||||d�S)Nz0C struct/union member cannot be declared 'cpdef')r6rZ)rr�)r=rFrGrHr6rZrr�r�rrr7r7r8r	ts

z$StructOrUnionScope.declare_cfunction)r�)NrErrrFF)NrErrrr7F)r@rArBr>r�r	r7r7r7r8rvWs

rvc@seZdZdd�Zdd�ZdS)�
ClassScopecCs t�||||�||_d|_dS)N)r�r>�
class_namerv)r=rFr�r7r7r8r>�szClassScope.__init__cCsdt�||�}|r|S|dkr`tddt�tt�dtd�gdd��}tj�	dd�|_
|�|�d|_|S)N�classmethodZ__Pyx_Method_ClassMethodrDrZClassMethodzCythonFunction.cr)
r�r�rCr
Z	CFuncTyper�CFuncTypeArgr�UtilityCodeZload_cachedr�r'ra)r=rFr�r7r7r8r��s
zClassScope.lookupN)r@rArBr>r�r7r7r7r8r�}s	r�c@sJeZdZdZdd�Zdd�Zdd�Zddd�Zd
d�Zdd�Z	dd�Z
dS)�PyClassScopercCs
|�|�S)N)�mangle_special_name)r=rFr7r7r8r��sz&PyClassScope.mangle_class_private_namecCs4|r0|�d�r0|�d�s0td|j�d�|f�}|S)Nr0z_%s%s�_)r3�endswithrr��lstrip)r=rFr7r7r8r��sz PyClassScope.mangle_special_namecCs|�|�}t�||�S)N)r�r�r�)r=rFr7r7r8r��s
zPyClassScope.lookup_hereNrErc	
CsB|�|�}|tkrt}tj|||||||||d�	}	d|	_d|	_|	S)N)r6rZrr�r�r)r�rrr�r�r]r_)
r=rFrGrHr6rZrr�r�r�r7r7r8r��s
zPyClassScope.declare_varcCsf|�|�}|r6|j|kr6|js6t|d|�|��n,|�|�}|dkrXt|d|�n
||j|<dS)Nz'%s' redeclared as nonlocalz"no binding for nonlocal '%s' found)r�r�rprrPr�r�)r=rFrHr�r�r7r7r8r��s


zPyClassScope.declare_nonlocalcCs4|�|�rt|dd�n|���|�}||j|<dS)Nz'%s' redeclared  r)r�rr�rr�)r=rFrHr�r7r7r8r��s
zPyClassScope.declare_globalcCs|j�|�S)N)r��add_default_value)r=rGr7r7r8r��szPyClassScope.add_default_value)NrErrr)r@rArBr0r�r�r�r�r�r�r�r7r7r7r8r��s
r�c@s�eZdZdZdZdZdZdZdZdZ	dZ
dd�Zdd�Zdd�Z
d d
d�Zd!dd�Zd"dd�Zdd�Zd#dd�Zd$dd�Zd%dd�Zdd�Zdd�ZdS)&rJrFcCsFt�|||�|dkr6|�tj|�|_|�tj|�|_g|_g|_	dS)Nr)
r�r>r�r	Zmethtab_prefixrjZgstab_prefixZgetset_table_cname�property_entries�inherited_var_entries)r=rFr�rZr7r7r8r>�szCClassScope.__init__cCsN|jr|j�dd�sdS|jj}|r8|jdk	r8|j��S|jjrJ|jjSdS)N�no_gcFT)	�has_cyclic_pyobject_attrsrKr�parent_typer�r��needs_gcr��is_gc_simple)r=r�r7r7r8r��s

zCClassScope.needs_gccCs|��o|j�dd�S)z�
        Do we need to generate an implementation for the tp_clear slot? Can
        be disabled to keep references for the __dealloc__ cleanup function.
        �no_gc_clearF)r�rKr)r=r7r7r8�needs_tp_clearszCClassScope.needs_tp_clearTcCs�g}g}g}xl|jD]b}|jjrL|s4|js4|jdkrv|s@|jjsv|�|�q|jtjkrd|�|�q|jj	r|�|�qW|p�|p�|}||||ffS)Nr1)
r�rGr��is_closure_class_scoperFr�r�r
Zc_py_buffer_typer�)r=Zinclude_weakrefZinclude_gc_simpleZpy_attrsZ
py_buffersZmemoryview_slicesr�Zhave_entriesr7r7r8�get_refcounted_entriessz"CClassScope.get_refcounted_entriesNrErc	
Cs�|�rX|jrt|d�|js2t|�r2t|d|�|sJ|}|dkrJt|�}|jrr|dkrr|�|�|�t�	d��|�
|||||�}	d|	_|j�
|	�|jr�d|_nD|jr�d|_n6|jr�|js�|dkr�d|_|jr�|jr�|j��r�d|_|d	kr�t|d
|�|dk�rNd|	_|j�s*|dk�r*t|d�|j�sT|�|��sTt|d
|�nd|	_|	S|tk�rft}tj|||||||||d�	}	d|	_d|	_d|jj |_!|	SdS)NzVC attributes cannot be added in implementation part of extension type defined in a pxdz/The name '%s' is reserved for a special method.rErz#include <new>rTr1)rEr�r�z1Attribute of extension type cannot be declared %s)r�r�z9Special attribute __weakref__ cannot be exposed to Pythonz7C attribute of type '%s' cannot be accessed from PythonF)r6rZrr�r�z(PyObject *)%s)"r�rr�rr9rir�r%rr�r�r`r�r�r��has_memoryview_attrs�has_cpp_class_attrsr��has_pyobject_attrsr�r�r�r�r�Zcan_coerce_to_pyobjectrrr�r�r^r]r�rNr;)
r=rFrGrHr6rZrr�r�r�r7r7r8r�%s^




zCClassScope.declare_varcCs�|tkr"|�d�rPt|d|�n.|dkrPx$tD]}|�|�r0t|d|�q0W|dkrbt|d�|j|t|dd�}t|�}|r�||_d|_nt|_d|_|j	�
|�|S)	NZ__richcmp__z$Cannot define both % and __richcmp__�__new__zv__new__ method of extension type will change semantics in a future version of Pyrex and Cython. Use __cinit__ instead.r)rZrr)rr�rr�rrr�r|rr�r�)r=rFrHr��nr�Zspecial_sigr7r7r8r�cs&




zCClassScope.declare_pyfunctioncCsD|js|dkrtd�}t�||�}|r@|jr@|jjs@|jjs@dS|S)Nr�Z	__cinit__)r�rr�r�rcr�r�rL)r=rFr�r7r7r8r�~s
zCClassScope.lookup_herer7cCs(t|�r|jjst|d�|j}|jsd|s6t|d�n.|j�|dj�sdt|d|dj||jf�|�|�}
|dkr~t	|�}|
�r�|
j
s�t|d|d�n�|r�|
jr�t|d|�|
j
r�|
jr�t|d�n�|j|
jdd	�r�|j|
jjkr�|
j�|j�|
_n�|j|
jdd	��r||j|
jjk�r||j�rd|�sd|j|
jddd
��sdt|d||jfd�t|
jd
d�|j||||d|	d�}
nt|d�t|
jd
�n0|j�r�t|d||jf�|�||||||	�}
|�r�|�tj|�|
_|
|
_|
|_d|	k�r�d|
_|jj�s|
j�s|j �!d��r$d|
_
|
j|
_"|
S)Nz7Special methods must be declared with 'def', not 'cdef'zC method has no self argumentrzCSelf argument (%s) of C method '%s' does not match parent type (%s)z'%s' redeclared  z'%s' already definedz'Overriding final methods is not allowedr)�
as_cmethod)r�Zas_pxd_definitionz�Compatible but non-identical C method '%s' not redeclared in definition part of extension type '%s'.  This may cause incorrect vtables to be generated.r/zPrevious declaration is herer�)rZrz2Signature not compatible with previous declarationzOC method '%s' not previously declared in definition part of extension type '%s'r.Tr�)#rr�r�rr�Zis_static_methodZassignable_fromrGr�r9rarrsrdrzZsame_c_signature_asr7rrrr�Z!same_c_signature_as_resolved_typer�rHrr�r	r�r�r�rerLrKrru)r=rFrGrHr6rZrr�r�rr�rr�r�r7r7r8r	�s^


"

zCClassScope.declare_cfunctionc

Cs4|�|�}tj||||||||d�}	d|	_||	_|	S)N)r
r)r�r�rrbr�)
r=rFrGrHr6rZrr
r�r�r7r7r8r�s
zCClassScope.add_cfunctioncCsNt|�}|j||d|d|d�}t||t�}d|_d|_||_|j|_||_|S)Nr)rZr�r)	rr	rCrr`r[r�r�rw)r=rFrGr6r�r�rr7r7r8rH�sz%CClassScope.declare_builtin_cfunctioncCs^|�|�}|dkr$|�||t|d�}d|_||_t||��|d�|_|j|j_|j	�
|�|S)NrEr)r�r�)r�r�rrkrv�
PropertyScoper�r�r�r�r�)r=rFrvrHr�r7r7r8�declare_property�s

zCClassScope.declare_propertyc
s.�fdd�}|j|j}x:|D]2�|��j|�j��jdd�}d|_|j�|�qWx(|jdd�D]��jj	rd�j�
�qdWx�|jD]���j}�j}|o�|j}|s�||�}|j
�j�j�j|�j�jdd�}d|_�j�rd|_�j|_|j|jks�|j�r�j|_|�rd|_||_�jr��j|_q�WdS)Ncsdtj�jfS)Nz%s.%s)r	r�r6)r6)�
base_entryr7r8�adapt�sz9CClassScope.declare_inherited_c_attributes.<locals>.adaptrErT)r
)r�r�r�rFr6rGr`r�r�r
Z"get_all_specialized_function_typesrwr[rrHrZrtrzrdrer�rurcr�)r=�
base_scoper�r�r�r6rr[r7)r�r8r��s@

z*CClassScope.declare_inherited_c_attributes)FT)NrErrr)F)NrErrrr7NF)F)N)r@rArBr1r�r�r�r�r�r�r�r>r�r�r�r�r�r�r	rrHr�r�r7r7r7r8rJ�s.

<

:
	
rJc@sFeZdZdZdZdZddd�Zddd�Zddd�Zd
d�Z	dd�Z
dS)�
CppClassScoperNcCsVt�|||d�|j|_g|_|dk	rRx*|D]"}|�||t�|�dd�}d|_q,WdS)Nrr)r�r>rKr�r�r
ZTemplatePlaceholderTyperg)r=rFr�r��TZtemplate_entryr7r7r8r>!	s
zCppClassScope.__init__rrc
Cs�|s|}|�|�}
|	rb|
dk	rb|
j�|�r<|
j�|j�|
_qt|jrV|�|
j�rV||
_qtt|d�n|�|||||�}
d|
_	|jr�|jr�|j�
�s�d|j��|f|
_|dkr�|	s�|dkr�|j
�|
�|
S)Nz6Function signature does not match previous declarationrz%s::%sr�z<init>)r�rGr�rrrarrr�r`Zget_fused_typesZempty_declaration_codersr�r�)r=rFrGrHr6rZrr�r�r�r�r7r7r8r�+	s"

zCppClassScope.declare_varr7Fcs(|j�d�d}||dfkrh|dkrhdtj|f}d}t��|_|j|_dd���fdd	�|jD�|_n,|d
kr�|dkr�dtj|f}d}t��|_|d
kr�|j	r�x>|j
jD]2}
|
j�
|�}|r�|j
j	s�t|d�t|jd�q�W|�|�}|j||||||d�}|�r|�s|��|_|
|_||_|S)Nz::r�r>z%s__init__%sz<init>cSs2|jjr*|jjs*t�|jt�|j�|j�S|SdS)N)rGriZis_referencer
r�rFZ
c_ref_typerH)rr7r7r8�	maybe_refO	sz2CppClassScope.declare_cfunction.<locals>.maybe_refcsg|]}�|��qSr7r7)r�r)r�r7r8rU	sz3CppClassScope.declare_cfunction.<locals>.<listcomp>Z__dealloc__z%s__dealloc__%sz<del>)z<init>z<del>zdConstructor cannot be called without GIL unless all base constructors can also be called without GILzBase constructor defined here.)r�r6rZ)rFr�r	r�r
Z	CVoidTyper8r�Z
original_argsr7rGr�r�r�rrHr�r�rRrJr�r�)r=rFrGrHr6rZrr�r�rr�rr��baser�r�r�r7)r�r8r	D	s6






zCppClassScope.declare_cfunctioncCs&|j}|}xt|dd�r |j}qWt|dd�r@dd�|jD�}nd}xb|j|jD]R}|jdkrbqR|j|jkrt|j|�|j|j	|j
dd�}d|_d|_|j�
|�qRWx<|jD]2}|j|j|j
|j|j	|jd	|j|jd
�}d|_q�Wx:|jD]0}|j|kr�|�|j|j
|j|j	|j�}d|_q�WdS)N�
template_typer�cSsg|]
}|j�qSr7)rF)r�r�r7r7r8rp	szBCppClassScope.declare_inherited_cpp_attributes.<locals>.<listcomp>r7)z<init>z<del>rrr)rrr�)r�r�r�r�r�r�rFr�r�r6rGr`rzr�r�r	rHrZrtr�r�r�)r=r�r�r�Zbase_templatesr�r�r7r7r8r�j	s>




z.CppClassScope.declare_inherited_cpp_attributesc	Cs�t|j|j�}||_x�|j��D]�}|jrN|j|j|j�|�|j	|j
dd�q |jjr�xX|��D](}|j
|j|j�|�|j	|j
|jd�q`Wq |�|j|j�|�|j	|j
|j�q W|S)Nr)r�)r�)r�rFr�rGr�r�rgr�rrHr6rarRr	r�r�rZ)r=r�Z
type_entryr�r�r�r7r7r8r�	s,



zCppClassScope.specialize)N)Nrrrrr)Nrrrrr7NF)r@rArBr�Zdefault_constructorrGr>r�r	r�rr7r7r7r8r�	s


$'r�c@seZdZdZddd�ZdS)r�rFcCs@t|�}|r.|�||t|d�}d|_||_|St|d�dSdS)NrErzKOnly __get__, __set__ and __del__ methods allowed in a property declaration)rr�rr|r�r)r=rFrHr�r�r�r7r7r8r��	s
z PropertyScope.declare_pyfunctionN)F)r@rArBr5r�r7r7r7r8r��	sr�c@seZdZdd�Zdd�ZdS)�CConstScopecCs$t�|d|j|j|j�||_dS)NZconst_)r�r>rFr�r��const_base_type_scope)r=r�r7r7r8r>�	szCConstScope.__init__cCs4|j�|�}|dk	r0t�|�}t�|j�|_|SdS)N)r�r�r�r
Zc_const_typerG)r=rFr�r7r7r8r��	s

zCConstScope.lookup_hereN)r@rArBr>r�r7r7r7r8r��	sr�c@seZdZdd�ZdS)�
TemplateScopecCst�|||d�|j|_dS)N)r�r>rK)r=rFr�r7r7r8r>�	szTemplateScope.__init__N)r@rArBr>r7r7r7r8r��	sr�)2�
__future__rr�r�r�r=rE�ImportErrorZErrorsrrrZStringEncodingrrDrr	r
rrZ	TypeSlotsr
rrrrrr�r5r9�objectr:rCr�r�r9r<Z
const_counterr\r�r�r�rvr�r�rJr�r�r�r�r7r7r7r8�<module>sl	:#.pid<&#<?