ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/cffi/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/cffi/__pycache__/cparser.cpython-38.pyc

U

ل=^W��@s�ddlmZddlmZmZddlmZmZzddlmZ	Wne
k
rXddl	Z	YnXddlZddlZddl
Z
z(e
jdkr�ddlZnddlZe��ZWne
k
r�dZYnXdd	�Zd
Ze�dejejB�Ze�dejejB�Ze�d
�Ze�d�Ze�d�Ze�d�Zdae�dej�Z e�d�Z!e�d�Z"e�d�Z#e�d�Z$e�d�Z%e�d�Z&e�d�Z'dd�Z(dd�Z)dd�Z*dd �Z+d!d"�Z,d#d$�Z-d%d&�Z.Gd'd(�d(e/�Z0dS))�)�model)�COMMON_TYPES�resolve_common_type)�FFIError�	CDefError)�
_pycparser�N)�cCsddl}ddl}dS�Nr)Zpycparser.yacctabZpycparser.lextab)�	pycparser�r�/cparser.py�%_workaround_for_static_import_finderssrz<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*\.\.\.cCstdkrt��atS�N)�
_parser_cacherZCParserrrrr
�_get_parser1srcCsg}t�|�}|sq�|�|d|����|�d�d}|�|���|��}|�d|�rl|�d�|d7}d}|}|t|�kr�||}|dkr�|d7}n.|dkr�|dkr�q�|d8}n|dkr�|dkr�q�|d7}qt|||�|||d�}q|�|�d�|�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_pycparser7s:






r'cCs,g}t�|�}|s�q|��d}|�|d|����d|�d�krR|�d�n
|�d�||dkr�|�d|�}|dkr�td��|�d|d|�dkr�td	��|�||d|��||dd�}nB|�d
|�}|dkr�td��|�|||d��||dd�}|�d�q|�|�d
�	|�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)rr r!r#r"Z	semicolonrrr
�_preprocess_extern_pythonas2



r/cCsJd|krdS|��D]0}d|kr|���d�sddl}|�d�qFqdS)N�"�#rz�String literal found in cdef() or type source. String literals are ignored here, but you should remove them anyway because some character sequences confuse pre-parsing.)�
splitlines�lstripr�warnings�warn)r�liner4rrr
�_warn_for_string_literal�s
r7cCs$|js ddl}|�d|jf�dS)NrzrGlobal variable '%s' in cdef(): for consistency with C it should have a storage class specifier (usually 'extern'))Zstorager4r5�name)�declr4rrr
�/_warn_for_non_extern_non_static_global_variable�s
�r:c	Cs�t�d|�}i}t�|�D](}|��\}}|�dd���}|||<qt�d|�}tjdkrbt	|�}t
�d|�}t�d|�}t�d|�}t
|�}t|�t�d|�}tt�|��}tt|��D]�\}}|��}||dk�r|�d	||���}||ks�t�d
|d|�|||dd�f}q�|||d�d	k�s6t�d|d|�|||dd�f}q�t�d
|�}t�d|�}|�d	d�|fS)N� z\
rz2.14z volatile volatile const(z volatile volatile const z[__dotdotdotarray__]�=�...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/r7�_r_partial_array�list�_r_partial_enum�	enumerate�reversedrr-r�AssertionError�_r_int_dotdotdot�_r_float_dotdotdot)	r�macrosr!Z	macronameZ
macrovalueZmatchesZnumber�pZp2rrr
�_preprocess�s>

��rScCs�tt�}|�d�|�d�|�d�|�d�|�d�t�}d}d}d}t�|�D]�}||kr�|dkr�|r�|�|�|�|�d}nj|dkr�d	}d}nX|dkr�|d
7}nF|dkr�|d
8}n4|dkr�|r�|dkr�|�|�|�|�n
|�|�|}qV|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>










