AlkantarClanX12

Your IP : 3.147.73.85


Current Path : /lib64/python3.6/site-packages/cffi/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/cffi/__pycache__/cparser.cpython-36.pyc

3

M��ZR��@s�ddlmZddlmZmZddlmZmZyddlmZ	Wne
k
rXddl	Z	YnXddlZddlZddl
Z
y(e
jd#kr�ddlZnddlZej�ZWne
k
r�dZYnXdZejd	ejejB�Zejd
ejejB�Zejd�Zejd�Zejd
�Zejd�Zdaejdej�Zejd�Z ejd�Z!ejd�Z"ejd�Z#ejd�Z$ejd�Z%ejd�Z&dd�Z'dd�Z(dd�Z)dd�Z*dd �Z+Gd!d"�d"e,�Z-dS)$�)�model)�COMMON_TYPES�resolve_common_type)�FFIError�	CDefError)�
_pycparser�N�z<cdef source string>z/\*.*?\*/|//([^\n\\]|\\.)*?$z?^\s*#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)\b((?:[^\n\\]|\\.)*?)$z=\s*\.\.\.\s*[,}]|\.\.\.\s*\}z__dotdotdot\d+__$z\[\s*\.\.\.\s*\]z\w+|\Sz-?0?x?[0-9a-f]+[lu]*$z\b(__stdcall|WINAPI)\bz[(]\s*(__stdcall|WINAPI)\bz\b__cdecl\bz9\bextern\s*"(Python|Python\s*\+\s*C|C\s*\+\s*Python)"\s*.z'[*]\s*((const|volatile|restrict)\b\s*)+z3(\b(int|long|short|signed|unsigned|char)\s*)+\.\.\.z\b(double|float)\s*\.\.\.cCstdkrtj�atS)N)�
_parser_cache�	pycparserZCParser�rr�/usr/lib64/python3.6/cparser.py�_get_parser*srcCsg}x�tj|�}|sP|j|d|j���|jd�d}|j|j��|j�}|jd|�rn|jd�|d7}d}|}x`|t|�kr�||}|dkr�|d7}n.|dkr�|dkr�P|d8}n|dkr�|dkr�P|d7}qxW|||�|||d�}qW|j|�dj|�S)N�(�)�*rrz,;=�)	�_r_star_const_space�search�append�start�group�end�
startswith�len�join)�csource�parts�match�closing�endpos�level�i�crrr
�_workaround_for_old_pycparser0s<




 
r$cCs0g}�xtj|�}|sP|j�d}|j|d|j���d|jd�krT|jd�n
|jd�||dkr�|jd|�}|dkr�td��|jd|d|�dkr�td	��|j||d|��||dd�}nB|jd
|�}|dkr�td��|j|||d��||dd�}|jd�qW|j|�d
j	|�S)Nr�Cz(void __cffi_extern_python_plus_c_start; z!void __cffi_extern_python_start; �{�}rz!'extern "Python" {': no '}' foundz7cannot use { } inside a block 'extern "Python" { ... }'�;z'extern "Python": no ';' foundz  void __cffi_extern_python_stop;r)
�_r_extern_pythonrrrrr�findr�NotImplementedErrorr)rrrr rZ	semicolonrrr
�_preprocess_extern_pythonZs4



r,c	Cs�tjd|�}i}x6tj|�D](}|j�\}}|jdd�j�}|||<qWtjd|�}tjdkrft	|�}t
jd|�}tjd|�}tjd|�}t
|�}tjd|�}ttj|��}x�tt|��D]�\}}|j�}||dk�r|jd	||j��}||ks�t�d
|d|�|||dd�f}q�|||d�d	k�s4t�d|d|�|||dd�f}q�Wtjd
|�}tjd|�}|jd	d�|fS)N� z\
rz2.14z volatile volatile const(z volatile volatile const z[__dotdotdotarray__]�=z...z%s,__dotdotdot%d__ %sr	z%s __dotdotdot%d__ %sz __dotdotdotint__ z __dotdotdotfloat__ z __dotdotdot__ )�
_r_comment�sub�	_r_define�finditer�groups�replace�stripr�__version__r$�_r_stdcall2�_r_stdcall1�_r_cdeclr,�_r_partial_array�list�_r_partial_enum�	enumerate�reversedrr*r�AssertionError�_r_int_dotdotdot�_r_float_dotdotdot)	r�macrosrZ	macronameZ
macrovalueZmatchesZnumber�pZp2rrr
�_preprocess�s8
rDcCstt�}|jd�|jd�|jd�|jd�|jd�t�}d}d}d}x�tj|�D]�}||kr�|dkr�|r�|j|�|j|�d}nj|dkr�d	}d}nX|dkr�|d
7}nF|dkr�|d
8}n4|dkr�|r�|dkr�|j|�|j|�n
|j|�|}qXW|S)Nr(�,rr�typedefFrrTr)�setr�add�_r_words�findall�discard)rZlook_for_wordsZ
words_usedZ
is_typedefZparenZ
previous_wordZwordrrr
�_common_type_names�s>










rLc@s�eZdZdd�Zdd�Zdd�Zdd�Zd8d
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd9dd�Zdd �Zd:d"d#�Zd;d$d%�Zd<d&d'�Zd(d)�Zd=d*d+�Zd,d-�Zd>d.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd!S)?�ParsercCs:i|_t�|_d|_tj�|_i|_i|_g|_	d|_
dS)Nr)�
_declarationsrG�_included_declarations�_anonymous_counter�weakref�WeakKeyDictionary�_structnode2type�_options�_int_constants�_recomplete�_uses_new_feature)�selfrrr
�__init__�s
zParser.__init__cCs4t|�\}}t|�}g}x<t|j�D].}|jd�r$|dd�}|j|�|j|�q$W|t|�7}g}|jd�x|D]}|jd|�qvW|jd�|jdtf�|j|�dj|�}t	dk	r�t	j
�zJyt�j|�}	Wn4t
jjk
�r}
z|j|
|�WYdd}
~
XnXWdt	dk	�r(t	j�X|	||fS)Nztypedef �z*# 1 "<cdef automatic initialization code>"ztypedef int %s;z@typedef int __dotdotdotint__, __dotdotdotfloat__, __dotdotdot__;z# 1 "%s"�
)rDrL�sortedrNrrrK�CDEF_SOURCE_STRINGr�lock�acquirer�parserZc_parserZ
ParseError�convert_pycparser_error�release)rXrrBZctn�	typenames�name�csourcelines�typenameZfullcsource�ast�errr
�_parse�s4






"

z
Parser._parsecCsfd}t|�}tjdtf|�}|rbt|jd�d�}|j�}d|koPt|�knrb||d}|S)Nz	%s:(\d+):r�
)�str�rerr]�intr�
splitlinesr)rXrhr�line�msgrZlinenumrerrr
�_convert_pycparser_errorszParser._convert_pycparser_errorcCs@|j||�}t|�}|r*d|j�|f}n
d|f}t|��dS)Nzcannot parse "%s"
%szparse error
%s)rqrkr5r)rXrhrrorprrr
ra+s
zParser.convert_pycparser_errorFcCs0|j}z|||d�|_|j|�Wd||_XdS)N)�override�packed�	dllexport)rT�_internal_parse)rXrrrrsrtZprev_optionsrrr
r`5s
zParser.parsecCs$|j|�\}}}|j|�t|j�}x |D]}|jdkr*Pq*WdsFt�d}�yBd|_�x4|D�]*}|}t|tj	j
�r�|j|�q\t|tj	j��rf|js�t
d|��d}t|jjtj	j�r�|jjjdjd�r�|j|�}nxt|jtj	j��r6t|jjtj	j��r6t|jjjtj	j��r6|jjjjdjd��r6|j|�}n|j|j|jdd�\}}|jd	|j||d
�q\|jjdk�rvq\t
d|jj|��q\WWn�t
k
�r�}	z&t|	j�dk�r�|	j|f|	_�WYdd}	~	XnNtk
�r}	z0|j|	|�}
|
�r|	jdd
|
f|	_�WYdd}	~	XnXdS)N�
__dotdotdot__r�__cffi_extern_python_stopz!typedef does not declare any namerZ__dotdotdotT)rd�partial_length_okztypedef )�qualsZPragmazBunexpected <%s>: this construct is valid C but not valid in cdef()z
    *** Err: %s���rz)ri�_process_macros�iter�extrdr?�_inside_extern_python�
