
    ?eF                         d dl m Z  ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZmZmZ ddlmZmZmZ d Zd Zd	 Zd
 Zd Zd Zej        fdZd Zd Zd Z d Z!dS )    )copy   )
ScopedName)	ArgumentArgumentTypeFunctionCallIfaceFileTypeKwArgs	Signature	TypeHintsValue	ValueType)template_codetemplate_code_blockstemplate_expansionstemplate_string)append_iface_filecached_namenormalised_scoped_namec
                    t          ||j                  t          |          t          |j        j                  <   t          |          }
|||
_        g |
_        g |
_        g |
_	        t          |	j        |          |
_        ||
_        ||
_        |	                    | ||t           j                  |
_        |	j        j        |
j        _        |
j        j        }t+          |	j        ||j        j                  |
j        _        |
j        j                            |j        j                   |j        j        D ]}t1          |
j        j        |           |	j        |
_        |
j        .|
j        j                            |
j        j        j                   |	j        rd|
j        j        _        d|
j        _        |j         t;          |	j        |j                  |
_        |j        fd|j        D             |
_        g |
_        |j        D ]}|j        j        }|j        j        |j         s|
j        !                    |           =tE          |j#                  D ]\  }}|j$        |j%        j$        k    r|j        j#        |         }|j&        tN          j(        u r(|	)                    | |t           j        |j%                  }nG|j&        tN          j        u r|j%        }n,|	*                    | |d+                    |                     |}|
j        !                    |           ɐtY          ||||
|	           t[          ||||
|	           t]          | |||||
|	           t_          ||||
|	          |
_0        tc          |j2        |
j        j        |	          |
_2        tg          |j4        |j2        |
j2        ||||
|		  	        |
_4        tk          |	j        ||j6                  |
_6        tk          |	j        ||j7                  |
_7        tk          |	j        ||j8                  |
_8        tk          |	j        ||j9                  |
_9        tk          |	j        ||j:                  |
_:        t+          |	j        ||j;                  |
_;        tk          |	j        ||j<                  |
_<        tk          |	j        ||j=                  |
_=        tk          |	j        ||j>                  |
_>        tk          |	j        ||j?                  |
_?        tk          |	j        ||j@                  |
_@        tk          |	j        ||jA                  |
_A        t+          |	j        ||jB                  |
_B        tk          |	j        ||jC                  |
_C        |	j        jD        E                    d|
           dS )z Instantiate a class template. NTc                 0    g | ]}t          |          S  )r   ).0s
expansionss     Alib/python3.11/site-packages/sipbuild/generator/instantiations.py
<listcomp>z%instantiate_class.<locals>.<listcomp>[   s3     $7 $7 $7 %4Az$B$B $7 $7 $7    z.template argument '{0}' must expand to a classr   )Fr   typesstr
iface_filefq_cpp_namer   	docstringmrovirtual_overloadsvisible_membersr   specpy_nametemplateno_type_namefind_iface_filer	   CLASSmodule_statemoduleusedr   type_header_codeextendr   scopein_main_modulecpp_name
type_hintsinstantiate_type_hintspyqt_flags_enumssuperclasses	is_simpleappend	enumerateargs	base_name
definitiontyper   DEFINED
find_classparser_errorformat_instantiate_enums_instantiate_vars_instantiate_typedefs_instantiate_ctorsctors_instantiate_methodsmembers_instantiate_overloads	overloadsr   bi_get_buffer_codebi_release_buffer_codeconvert_from_type_codeconvert_to_subclass_codeconvert_to_type_codedealloc_codedtor_virtual_catcher_codefinalisation_codegc_clear_codegc_traverse_codeinstance_codepickle_code	type_codetype_hint_codeclassesinsert)psymbolr"   
tmpl_namesproto_classr)   r(   r*   r#   pmi_classr/   r!   
superclasssuperclass_nameaargtmpl_argi_superclassr   s                      @r   instantiate_classri   "   s   
 %Z@@J ;>k:J:JJs;)5667 ;G%GK "G G!"'733GOG'G ++Av{! !G " 6G"D*>rw"3Z+A +AG''.."35 5 5 ",1 ? ?
',1:>>>> HGM} +22(9	; 	; 	; 
 $+/#(# )3BG&
4 4 #/$7 $7 $7 $7$5$7 $7 $7  G!. : :
$/;  '3?;T3 ''
333
00 	: 	:FAs(CN,DDD#>.q1=L$888#%==F)/1D$F $FLL]l&888#+#6LLOOAvLSSTcddf f f#-L$++L999	:" z;':   j+x*   !VZhZ% % % 'z;Z% %GM +;+>%r+ +GO.{/D*kgz2/ /G
 "/rw*J"8 "8G%227D.
&< &<G"%227D.
&< &<G"'4RWd0*(> (>G$#0$,j$: $:G /$j2 2G(5bgt1:)? )?G% -bgt):!7 !7G)"'4%z3 3G,RWd(* 6  6G)"'4%z3 3G'{7N G,RWd!:/ /G*27D&
4 4G GO1g&&&&&r   c           	         t          |           }| j        t          j        u r<| j        }t          |          }	t          |j        |||||          |	_        |	|_        | j        fd| j        D             |_        | j         t          |j
        | j                  |_        | j        t          j        u r| j        j        r| j        j        }
