B
    ž†\³ ã            %   @   sN  d dl mZ d dlZd dlZd dlZyd dlZW n ek
rL   d dlZY nX ddlm	Z	m
Z
mZ ddlmZ ddlmZmZ ddlmZ ddlmZmZ dd	lmZmZmZmZmZ dd
lmZ ddlmZ eddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/g$ƒZd0d1„ ZG d2d3„ d3eƒZ G d4d5„ d5eƒZ!G d6d7„ d7e!ƒZ"G d8d9„ d9eƒZ#G d:d;„ d;e#ƒZ$G d<d=„ d=e#ƒZ%dZ&G d>d?„ d?e#ƒZ'G d@dA„ dAe#ƒZ(G dBdC„ dCe#ƒZ)G dDdE„ dEe(ƒZ*G dFdG„ dGe#ƒZ+G dHdI„ dIe#ƒZ,G dJdK„ dKe,ƒZ-G dLdM„ dMe,ƒZ.G dNdO„ dOe#ƒZ/G dPdQ„ dQe#ƒZ0G dRdS„ dSe#ƒZ1G dTdU„ dUe#ƒZ2dS )Vé    )Ú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)ÚFuture)ÚCodeÚautoÚbreakZcaseÚcharZconstÚcontinueÚdefaultZdoZdoubleÚelseÚenumÚexternÚfloatÚforZgotoÚifÚintÚlongÚregisterÚreturnZshortÚsignedZsizeofZstaticÚstructZswitchZtypedefÚunionZunsignedZvoidZvolatileÚwhileZ_Boolz_Complex, _ImaginaryÚinlineZrestrictc             C   s:   | d d… dkr$|   tj¡s$| dkr,| tkr6tj|  } | S )Né   Ú__)Ú__weakref__Ú__dict__)Ú
startswithr	   Úpyrex_prefixÚiso_c99_keywords)Úcname© r0   ú5lib/python3.7/site-packages/Cython/Compiler/Symtab.pyÚc_safe_identifier%   s
    
r2   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	BufferAuxFc             C   s   || _ || _d S )N)Úbuflocal_nd_varÚ	rcbuf_var)Úselfr4   r5   r0   r0   r1   Ú__init__1   s    zBufferAux.__init__c             C   s
   d| j  S )Nz<BufferAux %r>)r+   )r6   r0   r0   r1   Ú__repr__5   s    zBufferAux.__repr__N)Ú__name__Ú
__module__Ú__qualname__Zwritable_neededr7   r8   r0   r0   r0   r1   r3   .   s   r3   c               @   sN  e 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dZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&g Z'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDddd„ZEd	d
„ ZFdd„ ZGdd„ ZHdd„ ZIdd„ ZJdd„ ZKdS )ÚEntryFr   Ú NÚprivateTc             C   s@   || _ || _|| _|| _|| _g | _g | _g | _g | _| | _	d S )N)
Únamer/   ÚtypeÚposÚinitÚoverloaded_alternativesÚcf_assignmentsÚcf_referencesÚinner_entriesÚdefining_entry)r6   r?   r/   r@   rA   rB   r0   r0   r1   r7   Ï   s    zEntry.__init__c             C   s   dt | ƒjt| ƒ| j| j f S )Nz%s(<%x>, name=%s, type=%s))r@   r9   Úidr?   )r6   r0   r0   r1   r8   Û   s    zEntry.__repr__c             C   s   t | jdƒ d S )NzPrevious declaration is here)r   rA   )r6   r0   r0   r1   Úalready_declared_hereÞ   s    zEntry.already_declared_herec             C   s   t |d| j ƒ |  ¡  d S )Nz('%s' does not match previous declaration)r   r?   rI   )r6   rA   r0   r0   r1   Ú
redeclaredá   s    zEntry.redeclaredc             C   s   | g| j  S )N)rC   )r6   r0   r0   r1   Úall_alternativeså   s    zEntry.all_alternativesc             C   s   | g| j  S )N)rF   )r6   r0   r0   r1   Úall_entriesè   s    zEntry.all_entriesc             C   s4   t | tƒr,t |tƒr,| j| jf|j|jfk S tS d S )N)Ú
isinstancer<   r?   r/   ÚNotImplemented)ÚleftÚrightr0   r0   r1   Ú__lt__ë   s    zEntry.__lt__)NN)Lr9   r:   r;   Zinline_func_in_pxdZborrowedrB   Z
annotationÚ
visibilityÚ
is_builtinÚ
is_cglobalÚis_pyglobalÚ	is_memberÚis_pyclass_attrÚis_variableÚis_cfunctionÚ
is_cmethodÚis_builtin_cmethodZis_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_cnameZis_self_argÚis_argÚis_localÚ
in_closureÚfrom_closureÚin_subscopeZis_declared_genericÚis_readonlyZpyfunc_cnameÚ
func_cnameÚfunc_modifiersÚfinal_func_cnameÚdocÚas_variableZxdecref_cleanupÚin_cincludeÚ	as_moduleÚis_inheritedZpystring_cnameZis_identifierZis_internedÚusedÚ
is_specialÚdefined_in_pxdÚis_implementedÚapiÚutility_codeÚis_overridableZ
buffer_auxÚ
prev_entryZmight_overflowZfused_cfunctionZis_fused_specializedÚutility_code_definitionÚneeds_propertyÚin_with_gil_blockZfrom_cython_utility_codeZerror_on_uninitializedZcf_usedÚouter_entryr7   r8   rI   rJ   rK   rL   rQ   r0   r0   r0   r1   r<   9   s’   S
r<   c               @   s,   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	S )
Ú
InnerEntryzK
    An entry in a closure scope that represents the real outer Entry.
    Tc             C   sr   t  | |j|j|j|j¡ || _|| _|}x|jr:|j}q,W || _|j	| _	|j
| _
|j| _|j| _| j	 | ¡ d S )N)r<   r7   r?   r/   r@   rA   r~   ÚscoperG   rF   rD   rE   rC   Úappend)r6   r~   r€   Zoutermost_entryr0   r0   r1   r7   ø   s    

zInnerEntry.__init__c             C   s   |  d¡rt|ƒ‚t| j|ƒS )Nr)   )r,   ÚAttributeErrorÚgetattrrG   )r6   r?   r0   r0   r1   Ú__getattr__  s    
zInnerEntry.__getattr__c             C   s
   | j  ¡ S )N)rG   rL   )r6   r0   r0   r1   rL     s    zInnerEntry.all_entriesN)r9   r:   r;   Ú__doc__rh   r7   r„   rL   r0   r0   r0   r1   r   ò   s
   r   c               @   sà  e 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d„ Zdd„ Zdhd	d
„Zdd„ Zdd„ Zdidd„Zdd„ Zdd„ Zdjdd„Zdd„ Zdd„ Zdd„ Zdkdd„Zdd „ Zdld"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?dwdfdg„Z@dS )xÚScoper   r=   Nc             C   sÞ   || _ || _|| _dt|ƒ| dd¡f }|  ¡ }|rP| |¡| _|j| | _nt	|ƒ| _|| _i | _
tƒ | _g | _g | _g | _g | _g | _g | _g | _g | _g | _i | _i | _i | _i | _i | _i | _g | _g | _i | _d S )Nz%d%s_Ú.Z_dot_)r?   Ú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_entriesZdefined_c_classesZimported_c_classesZcname_to_entryZstring_to_entryZidentifier_to_entryZnum_to_entryZobj_to_entryZbuffer_entriesÚlambda_defsÚid_counters)r6   r?   rˆ   r‰   Zmangled_nameZ
qual_scoper0   r0   r1   r7   C  s<    
zScope.__init__c             C   s   | S )Nr0   )r6   Úmemor0   r0   r1   Ú__deepcopy__f  s    zScope.__deepcopy__Tc       
      C   s¬   g }x:|j  ¡ D ],\}}|r$||kr|js.|r| ||f¡ qW | j  |¡ xZdD ]R}t| |ƒ}tdd„ |D ƒƒ}	x0t||ƒD ]"}|jsŒ|r~|j|	kr~| |¡ q~W qRW d S )N)r“   r”   r•   r–   r—   r˜   r™   rš   c             s   s   | ]}|j V  qd S )N)r?   )Ú.0Úer0   r0   r1   ú	<genexpr>|  s    z!Scope.merge_in.<locals>.<genexpr>)r   Úitemsrs   r   Úupdaterƒ   r‘   r?   )
r6   ÚotherZmerge_unusedZ	whitelistr   r?   ÚentryÚattrZself_entriesÚnamesr0   r0   r1   Úmerge_ini  s    