isinstancer�c_astZDecl�_parse_declZTypedefr�type�IdentifierType�namesr�_get_unknown_type�PtrDecl�TypeDecl�_get_unknown_ptr_type�_get_type_and_quals�_declare�	__class__�__name__r�argsrrq)rXrrgrB�iterator�declZcurrent_declryZrealtyperhrprrr
ru?sX




zParser._internal_parsecCs8||jkr*|j||krdStd|f��||j|<dS)Nz%multiple declarations of constant: %s)rUr)rX�key�valrrr
�_add_constantsus
zParser._add_constantscCs�|j�jd�}|jd�}|r(|dd�}|jd�rV|dkrV|jd�rVd|dd�}t|d�}|rj|}|j||�|jd||�dS)	NZul�-r�0�0xZ0orzmacro )�lower�rstriprrmr�r�)rXrdZint_str�negZpyvaluerrr
�_add_integer_constant}s

zParser._add_integer_constantcCshxb|j�D]V\}}|j�}tj|�r2|j||�q
|dkrL|jd||�q
td||||f��q
WdS)Nz...zmacro z�only supports one of the following syntax:
  #define %s ...     (literally dot-dot-dot)
  #define %s NUMBER  (with NUMBER an integer constant, decimal/hex/octal)
got:
  #define %s %s)�itemsr5�_r_int_literalrr�r�r)rXrBr��valuerrr
