
    ?e?                       d dl mZ d dlZd dlmZmZ ddlmZ ddlm	Z	 ddl
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mZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z< ddl=m>Z> ddl=m?Z? ddl@mAZAmBZB  G d d          ZC G d d          ZD G d d          ZE G d deF          ZGdS )    )partialN)lexyacc   )get_bindings_configuration)UserException   )ErrorLog)instantiate_class)invalid_global_slotslot_name_detail_map)
ScopedName) AccessSpecifierArgumentArgumentTypeArrayArgument
CachedNameClassKey	CodeBlockConstructorDocstringFormatDocstringSignatureEnumBaseType	GILAction	IfaceFileIfaceFileTypeKwArgs
MappedTypeMemberModuleOverloadPyQtMethodSpecifierPySlot	QualifierQualifierType	SignatureSourceLocationSpecificationTransfer	TypeHintsWrappedClassWrappedExceptionWrappedEnumWrappedEnumMember)encoded_template_namesame_template_signature)argument_as_strcached_namefind_iface_filenormalised_scoped_namesame_base_type   )rules)tokens)InvalidAnnotationvalidate_annotation_valuec                   x   e Zd ZdZd Zd Z	 dLdZd Z	 dMdZdLd	Z		 dNd
Z
dMdZd Zd Zd Zddddddddddd
dZd ZdOdZd Zd Zd Zd Zd Z	 	 dPdZd Zd Zd ZdLdZdLdZd Z	 	 dQd Zd! ZdRd#Z d$ Z!d% Z"d& Z#e$d'             Z%d( Z&d) Z'd* Z(d+ Z)d, Z*d- Z+d. Z,	 	 dSd/Z-dLd0Z.dTd2Z/e$d3             Z0e$d4             Z1e1j2        d5             Z1e$d6             Z3e3j2        d7             Z3e$d8             Z4d9 Z5d: Z6d; Z7d< Z8d= Z9d> Z:	 dLd?Z;d@ Z<dA Z=dB Z>dC Z?dDZ@dMdEZAdF ZBdG ZCdH ZDdI ZEdJ ZFdK ZGdS )UParserManagerzr This object manages the actual lexer and parser objects providing them
    with state and utility functions.
    c
                    t          j         t                    | _        | | j        _        t	          j        t
          d          | _        | | j        _        | j        t
          _        g | _        || _	        t          t          d |                    d          D                       |	|          | _        | j        j        g| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        dg| _        || _        || _        || _        || _        || _        g | _        g | _        t?                      | _         g | _!        d| _"        d| _#        g | _$        d| _%        g | _&        dS )z Initialise the manager. )moduleF)r>   debugc                 ,    g | ]}t          |          S  )int).0vs     Hlib/python3.11/site-packages/sipbuild/generator/parser/parser_manager.py
<listcomp>z*ParserManager.__init__.<locals>.<listcomp>Q   s    >>>!s1vv>>>    .Nr   )'r   r8   _lexerpmr   r7   _parserparserclass_templatestagsr(   tuplesplitspecr>   modules
c_bindings
code_blockmodule_stateparen_depthparsing_templateparsing_virtualraw_sip_file
skip_stack_hex_version	_encoding_disabled_features_protected_is_public_include_dirs_template_arg_classes_scope_stackr
   
_error_log_file_stack_pending_module_state_input_all_sip_files	_sip_file
_sip_files)
selfhex_versionencodingabi_versionrN   disabled_featuresprotected_is_publicinclude_dirs
sip_module	is_stricts
             rE   __init__zParserManager.__init__9   sc    gV,,, yU;;; |  " 	!>>{'8'8'='=>>>?? 	
 	()  %$  ' (!"3$7!)%'""**%)" rG   c                    | j         }|rC|j         ;|j        j        j         |j         j        j        k    r|                     ||d           n7t	          |j                  dk    r|                     ||d           nd|_        |                     |j        j        j        |          }t          | j
        |          |_        |                    dd          |_        |                    d          }|t          | j
        |          |_        |                    d	          }|t          | j
        |          |_        |                    d
d          |_        |                    dd          |_        |                    d          }	|	|	|j        _        |                     |||dd          }
|
|
|_        d|_        |                     |||dd          }|||_        |                    dd          |_        |                    d          |_        |j        r|                    dd          |_        n/|j        t4          j        |_        |                    dd          |_        t	          |j                  dk    rr|j        skt=          t?          t@          j!                            }tE          t4          j        ||          }||_#        |j        $                    |           d|_%        |j#        hd}|j        D ]W}|j&        t4          j        urt	          |j'        j(                  dk    s|j'        j(        d         j)        	||_#         n||}X||_#        |                    dd          |_*        |j+        |                    dd          rd|_,        |                    dd          rd|_-        d|_.        d|_%        |                    dd          |_/        |j/        rd| j0        j1        _2        dx}}|j3        D ]}|j4        tj          j6        tj          j7        tj          j8        fv rd}|j4        tj          j9        tj          j:        tj          j;        tj          j<        tj          j=        tj          j>        tj          j?        tj          j@        tj          jA        tj          jB        f
v rd}| o|}|j3        D ]}|jC        r
|jD        s|r|j4        tj          jE        u rtj          jF        |_4        8|j4        tj          jG        u rtj          jH        |_4        ]|j4        tj          jI        u rtj          jJ        |_4        |j4        tj          jK        u rtj          jL        |_4        | jM        rd|j        jN        _O        d|j        _O        | P                                 | Q                    ||||           |j        r| j         |                     ||d           |S )zg Complete the definition of the class that is the current scope, pop
        it and return it.
        NzKa scoped name cannot be specified in the definition of a class/struct/unionr   z4the class/struct has super-classes but no definitionT
NoTypeHintFMetatype	SupertypeExportDerivedMixinFileExtensionPyQtFlagsEnumsPyQt5r6   	PyQtFlagsPyQtNoQMetaObjectPyQtInterfaceExternalNoDefaultCtorsresult)py_signaturecpp_signature
Deprecated	AllowNoneAbstract	DelayDtor)ignorezJ/External/ classes/structs/unions can only be declared in the global scope)Rscope
iface_filefq_cpp_nameparser_errorlensuperclasses	is_opaqueget_py_name	base_namer2   rQ   py_namegetno_type_hintmetatype	supertypeexport_derivedmixinfile_extension_get_plugin_annotationpyqt_flags_enums
pyqt_flagspyqt_no_qmetaobjectpyqt_interfaceexternaldtorr   PUBLICno_default_ctorsctorsr&   r   r   VOIDr   default_ctorappend
can_createaccess_specifierr   argsdefault_value
deprecatedconvert_to_type_codehandles_noneis_abstractis_incomplete
delay_dtorrU   r>   has_delayed_dtorsmemberspy_slotr#   GETITEMSETITEMDELITEMSUBISUBMODIMODFLOORDIV	IFLOORDIVTRUEDIVITRUEDIVPOSNEG
is_numericis_sequenceADDCONCATIADDICONCATMULREPEATIMULIREPEATin_main_modulecpp_nameused	pop_scopecheck_attributes)ri   psymbolannotationshas_bodyklassr   r   r   r   r   r   	signaturectorlast_resort	seq_mightseq_notmddefault_to_sequences                      rE   complete_classzParserManager.complete_classq   s   
 
 		#{&#/59O9[[[%%aik k k#$$))aJL L L L #EO ""5#3#?#I #DIw77(__\5AA??:..(H==ENOOK00	 )$)Y??EO*FF!oogu55$99%.<E+66q&+ '+ +'%5E" E00FKW& &