zScope.merge_inc             C   s   d| j j| jf S )Nz<%s %s>)Ú	__class__r9   rŽ   )r6   r0   r0   r1   Ú__str__  s    zScope.__str__c             C   s   | j S )N)r‰   )r6   r0   r0   r1   rŒ   „  s    zScope.qualifying_scopec             C   s(   |rd|| j |f S | j || j¡S d S )Nz%s%s%s)r   r‰   Úmangler?   )r6   Úprefixr?   r0   r0   r1   r«   ‡  s    zScope.manglec             C   s   dt j|f }|  |¡S )Nz%s%s_)r	   r-   r«   )r6   r?   r¬   r0   r0   r1   Úmangle_internal  s    zScope.mangle_internalc             C   s   | j r| j  |¡S |S )N)r‰   Úmangle_class_private_name)r6   r?   r0   r0   r1   r®   ”  s    zScope.mangle_class_private_namec             C   s`   |   ¡ j}y|| d }W n tk
r2   d}Y nX |||< |rT|sH|S d||f S d| S d S )Nr   r   z%s%dz%d)Úglobal_scoperœ   ÚKeyError)r6   r?   ZcountersÚcountr0   r0   r1   Únext_id™  s    

zScope.next_idc             C   s
   | j  ¡ S )z6 Return the module-level scope containing this scope. )rˆ   r¯   )r6   r0   r0   r1   r¯   ©  s    zScope.global_scopec             C   s
   | j  ¡ S )z6 Return the module-level scope containing this scope. )rˆ   Úbuiltin_scope)r6   r0   r0   r1   r³   ­  s    zScope.builtin_scopec             c   s4   | V  | j r0x"t| j t d¡dD ]
}|V  q"W d S )Nr   )Úkey)r’   ÚsortedÚoperatorÚ
attrgetter)r6   r€   r0   r0   r1   Úiter_local_scopes±  s    zScope.iter_local_scopesc	             C   s|  |j rt| tƒst|dƒ | js@|r@t d|¡r@t|d| dƒ | j}	|r||	kr|s|	| }
d}|j	r²|
j
j	r²|  ¡ r²x2|
 ¡ D ]"}||j
krˆ|dkr¨|js¨d}P qˆW d}|r¸nZ| jrÊ|	| jrÊnH|dkrît|d	| | jræd
ndƒ n$|dkrt|d	| ƒ |	|  ¡  t||||d}| j|_||_|rP|  |¡|_|sP||	|< |jrld
dlm} |j|_| |_||_|S )Nz5Buffer types only allowed as function local variablesz
^_[_A-Z]+$z'%s' is a reserved name in C.éÿÿÿÿFz<init>Tr   z'%s' redeclared r   r   Úignore)rA   )Ú
MemoryView)Z	is_bufferrM   Ú
LocalScoper   rp   ÚreÚmatchr   r   rY   r@   Úis_cpprK   ÚargsÚis_cpp_class_scoperr   rI   r<   Úcreate_wrapperr   rŽ   Úis_memoryviewslicer=   r»   Zmemslice_entry_initrB   r€   rR   )r6   r?   r/   r@   rA   rR   Úshadowr_   rÂ   r   Z	old_entryZcpp_override_allowedÚ	alt_entryr¥   r»   r0   r0   r1   Údeclare·  sJ    


zScope.declarec             C   s   t d| j|f ƒS )Nz%s.%s)r   rŽ   )r6   r?   r0   r0   r1   r   ñ  s    zScope.qualify_namer>   c	       
      C   sP   |s*| j s|dks|r|}n|  tj|¡}| j||||||d}	d|	_||	_|	S )NÚpublic)rÂ   r   )rp   r«   r	   Zenum_prefixrÆ   rb   Z
value_node)
r6   r?   r@   ÚvaluerA   r/   rR   rw   rÂ   r¥   r0   r0   r1   Údeclare_constô  s    zScope.declare_constr   c
          	   C   sJ   |s|}| j ||||||dd}
d|
_||
_|r<| j |
¡ |	sF|
|_|
S )NT)r_   r   )rÆ   r_   rw   r”   r   r¥   )r6   r?   r@   rA   r/   rR   rw   ÚdefiningrÄ   Útemplater¥   r0   r0   r1   Údeclare_type   s    zScope.declare_typec          
   C   s¼   |s*| j s|dks|r|}n|  tj|¡}y6| jrD| j | j¡j}nd }t	 
||||dk|¡}W n8 tk
r˜ }	 zt||	jd ƒ t	j}W d d }	~	X Y nX | j||||||d}
|
j|_|
S )Nr>   r   r   )rR   rw   )rp   r«   r	   Útype_prefixrÁ   rˆ   Úlookupr?   r@   r
   Zcreate_typedef_typeÚ
ValueErrorr   rÀ   Ú
error_typerÌ   rŽ   )r6   r?   Ú	base_typerA   r/   rR   rw   Ú	namespacer@   r    r¥   r0   r0   r1   Údeclare_typedef  s$    


zScope.declare_typedefFc
          	   C   s  |s*| j s|dks|r|}n|  tj|¡}|  |¡}
|
s|t ||||||	¡}| j|||||||d k	d}
| j 	|
¡ |
|_
n~|
jr–|
jjr–|
jj|ks¨t|d| dƒ nR|rÆ|
jjrÆt|d| dƒ n4|  |
||¡ |  |
||¡ |rú||
j_| j 	|
¡ | jr| j | j¡j|
j_|
S )NrÇ   )rR   rw   rÊ   z'%s' redeclared  r   z2'%s' already defined  (ignoring second definition))rp   r«   r	   rÍ   Úlookup_herer
   ZCStructOrUnionTyperÌ   r•   r   r¥   r_   r@   Zis_struct_or_unionÚkindr   r€   Úcheck_previous_typedef_flagÚcheck_previous_visibilityr”   rÁ   rˆ   rÎ   r?   rÒ   )r6   r?   rÕ   r€   Útypedef_flagrA   r/   rR   rw   Zpackedr¥   r@   r0   r0   r1   Údeclare_struct_or_union*  s4    
zScope.declare_struct_or_unionr0   r   c       
         sž  |d kr*| j s|dkr|}n|  tj|¡}t|ƒ}|  |¡}|s|tj|||||d}	| j||	ˆ|||d k	d}| j	 
|¡ nÈ|jrŠ|jjs¤tˆd| ƒ | ¡  d S |rÂ|jjrÂtˆd| dƒ n|rÚ||j_| j 
|¡ |r|jjr|jj|krtˆdƒ | ¡  n||j_|s$|jjrD||jjkrDtˆdƒ | ¡  ‡ ‡fd	d
„‰ |r~ˆ ||ƒ |jddt |j¡|jd | jrš| j | j¡j|j_|S )Nr>   )Ú	templates)rR   rÊ   z'%s' redeclared z2'%s' already defined  (ignoring second definition)r   z-Base type does not match previous declarationz5Template parameters do not match previous declarationc                sN   xH|D ]@}|t jkrq|jd kr,tˆdƒ qˆ | |jƒ | jj |¡ qW d S )Nz#Cannot inherit from incomplete type)r
   rÐ   r€   r   Úbase_classesr@   Ú declare_inherited_cpp_attributes)r¥   rÛ   Ú
base_class)Údeclare_inherited_attributesrA   r0   r1   rÞ   s  s    


z=Scope.declare_cpp_class.<locals>.declare_inherited_attributesÚthis)r?   r/   r@   rA   )rp   r«   r	   rÍ   ÚlistrÔ   r
   ZCppClassTyperÌ   r•   r   r_   r@   ra   r   rI   r€   r   r”   rÛ   rÚ   Údeclare_varÚCPtrTyperA   rÁ   rˆ   rÎ   r?   rÒ   )
r6   r?   r€   rA   r/   rÛ   rR   rÚ   r¥   r@   r0   )rÞ   rA   r1   Údeclare_cpp_classM  sJ    



	
zScope.declare_cpp_classc             C   s,   ||j jkr(t|d|jd|j j f ƒ d S )Nz#'%s' previously declared using '%s')ÚcdefZctypedef)r@   rØ   r   r?   )r6   r¥   rØ   rA   r0   r0   r1   rÖ   ƒ  s    z!Scope.check_previous_typedef_flagc             C   s$   |j |kr t|d|j|j f ƒ d S )Nz '%s' previously declared as '%s')rR   r   r?   )r6   r¥   rR   rA   r0   r0   r1   r×   ˆ  s    
zScope.check_previous_visibilityc             C   sœ   |rd|s6| j s"|dks"|dks"|r(|}n|  tj|¡}| jrN| j | j¡j}nd }t	 
||||¡}	nt	j}	| j||	||||d}
||
_g |
_| j |
¡ |
S )NrÇ   r   )r/   rR   rw   )rp   r«   r	   rÍ   rÁ   rˆ   rÎ   r?   r@   r
   Z	CEnumTypeZc_anon_enum_typerÌ   rÂ   Zenum_valuesr•   r   )r6   r?   rA   r/   rØ   rR   rw   rÂ   rÒ   r@   r¥   r0   r0   r1   Údeclare_enum  s"    
zScope.declare_enumc             C   s   | j  ||¡S )N)rˆ   Údeclare_tuple_type)r6   rA   Ú
componentsr0   r0   r1   ræ   ¤  s    zScope.declare_tuple_typec	       
      C   s€   |s$|dks|r|}n|   tj|¡}|jr<|dkr<| |¡ |  |||||¡}	d|	_|rl|dkrld|	_d|	_|r|d|	_	d|	_|	S )Nr>   r   r   )
r«   r	   Ú
var_prefixra   Úcheck_nullary_constructorrÆ   rX   ru   rs   rw   )
r6   r?   r@   rA   r/   rR   rw   Úin_pxdÚis_cdefr¥   r0   r0   r1   rá   §  s    
zScope.declare_varc             C   s   | j  ||¡S )N)rˆ   Údeclare_builtin)r6   r?   rA   r0   r0   r1   rì   ¼  s    zScope.declare_builtinc             C   sN   |r&|j js&t|d| ƒ t|jdƒ | j|t||d}t|_| j 	|¡ |S )Nz'%s' already declaredzPrevious declaration is here)rR   )
r@   rY   r   rA   rá   r   r   Ú	signaturer˜   r   )r6   r?   rA   rR   r¥   r0   r0   r1   Ú_declare_pyfunction¿  s    zScope._declare_pyfunctionc             C   sž   |   |¡}|s | j||||dS |rR|jjr4t|_qd|jtk	rd| j||||dS n| j|t||d | jd t||dd}t|ƒ|_|  |¡|_	t
|_d|_|S )N)rR   r¥   )rR   r>   )r/   rR   T)rÔ   rî   r@   Zis_unspecifiedr   rá   r   r?   r   rŽ   r   rí   r^   )r6   r?   rA   Úallow_redefinerR   r¥   r0   r0   r1   Údeclare_pyfunctionÈ  s     




zScope.declare_pyfunctionc             C   sh   |   tjd |¡}|   tjd |¡}|  |¡}|  d |t|d¡}||_||_||_||_	t
|_d|_|S )NZfuncdef_Zmethdef_r>   T)r«   r	   Zlambda_func_prefixr   rÆ   r   r?   rŽ   Úpymethdef_cnamerk   r   rí   r^   )r6   Zlambda_namerA   rk   rñ   rŽ   r¥   r0   r0   r1   Údeclare_lambda_functionÜ  s    
zScope.declare_lambda_functionc             C   s   | j  |¡ d S )N)r›   r   )r6   Údef_noder0   r0   r1   Úadd_lambda_defë  s    zScope.add_lambda_defc             C   s   | j  |¡ d S )N)r˜   r   )r6   r¥   r0   r0   r1   Úregister_pyfunctionî  s    zScope.register_pyfunctionc             C   sp  |s$|dks|r|}n|   tj|¡}|  |¡}|r˜|s`||jkr`|dkr`d}|j}||_||_|dkrŠ||jkrŠt|d||j|f dƒ ||jkr°t|d||r¤dndf dƒ |j	 
|¡rÎ|j	 |j¡|_	nÈ|dkrh|jdkrhd	}|  ¡ röd}n4|r*x,| ¡ D ]}|jr||jkrP qW d}|rT|  ||||||	¡}| ¡ |_|}nt|d
dƒ ||_	n.|sŒ|jrŒ| |j	¡rŒ||_	n
t|d
ƒ n |  ||||||	¡}||_||_|rÎ|dkrÎd|_|rÚd|_|sþ|sþ|dkrþt|d| ƒ |r
d|_|	r|	|_|
r:|jr4td||f ƒ‚|
|_|rft||tƒ}d|_d|_|j|_||_||_|S )Nr>   r   Tz6Function '%s' previously declared as '%s', now as '%s'r   z)Function '%s' previously declared as '%s'Zcpdefrä   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Ô   rR   r/   rk   r   ry   r@   Úsame_asÚwith_with_gilÚwith_gilr¿   rK   Úadd_cfunctionrC   ru   Úcompatible_signature_withr   rw   rv   rl   rx   ÚAssertionErrorr<   r   rX   rU   r€   ro   r¥   )r6   r?   r@   rA   r/   rR   rw   rê   rÊ   Ú	modifiersrx   Úoverridabler¥   Zcan_overriderÅ   ZtempÚ	var_entryr0   r0   r1   Údeclare_cfunctionñ  sx    