r{�s
zParser._process_macroscCsX|j||�}|jjd�rd}n$|jdkr.d}n|jdkr>d}nd}|j||j|�dS)Nrtzdllexport_python Z__cffi_extern_python_startzextern_python Z!__cffi_extern_python_plus_c_startzextern_python_plus_c z	function )�_get_type_pointerrT�getr~r�rd)rX�tpryr��tagrrr
�_declare_function�s

zParser._declare_functioncCs|j}t|tjj�rJ|j||jd�\}}t|tj�s8t	�|j
|||��n�t|tjj�rf|jd|�nHt|tjj
�r�|jd|�n,t|tjj�r�|jd|�n|js�td|��|j�r
|j|dd�\}}|jr�|j
|||��n*|j��r(t|d��r(t|jd	��r(tj|jj��r(|j|j|jj�n�|j��r�t|jtjj��r�|jjd
k�r�t|jjd	��r�tj|jjj��r�|j|jd
|jjj�n||tjk�r�|jjd��r�|j|_nX|jdk�r�td
��|tj@�r�|j�r�|j d|j||d�n|j d|j||d�dS)N)rd�struct�union�enumz'construct does not declare any variableT)rx�initr�r�Z__cffi_extern_python_rwz<cannot declare constants or variables with 'extern "Python"'z	constant )ryz	variable )!r�rrr��FuncDeclr�rdr�RawFunctionTyper?r��Struct�_get_struct_union_enum_type�Union�EnumrZis_raw_functionZis_integer_type�hasattrr�r�rr�r��UnaryOp�op�expr�	void_typerr~�Q_CONSTZ
is_array_typer�)rXr�Znoder�ryrrr
r��sP


zParser._parse_declcCs|j|�dS)Nr)�parse_type_and_quals)rX�cdeclrrr
�
parse_type�szParser.parse_typecCsb|jd|�dd�\}}|s$t�|jdjjjd}t|tjj	�rVt
d|jf��|j|j�S)Nzvoid __dummy(
%s
);�rrzunknown identifier '%s'rz)
rir?r}r�r��paramsrrr��IDrrdr�)rXr�rgrB�exprnoderrr
r��s
zParser.parse_type_and_qualsrcCsx||jkrF|j|\}}||kr,||kr,dS|jjd�sFtd|f��d|j�ksVt�||f|j|<|rt|jj|�dS)NrrzPmultiple declarations of %s (for interactive usage, try cdef(xx, override=True))rv)rNrTr�r�splitr?rOrH)rXrd�obj�includedryZprevobjZ	prevqualsrrr
r��s

zParser._declarecCsZd}t|tjjtjjf�rVd|jkr.|tjO}d|jkrB|tjO}d|jkrV|tj	O}|S)Nr�const�volatileZrestrict)
rrr�r�r�ryrr�Z
Q_VOLATILEZ
Q_RESTRICT)rXr�ryrrr
�_extract_quals�s