!)E$/OO4G$O$O!*??? T	4(__Z??ENN z!,3
%0__5Eu%M%ME" 5;1$$U-C$%Xl6G-H-HIII	"?#9%.iI I I &*"""4(((#'  !)"!K 5 5D,O4JJJ 4,122a774;L;QRS;T;b;n-1* #*&*)4E&*|UCCE)5+//+W\:]:]5%)"z511 )$(!&*##( *{EBBE B=A!(: #('Im # #:&.&.&.!QQQ $I:&*fk6:v{TZTcekeuw}  xF  HN  HW  Y_  Yc  ek  eo  "p  p  p"G'.;#<9m 4 4= > 4%8 4zVZ//%+]

v{22%+^

vz11%+]

v{22%+^
 	&-1E%*!%EM 	a??? > 	bdj4a`b b b rG   Nc                 V   |                      ||t          j        t          || j                  |                    d          |                     |||                    }||_        ||_        | 	                    ||t          j        u rt          j        nt          j                   dS )z3 Create a new class and make it the current scope. VirtualErrorHandler)virtual_error_handler
type_hintsN)	new_classr   CLASSr4   r   r   get_type_hints	class_keyr   
push_scoper   r   PRIVATEr   )ri   r   r   r   scoped_namer   r   r   s           rE   define_classzParserManager.define_class  s     q&-*=&{DJ??&1oo6K&L&L..q&+FF  H H
 $)+4+F+F''OLb	d 	d 	d 	d 	drG   c                     ||v r|}n7|dk    rd}n.|                     d          rd}ndD ]
}||v rd} n
d|v rd}nd}|S )z/ Disambiguate a token by inspecting its value. z...ELLIPSISrH   	FILE_PATH)/z..-DOTTED_NAMENAME)
startswith)ri   valuekeywords
token_typemarkers        rE   disambiguate_tokenz ParserManager.disambiguate_token  s     HJJe^^#JJc"" 	($JJ* ( (U??!,JE # %<<!.JJ!'JrG   Fc                 \    |                      |                     ||||          |          S )zW Return a WrappedClass object for a C++ name creating it if
        necessary.
        )tmpl_arg)_find_class_with_iface_filer3   )ri   r   r   iface_file_typer   r   s         rE   
find_classzParserManager.find_class:  s;     //$$Q_MM! 0 # # 	#rG   c                    |                      |||t          j                  }| j        j        D ]}|j        |u r|c S |-|j        t          j        ur|                     ||d           d}n9|j        t          j        u rt          j        |_        | 	                    |          }t          |||          }| j        j                            |           |S )z3 Find an exception, optionally creating a new one. Nz_there is already a class with the same name or the exception has been used before being defined)class_exception)r3   r   	EXCEPTIONrQ   
exceptionsr   typer   r   r   r,   r   )ri   r   r   r   
raise_coder   w_exceptionr   s           rE   find_exceptionzParserManager.find_exceptionD  s
    ))!V[') )
  9/ 	# 	#K%33"""" 4 !m&===!!!Vy{ { { #OO -"999"/"5
">>zJJO 'z: /1 1 1 		##K000rG   c                 T   | j         t          j        u r|                     ||d           | j        }|C| j         t          j        u r#| j        sd|_        |t          j	        u rd|_
        |j        j        }nd}t          | j                  rt          |j                  }d}|                     ||||          }	|t          j        ur#|	j        j        |                     ||d           ||	_        | j        j        |	j        _        ||	_        ||	_        ||	j        j                            |           |t          j        u rb| j        j        D ]U}
|
|	u r|
j        j        t          j        ur |
j        j        |	j        j        k    r;|
|	_        | j        rd|
j        _        V|	S )zJ Create a new, unannotated class and add it to the current scope.
        zSclasses, structs, unions and namespaces must be in the public or protected sectionsNTz/the class/struct/union has already been defined)scope_access_specifierr   r   r   r   	PROTECTEDr^   is_protectedr   r   needs_shadowr   type_header_codeboolrS   r   r   r   	NAMESPACEr>   rU   r   r   extendrQ   classesr   r   
real_classr   needed)ri   r   r   r   r   r   r   r   r	  r   nss              rE   r   zParserManager.new_classk  s   
 &/*AAAaik k k 
*o.GGGPTPiG%)""m&999)-E&  %/@#   	 %[%:;;KE6?KHH -"999e>N>U>aaEG G G "&"3":&;#%'-445EFFF m555i' 0 0;;=%]-DDD=,0@0LLL#% & 0+/BM(rG   c                 x   | j         j        D ]B}|j        |u r7| j        s,	 | j                            |           n# t          $ r Y nw xY w|c S Ct          |t          | j         |j	        j
                  d          }|r| j                            |           | j         j                            d|           |S )z^ Return a WrappedClass object for an interface file creating it if
        necessary.
        Nr   )rQ   r  r   rW   r`   remove
ValueErrorr+   r2   r   r   r   insert)ri   r   r   r   s       rE   r   z)ParserManager._find_class_with_iface_file  s     Y& 	 	E:--, 299%@@@@%     . ZDIz'='GHH$P P  	5&--e444 		  E***s   ;
AAc                :   | j         }
||         |
j        j        j        k    r|                     ||d           t          | j                  r,t          |          dk    r|	|                     ||d           | j        |                     ||d           | j	        }|t          j        u r| j        rt          j        }t          |t          t           j                            }|                     |||           t'          ||          }|                    dd          r3||                     ||d	           |	|                     ||d
           n(|||_        n|                     |||           ||_        |                    dd          r&|
j        ||
_        n|                     ||d           ||_        |                     |||          |_        |                    dd          |_        |t          j        ur9|                     ||||          |_        d|
_        |t          j        u rd|
_        |	|_         |                    dd          |_!        |                    d          |_"        |                    d          |_#        ||_$        ||_%        |	>|                    d          )| j&        j'        s|                    dd          rd|_(        | )                    |||          |_*        |
j+        ,                    |           dS )z7 Create a Constructor and add it to the current scope. z3constructor doesn't have the same name as its classr   NzAconstructors with arguments in C modules must specify %MethodCodezAconstructors must be in the public, protected or private sectionsr   r   	NoDerivedFz?/NoDerived/ may not be specified with an explicit C++ signaturez>%MethodCode must also be specified if /NoDerived/ is specifiedDefaultz</Default/ has already been specified for another constructorr   Trt   PostHookPreHookNoRaisesPyExceptionRaisesPyException)-r   r   r   r   r   r
  rS   r   scope_pyqt_method_specifierr  r   r  r^   r   r&   r   r   r   _check_ellipsisr   r   r   r   	docstring_get_gil_action
gil_actionr   r   _get_kw_argskw_argsr   r  method_coder   posthookprehookpremethod_code
throw_argsrU   all_raise_py_exceptionraises_py_exceptionget_transfertransferr   r   )ri   r   r   arg_listr   r   r   r  r'  r$  r   r   r   r   s                 rE   add_ctorzParserManager.add_ctor  sq    
 V9(4>>>aIK K K    	YS]]a%7%7K<OaWY Y Y +7aWY Y Y  6888T=V8.5 !h 1224 4 4Q555 +\::??;.. 	/(!!!VY[ [ [ "!!!VXZ Z Z"!-D  FM:::!.D??9e,, 	X!)%)""!!!VVX X X #..q&+FF%//,>>?#:::,,Q " "DL#E?#<<<%)"&'OOL%@@#
33"y11,$;??3H#I#I#Q 7 0;??K^`e;f;f 0+/())!V[AA4     rG   c                N   | j         }
||
j        j        j        k    r|                     ||d           |
j        |                     ||d           t          | j                  r||                     ||d           | j        |                     ||d           | j	        rI| j         j
        t          j        u r|                     ||d           |	|                     ||d           n|r|                     ||d           | j        |
_        |                     |||          |
_        ||
_        |	|
_        ||
j                            |           ||
j                            |           |rd	|
_        | j	        st+          |
j                  d
k    r	d	|
_        dS dS )z" Add a dtor to the current scope. z2destructor doesn't have the same name as its classNz#destructor has already been definedz1destructors in C modules must specify %MethodCodez@destructors must be in the public, protected or private sectionsz(a union cannot have a virtual destructorz;destructors in C modules cannot specify %VirtualCatcherCodez&an abstract destructor must be virtualTr   )r   r   r   r   r   r   r
  rS   r  rX   r   r   UNIONr  r   dtor_gil_actiondtor_throw_argsdtor_virtual_catcher_codedealloc_coder   r   r   r  )ri   r   r   namer   r   abstractr'  r$  virtual_catcher_coder   s              rE   add_dtorzParserManager.add_dtor  s    
 5#/999aHJ J J :!a)NOOO   	I[%8aGI I I +7aVX X X  
	>z#x~55!!!VBD D D $/!!!VUW W W 	>a<> > > 0
 $ 4 4Q L L **>'%%%n555"%%k222 	% $E 	&3u'9#:#:a#?#?!%E $@#?rG   c           	      l   | j         t          j        u r|                     ||d           |r|                     ||d           |                    d          }t          j        }|| j        j	        dk     r|                     ||d           |dk    rt          j        }nv|dk    rt          j
        }nc|d	k    rt          j        }nP|d