zScope.declare_cfunctionc             C   s‚   |   |||||¡}d|_|r"||_|s,|jr:| j |¡ nDt| jƒ}	x*t| jƒD ]}
|
jsb|
j	jsdP |	d8 }	qPW | j 
|	|¡ |S )Nr   )rÆ   rY   rl   Úis_fusedr™   r   rŠ   Úreversedrr   r@   Úinsert)r6   r?   r@   rA   r/   rR   rý   Ú	inheritedr¥   ÚiZcfunc_entryr0   r0   r1   rú   @  s    

zScope.add_cfunctionc             C   s$   |   |¡}|r|S t|d| ƒ d S )Nz'%s' is not declared)rÎ   r   )r6   r?   rA   r¥   r0   r0   r1   ÚfindS  s    
z
Scope.findc             C   sP   | }xF|D ]>}|  ||¡}|s"d S |jr0|j}q
t|dd |¡ ƒ d S q
W |S )Nz'%s' is not a cimported moduler‡   )r  rq   r   Újoin)r6   ÚpathrA   r€   r?   r¥   r0   r0   r1   Úfind_imported_module[  s    
zScope.find_imported_modulec             C   s    |   |¡p| jr| j |¡pd S )N)rÔ   rˆ   rÎ   )r6   r?   r0   r0   r1   rÎ   j  s    
zScope.lookupc             C   s   | j  |d ¡S )N)r   Úget)r6   r?   r0   r0   r1   rÔ   q  s    zScope.lookup_herec             C   s    |   |¡}|s|  |td ¡}|S )N)rÔ   rá   r   )r6   r?   r¥   r0   r0   r1   Úlookup_targetu  s    
zScope.lookup_targetc             C   s:   |   |¡}|r6|jr6|jjr0| jr0|j | j¡S |jS d S )N)rÎ   r_   r@   r  Úfused_to_specificÚ
specialize)r6   r?   r¥   r0   r0   r1   Úlookup_type}  s
    

zScope.lookup_typec             C   s"  |d j jrr|d j }|j d| ¡}|d k	rrdd„ |dd … D ƒ}t dd„ |dd … D ƒ| ¡ ¡}|d k	rr|S |  d| ¡}g }|d k	r”| ¡ }g }	t|ƒdkrðxJtdƒD ]>}
||
 j jr®||
 j }|j d| ¡}|d k	r®|	| ¡ 7 }	q®W |	sü|süd S t	t
|	| ƒƒ}t dd„ |D ƒ|¡S )	Nr   z
operator%sc             S   s   g | ]
}|j ‘qS r0   )r@   )rŸ   Úargr0   r0   r1   ú
<listcomp>‰  s    z)Scope.lookup_operator.<locals>.<listcomp>r   c             S   s   g | ]
}|j ‘qS r0   )r@   )rŸ   r  r0   r0   r1   r  Š  s    r(   c             S   s   g | ]
}|j ‘qS r0   )r@   )rŸ   r  r0   r0   r1   r  £  s    )r@   ra   r€   rÎ   r
   Z
best_matchrK   rŠ   Úrangerà   r‘   )r6   r¶   ÚoperandsZobj_typeÚmethodZ	arg_typesZresZfunctionZfunction_alternativesZmethod_alternativesÚnrK   r0   r0   r1   Úlookup_operator„  s4    


zScope.lookup_operatorc                s<   ddl m} G dd„ d|ƒ‰ ‡ ‡fdd„|D ƒ}|  ||¡S )Nr   )ÚNodec               @   s   e Zd ZdS )z4Scope.lookup_operator_for_types.<locals>.FakeOperandN)r9   r:   r;   r0   r0   r0   r1   ÚFakeOperand¨  s   r  c                s   g | ]}ˆ ˆ|d ‘qS ))r@   r0   )rŸ   r@   )r  rA   r0   r1   r  ª  s    z3Scope.lookup_operator_for_types.<locals>.<listcomp>)ZNodesr  r  )r6   rA   r¶   Útypesr  r  r0   )r  rA   r1   Úlookup_operator_for_types¦  s    zScope.lookup_operator_for_typesc             C   s   |   ¡  |¡ d S )N)r¯   Úuse_utility_code)r6   Únew_coder0   r0   r1   r  ­  s    zScope.use_utility_codec             C   s   |   ¡  |¡ d S )N)r¯   Úuse_entry_utility_code)r6   r¥   r0   r0   r1   r  °  s    zScope.use_entry_utility_codec             C   s    x|D ]}|| j krdS qW dS )Nr   r   )r   )r6   r§   r?   r0   r0   r1   Údefines_any³  s    

zScope.defines_anyc             C   s,   x&|D ]}|| j kr| j | jrdS qW dS )Nr   r   )r   rt   )r6   r§   r?   r0   r0   r1   Údefines_any_specialº  s    
zScope.defines_any_specialc             C   s   ddl m} |ƒ  | ¡ d S )Nr   )Úget_type_inferer)ÚTypeInferencer  Úinfer_types)r6   r  r0   r0   r1   r!  Á  s    zScope.infer_typesc             C   s   | j }|d krdS | ¡ S d S )NF)rˆ   r¿   )r6   Zouterr0   r0   r1   r¿   Å  s    zScope.is_cppc             C   s   | j  |||¡ d S )N)rˆ   Úadd_include_file)r6   ÚfilenameÚverbatim_includeÚlater0   r0   r1   r"  Ì  s    zScope.add_include_file)TN)N)N)r   r   r   )Nr>   r   r   )Nr>   r   r   r   r   )Nr>   r   )Nr>   r   F)Nr0   r   N)r>   r   r   )Nr>   r   r   r   )r   N)Fr   )Nr>   r   r   r   r0   NF)F)NF)Ar9   r:   r;   Úis_builtin_scopeÚis_py_class_scopeÚis_c_class_scopeÚis_closure_scopeÚis_genexpr_scopeÚis_passthroughrÁ   Úis_property_scopeÚis_module_scopeZis_internalr   rp   Únogilr  Úreturn_typer7   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  r	  rÎ   rÔ   r  r  r  r  r  r  r  r  r!  r¿   r"  r0   r0   r0   r1   r†     sŠ   #