zParser._extract_qualsNcCsjt|tj�r|j�St|tj�r^|jjd�r^|jdd�j�r^|jdkr^|dk	r^tj	|||�Stj
||�S)N�$r)rrr��as_function_pointerZStructOrUnionOrEnumrdr�isdigit�	forcenameZNamedPointerType�PointerType)rXr�ry�declnamerrr
r�szParser._get_type_pointercCsHt|tjj�rtt|jtjj�rtt|jj�dkrtd|jjd|jkrt|jd|jjd\}}||j	|�O}||fSt|tjj
�r�|jdkr�d}n|j|j|d�}|j
|j|d�\}}tj||�|fSt|tjj��r|j
|j�\}}|j|||d�}|j	|�}||fSt|tjj��r�|j	|�}|j}	t|	tjj��rVt|	j�}
|
ddgk�ri}x<|
�r�|
d}|dk�r�|j|d�d||<|
d=nP�qVWg}x4dD],}
x$t|j|
d��D]}|j|
��q�W�q�W|
�s�dg}
|
dgk�r�d|k�s�d	|k�r�g}
||
}
dj|
�}|d
k�r"tj|fS|dk�r<td|jj��t||�\}}|||BfSt|	tjj��r||jd|	|�}||fSt|	tjj��r�|jd|	|�}||fSt|	tjj��r�|jd|	|�}||fSt|tjj ��r�|j!||�dfSt|tjj��r|jd||dd�dfSt|tjj��r4|jd||dd�dfStd|jj��dS)Nrztypedef r)rx)r��signed�char�short�long�unsignedrmr-�voidrvz:%d: bad usage of "..."r�r�r�T)�nestedz(:%d: bad or unsupported type declaration)r�r�r�r�)r�r�r�)"rrr�r�r�r�rr�rNr�Z	ArrayDeclZdim�_parse_constantr�r�	ArrayTyper�r�r;r��rangerrr�r�coordrorr�r�r�r�r��_parse_function_type)rX�typenoderdrxr�ryZlengthZitemtypeZ	itemqualsr�r��prefixesZnewnames�prefixr"ZidentZtp0Zquals0rrr
r�	s�











zParser._get_type_and_qualsc	s<tt|jdg��}x@t|�D]4\}}t|d�std|p8d|dt|dd�f��qWt|�dko�t|djt	j
j�o�t|djjt	j
j�o�|djjj
d	gk}|r�|j�|s�td
|p�d���fdd�|D�}|r�|tjgkr�g}�j|j�\}}	d}
t|jd
��r(|jjdd�dddgk�r(d}
tjt|�|||
�S)Nr�r�zt%s arg %d: unknown type '%s' (if you meant to use the old C syntax of giving untyped arguments, it is not supported)z
in expressionrrd�?rrvz=%s: a function with only '(...)' as argument is not correct Ccsg|]}�j�j|j���qSr)�_as_func_argr�r�)�.0Zargdeclnode)rXrr
�
<listcomp>|sz/Parser._parse_function_type.<locals>.<listcomp>ryr	r�r�Z	__stdcallrzrzrz���)r;�getattrr�r=r�rrrr�rr�r�r�r��poprr�r�ryr��tuple)rXr��funcnamer�r"�argZellipsisr��resultry�abir)rXr
r�gs6


zParser._parse_function_typecCs6t|tj�rtj|j|�St|tj�r.|j�S|SdS)N)rrr�r��itemr�r�)rXr�ryrrr
r��s
zParser._as_func_argc
Cs,y
|j|Stk
rYnX|}|j}|dkrb|dk	rDd|}n|jd7_d|j}d}n"|}d||f}|jj|d�\}}	|dk�r|dkr�tj|ddd�}nP|dkr�tj|ddd�}n6|dkr�|dkr�t	d	��|j
||j�}ntd
|f��|dk	�r2|j
||�n"|dk�r2|jdk	�r2td|��|j�sD|j|�|j�rjd|jk�rj|j
d
|j|�||j|<|dk�r�|S|jdk�r�|S|jdk	�r�t	d|��g}
g}g}g}
x�|jD]�}t|jtjj��r�dj|jj�dk�r�|j||��q�|jdk�rd}n|j|j�}d|_|j|jdd�\}}|j�rH|j||�t|tj��rj|j�rj|j||�|
j |j�pxd�|j |�|j |�|
j |��q�Wt!|
�|_t!|�|_"t!|�|_#t!|
�|_$|dgt%|�k�rt|tj��r|j�rtd|f��|j&jd�|_'|j(�r(d|_(|j)j |�|S)Nz$%srz$%dz%s %sr�r�r�rvz!Enums cannot be declared with ...z	kind = %rz^enum %s: the '{}' declaration should appear on the first time the enum is mentioned, not laterr�zanonymous %sz"duplicate declaration of struct %srFT)rxz#%s: using both bitfields and '...;'rsr)NNrzrz)*rS�KeyErrorrdrPrNr�rZ
StructTypeZ	UnionTyper�_build_enum_type�valuesr?r�r+r�Zforce_the_name�decls�fldnamesrr�rr�r�rr��
_make_partial�bitsizer��_partial_lengthr��partialrr��fldtypes�
fldbitsize�fldqualsrrTrsZ	completedrV)rX�kindr�rdr�Z
force_name�
explicit_namer�r��_r�r�r�r�r�r�Zfqualrrr
r��s�	