r[c@s�eZdZdd�Zdd�Zdd�Zdd�Zd:dd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd;dd�Zd d!�Zd<d"d#�Zd=d$d%�Zd>d&d'�Zd(d)�Zd?d*d+�Zd,d-�Zd@d.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd
S)A�ParsercCs:i|_t�|_d|_t��|_i|_i|_g|_	d|_
dSr
)�
_declarationsrV�_included_declarations�_anonymous_counter�weakref�WeakKeyDictionary�_structnode2type�_options�_int_constants�_recomplete�_uses_new_feature��selfrrr
�__init__
s
zParser.__init__c
Cs,t|�\}}t|�}g}t|j�D].}|�d�r"|dd�}|�|�|�|�q"|t|�7}g}|�d�|D]}|�d|�qp|�d�|�dtf�|�|�d�|�}t	dk	r�t	�
�zJzt��
|�}	Wn4tjjk
�r}
z|�|
|�W5d}
~
XYnXW5t	dk	�r t	��X|	||fS)N�typedef �z*# 1 "<cdef automatic initialization code>"ztypedef int %s;z@typedef int __dotdotdotint__, __dotdotdotfloat__, __dotdotdot__;z# 1 "%s"�
)rSr[�sortedr]rrrZ�CDEF_SOURCE_STRINGr�lock�acquire�releaser�parserZc_parserZ
ParseError�convert_pycparser_error)rhrrQZctn�	typenamesr8�csourcelines�typenameZfullcsource�ast�errr
�_parses4





"