:
 
 
  
! 
4
 

	
 
M
"r†   c               @   s"   e Zd ZejZdd„ Zdd„ ZdS )ÚPreImportScopec             C   s   t  | tjd d ¡ d S )N)r†   r7   r   Ú
pre_import)r6   r0   r0   r1   r7   Ô  s    zPreImportScope.__init__c             C   s"   |   ||t|d¡}d|_d|_|S )Nr>   T)rÆ   r   rX   rU   )r6   r?   rA   r¥   r0   r0   r1   rì   ×  s    zPreImportScope.declare_builtinN)r9   r:   r;   r	   Zpreimport_cnameÚnamespace_cnamer7   rì   r0   r0   r0   r1   r0  Ð  s   r0  c               @   s¾   e Zd ZdZdd„ Zd#dd„Zdd„ Zd$d	d
„Zd%dd„Zdd„ Z	de
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gde
gd e
gd!e
gd"œZdS )&ÚBuiltinScopeTc             C   sl   t jd krt | dd d ¡ nt | dtƒ d ¡ i | _x2t| j ¡ ƒD ] \}}|\}}|  	||d |¡ qDW d S )NÚ__builtin__)
r   r1  r†   r7   r0  Ú
type_namesrµ   Úbuiltin_entriesr¢   rá   )r6   r?   Z
definitionr/   r@   r0   r0   r1   r7   ã  s    
zBuiltinScope.__init__Nc             C   s,   |dkr |d kr|dk}|s d}t  | |¡S )NÚstr)Nr(   Úunicode)r†   rÎ   )r6   r?   Úlanguage_levelÚ
str_is_strr0   r0   r1   rÎ   î  s    zBuiltinScope.lookupc             C   sL   t t|ƒsH| jd k	r"| j ||¡S tjr8t|d| ƒ nt|d| dƒ d S )Nzundeclared name not builtin: %sr(   )ÚhasattrÚbuiltinsrˆ   rì   r   Úerror_on_unknown_namesr   r   )r6   r?   rA   r0   r0   r1   rì   ÷  s    

zBuiltinScope.declare_builtinc             C   sh   t |ƒ}| j||d |d|d}|rd|dkr0|}nt |ƒ}t||tƒ}d|_d|_||_|j|_||_|S )Nr   )rR   rx   Ú*r   )	r   r   r<   r   rX   rS   rx   r€   ro   )r6   r?   r@   r/   Zpython_equivrx   r¥   rÿ   r0   r0   r1   Údeclare_builtin_cfunction  s    z&BuiltinScope.declare_builtin_cfunctionc       	      C   s¾   t |ƒ}t |||¡}t|d dd}i |_|dkr8d|_| |¡ d| j|< | j||d dd}||_	t
|j|  d¡j|j|jjd}d|_d|_d|_d|_||_	| |_tjr´d|_||_|S )	Nr   )rˆ   rR   ÚboolTr   )rR   r@   )r?   r@   rA   r/   )r   r
   ZBuiltinObjectTypeÚCClassScopeÚ
directivesÚis_final_typeÚ	set_scoper5  rÌ   rx   r<   r?   rÎ   r@   rA   Útypeptr_cnamerX   rT   rj   rS   r€   r   Úcache_builtinsrb   ro   )	r6   r?   r/   rx   Úobjstruct_cnamer@   r€   r¥   rÿ   r0   r0   r1   Údeclare_builtin_type  s0    


z!BuiltinScope.declare_builtin_typec             C   s   | S )Nr0   )r6   r0   r0   r1   r³   0  s    zBuiltinScope.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)ZPy_NoneZPy_FalseZPy_True)r@   r@  r   r    r   ÚcomplexÚbytesÚ	bytearrayr7  r8  Útuplerà   Údictr‘   Ú	frozensetÚsliceÚNoneÚFalseÚTrue)NN)NN)NN)r9   r:   r;   r&  r7   rÎ   rì   r?  rH  r³   r   r6  r0   r0   r0   r1   r3  Þ  s4   
	


r3  c               @   s  e Zd ZdZdZdZdZdd„ Zdd„ Zdd„ Z	d@d
d„Z
dd„ Zdd„ ZdAdd„Zdd„ Zdd„ ZdBdd„Zdd„ Zdd„ Zdd„ Zd d!„ ZdCd#d$„ZdDd&d'„Zd(d)„ Zd*d+„ Zd,d-„ ZdEd.d/„Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d	S )FÚModuleScoper   r   c             C   s  ddl m} || _|j}t | |||¡ |dkr@|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 | _!xdD ]}|  "t|ƒt#d ¡ qâW |  $t%j&d	dd
¡ d S )Nr   )ÚBuiltinr7   TFr=   r   )	Ú__builtins__r9   Ú__file__r…   Ú__path__Ú__spec__Ú
__loader__Ú__package__Ú
__cached__zPython.h)Úinitial)'r=   rT  Úparent_moduler³   r†   r7   Úmodule_nameÚ
is_packager   Úcontextr	   Zmodule_cnameZmoddict_cnameZmodule_dict_cnameZmethtable_cnameÚmethod_table_cnamern   Zmoddoc_cnamerd   Úutility_code_listÚmodule_entriesÚ
c_includesrM  r5  Zpxd_file_loadedÚcimported_modulesr‘   Ztypes_importedZincluded_filesZhas_extern_classÚcached_builtinsÚundeclared_cached_builtinsr2  Ú_cached_tuple_typesrá   r   Úprocess_includer   ÚIncludeCode)r6   r?   r]  r`  rT  rˆ   Zvar_namer0   r0   r1   r7   p  s@    
zModuleScope.__init__c             C   s   | j S )N)r]  )r6   r0   r0   r1   rŒ   –  s    zModuleScope.qualifying_scopec             C   s   | S )Nr0   )r6   r0   r0   r1   r¯   ™  s    zModuleScope.global_scopeNc             C   sn   |   |¡}|d k	r|S |d kr4| jd k	r0| jjnd}|d kr\|dkpZ| jd k	oZtj| jjk}| jj|||dS )Né   r(   )r9  r:  )rÔ   r`  r9  r   Zunicode_literalsZfuture_directivesrˆ   rÎ   )r6   r?   r9  r:  r¥   r0   r0   r1   rÎ   œ  s    
zModuleScope.lookupc       
      C   sÌ   t |ƒ}y| j| }W n( tk
r>   t |¡ }| j|< Y nX |j}|  |¡}|sÂt|ƒ}x(t|ƒD ]\}}|j	d| ||d qfW | j
|d d|d||d}	| j |	¡ |	|_|  ||||¡}||_|S )Nzf%s)r?   r@   rA   Z_structr$   T)rØ   rA   r/   )rL  rh  r°   r
   Zc_tuple_typer/   rÔ   ÚStructOrUnionScopeÚ	enumeraterá   rÙ   r”   ÚremoveÚstruct_entryrÌ   r¥   )
r6   rA   rç   Zttyper/   r¥   r€   ZixZ	componentro  r0   r0   r1   ræ   ©  s$    
zModuleScope.declare_tuple_typec             C   s$  t t|ƒsx|tjkrx|tjkrx| jr6|  |t|¡}|S tj	rLt
|d| ƒ nt|d| dƒ |  |d t|d¡}d|_|S tjrœx| jD ]}|j|kr†|S q†W |dkr¶| js¶| j d¡S |  d d t|d¡}tjr|tjkrd|_d|_||_tj| |_| j |¡ | j |¡ nd|_||_|S )Nzundeclared name not builtin: %sr(   r>   r   ÚglobalsZ__Pyx_Globals)r;  r<  r   Znon_portable_builtins_mapZuncachable_builtinsÚhas_import_starrá   r   r   r=  r   r   rÆ   rS   rF  rf  r?   Úold_style_globalsrˆ   rÎ   rb   r	   Zbuiltin_prefixr/   r   rg  )r6   r?   rA   r¥   r0   r0   r1   rì   ½  s:    