t          |j                  D ]M\  }}|
|j        j        k    r8|j        j        |         }|j        |_        |j        |_        |j        |_         n5N|
|j        j        j        k    rt          j        |_        ||_        d|_        |S )z) Return an instantiated Argument object. Nc                 0    g | ]}t          |          S r   )_instantiate_value)r   vr   s     r   r   z)_instantiate_argument.<locals>.<listcomp>   s3     2 2 2  2!Z@@ 2 2 2r   )r   r?   r   TEMPLATEr>   _instantiate_signaturer   default_valuer5   r6   r'   r@   r9   r=   r;   r<   is_constrainedr!   r"   r,   original_type)	proto_argr`   r_   r)   rb   r   ra   i_argproto_template
i_templatenamere   rf   tads        `        r   _instantiate_argumentry      s   
 OOE ~..."-.))
1.2FZ7JL L
% *2 2 2 2"02 2 2 '1"'$j2 2 ~---)2F2P-#-
00 	+ 	+FAss~///n)!, X
#&>  (+'9$ 0 {-9CCC)/
#* &*#Lr   c                    g }|j         j        }|j        D ]}t          |          }	t	          |j        || |||||j                  |	_        |j        |j        u r|	j        |	_        n$t	          |j        j        || ||||          |	_        t          |j	        ||j
        |          |	_
        t          |j	        ||j        |          |	_        |j        |u r|	|_        |                    |	           |S )z> Return a list of the instantiated ctors of a template class. kw_args)r!   r/   rH   r   ro   py_signaturer|   cpp_signaturer   r'   method_codepremethod_codedefault_ctorr:   )
r_   r`   r)   rb   r   ra   i_ctorsr/   
proto_ctori_ctors
             r   rG   rG      s!    G"D!'  
j!!4Z5LZ7J"*, , , #z'>>>#)#6F  #9,:K':r$C $CF  +27D&
4 4 -bgt):!7 !7 #z11#)G vNr   c                 P   t          |j        j                  D ]
}|j        |urt	          |          }|j        Ft          |j        |          |_        t          |j        t          |j                            |_	        |j
        r!|j        d|_        |j	        d|j	        _        ||_        |j        j        |_        g |_        |j        D ]2}t	          |          }	||	_        |j                            |	           3|j        j                            d|           dS )- Instantiate the enums for a template class. NTr   )listr'   enumsr2   r   r"   r   r   r    cached_fq_cpp_namer3   r(   r/   r!   r.   rJ   r:   r\   )
r_   r`   r)   rb   r   ra   
proto_enumi_enumproto_memberw_members
             r   rD   rD     s8    27=))  (  (
;.. j!!!-!7
8N" "F(3BG*++)- )-F%  	6~)!%(415).*1&. 	, 	,LL))H#HNN!!(++++
Q''''A (  (r   c                     g }| D ]@}t          |          }||_        |j        rd|j        _        |                    |           A|S )zL Return a list of the instantiated methods of a template class or enum.
    T)r   r.   r3   r(   r/   r:   )proto_methodstarget_modulera   	i_methodsproto_methodi_methods         r   rI   rI   .  s_     I% 	# 	#%%' 	)$(H!""""r   c	                    g }	|j         j        }
| D ]8}t          |          }t          ||          D ]\  }}|j        |u r	||_         nt          |j        |||||||j                  |_        |j        |j        u r|j        |_        n$t          |j        j        ||||||          |_        t          |j
        |
|j        |          |_        t          |j
        |
|j        |          |_        t          |j
        |
|j        |          |_        t          |j
        |
|j        |          |_        |	                    |           :|	S )zR Return a list of the instantiated overloads of a template class or
    enum.
    r{   )r!   r/   r   zipcommonro   r}   r|   r~   r   r'   r   r   virtual_call_codevirtual_catcher_coder:   )proto_overloadsr   r   r_   r`   r)   rb   r   ra   i_overloadsr/   proto_overload
