Your IP : 3.137.177.204


Current Path : /usr/lib64/python3.6/site-packages/cffi/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/site-packages/cffi/__pycache__/cparser.cpython-36.opt-1.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]v\}}|j�}||dk�r|jd	||j��}d
|d|�|||dd�f}q�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�_r_int_dotdotdot�_r_float_dotdotdot)	r�macrosrZ	macronameZ
macrovalueZmatchesZnumber�pZp2rrr
�_preprocess�s4
rCcCstt�}|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>










rKc@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)�
_declarationsrF�_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"�
)rCrK�sortedrMrrrJ�CDEF_SOURCE_STRINGr�lock�acquirer�parserZc_parserZ
ParseError�convert_pycparser_error�release)rWrrAZctn�	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)rWrgr�line�msgrZlinenumrdr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)rprjr5r)rWrgrrnrorrr
r`+s
zParser.convert_pycparser_errorFcCs0|j}z|||d�|_|j|�Wd||_XdS)N)�override�packed�	dllexport)rS�_internal_parse)rWrrqrrrsZprev_optionsrrr
r_5s
zParser.parsecCs|j|�\}}}|j|�t|j�}x|D]}|jdkr*Pq*Wd}�yBd|_�x4|D�]*}|}t|tjj	�rx|j
|�qTt|tjj��r^|js�td|��d}t|j
j
tjj�r�|j
j
jdjd�r�|j|�}nxt|j
tjj��r.t|j
j
tjj��r.t|j
j
j
tjj��r.|j
j
j
jdjd��r.|j|�}n|j|j
|jdd�\}}|jd	|j||d
�qT|jjdk�rnqTtd|jj|��qTWWn�tk
�r�}	z&t|	j�dk�r�|	j|f|	_�WYdd}	~	XnNtk
�r}	z0|j|	|�}
|
�r|	jdd
|
f|	_�WYdd}	~	XnXdS)N�
__dotdotdot__�__cffi_extern_python_stopz!typedef does not declare any namerrZ__dotdotdotT)rc�partial_length_okztypedef )�qualsZPragmazBunexpected <%s>: this construct is valid C but not valid in cdef()z
    *** Err: %s���ry)rh�_process_macros�iter�extrc�_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�argsrrp)rWrrfrA�iterator�declZcurrent_declrxZrealtypergrorrr
rt?sV




zParser._internal_parsecCs8||jkr*|j||krdStd|f��||j|<dS)Nz%multiple declarations of constant: %s)rTr)rW�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�rstriprrlr�r�)rWrcZint_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)rWrAr��valuerrr
rz�s
zParser._process_macroscCsX|j||�}|jjd�rd}n$|jdkr.d}n|jdkr>d}nd}|j||j|�dS)Nrszdllexport_python Z__cffi_extern_python_startzextern_python Z!__cffi_extern_python_plus_c_startzextern_python_plus_c z	function )�_get_type_pointerrS�getr}r�rc)rW�tprxr��tagrrr
�_declare_function�s

zParser._declare_functioncCs�|j}t|tjj�r:|j||jd�\}}|j|||��n�t|tjj�rV|j	d|�nHt|tjj
�rr|j	d|�n,t|tjj�r�|j	d|�n|js�td|��|j�r�|j|dd�\}}|j
r�|j|||��n$|j�o�t|d�o�t|jd	�o�tj|jj��r|j|j|jj�n�|j��rxt|jtjj��rx|jjd
k�rxt|jjd	��rxtj|jjj��rx|j|jd
|jjj�n||tjk�r�|jjd��r�|j|_nX|jdk�r�td
��|tj@�r�|j�r�|jd|j||d�n|jd|j||d�dS)N)rc�struct�union�enumz'construct does not declare any variableT)rw�initr�r�Z__cffi_extern_python_rvz<cannot declare constants or variables with 'extern "Python"'z	constant )rxz	variable )r�r~rr�FuncDeclr�rcr��Struct�_get_struct_union_enum_type�Union�EnumrZis_raw_functionZis_integer_type�hasattrr�r�rr�r��UnaryOp�op�exprr�	void_typerr}�Q_CONSTZ
is_array_typer�)rWr�Znoder�rxrrr
r��sN


zParser._parse_declcCs|j|�dS)Nr)�parse_type_and_quals)rW�cdeclrrr
�
parse_type�szParser.parse_typecCsX|jd|�dd�\}}|jdjjjd}t|tjj�rLt	d|j
f��|j|j�S)Nzvoid __dummy(
%s
);�rrzunknown identifier '%s'ry)rhr|r�r��paramsr~rr�IDrrcr�)rWr�rfrA�exprnoderrr
r��s
zParser.parse_type_and_qualsrcCsh||jkrF|j|\}}||kr,||kr,dS|jjd�sFtd|f��||f|j|<|rd|jj|�dS)NrqzPmultiple declarations of %s (for interactive usage, try cdef(xx, override=True)))rMrSr�rrNrG)rWrc�obj�includedrxZprevobjZ	prevqualsrrr
r��s

zParser._declarecCsZd}t|tjjtjjf�rVd|jkr.|tjO}d|jkrB|tjO}d|jkrV|tj	O}|S)Nr�const�volatileZrestrict)
r~rrr�r�rxrr�Z
Q_VOLATILEZ
Q_RESTRICT)rWr�rxr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)r~r�RawFunctionType�as_function_pointerZStructOrUnionOrEnumrcr�isdigit�	forcenameZNamedPointerType�PointerType)rWr�rx�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)rw)r��signed�char�short�long�unsignedrlr-�voidruz:%d: bad usage of "..."r�r�r�T)�nestedz(:%d: bad or unsupported type declaration)r�r�r�r�)r�r�r�)"r~rrr�r�r�rr�rMr�Z	ArrayDeclZdim�_parse_constantr�r�	ArrayTyper�r�r;r��rangerrr�r�coordrnrr�r�r�r�r��_parse_function_type)rW�typenodercrwr�rxZlengthZitemtypeZ	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 expressionrrc�?rruz=%s: a function with only '(...)' as argument is not correct Ccsg|]}�j�j|j���qSr)�_as_func_argr�r�)�.0Zargdeclnode)rWrr
�
<listcomp>|sz/Parser._parse_function_type.<locals>.<listcomp>rxr	r�r�Z	__stdcallryryry���)r;�getattrr�r=r�rrr~r�rrr�r�r��poprr�r�rxr��tuple)rWr��funcnamer�r"�argZellipsisr��resultrx�abir)rWr
r�gs6


zParser._parse_function_typecCs6t|tj�rtj|j|�St|tj�r.|j�S|SdS)N)r~rr�r��itemr�r�)rWr�rxr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�ruz!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)rwz#%s: using both bitfields and '...;'rrr)NNryry)*rR�KeyErrorrcrOrMr�rZ
StructTypeZ	UnionTyper�_build_enum_type�values�AssertionErrorr�r+r�Zforce_the_name�decls�fldnamesr~r�rrr�rr��
_make_partial�bitsizer��_partial_lengthr��partialrr��fldtypes�
fldbitsize�fldqualsrrSrrZ	completedrU)rW�kindr�rcr�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)r~rZ
StructOrUnionrZ
has_c_namer+r�)rWr�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�rY�1r�9ri�'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 constantry���)r~rrZConstantr�rrlr�ordrr�r�r�r�r�rcrTr�rr�rnZBinaryOp�left�right)rWr�rw�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_dotdotdotrrcr�r�rr�r�rZEnumTyper�)	rWr�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��	anonymousrET)r�rx)r�r�r�r�rE)rMr�r�splitr�rTr�)rW�otherrcr�rxr��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)NruZ__dotdotdotint__z'typedef int... %s'Z__dotdotdotfloat__z'typedef float... %s'z*:%d: unsupported usage of "..." in typedef)r�r�rZunknown_typercrVZUnknownIntegerTypeZUnknownFloatTyperr�rn)rWr�rbrrr
r�ds





zParser._get_unknown_typecCs2|jjjjdgkrtj|j�Std|jj��dS)Nruz*:%d: unsupported usage of "..." in typedef)r�r�rZunknown_ptr_typercrr�rn)rWr�rrr
r�wszParser._get_unknown_ptr_type)FFF)Fr)N)NF)N)NF)F)r��
__module__�__qualname__rXrhrpr`r_rtr�r�rzr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�rrrr
rL�s4
&


62

	
^
#
v
3
rL)r	).rrZcommontypesrr�errorrrrr�ImportErrorrPrk�sys�version_infoZthread�_thread�
allocate_lockr]r\�compile�DOTALL�	MULTILINEr/r1r<r�r:rHr
�
IGNORECASEr�r8r7r9r)rr?r@rr$r,rCrK�objectrLrrrr
�<module>sN












*27(

?>