zModuleScope.declare_builtinr¹   c             C   sl   d }d}|d k	r>|dkr>| }x2|dkr:|r:|j }|d8 }qW n|dkrP| j }d}|  ¡ }|jj||||dS )NFr   r   T)Úrelative_torA   Úabsolute_fallback)r]  r¯   r`  Úfind_module)r6   r^  rA   Zrelative_levelrs  rt  Zmodule_scoper0   r0   r1   ru  á  s    zModuleScope.find_modulec             C   sX   d|kr|  dd¡\}}nd }|  |¡}|sFt|| | jd}|| j|< |rT| |¡}|S )Nr‡   r   )r]  r`  )ÚsplitÚlookup_submodulerS  r`  rc  Úfind_submodule)r6   r?   Ú	submoduler€   r0   r0   r1   rx  ø  s    


zModuleScope.find_submodulec             C   sF   d|kr|  dd¡\}}nd }| j |d ¡}|rB|d k	rB| |¡}|S )Nr‡   r   )rv  rc  r
  rw  )r6   r?   ry  Úmoduler0   r0   r1   rw    s    
zModuleScope.lookup_submoduleFc             C   s   t j|||d}|  |¡ dS )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.
        )r%  N)r   rj  ri  )r6   r#  r$  r%  Úincr0   r0   r1   r"    s    zModuleScope.add_include_filec             C   s4   |  ¡ }|dkr| ¡ }| | j|¡ | j| }dS )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	mainpieceZsortkeyZdict_updaterd  )r6   r{  r´   r0   r0   r1   ri    s
    zModuleScope.process_includec             C   sR   || j krNx|j ¡ D ]}|  |¡ qW | j  |¡ x|j D ]}|  |¡ q<W d S )N)re  rd  Úvaluesri  r   Úadd_imported_module)r6   r€   r{  Úmr0   r0   r1   r}  :  s    
zModuleScope.add_imported_modulec             C   s6   |j rd|_|| jkr"|| j|< nt|d| dƒ d S )NTz'%s' redeclared  r   )rU   rX   r   r   )r6   r?   r¥   rA   r0   r0   r1   Úadd_imported_entryB  s
    
zModuleScope.add_imported_entryc             C   s\   |   |¡}|r4|jr"|j|kr"|S |jr.|jrH|S n|  |t|¡}d|_||_|  |¡ |S )Nr   )rÔ   rU   rq   rá   r   rX   r}  )r6   r?   r€   rA   r¥   r0   r0   r1   Údeclare_moduleK  s    

zModuleScope.declare_moduler>   c	             C   sR  |dkrt |d| ƒ |s:|tkr&t}|jr2|jr:tdƒ‚|sl| }	|dksX|dkr^|	r^|}n|  tj|¡}|  	|¡}
|
rð|
j
rð|
j |¡s´|dkr´|
jdkr´t|d| dƒ ||
_|
jdkrà|  tj|¡}|
j|krà|}||
_|
jsðd	|
_|
S tj| ||||||||d
	}
|r:d|
_|
jjr,|
jj|
_| j |
¡ nd|
_tjrNd|
_|
S )N)r>   rÇ   r   z+Module-level variable cannot be declared %sz7Non-cdef global variable is not a generic Python objectr   rÇ   z6Variable '%s' type does not match previous declarationr   r>   T)r/   rR   rw   rê   rë   )r   r   r   Úis_pyobjectÚis_extension_typer   r«   r	   rè   rÔ   ru   r@   r÷   rR   r   r/   rv   r†   rá   rT   Údeclaration_valuerB   r—   r   rU   r   Zcimport_from_pyxrs   )r6   r?   r@   rA   r/   rR   rw   rê   rë   rÊ   r¥   Úmangled_cnamer0   r0   r1   rá   d  sN    





zModuleScope.declare_varr0   c             C   sÈ   |sd|	krt |ddƒ |sD|dks0|dkr6|r6|}n|  tj|¡}|dkr\|jr\t|dƒ |  |¡}|r¢|jr¢|jdkr¢|  tj	|¡}|j
|kr¢|}||_
||_tj| |||||||||	|
|d}|S )	Nr'   z+Declarations should not be declared inline.r   r   rÇ   z6Extern functions cannot have default arguments values.r>   )r/   rR   rw   rê   rÊ   rý   rx   rþ   )r   r«   r	   rö   Zoptional_arg_countr   rÔ   ru   rR   rè   r/   rk   r†   r   )r6   r?   r@   rA   r/   rR   rw   rê   rÊ   rý   rx   rþ   r¥   r„  r0   r0   r1   r   œ  s,    




zModuleScope.declare_cfunctionc             C   s    |   |¡}|s|  |t|¡ d S )N)rÔ   rá   r   )r6   r?   rA   r¥   r0   r0   r1   Údeclare_global¹  s    
zModuleScope.declare_globalc             C   s   |d k	r| j  |¡ d S )N)rb  r   )r6   r  r0   r0   r1   r  ¾  s    zModuleScope.use_utility_codec             C   s8   |d krd S |j r | j |j ¡ |jr4| j |j¡ d S )N)rx   rb  r   r{   )r6   r¥   r0   r0   r1   r  Â  s    z"ModuleScope.use_entry_utility_codec             C   sô  |r.|
dkr.|
dks$|s$t |ddƒ |}d}nd }|  |¡}|rº|sº|j}|jrV|js\d }n^|j}|r~|rp|jr~|  |||¡ |rˆ|js’|rª|jrª|rª||jk	rªt	|dƒ |rº|jsº||_|rÄ|r”t
j||||
dk|d}||_||_|d k	rö||_|
dkr||_n| j|_|	r|	|_n|  tj|¡|_| j||||
d|d}d	|_|rX||_n&|jsr|  tj|¡|_nt	|jd
ƒ |  |¡ | j |¡ |jsô|s¨|r2t|| |
d}| j ¡ |_|rÜ|jrÜ|  |j¡ | !|¡ | j" |¡ n>|r|jjrt	|d| ƒ n|r2|jj#r2t	|d| ƒ |r>d|_$|rJ||_|
dkrt|j%|
krtt	|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 )Nr   rÇ   z6ctypedef only valid for 'extern' , 'public', and 'api'r(   r   z-Base type does not match previous declaration)Ú
check_size)rR   rÊ   rÄ   Tz5Object name required for 'public' or 'extern' C class)r?   rˆ   rR   zC class '%s' already definedz C class '%s' already implementedr   r>   z&Class '%s' previously declared as '%s'z4Object struct name differs from previous declarationz2Type object name differs from previous declarationÚfinal)+r   rÔ   r@   r_   r‚  r€   ÚdefinedrÖ   rÑ   r   r
   ZPyExtensionTyperA   Úbuffer_defaultsÚobjtypedef_cnamer^  rŽ   rE  r«   r	   Ztypeptr_prefixrÌ   r`   rG  rp   Zobjstruct_prefixÚattach_var_entry_to_c_classrš   r   rA  rB  ÚcopyÚdeclare_inherited_c_attributesrD  r”   Úimplementedru   rR   rw   Útypeobj_cnamer
  rC  rs   )r6   r?   rA   rÊ   Zimplementingr^  rÑ   rG  r  rE  rR   rØ   rw   r†  r‰  rÄ   rŠ  r¥   r@   r€   r0   r0   r1   Údeclare_c_classÊ  sš    









zModuleScope.declare_c_classc             C   s²   |j }|jr*|jjr*dtj|jjf |_nZ|jr„|jjr„t|jjƒ}|j}x0|rz|jrf|t|jjƒkrhP |jrrd S |j}qLW tj|_|jr®|  	tj
|j¡|_|  	tj|j¡|_d S )Nz%s.%s)r@   rÑ   Úvtabslot_cnamer	   Úobj_base_cnamer€   r™   rŠ   Úis_builtin_typer«   Zvtabstruct_prefixr?   Zvtabstruct_cnameZvtabptr_prefixZvtabptr_cname)r6   r¥   r@   Zentry_countrÑ   r0   r0   r1   Úallocate_vtable_names:  s"    
z!ModuleScope.allocate_vtable_namesc             C   s.   x(| j D ]}|jjst|jd|j ƒ qW d S )Nz(C class '%s' is declared but not defined)rš   r@   r€   r   rA   r?   )r6   r¥   r0   r0   r1   Úcheck_c_classes_pxdW  s    zModuleScope.check_c_classes_pxdc             C   s˜   |j }|j}|j}|js(t|jd| ƒ |dkrF|jsF|  tj	|¡|_|jr|x.|jj
D ]"}|jsV|jsVt|jd|j ƒ qVW |jr”|  tj|j¡|_d S )Nz(C class '%s' is declared but not definedr   z)C method '%s' is declared but not defined)r@   r?   rR   r€   r   rA   r  r«   r	   Ztypeobj_prefixr™   rr   rk   r‘  Zvtable_prefixZvtable_cname)r6   r¥   r@   r?   rR   Zmethod_entryr0   r0   r1   Úcheck_c_classg  s    zModuleScope.check_c_classc             C   sb   d}|rt d| j ƒ xF| jD ]<}|rPt d|j|f ƒ t d|jƒ t d|jƒ |  |¡ qW d S )Nr   z&Scope.check_c_classes: checking scope z...entry %s %sz......type = z......visibility = )ÚprintrŽ   rš   r?   r@   rR   r–  )r6   Zdebug_check_c_classesr¥   r0   r0   r1   Úcheck_c_classes~  s    zModuleScope.check_c_classesc             C   sX   xR| j  ¡ D ]D\}}|jr|jr|j| kr|jdkr|js|jst|j	d| ƒ qW d S )Nr   z3Non-extern C function '%s' declared but not defined)
r   r¢   rY   ru   r€   rR   rp   rv   r   rA   )r6   r?   r¥   r0   r0   r1   Úcheck_c_functions–  s    

