
    ?e*(                         d dl m Z  ddlmZ ddlmZmZ ddlmZmZm	Z	 d Z
ddZd	 Zd
 Z	 ddZddZd Zd Zd ZdS )    )copy   )
ScopedName)ArgumentTypeIfaceFileType)append_iface_fileargument_as_strsame_base_typec                 ^   t          | j                  }| j        j        D ]
}d}|j        r|dz  }|j        r|dz  }d                    |j        j        |t          |j
                            }|j        t          j        u rt          |j                  }nR|j        t          j        u rt          |j                  }n*|j        t          j        u rt          |j                  }nd}||                    |           ||d         z   |d<   |D ]}|                    |           |S )z( Return the encoded name of a template. r   r      z
{:02d}{}{}N)r   cpp_nametypesargsis_constis_referenceformattypevaluelenderefsr   DEFINED
definitionTEMPLATEencoded_template_nameSTRUCTappend)templatesndadflagsencodingarg_sndnames          <lib/python3.11/site-packages/sipbuild/generator/templates.pyr   r      s>    X&
'
'Cn! ! !; 	QJE? 	QJE  &&rw}eS^^LL7l*** //GGW---+BM::GGW+++ //GGG?JJx     "GAJ.GAJ ! !

4    ! J    Fc                 X   t          | j                  t          |j                  k    rdS t          | j        |j                  D ]\  }}|j        t          j        u r|s|j        t          j        u rQ|j        t          j        u r>|j        |j        k    s*t          |j                  t          |j                  k    r dS |j        t          j        u r=|j        t          j        u r*t          |j
        j        |j
        j        |          s dS t          ||          s dS dS )z Return True if the template signatures are the same.  A deep comparison
    is used for mapped type templates where we want to recurse into any nested
    templates.
    F)deepT)r   r   zipr   r   r   r   r   r   same_template_signaturer   r   r
   )sig1sig2r'   type1type2s        r$   r)   r)   F   s7    49~~TY''uDIty11  u :---d- :---%*@T2T2T!U%7773u|;L;LPSTYT`PaPa;a;auu <b Z<000UZ<CX5X5X*5+;+A5CSCY`deee uu  u-- 	55	 4r%   c                 .    |dS t          | |||          S )zj Return a copy of an optional CodeBlock object with sub-strings replaced
    by corresponding values.
    N_template_code_block)specused
proto_code
expansionss       r$   template_coder5   f   s#     tdJ
CCCr%   c                 (      fd|D             S )zi Return a copy of a list of CodeBlock objects with sub-strings replaced
    by corresponding values.
    c                 4    g | ]}t          |          S  r/   ).0pcr4   r1   r2   s     r$   
<listcomp>z(template_code_blocks.<locals>.<listcomp>w   s7     ) ) ) !tR<< ) ) )r%   r8   )r1   r2   proto_code_blocksr4   s   `` `r$   template_code_blocksr=   r   s:    
) ) ) ) ) )') ) ) )r%   Nc                 ,   i }t          | j                  D ]{\  }}|j        t          j        u r|U|j        j        s(|j        D ]>}|j        t          j        ur|j        j        |j        j        k    r|j        j        } n?on|j        j        }|j        |         }|j        t          j        u rt          |j                  }	nt          |          }	|j
        rd|	z   }	|	||<   |j        t          j        u r|j        |         }|j        t          j        u rvt          |j        j        j                  t          |j        j        j                  k    r8|                    t          |j        j        |j        j        |                     }|S )a   Return a dict of expansions to be applied when instantiating mapped
    type of class templates (including handwritten code).  The key is the
    symbolic name of a template argument and the value is the replacement to be
    used in a particular instantiation.
    Nconst )	enumerater   r   r   r   r   	is_simple	base_namestrr	   r   r   r   r   updatetemplate_expansions)
template_namesinstantiation_valuesdeclared_namesr4   arg_nrname_argdeclaredr#   	value_argr   s
             r$   rE   rE   {   s    J%n&9:: ,M ,M=L000 )*4  . 3 	 	H}L,@@@ *48K8UUU'2< V    *4 -1&9I~!555I011'	22 ! * 5($Jt]l333,1&9I ~!6663x?R?X?];^;^befofz  gA  gF  cG  cG  <G  <G!!+H,?,E ) 4 :NL LM M M r%   c                     |                                 D ]B\  }}t          |          }||                    d|          }|                     ||          } C| S )zV Return a copy of a string with sub-strings replaced by corresponding
    values.
    N::)items_strip_constreplace)	proto_strr4   scope_replacementr#   r   s        r$   template_stringrT      sk    
 "'')) 3 3eU## (MM$(9::E %%dE22		r%   c                 D    |                      d          r
| dd         } | S )z* Strip any leading 'const' from a string. r?      N)
startswith)ss    r$   rP   rP      s*     	||H abbEHr%   c           	      @   t          |          }g }|j                            d          D ]D}|}|                                                    d          s|                                D ]\  }}	|                    |          }
|
dk    rdD ]v}|d|
                             |          rWt          |	          }	t          | ||	           |	                    d          r
|	dd         }	|	
                    dd          }	 nw|d|
         |	z   ||
t          |          z   d         z   }|                    ||
t          |	          z             }
|
dk    ͌|                    |           Fd                    |          |_        |j        |j        k    r|S |S )	z Return a copy of a CodeBlock object with sub-strings replaced by
    corresponding values or the original if there were no substitutions.
    
#r   )sipType_sipException_NrN   r   _)r   textsplitlstriprW   rO   findendswithrP   _add_used_from_coderQ   r   r   join)r1   r2   r3   r4   i_codei_lines
proto_linei_liner#   r   posgen_types               r$   r0   r0      s   
 *FG o++D11 ! !
   ""--c22 	>)//11 > >e kk$''Qhh %B " "!$3$<00:: "$0$7$7E/dEBBB  %//55 2(-abb	$)MM$$<$<E!E" $AcE]U2VC#d))O<L<L5MMF ++dC#e**,<==C) Qhh, 	v))G$$FK &+%%Mr%   c                 V   t          j        |          }|                                 | j        D ]?}|j        t
          j        t
          j        fv r|j        |k    rt          ||            dS @| j
        D ]1}|j        (|j        |k    rt          ||j        j                    dS 2dS )zE Add any interface files to a used list that are defined for a name. N)r   parsemake_absoluteiface_filesr   r   CLASS	EXCEPTIONfq_cpp_namer   enumsscope
iface_file)r1   r2   r#   ru   enums        r$   rd   rd     s     D!!D&  
?}2M4KLLL%--!$
333
  :!4''!$
(=>>>	 r%   )F)N)r   scoped_namer   specificationr   r   utilsr   r	   r
   r   r)   r5   r=   rE   rT   rP   r0   rd   r8   r%   r$   <module>rz      s  0       # # # # # # 6 6 6 6 6 6 6 6 E E E E E E E E E E$ $ $N   @	D 	D 	D) ) ) ? ? ? ?D   $  1 1 1h    r%   