z
Parser._parsecCsfd}t|�}t�dtf|�}|rbt|�d�d�}|��}d|krRt|�krbnn||d}|S)Nz	%s:(\d+):r�
)�str�rer!rn�intrr2r)rhrxrr6�msgr!Zlinenumrurrr
�_convert_pycparser_error:szParser._convert_pycparser_errorcCs@|�||�}t|�}|r*d|��|f}n
d|f}t|��dS)Nzcannot parse "%s"
%szparse error
%s)rr{rDr)rhrxrr6r~rrr
rsHs
zParser.convert_pycparser_errorFNcCsz|r&|dkrtd��|r td��d}n$|rF||d@rJtd|f��nd}|j}z|||d�|_|�|�W5||_XdS)NTzB'packed' should be False or True; use 'pack' to give another valuez$cannot give both 'pack' and 'packed'rz%'pack' must be a power of two, not %rr)�override�packed�	dllexport)�
ValueErrorrc�_internal_parse)rhrr�r��packr�Zprev_optionsrrr
rrRs(��zParser.parsec
Cs|�|�\}}}|�|�t|j�}|D]}|jdkr(qDq(dsDt�d}�z<d|_|D�]*}|}t|tj	j
�rz|�|�qVt|tj	j��r`|js�t
d|��d}t|jjtj	j�r�|jjjd�d�r�|�|�}nxt|jtj	j��r0t|jjtj	j��r0t|jjjtj	j��r0|jjjjd�d��r0|�|�}n|j|j|jdd�\}}|jd	|j||d
�qV|jjdk�rpqVt
d|jj|��qVWn�t
k
�r�}	z$t|	j�d
k�r�|	j|f|	_�W5d}	~	XYnNtk
�r}	z.|�|	|�}
|
�r|	jdd|
f|	_�W5d}	~	XYnXdS)N�
__dotdotdot__r�__cffi_extern_python_stopz!typedef does not declare any name���Z__dotdotdotT)r8�partial_length_okrj��qualsZPragmazBunexpected <%s>: this construct is valid C but not valid in cdef()rz
    *** Err: %s)ry�_process_macros�iter�extr8rN�_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�argsrr)rhrrwrQ�iteratorr9Zcurrent_declr�Zrealtyperxr~rrr
r�jsp



���
����
��
zParser._internal_parsecCs8||jkr*|j||krdStd|f��||j|<dS)Nz%multiple declarations of constant: %s)rdr)rh�key�valrrr
�_add_constants�s
�zParser._add_constantscCs�|���d�}|�d�}|r(|dd�}|�d�rT|dkrT|�d�sTd|dd�}t|d�}|rh|}|�||�|�d||�dS)	NZul�-r�0�0xZ0or�macro )�lower�rstriprr}r�r�)rhr8Zint_str�negZpyvaluerrr
�_add_integer_constant�s
�
zParser._add_integer_constantcCsd|��D]V\}}|��}t�|�r0|�||�q|dkrJ|�d||�qtd||||f��qdS)Nr=r�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)�itemsrD�_r_int_literalr!r�r�r)rhrQr��valuerrr
r��s

��zParser._process_macroscCsX|�||�}|j�d�rd}n$|jdkr.d}n|jdkr>d}nd}|�||j|�dS)Nr�zdllexport_python Z__cffi_extern_python_startzextern_python Z!__cffi_extern_python_plus_c_startzextern_python_plus_c z	function )�_get_type_pointerrc�getr�r�r8)rh�tpr�r9�tagrrr
�_declare_function�s

zParser._declare_functioncCs|j}t|tjj�rJ|j||jd�\}}t|tj�s8t	�|�
|||��n�t|tjj�rf|�d|�nHt|tjj
�r�|�d|�n,t|tjj�r�|�d|�n|js�td|��|j�r|j|dd�\}}|jr�|�
|||��n0|���r(t|d��r(t|jd	��r(t�|jj��r(|�|j|jj�n�|���r�t|jtjj��r�|jjd
k�r�t|jjd	��r�t�|jjj��r�|�|jd
|jjj�n�|tjk�r�|j�d��r�|j|_n^|jdk�r�td
��|tj@�r�|j�s�|j d|j||d�nt!|�|j d|j||d�dS)N)r8�struct�union�enumz'construct does not declare any variableT�r��initr�r�Z__cffi_extern_python_r�z<cannot declare constants or variables with 'extern "Python"'z	constant r�z	variable )"r�r�rr��FuncDeclr�r8r�RawFunctionTyperNr��Struct�_get_struct_union_enum_type�Union�EnumrZis_raw_functionZis_integer_type�hasattrr�r�r!r�r��UnaryOp�op�expr�	void_typerr��Q_CONSTZ
is_array_typer�r:)rhr9Znoder�r�rrr
r��sj��

�
��
�
����
�
�zParser._parse_declcCs|�|�dSr
)�parse_type_and_quals)rh�cdeclrrr
�
parse_typeszParser.parse_typecCs`|�d|�dd�\}}|r"t�|jdjjjd}t|tjj	�rTt
d|jf��|�|j�S)Nzvoid __dummy(
%s
);�r�rzunknown identifier '%s')
ryrNr�r�r��paramsr�rr��IDrr8r�)rhr�rwrQ�exprnoderrr
r�
szParser.parse_type_and_qualsrcCsx||jkrF|j|\}}||kr,||kr,dS|j�d�sFtd|f��d|��ksVt�||f|j|<|rt|j�|�dS)Nr�zPmultiple declarations of %s (for interactive usage, try cdef(xx, override=True))r�)r]rcr�r�splitrNr^rW)rhr8�obj�includedr�ZprevobjZ	prevqualsrrr
r�s
��zParser._declarecCsZd}t|tjjtjjf�rVd|jkr.|tjO}d|jkrB|tjO}d|jkrV|tj	O}|S)Nr�const�volatileZrestrict)
r�rr�r�r�r�rr�Z
Q_VOLATILEZ
Q_RESTRICT�rhr�r�rrr
�_extract_quals s
�





zParser._extract_qualscCsjt|tj�r|��St|tj�r^|j�d�r^|jdd���r^|jdkr^|dk	r^t�	|||�St�
||�S)N�$r)r�rr��as_function_pointerZStructOrUnionOrEnumr8r�isdigit�	forcenameZNamedPointerType�PointerType)rhr�r��declnamerrr
r�,s
����zParser._get_type_pointercCs>t|tjj�rtt|jtjj�rtt|jj�dkrtd|jjd|jkrt|jd|jjd\}}||�	|�O}||fSt|tjj
�r�|jdkr�d}n|j|j|d�}|j
|j|d�\}}t�||�|fSt|tjj��r|�
|j�\}}|j|||d�}|�	|�}||fSt|tjj��r�|�	|�}|j}	t|	tjj��rLt|	j�}
|
ddgk�r�i}|
�r�|
d}|dk�r�|�|d�d||<|
d=n�q��qTg}d	D](}
t|�|
d��D]}|�|
��q��q�|
�s�d
g}
|
d
gk�r�d|k�s�d|k�r�g}
||
}
d
�|
�}|dk�rtj|fS|dk�r2td|jj��t||�\}}|||BfSt|	tjj��rr|�d|	|�}||fSt|	tjj��r�|�d|	|�}||fSt|	tjj��r�|�d|	|�}||fSt|tjj ��r�|�!||�dfSt|tjj��r|jd||dd�dfSt|tjj��r*|jd||dd�dfStd|jj��dS)Nrrjrr�)r��signed�char)�short�longr��unsigned)r�r�r�r}r�r�r;Zvoidr�z:%d: bad usage of "..."r�r�r�T)�nestedz(:%d: bad or unsupported type declaration)"r�rr�r�r�r�rr�r]r�Z	ArrayDeclZdim�_parse_constantr�r�	ArrayTyper�r�rJr��rangerrr�r�coordr6rr�r�r�r�r��_parse_function_type)rh�typenoder8r�r�r�ZlengthZitemtypeZ	itemqualsr�r��prefixesZnewnames�prefixr%ZidentZtp0Zquals0rrr
r�5s����
��








�
��
���zParser._get_type_and_qualsc	s6tt|jdg��}t|�D]4\}}t|d�std|p6d|dt|dd�f��qt|�dko�t|d	jt	j
j�o�t|d	jjt	j
j�o�|d	jjj
d
gk}|r�|��|s�td|p�d���fdd
�|D�}|s�|tjgkr�g}��|j�\}}	d}
t|jd��r"|jjdd�dddgk�r"d}
t�t|�|||
�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 expressionrr8�?rr�r�z=%s: a function with only '(...)' as argument is not correct Ccsg|]}�j��|j���qSr)�_as_func_argr�r�)�.0Zargdeclnodergrr
�
<listcomp>�s�z/Parser._parse_function_type.<locals>.<listcomp>r����r�r�Z	__stdcall)rJ�getattrr�rLr�rrr�r�rr�r�r�r��poprr�r�r�r��tuple)rhr��funcnamer�r%�argZellipsisr��resultr�Zabirrgr
r��sH

��������
�zParser._parse_function_typecCs6t|tj�rt�|j|�St|tj�r.|��S|SdSr)r�rr�r��itemr�r�r�rrr
r��s
zParser._as_func_argcCs*z|j|WStk
r YnX|}|j}|dkrd|dk	rFd|}n|jd7_d|j}d}n"|}d||f}|j�|d�\}}	|dk�r|dkr�t�|ddd�}nP|dkr�t�|ddd�}n6|dkr�|d	kr�t	d
��|�
||j�}ntd|f��|dk	�r4|�
||�n"|dk�r4|jdk	�r4td|��|j�sF|�|�|j�rld
|jk�rl|�
d|j|�||j|<|dk�r�|S|jdk�r�|S|jdk	�r�t	d|��g}
g}g}g}
|jD]�}t|jtjj��r�d�|jj�d	k�r�|�||��q�|jdk�rd}n|�|j�}d|_|j|jdd�\}}|j�rH|�||�t|tj��rj|j�rj|�||�|
� |j�pxd�|� |�|� |�|
� |��q�t!|
�|_t!|�|_"t!|�|_#t!|
�|_$|dgt%|�k�r�t|tj��r�|j�r�td|f��|j&�d�|_'|j(�r&d|_(|j)� |�|S)Nz$%srz$%dz%s %s)NNr�r�r�r�z!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 %srr�FTr�z#%s: using both bitfields and '...;'r�r)*rb�KeyErrorr8r_r]r�rZ
StructTypeZ	UnionTyper�_build_enum_type�valuesrNr�r.r�Zforce_the_name�decls�fldnamesr�r�rr�r�rr��
_make_partial�bitsizer��_partial_lengthr��partialrr��fldtypes�
fldbitsize�fldqualsrrcr�Z	completedre)rh�kindr�r8r�Z
force_name�
explicit_namer�r��_r�r�r�r�r9r�Zfqualrrr
r��s�	




��



��






�z"Parser._get_struct_union_enum_typecCs>t|tj�std|f��|��s4|s4td|f��d|_dS)Nz%s cannot be partialz%s is partial but has no C nameT)r�rZ
StructOrUnionrZ
has_c_namer.r�)rhr�r�rrr
r�4s
zParser._make_partialcCst|tjj��r8|j}d|dkr.dkr�nn�|�d�}z&|�d�rTt|d�WSt|d�WSWndtk
r�t	|�dkr�|�
�dd�d	kr�t|d
�YS|�
�dd�dkr�t|d�YSYnXtd|f��n`|dd
k�r*|dd
k�r*t	|�dk�st	|�dk�r*|ddk�r*t|d�Std|f��t|tjj
��r`|jdk�r`|�|j�St|tjj
��r�|jdk�r�|�|j�St|tjj��r�|j|jk�r�|j|jSt|tjj��r�|jdk�r�|�r�d|_dStd|jj��t|tjj��r�|�|j�}|�|j�}|jdk�r,||S|jdk�r@||S|jdk�rT||S|jdk�rl|�||�S|jdk�r�||�||�|S|jdk�r�||>S|jdk�r�||?S|jdk�r�||@S|jdk�r�||BS|jd k�r�||AStd!|jj��dS)"Nr�r�9ZuUlLrkrzrr�r��Z0bzinvalid constant %r�'r�r	��\����+r�Z__dotdotdotarray__Tr=zT:%d: unsupported '[...]' here, cannot derive the actual array length in this contextr�/�%z<<z>>�&�|�^z?:%d: unsupported expression: expected a simple numeric constant)r�rr�ZConstantr�r�rr}r�rr�r�ordr�r�r�r�r�r8rdr�rr�r6ZBinaryOp�left�right�_c_div)rhr�r��srrrrr
r�;s�


�
�
���
����zParser._parse_constantcCs0||}|dk|dkAr,||dkr,|d7}|S)Nrrr)rh�a�br�rrr
r�sz
Parser._c_divc	Cs�|dk	r�d}g}g}d}|jD]X}t�|j�r4d}q|jdk	rJ|�|j�}|�|j�|�|�|�|j|�|d7}qt|�}t|�}t	�
|||�}||_nt	�
|dd�}|S)NFrTrr)�enumerators�_r_enum_dotdotdotr!r8r�r�rr�r�rZEnumTyper�)	rhr�r�r�rZ
enumvaluesZ
nextenumvaluer�r�rrr
r��s*



zParser._build_enum_typecCsr|j��D]B\}\}}|�d�r"q
|�dd�d}|dkr
|j||d|d�q
|j��D]\}}|�||�qXdS)Nzanonymous $enum_$r;rr)r�r�r�Z	anonymousrUT)r�r�)r]r�rr�r�rdr�)rh�otherr8r�r�r��k�vrrr
�include�s
zParser.includecCs�|jjj}|dgkr t�|j�S|dgkrL|jdkr@d|j|_t�|j�S|dgkrx|jdkrld|j|_t�|j�Std|j	j
��dS)Nr�Z__dotdotdotint__z'typedef int... %s'Z__dotdotdotfloat__z'typedef float... %s'�*:%d: unsupported usage of "..." in typedef)r�r�rZunknown_typer8rfZUnknownIntegerTypeZUnknownFloatTyperr�r6)rhr9rtrrr
r��s





�zParser._get_unknown_typecCs2|jjjjdgkrt�|j�Std|jj��dS)Nr�r)r�r�rZunknown_ptr_typer8rr�r6)rhr9rrr
r��s
�zParser._get_unknown_ptr_type)FFNF)Fr)N)NF)N)NF)F)r��
__module__�__qualname__riryrrsrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�rr�r�rrrr
r\s:
&
�
63

	
^
#
v
I
r\)1rrZcommontypesrr�errorrrrr�ImportErrorr`r|�sys�version_info�thread�_thread�
allocate_lockrorrn�compile�DOTALL�	MULTILINEr>r@rKrrIrXr�
IGNORECASEr�rGrFrHr,rrOrPrr'r/r7r:rSr[�objectr\rrrr
�<module>sZ



�
�







�

*2:(

Zerion Mini Shell 1.0