i_overloadr   r   s                  r   rK   rK   B  s    K"D) ' '.))
&))]&C&C 	 	"Hl$44$,
! 5 #9+[*hR1G#I #I #I
 '>+FFF'1'>J$$'="0>':r(C (CJ$ "/rw*J"8 "8
$1"'4-z%; %;
!'4RWd0*(> (>
$*73Z+A +A
' 	:&&&&r   c           
      Z   t                      }| j        D ]n}	t          |	||||||          }
|j                            |
           |j        r6|
j        /|t          j        u s|t          j        u r|
j	        d|
j        _
        o| j        t          | j        ||||||          |_        |S )z* Return an instantiated Signature object. NT)r   r<   ry   r:   r3   rw   r
   ALLOPTIONALrp   r/   result)proto_signaturer`   r_   r)   rb   r   ra   r|   i_signaturers   rt   s              r   ro   ro   m  s     ++K$) 	' 	'	%ij':r3 3 	&&&  	'!7&*$$FO)C)CH[Hg"&
)2?3IZ7JL L r   c                     |j         t          |j         |d          }nd}|j        t          |j        |d          }nd}t          |||j                  S )z* Return an instantiated TypeHints object. N.)scope_replacement)hint_inhint_outrp   )r   r   r   r   rp   )r'   proto_type_hintsr   r   r   s        r   r6   r6     s     +!"2":J*-/ / /  ,"#3#<j*-/ / / Wx*8: : : :r   c           
      &   |j         j        D ]}|j        |urt          |          }	t	          |j        |          |	_        ||	_        |j        j        |	_        t          |j	        ||||||          |	_	        |
                    | ||	           dS )z/ Instantiate the typedefs of a template class. N)r'   typedefsr2   r   r   r"   r!   r.   ry   r?   add_typedef)
r]   r^   r_   r`   r)   rb   r   ra   proto_typedef	i_typedefs
             r   rF   rF     s     ) - -k11 ''	 6)7!4 !4	!	"-4	.}/A;Hgz2? ?	 	q&),,,,- -r   c                    | }| j         t          j        u r| j        j        j        t          j        u r| j        j        j        }|j	        rxt          j        t          |j        |                    }t          t          j        |          }t          || j        j                  }t#          t          j        |          }|S )z& Return an instantiated Value object. )r?   r>   )r   r<   )value)
value_typer   FCALLr   r   r?   r   r@   r>   r9   r   parser   r=   r   r   r<   r   )proto_valuer   i_value
proto_namei_namei_resulti_fcalls          r   rl   rl     s    
 G00[5F5M5RVbVj5j5j &-8
 	<%#J$8*EEG GF\%9fMMMH"($*/1 1 1GIO7;;;GNr   c           
      >   |j         j        }|j        j        D ]}|j        |urt          |          }|j        rd|j        _        t          |j	        |          |_	        ||_        |j         j
        |_
        t          |j        || ||||          |_        t          |j        ||j        |          |_        t          |j        ||j        |          |_        t          |j        ||j        |          |_        |j        j                            |           dS )r   TN)r!   r/   r'   	variablesr2   r   r3   r(   r   r"   r.   ry   r?   r   access_codeget_codeset_coder:   )	r_   r`   r)   rb   r   ra   r/   	proto_vari_vars	            r   rE   rE     s-    "DW& ( (	?+-- Y 	&!%EM293H )0*9>;Hgz2? ?
 *"'49N &rwi6H &rwi6H  	  ''''3( (r   N)"r   scoped_namer   specificationr   r   r   r	   r
   r   r   r   r   	templatesr   r   r   r   utilsr   r   r   ri   ry   rG   rD   rI   rK   NONEro   r6   rF   rl   rE   r   r   r   <module>r      s  0       # # # # # #G G G G G G G G G G G G G G G G G G G G G G. . . . . . . . . . . . I I I I I I I I I IL' L' L'^/ / /d! ! !H$( $( $(N  (( ( (X *0   0: : :&- - -,  *( ( ( ( (r   