
    iq{                    h   S SK r \ R                  " SI0 S\_S\_S\_S\_S\_S\_S\_S	\_S
\_S\_S\_S\_S\_S\_S\_S\_S\_S\_6  S SKrS SKrS SKrS SKrS SKJrJ	r	  S SK
Jr  SSKJr  SSKJrJr  \\4rSSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS KJrJr  SS!KJrJrJ r   SS"K!J"r"J#r#  SS#K$J%r%  S$S%KJ&r&  S& r'\RP                  \RR                  44S' jr*S( r+S) r,S* r-S+\.4S, jr/ " S- S.\R`                  5      r1S/ r2S0 r3 " S1 S2\Rh                  5      r5 " S3 S4\Rh                  5      r6 " S5 S6\Rn                  \%5      r8 " S7 S8\Rn                  5      r9 " S9 S:\Rh                  5      r: " S; S<\Rv                  \Rh                  5      r< " S= S>\Rv                  \Rz                  5      r>S? r?\R                  " S@SA5      rA\R                  " SBSA5      rB " SC SD\Rn                  \%5      rC " SE SF\Rh                  \Rv                  5      rD " SG SH\R                  5      rFg)J    NUtilityCodeEncodedStringbytes_literalencoded_stringNodes	ExprNodes
PyrexTypesBuiltin	UtilNodesOptionsUtilsrecopycodecs	itertools
attrgetterpartialreduce)r   r   )r      )	TypeSlots)UnicodeNodenot_a_constant)r   )r   )r	   )Visitor)r
   )r   )r   )r   TempitaUtilityCode)r   r   r   )errorwarning)SkipDeclarations   )r   c                 0    [         R                  " U S5      $ )N
Optimize.c)r   load_cached)names    X/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/Cython/Compiler/Optimize.pyload_c_utilityr$   %   s    ""466    c                 >    [        X5      (       a  U R                  $ U $ N)
isinstancearg)nodecoercion_nodess     r#   unwrap_coerced_noder,   )   s    $''xxKr%   c                     [        U [        R                  5      (       a-  U R                  n [        U [        R                  5      (       a  M-  U $ r'   )r(   r   ResultRefNode
expressionr*   s    r#   unwrap_noder1   /   s8    
T922
3
3 T922
3
3Kr%   c                 
   [        U 5      n [        U5      n[        U [        R                  5      (       a8  [        U[        R                  5      (       a  U R                  UR                  :H  $ [        U [        R
                  5      (       aw  [        U[        R
                  5      (       aX  U R                  (       + =(       a@    [        U R                  UR                  5      =(       a    U R                  UR                  :H  $ gNF)
r1   r(   r   NameNoder"   AttributeNode
is_py_attris_common_valueobj	attribute)abs     r#   r7   r7   5   s    AAAA!Y''((Z9;M;M-N-Nvv!Y,,--*Q	@W@W2X2X<<`OAEE155$A`akkUVU`U`F``r%   c                 (    U b  U R                   c  g U $ r'   )constant_resultr0   s    r#   filter_none_noder>   ?   s    D008Kr%   union_type_nodesc                 x  ^^ [         R                  mUU4S jm/ nS nU S S S2   nU(       Ga  UR                  5       n[        UT5      (       a  [	        T" U5      5      n[        U5      S:X  a  UR                  5       [        R                  L a  UR                  R                  (       a  Uc  UR                  nOUR                  UR                  5        UR                  R                  (       a  Uc  UR                  nOUR                  UR                  5        M  UR                  U5        U(       a  GM  X4$ )Nc              3      >#    [        U T5      (       a5  T" U R                  5       S h  vN   T" U R                  5       S h  vN   g U R                  (       d  U R                  v   g g  N@ N(7fr'   )r(   operand1operand2is_nonetype)	tree_nodeBitwiseOrNodecollect_tree_typess    r#   rH   4_unpack_union_type_nodes.<locals>.collect_tree_typesI   s[     i//))*<*<===))*<*<===""..  # >=s!   'A/A+A/A-'A/-A/r   )r   rG   popr(   setlenr
   	type_typerC   rD   appendrB   )r?   typesallowed_none_node
type_stacktptype_setrG   rH   s         @@r#   _unpack_union_type_nodesrU   E   s    ++M! E!$B$'J
^^b-(( -b12H8}!hlln8I8I&I;;&&(0,.KK)%%bkk2;;&&(0,.KK)%%bkk2R% *( ##r%   c                   h    \ rS rSrSrS r\R                  R                  r	S r
S rS rS rS rS	rg
)_YieldNodeCollectork   z1
YieldExprNode finder for generator expressions.
c                 ^    [         R                  R                  U 5        0 U l        / U l        g r'   )r   TreeVisitor__init__yield_stat_nodesyield_nodes)selfs    r#   r[   _YieldNodeCollector.__init__o   s&    $$T* "r%   c                 \    U R                   R                  U5        U R                  U5        g r'   )r]   rO   visitchildrenr^   r*   s     r#   visit_YieldExprNode'_YieldNodeCollector.visit_YieldExprNodev   s$    %4 r%   c                     U R                  U5        UR                  U R                  ;   a  XR                  UR                  '   g g r'   )ra   exprr]   r\   rb   s     r#   visit_ExprStatNode&_YieldNodeCollector.visit_ExprStatNodez   s9    4 99(((/3!!$)), )r%   c                     g r'    rb   s     r#   visit_GeneratorExpressionNode1_YieldNodeCollector.visit_GeneratorExpressionNode       r%   c                     g r'   rj   rb   s     r#   visit_LambdaNode$_YieldNodeCollector.visit_LambdaNode   rm   r%   c                     g r'   rj   rb   s     r#   visit_FuncDefNode%_YieldNodeCollector.visit_FuncDefNode   rm   r%   )r]   r\   N)__name__
__module____qualname____firstlineno____doc__r[   r   rZ   ra   
visit_Noderc   rg   rk   ro   rr   __static_attributes__rj   r%   r#   rW   rW   k   s8    
 $$22J!4r%   rW   c                 B    [        U 5      n[        U5      S:w  a  gUS   $ )Nr   )NNr   )_find_yield_statementsrM   )r*   yield_statementss     r#   _find_single_yield_expressionr~      s)    -d3
!Ar%   c                     [        5       nUR                  U 5         UR                   Vs/ s H  nUR                  UR                  U   4PM      nnU$ s  snf ! [
         a    / n U$ f = fr'   )rW   ra   r]   r)   r\   KeyError)r*   	collector
yield_noder}   s       r#   r|   r|      s    #%ID! (33
3
 ^^Y77
CD3 	 
 
  s"   A %AA A A)(A)c                      \ rS rSrSrS rS rS#S jrS rS#S jr	\
R                  " \
R                  \
R                  " S\R                  S	5      /S
S9r\
R                  " \
R"                  \
R                  " S\R                  S	5      /SS9rS#S jr\
R                  " \
R(                  \
R                  " S\
R*                  S	5      \
R                  " S\
R,                  S	5      \
R                  " S\
R"                  S	5      /5      r\
R                  " \
R*                  \
R                  " S\
R0                  S	5      \
R                  " S\
R2                  S	5      \
R                  " S\
R4                  S	5      \
R                  " S\
R6                  S	5      /SS9rS#S jrS#S jrS rS r S#S jr!S r"S r#\
R                  " \
R0                  \
R                  " S\
R0                  S	5      \
R                  " S\
R*                  S	5      \
R                  " S\
R0                  S	5      \
R                  " S\
R2                  S	5      \
R                  " S\
R6                  S	5      /5      r$\
R                  " \
R0                  \
R                  " S\
R0                  S	5      \
R                  " S\
R*                  S	5      \
R                  " S\
R2                  S	5      \
R                  " S \
R6                  S	5      /5      r%S! r&S"r'g	)$IterationTransform   zTransform some common for-in loop patterns into efficient C loops:

- for-in-dict loop becomes a while loop calling PyDict_Next()
- for-in-enumerate is replaced by an external counter variable
- for-in-range loop becomes a plain C for loop
c                    UR                  5       (       Ga;  UR                  n[        R                  " U5      nUR                  R
                  (       a+  UR                  R                  R                  R                  nO UR                  R                  R                  n[        R                  " U5      nUR                  U5      n[        R                  " USUR                  US9n[        R                  " U[        R                   " X#[        R"                  " USS9S9[        R$                  " U5      /S9n[        R&                  " U[        R(                  " X'US9/S S9n	[        R*                  " UU/[        R,                  " UU[        R.                  " UR                  R                  UR                  S	9U	[        R                   " X#[        R"                  " US
S9S9S9S9n
U
R1                  U R3                  5       5      n
U R5                  U
5      n
[        R6                  " X:5      nUR8                  S:X  a  [        R:                  " X+S9nU$ U R=                  U5        U$ )N==operatorrB   rC   Tvaluelhsrhsstats	conditionbody
if_clauseselse_clause)sequenceF)targetiteratorr   r   tempsr   not_inoperand)is_ptr_containsposr   r.   rC   is_subscriptbaserE   	base_type
TempHandlerefr   PrimaryCmpNoderB   r   StatListNodeSingleAssignmentNodeBoolNodeBreakStatNode
IfStatNodeIfClauseNodeTempsBlockNodeForInStatNodeIteratorNodeanalyse_expressionscurrent_envvisitTempResultFromStatNoder   NotNodera   )r^   r*   r   
result_refr   target_handler   cmp_nodeif_bodyif_nodefor_loopnew_nodes               r#   visit_PrimaryCmpNode'IterationTransform.visit_PrimaryCmpNode   s   !! ((C"006J}})) MM..33==	 MM..88	%00;M"&&s+F //dT]]VMH((33CYM_M_`ckoMpq,,S134G &&!..sWUV "G !//&**!&33DMM4E4EPTP]P]^  % : :1C1CCu1U!WX	YH  33D4D4D4FGHzz(+H 77
MH}}($,,SCO t$Kr%   c                 n    U R                  U5        U R                  XR                  R                  5      $ r'   )ra   _optimise_for_loopr   r   rb   s     r#   visit_ForInStatNode&IterationTransform.visit_ForInStatNode   s+    4 &&t]]-C-CDDr%   c           	      \   UR                   nS nUR                  (       d  UR                  (       ai  UR                  (       aX  UR                  R                  (       a=  UR                  R                  R
                  nUR                  (       a  UR                  n[        R                  XE4;   a  U(       a  U$ U R                  XS SSS9$ [        R                  XE4;   d  [        R                  XE4;   a  U(       a  U$ U R                  X5      $ U R                  5       nUR                  (       d  UR                   (       a  U R#                  XUS9$ UR$                  (       a  UR&                  (       d  [(        R*                  " XrUS9nU(       a  UR,                  (       d  [/        S UR0                   5       5      (       d  [(        R2                  " UR4                  UR0                  S9R7                  U5      R9                  [:        R<                  " U[?        UR0                  5      5      U5      nU R#                  XUS9$ UR@                  (       Ga'  UR&                  (       Gd  U[        RB                  L a+  [:        RD                  n[G        [H        URJ                  5      n	O[:        RL                  nURJ                  n	[O        [(        RP                  RR                  UR4                  US9n
[(        R2                  " UR4                  U	 Vs/ s H
  o" U5      PM     snS9nUR7                  U5      R9                  [:        R<                  " U[?        UR0                  5      5      U5      nU R#                  XUS9$ U[        RT                  L a2  UR&                  (       a  U RW                  XSUS	9$ U RY                  XUS9$ U[        RB                  L a  U R[                  XUS9$ U[        R\                  L a  U RW                  XSUS	9$ [_        U[(        R`                  5      (       a@  URb                  R                   Rd                  (       a  U RW                  XRb                  SUS	9$ [_        U[(        Rf                  5      (       d  U$ UR0                  c<  URh                  =(       a    [?        URh                  R0                  5      =(       d    S
nO.[?        UR0                  5      nU(       a  URj                  b  US-  nURl                  nUR                  (       GaR  U(       GdJ  U(       GdB  URj                  =(       d    URn                  nURp                  nU Rs                  5       Rt                  Rv                  S:  nU(       d  US;   az  [_        U[(        Rx                  5      (       a[  URl                  nUR                  (       a>  URz                  S:X  a.  UR                  (       a  UR                  R|                  (       a  SnS=nnUS:X  d  U(       a	  US:X  a  SnO-US:X  d  U(       a	  US:X  a  SnOUS:X  d  U(       a
  US:X  a  S=nnU(       d  U(       a  U R                  XUUU5      $ URj                  c  UR                  (       a  UR                  (       ao  UR                  R|                  (       aT  URz                  S:X  a  U(       a  U$ U R                  X5      $ URz                  S:X  a  U(       a  U$ U R                  X5      $ [        R                  (       Ga  SUs=::  a  S::  Gay  O  U$ URj                  Gcg  UR                  (       GaU  URz                  S;   GaD  UR                  (       Ga2  UR                  R|                  (       Ga  UR                  R                   R                  (       d%  UR                  R                   R                  (       a  U R                  XUS9$ UR                  R                   R,                  (       a  UR0                  c  URh                  R0                  OUR0                   HT  n[_        U[(        RP                  5      (       a1  UR                  5       (       a  SUR                  s=::  a  S:  a  O  OMS    U$    U R                  XUS9$ U$ s  snf )NTF)dict_objmethodkeysvaluesreversed)seq_typec              3   8   #    U  H  oR                   v   M     g 7fr'   )
is_starred).0items     r#   	<genexpr>8IterationTransform._optimise_for_loop.<locals>.<genexpr>   s     Bm_lW[??_l   argsrE   )
is_mutabler   r   r      )r   r   itemsdictiterkeysr   
itervaluesr   	iteritemsr   	enumerater   )rangexrange      @)IrE   is_nameis_attributeentry
annotationrf   r   r   r
   	dict_type_transform_dict_iterationset_typefrozenset_type_transform_set_iterationr   is_ptris_array_transform_carray_iterationis_sequence_constructoris_generator_scoper   infer_sequence_item_typeis_pyobjectanyr   ListNoder   analyse_types	coerce_tor	   c_array_typerM   is_string_literalunicode_typec_py_ucs4_typemapordr   c_uchar_typer   IntNodefor_int
bytes_type_transform_indexable_iteration_transform_bytes_iteration_transform_unicode_iterationbytearray_typer(   CoerceToPyTypeNoder)   is_memoryviewsliceSimpleCallNode	arg_tupler^   functionr8   r9   global_scopecontextlanguage_levelCallNoder"   
is_builtin_transform_enumerate_iteration_transform_reversed_iterationr   convert_ranger   is_intis_enum_transform_range_iterationhas_constant_resultr=   )r^   r*   iterabler   	iter_typeannotation_typer   env	item_typer   as_int_nodech	arg_countr  base_objr   is_safe_iterinner_functionr   r   r)   s                        r#   r   %IterationTransform._optimise_for_loop   s   MM	 5 58>>hnnNgNg!2277J&&'__
 <<114 2 O O  <<&&9*FF00@@  y1133DX3VV++C4J4J "::	3I!6!6sBm_g_l_lBm?m?m$--hllO]]^abll++Is8==7IJCQ77QY7ZZ%%%c.D.D.D G000&55	C0&33	 !)"3"3";";X\\PYZK ))(,,W\=]W\QSk"oW\=]^H--c2<<Z=T=TU^`cdldqdq`r=suxyH33DX3VV***%%::4V[fn:oo66tPX6YY,,,44Th4WW ...66tRVai6jjh	 < <==(,,BSBSBfBf66t\\V[fn6oo (I$<$<==K==  **Ks83E3E3J3J/KPqIHMM*IX]]6Q	$$   )}}4H''F,,.66EEJLF.I$Ih	(:(:;;%-%6%6N&..>3F3F&3P . 4 4 . 4 4 ? ?'+!!D6#69I<'LVx=O;&<Fg<M $$vv55FD&: : == X%5%5~~(..";";}}+K::4JJ*,K99$II    Q)%8q%8   %   X]]6I%I8>>#<#<#<{{&&$++*:*:*B*B66tPX6YY{{++7?}}7LH..33RZR_R__C!#y'8'89922443CVCV9^Y^9^$  `  ::4T\:]]s >^s   
b)
c                    UR                   R                  n[        U5      S:X  a  [        UR                  S5        U$ [        U5      S:  a  [        UR                  S5        U$ US   nUR
                  [        R                  [        R                  4;   a3  UR                  S5      UR                  l        SUR                  l        U$ U R                  XSS9$ )Nr   z(reversed() requires an iterable argumentr   z#reversed() takes exactly 1 argument!'NoneType' object is not iterableTr   )r  r   rM   r   r   rE   r
   
tuple_type	list_typeas_none_safe_noder   r   r   r   )r^   r*   reversed_functionr   r)   s        r#   r  0IterationTransform._transform_reversed_iterationh  s     **//t9>#''<>KY]#''79K1g 88**G,=,=>>%(%:%:;^%_DMM"%)DMM"K&&t4&@@r%   c                 $
   / n[         R                  " UR                  S5      SSS9nUR                  U5        [        R
                  " UR                  [        R                  " UR                  S[        R                  R                  S5      S9U/S9nU(       a  UnO4[         R                  " U[        R                  S9nUR                  U5        [         R                  " [        R                  " UR                  SS	95      n	UR                  U	5        U(       a1  Un
[        R                  R                  UR                  S
5      nSu  pO.[        R                  R                  UR                  S5      n
Su  p[         R                   " U
5      n[         R                  " U
[        R                  S9nUR                  U5        [        R"                  " UR                  UUUS9nU(       aG  U(       a@  [        R$                  " UR                  SU[        R"                  " UR                  UUUS9S9n[&        R(                  " UR                  [&        R*                  " UR                  U	[        R                  " UR                  SS	9S9[&        R,                  " UR                  5      /S9n[        R.                  " UR                  XnS9n[&        R*                  " UR0                  R                  UR0                  US9nU R3                  5       n[4        R6                  " UR8                  SSS9n[&        R:                  " UR                  UUS9n[&        R<                  " UR                  [&        R>                  " UR                  UUS9/US9nU(       a^  UR@                  RB                  (       d   UR@                  5       e[&        RD                  " UR                  U/US9nURG                  U5        [&        R(                  " UR                  [&        R*                  " UR                  U[        RH                  " UR                  U(       a  SOSSU[        R                  R                  UR                  S5      S9S9U/S9n[&        RJ                  " UR                  U	UURL                  S9nUnUSSS2    H  n[         RN                  " UU5      nM     URQ                  U5      nURR                  R                  URT                  5        U$ )zUIteration over iterables that Cython has a len() for and knows how to index.
        'NoneType' is not iterableFT)may_hold_noneis_temprM   )r"   r   r  r   r   r   r   >>=rJ   <=<r   andr   r   )r   indexr   r   r   )boundscheck
wraparound)
directivesr   r   r   )r   r   -+r   )r   inplacerB   rC   r   r   r   N)+r   
LetRefNoder#  rO   r   r  r   r4   r
   builtin_scopelookupr	   c_py_ssize_t_typer   r   for_sizer   r   BoolBinopNoder   r   r   ContinueStatNode	IndexNoder   r   r   copy_inherited_directivesr6  CompilerDirectivesNoder   r   rE   r   CriticalSectionStatNodeanalyse_declarations
binop_nodeWhileStatNoder   LetNoder   r   r   )r^   r*   
slice_noder   r   
temp_nodesunpack_temp_nodelength_call_nodeend_nodekeep_going_ref
start_node	relation1	relation2start_check_nodecounter_ref	test_nodefailed_test_bodytarget_valuetarget_assignr  new_directiveslength_check_and_target_assignr   	loop_noderetlet_ref_nodes                             r#   r   1IterationTransform._transform_indexable_iteration|  sF   & 
$//(()EF

 	*+$33HH''u++2259 ##
 'H ++,<:C_C_`Hh'"--i.@.@QU.VW.)!J ((11$((A>H#, Iy"**33DHHbAJ#, I99Z0**:J<X<XY+&,,HH 	
	 (!//""11HH&-(		
I !--HH **HH&!**4885A
 &&txx0
 !**:>>@Pd22++//++
   ::3>>W\ino44%
 */)9)9HH""HH'& )
*
& ??..?
?. .3-J-J&'3.*
 +??D!!HH**HH#!,,(0c $!,!*!2!2!;!;DHHa!H
 /$ ''HH&**	
	 &tt,L##L#6C - %%c*

$))$
r%   sNNULLexception_valuerJ   c                    UR                   R                  nUR                  (       d  U[        R                  La  U$ [
        R                  " UR                  S5      5      n[        R                  " UR                  SU R                  U/SS9n[        R                  " UR                  SU R                  U/SS9n[
        R                  " UU R                  U[        R                  " UR                  US S UUR                  SS9US95      $ )Nr'  __Pyx_PyBytes_AsWritableStringr   r   r)  __Pyx_PyBytes_GET_SIZE)r   startstepstoprE   r)  r   )r   rE   r  r
   r   r   r;  r#  r   PythonCapiCallNoder   PyBytes_AS_STRING_func_typePyBytes_GET_SIZE_func_typerI  r   SliceIndexNode)r^   r*   rJ  r   target_typerL  slice_base_nodelen_nodes           r#   r   -IterationTransform._transform_bytes_iteration*  s   kk&&!!k9K9K&K K$//(()EFH $66NN<,,$%	 //NN4++$%	   ,,((NN* #*// $ - %& 	&r%   kinddatar2  lengthc                 x
   U R                  5       nUR                  (       a  UR                  (       d   [        UR                  R                  S5      S5      n[        R                  " UR                  [        R                  " UR                  UU[        R                  S9R                  [        R                  U5      S [        R                  R                  UR                  [!        U5      5      ["        R$                  S9nU R'                  XU5      $ [*        R,                  " UR/                  S5      5      n[        R                  R                  UR                  S5      n[*        R0                  " [        R2                  5      n	U	R5                  UR                  5      n
U(       a  Su  pXpOSu  p[*        R0                  " [        R6                  5      n[*        R0                  " [        R8                  5      n[*        R0                  " [        R2                  5      n[        R:                  " UR                  S	U R<                  UR5                  UR                  5      UR5                  UR                  5      UR5                  UR>                  R                  5      /S
S9nUR@                  UR>                  R@                  :w  a&  UR                  UR>                  R@                  U5      n[B        RD                  " UR>                  R                  UR>                  US9n[B        RF                  " UR                  UURH                  /S9n[B        RJ                  " UR                  XUR5                  UR>                  R                  5      XS UURL                  SS9
n[B        RN                  " UR                  [        R:                  " UR                  SU RP                  U[        RR                  " UR                  U	R5                  UR                  5      [        RT                  S9[        RR                  " UR                  UR5                  UR                  5      [        RV                  S9[        RR                  " UR                  UR5                  UR                  5      [        RX                  S9/SS
[Z        R\                  " SS5      S9S9n[*        R^                  " U[*        R`                  " UR                  XX/[B        RF                  " UR                  UU/S9S95      $ ! [(         a     GN!f = f)Nlatin1z	iso8859-1r   r=   rE   )r   rg  ri  rE   r'  r   r+  r.  __Pyx_PyUnicode_READFre  r3  r   T	bound1rQ  r   rR  bound2rh  r   r   
from_range__Pyx_init_unicode_iterationr   rE   unicode_iterr    )r   r)  result_is_usedutility_code)rf   r   )1r   
is_literalr   r   r   encoder   rm  r   	BytesNoder	   c_const_char_ptr_typer   c_const_uchar_ptr_typer   r?  rM   r
   r   r   UnicodeEncodeErrorr   r;  r#  r   r>  r   
c_int_typec_void_ptr_typerj  PyUnicode_READ_func_typer   rE   r   r   r   r   ForFromStatNoder   ExprStatNode init_unicode_iteration_func_typeAmpersandNodec_py_ssize_t_ptr_typec_void_ptr_ptr_typec_int_ptr_typer   r!   rI  r   )r^   r*   rJ  r   r  bytes_valuebytes_slicerL  rP  length_temprN  rQ  rR  	kind_temp	data_tempcounter_temprW  rX  r   r[  
setup_nodes                        r#   r   /IterationTransform._transform_unicode_iterationa  s      )?)?U+J,<,<,C,CH,M{[ (66NN",,"k(3'==? @Iy&==s@D"**33JNNCDTU --
 778TT$//(()EFH &&//!<
**:+G+GH??488,#, I#+#, I(()>)>?	(()C)CD	 ++J,H,HI 33NN2))MM*..1MM*..1 $$T[[__57   0 00'11$++2B2BCHL22++//++  !!HH"DII.0 ))HH##DKKOO4D((	 ''HH// >55(!//
XbXfXfHg5?5U5UW!//
	V`VdVdHe5?5S5SU!//
	V`VdVdHe5?5N5NP !&(44^\R
"   $$I Q''Y8OPRS 	SY & s   %T+ +
T98T9c                    Sn[        U[        R                  5      (       at  UR                  n[	        UR
                  5      n[	        UR                  5      nS nU(       d3  UR                  R                  (       d  [        UR                  S5        U$ GO;UR                  (       Gah  [        UR                  [        R                  5      (       d   eUR                  nUR                  n	[	        U	R
                  5      n[	        U	R                  5      n[	        U	R                  5      nU(       a  [        UR                  [         5      (       a>  UR                  S:X  d.  UR                  S:  a  U(       a  UR                  S:  a:  U(       d3  UR                  R                  (       d  [        UR                  S5        U$ UR                  n
U(       a  U
* n
U
S:  n[        R"                  R%                  UR                  ['        U
5      5      nOUR                  R(                  (       as  UR                  R*                  c  [        UR                  S5        U$ UnS =ph[        R"                  R%                  UR                  UR                  R*                  5      nO3UR                  R                  (       d  [        UR                  S5        U$ U(       a.  UR-                  [.        R0                  U R3                  5       5      nU(       a.  UR-                  [.        R0                  U R3                  5       5      nUcJ  U(       a+  [        R"                  R%                  UR                  S5      nO[        UR                  S5        U$ U(       a3  U(       d*  [        R"                  R%                  UR                  S5      nXvpvUR                  nUR(                  (       a  UR5                  5       nUR7                  U R3                  5       5      nU(       a3  UR                  S:w  a#  [        R8                  " UR                  USUUS9nOUnU(       ad  UR                  S:w  aT  [        R8                  " UR                  [        R:                  " U5      SUUS9R7                  U R3                  5       5      nO[        R:                  " U5      n[<        R>                  " U5      nURA                  URB                  R                  5      nUR                  RD                  (       Gan  URB                  R                  R                  (       GaH  UR                  [F        RH                  L a  [        RJ                  " [        RL                  " URB                  R                  UURN                  S9[.        RP                  5      R-                  URB                  R                  U R3                  5       5      nGOc[        R                  " URB                  R                  [        R"                  RS                  URB                  R                  S5      [        R"                  RS                  URB                  R                  S	5      U[F        RT                  S	S
9nOURB                  R                  RV                  (       a7  URB                  R                  RY                  URN                  5      (       d  UnOg[        RZ                  " URB                  R                  [        R"                  RS                  URB                  R                  S5      UURN                  S9nUR                  URB                  R                  :w  a4  UR-                  URB                  R                  U R3                  5       5      n[\        R^                  " URB                  R                  URB                  US9n[\        R`                  " UR                  UURb                  /S9nU Re                  XC5      u  nn[\        Rf                  " UR                  UUUUUUUURh                  SS9
n[<        Rj                  " UR                  U/US9$ )NFz*C array iteration requires known end indexr   z8C array iteration requires known step size and end indexrJ   r8  rB   r   rC   rE   r~  r   )rg  ri  r   rE   r)  )r2  r   rE   r3  r   Try  r   )6r(   r   rm  r   r>   rg  ri  rE   r   r   r   r   r2  	SliceNoderh  r=   intr   r?  absr   sizer   r	   r>  r   element_ptr_typecoerce_to_simpleAddNode	CloneNoder   r   r   r   	is_stringr
   r   CastNodeDereferenceNoder   r   r   r   r   assignable_fromrB  r   r   r   r   _find_for_from_node_relationsr  r   r   )r^   r*   rJ  r   neg_step
slice_baserg  ri  rh  r2  
step_valueptr_type
carray_ptrstart_ptr_nodestop_ptr_nodecounterr  rW  rX  r   rQ  rR  for_nodes                          r#   r   .IterationTransform._transform_carray_iteration  s0   j)":":;;#J$Z%5%56E#JOO4DD!22*..*VW 
 $$$j..	0C0CDDDD#J$$E$U[[1E#EJJ/D#EJJ/D!$"6"6<<..!3..24..25%??66dhh(bcK "&!5!5J&0[
)A~H$,,55dhhJPD__%%##+jnn&RS#JE$$--jnnjoo>R>RSD ??..jnn&RSKOOJ$@$@$BRBRBTUE>>*">">@P@P@RSD< ((11*.."Ejnn&`a!))22:>>1E4??002H001A1A1CD
U**a/&..		#N (ND((A-%--",,Z8 #"4#3#3#56  &//
;M&&x0{{4;;??3??$$$)9)9)E)E)E'"6"66(11--%//1 --	 / 09y(($*:*:*<0>	   )77KKOO#++33DKKOOQG"**224;;??AF% ++  [[$$T[[-=-=-M-MhN`N`-a-a'L %..''//C!''	)L  0 00'11$++2B2B262B2B2DFL 22++//++ 
 !!HH"DII.0  $AA(U	9((HH!YD(( ''HHWI 	r%   c           
      "   UR                   R                  n[        U5      S:X  a  [        UR                  S5        U$ [        U5      S:  a  [        UR                  S5        U$ UR
                  R                  (       d  U$ UR
                  R                  n[        U5      S:w  a  U$ Uu  pVUR                  nUR                  (       d  UR                  (       d  U$ [        U5      S:X  a,  [        US   5      R                  XpR                  5       5      nO)[        R                  R                  UR                  SUS9n[         R"                  " U5      n	[        R$                  " UR                  U	[        R                  R                  UR                  SUS9SUUR                  S9n
[&        R(                  " UR                  UU	S	9[&        R(                  " UR                  U	U
S	9/n[+        UR,                  [&        R.                  5      (       a(  XR,                  R0                  -   UR,                  l        OIUR3                  UR,                  5        [&        R.                  " UR,                  R                  US
9Ul        Xal        UR4                  R                  UR                  U R                  5       5      Ul        US   UR6                  l        [         R:                  " XR=                  XR6                  R8                  5      5      $ )Nr   z)enumerate() requires an iterable argumentr   z%enumerate() takes at most 2 argumentsr   r   r8  )rB   rC   r   rE   r)  r3  r   )r  r   rM   r   r   r   r   rE   r   r  r,   r   r   r   r   r   r   r;  r  r   r   r(   r   r   r   rO   r   r   r   rI  r   )r^   r*   enumerate_functionr   targetsenumerate_targetiterable_targetcounter_typerg  tempinc_expression	loop_bodys               r#   r  1IterationTransform._transform_enumerate_iterationP  sn   !++00t9>$((=?KY]$((9;K{{22K++""w<1K,3)',,''0C0CKt9>'Q0::<IYIYI[\E%%--.@.D.Dal-[E##E*"**"" ((001<0P".. &&&**& &&&**$&		 dii!3!344'))//9DIIOTYY'**		!#DI &II''(<(<d>N>N>PQ	!%a   '>'>t]]E[E['\]]r%   c                 4    U(       a	  U(       a  ggU(       a  gg)N)r0  r/  r+  )r-  r,  r.  rj   )r^   neg_step_valuer   s      r#   r  0IterationTransform._find_for_from_node_relations  s        r%   c                 .   UR                   R                  n[        U5      S:  a/  UR                  nSn[        R
                  R                  US5      nOeUS   nUR                  n[        UR                  [        5      (       d  U$ UR                  nUS:X  a  U$ [        R
                  R                  XV5      n[        U5      S:X  aM  [        R
                  R                  UR                  S5      nUS   R                  U R                  5       5      n	ODUS   R                  U R                  5       5      nUS   R                  U R                  5       5      n	U R                  US:  U5      u  pS nU(       Ga(  Xp[        U5      nUS:w  Ga  [        UR                  [        5      (       a  [        U	R                  [        5      (       a  US:  a+  U	R                  nUR                  nXX-
  S-
  U-  -  -
  S-
  nO*UR                  nU	R                  nXX-
  S-
  U-  -  -   S-   n[        R
                  R                  UR                  U[        R                   " UR"                  U	R"                  5      S9nO([$        R&                  " U	5      nU R)                  XXv5      nUS:  a  U* n[+        U5      Ul        Xgl        UR                  U R                  5       5      nU	R.                  (       d"  SnU=(       d    [$        R&                  " U	5      n	OSn[0        R2                  " UR                  UR4                  XXXqR6                  UR8                  SS9
nUR;                  U R                  5       5        U(       a  [$        R<                  " U	U5      nU$ )	Nr   r   r   r   r   TF)	r   rz  rQ  rR  r{  rh  r   r   r|  )r  r   rM   r   r   r   r?  r(   r=   r  coerce_to_indexr   r  r  r   r	   spanning_typerE   r   r;  _build_range_step_calculationstrr   r  r   r  r   r   r   set_up_looprI  )r^   r*   range_functionr   r   step_posr  rh  rz  r{  rQ  rR  bound2_ref_nodeabs_stepbegin_value	end_valuebound1_valuebound2_is_tempr  s                      r#   r  -IterationTransform._transform_range_iteration  s"   '',,t9q=%))HJ$$--h:D7DxxHd22C88--JQ$$--hCDt9>&&//0B0BAFF!W,,T-=-=-?@F!W,,T-=-=-?@F!W,,T-=-=-?@F#AA*q.RZ[	#F:H1}v55s;;"6#9#93??!A~&,&<&<$*$:$:	'2+BY\]B]bjAj5k'kno'o&,&<&<$*$:$:	'0@WZ[@[`h?h3i'ilm'm&..66

L'55fkk6;;O 7 QF
 '0&:&:6&BO!??CF >$J_
)##D$4$4$67  !N$D	(<(<V(DF"N((HH;;II(( 	T--/0 ((:Hr%   c                 "   [        U5      n[        R                  " UR                  UR                  5      nUR                  R                  (       a,  US:  a&  [        R                  " U[        R
                  5      nO [        R                  " XcR                  5      nUS:  a  UnUn	Sn
OUnUn	Sn
[        R                  " UR                  [        R                  " UR                  UU
[        R                  " UR                  [        R                  R                  UR                  XWS9S[        R                  " UR                  [        R                  " UR                  [        R                  " UR                  USU	US9S[        R                  R                  UR                  S5      US9S	[        R                  R                  UR                  XWS9US9US9US9U
[        R                  R                  UR                  S5      US9nU$ )
Ni  r   r7  r8  r   *r  r   z//)r  r	   r  rE   r  r  r   rG  r   MulNoder   r   DivNodeSubNode)r^   rz  r  rh  r  r  r  spanning_step_typer  r  final_opstep_calculation_nodes               r#   r  0IterationTransform._build_range_step_calculation  s   z?"00o>R>RS996 1!+!9!9-I^I^!_!+!9!9-!S>)KIH K'IH ) 4 4JJ))

(!"**JJ&..66vzz86e &..

!*!2!2"JJ%.%6%6 &

)4),)2%2&4 &)%.%6%6%>%>vzz1%M!3
"5 "&!*!2!2!:!:6::x!:!i/1  ,)-* (3)4 &&..vzz1==! > %$r%   c                 
   / n[         R                  " [        R                  5      nUR	                  U5        UR                  UR                  5      n[         R                  " [        R                  5      nUR	                  U5        UR                  UR                  5      n	S =n
=pU(       am  U(       af  UR                  R                  (       a>  [        UR                  R                  5      S:X  a  UR                  R                  u  pO/U$ UR                  nO U(       a  UR                  n
OUR                  n[        UR                  [        R                  5      (       a  UR                  nO4[        R                  " UR                  R                  UR                  /S9n[         R                  " [        R                  5      nUR	                  U5        [         R"                  " UR                  UR                  UR                  5      [        R$                  " UR&                  5      S9n[         R                  " [        R(                  5      nUR	                  U5        UR                  UR                  5      n[         R"                  " UR                  U[        R$                  " UR&                  5      S9n[        R*                  " XR                  UR                  5      U	XUU5      nUR-                  U R/                  5       5      nU/UR0                  SS& U(       aR  [         R2                  " UR                  US9nUR5                  SR7                  [        U5      S::  a  SOS	5      S
U/S9nO1[         R8                  " UR                  5      nUR5                  S5      n[         R:                  R=                  UR                  [?        UR&                  [@        RB                  L 5      5      n[        RD                  " UR                  U	[         R:                  RG                  UR                  S5      S9[        RD                  " UR                  U[         RH                  " UR                  SU RJ                  [L        RN                  " SS5      UUUUU/SS9S9[        RP                  " UR                  S UURR                  S9/n[         RT                  " UR                  U[        R                  " UR                  US9S9$ )Nr   r   r   r~  r   r   )'NoneType' object has no attribute '%{}s'   .30 PyExc_AttributeErrorr   format_argsr   r   __Pyx_dict_iterator	dict_iterr    Tr  r   r)  r:  r   r   )+r   r   r	   py_object_typerO   r   r   r>  r   r   rM   r   r(   r   r   r   r   r  
c_ptr_typerE   r  DictIterationNextNoder   r   r   IdentifierStringNoder#  formatNullNoder   r   r  r
   r   r   r?  rj  PyDict_Iterator_func_typer   r!   rH  r   r   )r^   r*   r   r   r   r   r   r  	dict_temppos_temp
key_targetvalue_targettuple_targetr   dict_len_tempdict_len_temp_addris_dict_tempis_dict_temp_addriter_next_nodemethod_nodeis_dictresult_codes                         r#   r   ,IterationTransform._transform_dict_iteration#  s   ##J$=$=>THHX\\*	##J$@$@AT88DHH%377
7\F{{22t{{''(A-/3{{/?/?,J  K#{{J;;Ldii!3!34499D%%DIIMM/3yyk;D ",,Z-I-IJ]#&44HHm//=&&}'9'9:< ##J$9$9:Txx)%33HHl&&tyy13 44((6l (;;D<L<L<NO)*

1Q#88VTK11;BBCPVK[]L]5cef.%h 2 (H
 $,,X\\:K112UVH##++DHHc(--7K\K\:\6]^ &&''001=
 &&22LL)22#.#:#:;#U$g{<NPab 
  "..	#2 ''HHE### 	r%   r   r  method_namep_orig_length	p_is_dictrL   is_setp_is_setc                    / n[         R                  " [        R                  5      nUR	                  U5        UR                  UR                  5      n[         R                  " [        R                  5      nUR	                  U5        UR                  UR                  5      n[        UR                  [        R                  5      (       a  UR                  nO4[        R                  " UR                  R                  UR                  /S9n[         R                  " [        R                  5      nUR	                  U5        [        R                  " UR                  UR                  UR                  5      [        R                  " UR                  5      S9n	[         R                  " [        R                   5      nUR	                  U5        UR                  UR                  5      n
[        R                  " UR                  U
[        R                  " UR                  5      S9nUR"                  n[        R$                  " XXR                  UR                  5      XlU
5      nUR'                  U R)                  5       5      nU/UR*                  SS& [        R,                  R/                  UR                  [1        UR                  [2        R4                  L 5      5      n[        R6                  " UR                  U[        R,                  R9                  UR                  S5      S9[        R6                  " UR                  U[        R:                  " UR                  SU R<                  [>        R@                  " SS5      X.X/SS	9S9[        RB                  " UR                  S UURD                  S
9/n[         RF                  " UR                  U[        R                  " UR                  US9S9$ )Nr  r~  r   r   __Pyx_set_iteratorset_iterr    Tr  r:  r   r   )$r   r   r	   r  rO   r   r   r>  r(   r   r   r   r   r  r  rE   r  r   SetIterationNextNoder   r   r   r   r   r  r
   r   r   r?  rj  PySet_Iterator_func_typer   r!   rH  r   r   )r^   r*   set_objr   r  set_tempr  r   set_len_tempset_len_temp_addris_set_tempis_set_temp_addrr  r  r  r  s                   r#   r   +IterationTransform._transform_set_iteration  s   ##J$=$=>T88GKK(##J$@$@AT88DHH%dii!3!34499D%%DIIMM/3yyk;D !++J,H,HI\"%33HHl..w{{;&&|'8'89; ##J$9$9:Thhtxx($22HHk&&tyy13 {{33&&w{{3X[Z';;D<L<L<NO)*

1Q""**488SIYIY9Y5Z[ &&%%..txx;
 &&00KK(11!,!8!8\!R!+<O 
  ,,	#2 ''HHE### 	r%   rj   F)(rt   ru   rv   rw   rx   r   r   r   r  r   r	   	CFuncTypec_char_ptr_typeCFuncTypeArgr
   r   rk  r>  rl  r   r   r  r  r  r  r  r  r  r  r   r   r  r  r  r  r   r  r  r   rz   rj   r%   r#   r   r      s   0dEIVA(aF #-"6"6""##C););TB%%#'
 ",!5!5$$##C););TB'
 	"%&N  *33!!##FJ,A,A4H##FJ,F,FM##GZ-I-I4P$
  (2';';##C)B)BDI##Hj.N.NPTU##FJ,J,JDQ##FJ,E,EtL	 
 ($VSpUnB^H
!Ob0%d\| !+ 4 4!!##FZ-F-FM##I
0E0EtL##MJ4M4MtT##Oj6V6VX\]##K*2K2KTR$!  *33!!##EJ,E,EtL##Hz/D/DdK##Oj6V6VX\]##J1J1JDQ	$ Br%   r   c                       \ rS rSrSrSrS rS rS rS r	S r
S	 rS
 rS rS rS r\R"                  R$                  rSrg)SwitchTransformi  z
This transformation tries to turn long if statements into C switch statements.
The requirement is that every clause be an (or of) var == value, where the var
is common among all clauses and both var and value are ints.
)NNNc                 d    [        U[        R                  [        R                  45      (       a  UR                  nO[        U[        R
                  5      (       a  UR                  R                  nOY[        U[        R                  5      (       a  UR                  nO-[        U[        R                  5      (       a  UR                  nOOM  [        U[        R                  5      (       Gax  UR                  b  U R                  $ UR                  5       (       a  [        UR                  [        R                   [        R"                  45      (       aP  UR$                  S:H  nU(       a  U(       d  U R                  $ X1R&                  U R)                  UR                  5      4$ UR+                  5       (       Gd  UR$                  S:X  a  SnO&U(       a  UR$                  S:X  a  SnOU R                  $ [-        UR&                  UR&                  5      (       a  UR                  R.                  (       a  X1R&                  UR                  /4$ [1        UR                  SS 5      (       a>  UR                  R2                  R4                  (       a  X1R&                  UR                  /4$ [-        UR                  UR                  5      (       a  UR&                  R.                  (       a  X1R                  UR&                  /4$ [1        UR&                  SS 5      (       a>  UR&                  R2                  R4                  (       a  X1R                  UR&                  /4$ U R                  $ [        U[        R6                  5      (       a  UR$                  S:X  d  U(       a  UR$                  S:X  ay  UR$                  S:H  nU R9                  UR&                  U5      u  pEnU R9                  UR                  U5      u  pxn	Ub)  XG:X  a$  [-        XX5      (       a  U(       a  U(       a  XEXi-   4$ U R                  $ )	NTr   r   F!=r   orr1  )r(   r   CoerceToTempNodeCoerceToBooleanNoder)   BoolBinopResultNoder   EvalWithTempExprNodesubexpressionTypecastNoder   r   cascadeNO_MATCHis_c_string_containsrC   r   r  r   rB   extract_in_string_conditionsis_python_comparisonr7   r  getattrr   is_constr@  extract_conditions)
r^   condallow_not_inr   not_in_1t1c1not_in_2t2c2s
             r#   r   "SwitchTransform.extract_conditions  s   $!;!;!*!>!>!@ A AxxD)"?"?@@xx||D)"@"@AA))D)"8"899||  dI4455||'}}$**,,dmmi.C.CYEXEX-YZZ(2,==(}}d.O.OPTP]P].^^^..00==D("F!dmmt&;!F==( #4==$--@@}}//%}}t}}oEE >>!%!4!4!=!=%}}t}}oEE"4==$--@@}}//%}}t}}oEE >>!%!4!4!=!=%}}t}}oEE }} i5566}}$$--5:P $ 6#'#:#:4==,#W b#'#:#:4==,#W b>h&:r?V?V$'RU22}}r%   c           
      J   [        U[        R                  5      (       ar  [        [	        [        [        UR                  5      5      5      n[        [        R                  R                  UR                  5      nU Vs/ s H
  oC" U5      PM     sn$ UR                  nUR                  n[        [        [        U5      5       Vs1 s H	  ouXwS-    iM     sn5      nU Vs/ s H,  n[        R                  " UR                  [!        X5      US9PM.     sn$ s  snf s  snf s  snf )Nr   r   r=   )r(   r   r   sortedrL   r   r   r   r   r   r   r   encodingr   rM   CharNoder   )	r^   string_literalcharvalsnode_for_charcharval
charactersr-  i	characters	            r#   r  ,SwitchTransform.extract_in_string_conditions  s    ni&;&;<<c#c>+?+?"@ABH#I$5$5$=$=~?Q?QRM:BC(wM'*(CC (--J!**HU3z?=S U=SQs"3=S UVJ '13&0 ''(:(:-PYBd8AC&03 3 D
 !V3s   >DD 3D c                    U R                  X#5      u  pEnUc  U R                  $ Ub  [        XQ5      (       d  U R                  $ UR                  R                  (       d  UR                  R
                  (       aV  [        U Vs/ s H:  owR                  R                  =(       d    UR                  R
                  (       + PM<     sn5      (       a  U R                  $ XEU4$ s  snf r'   )r   r  r7   rE   r  r  r   )r^   
common_varr   r"  r   var
conditionsr!  s           r#   extract_common_conditions)SwitchTransform.extract_common_conditions$  s    "&"9"9)"RZ;== #OC,L,L== ((//SXX%5%5#ISTii&&;$))*;*;<T;V ;V== J&& Us   ACc                    [        5       nU H  nUR                  5       (       a/  UR                  U;   a    gUR                  UR                  5        MG   UR                  nUR
                  R                  (       d  UR
                  R                  (       a  UR                  b  UR                  nOUR                  n XR;   a    gUR                  U5        M     g! [         a       gf = f)NTF)rL   r  r=   addr   rE   r  is_cpp_enumenum_int_valuecnameAttributeError)r^   condition_valuesseenr   value_entryvalue_for_seens         r#   has_duplicate_values$SwitchTransform.has_duplicate_values/  s    u%E((**((D0../ "'++K$))11[5E5E5Q5Q + : : F)4)C)C)4):): ")(' &(  &   s   AC1C
C)(C)c           	      .   U R                   R                  S5      (       d  U R                  U5        U$ S n/ nUR                   Hs  nU R	                  X$R
                  S5      u  pRnUc  U R                  U5        Us  $ UR                  [        R                  " UR                  UUR                  S95        Mu     U VVs/ s H  owR                    H  oPM     M     n	nn[        U	5      S:  a  U R                  U5        U$ U R                  U	5      (       a  U R                  U5        U$ U R                  US5        U H  nU R                  US5        M     [        U5      n[        R                  " UR                  UUUR                   S9n
U
$ s  snnf )Noptimize.use_switchFr   r:  r   r   r   r   r   testcasesr   )current_directivesgetra   r   r;  r   rO   r   SwitchCaseNoder   r   r:  rM   rG  r1   SwitchStatNoder   )r^   r*   r8  rN  	if_clause_r:  caser!  rC  switch_nodes              r#   visit_IfStatNode SwitchTransform.visit_IfStatNodeH  s   &&**+@AAt$K
I(,(F(F//)8%A:!""4(LL--)--9C3<>>C D ) #@"TtDDU 	 @ 1$t$K$$%566t$K 	4/DtV,  !,
**txx0:167;7G7GI '@s    Fc                 n   U R                   R                  S5      (       d  U R                  U5        U$ U R                  S UR                  S5      u  p#nUb%  [        U5      S:  d  U R                  U5      (       a  U R                  U5        U$ U R                  XXBUR                  UR                  5      $ )NrJ  Tr   )
rO  rP  ra   r;  rM  rM   rG  build_simple_switch_statementtrue_val	false_valr^   r*   r   r8  r:  s        r#   visit_CondExprNode"SwitchTransform.visit_CondExprNoden  s    &&**+@AAt$K)-)G)G$))T*#&Jz?Q&,,Z88t$K11jMM4>>+ 	+r%   c                    U R                   R                  S5      (       d  U R                  U5        U$ U R                  S US5      u  p#nUb%  [	        U5      S:  d  U R                  U5      (       a2  U R                  U5        UR                  U R                  5       5        U$ U R                  XXB[        R                  " UR                  SS9[        R                  " UR                  SS95      $ NrJ  Tr   r   F)rO  rP  ra   r;  rM   rG  wrap_operandsr   rZ  r   r   r   r]  s        r#   visit_BoolBinopNode#SwitchTransform.visit_BoolBinopNode  s    &&**+@AAt$K)-)G)G$*&Jz?Q&,,Z88t$t//12K11jtxxt4txxu57 	7r%   c                    U R                   R                  S5      (       d  U R                  U5        U$ U R                  S US5      u  p#nUb%  [	        U5      S:  d  U R                  U5      (       a  U R                  U5        U$ U R                  XXB[        R                  " UR                  SS9[        R                  " UR                  SS95      $ ra  )
rO  rP  ra   r;  rM   rG  rZ  r   r   r   r]  s        r#   r   $SwitchTransform.visit_PrimaryCmpNode  s    &&**+@AAt$K)-)G)G$*&Jz?Q&,,Z88t$K11jtxxt4txxu57 	7r%   c           	      .   [         R                  " U5      n[        R                  " UR                  UUR                  UR                  U R                  5       5      SS9n[        R                  " UR                  UUR                  UR                  U R                  5       5      SS9n	U(       a  Xp[        R                  " UR                  UUS9/n
[        U5      n[        R                  " UR                  UU
U	S9n[         R                  " X{5      nU$ )NTr   r   firstrK  rL  )r   r.   r   r   r   r   rE   r   rQ  r1   rR  r   )r^   r*   r8  r:  r   r[  r\  r   	true_body
false_bodyrN  rV  replacements                r#   rZ  -SwitchTransform.build_simple_switch_statement  s    ,,T2
..HH""499d.>.>.@A		
 //HH##DIIt/?/?/AB	
 $.z%%DHH3=-68 9 !,
**2<389CE  66zOr%   c                 @   U R                   R                  S5      (       d  U R                  U5        U$ UR                  nUR                  nU R                  U5        UR                  ULa2  [
        R                  " UR                  U5      (       d  UR                  $ U$ )NrJ  )rO  rP  ra   r  	lazy_tempr   tree_contains)r^   r*   	orig_exprtemp_refs       r#   visit_EvalWithTempExprNode*SwitchTransform.visit_EvalWithTempExprNode  s    &&**+@AAt$K &&	>>4 Y.((););XFF)))r%   rj   N)rt   ru   rv   rw   rx   r  r   r  r;  rG  rW  r^  rc  r   rZ  rs  r   VisitorTransformrecurse_to_childrenry   rz   rj   r%   r#   r  r    sU    
 "H5n3	'2$L+"7&7$: ))==Jr%   r  c                   J    \ rS rSrSrS r\R                  R                  r	Sr
g)FlattenInListTransformi  z^
This transformation flattens "x in [val1, ..., valn]" into a sequential list
of comparisons.
c           	        ^^ U R                  T5        TR                  b  T$ TR                  S:X  a  SmSnOTR                  S:X  a  SmSnOT$ [        TR                  [
        R                  [
        R                  [
        R                  45      (       d  T$ TR                  nTR                  R                  n[        U5      S:X  aE  UR                  5       (       a.  TR                  S:H  n[
        R                  " TR                  US9$ T$ [        U Vs/ s H  ofR                   PM     sn5      (       a  T$ ["        R$                  " U5      n/ n/ nU H  nUR                  5       (       d'  ["        R&                  " U5      nUR)                  U5        [
        R*                  " TR                  UUUS S	9n	UR)                  [
        R,                  " TR                  U	[.        R0                  S
95        M     UU4S jn
[3        X5      n["        R4                  " X;5      nUS S S2    H  n["        R4                  " X5      nM     U$ s  snf )Ninr  r   r   r1  r  r   r   )r   rB   r   rC   r  )r   r   rE   c                 F   > [         R                  " TR                  TU US9$ )N)r   r   rB   rC   )r   r@  r   )leftrightconjunctionr*   s     r#   concat;FlattenInListTransform.visit_PrimaryCmpNode.<locals>.concat  s&    **&*hh+6+/+0	2 2r%   rJ   )ra   r  r   r(   rC   r   	TupleNoder   SetNoderB   r   rM   try_is_simpler   r   r   r   r   r.   r;  rO   r   r  r	   c_bint_typer   r  )r^   r*   	eq_or_neqr   r   r=   r)   condsr   r!  r  r   r   r  r~  s    `            @r#   r   +FlattenInListTransform.visit_PrimaryCmpNode  s   4 <<#K]]d"KI]]h&KIK$--)*=*=*3*<*<*3*;*;*= > > Kmm}}!!t9>  """&--8"; ))$((/JJK$/$3$/00K%%c*C$$&&**3/S!++&*hh+.+4+.*.0D LL//&*hh*.'1'='=? @  	2 6)	11#A$B$KD 55dEH  G 0s   Irj   N)rt   ru   rv   rw   rx   r   r   ru  rv  ry   rz   rj   r%   r#   rx  rx    s     
>@ ))==Jr%   rx  c                   V    \ rS rSrSr\R                  R                  rS r	S r
S rSrg)DropRefcountingTransformi  z&Drop ref-counting in safe places.
    c                    / / p2/ / pT/ nUR                    H  n[        U[        R                  5      (       aN  U R	                  UR
                  UXF5      (       d  Us  $ U R	                  UR                  UXV5      (       d  Us  $ Mp  [        U[        R                  5      (       a  Us  $ Us  $    U(       d  U(       ai  U VV	s/ s H  u  pUPM	     n
nn	U VV	s/ s H  u  pUPM	     nnn	[        U
5      [        U5      :w  a  U$ [        [        U
5      5      [        U5      :w  a  U$ U(       d  U(       a  / nU H0  nU R                  U5      nU(       d  Us  $ UR                  U5        M2     / nU H0  nU R                  U5      nU(       d  Us  $ UR                  U5        M2     [        U5      [        U5      :w  a  U$ [        [        U5      5      [        U5      :w  a  U$ U$ U Vs/ s H  nUR                  PM     nnU H
  nSUl        M     X#-    H  u  nnUU;  d  M  SUl        M     XE-    H
  nSUl        M     U$ s  sn	nf s  sn	nf s  snf )z6
Parallel swap assignments like 'a,b = b,a' are safe.
F)r   r(   r   r   _extract_operandr   r   CascadedAssignmentNoderL   rM   _extract_index_idrO   r)   use_managed_ref)r^   r*   
left_namesright_namesleft_indicesright_indicesr   statpathnlnamesrnameslindiceslhs_nodeindex_idrindicesrhs_nodet	temp_argsr  rT  	name_node
index_nodes                          r#   visit_ParallelAssignmentNode5DropRefcountingTransform.visit_ParallelAssignmentNode!  s+    #%bK&("mJJD$ : :;;,,TXXz-9B BK,,TXX{-:C CKC D%">">??  +57:t:F7+68;t;F86{c&k)3v;3{#33= H(11(;K)	 )
 H)11(;K)	 * 8}H-3x=!S%77 K$)*EqQUUE	*D#(D   '4LAy	),1	) 5 '6J).J& 7 W 88> +s   H?I&Ic                 R   [        U5      nUR                  R                  (       d  g[        U[        R
                  5      (       a  UR                  U5        UR                  n/ nUnUR                  (       aL  UR                  (       a  gUR                  UR                  5        UR                  nUR                  (       a  ML  UR                  (       aD  UR                  UR                  5        UR                  SR                  US S S2   5      U45        gUR                  (       a}  UR                   R                  ["        R$                  :w  a  gUR&                  R                  R(                  (       d  gUR                   R                  (       d  gUR                  U5        gg)NF.rJ   T)r1   rE   r   r(   r   r  rO   r)   r   r6   memberr8   r   r"   joinr   r   r
   r"  r2  r  )r^   r*   namesindicesr   	name_pathobj_nodes          r#   r  )DropRefcountingTransform._extract_operandf  s.   4 yy$$dI6677LL88D	##""X__-||H	 ###
 X]]+LL388IddO4d;=  yy~~!2!22::??))99$$NN4   r%   c                     UR                   nUR                  n[        U[        R                  5      (       a  UR
                  nO![        U[        R                  5      (       a  g g UR
                  U4$ r'   )r   r2  r(   r   r4   r"   	ConstNode)r^   r  r   r2  	index_vals        r#   r  *DropRefcountingTransform._extract_index_id  sZ      eY//00

Iy2233		9%%r%   rj   N)rt   ru   rv   rw   rx   r   ru  rv  ry   r  r  r  rz   rj   r%   r#   r  r    s)    ))==JCJ:
&r%   r  c                   T   \ rS rSrSr\R                  R                  rS r	S r
S rSS jrSS jrSS	 jrS
 rS rS rS rS rS r\R,                  " \R0                  \R2                  " S\R4                  S5      /5      rS rS rS rS rS r S r!S r"S r#S r$S r%S r&S r'Sr(g)EarlyReplaceBuiltinCallsi  a  Optimize some common calls to builtin types *before* the type
analysis phase and *after* the declarations analysis phase.

This transform cannot make use of any argument types, but it can
restructure the tree in a way that the type analysis phase can
respond to.

Introducing C function calls here may not be a good idea.  Move
them to the OptimizeBuiltinCalls transform instead, which runs
after type analysis.
c                     U R                  U5        UR                  nU R                  U5      (       d  U$ U R                  XUR                  5      $ r'   )ra   r  _function_is_builtin_name_dispatch_to_handlerr   )r^   r*   r  s      r#   visit_SimpleCallNode-EarlyReplaceBuiltinCalls.visit_SimpleCallNode  sF    4 ==--h77K((CCr%   c                    U R                  U5        UR                  nU R                  U5      (       d  U$ UR                  n[	        U[
        R                  5      (       d  U$ UR                  nU R                  XXAR                  5      $ r'   )
ra   r  r  positional_argsr(   r   r  r   r  keyword_args)r^   r*   r  r  r   s        r#   visit_GeneralCallNode.EarlyReplaceBuiltinCalls.visit_GeneralCallNode  sy    4 ==--h77K((	)Y%8%899K~~((D"3"35 	5r%   c                     UR                   (       d  gU R                  5       nUR                  UR                  5      nX2R	                  5       R                  UR                  5      La  gg)NFT)r   r   r=  r"   r<  lookup_here)r^   r  r  r   s       r#   r  2EarlyReplaceBuiltinCalls._function_is_builtin_name  sR     

8==)))+77FFr%   Nc                     Uc  SUR                   -  nOSUR                   -  n[        XS 5      nUb  Uc  U" X5      $ U" XU5      $ U$ )Nz_handle_simple_function_%sz_handle_general_function_%s)r"   r  )r^   r*   r  r   kwargshandler_namehandle_calls          r#   r  -EarlyReplaceBuiltinCalls._dispatch_to_handler  sW    >7(--GL88==HLd$7"~"4.."4v66r%   c                     [         R                  " UR                  R                  UR                  R                  X#US9Ul        g )Nr  )r   PythonCapiFunctionNoder  r   r"   )r^   r*   rA  	func_typer  s        r#   _inject_capi_function.EarlyReplaceBuiltinCalls._inject_capi_function  s2    !88MMt}}115')r%   c           
          U(       d  SnO)[        U[        5      (       d  US:  a  SnOUS:X  a  SnOSnUb  SU-  nOSn[        UR                  SXU[	        U5      4-  5        g Nr  r   z...xzexpected %s, z3%s(%s) called with wrong number of args, %sfound %dr(   r  r   r   rM   r^   function_namer*   r   expectedarg_strexpected_strs          r#   _error_wrong_arg_count/EarlyReplaceBuiltinCalls._error_wrong_arg_count  o    G#&&(Q,G]GG*X5LLdhhML#d)Q= = 	>r%   c                    U(       d  [         R                  " UR                  SS9$ [        U5      S:  a  U R	                  SXS5        [        US   SS 5      nU[        R                  [        R                  4;   a  US   $ U$ )N0.0r   r   floatr   rE   )
r   	FloatNoder   rM   r  r  r	   c_double_typer
   
float_type)r^   r*   pos_argsarg_types       r#   _handle_simple_function_float6EarlyReplaceBuiltinCalls._handle_simple_function_float  st    &&txxu==x=1''C8A;5
00'2D2DEEA;r%   c                 h   [        U5      nS =pEUS:X  a  Uu  nO+US:X  a  Uu  pFO US:X  a  Uu  pFnOU R                  SX5        U$ [        R                  " UR                  U=(       d     [        R
                  " UR                  5      UU=(       d     [        R
                  " UR                  5      S9$ )Nr   r   r   slice)rg  ri  rh  )rM   r  r   r  r   NoneNode)r^   r*   r  r  rg  rh  ri  s          r#   _handle_simple_function_slice6EarlyReplaceBuiltinCalls._handle_simple_function_slice  s    M	>ED!^"KE4!^ (E''@K""HH79--dhh75++DHH5	7 	7r%   c                 V   [        U5      S:w  a  U$ US   n[        U[        R                  [        R                  45      (       ac  [        UR
                  5      S:X  aJ  [        R                  R                  UR                  [        UR
                  5      [        R                  S9$ U$ )zUnpack ord('X').
        r   r   r   )rM   r(   r   r   r  r   r   r   r   r   r	   c_long_type)r^   r*   r  r)   s       r#   _handle_simple_function_ord4EarlyReplaceBuiltinCalls._handle_simple_function_ord  s     x=AKqkcI1193F3FGHH399~" ((00#cii.zOeOe0ffr%   c                 &    U R                  XS5      $ )zTransform

_result = all(p(x) for L in LL for x in L)

into

for L in LL:
    for x in L:
        if not p(x):
            return False
else:
    return True
F_transform_any_allr^   r*   r  s      r#   _handle_simple_function_all4EarlyReplaceBuiltinCalls._handle_simple_function_all	  s     &&tu==r%   c                 &    U R                  XS5      $ )zTransform

_result = any(p(x) for L in LL for x in L)

into

for L in LL:
    for x in L:
        if p(x):
            return True
else:
    return False
Tr  r  s      r#   _handle_simple_function_any4EarlyReplaceBuiltinCalls._handle_simple_function_any  s     &&tt<<r%   c                 0   [        U5      S:w  a  U$ [        US   [        R                  5      (       d  U$ US   nUR                  R
                  nUR                  n[        U5      u  pxUc  U$ U(       a  Un	O[        R                  " UR                  US9n	[        R                  " UR                  S [        R                  " UR                  U	[        R                  " UR                  [        R                  " UR                  US9S9S9/S9n
[        R                  " UR                  [        R                  " UR                  U(       + S9S9Ul        [         R"                  " XHU
5        [        R$                  " UR                  XC(       a  SS	9$ SS	9$ )
Nr   r   r   r   r   )r   r   r   all)gen	orig_func)rM   r(   r   GeneratorExpressionNodedef_nodegbodyr   r~   r   r   r   r   r   ReturnStatNoder   r   r   recursively_replace_nodeInlinedGeneratorExpressionNode)r^   r*   r  is_anygen_expr_nodegenerator_bodyr[  yield_expressionyield_stat_noder   rU  s              r#   r  +EarlyReplaceBuiltinCalls._transform_any_all)  sr   x=AK(1+y'H'HIIK &//55"''	,I),T)#K(I!))*:*>*>HXYI$$  d""$(('--'001A1E1EVTV@	
	 !& 4 4HH$$%5%9%9VL!N	 	((S77=VEX 	XQVX 	Xr%   itc                    [        U5      S:w  a  U$ US   n[        U[        R                  5      (       a!  UR                  [
        R                  L a  UnGON[        U[        R                  5      (       a  Un[        UR                  5      nU(       d  U$ [        R                  " UR                  US[
        R                  S9nU HF  u  px[        R                  " UR                  UUR                  S9n	[        R                  " XXU	5        MH     OUR                   (       a  UR#                  5       nOq[        R$                  " UR                  UR'                  5       (       a0  UR                  [(        R*                  [
        R                  4;   a  SOSU R,                  USS	9n[        R.                  " UR                  U5      $ )
zTransform sorted(genexpr) and sorted([listcomp]) into
[listcomp].sort().  CPython just reads the iterable into a
list and calls .sort() on it.  Expanding the iterable in a
listcomp is still faster and the result can be sorted in
place.
r   r   r,  r  comprehension_typerf   r   __Pyx_PySequence_ListKeepNewPySequence_ListTre  )rM   r(   r   ComprehensionNoderE   r
   r"  r  r|   loopr  r   ComprehensionAppendNoder   r   r  r   as_listrj  result_in_tempr	   r  PySequence_List_func_typeSortedListNode)
r^   r*   r  r)   	list_noder  r}   r  r   append_nodes
             r#   _handle_simple_function_sorted7EarlyReplaceBuiltinCalls._handle_simple_function_sortedQ  sr    x=AKqkc96677CHHHYHY<YIY>>??M5m6H6HI#!@@-8#*#4#46I 6F1 '??$(()$++- 00Q\] 6F (( I
 "44))++Z=V=VX_XiXi<j0j /*..t-I '')<<r%   c                 v   [        U5      S;  a  U$ [        US   [        R                  [        R                  45      (       d  U$ US   nUR
                  n[        U[        R                  5      (       a  [        U5      u  pVSnUc  U$ OHUR                  nUR                  n UR                  (       a  UR                  R                  (       d  U$  [        U5      S:X  a+  [        R                  R                  UR                  S5      nOUS   n[         R"                  " UR                  [$        R&                  S9n[(        R*                  " UR                  U[        R,                  " UR                  SX5      S9n	[.        R0                  " X6U	5        [(        R2                  " UR                  [(        R*                  " UR                  [         R"                  " UR                  US9US	S
9U/S9n
[        R4                  " UR                  XUR6                  SUR8                  S9$ ! [         a    Us $ f = f)zLTransform sum(genexpr) into an equivalent inlined aggregation loop.
        r   r   r   Nr   )r   rE   r8  r   )r   r/   Trh  r   sum)r
  result_node
expr_scoper  has_local_scope)rM   r(   r   r  r	  r
  r~   rO   rf   r  rE   r  rB  r   r?  r   r   r.   r	   r  r   r   rG  r   r  r   r  r  r  )r^   r*   r  r  r[  r  r   rg  r   add_node	exec_codes              r#   __handle_simple_function_sum5EarlyReplaceBuiltinCalls.__handle_simple_function_sum  s    x=%K(1+	(I(I(1(C(C(E F FK !&&	mY%F%FGG0Mi0X-#' ( ,22O.33'22:J:O:O:V:VK ;W x=A%%..txx;EQKE,,
@Y@YZ
--  &&txxjS 	((R&&HH**II#11dhh:V 	"
 		 77i&11u+;;= 	== " s   $-H) )H87H8c                 &    U R                  XS5      $ )Nr0  _optimise_min_maxr  s      r#   _handle_simple_function_min4EarlyReplaceBuiltinCalls._handle_simple_function_min      %%dc::r%   c                 &    U R                  XS5      $ )Nr,  r  r  s      r#   _handle_simple_function_max4EarlyReplaceBuiltinCalls._handle_simple_function_max  r#  r%   c                 4   [        U5      S::  aC  [        U5      S:X  a#  US   R                  (       a  US   R                  n[        U5      S::  a  U$ [        [	        [
        R                  USS 5      5      nUS   nU Ho  n[
        R                  " U5      n[        R                  " UR                  UU[        R                  " UR                  UUUS9S9n[
        R                  " Xu5      nMq     USSS2    H  n[
        R                  " X5      nM     U$ )zKReplace min(a,b,...) and max(a,b,...) by explicit comparison code.
        r   r   NrB   r   rC   )r[  r\  rM  rJ   )rM   r   r   listr   r   r.   r   CondExprNoder   r   r  )	r^   r*   r   r   cascaded_nodeslast_resultarg_noder   ref_nodes	            r#   r   *EarlyReplaceBuiltinCalls._optimise_min_max  s     t9>4yA~$q'"A"AAw||4yA~c)"9"948DE1g&H"00=J#00#& //LL'')		
K $88QK ' 'tt,H#88OK - r%   c                     U(       d   [         R                  " UR                  / SS9$ U R                  X[        R
                  5      nX1La  [         R                  " UR                  US9$ U$ )Nrj   r   r=   )r)   )r   r  r   _transform_list_set_genexprr
   r"  AsTupleNode)r^   r*   r  results       r#   &_DISABLED_handle_simple_function_tuple?EarlyReplaceBuiltinCalls._DISABLED_handle_simple_function_tuple  sZ    &&txxb"MM 11$'BSBST((v>>r%   c                     [        U5      S:w  a  U$ US   R                  (       a  US   R                  (       d  US	 U$ [        US   [        R
                  5      (       a  US   R                  5       US'   U$ )zSReplace frozenset([...]) by frozenset((...)) as tuples are more efficient.
        r   r   )rM   r   r   r(   r   r   as_tupler  s      r#   !_handle_simple_function_frozenset:EarlyReplaceBuiltinCalls._handle_simple_function_frozenset  sp     x=AKA;..x{7G7G  Y%7%788"1+..0HQKr%   c                     U(       d   [         R                  " UR                  / / S9$ U R                  X[        R
                  5      $ Nr1  )r   r   r   r2  r
   r"  r  s      r#   _handle_simple_function_list5EarlyReplaceBuiltinCalls._handle_simple_function_list  s7    %%dhhRLL//@Q@QRRr%   c                     U(       d(  [         R                  " UR                  / [        5       S9$ U R	                  X[
        R                  5      $ r<  )r   r  r   rL   r2  r
   r   r  s      r#   _handle_simple_function_set4EarlyReplaceBuiltinCalls._handle_simple_function_set  s9    $$TXXBNN//@P@PQQr%   c                    [        U5      S:  a  U$ [        US   [        R                  5      (       d  U$ US   nUR                  n[        U5      nU(       d  U$ [        R                  " UR                  UU[        R                  L a  SOSUS9nU HF  u  p[        R                  " UR                  UUR                  S9n
[        R                  " XIU
5        MH     U$ )zLReplace set(genexpr) and list(genexpr) by an inlined comprehension.
        r   r   rL   r)  r  r  )rM   r(   r   r  r
  r|   r  r   r
   r   r  r   r   r  )r^   r*   r  rn  r  r[  r}   r  r  r   r  s              r#   r2  4EarlyReplaceBuiltinCalls._transform_list_set_genexpr	  s     x=1K(1+y'H'HIIK !&&	1)<K>>HHm*g.>.>>eF*,
 2B-#;; $$%"))+K ,,][Y 2B r%   c                    [        U5      S:X  a   [        R                  " UR                  / 0 S9$ [        U5      S:  a  U$ [	        US   [        R
                  5      (       d  U$ US   nUR                  n[        U5      nU(       d  U$ U HE  u  pg[	        U[        R                  5      (       d  Us  $ [        UR                  5      S:w  d  MC  Us  $    [        R                  " UR                  US[        R                  S9nU Ha  u  pi[        R                  " UR                  UR                  S   UR                  S   UR                  S9n
[        R                   " X9U
5        Mc     U$ )zDReplace dict( (a,b) for ... ) by an inlined { a:b for ... }
        r   key_value_pairsr=   r   r   r   r  )key_expr
value_exprr   )rM   r   DictNoder   r(   r  r
  r|   r  r   r  r
   r   DictComprehensionAppendNoder   r   r  )r^   r*   r  r  r[  r}   r  rT  r  r   r  s              r#   _handle_simple_function_dict5EarlyReplaceBuiltinCalls._handle_simple_function_dict%  sN    x=A%%dhhTVWWx=1K(1+y'H'HIIK !&&	1)<K#3.	0C0CDD#(()Q.	 $4  >>HHmv&002 2B-#?? $$)..q1+003"))	+K
 ,,][Y 2B r%   c                 j    [        U5      S:  a  U$ [        U[        R                  5      (       d  U$ U$ )z\Replace dict(a=b,c=d,...) by the underlying keyword dict
construction which is done anyway.
r   )rM   r(   r   rI  )r^   r*   r  r  s       r#   _handle_general_function_dict6EarlyReplaceBuiltinCalls._handle_general_function_dictK  s2     x=1K&)"4"455Kr%   rj   r'   ))rt   ru   rv   rw   rx   r   ru  rv  ry   r  r  r  r  r  r  r  r  r  r  r  r  r	   r  r
   r"  r  r  r  r  5_EarlyReplaceBuiltinCalls__handle_simple_function_sumr!  r%  r   r5  r9  r=  r@  r2  rK  rN  rz   rj   r%   r#   r  r    s    
 ))==JD
5)
>$7$	> = "XH !+ 4 4		 	 z'@'@$	GH!J/=b8=t;;F	S
R
8"Lr%   r  c                   L    \ rS rSr\R
                  R                  rS rS r	Sr
g)InlineDefNodeCallsiV  c                 >   UR                   c  g UR                   R                  (       a  g U R                  5       R                  UR                  5      nU(       a*  UR
                  (       a  [        UR
                  5      S:w  a  g UR
                  S   R                  $ Nr   r   )cf_state
cf_is_nullr   r=  r"   cf_assignmentsrM   r   )r^   r  r   s      r#   get_constant_value_node*InlineDefNodeCalls.get_constant_value_nodeY  sx    %((  ")))..9U11 4 45:##A&***r%   c                    U R                  U5        U R                  R                  S5      (       d  U$ UR                  nUR                  (       d  U$ U R                  U5      n[        U[        R                  5      (       d  U$ [        R                  " UR                  UX1R                  UR                  S9nUR                  5       (       a  U R                  X5      $ U$ )Nzoptimize.inline_defnode_calls)r  r  r   generator_arg_tag)ra   rO  rP  r  r   rX  r(   r   PyCFunctionNodeInlinedDefNodeCallNoder   r   r[  can_be_inlinedreplace)r^   r*   r  r  inlineds        r#   r  'InlineDefNodeCalls.visit_SimpleCallNodee  s    4 &&**+JKKK$$K//>(I$=$=>>K22HHMII"446 !!##<<..r%   rj   N)rt   ru   rv   rw   r   ru  rv  ry   rX  r  rz   rj   r%   r#   rR  rR  V  s    ))==J
+r%   rR  c                   '   \ rS rSrSrS rS rS rS r\	R                  " \	R                  \	R                  " S\	R                  S5      /5      rS	 rS
 r\	R                   \	R"                  \	R$                  4 V VVs0 s H2  nU[        R                  " U[        R                  " SUS5      /5      _M4     snnn rS r\	R                  " \	R*                  \	R                  " S\	R,                  S5      /SS9r\	R                  " \	R"                  \	R                  " S\	R,                  S5      /SS9rS rSS jrS rS rS r\	R                  " \R>                  \	R                  " S\	R                  S5      /5      r S r!\!r"S r#\	R                  " \RH                  \	R                  " S\RH                  S5      /5      r%S r&\	R                  " \RN                  \	R                  " S\	R                  S5      /5      r(S r)\	R                  " \RT                  \	R                  " S\RN                  S5      /5      r+S r,\	R                  " \RZ                  \	R                  " S\	R                  S5      /5      r.S r/\	R                  " \R`                  \	R                  " S\	R                  S5      /5      r1S r2\	R                  " \	R"                  \	R                  " S\	R                  S5      /S S!S"9r3S# r4\	R                  " \Rj                  \	R                  " S\	R                  S5      /5      r6\	R                  " \Rj                  \	R                  " S$\	R"                  S5      /5      r7S% r8S& r9\	R                  " \Rt                  \	R                  " S$\	R                  S5      /5      r;\	R                  " \Rt                  \	R                  " S$\Rx                  S5      /5      r=S' r>\	R                  " \	R~                  \	R                  " S(\	R                  S5      /SS9rA\	R                  " \	R~                  \	R                  " S)\	R                  S5      /SS9rC\	R                  " \	R~                  \	R                  " S\	R                  S5      /SS9rD\R>                  S*\R                  S+\R                  S,\RN                  S-\RT                  S.\RZ                  S/\R`                  S/\RH                  S00R                  rHS11rIS2 rJ\	R                  " \R                  \	R                  " S3\	R                  S5      /5      rLS4 rM\	R                  " \	R                  \	R                  " S\	R                  S5      /5      rOS5 rPS6 rQ\	R                  " \	R                  \	R                  " S7\	R                  S5      \	R                  " S8\RT                  S5      /5      rR\	R                  " \	R                  \	R                  " S7\	R                  S5      \	R                  " S8\RT                  S5      \	R                  " S9\RH                  S5      /5      rS SS: jrT SS; jrU\	R                  " \	R                  \	R                  " S\	R                  S5      \	R                  " S<\	R                  S5      /SS9rWS= rXS> rY\	R                  " \	R                  \	R                  " S?\	R                  S5      \	R                  " S$\	R*                  S5      /SS9rZ\	R                  " \	R                  \	R                  " S?\	R                  S5      \	R                  " S$\	R                  S5      /SS9r[S@ r\\	R                  " \	R                  \	R                  " S\	R                  S5      /5      r]\	R                  " \	R                  \	R                  " S\	R                  S5      \	R                  " SA\	R                  S5      \	R                  " SB\	R~                  S5      \	R                  " SC\	R*                  S5      /S!SD9r^SE r_SSF jr`\	R                  " \	R                  \	R                  " S\	R                  S5      /SS9raSG rb\	R                  " \	R                  \	R                  " S\	R                  S5      \	R                  " SH\	R                  S5      \	R                  " SI\	R                  S5      /5      rcSJ rd\	R                  " \	R                  \	R                  " S\	R                  S5      \	R                  " SH\	R                  S5      \	R                  " SI\	R                  S5      \	R                  " SK\	R*                  S5      /5      reSL rf\	R                  " \	R                  \	R                  " S\	R                  S5      \	R                  " SH\	R                  S5      \	R                  " SI\	R                  S5      /5      rg\	R                  " \	R*                  \	R                  " S\	R                  S5      \	R                  " SH\	R                  S5      \	R                  " SI\	R                  S5      /\	R*                  R                  S9riSM rj\	R                  \	R"                  4 V VVVs0 s GH  n[        R                  [        R                  4  H  nX44[        R                  " U[        R                  " SN[        R                  S5      [        R                  " SO[        R                  S5      [        R                  " SPUS5      [        R                  " SQ[        R                  S5      [        R                  " SR[        R                  S5      /UR                  (       a  SOUR                  S9_M     GM     snnnn rmSS rnST roSU rpSV rqSW rrSX rsSY rtSZ ruS[ rvS\ rwS] rxS^ ryS_ rzS` r{\nr|\or}\pr~\qr\rr\sr\tr\ur\vr\wr\xr\yr\zrSa rSb rSc rSd rSe rSf rSg rSh rSi r\	R                  " \	R                  \	R                  " Sj\	R,                  S5      /5      rSk r\r\r\r\r\r\r\r\r\r\r\	R                  " \	R,                  \	R                  " Sj\	R,                  S5      /5      r \	R                  " \RN                  \	R                  " Sl\R>                  S5      \	R                  " Sm\	R                  S5      /5      rSn r\	R                  " \RN                  \	R                  " Sl\R>                  S5      \	R                  " So\	R                  S5      \	R                  " Sp\	R~                  S5      /5      rSq r\	R                  " \R>                  \	R                  " Sl\R>                  S5      \	R                  " Sr\	R                  S5      /5      rSs r\	R                  " \	R                  \	R                  " Sl\	R                  S5      \	R                  " St\	R                  S5      \	R                  " Su\	R~                  S5      \	R                  " Sv\	R~                  S5      \	R                  " Sw\	R*                  S5      /SS9rSx rSy rSz r\	R                  " \	R~                  \	R                  " Sl\R>                  S5      \	R                  " St\	R                  S5      \	R                  " Su\	R~                  S5      \	R                  " Sv\	R~                  S5      \	R                  " Sw\	R*                  S5      /S{S9rS| rS} rS~ r\	R                  " \	R~                  \	R                  " Sl\R>                  S5      \	R                  " St\	R                  S5      \	R                  " Su\	R~                  S5      \	R                  " Sv\	R~                  S5      /SS9rS r\	R                  " \R>                  \	R                  " Sl\R>                  S5      \	R                  " St\	R                  S5      \	R                  " S\	R                  S5      \	R                  " S\	R~                  S5      /5      rS r\	R                  " \R                  \	R                  " S\R>                  S5      \	R                  " S\	R                  S5      \	R                  " S\	R                  S5      /5      r\	R                  " \R                  \	R                  " S\R>                  S5      /5      r/ SQr\ V VVs/ s H  nUG[h        GRj                  " U5      4PM     snnn rS r\	GRp                  " \	R                  " \R>                  \	R                  " S\	R                  S5      \	R                  " S\	R~                  S5      \	R                  " S\	R                  S5      /5      5      r\	R                  " \R>                  \	R                  " S\	R                  S5      \	R                  " Su\	R~                  S5      \	R                  " S\	R~                  S5      \	R                  " S\	R                  S5      \	R                  " S\	R                  S5      \	R                  " S\S5      /5      r\	R                  " \R>                  \	R                  " S\	R                  S5      \	R                  " Su\	R~                  S5      \	R                  " S\	R~                  S5      \	R                  " S\	R                  S5      \	R                  " S\	R                  S5      \	R                  " S\S5      /5      rSrS r\rS rS rS rS rS r SSS\GR                  GR                  S!4S jrS r\	R                  " \	R                  \	R                  " S\	R                  S5      /5      rS rS rS rSrgs  snnn f s  snnnn f s  snnn f )OptimizeBuiltinCallsix  a(  Optimize some common methods calls and instantiation patterns
for builtin types *after* the type analysis phase.

Running after type analysis, this transform can only perform
function replacements that do not alter the function return type
in a way that was not anticipated by the type analysis.
c                 D    U R                  U5        UR                  5       $ )z:Flatten redundant type checks after tree changes.
        )ra   	reanalyserb   s     r#   visit_PyTypeTestNode)OptimizeBuiltinCalls.visit_PyTypeTestNode  s     	4 ~~r%   c                     U R                  U5        UR                  UR                  R                  :X  a  UR                  $ U$ )z
Drop redundant type casts.
)ra   rE   r   rb   s     r#   _visit_TypecastNode(OptimizeBuiltinCalls._visit_TypecastNode  s7     	4 99)))<<r%   c                    U R                  U5        [        UR                  [        R                  5      (       a  UR                  R
                  Ul        UR                  nUb"  UR                  (       d  UR                  (       a  gUR                  (       aH  UR                  (       a7  UR                  R                  (       d  UR                  R                  (       a  gU$ )z'
Drop dead code and useless coercions.
N)ra   r(   rf   r   r  r)   rD   r  r   r   is_localis_arg)r^   r*   rf   s      r#   rg   'OptimizeBuiltinCalls.visit_ExprStatNode  s     	4 dii!=!=>>		DIyy<4<<4??<<DJJDJJ,?,?4::CTCTr%   c                    U R                  U5        UR                  n[        U[        R                  5      (       a  UR                  n[        U[        R
                  5      (       aW  UR                  [        R                  [        R                  4;   a)  UR                  R                  U R                  5       5      $ U$ )z<Drop redundant conversion nodes after tree changes.
        )ra   r)   r(   r   PyTypeTestNoder  rE   r	   r  r
   	bool_typecoerce_to_booleanr   r^   r*   r)   s      r#   visit_CoerceToBooleanNode.OptimizeBuiltinCalls.visit_CoerceToBooleanNode  s     	4 hhc93344''Cc97788xxJ55w7H7HIIww001A1A1CDDr%   oNc                 $   U R                  U5        UR                  n[        U[        R                  5      (       a  UR                  n[        U[        R
                  5      (       Ga'  UR                  R                  S:X  Ga  [        UR                  5      S:X  a  UR                  S   nUR                  [        R                  L a  UR                  S5      $ UR                  R                  (       a  UR                  R                  S:X  a  [        R
                  " UR                   SU R"                  U/SUR$                  [&        R(                  " SS5      UR*                  S	9R-                  UR                  U R/                  5       5      $ U$ )
z3Drop redundant conversion nodes after tree changes.r  r   r   =float() argument must be a string or a number, not 'NoneType'__Pyx_PyObject_AsDouble__Pyx_PyNumber_Floatpynumber_floatzTypeConversion.c)r   py_namer)  r  r  )ra   r)   r(   r   CoerceFromPyTypeNoderj  r  r"   rM   r   rE   r
   r  r#  r   rA  r   PyNumber_Float_func_typer)  r   r!   r  r   r   )r^   r*   r)   func_args       r#   visit_CoerceToPyTypeNode-OptimizeBuiltinCalls.visit_CoerceToPyTypeNode  s*   4 hhc999::''Cc97788||  G+CHH0B88A;==G$6$66#556uvv]]..3<<3E3EIb3b$77"8$:W:W&Z ' $'2'>'>?OQc'd'+':':  i		4+;+;+=>? r%   c                 p   U R                  U5        UR                  nUR                  R                  (       dF  UR                  UR                  :w  a*  UR	                  UR                  U R                  5       5      nU$ [        U[        R                  5      (       a  UR                  nUR                  (       a  UR                  R                  (       a  [        U[        R                  5      (       dt  UR                  R                  (       a  [        U[        R                  5      (       d:  UR                  R                  (       aI  [        U[        R                  5      (       a*  UR	                  UR                  U R                  5       5      $ U$ [        U[        R                  5      (       Ga  UR                  [         R"                  L ak  UR                  R%                  UR                  R                  5      (       a4  UR                  R	                  UR                  U R                  5       5      $  U$ UR                  [&        R(                  L at  UR                  R                  R*                  (       aO  UR                  R*                  (       a4  UR                  R	                  UR                  U R                  5       5      $ U$ [        U[        R,                  5      (       aG  UR                  R                  (       d  UR                  R                  (       a  U R/                  X5      $ U$ )zDrop redundant conversion nodes after tree changes.

Also, optimise away calls to Python's builtin int() and
float() if the result is going to be coerced back into a C
type anyway.
)ra   r)   rE   r   r   r   r(   r   rp  r  r  r   is_floatr  r   r  r	   r  r  r
   r   is_unicode_charr  _optimise_numeric_cast_callrs  s      r#   visit_CoerceFromPyTypeNode/OptimizeBuiltinCalls.visit_CoerceFromPyTypeNode  s    	4 hhxx##yyCHH$mmDIIt/?/?/ABJc93344''C>>		  ZY5F5F%G%GII&&:c9;N;N+O+OII$$C9K9K)L)L}}TYY0@0@0BCC  Y99::xx:44499,,SWW\\::77,,TYY8H8H8JKK ;  W11177<<//DII4M4M77,,TYY8H8H8JKK  Y5566yy499#5#577BBr%   r)   c           
      n   UR                   nS n[        U[        R                  5      (       a  UR                  nOy[        U[        R
                  5      (       aZ  UR                  R                  (       a?  [        UR                  [        R                  5      (       a  UR                  R                  nUb  [        U5      S:w  a  U$ US   n[        U[        R                  5      (       a  UR                  nOUR                  R                  (       a  U$ UR                  S:X  Ga  UR                  R                  (       d  UR                  R                  (       a  UR                  UR                  :X  a  U$ UR                  [         R"                  [         R$                  4;   a  U R'                  XR                  U5      $ UR                  R)                  UR                  5      (       d  UR                  R*                  (       a)  [        R,                  " UR.                  XQR                  S9$  U$ UR                  R*                  (       a  UR                  R0                  (       a  UR                  R2                  S:X  a  SnOSUR                  R2                  -   n[        R                  " UR.                  UU R4                  UR                     U/SUR6                  UR8                  S9R;                  UR                  U R=                  5       5      $ U$ UR                  S	:X  Ga
  UR                  R*                  (       d  UR                  R*                  (       a  UR                  UR                  :X  a  U$ UR                  [         R"                  [         R$                  4;   a  U R'                  XR                  U5      $ UR                  R)                  UR                  5      (       d  UR                  R*                  (       a)  [        R,                  " UR.                  XQR                  S9$ U$ )
Nr   r   r  r~  l__Pyx_truncltrunc)r  r   r|  r)  r  r  )r  r(   r   rj  r   r4   rE   is_builtin_typer  r  rM   r  r)   r   r"   r  r	   r   c_py_unicode_type_pyucs4_to_numberr  r  r  r   
is_numericmath_h_modifierfloat_float_func_typesr)  r  r   r   )r^   r*   r)   r  r   r  truncls          r#   r  0OptimizeBuiltinCalls._optimise_numeric_cast_call  s   <<c9778888D)"4"455}},,CMM9K^K^1_1_}}))<3t9>K7h	 < <==||H]]&&K==E!}}##tyy'7'7==DII-#O]]z'@'@*B^B^&__11$xPPYY..x}}==AWAW$11$((HS\S\]] BX4 1 ''DII,@,@==00C7+F$x}}'D'DDF 33HHf"99(--H"! LL#'#6#6 )DIIt'7'7'9:;$  ]]g%}}%%););==DII-#O]]z'@'@*B^B^&__11$xPPYY..x}}==AWAW$11(D Dr%   rJ   ra  g      c                 X   US;   d   e[         R                  " UR                  US:X  a  SOSUS:X  a  U R                  OU R                  U/UUR
                  UR                  [        R                  " US:X  a  SOSS5      S9R                  UR                  U R                  5       5      $ )	N)r  r  r  __Pyx_int_from_UCS4__Pyx_double_from_UCS4
int_pyucs4float_pyucs4
Builtins.c)r  r   r|  r)  r  r  )r   rj  r   pyucs4_int_func_typepyucs4_double_func_typer)  r  r   r!   r   rE   r   )r^   r*   py_type_namer  s       r#   r  &OptimizeBuiltinCalls._pyucs4_to_number7	  s    ////++HH|u/D+Jb3?53Hd//dNjNj LL..$00QVAV\jlxy
 )DIIt//1
2	3r%   c           
          U(       d  SnO)[        U[        5      (       d  US:  a  SnOUS:X  a  SnOSnUb  SU-  nOSn[        UR                  SXU[	        U5      4-  5        g r  r  r  s          r#   r  +OptimizeBuiltinCalls._error_wrong_arg_countC	  r  r%   c                     U$ r'   rj   )r^   r*   r  r  arg_listr  s         r#   _handle_function%OptimizeBuiltinCalls._handle_functionU	  s    r%   c           
      X   U(       a  U$ U(       a,  UR                   (       a  UR                  R                  (       d  U$ U R                  5       R	                  U5      nU(       d  U$ [
        R                  " UR                  R                  [
        R                  " UR                  UUUR                  S9USS9R                  U R                  5       5      n	U	c  U R                  XXEU5      $ UR                  n
U
c'  UR                  (       a  UR                  R                  n
[
        R                  " UR                  U	U
S9nU(       d  UR                  Ul        UR#                  U R                  5       5        SUl        UR'                  UR                  U R                  5       5      $ )z
Try to inject C-API calls for unbound method calls to builtin types.
While the method declarations in Builtin.py already handle this, we
can additionally resolve bound and unbound methods here that were
assigned to variables ahead of time.
)r"   r   rE   T)r8   r9   	is_calledr*  )r   r8   r   r   r=  r   r5   r  r   r4   rE   analyse_as_type_attribute%_optimise_generic_builtin_method_callr   r  r  r^   analyse_c_function_callanalysedr   )r^   r*   	type_name	attr_namer  r  is_unbound_methodr  
type_entryr   r   	call_nodes               r#   _handle_method#OptimizeBuiltinCalls._handle_methodX	  s^    Kx44HLL<P<P K%%'..y9
K((MM"" __	&
   65d6F6F6HI 	 >==5FH Hyy<DNN>>&&D,,HH	 !%\\IN))$*:*:*<=!	""499d.>.>.@AAr%   c                 \   [        U5      nU(       d(  US:  d"  UR                  (       a  UR                  (       d  U$ UR                  R                  R
                  (       d  U$ UR                  R                  [        R                  L a  U$ [        R                  " XR                  X$5      $ )z
Try to inject an unbound method call for a call to a method of a known builtin type.
This enables caching the underlying C function of the method at runtime.
r   )
rM   r   r6   r8   rE   r  r
   rN   r   CachedBuiltinMethodCallNode)r^   r*   r  r  r  r  r  s          r#   r  :OptimizeBuiltinCalls._optimise_generic_builtin_method_call	  s}    
 M		Qx7L7LQYQdQdK||  00K<< 1 11K44,,	5 	5r%   r8   c           
         [        U5      S:w  a8  [        U5      S:X  a'  [        R                  " UR                  [	        5       S9$ U$ US   nUR
                  [        R                  L a1  UR                  5       (       d  U$ Sn[        R                  " SS5      nOSn[        R                  " SS5      n[        R                  " UR                  XPR                  UUR                  US	S
9$ )z5Optimise single argument calls to unicode().
        r   r   r   __Pyx_PyUnicode_UnicodePyUnicode_UnicodeStringTools.c__Pyx_PyObject_UnicodePyObject_Unicodeunicoder   r)  r  r|  )rM   r   r   r   r   rE   r
   r   may_be_noner   r!   rj  PyObject_Unicode_func_typer)  )r^   r*   r  r  r)   rA  r  s          r#   _handle_simple_function_unicode4OptimizeBuiltinCalls._handle_simple_function_unicode	  s     x=A8}! ,,TXX]_MMKqk88w+++??$$
-E&223FXL,E&223EWL++HHe<<LL% 	r%   c                 8   U R                  U5        UR                  R                  [        R                  L aa  UR
                  (       dP  UR                  (       d?  UR                  (       a  UR                  S:X  a  U R                  USUR                  /5      $ U$ )zSimplify or avoid plain string formatting of a unicode value.
This seems misplaced here, but plain unicode formatting is essentially
a call to the unicode() builtin, which is optimised right above.
r_  N)	ra   r   rE   r
   r   c_format_specformat_specconversion_charr  rb   s     r#   visit_FormattedValueNode-OptimizeBuiltinCalls.visit_FormattedValueNode	  so    
 	4 ::??g2224;M;MVZVfVf''4+?+?3+F;;D$UUr%   r   c                     [        U5      S:w  a  U$ US   nUR                  [        R                  L aH  UR	                  S5      n[
        R                  " UR                  SU R                  U/UR                  S9$ U$ )z;Replace dict(some_dict) by PyDict_Copy(some_dict).
        r   r   r'  PyDict_Copyre  )
rM   rE   r
   r   r#  r   rj  r   PyDict_Copy_func_typer)  r^   r*   r  r  r)   s        r#   rK  1OptimizeBuiltinCalls._handle_simple_function_dict	  sx     x=AKqk88w(((''(DEC//-)C)Cu,, 
 r%   r  c                 N   [        U5      S:w  a  U$ US   n[        R                  " UR                  UR	                  5       (       aE  UR	                  5       (       a0  UR
                  [        R                  [        R                  4;   a  SOSU R                  UUR                  S9$ )z0Turn list(ob) into PySequence_List(ob).
        r   r   r  r  re  )rM   r   rj  r   r  rE   r	   r  r
   r"  r  r)  r  s        r#   r=  1OptimizeBuiltinCalls._handle_simple_function_list	  s     x=AKqk++HH''))c.@.@.B.BHH!:!:G<M<M NN + '**LL	
 		
r%   r)  c                    [        U5      S:w  d  UR                  5       (       d  U$ US   nUR                  [        R                  L a  UR                  5       (       d  U$ UR                  [        R                  L a@  UR                  S5      US'   [        R                  " UR                  SU R                  USS9$ [        R                  " UR                  U[        R                  S9$ )zDReplace tuple([...]) by PyList_AsTuple or PySequence_Tuple.
        r   r   r   PyList_AsTupleTre  )r)   rE   )rM   r  rE   r
   r!  r  r"  r#  r   rj  r   PyList_AsTuple_func_typer3  r  s        r#   _handle_simple_function_tuple2OptimizeBuiltinCalls._handle_simple_function_tuple	  s     x=AT%8%8%:%:Kqk88w)))#//2C2CJ88w(((//35HQK //*D,I,It- - ((sASASTTr%   c                 X   [        U5      S:w  a  U$ US   R                  (       a  / n/ nUS   R                   HP  nUR                  5       (       d'  [        R
                  " U5      nUR                  U5        UR                  U5        MR     [        R                  " UR                  SUS9nU R                  X5        US S S2    H  n[        R                  " X5      nM     U$ U R                  U[        R                  " UR                  SU R                  UUR                  SS95      $ )Nr   r   )r)  r   rJ   	PySet_NewrL   r   r)  r|  )rM   r   r   	is_simpler   r;  rO   r   r  r   r_  r  rj  PySet_New_func_typer)  )	r^   r*   r  r  r   r   r)   r4  r  s	            r#   r@  0OptimizeBuiltinCalls._handle_simple_function_set
  s   x=AKA;.. DE{''}}#..s3CLL%C 	 (
 &&txxFFLL&dd"77E $M <<i&B&B+(('    r%   c                    U(       d"  [         R                  " UR                  5      /nON[        U5      S:  a  U$ US   R                  [
        R                  L a  US   R                  5       (       d  US   $ [         R                  " UR                  SU R                  UUR                  [        R                  " SS5      SS9$ )Nr   r   __Pyx_PyFrozenSet_Newpyfrozenset_newr  	frozensetr  )r   r  r   rM   rE   r
   r   r  rj  PyFrozenSet_New_func_typer)  r   r!   r^   r*   r  r  s       r#   r9  6OptimizeBuiltinCalls._handle_simple_function_frozenset&
  s    !**48845H]QKa[!7!77@W@W@Y@YA;++HH-**LL$001BLQ! 	!r%   z((double)-1)T)rb  exception_checkc           
         [        U5      S:X  aB  [        R                  " USSS9R                  [        R
                  U R                  5       5      $ [        U5      S:w  a  U R                  SXS5        U$ US   n[        U[        R                  5      (       a  UR                  nUR                  [        R                  L a  U$ UR                  [        R                  [        R                  4;   a  U R!                  XR"                  U5      $ UR                  R%                  UR                  5      (       d  UR                  R&                  (       a)  [        R(                  " UR*                  XAR                  S9$ US   R-                  S	5      nUR                  [        R.                  L a  S
nSnOoUR                  [        R0                  L a  SnSnOMUR                  [        R2                  L a  SnSnO+UR                  [        R4                  L a  SnSnO	US   nSnSn[        R6                  " UR*                  UU R8                  U/UR:                  U(       a  [=        U5      SS9$ SSS9$ )zITransform float() into either a C type cast or a faster C
function call.
r   r  g        r+  r   r  0 or 1r~  rx  __Pyx_PyBytes_AsDoublepybytes_as_double__Pyx_PyByteArray_AsDouble__Pyx_PyUnicode_AsDoublepyunicode_as_doublePyLong_AsDoubleNry  pyobject_as_doubler  )rM   r   r  r   r
   r  r   r  r(   r  r)   rE   r	   r  r   r  r  r"   r  r  r  r   r#  r   r  r   int_typerj  PyObject_AsDouble_func_typer)  r$   )r^   r*   r  r  r  r)   
cfunc_nameutility_code_names           r#   r  2OptimizeBuiltinCalls._handle_simple_function_float=
  s    x=A&&E3)G..0@0@0BCD ]a''JKA;h	 < <==||H==J444O]]z88*:V:VWW))$xHHYY&&x}}559Q9Q))(< < qk++KM ==G...1J 3]]g4445J 3]]g2223J 5]]g...*J $1+C2J 4++HHj,,5ll@Q>*;< 	
 X\ 	r%   r   c           	         [        U5      S:X  a7  [        R                  R                  UR                  S[
        R                  S9$ [        U5      S:w  a  U$ US   n[        U[        R                  5      (       a_  UR                  R                  R                  (       a8  [        R                  " UR                  SU R                  UR                  /SSS9$ U$ UR                  R                  (       aH  UR                  R                  (       a-  [        R                  " UR                  SU R                  USSS9$ U$ )	z7Transform int() into a faster C function call.
        r   r   r   PyLong_FromDoubleTr  r  __Pyx_PyNumber_Int)rM   r   r   r   r   r
   r  r(   r  r)   rE   r  rj  PyLong_FromDouble_func_typer   PyNumber_Int_func_type)r^   r*   r  r  r  s        r#   _handle_simple_function_int0OptimizeBuiltinCalls._handle_simple_function_int}
  s     x=A$$,,TXXqw?O?O,PP]aKA;h	 < <==||  )) 33HH143S3S",,u 
 ==$$)>)>//.0K0KtU< < r%   c                    [        U5      S:X  a.  [        R                  " UR                  S[        R
                  S9$ [        U5      S:w  a  U R                  SXS5        U$ US   R                  U R                  5       5      n[        R                  " UR                  US9n[        R                  " UR                  US9nUR                  U R                  5       5      $ )z=Transform bool(x) into a type coercion to a boolean.
        r   Fr   rE   r   boolr  r   )rM   r   r   r   r
   rq  r  rr  r   r   coerce_to_pyobject)r^   r*   r  r  r   s        r#   _handle_simple_function_bool1OptimizeBuiltinCalls._handle_simple_function_bool
  s     x=A%%dhhe'BSBSTT]a''IK qk33D4D4D4FGG''GDG''GDG--d.>.>.@AAr%   c           	         [        U5      S:w  a  U R                  SXS5        U$ US   R                  R                  (       a;  [        R
                  " UR                  SU R                  US   /UR                  SS9$ US   R                  R                  (       a[  US   R                  [        R                  L a;  [        R
                  " UR                  SU R                  US   /UR                  SS9$ U$ )Nr   
memoryview1r   PyMemoryView_FromObjectr  PyMemoryView_FromBuffer)rM   r  rE   r   r   rj  r   !PyMemoryView_FromObject_func_typer)  r   r   r
   py_buffer_type!PyMemoryView_FromBuffer_func_typer  s       r#   "_handle_simple_function_memoryview7OptimizeBuiltinCalls._handle_simple_function_memoryview
  s    x=A''dcJK{++ 33HH7::$QK="ll*, , !!!((Xa[-B-BgF\F\-\ !33HH7::$QK="ll*, , r%   bytesr  __Pyx_PyUnicode_GET_LENGTHrf  __Pyx_PyByteArray_GET_SIZE__Pyx_PyList_GET_SIZE__Pyx_PyTuple_GET_SIZE__Pyx_PySet_GET_SIZEPyDict_Sizezcpython.array.arrayc                 H   [        U5      S:w  a  U R                  SXS5        U$ US   n[        U[        R                  5      (       a  UR
                  nUR                  R                  (       a9  [        R                  " UR                  SU R                  U/UR                  S9nGO!UR                  R                  (       aO  [        R                  " UR                  SU R                  U/UR                  [        R                  " SS5      S	9nGOUR                  R                   (       at  ["        R$                  " ["        R&                  ["        R(                  " S
UR                  S5      /SS9n[        R                  " UR                  SUU/UR                  S9nGO(UR                  R*                  (       a  U R-                  UR                  5      nUcW  UR                  nUR.                  (       d  UR0                  (       a'  UR2                  R4                  U R6                  ;   a  SnOU$ UR9                  S5      n[        R                  " UR                  XpR:                  U/UR                  S9nOPUR                  R<                  (       a3  [        R>                  RA                  UR                  SUR                  S9$ U$ UR                  ["        RB                  ["        R&                  4;  a*  URE                  UR                  U RG                  5       5      nU$ )zReplace len(char*) by the equivalent call to strlen(),
len(Py_UNICODE) by the equivalent Py_UNICODE_strlen() and
len(known_builtin_type) by an equivalent C-API call.
r   rM   r   __Pyx_ssize_strlenre  __Pyx_Py_UNICODE_ssize_strlenssize_pyunicode_strlenr  r   r)  r  memoryviewsliceNT)nogil__Pyx_MemoryView_LenPy_SIZEz&object of type 'NoneType' has no len()r   )$rM   r  r(   r   r  r)   rE   r  rj  r   Pyx_ssize_strlen_func_typer)  is_pyunicode_ptrPyx_Py_UNICODE_strlen_func_typer   r!   r  r	   r  r>  r  r   _map_to_capi_len_functionis_extension_typer  r   qualified_name_ext_types_with_pysizer#  PyObject_Size_func_typer  r   r   c_size_t_typer   r   )	r^   r*   r  r  r)   r   r  r  r  s	            r#   _handle_simple_function_len0OptimizeBuiltinCalls._handle_simple_function_len
  sd   
 x=A''tqAKqkc97788''C88 33.0O0Ou,,(H XX&& 3394;_;_u,,*667OQ`a	cH
 XX((",,,,++,=sxxN/I !330)UDLL2H XX!!77AJ!88//83K3K$NN99T=X=XX!*JK''8:C 33*&B&BUDLL2H XX%%$$,,TXXqtyy,IIK99Z55z7S7STT))$))T5E5E5GHHr%   objectc                     [        U5      S:w  a  U$ [        R                  " UR                  SU R                  USS9n[        R
                  " U[        R                  5      $ )z7Replace type(o) by a macro call to Py_TYPE(o).
        r   Py_TYPEFre  )rM   r   rj  r   Pyx_Type_func_typer  r	   r  r  s       r#   _handle_simple_function_type1OptimizeBuiltinCalls._handle_simple_function_type  sW     x=AK++HHi!8!8 !!$
(A(ABBr%   c                 <  ^^ [        U5      S:w  a  T$ Uu  pE/ n[        U[        R                  5      (       a  UR                  nOBUR
                  [        R                  L d  [        U[        R                  5      (       a  U/nOT$ [        U5      u  pxU(       ac  U(       d  [        U5      S:  aM  UR                  (       d  UR                  5       (       d'  [        R                  " U5      nUR                  U5        / n	U R                  5       mUb]  U	R                  [        R                   " UR"                  USUS9R%                  T5      R'                  [(        R*                  T5      5        [-        5       n
U GH  nS=pUR.                  (       au  UR0                  (       ad  TR3                  UR0                  R4                  5      nU(       a8  UR
                  (       a'  UR
                  R6                  (       a  UR
                  nU[        R                  L a>  UR4                  S:w  d,  UR8                  (       a  UR8                  R:                  (       d  SnUb+  UR=                  SS9nX;   a  M  U
R?                  U5        U/nO`UR
                  [        R                  L a  S	nXK/nO=UR@                  (       d'  [        R                  " U5      nUR                  U5        S
nXK/nU	R                  [        RB                  " UR"                  XRD                  UUb  URF                  OSSS95        GM     [        RH                  4UU4S jjn[K        UU	5      R'                  TR
                  T5      nUSSS2    H  n[        RL                  " UU5      nM     U$ )zSReplace isinstance() checks against builtin types by the
corresponding C-API call.
r   r   Nisr(  rE   F)exact__Pyx_TypeCheckPyObject_IsInstanceTr   r  r)  c                 |   > U" TR                   SX5      n[        R                  Ul        UR	                  T5        U$ )Nr  )r   r	   r  rE   rb  )r:   r;   make_binop_nodeor_noder  r*   s       r#   join_with_orMOptimizeBuiltinCalls._handle_simple_function_isinstance.<locals>.join_with_orx  s5    %dhha;G%11GL!!#&Nr%   rJ   )'rM   r(   r   r  r   rE   r
   rN   rG   rU   r   r  r   r.   rO   r   r   r   r   r   r	   r  rL   r   r   r=  r"   r  scopeis_builtin_scopetype_check_functionr>  r  rj  Py_type_check_func_typer  rG  r   r  )r^   r*   r  r  r)   
type_nodesr   rP   rQ   
test_nodesbuiltin_teststest_type_nodebuiltin_typer   r3  type_check_argsr/  rU  r  r  s    `                 @r#   "_handle_simple_function_isinstance7OptimizeBuiltinCalls._handle_simple_function_isinstance/  s    x=AK"j)"5"566#J__ 1 11Z
ILcLc5d5d$JK $<J#G  '3u:>s}}--c2S!
 (((%)) !.	
 mC :+A+A3!GI #N#''L%%.*>*>

>#7#7#<#<=UZZEJJ,F,F#(::Lw000::'(D(D#'L'&2&F&FU&F&S#&7!!"56#&%$$(9(99&7##&"7%00%.%<%<^%LNLL0&;##&"7,,"&&(;=Y=Y(7<7H!3!3d 	5 $D 09/C/C 	 	 <4>>tyy#N	$B$KD!66tYGI  r%   c                    [        U5      S:w  a  U$ US   n[        U[        R                  5      (       a  UR                  R
                  R                  (       a`  [        R                  " UR                  UR                  [        R                  S9R                  UR
                  U R                  5       5      $  U$ [        U[        R                  [        R                  45      (       a~  [        UR                  5      S:X  ae  [        R                   R#                  UR                  [%        UR                  5      5      R                  UR
                  U R                  5       5      $ U$ )z-Unpack ord(Py_UNICODE) and ord('X').
        r   r   r~  )rM   r(   r   r  r)   rE   r  r  r   r	   r  r   r   r   r  r   r   r   r   r  s        r#   r  0OptimizeBuiltinCalls._handle_simple_function_ord  s    x=AKqkc97788ww||++ --GGSWW:3I3Ii		4+;+;+=>? ,  i33Y5H5HIJJ399~" ((00#cii.ISSTXT]T]_c_o_o_qrrr%   rE   r   r  c           
      v   UR                   nU(       a  [        U5      S:  a  U$ US   nUR                  (       a  UR                  (       d  U$ UR                  [        R
                  :w  d  UR                  [        R
                  :w  a  U$ UR                  (       a  UR                  (       d  UR                  UR                  :w  a  U$ OUR                  UR                  :w  a  U$ [        R                  " UR                  USS S9nUR                  U R                  5       SS9nUR                  (       Ga  UR                  R                  n	U	R                  (       Ga  U	R                  (       Ga  U	R                  R!                  5       U R                  5       R!                  5       :X  Gal  ["        R$                  " SS5      n
["        R&                  " U	R                  U
5      nU(       Ga,  U R(                  R*                  n[,        R.                  " UR1                  S	5      R                  5      n[,        R2                  " U	[,        R4                  " S
US5      [,        R4                  " S[,        R6                  S5      [,        R4                  " S[,        R6                  S5      /5      n[        R8                  " X}5      nU(       d-  [        R:                  " UR                  [,        R6                  S9n[        R<                  " UR                  UUXxU/SSS9$ OUR?                  S5      n[@        RB                  " SS5      nU(       a9  [        R<                  " UR                  SU RD                  XxU/UURF                  S9$ [        R<                  " UR                  SU RH                  Xx/UURF                  S9$ )zOReplace 'exttype.__new__(exttype, ...)' by a call to exttype->tp_new()
        r   r   Nr   T)skip_childrentp_new__new__PyTypeObjectrE   r   r  r   F)r   may_return_noner)  z4object.__new__(X): X is not a type object (NoneType)zObjectHandling.c__Pyx_tp_new_kwargsr+  __Pyx_tp_new)%r8   rM   r   rE   r
   rN   r  r"   r   r  r   r   r   r  typeobj_cnamer1  r  r   ConstructorSlotget_slot_functionr  cython_scoper	   CPtrTyper=  r  r  r  r  r  rj  r#  r   r!   Pyx_tp_new_kwargs_func_typer)  Pyx_tp_new_func_type)r^   r*   r  r   r  r  r8   type_arg
args_tupleext_typetp_slotslot_func_cnamerJ  PyTypeObjectPtrpyx_tp_new_kwargs_func_typer  s                   r#   _handle_any_slot__new__,OptimizeBuiltinCalls._handle_any_slot__new__  s    ll CIMK7{{("2"2K88w(((HMMW=N=N,NK""#..xx8==( )   CNN2K((QRA
--d . 4
 **//H***x/E/E/ENN//1T5E5E5G5T5T5VV#33HiH"+"="=hnng"V"#'<<#<#<L&0&9&9$++N;@@'BO2<2F2F &33FotT&33Fj>W>WY]^&33Hj>W>WY]^#3/  )11(LH!!*!3!3DHH:C\C\!]$77/3&F;(- $& &  11FHH #..x9KL///1Q1QF3)	  //.$*C*C+)	 r%   c                     U$ r'   rj   )r^   r*   r  r   r  r  s         r#   _handle_any_slot__class__.OptimizeBuiltinCalls._handle_any_slot__class__  s	    
 r%   r   c                     [        U5      S:w  d,  UR                  (       d  UR                  R                  (       a  U$ [        R
                  " UR                  SU R                  USUR                  S[        S5      S9$ )zLOptimistic optimisation as X.append() is almost always
referring to a list.
r   __Pyx_PyObject_AppendFrO   )r   rD  r)  r  r  )
rM   r  r  r   r   rj  r   PyObject_Append_func_typer)  r$   r^   r*   r  r   r  s        r#   #_handle_simple_method_object_append8OptimizeBuiltinCalls._handle_simple_method_object_append  se     t9>T00DMM4G4GK++HH-t/M/M!LL '1
 	
r%   c                    [        U5      S:w  a  U$ Uu  pVUR                  (       d  U$ [        UR                  5      nUR                  c  [        U5      S:  a   U$ U R                  XRUS5      n	U(       d  UR                  U	l        U	$ U	=p[        U5      S:  a+  UR                  5       (       d  [         R"                  " U5      n
/ nUS   nUR                  5       (       d'  [         R"                  " U5      nUR%                  U5        [        R&                  " UR(                  SU R*                  X/S[-        S	5      S
9nUSSS2    H  nUR                  5       (       d'  [         R"                  " U5      nUR%                  U5        [        R.                  " UR(                  S[        R&                  " UR(                  SU R*                  X/SS[-        S5      S9U[0        R2                  S9nM     UR                  Ul        XLa  UR%                  U
5        U H*  n[         R4                  " X5      nUR                  Ul        M,     U$ )zReplace list.extend([...]) for short sequence literals values by sequential appends
to avoid creating an intermediate sequence argument.
r   N   r   TextendrJ   __Pyx_PyList_Append
ListAppendr  |__Pyx_ListComp_AppendListCompAppend)r   r|  r)  r  r   )rM   r   r)  r   mult_factorr(   r   r   r8  r   r   r   r  _wrap_self_argr  r  r   r;  rO   rj  r   r\  r$   rG  r	   c_returncode_typer  )r^   r*   r  r   r  r8   r   r   
tuple_nodewrapped_obj
cloned_objr   r)   r   r  s                  r#   !_handle_simple_method_list_extend6OptimizeBuiltinCalls._handle_simple_method_list_extend  s    t9>K
,,KUZZ (CJN  K))#9JHU)-)<)<K&&&
u:>#--//"--c2J Bi}}&&s+CLL//HH+T-K-K"'5	7
 R=C==??**3/S! ++#,,HH5t7U7U$*H !/0@!A	C
 11	H	 ! #'"5"5 LL$D 55dEH&*&9&9H#  r%   	bytearrayc           
         [        U5      S:w  a  U$ SnU R                  n[        US   5      nUR                  R                  (       d  [        U[        R                  5      (       aF  UR                  [        R                  U R                  5       5      n[        R                  " SS5      nOUR                  (       a]  UR                  5       (       d  U$ UR                  [        R                   U R                  5       5      n[        R                  " SS5      nOCUR                  R"                  (       a&  SnU R$                  n[        R                  " SS5      nOU$ [        R&                  " UR(                  XVUS   U/S	UR*                  US
9n	UR,                  (       a*  U	R                  UR                  U R                  5       5      n	U	$ )Nr   __Pyx_PyByteArray_Appendr   ByteArrayAppendr  __Pyx_PyByteArray_AppendObjectByteArrayAppendObjectr   Fr   rD  r)  r  )rM   PyByteArray_Append_func_typer,   rE   r  r(   r   r   r   r	   r  r   r   r!   r   can_coerce_to_char_literalc_char_typer   "PyByteArray_AppendObject_func_typerj  r   r)  r  )
r^   r*   r  r   r  	func_namer  r   r  r   s
             r#   &_handle_simple_method_bytearray_append;OptimizeBuiltinCalls._handle_simple_method_bytearray_appendX  sf   t9>K.	55	#DG,::
5)2C2C D DOOJ$9$94;K;K;MNE&223DoVL$$3355OOJ$:$:D<L<L<NOE&223DoVLZZ##8I??I&223JO\LK//HHiq'5!!LL%
 ))$))T5E5E5GHHr%   py_indexc_index	is_signed)has_varargsc                 $    U R                  XX4SS9$ )NT)is_list) _handle_simple_method_object_popr]  s        r#   _handle_simple_method_list_pop3OptimizeBuiltinCalls._handle_simple_method_list_pop  s#    44DT 5 C 	Cr%   c                 v   U(       d  U$ US   nU(       a  SnUR                  SSS/S9nOSn[        U5      S:X  aE  [        R                  " UR                  S	U-  U R
                  U/S
UR                  [        S5      S9$ [        U5      S:X  Ga(  [        US   5      n[        R                  " UR                  5      n	UR                  n
UR                  R                  (       d  [        U[        R                  5      (       aN  UR                  U R                  5       5      n	UR!                  ["        R$                  U R                  5       5      nOU(       a  UR                  R&                  (       a5  UR)                  U R                  5       5      n	[        R*                  " U	5      nUR!                  ["        R$                  U R                  5       5      nOvU$ ["        R,                  " UR                  ["        R$                  5      (       d  U$ [        U[        R                  5      (       a  UR                  U R                  5       5      n	U
R                  (       d  UR                  n
U
R/                  U R                  5       5      (       d  U$ U
R0                  n["        R2                  " ["        R4                  ["        R6                  " SU
S5      /5      n[        R                  " UR                  SU-  U R8                  XiU[        R                  R;                  UR                  U
R<                  (       a  SOS5      [        R>                  " UR                  ["        R@                  U
RC                  5       5      [        R>                  " UR                  X5      /S
UR                  [        S5      S9$ U$ )zLOptimistic optimisation as X.pop([n]) is almost always
referring to a list.
r   List*'NoneType' object has no attribute '%.30s'r  rK   r  Objectr   z__Pyx_Py%s_PopTrw  r   intvalNz__Pyx_Py%s_PopIndex	pop_index)"r#  rM   r   rj  r   PyObject_Pop_func_typer)  r$   r,   r  rE   r  r(   r   r  r   r   r	   r>  r   r  r  numeric_type_fitscreate_to_py_utility_codeto_py_functionr  r  r  PyObject_PopIndex_func_typer   signedRawCNameExprNodec_void_typeempty_declaration_code)r^   r*   r  r   r  r  r8   r  r2  r  orig_index_typeconvert_funcconversion_types                r#   r  5OptimizeBuiltinCalls._handle_simple_method_object_pop  s    K1gI''<,"G ( %C
 !It9>//*Y6++U $+E2  Y!^'Q0E ))%))4H#jjO::$$eY%6%677$778H8H8JKH!OOJ,H,H$JZJZJ\]Ezz--#(#9#9$:J:J:L#M ) 3 3H =!OOJ,H,H$JZJZJ\]EK11%**j>Z>Z[[E9#4#455 33D4D4D4FG"))"'**"<<T=M=M=OPP*99L(22))J,C,CHo_c,d+egO///);00U''//		@V@V1\]^00J<R<R1@1W1W1Y[00OZ	\
 !%+K8  r%   c           	          [        U5      S:w  a  U$ U R                  XSU R                  SXC5      R                  UR                  U R
                  5      $ )z?Call PyList_Sort() instead of the 0-argument l.sort().
        r   PyList_Sortsort)rM   _substitute_method_callsingle_param_func_typer   rE   r   r]  s        r#   _handle_simple_method_list_sort4OptimizeBuiltinCalls._handle_simple_method_list_sort  sQ     t9>K++M4+F+F%--6Ytyy$BRBR-S	Tr%   keydefaultc                    [        U5      S:X  a0  UR                  [        R                  " UR                  5      5        O$[        U5      S:w  a  U R                  SXS5        U$ U R                  XSU R                  SXCS[        S5      S	9	$ )
z:Replace dict.get() by a call to PyDict_GetItem().
        r   r   zdict.get2 or 3__Pyx_PyDict_GetItemDefaultrP  Tdict_getitem_defaultrD  r  )	rM   rO   r   r  r   r  r  Pyx_PyDict_GetItem_func_typer$   r]  s        r#   _handle_simple_method_dict_get3OptimizeBuiltinCalls._handle_simple_method_dict_get  s     t9>KK	**48845Y!^''
DIK++)4+L+L$")*@A , C 	Cr%   is_safe_typec                 0   [        U5      S:X  a0  UR                  [        R                  " UR                  5      5        O$[        U5      S:w  a  U R                  SXS5        U$ U R                  XSU R                  SXCS[        R                  " SS	5      S
9	$ )zUReplace dict.setdefault() by calls to PyDict_GetItem() and PyDict_SetItem().
        r   r   zdict.setdefaultr  __Pyx_PyDict_SetDefault
setdefaultTdict_setdefaultr  r  )
rM   rO   r   r  r   r  r  Pyx_PyDict_SetDefault_func_typer   r!   r]  s        r#   %_handle_simple_method_dict_setdefault:OptimizeBuiltinCalls._handle_simple_method_dict_setdefault  s     t9>KK	**48845Y!^''(94xPK++%t'K'K+ $001BLQ , S 	Sr%   c                 f   SnSnU R                   n[        U5      S:X  a0  UR                  [        R                  " UR
                  5      5        OF[        U5      S:X  a"  UR                  (       d  SnSnU R                  nOU R                  SXS5        U$ U R                  XXWS	XCS
[        U5      S9	$ )z7Replace dict.pop() by a call to _PyDict_Pop().
        __Pyx_PyDict_Poppy_dict_popr   r   __Pyx_PyDict_Pop_ignorepy_dict_pop_ignorezdict.popr  rK   Tr  )PyDict_Pop_func_typerM   rO   r   r  r   r  PyDict_Pop_ignore_func_typer  r  r$   )r^   r*   r  r   r  	capi_funcr  r  s           r#   _handle_simple_method_dict_pop3OptimizeBuiltinCalls._handle_simple_method_dict_pop  s     '	)--	t9>KK	**48845Y!^&&5	$8! <<	''
DIK++$ '(9: , < 	<r%   op1op2cvalr9  zerodiv_checkc                 (    U R                  SXX45      $ NAdd_optimise_num_binopr]  s        r#   $_handle_simple_method_object___add__9OptimizeBuiltinCalls._handle_simple_method_object___add__B      ''ttWWr%   c                 (    U R                  SXX45      $ NSubtractr  r]  s        r#   $_handle_simple_method_object___sub__9OptimizeBuiltinCalls._handle_simple_method_object___sub__E      ''
DD\\r%   c                 (    U R                  SXX45      $ )NMultiplyr  r]  s        r#   $_handle_simple_method_object___mul__9OptimizeBuiltinCalls._handle_simple_method_object___mul__H  r  r%   c                 (    U R                  SXX45      $ NEqr  r]  s        r#   #_handle_simple_method_object___eq__8OptimizeBuiltinCalls._handle_simple_method_object___eq__K      ''ddVVr%   c                 (    U R                  SXX45      $ NNer  r]  s        r#   #_handle_simple_method_object___ne__8OptimizeBuiltinCalls._handle_simple_method_object___ne__N  r  r%   c                 (    U R                  SXX45      $ )NAndr  r]  s        r#   $_handle_simple_method_object___and__9OptimizeBuiltinCalls._handle_simple_method_object___and__Q  r  r%   c                 (    U R                  SXX45      $ )NOrr  r]  s        r#   #_handle_simple_method_object___or__8OptimizeBuiltinCalls._handle_simple_method_object___or__T  r  r%   c                 (    U R                  SXX45      $ )NXorr  r]  s        r#   $_handle_simple_method_object___xor__9OptimizeBuiltinCalls._handle_simple_method_object___xor__W  r  r%   c                     [        U5      S:w  d"  [        US   [        R                  5      (       d  U$ US   R	                  5       (       a  SUS   R
                  s=::  a  S::  d   U$   U$ U R                  SXX45      $ )Nr   r   ?   RshiftrM   r(   r   r   r  r=   r  r]  s        r#   '_handle_simple_method_object___rshift__<OptimizeBuiltinCalls._handle_simple_method_object___rshift__Z  w    t9>DGY5F5F!G!GKAw**,,Q$q':Q:Q5WUW5WK 6XK''$$ZZr%   c                     [        U5      S:w  d"  [        US   [        R                  5      (       d  U$ US   R	                  5       (       a  SUS   R
                  s=::  a  S::  d   U$   U$ U R                  SXX45      $ )Nr   r   r  Lshiftr  r]  s        r#   '_handle_simple_method_object___lshift__<OptimizeBuiltinCalls._handle_simple_method_object___lshift__a  r  r%   c                 (    U R                  SXX45      $ N	Remainder_optimise_num_divr]  s        r#   $_handle_simple_method_object___mod__9OptimizeBuiltinCalls._handle_simple_method_object___mod__h  s    %%k44[[r%   c                 (    U R                  SXX45      $ )NFloorDivider  r]  s        r#   )_handle_simple_method_object___floordiv__>OptimizeBuiltinCalls._handle_simple_method_object___floordiv__k  s    %%mTT]]r%   c                 (    U R                  SXX45      $ N
TrueDivider  r]  s        r#   (_handle_simple_method_object___truediv__=OptimizeBuiltinCalls._handle_simple_method_object___truediv__n  s    %%lDD\\r%   c                 (    U R                  SXX45      $ NDivider  r]  s        r#   $_handle_simple_method_object___div__9OptimizeBuiltinCalls._handle_simple_method_object___div__q  s    %%hXXr%   c                    [        U5      S:w  d+  US   R                  5       (       a  US   R                  S:X  a  U$ [        US   [        R
                  5      (       a!  SUS   R                  s=::  a  S::  d   U$   U$ OE[        US   [        R                  5      (       a!  SUS   R                  s=::  a  S::  d   U$   U$ OU$ U R                  XX4U5      $ )Nr   r   r   r   r   l       l          )rM   r  r=   r(   r   r   r  r  )r^   r   r*   r  r   r  s         r#   r  &OptimizeBuiltinCalls._optimise_num_div  s    t9>a!<!<!>!>$q'BYBY]^B^Kd1gy0011d1g55>> ? ?Q!4!455d1g55>> ? ? K''HYZZr%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   #_handle_simple_method_float___add__8OptimizeBuiltinCalls._handle_simple_method_float___add__  r  r%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   #_handle_simple_method_float___sub__8OptimizeBuiltinCalls._handle_simple_method_float___sub__  r  r%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   '_handle_simple_method_float___truediv__<OptimizeBuiltinCalls._handle_simple_method_float___truediv__  s    ''dd^^r%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   #_handle_simple_method_float___div__8OptimizeBuiltinCalls._handle_simple_method_float___div__  s    ''$$ZZr%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   #_handle_simple_method_float___mod__8OptimizeBuiltinCalls._handle_simple_method_float___mod__  s    ''TT]]r%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   "_handle_simple_method_float___eq__7OptimizeBuiltinCalls._handle_simple_method_float___eq__  r  r%   c                 (    U R                  SXX45      $ r  r  r]  s        r#   "_handle_simple_method_float___ne__7OptimizeBuiltinCalls._handle_simple_method_float___ne__  r  r%   c                    [        USS5      (       a  U$ [        U5      S:w  a  U$ UR                  R                  (       a  [        R
                  nO6UR                  [        R                  L a  US;   a  [        R                  nOU$ [        XXdS   US   5      nU(       d  U$ Uu  pp[        U Vs/ s H  oR                  R                  PM     sn5      (       d   e[        U5      U
-   nU R                  X#UU R                  X4   SUSS R                  5       -  XTS	S
U	S9
nUR                  R                  (       a@  UR                  (       d/  [        R                  " XR                  5       UR                  5      nU$ s  snf )I
Optimise math operators for (likely) float or small integer operations.
special_bool_cmp_functionNr   r  r  r   r   z__%s__r   TF)rD  with_none_checkr  )r  rM   rE   r   r	   r  r  optimise_numeric_binopr  r)  r  Pyx_BinopInt_func_typeslowerr   r  r   )r^   r   r*   r  r   r  ret_typer4  
func_cnamer  
extra_argsnum_typer)   r  s                 r#   r  (OptimizeBuiltinCalls._optimise_num_binop  s\    44d;;Kt9>K99  !00HYY*000X5M!--HK'q'4PQ7SK9?6
*D9DSHH((D9::::DzJ&00((()=>x|))++-> !% 1 '	 99  )=)=!44Y@P@P@RTXT]T]^I :s   2Fucharc                    U(       d  [        U5      S:w  a  U$ US   n[        U[        R                  5      (       a%  UR                  R
                  R                  (       d  U$ UR                  nUR                  n[        R                  " SS[        US9S9nSUR                  5       -  n	U R                  XXR                  XtU/US9n
UR
                  R                  (       a  U
R                  U R                   5      n
U
$ )	Nr   r   py_unicode_predicater  )r  r  z__Pyx_Py_UNICODE_%sr  )rM   r(   r   r  r)   rE   r  r9   r   r!   r   upperr  #PyUnicode_uchar_predicate_func_typer   r  r   )r^   r*   r  r   r  ustringr/  r  r  r  	func_calls              r#   _inject_unicode_predicate.OptimizeBuiltinCalls._inject_unicode_predicate  s    D	QKq''9#?#?@@;;##33K(()55"O[1
 .0A0A0CC00CCUG'	 1 )	
 99  !44T5E5EFIr%   r  keependsc           	          [        U5      S;  a  U R                  SXS5        U$ U R                  XSS5        U R                  XSU R                  SXC5      $ )zVReplace unicode.splitlines(...) by a direct call to the
corresponding C-API function.
r  zunicode.splitlinesz1 or 2r   FPyUnicode_Splitlines
splitlines)rM   r  _inject_bint_default_argumentr  PyUnicode_Splitlines_func_typer]  s        r#   (_handle_simple_method_unicode_splitlines=OptimizeBuiltinCalls._handle_simple_method_unicode_splitlines  sa     t9E!''(<d(SK**4q%@++"D$G$G+3 	3r%   sepmaxsplitc           	      n   [        U5      S;  a  U R                  SXS5        U$ [        U5      S:  a0  UR                  [        R                  " UR
                  5      5        OU R                  US5        U R                  XS[        R                  S5        U R                  XSU R                  SXC5      $ )	zQReplace unicode.split(...) by a direct call to the
corresponding C-API function.
)r   r   r   zunicode.split1-3r   r   -1PyUnicode_Splitsplit)rM   r  rO   r   r  r   _inject_null_for_none_inject_int_default_argumentr	   r>  r  PyUnicode_Split_func_typer]  s        r#   #_handle_simple_method_unicode_split8OptimizeBuiltinCalls._handle_simple_method_unicode_split-  s     t9G#''UKKt9q=KK	**48845&&tQ/)):77	? ++t==&. 	.r%   seqc           	         [        U5      S:w  a  U R                  SXS5        U$ [        US   [        R                  5      (       a  US   nUR
                  n[        U5      nU(       a  [        R                  " UR                  US[        R                  S9nU HF  u  p[        R                  " U	R                  U	UR                  S9n[        R                  " XZU5        MH     XS'   U R                  XSU R                   S	XC5      $ )
zN
unicode.join() builds a list first => see if we can do this more efficiently
r   zunicode.join2r   r)  r  r  PyUnicode_Joinr  )rM   r  r(   r   r  r
  r|   r  r   r
   r"  r  r   r   r  r  PyUnicode_Join_func_type)r^   r*   r  r   r  r  r[  r}   inlined_genexprr  r   r  s               r#   "_handle_simple_method_unicode_join7OptimizeBuiltinCalls._handle_simple_method_unicode_joinF  s     t9>''CHKd1gy@@AA GM%**I5i@"+"J"JHHmv'.'8'8#: :J5$"+"C"C(,,-.55#7K
 44]U`a :J *Q++d;;%- 	-r%   	substringrg  end	directionc           
      6    U R                  XX4SS[        S5      $ )Nr  endswithr   _inject_tailmatchunicode_tailmatch_utility_coder]  s        r#   &_handle_simple_method_unicode_endswith;OptimizeBuiltinCalls._handle_simple_method_unicode_endswithp  s#    %%DUJ*B0 	0r%   c           
      6    U R                  XX4SS[        S5      $ )Nr  
startswithrJ   rZ  r]  s        r#   (_handle_simple_method_unicode_startswith=OptimizeBuiltinCalls._handle_simple_method_unicode_startswithu  s#    %%DUL*B0 	0r%   c	                    [        U5      S;  a  U R                  U SU 3XS5        U$ U R                  XS[        R                  S5        U R                  XS[        R                  S5        UR                  [        R                  R                  UR                  U5      5        US:X  a  S	n	OS
UR                  5        S3n	U R                  XXR                  XdUUS9n
U
R                  [        R                  U R!                  5       5      $ )zpReplace unicode.startswith(...) and unicode.endswith(...)
by a direct call to the corresponding C-API function.
r   r      r  2-4r   0r   PY_SSIZE_T_MAXr  __Pyx_PyUnicode_Tailmatch__Pyx_Py
_Tailmatchr  )rM   r  rI  r	   r>  rO   r   r   r   r   
capitalizer  PyString_Tailmatch_func_typer   r
   rq  r   )r^   r*   r  r   r  r  r  r  rW  r|  method_calls              r#   r[  &OptimizeBuiltinCalls._inject_tailmatchz  s   
 t9G#''9+Q{m(DdRWXK)):77	>)):779I	KI%%--dhh	BC3I"9#7#7#9":*EI2288D'	 3 )
 $$W%6%68H8H8JKKr%   re  c                 *    U R                  XX4SS5      $ )Nfindr   _inject_unicode_findr]  s        r#   "_handle_simple_method_unicode_find7OptimizeBuiltinCalls._handle_simple_method_unicode_find  s     ((DVRA 	Ar%   c                 *    U R                  XX4SS5      $ )NrfindrJ   rr  r]  s        r#   #_handle_simple_method_unicode_rfind8OptimizeBuiltinCalls._handle_simple_method_unicode_rfind  s     ((DWbB 	Br%   c           	         [        U5      S;  a  U R                  SU-  XS5        U$ U R                  XS[        R                  S5        U R                  XS[        R                  S5        UR                  [        R                  R                  UR                  U5      5        U R                  XSU R                  XTU5      nUR                  U R                  5       5      $ )	zgReplace unicode.find(...) and unicode.rfind(...) by a
direct call to the corresponding C-API function.
rd  z
unicode.%srf  r   rg  r   rh  PyUnicode_Find)rM   r  rI  r	   r>  rO   r   r   r   r   r  PyUnicode_Find_func_typer  r   )r^   r*   r  r   r  r  rW  rn  s           r#   rs  )OptimizeBuiltinCalls._inject_unicode_find  s    
 t9G#''{(BDPUVK)):77	>)):779I	KI%%--dhh	BC22,d.K.KD2 --d.>.>.@AAr%   c           	      N   [        U5      S;  a  U R                  SXS5        U$ U R                  XS[        R                  S5        U R                  XS[        R                  S5        U R                  XSU R                  S	XC5      nUR                  U R                  5       5      $ )
zQReplace unicode.count(...) by a direct call to the
corresponding C-API function.
rd  zunicode.countrf  r   rg  r   rh  PyUnicode_Countcount)	rM   r  rI  r	   r>  r  PyUnicode_Count_func_typer  r   )r^   r*   r  r   r  rn  s         r#   #_handle_simple_method_unicode_count8OptimizeBuiltinCalls._handle_simple_method_unicode_count  s     t9G#''UKK)):77	>)):779I	K 22-t/M/M&. --d.>.>.@AAr%   replstrmaxcountc           	          [        U5      S;  a  U R                  SXS5        U$ U R                  XS[        R                  S5        U R                  XSU R                  SXC5      $ )zSReplace unicode.replace(...) by a direct call to the
corresponding C-API function.
)r   re  zunicode.replacez3-4r   rE  PyUnicode_Replacer_  )rM   r  rI  r	   r>  r  PyUnicode_Replace_func_typer]  s        r#   %_handle_simple_method_unicode_replace:OptimizeBuiltinCalls._handle_simple_method_unicode_replace  sn     t9E!''(94uMK)):77	? ++/1Q1Q(0 	0r%   r-  errors)UTF8UTF16UTF-16LEUTF-16BELatin1ASCIIunicode_escaperaw_unicode_escapec                 .   [        U5      S:  d  [        U5      S:  a  U R                  SXS5        U$ US   nU R                  UR                  U5      nUc  U$ Uu  pxpUR	                  5       (       a^   UR
                  R                  Xy5      n[        X=(       d    S5      n[        R                  " UR                  U[        R                  S9$ [        U5      S:X  aA  [        R                  " UR                  5      nU R                  XSU R                  S	XEX/5      $ U(       aE  U	S
:X  a?  U R                  U5      nUb+  SU;  a%  SU-  nU R                  XUU R                   S	XE/5      $ U R                  XSU R                  S	UXXU
/5      $ !    N= f)zOReplace unicode.encode(...) by a direct C-API call to the
corresponding codec.
r   r   zunicode.encoderD  r   zUTF-8r  PyUnicode_AsEncodedStringr  strictr7  zPyUnicode_As%sString)rM   r  _unpack_encoding_and_error_moder   r  r=   r  r   r   r  r
   r   r  r  #PyUnicode_AsEncodedString_func_type_find_special_codec_namePyUnicode_AsXyzString_func_type)r^   r*   r  r   r  string_node
parametersr-  encoding_nodeerror_handlingerror_handling_noder   	null_node
codec_nameencode_functions                  r#   $_handle_simple_method_unicode_encode9OptimizeBuiltinCalls._handle_simple_method_unicode_encode  s    t9q=CIM''(8$eLK1g99$((DI
KGQD**,,b#33::8T
 &e-@A **;??%gN`N`aat9>!**4884I// ;88+9-PR R
 (266x@J%#Z*?"8:"E33O88/@ @
 ++744')<=	? 	?1s   5F Fstringr  ri  decode_funcc                 &   S[        U5      s=::  a  S::  d  O  U R                  SXS5        U$ US   nU R                  UR                  U5      nUc  U$ Uu  pxpUR	                  5       (       aD   UR
                  R                  Xy5      n[        UR                  [        U5      UR
                  S9$ S=p[        U[        R                  5      (       a>  UnUR                  nUR                   UR"                  pU(       a  UR
                  S:X  a  Sn[        U[        R$                  5      (       a  UR&                  nUR(                  nU[*        R,                  [*        R.                  4;   a7  U(       a  UR1                  SS	UR2                  /S
9nO7UR1                  SSS	/S9nO$UR4                  (       d  UR6                  (       d  U$ U(       d+  [        R8                  R;                  UR                  S5      nOIUR(                  R<                  (       d.  UR?                  [@        RB                  U RE                  5       5      nU(       aI  UR(                  R<                  (       d.  UR?                  [@        RB                  U RE                  5       5      nSnUb  U RG                  U5      nUbl  US;   a  SURI                  SS5      -  nOSU-  n[        RJ                  " UR                  U RL                  US9n[        RN                  " UR                  5      nO [        RN                  " UR                  5      n/ nUR4                  (       a|  U(       de  URP                  (       d'  [R        RT                  " U5      nURW                  U5        [        RX                  " UR                  SU RZ                  U/SS9nU R\                  nSnGOUR6                  (       GaT  U(       d.  [        R8                  " UR                  S[        R^                  S9nU R`                  c  [@        Rb                  " [*        Rd                  [@        Rf                  " SUS5      [@        Rf                  " S[@        RB                  S5      [@        Rf                  " S[@        RB                  S5      [@        Rf                  " S[@        Rh                  S5      [@        Rf                  " S[@        Rh                  S5      [@        Rf                  " SU RL                  S5      /5      U l0        U R`                  nS UR2                   3nOYU(       d.  [        R8                  " UR                  S[        R^                  S9nU Rj                  nU[*        R,                  L a  S!nOS"n[        RX                  " UR                  S#U-  UX\XU
U/URl                  [n        Rp                  " US$5      S%9nUSSS&2    H  n[R        Rr                  " UU5      nM     U$ ! [        [        [        4 a     GN]f = f)'zsReplace char*.decode() by a direct C-API call to the
corresponding codec, possibly resolving a slice on the char*.
r   r   zbytes.decoderD  r   Nr   r  @descriptor '%s' requires a '%s' object but received a 'NoneType'decoder  r  r  r  )r  r  r  z__Pyx_PyUnicode_Decode%sr7  r  zPyUnicode_Decode%s)rE   rA  r  Tre  decode_c_stringrh  r+  r  rg  ri  r-  r  r  decode_cpp_decode_bytesdecode_bytearrayz__Pyx_%sr  r  rJ   ):rM   r  r  r   r  r=   r  r   r   rB  
ValueErrorUnicodeDecodeErrorr(   r   rm  r   rg  ri  r  r)   rE   r
   r   r  r#  r"   r  is_cpp_stringr   r?  r  r   r	   r>  r   r  r_  r  !PyUnicode_DecodeXyz_func_ptr_typer  r   r   r;  rO   rj  r  _decode_c_string_func_typer   _decode_cpp_string_func_typer  r   r  r  _decode_bytes_func_typer)  r   r!   r  )r^   r*   r  r   r  r  r  r-  r  r  r  r=   rg  ri  r  string_typer  codec_cnamedecode_functionr   helper_func_typer  r  s                          r#   "_handle_simple_method_bytes_decode7OptimizeBuiltinCalls._handle_simple_method_bytes_decodeI  s    SY#!#''EJK 1g99$((DI
KGQD**,,	"-"="="D"DX"^ #OO'8 + ; ;  k9#;#;<<$J$//K$**JOO4E11Q6k9#?#?@@%//K!&&7--w/E/EFF );;V!);+;+; < < > *;;@0!)
 < , &&{/H/HK%%..txx;E""OOJ$@$@$BRBRBTUE		((>>*">">@P@P@RSD 
66x@J!>>8:;M;McSU;VV2Z?'88tEE[ZO%..txx8M'00:O   "**"+"6"6{"CKLL- 33OO%94;Z;Z% 
  $>> 1&&& ((9I9B9Q9QS0084>4H4H(("//+tL"//9U9UW[\"//
8T8TVZ["//
J<\<\^bc"//*:Z:Z\`a"//t?e?egkl+51  $@@"-k.>.>-? @  ((9I9B9Q9QS#;;g000$2!$6!++HHj#446Fd;NP_`LL$001BOT	
 $B$KD11$=D  _ #J0BC s   /W7 7XXc                 "    [         R                  " U5      nU R                   HS  u  p4XB:X  d  M  SU;   a?  SR	                  UR                  S5       Vs/ s H  nUR                  5       PM     sn5      nUs  $    g ! [         a     g f = fs  snf )NrT  r  )r   
getencoderLookupError_special_codecsr  rG  rl  )r^   r-  requested_codecr"   codecr_  s         r#   r  -OptimizeBuiltinCalls._find_special_codec_name  s    	$//9O  //KD'$;77-1ZZ_$>-< %&LLN-<$> ?D 0   		
$>s   A< B
<
B	B	c                     [         R                  " U5      n[        U5      S:  a  U R                  US   5      u  pEUc  g OS nUn[        U5      S:X  a#  U R                  US   5      u  pgUc  g US:X  a  UnOSnUnXEXg4$ )Nr   r   r   r  )r   r  rM   _unpack_string_and_cstring_node)r^   r   r   r  r-  r  r  r  s           r#   r  4OptimizeBuiltinCalls._unpack_encoding_and_error_mode  s    &&s+	t9>&*&J&J4PQ7&S#H$ % H%Mt9>262V2VW[\]W^2_/N"*)&/#%N"+MMr%   c                    [        U[        R                  5      (       a  UR                  n[        U[        R                  5      (       aK  UR
                  n[        R                  " UR                  UR                  5       [        R                  S9nX!4$ [        U[        R                  5      (       aV  UR
                  R                  S5      n[        R                  " UR                  UR
                  [        R                  S9nX!4$ UR                  [        R                  L a3  S nUR                  [        R                  U R!                  5       5      nX!4$ UR                  R"                  (       a  S nX!4$ S =p!X!4$ )Nr  z
ISO-8859-1)r(   r   r  r)   r   r   r  r   as_utf8_stringr	   r  r  rE   r
   r   r   r   r  )r^   r*   r-  s      r#   r  4OptimizeBuiltinCalls._unpack_string_and_cstring_node  s:   dI889988DdI1122zzH&& 7 7 9
@`@`bD ~ i1122zz((6H&&

1Q1QSD ~ YY',,,H>>*"B"BDDTDTDVWD
 ~	 YY  H ~ #"H~r%   c           
      6    U R                  XX4SS[        S5      $ )Nr  rY  r   r[  bytes_tailmatch_utility_coder]  s        r#   $_handle_simple_method_bytes_endswith9OptimizeBuiltinCalls._handle_simple_method_bytes_endswith  s#    %%DWj(". 	.r%   c           
      6    U R                  XX4SS[        S5      $ )Nr  r`  rJ   r  r]  s        r#   &_handle_simple_method_bytes_startswith;OptimizeBuiltinCalls._handle_simple_method_bytes_startswith  s#    %%DWl(". 	.r%   rj   c                     [        U5      nU(       a   U(       a  U R                  US   X&U5      US'   U	c  UR                  n	[        R                  " UR
                  X4UU	UU
UR                  S9$ )Nr   )r   r)  r  rD  r  )r)  rj  r)  r   rj  r   r  )r^   r*   r  r"   r  r  r  r   r  r)  rD  r&  s               r#   r  ,OptimizeBuiltinCalls._substitute_method_call  sn    
 Dzt))$q'8PYZDG?llG++HHd'-!00 	r%   c                     UR                   (       a  U$ U(       a'  UR                  SXAR                  R                  /S9nU$ UR                  SR	                  [        U5      S::  a  SOS5      SU/S9nU$ )	Nr  r  r  r  r  r  r  r  )r  r#  rE   r"   r  rM   )r^   self_argr  r  r  s        r#   rj  #OptimizeBuiltinCalls._wrap_self_arg1  s    O11R&(:(:; 2 =H 	  11;BBCPYN^`L`5fhi,&K 2 )H r%   c           	      R   [        U5      U::  a  g X   nUR                  5       (       d  g UR                  (       a   [        R                  " UR
                  5      OI[        R                  " UR
                  SU R                  UR                  U R                  5       5      /SS9X'   g )N__Pyx_NoneAsNullr   re  )
rM   r  rD   r   r  r   rj  obj_to_obj_func_typer  r   )r^   r   r2  r)   s       r#   rH  *OptimizeBuiltinCalls._inject_null_for_noneD  s    t9k  58[[i((1iFbFbGG'%%&&t'7'7'9:;	G
r%   c                 t   [        U5      U:  d   e[        U5      U:X  d  X#   R                  (       a  [        U[        5      (       d-  [	        U5      R                  S5      R                  5       (       a4  [        R                  R                  UR                  [        U5      5      nO)[        R                  " UR                  [	        U5      US9nUR                  U5        g X#   R                  X@R                  5       5      n[        U[        R                  5      (       a  [	        U5      Ul        XrU'   g )Nz+-r  )rM   rD   r(   r  r  lstrip	isdecimalr   r   r   r   rO   r   r   r}  special_none_cvalue)r^   r*   r   	arg_indexrE   default_valueint_noder)   s           r#   rI  1OptimizeBuiltinCalls._inject_int_default_argumentS  s     4yI%%%t9	!T_%<%<---]1C1J1J41P1Z1Z1\1\$,,44TXXs=?QR$,,TXXS=OVZ[KK!/++D2B2B2DEC#y==>>*-m*<'!Or%   c                     [        U5      U:  d   e[        U5      U:X  a8  UR                  [        R                  " UR                  [        U5      S95        g X#   R                  U R                  5       5      X#'   g Nr   )rM   rO   r   r   r   r  rr  r   )r^   r*   r   r  r  s        r#   r=  2OptimizeBuiltinCalls._inject_bint_default_argumentd  s_    4yI%%%t9	!KK	**4884;NOP"o??@P@P@RSDOr%   )r  r'   r
  )rt   ru   rv   rw   rx   rf  ri  rg   rt  r	   r  r  r  r~  r  r  c_float_typer  c_longdouble_typer  r  r  r   r  r  r  r  r  r  r  r
   r   r  r  _handle_simple_function_strr  r   r  rK  r"  r  r=  r!  r  r  r   r  r@  r   r  r9  r  r  r  r  r  r  r  memoryview_typer   r  r  r  r>  r  r  c_const_py_unicode_ptr_typer  r  r   r  rP  r  r  r  rN   r#  r$  r  r4  r;  r  rM  rL  rU  rX  rk  r\  r^  ro  rx  r{  r}  r  r  r  r  r  r  r  r  r  r  r  rb  r  r  r  r   r(  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  !_handle_simple_method_int___add__!_handle_simple_method_int___sub__!_handle_simple_method_int___mul__ _handle_simple_method_int___eq__ _handle_simple_method_int___ne__!_handle_simple_method_int___and__ _handle_simple_method_int___or__!_handle_simple_method_int___xor__$_handle_simple_method_int___rshift__$_handle_simple_method_int___lshift__!_handle_simple_method_int___mod__&_handle_simple_method_int___floordiv__%_handle_simple_method_int___truediv__r  r  r  r  r  r  r  r   r  r4  r7  %_handle_simple_method_unicode_isalnum%_handle_simple_method_unicode_isalpha'_handle_simple_method_unicode_isdecimal%_handle_simple_method_unicode_isdigit%_handle_simple_method_unicode_islower'_handle_simple_method_unicode_isnumeric%_handle_simple_method_unicode_isspace%_handle_simple_method_unicode_istitle%_handle_simple_method_unicode_isupper)_handle_simple_method_unicode_isprintable$PyUnicode_uchar_conversion_func_typer>  r?  rJ  rK  rQ  rS  rm  r]  ra  r[  r|  rt  rx  rs  r  r  r  r  r  r  _special_encodingsr   r  r  r  rK  r  r  r  r  r  &_handle_simple_method_bytearray_decoder  r  r  r  r  r   rj  rD  r  rj  r  rH  rI  r=  rz   )r   r  r	   ctyper*  r"   r   s   0000000r#   rc  rc  x  sI    	 
  *33!!##C)B)BDI$ 
. N &22J4L4LjNjNjk
 lJ	 	J((''z4@ 	 l3j &//##E:+D+DdK 
 	 )22  ##E:+D+DdK#
 	
3>$(BX5  ",!5!5##E:+D+DdK"
. #B
 '00##FG,=,=tD
 !+ 4 4		 	 z'@'@$	GH!J
"  *33##FG,=,=tD 
U$ %..##D**C*CTJ

 < !+ 4 4##D**C*CTJ!
!
!  #-"6"6  ##E:+D+DdK# )# 4l (11##C)B)BDI
 #-"6"6##GZ-E-EtL#
,B  )3(<(<##GZ-F-FM")%
 )3(<(<##GW-C-CTJ")%
4 ",!5!5$$##GZ-M-MtT'
 	" '1&:&:$$##Iz/U/UW[\'
 	'# )22$$##E:+D+DdK'
 	 	!=!9!=!8!9!7!7	! 
c  442h $--##Hj.G.GN
	C )22##E:+D+DdK!
Rh$ &//!!##Fj.G.GN##Fg.@.@$G$ #-"6"6!!##Fj.G.GN##Fg.@.@$G##Hg.?.?F$
# ;?GT ;? !+ 4 4$$##FJ,E,EtL##FJ,E,EtL' !
 =~ $.#7#7$$##K1J1JDQ##GZ-B-BDI' $  *4)=)=$$##K1J1JDQ##GZ-F-FM' *&B (11!!##FJ,E,EtL$
 #-"6"6!!##FJ,E,EtL##J
0I0I4P##Iz/K/KTR##K1F1FM	$
 #C@D (11$$##E:+D+DdK' 	T $.#7#7!!##FJ,E,EtL##E:+D+DdK##Iz/H/H$O$$ C  '1&:&:!!##FJ,E,EtL##E:+D+DdK##Iz/H/H$O##NJ4I4I4P	$'#S  &//!!##FJ,E,EtL##E:+D+DdK##Iz/H/H$O$ #-"6"6##FJ,E,EtL##E:+D+DdK##Iz/H/H$O 
 '11AA#<F !,,j.F.FG
 HE#22J4J4JKH 
://''z/H/H$O''z/H/H$O''t<''	:3I3I4P''9O9OQUV (0';';tAYAY[ 	[ L 	 H
X]]WWXWX[[\^]Y )M%(L%(L%'J$'J$(L%'J$(L%+R(+R((L%-V*,T)[X]_[^WW#N +5*>*>##GZ-F-FM!+'
0 /H).G).G+.G).G).G+.G).G).G)0I-+5+?+?!!##GZ-F-FM$,(0 &0%9%9##E7+?+?F##J
0F0FM&"3 !+ 4 4##E7+?+?F##E:+D+DdK##J
0L0LdS!
.&  *33##E7+?+?F##E:+D+DdK -@ $.#7#7##E:+D+DdK##K1J1JDQ##GZ-I-I4P##E:+G+GN##K1F1FM! $ 0
0
L4  *33$$##E7+?+?F##K1J1JDQ##GZ-I-I4P##E:+G+GN##K1F1FM'  ABB& !+ 4 4$$##E7+?+?F##K1J1JDQ##GZ-I-I4P##E:+G+GN	' !B" #-"6"6##E7+?+?F##K1J1JDQ##Iz/H/H$O##J
0L0LdS	#0 +5*>*>##E7+?+?F##J
0P0PRVW##Hj.N.NPTU+' '1&:&:##E7+?+?F'#
B %79$6D v0067$69O/?b )3(;(;J<P<P##Hj.N.NPTU##FJ,H,H$O##Hj.N.NPTU
= )% ",!5!5##Hj.N.NPTU##GZ-I-I4P##FJ,H,H$O##J
0P0PRVW##Hj.N.NPTU##M3TVZ[
" )22##Hj.G.GN##GZ-I-I4P##FJ,H,H$O##J
0P0PRVW##Hj.N.NPTU##M3TVZ[
 $( AF .P*N.(.
.

 DF-14090L0L0\0\04	& &//!!##E:+D+DdK$


""Tm;N"
F9s   <9AN?DAO
D$AOrc  c           
         [         R                  [         R                  4n[        XE5      (       a@  UR                  [
        R                  La  UR                  [        R                  La  gUnSnOQ[        X55      (       a@  UR                  [
        R                  La  UR                  [        R                  La  gUnSnOgUR                  5       (       d  g[        U[         R                  5      nU(       a  [
        R                  O[
        R                  n	U(       a  U S;  a  gO!U S:X  a  g[        UR                  5      S:  a  gU S;   a  UR                  S:X  a  g/ n
U
R                  U(       a  [         R                  O[         R                  " UR                  UR                   UR                  U	S	95        [        U[         R"                  5      (       a  UR$                  OS
nU
R                  [         R&                  " UR                  US95        U(       d  U S;  al  US:H  =(       a2    [        U[         R(                  5      (       a  UR*                  (       + OS
nU
R                  [         R&                  " UR                  US95        [,        R.                  " U(       a  SO	U S;   a  SOSS[1        XUS9S9nSU(       a  SOS< SUR2                  (       a  SOS< U < U< 3nXX4$ )r#  NObjCCObj)r  r  r  r  r  r  r  r  r   )r  r  r  r  r   rw  Fr   r%  PyFloatBinopPyLongComparePyLongBinopr    )oporderr*  r2  rj  FloatLongrT  r  Bool)r   r   r  r(   rE   r	   r  r
   r  r  r  r  r  r=   rO   r   r   NumBinopNoder9  r   r  	cdivisionr   r!   r   r   )r   r*   r*  arg0arg1	num_nodesnumval	arg_orderr  r-  r,  r9  zerodivision_checkr  r+  s                  r#   r'  r'  l  sa    ""I$7$78I$""99J555$))7K[K[:[		D	$	$99J555$))7K[K[:[	%%'' &)"5"56H+3z''9O9OH__ `	X		V##	$u	,GG1$Jhy**I<M<MM

&,,8N8N  )y/E/EFFdllEGi((AB8</&&0 R",T93D3D"E"E5 	),,TXX=OPQ%11"8|;SYfHEGL '"".	J Z99r%   unicode_tailmatchr  bytes_tailmatchc                     ^  \ rS rSrSrS*U 4S jjrS r\R                  \R                  \R                  \R                  /rS rS rS rS rS	S
SSS.R"                  rS rS rS rS rS rS rS rS rS rS rSrS rS rS r S r!S r"S r#S r$S  r%S! r&S" r'S# r(S$ r)S% r*S& r+S' r,S( r-\.R^                  R`                  r1S)r2U =r3$ )+ConstantFoldingi  a  Calculate the result of constant expressions to store it in
``expr_node.constant_result``, and replace trivial cases by their
constant result.

General rules:

- We calculate float constants to make them available to the
  compiler, but we do not aggregate them into a single literal
  node to prevent any loss of precision.

- We recursively calculate constants from non-literal nodes to
  make them available to the compiler, but we only aggregate
  literal nodes at each step.  Non-literal nodes are never merged
  into a single node.
c                 .   > [         TU ]  5         Xl        g)zo
The reevaluate argument specifies whether constant values that were
previously computed should be recomputed.
N)superr[   
reevaluate)r^   r  	__class__s     r#   r[   ConstantFolding.__init__  s    
 	$r%   c                 0   U R                   (       d  UR                  [        R                  La  g [        R                  nX!l        U R                  U5      nUR                  5        HE  n[        U5      [        L a  U H  n[        USU5      UL d  M      g    M3  [        USU5      UL d  ME    g     UR                  5         g ! [        [        [        [        [        [         4 a     g ["         a$    SS KnSS KnUR)                  UR*                  S9   g f = f)Nr=   r   )file)r  r=   r   constant_value_not_setr   ra   r   rE   r)  r  calculate_constant_resultr  	TypeErrorr   
IndexErrorrB  ArithmeticError	Exception	tracebacksys	print_excstdout)r^   r*   r   childrenchild_resultchildr*  r+  s           r#   _calculate_const ConstantFolding._calculate_const  s    $$I,L,LL #11- %%d+$OO-LL!T))Eu&7HNZ * '8.I^[ .
	1**, Ix^_] 	 	1!SZZ0	1s   1C $D(*DDc           
           U R                   [        [        U R                   R                  [        [        U5      5      5         $ ! [
         a     g f = fr'   )NODE_TYPE_ORDERmaxr   r2  rE   r  )r^   nodess     r#   _widest_node_class"ConstantFolding._widest_node_class  sP    	''C,,22Ce4DEFH H 		s   AA 
AAc                 R    [         R                  " UR                  [        U5      S9$ r  )r   r   r   r  )r^   r*   r   s      r#   
_bool_nodeConstantFolding._bool_node  s    !!$(($u+>>r%   c                 (    U R                  U5        U$ r'   )r1  rb   s     r#   visit_ExprNodeConstantFolding.visit_ExprNode  s    d#r%   c                 x   U R                  U5        UR                  5       (       d#  UR                  S:X  a  U R                  U5      $ U$ UR                  R
                  (       d  U$ UR                  S:X  a  U R                  XR                  5      $ [        UR                  [        R                  5      (       a=  [        R                  R                  UR                  [        UR                  5      5      $ UR                  S:X  a  U R                  U5      $ UR                  S:X  a  U R!                  U5      $ U$ )N!r8  r7  )r1  r  r   _handle_NotNoder   r  r:  r=   r(   r   r   r   r   r   r  _handle_UnaryPlusNode_handle_UnaryMinusNoderb   s     r#   visit_UnopNodeConstantFolding.visit_UnopNode  s    d#''))}}#++D11K||&&K==C??4)=)=>>i&8&899$$,,TXXs4;O;O7PQQ]]c!--d33]]c!..t44r%   r   rz  is_notr'  )rz  r   r'  rF  c                     UR                   n[        U[        R                  5      (       aO  U R	                  UR
                  5      nU(       a-  [        R                  " U5      nX1l        U R                  U5      nU$ r'   )r   r(   r   r   _negate_operatorr   r   r   )r^   r*   r   r   s       r#   rA  ConstantFolding._handle_NotNode  s_    ,,gy7788,,W-=-=>Hyy) (006r%   c                    S nUR                   R                  n[        UR                   [        R                  5      (       aE  [        R                  " UR
                  U" UR                   R                  5      UUR                  S9$ UR                  (       a  UR                  (       d:  [        UR                   [        R                  5      (       ak  UR                  (       aZ  [        R                  " UR
                  U" UR                   R                  5      UUR                   R                  UR                  S9$ U$ )Nc                 J    U R                  S5      (       a  U SS  n U $ SU -   n U $ )Nr7  r   )r`  r   s    r#   _negate7ConstantFolding._handle_UnaryMinusNode.<locals>._negate#  s5    $$ab	 L eLr%   )r   rE   r=   )r   rE   longnessr=   )r   rE   r(   r   r  r   r   r=   r  r  r   r   rN  )r^   r*   rL  	node_types       r#   rC  &ConstantFolding._handle_UnaryMinusNode"  s    	 LL%%	dllI$7$788&&txxwt||?Q?Q7R,57;7K7KM M 	 0 04<<):):;;	@U@U$$TXXWT\\=O=O5P*3.2ll.C.C595I5IK K r%   c                     UR                   R                  5       (       a0  UR                  UR                   R                  :X  a  UR                   $ U$ r'   )r   r  r=   rb   s     r#   rB  %ConstantFolding._handle_UnaryPlusNode8  s<    LL,,..((DLL,H,HH<<r%   c                 <   U R                  U5        UR                  R                  5       (       d  U$ UR                  R                  (       a(  UR                  S:X  a  UR
                  $ UR                  $ UR                  S:X  a  UR                  $ UR
                  $ )Nr1  )r1  rB   r  r=   r   rC   rb   s     r#   rc  #ConstantFolding.visit_BoolBinopNode>  su    d#}}0022K==((}}%}}$}}$}}%}}$}}$r%   c                 l   U R                  U5        UR                  [        R                  L a  U$ [	        UR                  [
        5      (       a  U$ UR                  UR                  p2UR                  (       a  UR                  (       d  U$  UR                  UR                  pTUb  Uc  U$  UR                  (       a(  UR                  (       a  [        R                  " XE5      nO[        R                  nU R                  X#5      nUc  U$ U[        R                   L a!  UR"                  S;   a  [        R$                  nO3U[        R&                  L a   UR"                  S;   a  [        R$                  nU[        R$                  L Ga+  [)        USS5      =(       a    [)        USS5      nSS [+        [-        [)        USS5      5      [-        [)        USS5      5      5       n	[/        [1        UR                  5      5      n
[2        R4                  " U
5      n
[        R$                  " UR6                  XU
[1        UR                  5      S9nUR8                  (       d  UR                  R8                  (       a  [        R                  Ul	        U$ [        R                  " XkR                  5      Ul	         U$ U[        R                   L a,  [        R                   " UR6                  UR                  US9nU$ U" UR6                  U[;        UR                  5      UR                  S	9nU$ ! [         a    Us $ f = f)
Nz+-//<<%**>>z+-//<<%**>>&|^unsignedr  LLrN  )r   rV  rN  r   r=   r  )r   rE   r   r=   )r1  r=   r   r   r(   r  rB   rC   r  rE   rB  r  r	   widest_numeric_typer  r7  r   r   r   r.  r  r5  rM   hexr  r   strip_py2_long_suffixr   r   r  )r^   r*   rB   rC   type1type2widest_typetarget_classrV  rN  r   r   s               r#   visit_BinopNodeConstantFolding.visit_BinopNodeM  s   d#9#;#;;Kd**E22K!]]DMM(""(*=*=K	#==(--5} !.
  0 0$88FK$33K..xBKY///DMM]4R$,,LY///DMMEU4U$,,L9,,,xR8 9xR8  ISWXz2%F!G!$WXz2%F!GI JHD0012E//6E ((TXX2:/49<T=Q=Q9RTH &&(--*C*C * 9 9  !+ > >{MM Z  Y/// ))$(($:N:NU`aH
  ${*-d.B.B*C484H4HJH S  	K	s   L$ $L32L3c                 V	   U R                  U5        [        UR                  [        5      (       a<  [        R
                  " UR                  R                  [        UR                  5      S9$ UR                  UR                  p2[        U[        R                  5      (       Ga&  [        U[        R                  5      (       aK  UR                  R                  UR                  5        [        R                  Ul        U R                  U5      $ [        UR                  [        5      (       a  UR                  (       d  U$ [        U[        R
                  5      (       d)  [        R
                  " UR                  UR                  S9nUR                  R                  U5        [        R                  Ul        U R                  U5      $ O[        U[        R                  5      (       a  [        UR                  [        5      (       a  UR                  (       d  U$ [        U[        R
                  5      (       d)  [        R
                  " UR                  UR                  S9nUR                  R!                  SU5        [        R                  Ul        U R                  U5      $ UR                  [        R"                  L a  U$ UR$                  (       Ga  UR$                  (       Ga  [        U[        R
                  5      (       a  [        U[        R
                  5      (       a  S nUR&                  br  UR&                  be  UR&                  R(                  UR&                  R(                  :X  a7  [+        UR&                  UR&                  -   UR&                  R(                  5      n[        UR                  5      n[        R
                  " UR                  XTS9$ [        U[        R,                  5      (       a  [        U[        R,                  5      (       a  UR.                  R(                  UR.                  R(                  :X  aS  [+        UR                  UR.                  R(                  5      n[        R,                  " UR                  XAR                  S9$ U R1                  U5      $ )Nr   r   r  r+  )r1  r(   r=   r  r   r   rB   r   r   rC   JoinedStrNoder   rb  r$  simplify_JoinedStrNoderO   insertr   r   r  r-  r   r  r   r_  )r^   r*   rB   rC   r  string_values         r#   visit_AddNodeConstantFolding.visit_AddNode  sZ   d#d**C00((!!t7K7K)LN N "]]DMM( h	 7 788(I$;$;<<&&x7+4+K+K(228<<(22C88//#O!(I,A,ABB(44 H,D,D FH&&x0+4+K+K(228<< 9 )"9"9::(22C88//#O!(I,A,ABB(44 H,D,D FH&&q(3+4+K+K(228<<9#;#;;K%%%(*D*D*D(I$9$9::z(T]TiTi?j?j"''38L8L8X++448L8L8U8UU&3$0083G3GG$0099';  -T-A-AB ,,X\\ggHi&9&9::z(T]TgTg?h?h>>**hnn.E.EE"/0D0DhnnF]F]"^K$..x||;`t`tuu##D))r%   c                    U R                  U5        UR                  R                  (       a&  U R                  XR                  UR                  5      $ [        UR                  [        R                  5      (       aA  UR                  R                  (       a&  U R                  XR                  UR                  5      $ UR                  R                  (       a&  U R                  XR                  UR                  5      $ UR                  R                  (       a&  U R                  XR                  UR                  5      $ U R                  U5      $ r'   )r1  rB   r   _calculate_constant_seqrC   r(   r   r   r   _multiply_stringr_  rb   s     r#   visit_MulNodeConstantFolding.visit_MulNode  s    d#==00//mmT]]SSdmmY%6%67755//mmT]]SS==**((}}dmmLL]],,((}}dmmLL##D))r%   c                    UR                   n[        U[        5      (       d  U$ UR                  5       (       a  [        UR                   [        5      (       d  U$ [        UR                   5      S:  a  U$ [        U[        R                  5      (       a  [        nOx[        U[        R                  5      (       aF  [        nUR                  b2  [        UR                  U-  UR                  R                  5      Ul        O S[        U5      -  5       eU" UR                  U-  UR                  R                  5      Ul        UR                  Ul         U$ )N   zunknown string node type: %s)r=   r(   r  r  _py_string_typesrM   r   r  r   r   r   r  r-  rE   r   )r^   r*   r  multiplier_node
multiplierbuild_strings         r#   rj   ConstantFolding._multiply_string  s   $44
*c**K((**z$:N:NP`/a/aKt##$s*Kk9#6#677(LY%:%:;;)L&&2*7++j8++44+6' M84;LLL5(
*&&( '2&7&7#r%   c                 n   UR                   S:w  Ga#  UR                  (       Ga  [        UR                   [        5      (       a(  UR                   S::  a  UR                  S S 2	 S Ul        U$ UR                  b  [        UR                   [        5      (       a  [        UR                  R                   [        5      (       a^  UR                  R                   UR                   -  n[
        R                  R                  UR                  R                  U5      Ul        U$ U R                  U5      $ X2l        U$ rT  )
r=   r   r(   r  ri  r   r   r?  r   r_  )r^   r*   sequence_nodefactorr   s        r#   ri  'ConstantFolding._calculate_constant_seq  s    !!Q&=+=+=+=&00#666;Q;QUV;V!&&q),0)  **6v55s;;"=#<#<#L#LcRR)55EEH^H^^E090A0A0J0J=KdKdKhKhjo0pM-   //55,2)r%   c                    U R                  U5        [        UR                  [        R                  5      (       a  [        UR
                  [        R                  5      (       ao  UR
                  R                  (       dT  U R                  UR                  R                  UR                  R                  UR
                  R                  5      nUb  U$ U R                  U5      $ r'   )ra   r(   rB   r   r   rC   r  ri  _build_fstringr   r   r   r_  )r^   r*   fstrings      r#   visit_ModNodeConstantFolding.visit_ModNode  s    4 dmmY%:%:;;
4==ZcZmZm@n@n==,,--dmm.?.?ATATVZVcVcVhVhi&"N##D))r%   z'(%(?:(?:[-0-9]+|[ ])?(?:[.][0-9]+)?)?.)c                 \   [        U5      n/ nSn[        R                  " U R                  U5       GH  nU(       d  M  US:X  a/  UR	                  [
        R                  " U[        S5      S95        MB  US   S:w  aL  US   S:X  a  [        USUSS   S	3S
S9  SnUR	                  [
        R                  " U[        U5      S95        M  US   n [        U5      n	U	R                  (       a  Sn  OUS;   a  US
S  n
S nUS;   a	  SU
;   a  SnO4US;   a&  U
S S n
UnU
R                  S5      (       a  SU
S
S  -   n
OUS:X  a  SnU
R                  S5      (       a  SU
S
S  -   n
UR	                  [
        R                  " U	R                  U	UU
(       a  [
        R                  " U[        U
5      S9OS S95        GM  Sn  O   U(       d  g  [        U5        [        USS
S9  g ! [         a    [        USS
S9  Sn   M;  f = f! [         a     Of = f[
        R                  " XS9nU R!                  U5      $ )NTz%%%r   r   rJ   zIncomplete format: '...'r   )levelFz)Too few arguments for format placeholdersasrfdoxXdoxXr  arsrg  r,  dr7  r0  )r   r  r  z*Too many arguments for format placeholders)r   )iterr   rG  _parse_string_format_regexrO   r   r   r   r   nextStopIterationr   r`  FormattedValueNoder   rb  visit_JoinedStrNode)r^   r   r5  r  r   
substringscan_be_optimisedr_  format_typer)   r  r  r*   s                r#   ry  ConstantFolding._build_fstring  sQ   K 
$997CADy!!)"7"7=QTCU"VWts{R5C<C#:1RS6(!!DAN',$!!)"7"7=QRCS"TUB%K4j
 ~~#( j(e"&&(SK-?',$ E)"-cr"2K&1O"--c22&)KO&; C'&)O))#.."%AB"7K!!)">">GG3$3& !* 5 5c{A[ \,0	#  $) c Df  	J CEQO[ ! HPQR#( T "d"
 &&s>''--s$   GG9 G65G69
HHc                    U R                  U5        UR                  =(       d    SnUR                  b=  UR                  R                  (       a"  UR                  R                  (       d  S Ul        UR                  c  UR                  R                  5       (       az  [        UR                  R                  [        5      (       aQ  [        [        UR                  R                  5      5      n[        R                  " UR                  R                  US9$ UR                  c-  US:X  a'  UR                  R                  (       a  UR                  $ U$ )Nr_  r   )ra   r  r  r   r   r  r(   r=   r  r   r  r   r   r   )r^   r*   r  r   s       r#   r  (ConstantFolding.visit_FormattedValueNodeM  s    4 ..5#'D,<,<,N,NW[WgWgWmWm#D#

(F(F(H(HZX\XbXbXrXrtwMxMx!#djj&@&@"ABE((uEE#3(>zz++zz!r%   c                 F    U R                  U5        U R                  U5      $ r'   )ra   rc  rb   s     r#   r  #ConstantFolding.visit_JoinedStrNodeZ  s!    4 **400r%   c                    / n[         R                  " UR                  [        S5      S9 H  u  p4U(       a  [	        U5      nUS   n[        U5      S:  a@  [        SR                  S U 5       5      5      n[        R                  " UR                  US9nUR                  (       a  UR                  U5        M  M  UR                  U5        M     U(       d*  [        R                  " UR                  [        S5      S9nU$ [        U5      S:X  a  US   nU$ [        U5      S:X  a$  [        R                  " UR                  S	/UQ76 nU$ X!l        U$ )
z
Clean up after the parser by discarding empty Unicode strings and merging
substring sequences.  Empty or single-value join lists are not uncommon
because f-string format specs are always parsed into JoinedStrNodes.
r   )r  r   r   r  c              3   8   #    U  H  oR                   v   M     g 7fr'   r   )r   r   s     r#   r   9ConstantFolding.simplify_JoinedStrNode.<locals>.<genexpr>j  s     1V:%++:r   r   r   r8  )r   groupbyr   r   r)  rM   r   r  r   r   r   r   rO   rb  rG  )r^   r*   r   is_unode_groupr  unoder   s          r#   rc  &ConstantFolding.simplify_JoinedStrNode^  s&    *3*;*;DKKZXkMl*m&N!*-
"1z?Q&)"''1V:1V*VWE%11%))5IE;;MM%(  j) +n ((r9JKD  [A!9D  [A''#??D  !Kr%   c                 x  ^^^ U R                  U5        / m/ mUUU4S jmUR                   H  nT" X5        M     T(       a  TR                  T5        [        T5      S:X  a7  TS   nUR                  (       d  [        U[        R                  5      (       a  U$ TUR                  SS& U R                  U5        U$ )z!Unpack **args in place if we can.c                   > UR                   (       a_  T(       aF  TS   R                  UR                  :X  a)  TS   R                  R                  UR                  5        g TR	                  U5        g [        U[        R                  5      (       a6  U R                  UR                  :X  a  UR                   H  nT" X5        M     g T(       a  TR                  T5        TS S 2	 TR	                  U5        g )NrJ   )	is_dict_literalreject_duplicatesrF  rb  rO   r(   r   MergedDictNoder  )parentr)   	child_argr>  r   r   s      r#   r>  1ConstantFolding.visit_MergedDictNode.<locals>.add  s    ""U2Y88C<Q<QQ"I--44S5H5HILL%C!9!9::v?W?W[^[p[p?p!$!1!1I' "2 KK&aC r%   r   r   N)	ra   r  rb  rM   r  r(   r   r  r1  )r^   r*   r)   r>  r   r   s      @@@r#   visit_MergedDictNode$ConstantFolding.visit_MergedDictNode}  s    4 	! $$CN %KKt9>q'C""ji6N6N&O&O
#!d#r%   c                   ^^^^ U R                  U5        UR                  [        R                  L m/ m/ mUUUU4S jmUR                   H  nT" U5        M     T(       a  TR                  TS   5        [        T5      S:X  ah  TS   nT(       a  UR                  (       dI  UR                  (       a  UR                  UR                  L d  [        U[        R                  5      (       a  U$ TUR                  SS& U R                  U5        U$ ) Unpack *args in place if we can.c                   > T(       a  U R                   (       d"  U R                  (       aS  U R                  (       dB  T(       a)  TS   R                  R	                  U R                  5        g TR                  U 5        g [        U [        R                  5      (       a  U R                   H  nT" U5        M     g T(       a  TR                  TS   5        TS S 2	 TR                  U 5        g )Nr   )	is_set_literalr   ri  r   rb  rO   r(   r   MergedSequenceNode)r)   r  r>  r   r  r   s     r#   r>  5ConstantFolding.visit_MergedSequenceNode.<locals>.add  s    3--33N3NWZWfWf1INN))#((3MM#&C!=!=>>!$I	N "* KKq	*q	C r%   r   r   N)ra   rE   r
   r   r   rO   rM   r  r   r(   r   r  r1  )r^   r*   r)   r>  r   r  r   s      @@@@r#   visit_MergedSequenceNode(ConstantFolding.visit_MergedSequenceNode  s    4 g...	! 	! 99CH KKq	"t9>q'CC..00SXX5JsI$@$@AA
		!d#r%   c                    U R                  U5        / nUR                   H  nUR                  (       d  UR                  U5        M'  UR                  R
                  (       aB  UR                  R                  (       d'  UR                  UR                  R                  5        M  UR                  U5        M     X!R                  SS& U R                  U5        U$ )r  N)	ra   r   r   rO   r   r   ri  rb  r1  )r^   r*   r   r)   s       r#   visit_SequenceNode"ConstantFolding.visit_SequenceNode  s    4 99C>>C 33CJJ<R<RCJJOO,C   		!d#r%   c           	         U R                  US/5        UR                  nUnUb  U R                  US/5        UR                  n[        Ul        UR                  5       (       a1  UR                  5       (       a   UR                  UR                  5        UnUR                  nUb  M  UR                  (       d2  UR                  5       (       a  U R                  XR                  5      $ U$ UR                  //n/ nUnUb  UR                  5       (       aP  UR                  (       d"  UR                  U R                  US5      5        OBUR                  UR                  /5        OUS   R                  U5        UR                  nUb  M  / nU H  n[!        U5      S:  a  M  US   n["        R$                  " UR&                  US   UR(                  UR                  [        S9n	UR                  U	5        U	n
USS   H  nX:l        Un
M     S U
l        M     U(       a  UR                  US   5        OU(       d  U R                  US	5      $ US   n[!        U5      S:X  a3  UR                  5       (       a  U R                  XR                  5      $  U$ USS   H)  n["        R*                  " UR&                  US
U[        S9nM+     U$ ! [        [        [        [        [        [        4 a     GNXf = f)NrB   rC   FrJ   r   r   r   )rB   r   rC   r=   Tr1  )ra   rB   rC   r   r=   r  "calculate_cascaded_constant_resultr  r&  r   r'  rB  r(  r  r:  rO   rM   r   r   r   r   r@  )r^   r*   	left_noder   
right_nodecascadesfinal_false_result	cmp_nodesr  	pcmp_nodelast_cmp_nodes              r#   r   $ConstantFolding.visit_PrimaryCmpNode  s   4*.MM	"x*6!**J'5H$,,..:3Q3Q3S3S??	@Y@YZ #I''H " ||''))t-A-ABBK ]]O$"++--//&--dooh.NO OOX%6%6$78 ##H-''H " 	G7|aqzH!00 !**!** .0I Y'%M#ABK(0% ( ( %)M!!  $ /23??4..|y>Q''))t-A-ABB *  &abM ..HH!"%$24 * E #Ix^Ude s   :K $K.-K.c                     U R                  U5        UR                  R                  5       (       d  U$ UR                  R                  (       a  UR                  $ UR
                  $ r'   )r1  rM  r  r=   r[  r\  rb   s     r#   r^  "ConstantFolding.visit_CondExprNode$  sI    d#yy,,..K99$$== >>!r%   c                    U R                  U5        / nUR                   H[  nUR                  nUR                  5       (       a&  UR                  (       a  UR
                  Ul          OMJ  UR                  U5        M]     U(       a  X!l        U$ UR                  (       a  UR                  $ [        R                  " UR                  / S9$ Nr   )ra   r   r   r  r=   r   r   rO   r   r   r   )r^   r*   r   rS  r   s        r#   rW   ConstantFolding.visit_IfStatNode-  s    4 
I!++I,,..,,'0~~D$ - !!), ) (OK###%%dhhb99r%   c                 &   U R                  U5        UR                  b  UR                  R                  c	  S =o!l        OUR                  R                  nUR                  b  UR                  R                  c	  S =o1l        OUR                  R                  nUR                  [        Laf  UR
                  nUR                  (       a"  UR                  c  UR                  X# Ul        U$ UR                  (       a  UR                  X#5      nUb  U$ U$ r'   )r1  rg  r=   ri  r   r   r   ri  r   r   as_sliced_node)r^   r*   rg  ri  r   s        r#   visit_SliceIndexNode$ConstantFolding.visit_SliceIndexNodeD  s    d#::!;!;!C!%%EJJJ..E99		 9 9 A##D999,,D~599D++0@0@0H IIe1	''**57#Kr%   c                 .   U R                  U5        [        UR                  [        R                  5      (       a  UR                  R
                  (       d  UR                  [        R                  L a   [        R                  " UR                  / / S9$ UR                  [        R                  L a(  [        R                  " UR                  / [        5       S9$ UR                  [        R                  L a   [        R                   " UR                  / 0 S9$ U$ )Nr1  rE  )ra   r(   r
  r   r   r   rE   r
   r"  r   r   r   r   r  rL   r   rI  rb   s     r#   visit_ComprehensionNode'ConstantFolding.visit_ComprehensionNode[  s    4 dii!3!344TYY__yyG--- ))HH2r; ;g... ((HH2su> >g/// ))HHb"F Fr%   c                    U R                  U5        UR                  R                  n[        U[        R
                  5      (       a  UR                  (       d<  UR                  (       a  UR                  $ [        R                  " UR                  / S9$ [        U[        R                  5      (       a  UR                  5       UR                  l        U$ r  )ra   r   r   r(   r   SequenceNoder   r   r   r   r   r   r8  )r^   r*   r   s      r#   r   #ConstantFolding.visit_ForInStatNodej  s    4 ==))h	 6 677==##+++ !--dhhbAA(I$6$677)1):):)<&r%   c                     U R                  U5        UR                  (       aV  UR                  R                  5       (       a7  UR                  R                  (       a  S Ul        S Ul        U$ UR                  $ U$ r'   )ra   r   r  r=   r   rb   s     r#   visit_WhileStatNode#ConstantFolding.visit_WhileStatNodey  s_    4 >>dnn@@BB~~--!%#'   '''r%   c                     U R                  U5        [        UR                  [        R                  5      (       d  U$ UR                  R                  5       (       a  g U$ r'   )ra   r(   rf   r   ExprNoder  rb   s     r#   rg   "ConstantFolding.visit_ExprStatNode  sG    4 $))Y%7%788K99((**r%   c                     U R                  U5        UR                  c  U$ UR                  R                  5       (       a0  UR                  R                  (       a	  S Ul        U$ UR                  $ U$ r'   )ra   r   r  r=   r   rb   s     r#   visit_GILStatNode!ConstantFolding.visit_GILStatNode  sb    4 >>!K>>--// ~~--!%  yy  r%   )r  r
  )4rt   ru   rv   rw   rx   r[   r1  r   r   r.  r   r  r4  r7  r:  r=  rD  rP  rH  rA  rC  rB  rc  r_  rf  rk  rj  ri  r{  r  ry  r  r  rc  r  r  r  r   r^  rW  r  r  r   r  rg   r  r   ru  rv  ry   rz   __classcell__)r   s   @r#   r  r    s    %1@ !))9+=+= (()*=*=?O?& 	
 
c ,%8t5*n*6"*	 D.L1> D$LN`":..6 ))==Jr%   r  c                   ~    \ rS rSrSrSrS rS rS rS r	S r
S	 rS
 rS rS rSS jrS\R"                  4S jrSrg)FinalOptimizePhasei  a  
This visitor handles several commuting optimizations, and is run
just before the C code generation phase.

The optimizations currently implemented in this class are:
    - eliminate None assignment and refcounting for first assignment.
    - isinstance -> typecheck for cdef types
    - eliminate checks for None and/or types that became redundant after tree changes
    - eliminate useless string formatting steps
    - inject branch hints for unlikely if-cases that only raise exceptions
    - replace Python function calls that look like method calls by a faster PyMethodCallNode
    - replace duplicate FormattedValueNodes in f-strings with CloneNodes
Fc                 p    U R                  U5        UR                  (       a  UR                  nSUl        U$ )zQAvoid redundant initialisation of local variables before their
first assignment.
T)ra   ri  r   lhs_of_first_assignment)r^   r*   r   s      r#   visit_SingleAssignmentNode-FinalOptimizePhase.visit_SingleAssignmentNode  s/     	4 ::((C*.C'r%   c                    UR                   nUR                  nUR                  (       d  UR                  (       a  UR                  OS nU R                  5       nUR                  =(       d<    UR                  =(       d)    UR                  =(       a    UR                  R                  nUR                  5       =(       a    UR                  =(       ao    U[        R                  L=(       aV    U=(       a    UR                  (       + =(       a5    U R                  R!                  U R"                  (       d	  U(       a  SOS5      $ )Nz&optimize.unpack_method_calls_in_pyinitzoptimize.unpack_method_calls)r  rE   r   r   r   r   is_module_scopeis_c_class_scopeis_py_class_scopeouter_scoper  r   r
   rN   r  rO  rP  in_loop)r^   r*   r  function_typer   r  in_global_scopes          r#   _check_optimize_method_calls/FinalOptimizePhase._check_optimize_method_calls  s    == "*"2"2h6K6KQU  H  H""Fs'F'F 	 ! 5%%5!2!225 +5++,5 ##''|| 935		
r%   c                 &   U R                  U5        UR                  nUR                  R                  (       Ga)  UR                  (       Ga  UR
                  S:X  Ga  [        UR                  5      S:X  a  UR                  S   nUR                  R                  (       a  UR                  R
                  S:X  a  U R                  R                  nUR                  S5      Ul        UR                  R                  Ul        [        R                  " UR                  S5      R                  5      n[        R                   " UR                  S   U5      UR                  S'   U$ [        R"                  R%                  UR&                  SS9(       Ga   [        R"                  R)                  U5      (       a  UR*                  (       ax  UR,                  (       ag  [/        UR0                  [        R2                  5      (       a>  UR0                  R4                  UR*                  L a  UR0                  R4                  Ul        U R7                  U[        R"                  R9                  XUR&                  UR                  U R;                  U5      S	95      nU$ )
z
Replace generic calls to isinstance(x, type) by a more efficient type check.
Replace likely Python method calls by a specialised PyMethodCallNode.
r(   r   r   rE   PyObject_TypeCheckrC  F)
has_kwargs)r  r  rE   unpack)ra   r  rE   is_cfunctionr   r"   rM   r   r  r  rJ  r=  r   r	   rK  r   r  PyMethodCallNodecan_be_used_for_posargsr  can_be_used_for_functionr^   r   r(   r8   r  r)   r_  	from_noder  )r^   r*   r  rN  rJ  rS  s         r#   r  'FinalOptimizePhase.visit_SimpleCallNode  s   
 	4 ====%%%(*:*:*:}},TYY11D99Q<==00X]]5G5G65Q#'<<#<#<L%1%8%89M%NHN$,NN$7$7HM&0&9&9,:M:Mn:]:b:b&cO#,#5#5diilO#TDIIaL  ))AA$..]bAc--FFxPP		h&;&;&x||Y5H5HIIhllN^N^bfbkbkNk'/||'7'7<<i.H.H.R.R4>>PTPYPY#@@F /S /H ID r%   c                    U R                  U5        [        UR                  5      n[        UR                  [        R
                  5      n[        R                  R                  UR                  X#S9(       d  U$ UR                  n[        R                  R                  U5      (       d  U$ U R                  U[        R                  R                  XUR                  UR                  UR                  U R                  U5      S95      nU$ )zG
Replace likely Python method calls by a specialised PyMethodCallNode.
)r  has_explicit_kwargs)r  r  kwdictrE   r  )ra   r  r  r(   r   rI  r  r  r  r  r  r_  r  rE   r  )r^   r*   r  r  r  s        r#   r  (FinalOptimizePhase.visit_GeneralCallNode  s     	4 $++,
():):I<N<NO))AA$$ B fK==))BB8LLK||D)"<"<"F"Ft/C/CDL]L]4#D#DT#J #G #L M r%   c                 (    U R                  U5        U$ r'   )ra   rb   s     r#   visit_NumPyMethodCallNode,FinalOptimizePhase.visit_NumPyMethodCallNode  s    4 r%   c                     U R                  U5        UR                  (       d&  UR                  R                  5       (       d  SUl        U$ )zyRemove tests for alternatively allowed None values from
type tests when we know that the argument cannot be None
anyway.
T)ra   notnoner)   r  rb   s     r#   rf  'FinalOptimizePhase.visit_PyTypeTestNode  s8    
 	4 ||88''))#r%   c                 ~    U R                  U5        UR                  R                  5       (       d  UR                  $ U$ )zORemove None checks from expressions that definitely do not
carry a None value.
)ra   r)   r  rb   s     r#   visit_NoneCheckNode&FinalOptimizePhase.visit_NoneCheckNode  s3     	4 xx##%%88Or%   c                 Z    U R                   nSU l         U R                  U5        X l         U$ )zeRemember when we enter a loop as some expensive optimisations might still be worth it there.
        T)r  ra   )r^   r*   old_vals      r#   visit_LoopNode!FinalOptimizePhase.visit_LoopNode$  s,     ,,4 r%   c                 ,   U R                  U5        Sn[        UR                  5       H5  u  p4U R                  XDR                  5        UR
                  (       a  M3  UnM7     UR                  (       a!  U(       a  U R                  X!R                  SS9  U$ )zQAssign 'unlikely' branch hints to if-clauses that only raise exceptions.
        NT)inverse)ra   r   r   _set_ifclause_branch_hintr   branch_hintr   )r^   r*   last_non_unlikely_clauser4  rS  s        r#   rW  #FinalOptimizePhase.visit_IfStatNode-  s     	4 #' %doo6LA**9nnE(((+4( 7  8**+CEUEU_c*dr%   c                    UR                   (       d  g[        R                  [        R                  [        R                  [        R
                  [        R                  [        R                  4nU/n[        US5       H  u  pg[        U[        R                  5      (       a  UR                  XgR                  5        MA  [        U[        R                  5      (       a  UR                  XVU& Mp  [        Xt5      (       a  M  U[        U5      :X  a?  [        U[        R                   [        R"                  45      (       a  U(       a  SOSUl          g   g)z\Inject a branch hint if the if-clause unconditionally leads to a 'raise' statement.
        Nr   likelyunlikely)is_terminatorr   r  AssignmentNodeAssertStatNodeDelStatNode
GlobalNodeNonlocalNoder   r(   GILStatNoderd  r   r   r   rM   RaiseStatNodeReraiseStatNoder  )r^   clausestatements_noder  non_branch_nodes
statementsnext_node_posr*   s           r#   r   ,FinalOptimizePhase._set_ifclause_branch_hint;  s     ,,     
 &&
#,Z#;M$ 1 122!!-;$ 2 233:>**
7d55 C
O3
4%J]J]_d_t_tIu8v8v5<*F& $<r%   r*   c                    [         R                  n[         R                  n0 nUR                  SS n[	        UR                  5       GH  u  pg[        Xr5      (       d  M  UR                  n[        UR                  U5      (       a  UR                  nO,UR                  b  OUR                  R                  (       a  OMx  UR                  (       a  UR                  5       (       d  M  UR                  UR                  UR                  UR                  =(       d    S4n	UR!                  X5      n
XL a  M  [         R"                  " U
5      nUR$                  Ul        XU'   GM     XQR                  SS& U$ )a  
Deduplicate repeatedly formatted (C) values by replacing them with CloneNodes.
It's not uncommon for a formatting expression to appear multiple times in an f-string.

Note that this is somewhat handwavy since it's potentially possible even for simple
expressions to change their value while processing an f-string, e.g. by modifying the
world in a ".__format__" method.  However, this seems unlikely enough to appear in
real-world code that we ignore the case here.
Nr_  )r   r  r  r   r   r(   r   r)   r  rE   r  r   r  r"   r  r  r  r  r   )r^   r*   r  r  rD  r   r4  fnodefnode_value_noder  
seen_fnodededup_fnodes               r#   r  &FinalOptimizePhase.visit_JoinedStrNodeW  s8    '99&99Q!$++.HAe88${{%++'9::#3#7#7 $$0!&&66  $,,1A1K1K1M1M
 #((%*=*=u?P?PRWRgRgRnknoC4J"#--j9K#iiKO#1IE /H  Ar%   )r  Nr
  )rt   ru   rv   rw   rx   r  r  r  r  r  r  rf  r  r  rW  r   r   rb  r  rz   rj   r%   r#   r  r    sR     G
*<&
	84	(?(? 4r%   r  c                   (    \ rS rSrSrSrS rS rSrg)ConsolidateOverflowChecki  a!  
This class facilitates the sharing of overflow checking among all nodes
of a nested arithmetic expression.  For example, given the expression
a*b + c, where a, b, and x are all possibly overflowing ints, the entire
sequence will be evaluated and the overflow bit checked only at the end.
Nc                     U R                   b,  U R                   nS U l         U R                  U5        X l         U$ U R                  U5        U$ r'   )overflow_bit_nodera   )r^   r*   saveds      r#   ry   #ConsolidateOverflowCheck.visit_Node  sQ    !!-**E%)D"t$%*"  t$r%   c                    UR                   (       af  UR                  (       aU  U R                  S L nU(       a  Xl        OU R                  Ul        SUl         U R                  U5        U(       a  S U l        U$ U R                  U5        U$ r3   )overflow_checkoverflow_foldr  ra   )r^   r*   top_level_overflows      r#   visit_NumBinopNode+ConsolidateOverflowCheck.visit_NumBinopNode  sx    4#5#5!%!7!74!?!)-&)-)?)?&&+#t$!)-&  t$r%   )r  )	rt   ru   rv   rw   rx   r  ry   r&  rz   rj   r%   r#   r  r    s     r%   r  rj   )Gcythondeclarer   r   r   r   r   	functoolsr   r   r   r   r  r   r   r   r   r  r  ro  r   r	   r   r
   r   r   Coder   r   StringEncodingr   r   r   Errorsr   r   ParseTreeTransformsr   r   r$   r  r}  r,   r1   r7   r>   r)  rU   rZ   rW   r~   r|   EnvTransformr   r  ru  rx  r  r  NodeRefCleanupMixinrR  MethodDispatcherTransformrc  r'  r!   r\  r  r  r  CythonTransformr  rj   r%   r#   <module>r3     sx     .6 . .v .^d ..'-.:@.JP..)/.7=. .  &. /5. AG. TZ. 	. '-	. 
    %   23<         1 H H " 1 7 /8.J.JILjLj-k #$t #$L'-- @t-- tn!y>g** y>xF>W557G F>Rq&w77 q&hCw33 CL44g6J6J DqT766"<<qTh?B:J "-!8!89Lo!^ *667H/Z s>g..0@ s>l`--w/J/J `F w66  r%   