k    rt          j        }n=|dk    rt          j        }n*|                     |dd                    |                     |d}	d}
d}nt          || j                  }	t#          | j        t%          |	                    }
t#          | j        |                     ||                    }|                     |||           | j        rd|
_        d|_        t/          ||	| j        j        |
||| j                  }| j         t          j        u r| j        sd|_        d| j        _        |                    dd          |_        |                    dd          |_        |D ]]\  }}}|s|                     |||j                    |j!        "                    tG          ||||                     | j        rd|_        ^| j        j$        %                    d|           dS )z4 Create a new enum and add it to the current scope. zclass enums cannot be privatezscoped enumsBaseTypeN   r   z4/BaseType/ is only supported for ABI v13.0 and laterEnumFlagIntEnumUIntEnumIntFlagr6   z''{0}' is an invalid value of /BaseType/T)cached_fq_cpp_name	is_scopedr   r   NoScopeFrt   )r   r   )&r  r   r   r   cpp_onlyr   r   ENUMrQ   rl   FLAGINT_ENUMUNSIGNED_INT_ENUMINT_FLAGformatr4   r   r2   strr   r   r   r   r-   rU   r>   r  r^   r  r  no_scoper   r5  r   r   r.   enumsr  )ri   r   r   r   rC  r   r   base_type_s	base_typer   rB  r   w_enum
m_cpp_name	m_py_namem_no_type_hints                   rE   add_enumzParserManager.add_enumM  s    &/*AAAa)HIII 	5MM!V^444 "ooj11 %	"y$w..!!!VNP P P f$$(-		&&(-			))(1		
**(:			))(1		!!!QAHH +- -. . . K!%GG04:FFK!,TYK8H8H!I!I!$)$$X{;;= =G !!!VW555" $*."'#YT5F5M#5tz3 3 3 &/*CCC, /&*#*.
'%//)U;;)oolEBB 6= 		& 		&1J	> A%%a@@@N!!%j)V)79 9 9: : : " &!%		q&)))))rG   )
constfinalr   r6  r   r  r'  r$  r7  virtual_call_codec       
   	         |                      ||          }t          ||          }|                     |||           ||}n|                     |||           |                     ||||||          }t	          | j        ||||          }| j        j        j        D ],}||u r&| j        j        j	        
                    |            n -| j        j	        
                    |           | j        |_        |j        t          j        u r| j        rt          j        |_        d|_        |j        t          j        u rd| j        _        d|_        |j        t          j        u r|j        t,          j        u rd| j        _        ||_        |
|_        ||_        |dk    |_        ||_        ||_        |	|_        ||_        ||_         | !                    ||          |_"        | j        d}||v rd| j        _#        |$                    dd          |_%        |$                    d          }|| &                    |||	          |_'        | (                    |||          |_)        |$                    d
d          |_*        |$                    dd          |_+        |$                    dd          |_,        | -                    |||          |_.        |j        t          j/        ur|j0        |j0        tb          j2        u r| 3                    |||||j                  |_4        |j4        tj          j6        urd|_7        |j        t,          j        ur|j        t          j        u rq| j8        sj| j        j	        D ]]}|j9        |ur|j4        tj          j6        u r |j:        j;        D ]0}|j4        tj          j<        u r|j=        |j>        d|j>        _?        1^|$                    dd          |_@        |$                    d          |_A        |$                    d          |_B        |>|$                    d          )| j        jC        s|$                    dd          rd|_D        |$                    d          |_E        |$                    dd          |_F        |$                    dd          r&|jG        r| H                    ||d           nd|_I        |$                    dd          r&|jI        r| H                    ||d           nd|_G        | J                    |||j:        jK        |           ||_L        d|v rv|}|0t          ddN                    |                    }|| j        _O        t          t          t          jR                            }| S                    |||d|||           d|v r| S                    |||d|||           d|v r| S                    |||d|||           |S ) z@ Create and return an Overload and add it to the current scope. r  NT__delattr__)__getattribute____getattr__	__enter____exit__
__aenter__	__aexit__AbortOnExceptionFAutoGen)r5  Factoryr   	NewThread)	need_namert   r  r  r  r  r   NoVirtualErrorHandlerNumericz,an overload has already specified /Sequence/Sequencez+an overload has already specified /Numeric/__len__zAuto-generatedz0            sipRes = (Py_ssize_t)sipCpp->{0}();
)textr   
__matmul____imatmul__)Tr   r&   r  _find_memberr!   r  rU   r>   global_functions	overloadsr   r   r  pyqt_method_specifierr   r   r  r^   r   access_is_really_protectedr  has_protectedr"   SIGNALr  r   is_const
is_delattris_finalr'  r(  rX  r7  get_source_locationsource_locationhas_nonlazy_methodr   abort_on_exceptionevaluate_feature_or_platformis_auto_generatedr   r!  factoryr   
new_threadr+  r,  r   r   r#   CALLr"  r#  r   NONEallow_keyword_argsr   commonr   r   OPTIONALr   r5  r   r   r%  r&  r)  r*  r   no_virtual_error_handlerr   r   r   !apply_common_argument_annotationsr   r$  r   rK  len_cpp_namer   r   SSIZE_add_auto_slot)ri   r   r   r   r   r-  r   rV  rW  r   r6  r   r  r'  r$  r7  rX  r   r   memberoverloadmNONLAZY_METHOD_NAMESauto_genkwodarglen_method_codelen_py_signatures                               rE   add_functionzParserManager.add_function  s    ""8[99 !hv>>>Q555 (MM  FM::: ""1fgx  D7|- - "): 	2 	2AF{{!(299(CCC  J ''111)-)I&$(AAAdF_A(7(>H%26H/$(AAA&*DJ##'F $(>>>-1D1KKK*.
'&'!&-7!"0(%6"(<%#'#;#;Av#F#F 
 :!$  ///04
- '2oo6H' '# ??9--)-)J)J1 *K *+ *+H& #221fkJJ&??9e<<)oolEBB)ook5AA --aEE$O,CCC~%6;)F)F#'#4#4Q$0D $5 $F $F  #6;6604F-
 19L9SSSX`Xq  vE  vO  YO  YO  X\  Xk  YO $
 4 5 5;f44$<6;66$#'#4#9 5 5C#|v>>3CTC\ ("x3045 !,e D D'OOJ77&??955;??3H#I#I#Q 7 4;??K^`e;f;f 4/3,)49N)O)O&,7OO'-0 -0) ??9e,, 	)! )!!!VFH H H H %)!??:u-- 	*  *!!!VEG G G G &*"..q&%,k	; 	; 	;  + ##)O&"+,<PWWX`aa#c #c #c
 +3
'(9K0L0LMMM6;	$&6I I I ;&&6; -> > > K''6; -> > > rG   c                    |j         t          j        u r)t          |j        | j                  x}|_        |j        }n|j         t          j        u r@t          |j        j        | j                  |j        _        t          |j                  }d}nU|j         t          j
        u r)t          |j        | j                  x}|_        |j        }n|                     ||d           d}|                     |||t          j        |          }| j        j        D ]J}|j        |u r?|j         t          j        ust%          ||j                   r|                     ||d           K| j        j        |_        t+          ||          }	t-          | j        t/          |                    |	_        |.t-          | j        |                    d|                    |	_        |                     |||	|           | j        j                            d|	           | j        rd|	j        _        |	j        d|	j        _        |                     |	           dS )	z; Create a new mapped type and add it to the current scope. Nzinvalid type for %MappedType )cpp_typez7the mapped type has already been defined in this modulePyNamer   T)r   r   DEFINEDr4   
definitionr   r   TEMPLATEr   r/   STRUCTr   r3   r   MAPPED_TYPErQ   mapped_typesr   r5   rU   r>   r   r2   r1   r   r   annotate_mapped_typer  r   r   r   )
ri   r   r   r  r   r   r   r   mtdmapped_types
             rE   add_mapped_typezParserManager.add_mapped_typeF  se    =L0000F'15 15 5K(-",HH]l333+A'0$*,> ,>H(/0CDDKHH]l1110F'15 15 5K(-",HHa)GHHHK))!V[)H * > >
 9) 	W 	WC~++ =(===PXZ]ZbAcAc=%%aUW W W !-4
 !X66*49)) +  + "-diOOHh77#9 #9K 	!!!V[+FFF	%%a555 	0(,K %".+/#($$$$$rG   r   c                    | j         j        }|                     |||d          }|a|j        t          j        us"|t          j        us|j        |u r7|j        |k    r,|                     ||d                    |                     dS t          |||||          }|t          j        u s| j
        sd|_        |j                            d|           dS )z6 Create a Qualifier and add it to the current module. F)requiredNz-'{0}' has already been defined as a qualifier)ordertimelineTr   )rU   r>   find_qualifierr   r%   TIMEr  r   rK  r$   skippingenabled_by_default
qualifiersr  )	ri   r   r   r5  r   r  r  r>   	qualifiers	            rE   add_qualifierzParserManager.add_qualifier  s    ") ''64%'HH	 
 ~]%7774}GY;Y;Y^g^nrx^x^x  ~G  ~P  T\  ~\  ~\!!!VGNN $& &' ' ' fdD!# # #	 =%%%T]%+/I(  I.....rG   c                 ,   | j         j        rN| j         j        D ]A}|j        |j        k    r/|                     ||d                    |j                             B| j        j        xj        dz  c_        | j         j        	                    |           dS )z% Add a typedef to the current scope. z'{0}' has already been definedr6   N)
rQ   rq   typedefsr   r   rK  rU   r>   nr_typedefsr   )ri   r   r   typedeftds        rE   add_typedefzParserManager.add_typedef  s     9 	:i( : :>W%888%%a<CC$+$79 9: : : 	 ,,1,,	!!'*****rG   c                    |                     dd          |_        |                     dd          |_        |                     dd          |_        |                     dd          |_        |                     dd          |_        |                     |||          |_        |j        rd|_        d|_        d|_        |                     |||dd	          }|	||_	        d
S d
S )z% Apply annotations to a mapped type. r   FNoAssignmentOperator
NoCopyCtorNoDefaultCtor	NoReleaseTr|   PyQt6N)
r   r   no_assignment_operatorno_copy_ctorno_default_ctor
no_releaser   r   r   r   )ri   r   r   r  r   r   s         rE   r  z"ParserManager.annotate_mapped_type  s     $/??;#F#F -8__&./ ./*#.??<#G#G &1ooou&M&M#!,e!D!D!%!4!4Q!L!L! 	/15K.'+K$*.K'00FKW& &
!%/K""" "!rG   c                    |                     dd          |_        |                     dd          |_        |                     dd          |_        	 |d         }|,| j        j        j        }| j        j        xj        dz  c_        n|dk     r|                     ||d	           ||_        dS # t          $ r Y dS w xY w)
zM Apply the annotations common to callable arguments and return type.
        r   FDisallowNoneNoCopyKeepReferenceNr6   r   z(a /KeepReference/ key cannot be negative)
r   
allow_nonedisallow_noneno_copyrU   r>   next_keyr   keyKeyError)ri   r   r   r  r   r  s         rE   r  z/ParserManager.apply_common_argument_annotations  s     %e<<'OONEBB!ooh66	o.C{'.7!(11Q6111q!!!VBD D D CGGG 	 	 	DD	s   AB/ /
B=<B=c                 @   |                      |||          |_        |                    d          n|j        t          j        u rt          j        |_        nI|j        t          j        u rt          j        |_        n$|j        t          j	        u rt          j
        |_        |j        t          j        u o|j        t          j        u o|j         }|rN|                    d          }|| j        j        }|	||_        dS dS |                     |||          |_        dS dS )z- Apply the annotations for an argument type. PyIntNEncoding)r   r   r   r   r   STRINGBYTESSTRINGSBYTEUSTRINGUBYTEarrayr   r  is_referencerU   default_encodingconvert_encoding)ri   r   r   r   r   can_be_encodedrk   r  s           rE   apply_type_annotationsz$ParserManager.apply_type_annotations  s    --aEE ??7##/yL///(-		l222(.		l222(.	 l&99xdjML^>^xgkgxcx 	G"z22H#'#4#E #/ 0DIII 0/ !11!VXFF				G 	GrG   c           	      z    ||         D ]1}||vr+|                      ||d                    ||                     2dS )zp Check that all the annotations provided as a dict of name/values
        are valid in a given context.
        z!{0} is not a valid {1} annotationNr   rK  )ri   r   r   contextr   r5  s         rE   check_annotationszParserManager.check_annotations  sa    
 fI 	* 	*D;&&!!!V;BB4 ') )* * *	* 	*rG   c                      j         j        sdS  fd} j         j        D ]`}|j        
|j         j        ur|j        j        k    r |d           |j        s%|j        D ]}|j        j        k    r |d           a|sK j         j        j	        j
        }	d}
n j        j        }	d}
|	D ]}|j        j        k    r ||
            n t           j        t                    rdS  j         j        D ].}|j         j        ur|j        j        k    r |d            n/ j         j        D ]9}|j         j        ur||u r|j        r|j        j        k    r |d           : j        1 j         j        D ]"}|j        |j        k    r |d	            dS #dS  j        j        D ] }|j        j        k    r |d
            dS !dS )zg Check that a Python name will not clash with another object in the
        same Python scope.
        Nc                 ^                         d                    |                      d S )Nz*there is already {0} in scope called '{1}'r  )thingr   r   ri   r   s    rE   clashz-ParserManager.check_attributes.<locals>.clash  sA    a@GG#% %& & & & &rG   zan enumzan enum memberz
a functionza methodz
a variableza class or namespacezan exceptionz
a property)rQ   rq   rN  r   r   r5  rC  r   rU   r>   rn  
isinstancer   	variablesr  r   r   
properties)ri   r   r   r   is_functionr   r  edemdr   r  r   vdcdxdpds   ````            rE   r   zParserManager.check_attributes  s    y" 	F	& 	& 	& 	& 	& 	& 	& 	& )/ 	0 	0Bz!xtz))z'))i   < 0: 0 0C{'722.///  	z!+2C$*,"  :?g--E%LLLE .
 dj*-- 	F )% 	 	Bxtz))z'))l### *
 )# 	. 	.Bxtz)) V||{ z')),---:i*  :)bjG.C.CE.)))EE  j+  7<7**E,'''EE + rG   c                 f    t          | j                  r|                     |||dz              dS dS )z: Check that a C++ feature isn't being used in a C module. z are not allowed in a C moduleN)r
  rS   r   )ri   r   r   features       rE   rE  zParserManager.cpp_onlyU  sW        	@a>>@ @ @ @ @	@ 	@rG   c                     ||         }|dk    rt           j        S |dk    rt           j        S |                     ||d                    |                     t           j        S )z? Convert a string to the corresponding DocstringFormat member. 
deindentedrawz1'{0}' is not a valid value for a docstring format)r   
DEINDENTEDRAWr   rK  ri   r   r   r   s       rE   convert_docstring_formatz&ParserManager.convert_docstring_format\  sp     &	L  "--E>>"&&!VCJJ 	  	  	 
 ""rG   c                     ||         }|dk    rt           j        S |dk    rt           j        S |dk    rt           j        S |                     ||d                    |                     t           j        S )zJ Convert a string to the corresponding DocstringSignature member.
        appended	discarded	prependedz4'{0}' is not a valid value for a docstring signature)r   APPENDED	DISCARDED	PREPENDEDr   rK  r  s       rE   convert_docstring_signaturez)ParserManager.convert_docstring_signaturen  s     &	J%..K%//K%//!VFMM 	  	  	 
 "++rG   c                    |||         }|dk    rt           j        S |dk    rt           j        S |dk    rt           j        S |dk    rt           j        S |                     ||d                    |                     t           j        S )z< Convert a string to the corresponding ArgumentType member. NASCIIzLatin-1NonezUTF-8z'{0}' is not a valid encoding)r   ASCII_STRINGLATIN1_STRINGr  UTF8_STRINGr   rK  r  r  s       rE   r  zParserManager.convert_encoding  s     =fIEG,,I--F??&&G++!V/66u==	? 	? 	?   rG   c                     |||         }|dk    rt           j        S |dk    rt           j        S |dk    rt           j        S |                     ||d                    |                     t           j        S )z6 Convert a string to the corresponding KwArgs member. NAllr  Optionalz0'{0}' is not a valid value for keyword arguments)r   ALLr  r  r   rK  r  s       rE   convert_kw_argszParserManager.convert_kw_args  s     =fIEE>>:F??;J?"!VBII 	  	  	 
 rG   c                     | j                                         \  }}}}}}|!|                     | j                   | j        }| j                             ||||||f           dS )z We allow %Modules that are part of a %CompositeModule to be either
        %Imported or %Included.  In the case of the latter we need to adjust
        things so that it appears like the former.
        N)rc   pop_import_modulerg   rU   r   )ri   sip_filerY   inputlinenolexposrU   s          rE   ensure_importzParserManager.ensure_import  s     GKFVFZFZF\F\C,vv|///,L<M	O 	O 	O 	O 	OrG   c                 V   |||         }|                      |||          }|dS |j        t          j        u r|j        | j        v}n\|j        t          j        u r| j        j        sdS |j        | j	        v }n,| 
                    ||d                    |                     dS |r| }|S )z+ Evaluate a feature or platform qualifier. NFTz@'{0}' is a %Timeline qualifier which can only be used in a range)r  r   r%   FEATUREr5  r]   PLATFORMrQ   rq   rN   r   rK  )ri   r   r   r5  invertedqualr   s          rE   r{  z*ParserManager.evaluate_feature_or_platform  s     <V9D""1fd33<59---IT%<<EEY-0009& tI*EEaV]]^bcce e e5 	IErG   c                    ||         }|r|                      ||          }|dS nd}||         }|r|                      ||          }|dS nd}|||                     ||d           dS |||j        |j        us|j        |j        k    r-|                     ||d                    ||                     dS ||u r|                     ||d           dS |j        |j        k    r-|                     ||d                    ||                     dS ||j        }|j        }	n|j        }|j        }	|	dk     r*|| j        |j        k     rdS || j        |j        k    rdS dS |j        D ][}
|
j        t          j
        u rF|
j        |	k    r;|
j        | j        v r-||
j        |j        k     r dS ||
j        |j        k    r dS  dS \|du S )	z  Evaluate a timeline qualifier. NFz1the lower and upper bounds cannot both be omittedz3'{0}' and '{1}' are defined in different %Timelinesz,the lower and upper bounds must be differentz*'{0}' is later in the %Timeline than '{1}'r   T)_find_timeline_qualifierr   r>   r  rK  r  r[   r  r   r%   r  r5  rN   )ri   r   symbol_lowersymbol_upper
lower_name
lower_qual
upper_name
upper_qualr>   r  r  s              rE   evaluate_timelinezParserManager.evaluate_timeline  s    |_
 	66q,GGJ!u " J|_
 	66q,GGJ!u " J*"4aGI I I5!j&< 
(999Z=PT^Tg=g=g!!!\MTTU_aklln n nuZ''!!!\FH H Hu*"222!!!\DKKJXbcce e eu !&F!*HH&F!*H a<<%$*;j>N*N*Nu%$*;z?O*O*Ou4 % 	 	DyM...4=H3L3LQUQZ^b^gQgQg)dj:;K.K.K 55)djJ<L.L.L 55ttT!!rG   Tc                    | j         D ]}|j        D ]}|j        |k    r|c c S |                    d          r|                    d          dd         }t          |          dk    rd}nkt          |          dk     r(|                    d           t          |          dk     (d}|D ]+}		 |d	z  t          |	          z   }# t          $ r d}Y  nw xY w|dk    rE| j	        j
        }t          ||t          j        |
          }
|j                            |
           |
S |r*|                     ||d                    |                     dS )z2 Return a Qualifier or None if one doesn't exist. SIP__r6   Nr   0r      )r  z'{0}' is not a known qualifier)rR   r  r5  r   rP   r   r   rB   r  rU   r>   r$   r%   r  r   rK  )ri   r   r   r5  r  r>   r  partsr  partr  s              rE   r  zParserManager.find_qualifier&  s    l 	  	 F)    9$$KKKKK % 
 ??6"" 	!JJsOOABB'E5zzA~~%jj1nnLL%%% %jj1nn !  D!&!s4yy 8%    " zz*1%fdM4F#% % %	!((333   	Ca4;;DAAC C C ts   0CCCc                     	 |d         S # t           $ r Y nw xY w|}| j        j        D ]B}|d         dk    r4|d         }|                    |          r|t	          |          d         }C|| j        v r|dz  }|S )z0 Return a valid Python name given a C/C++ name. r  r   REMOVE_LEADINGr6   Nr  )r  rU   auto_py_name_rulesr   r   _PYTHON_KEYWORDS)ri   r   r   r   ruleleadings         rE   r   zParserManager.get_py_nameO  s    	x(( 	 	 	D	  %8 	5 	5DAw***q'%%g.. 5%c'llmm4G d+++sNGs   
 
c                 h   |                     dd          }|                     dd          }|                     dd          }d}|r|s|rnAt          j        }n4|r|s|rn-t          j        }n |r|s|rnt          j        }nt          j        }|#|                     ||d           t          j        }|S )z9 Return the a Transfer value from a dict of annotations. r)   FTransferBackTransferThisNz-Only one transfer annotation may be specified)r   r)   TRANSFERTRANSFER_BACKTRANSFER_THISr  r   )ri   r   r   r   has_transferhas_transfer_backhas_transfer_thisr,  s           rE   r+  zParserManager.get_transferh  s     #z599'OONEBB'OONEBB 	%  -$5 -#, 	% 20 2#1 	% 20 2#1}HaCE E E}HrG   c                    |                     d          }|                     d          }|                     d          }|                     d          }||}n||                     ||d           dS ||}n||                     ||d           dS |||=|                     d          |                     ||d	           t          |||          S dS )
zr Return a TypeHints object constructed from a dict of annotations or
        None if none were specified.
        TypeHint
TypeHintInTypeHintOutTypeHintValueNz4'TypeHint' and 'TypeHintIn' cannot both be specifiedz5'TypeHint' and 'TypeHintOut' cannot both be specifiedrt   z1'NoTypeHint' cannot be specified with a type hint)r   r   r*   )ri   r   r   r   thth_inth_outth_values           rE   r   zParserManager.get_type_hints  s   
 __Z((--//???33=EE^aJL L L 4>FF^aKM M M 4 2h6J|,,8!!!VKM M M UFH555trG   c                 2    | j         j        | j        j        u S )zn Set if the current module is the main one, ie. the one for which
        code will be generated for.
        )rU   r>   rQ   ri   s    rE   r   zParserManager.in_main_module  s      '49+;;;rG   c                     | j         D ]G\  }}	|	j        j                            |j        | j                  rt          ||j                  r nHdS t          |||||	||||| 
  
         dS )zX Try and instantiate a class template and return True if one was
        found.
        )r   FT)	rM   r   r   matchesr   r   r0   typesr   )
ri   r   r   r   templater   no_type_namer  
tmpl_namesproto_classs
             rE   instantiate_class_templatez(ParserManager.instantiate_class_template  s     (,'; 	 	#J%199(:KSWS]9^^ cz  |F  HP  HV  dW  dW  5!V[*k'<D	B 	B 	B trG   c           
          | j                             |t          | j        |j        |                     |j                                       dS )z$ Record an error caused by a token. linecolumnN)rb   logr'   rg   r  _get_column_from_lexposr	  )ri   trj  s      rE   lexer_errorzParserManager.lexer_error  s_     	Dt~AH#;;AHEEG G G	H 	H 	H 	H 	HrG   c                 6   |}t           j                            |          }t          | j        j        |          | _        	 | j                            | 	                    ||          | j
        d           n$# t          $ r |                                  Y nw xY w|                                  | j                                         t!          | j                  | j        _        | j        j                            d            | j        j                            d            d | j        D             }t-          | j        j                  D ]/}|j        |v r$t          j        j                            |           0t-          | j        j                  D ]/}|j        |v r$t          j        j                            |           0t-          | j        j                  D ]/}|j        |v r$t          j        j                            |           0|D ]E}| j        j                            |           | j        j                            |j                   F| j        D ]!}| j        j                            |           "| j        | j        | j        fS )z Parse a .sip file and return a 3-tuple of a Specification object, a
        list of Module objects and a list of the .sip files that specify the
        module to be generated.  A UserException is raised if there was an
        error.
        T)lexertrackingc                     | j         S N)r   ks    rE   <lambda>z%ParserManager.parse.<locals>.<lambda>  s    am rG   )r  c                     | j         j        S rO  )r   r5  rP  s    rE   rR  z%ParserManager.parse.<locals>.<lambda>  s
    qy~ rG   c                     g | ]\  }}|S rA   rA   )rC   r  rQ  s      rE   rF   z'ParserManager.parse.<locals>.<listcomp>  s    ???$!QA???rG   ) ospathabspathModuleStaterQ   r>   rU   rK   parse_readrI   UnexpectedEOF_unexpected_eof_error_handle_eomrb   as_exceptionr
  rS   r  sortr  rM   listrN  r   r  r  iface_filesr   r`   rR   rh   )ri   r  rY   template_classesenumr  variabler   s           rE   rY  zParserManager.parse  s     7??8,,'	(8(CC	)Ltzz(LAA+  6 6 6 6 	) 	) 	)&&(((((	) 	$$&&&#DO44		$;$;<<<	  %=%= >>> @?$*>???)) 	- 	-Dz---	&&t,,,DI.// 	3 	3G} 000	"))'222TY011 	5 	5H~!111	#**8444% 	; 	;EI$$U+++I!(()9:::: / 	, 	,EI$$U++++y$,77s   6A9 9BBc                 d    | j                             ||                     ||                     dS )z5 Record an error caused by a symbol in a production. N)rb   rG  rw  )ri   r   r   rj  s       rE   r   zParserManager.parser_error  s2     	D$":":1f"E"EFFFFFrG   c                     | j                                         \  | _        | _        | _        | j        _        }| _        | j                            | j                   || j        _	        dS )z Restore the current .sip file from the stack and make it current.
        An IndexError is raised if the stack is empty.
        N)
rc   r  rg   rY   re   rI   r  rd   r  r	  )ri   r	  s     rE   pop_filezParserManager.pop_file  ss     rv  rB  rF  rF  rH  rHn)4;8JFTXTn$+&&&#rG   c                     | j         dS |                                  | j         j        | j        j        | j         _        | j         j        | j        j        | j         _        | j         | _        d| _         dS )z# Restore the current module state. N)rd   r]  r  rU   call_super_initr:  s    rE   pop_module_statezParserManager.pop_module_state  s{     %-F %6>:>:K:\D&7 %5=9=9J9ZD&6 6%)"""rG   c                 8    | j                                          dS )z Pop the current scope. N)ra   r  r:  s    rE   r   zParserManager.pop_scope+  s     	rG   c                 l   |||         }|}|                     dt          j                  }t          j                            |          rnd}t          j                            |          st          j                            | j                  g}|                    | j	                   |D ]E}	t          j        
                    |	|          }
t          j                            |
          r|
} nF|.|s*|                     ||d                    |                     dS |x}}t          j                            |          }| j        D ];}|d         |k    r-|                     ||d                    |                      dS <|| j        v rdS |r| j        }|                     |           nd}| j                            | j        | j        | j        | j        j        | j        j        |f           d| j        _        | j                            |                     ||                     dS )z Push the current .sip file onto the stack and make the new one
        current.  The new .sip file may be part of a new module (ie. %Import
        rather than %Include).
        Nr   z'{0}' could not be foundr   z'{0}' is being read recursivelyr6   )replacerU  seprV  isfileisabsdirnamerg   r  r_   joinr   rK  rW  rc   rf   rU   r  r   rY   re   rI   r  r	  r  rZ  )ri   r   r   r  
new_moduleoptionalrY   foundinc_dirsinc_dirfndetailold_module_states                rE   	push_filezParserManager.push_file0  sa    yH ##C00 7>>(## 	,E 7==** GOODN;;< 2333'  Ggx88Bw~~b))  " } M%%a6==lKKM M M  ',+L87??8,, & 	 	FayH$$!!!V9@@JJL L L % t***F 	$#0))))  $ 	!2DK*DK,>(*	+ 	+ 	+ $**X|<<=====rG   c                 V    | j                             t          ||                     dS )z Push a new scope. N)ra   r   
ScopeStateri   r   r   s      rE   r   zParserManager.push_scopey  s,     	  E3C!D!DEEEEErG   INITIALc                 :    | j                             |           dS )z Set the lexer state. N)rI   begin)ri   states     rE   set_lexer_statezParserManager.set_lexer_state~  s      	%     rG   c                 L    	 | j         d         j        S # t          $ r Y nw xY wdS )z The current scope if any. r  N)ra   r   
IndexErrorr:  s    rE   r   zParserManager.scope  s?    	$R(.. 	 	 	D	 ts    
!!c                 Z    t          | j                  dk    rdn| j        d         j        S )z The current access specifier. r   Nr  )r   ra   r   r:  s    rE   r  z$ParserManager.scope_access_specifier  s.     4,--22tt8I"8M8^^rG   c                 *    || j         d         _        dS )z# Set the current access specifier. r  N)ra   r   )ri   r   s     rE   r  z$ParserManager.scope_access_specifier  s     2B"...rG   c                 Z    t          | j                  dk    rdn| j        d         j        S )z The current method specifier. r   Nr  )r   ra   rp  r:  s    rE   r  z)ParserManager.scope_pyqt_method_specifier  s.     4,--22tt8I"8M8ccrG   c                 *    || j         d         _        dS )z# Set the current method specifier. r  N)ra   rp  )ri   rp  s     rE   r  z)ParserManager.scope_pyqt_method_specifier  s     7L"333rG   c                     | j         d         S )z. True if symbols are currently being skipped. r  )rZ   r:  s    rE   r  zParserManager.skipping  s     r""rG   c                     	 t          | ||||         |          }nB# t          $ r5}|                     ||t          |                     |j        }Y d}~nd}~ww xY w|S )z_ Validate an annotation and its value and return a valid version of
        the value.
        N)r:   r9   r   rL  use)ri   r   r   r   es        rE   validate_annotationz!ParserManager.validate_annotation  s|    
	-dAvqy EE  	 	 	aQ000EEEEEEE	 s    
A+AAc                    t          | j        ||          }t          | j        ||          }|j        |j        r |d           n |d           |j        rB|j        j        }|j        t          j
        ust          |j                  dk    r |d           |j        r) |d           |j        t          j        u r |d           |j         |d           |j        r|j        |j        r |d	           nl|j        r |d
           |j        r |d           |j         |d           |j         |d           |j         |d           |j        r |d           |j        r|j        t4          j        u r |d           n=| j        |j        r/|j        j        D ]"}|j        t4          j        u r |d            n#|j         j!        r|j"         |d           dS dS dS )z  Validate a completed function. Nz1abstract non-member functions cannot be specifiedzstruct/union member functionsr   z4/NewThread/ may only be specified for void functionsz static struct/union data memberszsignals cannot be staticr   zJ/VirtualErrorHandler/ and /NoVirtualErrorHandler/ cannot both be specifiedzG/AbortOnException/ cannot be specified for non-virtual member functionsz@/NewThread/ cannot be specified for non-virtual member functionszE%VirtualCallCode cannot be specified for non-virtual member functionszH%VirtualCatcherCode cannot be specified for non-virtual member functionszJ/VirtualErrorHandler/ cannot be specified for non-virtual member functionszL/NoVirtualErrorHandler/ cannot be specified for non-virtual member functionsz5/TransferBack/ and /Factory/ cannot both be specifiedzJ/TransferThis/ may only be specified for constructors and member functionsz=%MethodCode must be specified when /NoArgParser/ is specified)#r   rE  r   r   r   r~  r   r   r   r   r   r   derefs	is_staticrp  r"   rs  r(  
is_virtualr   r  rz  rX  r7  r}  r,  r)   r+  r  r   r   r,  r  no_arg_parserr$  )ri   r   r   r  rE  errorr   r  s           rE   validate_functionzParserManager.validate_function  s    4=!V44)1f55$,# KIJJJH4555 	N +2F{,"333s6=7I7IQ7N7NLMMM 	2H7888-1D1KKK0111*H\""" 	f-9h>_9bccc* a_```" ZXYYY)5]^^^,8`aaa-9bccc0 fdeee 	 H$:::MNNN(0H4F0,1  <8#999EfgggE : ?( 	SX-A-IEQRRRRR	S 	S-I-IrG   c                 N   | j         j        dk    rV|j        duod|j        j        v }|j        duod|j        j        v }||k    r|                     ||d           |p||_        dS |j        |                     ||d           |j        |                     ||d           dS dS )z# Validate a completed mapped type. r;  NsipUserStatezLboth %ConvertToTypeCode and %ReleaseCode must use user state or neither mustz4%MappedType must have a %ConvertToTypeCode directivez6%MappedType must have a %ConvertFromTypeCode directive)rQ   rl   r   rj  release_coder   needs_user_stateconvert_from_type_code)ri   r   r   r  convert_to_us
release_uss         rE   validate_mapped_typez"ParserManager.validate_mapped_type  s	    9 G++'<DH  E^_j_  `E  NEM$1=q.T_TlTqBqJ
**!!!Vfh h h ,9+FJK(((/7!!!VNP P P 19!!!VPR R R R R :9rG   c                 \   |j         j         t          j        u r|                     ||d           | j        }|b|t
          j        ur|                     ||d           |j        r|                     ||d           n|j	        |                     ||d           |j
        |j        <|j	        |                     ||d           | j        |                     ||d           | j        $| j        j        j         t          j        u rd|_        |                     |||j                   dS )	z  Validate a completed variable. z'capsule variables are not yet supportedNz-class variables must be in the public sectionzstatic members in C structuresz>%AccessCode cannot be specified for non-static class variablesz9%AccessCode cannot be specified with %GetCode or %SetCodez=%GetCode or %SetCode cannot be specified for global variablesT)r   r   CAPSULEr   r  r   r   r  rE  access_codeget_codeset_coder   r   r   r  r   r   )ri   r   r   rd  r   s        rE   validate_variablezParserManager.validate_variable  s~    =!555a=? ? ?  6''===!!!VGI I I ! Za)IJJJJ%1!!!VXZ Z Z (H,=,I#/!!!VSU U U z! !!!VWY Y Y :!dj&;&@MD[&[&[!%Ha)9:::::rG   c                    |                      ||||j        ||          }t          t          j        |||||          }	| j        &| j        j        j        	                    |	           dS | j        j        	                    |	           dS )z& Add an automatically generated slot. )r$  N)
rm  r   r!   r   r   r   rU   r>   ro  r   )
ri   r   r   r   r   r   r   r$  r  r  s
             rE   r  zParserManager._add_auto_slot3  s     ""1fg|7H[* * O2FG|F F F :$.55h?????J ''11111rG   c                     d}|j         D ]k}|j        t          j        u r3t	          d          |_        |r|                     ||d            dS d}H|r!|j        |                     ||d            dS ldS )z$ Check any ellipsis in a signature. Fz*argsz '...' may only be specified onceTNz4'...' must be at the end of the positional arguments)r   r   r   r   r   r5  r   r   )ri   r   r   r   seen_ellipsisr  s         rE   r  zParserManager._check_ellipsisB  s     > 	 	Cx<000 &g..  %%a>@ @ @EE $ 3#4#<!!!VNP P P!	 	rG   c           	      j      fd}t           j         j        j        |||| j                  S )zn Return an interface file for a fully qualified C/C++ name and type
        creating it if necessary.
        c                 6                         |            d S rO  )r   )rj  r   ri   r   s    rE   error_loggerz3ParserManager.find_iface_file.<locals>.error_logger_  s!    a.....rG   )r  r   )r3   rQ   rU   r>   r   )ri   r   r   r   r   r  r  s   ```    rE   r3   zParserManager.find_iface_fileY  s[    	/ 	/ 	/ 	/ 	/ 	/ 	/ ty$*;*B_lXj" " " 	"rG   c                    t          j        |          }|d}n|\  }}	}
|	r*|(|                     d                    |                     |
dk    r| j        >|
dz  }
t          |          r*|                     ||d                    |                     t          |          }|
|k    r+|                     ||d                    |
|                     |t          j        u r/| j	        rdt          | j        |          _        t          j        }d}|                     |||d	           |                    d
d          }| j        | j        j        j        }d}nK| j        j        j        t*          j        u r || j        j        j        }| j        j        }n| j        j        }d}|D ]2}|j        j        |k    r |j        r|                     ||d            nl3t7          | j        j        t          | j        |                    }||_        ||_        ||_        | j	        rd|j        _        |                    d|           |S )z> Return (creating if necessary) the member for a Python name. Nz'{0}' requires %MethodCoder   r6   z-'{0}' cannot be specified at the module levelz-{0} arguments are needed but {1} are providedT__setattr__)r  NoArgParserFzKan overloaded member function has already been specified with /NoArgParser/)r   r   r   rK  r  r   r   r#   DELATTRr   r2   rQ   r   SETATTRr   r   rU   r>   rn  r   r   r   r  r   r   r5  r  r   namespace_iface_filer   r  )ri   r   r   r   r   r   r$  slot_detailr   needs_method_codenr_args_needednr_argsr  r   r  r  s                   rE   rm  zParserManager._find_memberf  s   
 +.w77GG9D6G&  P[%8!!">"E"Eg"N"NOOO"".6"a'N +733 a))!V O V VW^ _ _a a a d))!W,,%%aKRR$2G= => > >
 &.((& @;?K	7338 .' 	adCCC $u==:'.?G#'  Z"'=+BBBwGZ '.?G#':#8  j(G#'  	& 	&F~"g-- ' k%%aik k k  . D-4	7335 5F*>F'#0F $FN" +&*#NN1f%%%rG   c                     ||         }|                      |||          }|dS |j        t          j        ur,|                     ||d                    |                     dS |S )z( Return an optional timeline qualifier. Nz"'{0}' is not a %Timeline qualifier)r  r   r%   r  r   rK  )ri   r   r   r5  r  s        rE   r  z&ParserManager._find_timeline_qualifier  sx     y""1fd33<49M...a8??EEG G G4rG   c                 P    | j                             dd|          dz   }||z
  dz   S )z^ Return the column within the current line corresponding to a lexer
        position.
        
r   r6   )re   rfind)ri   r	  
line_starts      rE   rH  z%ParserManager._get_column_from_lexpos  s2    
 [&&tQ77!;

"Q&&rG   c                     |                     dd          }|                     dd          }|r%|r|                     ||d           t          j        S |rt          j        S t          j        S )z? Return an appropriate GILAction according to the annotations. HoldGILF
ReleaseGILz3/HoldGIL/ and /ReleaseGIL' cannot both be specified)r   r   r   HOLDRELEASEDEFAULT)ri   r   r   r   holdreleases         rE   r   zParserManager._get_gil_action  s     y%00//,66 	" O!!!VMO O O >! 	%$$  rG   )#Falser  Trueandasassertasyncawaitbreakclasscontinuedefdelelifelseexceptfinallyforfromglobalifimportinislambdanonlocalnotorpassraisereturntrywhilewithyieldc                    |                     d          }||                     |||          }n| j        j        }t	          |j                  dk    r*|j        d         j        t          j        u rt          j
        }|t          j
        urNd}|j        D ]6}|t          j        u r|j        |j        |s| j        rd|j        _        d}7|rt          j
        }|S )z& Return the keyword argument support. KeywordArgsNr   r  TF)r   r  rU   r#  r   r   r   r   r   r   r  r  r   r5  r   r   )	ri   r   r   r   r   re  r#  no_namer  s	            rE   r"  zParserManager._get_kw_args  s     //-00**1fg>>GG'/G y~""y~b'9'>,BW'W'WkG &+%%G ~ $ $fo--#2C2K8'  -D$7 -(,#G & +rG   c                     |                     |          }|9|| j        j        vr+|                     ||d                    ||                     |S )z: Return an annotation that is only supported by a plugin. Nz/{0}/ is only supported for {1})r   rQ   pluginsr   rK  )ri   r   r   r   r5  pluginannos          rE   r   z$ParserManager._get_plugin_annotation  sc     t$$di.? ? ?a5<<T6JJL L L rG   c           	          t          | j        |                    |          |                     |                    |                              S )z. Return a SourceLocation object for a symbol. rD  )r'   rg   r  rH  r	  )ri   r   r   s      rE   rw  z!ParserManager.get_source_location  sN     dn188F3C3C33AHHV4D4DEEG G G 	GrG   c                     | j         }|j        }|j        -| j                            dt          | j                             t          |j                  |_        dS )z, Check that the current module is complete. Nz%Module has not been specified)	rU   r>   
fq_py_namerb   rG  r'   rg   r
  ri  )ri   rU   r>   s      rE   r]  zParserManager._handle_eom  sb     ($$O @"4>224 4 4 "&l&B!C!CrG   c                    | j         j        }t                      }| j                            |           | j         j        j        |_        t          ||          | _         t          | j        j	        d         || j
                  \  }}|D ]%}|| j        vr| j                            |           &|D ]%}|| j        vr| j                            |           &|j                            |           dS )zv Create a new Module object and corresponding ModuleState object for
        a .sip file and make it current.
        r   N)rU   r>   r    rR   r   default_exceptionrX  r   rQ   rl   r_   rN   r]   imports)ri   r  importing_fromr>   mod_tagsmod_disabledtagr  s           rE   r  zParserManager._import_module*  s   
 *1F####'#4#;#M '99 "<	%a((D4F"H "H,  	& 	&C$)##	  %%%# 	8 	8Gd555'..w777 	%%f-----rG   c                    	 t          || j                  5 }|                                | _        ddd           n# 1 swxY w Y   nt# t          $ r# t          d                    |                    t          $ r<}t          d                    || j                  t          |                    d}~ww xY w|| _	        || _
        | j                            |           | j        r| j                            |           | j        S )z/ Return the contents of the current .sip file. )rk   Nzunable to read '{0}'z.'{0}' doesn't appear to use the '{1}' encoding)ry  )openr\   readre   FileNotFoundErrorr   rK  UnicodeDecodeErrorrL  rY   rg   rf   r   r   rh   )ri   r  rY   fr  s        rE   rZ  zParserManager._readF  sZ   		#h888 'Affhh' ' ' ' ' ' ' ' ' ' ' ' ' ' '  	I 	I 	I 6 = =h G GHHH! 	# 	# 	#DKK$dn6 6q66# # # #	# )!""8,,, 	-O""8,,,{s7   A
 >A
 AA
 AA
 
5B;?7B66B;c                 `    | j                             dt          | j                             dS )z. Record an error caused by an unexpected EOF. zunexpected end of fileN)rb   rG  r'   rg   r:  s    rE   r\  z#ParserManager._unexpected_eof_error]  s8     	4t~..	0 	0 	0 	0 	0rG   rO  )F)NN)r   r   )FN)NF)T)NFF)r  )H__name__
__module____qualname____doc__rr   r   r   r   r   r  r   r   r.  r8  rU  r  r  r  r  r  r  r  r  r   rE  r  r  r  r  r
  r{  r  r  r   r+  r   propertyr   rB  rJ  rY  r   rg  rj  r   r{  r   r  r   r  setterr  r  r  r  r  r  r  r  r3   rm  r  rH  r   r$  r"  r   rw  r]  r  rZ  r\  rA   rG   rE   r<   r<   4   sr        6 6 6p[ [ [| d d d d  < # # # #% % % %P 48> > > >@   8P! P! P!d2& 2& 2&hI* I* I*X %D5$t4"	l l l l l\7% 7% 7%r/ / / /8+ + +0 0 0*  0G G G6	* 	* 	* @EW W W Wr@ @ @# # #$, , ,,! ! ! !0   ,O O O <@   :F" F" F"P' ' ' 'R  2     D" " "H < < X<  &H H H58 58 58nG G G

$ 
$ 
$* * *&     
 >CG> G> G> G>RF F F F
! ! ! !
   X _ _ X_
 "B B #"B
 d d Xd
 !'L L ('L
 # # X#
  >S >S >S@R R R,!; !; !;F2 2 2  0 " " " "P P Pd   ' ' '! ! !&   @	 	 	G G GD D D. . .8  .0 0 0 0 0rG   r<   c                       e Zd ZdZd ZdS )rX  z4 Encapsulate the parser-related state for a module. c                     || _         || _        d| _        g | _        d| _        d| _        t          j        | _        d| _	        dS ) Initialise the state. FNr   )
r>   r  r)  r#  ri  r  r   r  r#  nr_timelines)ri   r>   r  s      rE   rr   zModuleState.__init__g  sI      &+#"$# ${rG   Nr  r  r  r  rr   rA   rG   rE   rX  rX  d  s)        >>    rG   rX  c                       e Zd ZdZd ZdS )r}  z3 Encapsulate the parser-related state for a scope. c                 0    || _         || _        d| _        dS )r  N)r   r   rp  r~  s      rE   rr   zScopeState.__init__x  s!     
 0%)"""rG   Nr  rA   rG   rE   r}  r}  u  s)        ==* * * * *rG   r}  c                       e Zd ZdZdS )r[  z= This is raised by p_error() when an unexpected EOF is seen. N)r  r  r  r  rA   rG   rE   r[  r[    s        GGGGrG   r[  )H	functoolsr   rU  plyr   r   bindings_configurationr   r   r   	error_logr
   instantiationsr   python_slotsr   r   r   r   specificationr   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.   	templatesr/   r0   utilsr1   r2   r3   r4   r5   r  r7   r8   r   r9   r:   r<   rX  r}  	Exceptionr[  rA   rG   rE   <module>r     s_  0       				         @ @ @ @ @ @ ' ' ' ' ' '             . . . . . . D D D D D D D D $ $ $ $ $ $: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : G F F F F F F F0 0 0 0 0 0 0 0 0 0 0 0 0 0             E E E E E E E Em 0 m 0 m 0 m 0 m 0 m 0 m 0 m 0`A       "* * * * * * * *H H H H HI H H H H HrG   