zModuleScope.check_c_functionsc             C   sJ   ddl m} t|j|j|j|jjd}d|_d|_	d|_
|j|_||_d S )Nr   )rT  )r?   r@   rA   r/   )r=   rT  r<   r?   Z	type_typerA   r@   rE  rX   rT   rj   r€   ro   )r6   r¥   rT  rÿ   r0   r0   r1   r‹  ¢  s    z'ModuleScope.attach_var_entry_to_c_classc             C   s   | j S )N)Zcpp)r6   r0   r0   r1   r¿   ´  s    zModuleScope.is_cppc             C   s   ddl m} |ƒ  | ¡ d S )Nr   )ÚPyObjectTypeInferer)r   rš  r!  )r6   rš  r0   r0   r1   r!  ·  s    zModuleScope.infer_types)NN)r¹   )NF)Nr>   r   r   r   )Nr>   r   r   r   r0   NF)r   r   NNNNNr>   r   r   NNr   )#r9   r:   r;   r-  rq  Zis_cython_builtinrr  r7   rŒ   r¯   rÎ   ræ   rì   ru  rx  rw  r"  ri  r}  r  r€  rá   r   r…  r  r  r  r”  r•  r–  r˜  r™  r‹  r¿   r!  r0   r0   r0   r1   rS  R  sL   &
$

		 
7 
    
lrS  c               @   sX   e Zd ZdZdZddd„Zdd„ Zdd„ Zddd„Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )r¼   FNc             C   s    |d kr|}t  | |||¡ d S )N)r†   r7   )r6   r?   rˆ   r‰   r0   r0   r1   r7   Ä  s    zLocalScope.__init__c             C   s   || S )Nr0   )r6   r¬   r?   r0   r0   r1   r«   É  s    zLocalScope.manglec             C   sH   |   tj|¡}|  ||||d¡}d|_|jr2d|_d|_| j 	|¡ |S )Nr>   r   Ú0)
r«   r	   rè   rÆ   rX   r  rB   re   r–   r   )r6   r?   r@   rA   r/   r¥   r0   r0   r1   Údeclare_argÌ  s    zLocalScope.declare_argr>   r   c	       
      C   sb   |dkrt |d| ƒ tj| ||||||||d	}	|	jjrD|	jj|	_d|	_| j|	_| j	 
|	¡ |	S )N)rÇ   Úreadonlyz$Local variable cannot be declared %s)r/   rR   rw   rê   rë   r   )r   r†   rá   r@   rƒ  rB   rf   Ú_in_with_gil_blockr}   r—   r   )
r6   r?   r@   rA   r/   rR   rw   rê   rë   r¥   r0   r0   r1   rá   Ø  s    
zLocalScope.declare_varc             C   s4   |   |¡rt|ddƒ n|  ¡  |¡}|| j|< d S )Nz'%s' redeclared  r   )rÔ   r   r¯   r  r   )r6   r?   rA   r¥   r0   r0   r1   r…  é  s    
zLocalScope.declare_globalc             C   s`   |   |¡}|r6|j| kr6|js6t|d| ƒ | ¡  n&|  |¡}|d ksN|js\t|d| ƒ d S )Nz'%s' redeclared as nonlocalz"no binding for nonlocal '%s' found)rÔ   r€   rh   r   rI   rÎ   )r6   r?   rA   Ú
orig_entryr¥   r0   r0   r1   Údeclare_nonlocalñ  s    


zLocalScope.declare_nonlocalc             C   sv   t  | |¡}|d k	rr|j}x|jr*|j}qW || k	rr|jrrt|jdƒrNtdƒ‚d|_t	|| ƒ}d|_
|| j|< |S |S )NZscope_classz#lookup() after scope class created.T)r†   rÎ   r€   r*  rˆ   r)  r;  r   rg   r   rX   r   )r6   r?   r¥   Zentry_scopeZinner_entryr0   r0   r1   rÎ   ü  s    


zLocalScope.lookupc             C   s˜   x’|   ¡ D ]†}x€|j ¡ D ]r}|jrl|jj}| jr:||_qŒ| tj	¡r\|t
tj	ƒd d … }d||f |_q|jr|j|_dtj	|jf |_qW q
W d S )Nr(   z%s->%s)r¸   r   r|  rh   r~   r/   r+  r,   r	   Zcur_scope_cnamerŠ   rg   Zoriginal_cname)r6   Zouter_scope_cnamer€   r¥   r/   r0   r0   r1   Úmangle_closure_cnames  s    z LocalScope.mangle_closure_cnames)N)Nr>   r   r   r   )r9   r:   r;   Zhas_with_gil_blockrž  r7   r«   rœ  rá   r…  r   rÎ   r¡  r0   r0   r0   r1   r¼   ¼  s   
 
r¼   c               @   sH   e Zd ZdZdZdd„ Zdd„ Zdd
d„Zddd„Zdd„ Z	dd„ Z
dS )Ú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).
    Tc             C   sŠ   |}x|j r|j}qW | ¡  tj¡}t | |||¡ |j| _dtj	t
|ƒ|f | _x|j sh|jsh|jrp|j}qVW |j| _|j | ¡ d S )Nz%s%d%s)r*  r‰   r¯   r²   r	   Zgenexpr_id_refr†   r7   rB  r-   rŠ   Úgenexp_prefixr(  r'  rˆ   r—   r’   Úadd)r6   rˆ   r‰   r?   r0   r0   r1   r7   '  s    

z!GeneratorExpressionScope.__init__c             C   s   d| j | j ||¡f S )Nz%s%s)r£  r‰   r«   )r6   r¬   r?   r0   r0   r1   r«   8  s    zGeneratorExpressionScope.mangleNr>   r   c	             C   s”   |t kr$| j |¡}	|	r$|	jr$|	j}d| j| j tj	|p>|  
¡ ¡f }|  |||||¡}
d|
_| jjrnd|
_nd|
_d|
_| j |
¡ |
| j|< |
S )Nz%s%sT)r   rˆ   rÎ   rX   r@   r£  r‰   r«   r	   rè   r²   rÆ   r-  rT   rf   ri   r—   r   r   )r6   r?   r@   rA   r/   rR   rw   rê   rë   r~   r¥   r0   r0   r1   rá   ;  s    
"
z$GeneratorExpressionScope.declare_varFc             C   s   | j  |||¡S )N)rˆ   rð   )r6   r?   rA   rï   r0   r0   r1   rð   Q  s    z+GeneratorExpressionScope.declare_pyfunctionc             C   s   | j  ||¡S )N)rˆ   rò   )r6   rk   rA   r0   r0   r1   rò   U  s    z0GeneratorExpressionScope.declare_lambda_functionc             C   s   | j  |¡S )N)rˆ   rô   )r6   ró   r0   r0   r1   rô   X  s    z'GeneratorExpressionScope.add_lambda_def)Nr>   r   r   T)F)r9   r:   r;   r…   r*  r7   r«   rá   rð   rò   rô   r0   r0   r0   r1   r¢     s    

r¢  c               @   s$   e Zd ZdZddd„Zd	dd„ZdS )
ÚClosureScopeTNc             C   s$   t  | |||¡ dtj|f | _d S )Nz%s%s)r¼   r7   r	   Zclosure_scope_prefixZclosure_cname)r6   r?   Z
scope_namerˆ   r‰   r0   r0   r1   r7   `  s    zClosureScope.__init__Fc             C   s   t j| |||ddS )Nr>   )rR   )r¼   rð   )r6   r?   rA   rï   r0   r0   r1   rð   m  s    zClosureScope.declare_pyfunction)N)F)r9   r:   r;   r)  r7   rð   r0   r0   r0   r1   r¥  \  s   
r¥  c               @   s*   e Zd Zddd„Zddd	„Zddd„ZdS )rl  ú?c             C   s   t  | |d d ¡ d S )N)r†   r7   )r6   r?   r0   r0   r1   r7   t  s    zStructOrUnionScope.__init__Nr>   r   Fc             C   s   |s|}|dkrt |ƒ}|jr(t |¡}|  |||||¡}d|_| j |¡ |jrb|	sbt	|dƒ n|j
rv|
svt	|dƒ |dkrŒt	|d| ƒ |S )Nr>   r   z/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)r2   rY   r
   râ   rÆ   rX   r—   r   r  r   rÃ   )r6   r?   r@   rA   r/   rR   rw   rê   rë   Zallow_pyobjectZallow_memoryviewr¥   r0   r0   r1   rá   w  s     



zStructOrUnionScope.declare_varr0   c             C   s"   |
rt |dƒ | j|||||dS )Nz0C struct/union member cannot be declared 'cpdef')r/   rR   )r   rá   )r6   r?   r@   rA   r/   rR   rw   rê   rÊ   rý   rþ   r0   r0   r1   r   Ž  s    

z$StructOrUnionScope.declare_cfunction)r¦  )Nr>   r   r   r   FF)Nr>   r   r   r   r0   F)r9   r:   r;   r7   rá   r   r0   r0   r0   r1   rl  q  s   
  
 rl  c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú
ClassScopec             C   s    t  | |||¡ || _d | _d S )N)r†   r7   Ú
class_namern   )r6   r?   rˆ   r0   r0   r1   r7      s    zClassScope.__init__c             C   sd   t  | |¡}|r|S |dkr`tddt tt dtd ¡gdd¡ƒ}tj 	dd¡|_
|  |¡ d|_|S )NÚclassmethodZ__Pyx_Method_ClassMethodr=   r   ZClassMethodzCythonFunction.cr   )r†   rÎ   r<   r
   Z	CFuncTyper   ÚCFuncTypeArgr   ÚUtilityCodeZload_cachedr{   r  rY   )r6   r?   r¥   r0   r0   r1   rÎ   ¥  s    
zClassScope.lookupN)r9   r:   r;   r7   rÎ   r0   r0   r0   r1   r§  —  s   	r§  c               @   sJ   e Zd ZdZdd„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Z	dd„ Z
dS )ÚPyClassScoper   c             C   s
   |   |¡S )N)Úmangle_special_name)r6   r?   r0   r0   r1   r®   Á  s    z&PyClassScope.mangle_class_private_namec             C   s4   |r0|  d¡r0| d¡s0td| j d¡|f ƒ}|S )Nr)   z_%s%sÚ_)r,   Úendswithr   r¨  Úlstrip)r6   r?   r0   r0   r1   r­  Ä  s    z PyClassScope.mangle_special_namec             C   s   |   |¡}t | |¡S )N)r­  r§  rÔ   )r6   r?   r0   r0   r1   rÔ   É  s    
zPyClassScope.lookup_hereNr>   r   c	       
      C   sB   |   |¡}|tkrt}tj| ||||||||d	}	d|	_d|	_|	S )N)r/   rR   rw   rê   rë   r   )r­  r   r   r†   rá   rU   rW   )
r6   r?   r@   rA   r/   rR   rw   rê   rë   r¥   r0   r0   r1   rá   Í  s    
zPyClassScope.declare_varc             C   sf   |   |¡}|r6|j| kr6|js6t|d| ƒ | ¡  n,|  |¡}|d krXt|d| ƒ n
|| j|< d S )Nz'%s' redeclared as nonlocalz"no binding for nonlocal '%s' found)rÔ   r€   rh   r   rI   rÎ   r   )r6   r?   rA   rŸ  r¥   r0   r0   r1   r   Û  s    


zPyClassScope.declare_nonlocalc             C   s4   |   |¡rt|ddƒ n|  ¡  |¡}|| j|< d S )Nz'%s' redeclared  r   )rÔ   r   r¯   r  r   )r6   r?   rA   r¥   r0   r0   r1   r…  ê  s    
zPyClassScope.declare_globalc             C   s   | j  |¡S )N)rˆ   Úadd_default_value)r6   r@   r0   r0   r1   r±  ò  s    zPyClassScope.add_default_value)Nr>   r   r   r   )r9   r:   r;   r'  r®   r­  rÔ   rá   r   r…  r±  r0   r0   r0   r1   r¬  º  s    
r¬  c               @   s˜   e Zd ZdZdZdZdZdZdZdZ	dZ
dd„ Zdd„ Zdd„ Zd d
d„Zd!dd„Zd"dd„Zdd„ Zd#dd„Zd$dd„Zd%dd„Zdd„ Zdd„ ZdS )&rA  r   Fc             C   sF   t  | ||¡ |dkr6| tj|¡| _| tj|¡| _g | _g | _	d S )Nr   )
r§  r7   r«   r	   Zmethtab_prefixra  Zgstab_prefixZgetset_table_cnameÚproperty_entriesÚinherited_var_entries)r6   r?   rˆ   rR   r0   r0   r1   r7     s    zCClassScope.__init__c             C   sN   | j r| j dd¡sdS | jj}|r8|jd k	r8|j ¡ S | jjrJ| jj S dS )NZno_gcFT)	Úhas_cyclic_pyobject_attrsrB  r
  Úparent_typerÑ   r€   Úneeds_gcr“  Úis_gc_simple)r6   rÑ   r0   r0   r1   r¶    s    

zCClassScope.needs_gcc             C   s   |   ¡ o| j dd¡ 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.
        Zno_gc_clearF)r¶  rB  r
  )r6   r0   r0   r1   Úneeds_tp_clear%  s    zCClassScope.needs_tp_clearTc             C   s”   g }g }g }xl| j D ]b}|jjrL|s4| js4|jdkrv|s@|jjsv| |¡ q|jtjkrd| |¡ q|jj	r| |¡ qW |p„|p„|}||||ffS )Nr*   )
r—   r@   r  Úis_closure_class_scoper?   r·  r   r
   Zc_py_buffer_typerÃ   )r6   Zinclude_weakrefZinclude_gc_simpleZpy_attrsZ
py_buffersZmemoryview_slicesr¥   Zhave_entriesr0   r0   r1   Úget_refcounted_entries,  s    z"CClassScope.get_refcounted_entriesNr>   r   c	       
      C   s¤  |rX| j rt|dƒ | js2t|ƒr2t|d| ƒ |sJ|}|dkrJt|ƒ}|jrr|dkrr| |¡ |  t 	d¡¡ |  
|||||¡}	d|	_| j |	¡ |jr¤d| _nD|jr²d| _n6|jrè| jsÆ|dkrèd| _|jrâ|jrâ|j ¡ rèd| _|d	krþt|d
| ƒ |dkrNd|	_| js*|dkr*t|dƒ |jsT| | ¡sTt|d| ƒ nd|	_|	S |tkrft}tj| ||||||||d	}	d|	_d|	_d| jj  | _!|	S d S )NzVC attributes cannot be added in implementation part of extension type defined in a pxdz/The name '%s' is reserved for a special method.r>   r   z#include <new>r   Tr*   )r>   rÇ   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)r/   rR   rw   rê   rë   z(PyObject *)%s)"rˆ  r   r¹  r   r2   ra   ré   r  r   r«  rÆ   rX   r—   r   rÃ   Úhas_memoryview_attrsÚhas_cpp_class_attrsr  Úhas_pyobject_attrsr“  r€   r¶  r´  r|   Zcan_coerce_to_pyobjectr   r   r†   rá   rV   rU   rµ  rE  r2  )
r6   r?   r@   rA   r/   rR   rw   rê   rë   r¥   r0   r0   r1   rá   ?  s^    




zCClassScope.declare_varc             C   sª   |t kr"|  d¡rPt|d| ƒ n.|dkrPx$t D ]}|  |¡r0t|d| ƒ q0W |dkrbt|dƒ | j|t|dd}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   )rR   r   r   )r   rÔ   r   rá   r   r   rí   rt   r   r˜   r   )r6   r?   rA   rï   r  r¥   Zspecial_sigr0   r0   r1   rð   }  s&    




zCClassScope.declare_pyfunctionc             C   sD   | j s|dkrtdƒ}t | |¡}|r@|jr@| jjs@| jjs@d S |S )Nr¾  Z	__cinit__)r¹  r   r§  rÔ   r[   rµ  r“  rC  )r6   r?   r¥   r0   r0   r1   rÔ   ˜  s    
zCClassScope.lookup_herer0   c             C   s(  t |ƒr| jjst|dƒ |j}|jsd|s6t|dƒ n.| j |d j¡sdt|d|d j|| jf ƒ |  |¡}|d kr~t	|ƒ}|r”|j
sœt|d| dƒ nö|r´|jr´t|d| ƒ |jrÌ|jrÌt|dƒ nÆ|j|jdd	rü|j|jjkrü|j |j¡|_n–|j|jdd	r||j|jjkr|| jrd|sd|j|jddd
sdt|d|| jf dƒ t|jddƒ | j||||d|	d}nt|dƒ t|jdƒ n0| jr°t|d|| jf ƒ |  ||||||	¡}|rÚ|  tj|¡|_|
|_||_d|	kröd|_| jjs|js| j  !d¡r$d|_|j|_"|S )Nz7Special methods must be declared with 'def', not 'cdef'zC method has no self argumentr   zCSelf 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¿  Zas_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(   zPrevious declaration is hererº   )rR   rý   z2Signature not compatible with previous declarationzOC method '%s' not previously declared in definition part of extension type '%s'r'   Tr‡  )#r   rµ  r“  r   rÀ   Zis_static_methodZassignable_fromr@   rÔ   r2   rY   r   rk   r\   rr   Zsame_c_signature_asr.  rø   rù   rû   rˆ  Z!same_c_signature_as_resolved_typer¨  rA   rú   r«   r	   rö   rx   r¥   r]   rC  rB  r
  rm   )r6   r?   r@   rA   r/   rR   rw   rê   rÊ   rý   rx   rþ   rÀ   r¥   r0   r0   r1   r   §  s^    


"

zCClassScope.declare_cfunctionc       
   
   C   s4   |   |¡}tj| |||||||d}	d|	_||	_|	S )N)r  r   )rÔ   r§  rú   rZ   rz   )
r6   r?   r@   rA   r/   rR   rý   r  rz   r¥   r0   r0   r1   rú   å  s    
zCClassScope.add_cfunctionc             C   sN   t |ƒ}| j||d |d|d}t||tƒ}d|_d|_||_|j|_||_|S )Nr   )rR   rx   r   )	r   r   r<   r   rX   rS   rx   r€   ro   )r6   r?   r@   r/   rx   r¥   rÿ   r0   r0   r1   r?  î  s    z%CClassScope.declare_builtin_cfunctionc             C   s^   |   |¡}|d kr$|  ||t|d¡}d|_||_t||  ¡ | d|_| j|j_| j	 
|¡ |S )Nr>   r   )rˆ   r‰   )rÔ   rÆ   r   rc   rn   ÚPropertyScoper¯   r€   rµ  r²  r   )r6   r?   rn   rA   r¥   r0   r0   r1   Údeclare_propertyü  s    

zCClassScope.declare_propertyc          
      s.  ‡ fdd„}|j |j }x:|D ]2‰ |  ˆ j|ˆ jƒˆ jd d¡}d|_| j  |¡ qW x(|jd d … D ]‰ ˆ jj	rdˆ j 
¡  qdW xª|jD ] ‰ ˆ j}ˆ j}|ož|j}|s¬||ƒ}| jˆ jˆ jˆ j|ˆ jˆ jdd}d|_ˆ jrd|_ˆ j|_| j|jksþ|jrˆ j|_|rd|_||_ˆ jr†ˆ j|_q†W d S )Nc                s   dt jˆ jf S )Nz%s.%s)r	   r’  r/   )r/   )Ú
base_entryr0   r1   Úadapt	  s    z9CClassScope.declare_inherited_c_attributes.<locals>.adaptr>   r   T)r  )r³  r—   rÆ   r?   r/   r@   rX   r   r™   r  Z"get_all_specialized_function_typesro   rS   rú   rA   rR   rl   rr   r\   r]   r‰   rm   r[   rx   )r6   Ú
base_scoperÃ  r   r¥   r/   rÿ   rS   r0   )rÂ  r1   r  	  s@    

z*CClassScope.declare_inherited_c_attributes)FT)Nr>   r   r   r   )F)Nr>   r   r   r   r0   NF)F)N)r9   r:   r;   r(  r¹  r½  r»  r¼  r´  rˆ  rŽ  r7   r¶  r¸  rº  rá   rð   rÔ   r   rú   r?  rÁ  r  r0   r0   r0   r1   rA  ö  s.    
 
<
 
<
	
rA  c               @   sF   e Zd ZdZdZdZddd„Zddd„Zddd„Zdd„ Z	dd„ Z
dS )ÚCppClassScoper   Nc             C   sV   t  | ||d ¡ |j| _g | _|d k	rRx*|D ]"}|  ||t |¡d d¡}d|_q,W d S )Nr   r   )r†   r7   rB  r³  rÆ   r
   ZTemplatePlaceholderTyper_   )r6   r?   rˆ   rÚ   ÚTZtemplate_entryr0   r0   r1   r7   =	  s    
zCppClassScope.__init__r   r   c
             C   sÈ   |s|}|   |¡}
|	rb|
d k	rb|
j |¡r<|
j |j¡|
_qt|jrV| |
j¡rV||
_qtt|dƒ n|  |||||¡}
d|
_	|jr¤| jr¤| j 
¡ s¤d| j ¡ |f |
_|dkrÄ|	s¸|dkrÄ| j |
¡ |
S )Nz6Function signature does not match previous declarationr   z%s::%srß   z<init>)rÔ   r@   r÷   rø   rù   rY   rû   r   rÆ   rX   Zget_fused_typesZempty_declaration_coderk   r—   r   )r6   r?   r@   rA   r/   rR   rw   rê   rë   rÊ   r¥   r0   r0   r1   rá   G	  s"    

zCppClassScope.declare_varr0   Fc                s(  | j  d¡d }||dfkrh|d krhdtj|f }d}t ¡ |_|j|_dd„ ‰ ‡ fdd	„|jD ƒ|_n,|d
kr”|d kr”dtj|f }d}t ¡ |_|dkrâ|j	râx>| j
jD ]2}|j |¡}|r¬|j
j	s¬t|dƒ t|jdƒ q¬W |  |¡}| j||||||d}|r|s| ¡ |_|
|_||_|S )Nz::r¹   r7   z%s__init__%sz<init>c             S   s2   | j jr*| j js*t | jt | j ¡| j¡S | S d S )N)r@   ra   Zis_referencer
   rª  r?   Z
c_ref_typerA   )r  r0   r0   r1   Ú	maybe_refk	  s    z2CppClassScope.declare_cfunction.<locals>.maybe_refc                s   g | ]}ˆ |ƒ‘qS r0   r0   )rŸ   r  )rÇ  r0   r1   r  q	  s    z3CppClassScope.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 GILzBase constructor defined here.)rÊ   r/   rR   )r?   rv  r	   rö   r
   Z	CVoidTyper/  rÀ   Zoriginal_argsr.  r@   rÛ   r€   rÎ   r   rA   rÔ   rá   rK   rC   rx   r¥   )r6   r?   r@   rA   r/   rR   rw   rê   rÊ   rý   rx   rþ   r¨  ÚbaserÂ  rz   r¥   r0   )rÇ  r1   r   `	  s6    