z"Parser._get_struct_union_enum_typecCsBt|tj�std|f��|j�r8|r8td|f��d|_dS)Nz%s cannot be partialz%s is partial but has no C nameT)rrZ
StructOrUnionrZ
has_c_namer+r�)rXr�r�rrr
r�s
zParser._make_partialcCs�t|tjj�r�|j}|jd�rF|jd�s2|jd�r<t|d�St|d�Sd|dko\dknrlt|d	�S|dd
kr�|dd
kr�t|�dks�t|�d
kr�|ddkr�t|d�St	d|f��t|tjj
�r�|jdkr�|j|j
�St|tjj
��r|jdk�r|j|j
�St|tjj��r:|j|jk�r:|j|jSt|tjj��rv|jdk�rv|�rfd|_dStd|jj��t|tjj��r�|jdk�r�|j|j�|j|j�St|tjj��r�|jdk�r�|j|j�|j|j�Std|jj��dS)Nr�r�Z0X�rZ�1r�9rj�'rr	��\r�zinvalid constant %r�+r�Z__dotdotdotarray__Tz...zT:%d: unsupported '[...]' here, cannot derive the actual array length in this contextz?:%d: unsupported expression: expected a simple numeric constantrz���)rrr�ZConstantr�rrmr�ordrr�r�r�r�r�rdrUr�rr�roZBinaryOp�left�right)rXr�rx�srrr
r�sL



$


zParser._parse_constantc	Cs�|dk	r�d}g}g}d}xb|jD]X}tj|j�r6d}q |jdk	rL|j|j�}|j|j�|j|�|j|j|�|d7}q Wt|�}t|�}t	j
|||�}||_nt	j
|ff�}|S)NFrTr)�enumerators�_r_enum_dotdotdotrrdr�r�rr�r�rZEnumTyper�)	rXr�r�r�r�Z
enumvaluesZ
nextenumvaluer�r�rrr
r�Bs*

zParser._build_enum_typecCszxP|jj�D]B\}\}}|jd�r$q|jdd�d}|dkr|j||d
|d�qWx"|jj�D]\}}|j||�q^WdS)
Nzanonymous $enum_$r-rrr�r�r��	anonymousrFT)r�ry)r�r�r�r�rF)rNr�rr�r�rUr�)rX�otherrdr�ryr��k�vrrr
�includeZs
zParser.includecCs�|jjj}|dgkr tj|j�S|dgkrL|jdkr@d|j|_tj|j�S|dgkrx|jdkrld|j|_tj|j�Std|j	j
��dS)NrvZ__dotdotdotint__z'typedef int... %s'Z__dotdotdotfloat__z'typedef float... %s'z*:%d: unsupported usage of "..." in typedef)r�r�rZunknown_typerdrWZUnknownIntegerTypeZUnknownFloatTyperr�ro)rXr�rcrrr
r�ds





zParser._get_unknown_typecCs2|jjjjdgkrtj|j�Std|jj��dS)Nrvz*:%d: unsupported usage of "..." in typedef)r�r�rZunknown_ptr_typerdrr�ro)rXr�rrr
r�wszParser._get_unknown_ptr_type)FFF)Fr)N)NF)N)NF)F)r��
__module__�__qualname__rYrirqrar`rur�r�r{r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rrrr
rM�s4
&


62

	
^
#
v
3
rM)r	).rrZcommontypesrr�errorrrrr�ImportErrorrQrl�sys�version_infoZthread�_thread�
allocate_lockr^r]�compile�DOTALL�	MULTILINEr/r1r<r�r:rIr
�
IGNORECASEr�r8r7r9r)rr@rArr$r,rDrL�objectrMrrrr
�<module>sN












*27(