zCppClassScope.declare_cfunctionc             C   s&  |j }|}xt|dd ƒr |j}qW t|dd ƒr@dd„ |jD ƒ}nd}xb|j|j D ]R}|jdkrbqR|j| jkrt|j |  |j|j	|j
d d¡}d|_d|_| j |¡ qRW x<|jD ]2}| j|j|j
|j|j	|jd	|j|jd
}d|_q°W x:|jD ]0}|j|krî|  |j|j
|j|j	|j¡}d|_qîW d S )NÚtemplate_typerÚ   c             S   s   g | ]
}|j ‘qS r0   )r?   )rŸ   rÆ  r0   r0   r1   r  Œ	  s    zBCppClassScope.declare_inherited_cpp_attributes.<locals>.<listcomp>r0   )z<init>z<del>r   r   r   )rw   rý   rx   )r€   rƒ   rÉ  rÚ   r³  r—   r?   r   rÆ   r/   r@   rX   rr   r   r™   r   rA   rR   rl   rx   r”   rÌ   )r6   rÝ   rÄ  rÉ  Zbase_templatesrÂ  r¥   r0   r0   r1   rÜ   †	  s>    




z.CppClassScope.declare_inherited_cpp_attributesc          	   C   s¸   t | j| jƒ}||_xž| j ¡ D ]}|jrN|j|j|j |¡|j	|j
dd q |jjrŽxX| ¡ D ](}|j|j|j |¡|j	|j
|jd q`W q | |j|j |¡|j	|j
|j¡ q W |S )Nr   )rË   )rx   )rÅ  r?   rˆ   r@   r   r|  r_   rÌ   r  rA   r/   rY   rK   r   rx   rá   rR   )r6   r|  Z
type_entryr€   r¥   r    r0   r0   r1   r  ­	  s,    



zCppClassScope.specialize)N)Nr   r   r   r   r   )Nr   r   r   r   r0   NF)r9   r:   r;   rÁ   Zdefault_constructorr@   r7   rá   r   rÜ   r  r0   r0   r0   r1   rÅ  5	  s   
 
 
$'rÅ  c               @   s   e Zd ZdZddd„ZdS )rÀ  r   Fc             C   s@   t |ƒ}|r.|  ||t|d¡}d|_||_|S t|dƒ d S d S )Nr>   r   zKOnly __get__, __set__ and __del__ methods allowed in a property declaration)r   rÆ   r   rt   rí   r   )r6   r?   rA   rï   rí   r¥   r0   r0   r1   rð   Ð	  s    
z PropertyScope.declare_pyfunctionN)F)r9   r:   r;   r,  rð   r0   r0   r0   r1   rÀ  È	  s   rÀ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚCConstScopec             C   s$   t  | d|j |j|j¡ || _d S )NZconst_)r†   r7   r?   rˆ   r‰   Úconst_base_type_scope)r6   rË  r0   r0   r1   r7   à	  s    zCConstScope.__init__c             C   s4   | j  |¡}|d k	r0t |¡}t |j¡|_|S d S )N)rË  rÔ   rŒ  r
   Zc_const_typer@   )r6   r?   r¥   r0   r0   r1   rÔ   è	  s
    
zCConstScope.lookup_hereN)r9   r:   r;   r7   rÔ   r0   r0   r0   r1   rÊ  Þ	  s   rÊ  c               @   s   e Zd Zdd„ ZdS )ÚTemplateScopec             C   s   t  | ||d ¡ |j| _d S )N)r†   r7   rB  )r6   r?   rˆ   r0   r0   r1   r7   ð	  s    zTemplateScope.__init__N)r9   r:   r;   r7   r0   r0   r0   r1   rÌ  ï	  s   rÌ  )3Z
__future__r   r½   rŒ  r¶   r4  r<  ÚImportErrorZErrorsr   r   r   ZStringEncodingr   r=   r   r	   r
   r   r   Z	TypeSlotsr   r   r   r   r   r   r   r‘   r.   r2   Úobjectr3   r<   r   r†   r0  r3  Zconst_counterrS  r¼   r¢  r¥  rl  r§  r¬  rA  rÅ  rÀ  rÊ  rÌ  r0   r0   r0   r1   Ú<module>   sn   	 :#     @r    nd<&#<  A 