U
    jg2                     @   s   d Z ddlZzddlZddlZW n ek
r<   edY nX G dd dZG dd dZG dd	 d	ZG d
d dZG dd dZ	dd Z
eje e
  dS )z(gdb printing extension for Numba types.
    Nz$GDB python support is not available.c                   @   s   e Zd Zdd Zdd ZdS )NumbaArrayPrinterc                 C   s
   || _ d S Nvalselfr    r   B/tmp/pip-unpacked-wheel-qtpwf23r/numba/misc/gdb_print_extension.py__init__   s    zNumbaArrayPrinter.__init__c           )   
   C   s  zdd l }d}W n tk
r(   d}Y nX zd}| jd }| jd }| jd }| jd }d}t| jj}	|rd|	ksd	|	kr|	d
d }	td}
dd |
	|	
 D }|\}}}d}t	||}|
 \}}}|dk}|d}g }|D ]}|d}|d }|dd  }t|dkr4td| n@|d }d|krRtd| |dd dd }||}|||f q|}nJtd}
dd |
	|	
 D }|\}}}d|kr|dd dd}dd }||}||}||kr|r|dd |D }||} |||  }!|!t|7 }!|j||d }"|"}t }#|#t||!}$|j|$|d!}%|jjj|%||d"}&d#t|& W S d$||f W S td%g}'d&d'|' d( d) W S W n0 tk
r }( zd*|(  W Y S d }(~(X Y nX d S )+Nr   TFdataitemsizeshapestridesZalignedZRecordz
unaligned  z%array\((Record.*), (.*), (.*)\)\ \(.*c                 S   s   g | ]}|  qS r   strip.0xr   r   r	   
<listcomp>8   s     z/NumbaArrayPrinter.to_string.<locals>.<listcomp>z(Record\((.*\[.*\]);([0-9]+);(True|False)True,[   zUnsupported sub-type: %sZnestedarray;=zarray\((.*),(.*),(.*)\)\ \(.*c                 S   s   g | ]}|  qS r   r   r   r   r   r	   r   R   s     z	unichr x z<Uc                    s<    j  }|d j  \}}t fddt||d D S )Nr   c                    s   g | ]}t  | qS r   )intr   dwarrr   r	   r   \   s     zGNumbaArrayPrinter.to_string.<locals>.dwarr2inttuple.<locals>.<listcomp>r   )typefieldsrangetuple)r   r!   lohir   r   r	   dwarr2inttupleX   s    
z3NumbaArrayPrinter.to_string.<locals>.dwarr2inttuplec                 S   s   g | ]}t d |d qS )r   r   )maxr   r   r   r	   r   h   s     )Zalign)dtype)r   r   
z array([...], dtype=%s, shape=%s)zNULL/Uninitializedzarray([, ])z%array[Exception: Failed to parse. %s])ZnumpyImportErrorr   strr    replacer   recompilematchgroupssplitlen	TypeErrorr(   appendarraysumr   gdbselected_inferiorread_memoryZ
frombufferlibZstride_tricksZ
as_stridedlistjoin	Exception))r   npZ
HAVE_NUMPYNULLr   r   ZrshpZrstridesZ
is_alignedZty_strmatcherZarr_infoZ	dtype_strZndim_strZ	order_strZrstrZ
rstr_matchr!   ZbalignZis_aligned_strZ	field_dtsZstruct_entriesfZsplittednameZdt_partZ	dt_as_strr(   r&   r   r   Zshp_arrZstrd_arrZextentZdtype_clazz	this_procmemZarr_dataZnew_arrbufer   r   r	   	to_string   s    

















zNumbaArrayPrinter.to_stringN__name__
__module____qualname__r
   rJ   r   r   r   r	   r      s   r   c                   @   s   e Zd Zdd Zdd ZdS )NumbaComplexPrinterc                 C   s
   || _ d S r   r   r   r   r   r	   r
      s    zNumbaComplexPrinter.__init__c                 C   s   d| j d | j d f S )Nz%s+%sjrealimagr   )r   r   r   r	   rJ      s    zNumbaComplexPrinter.to_stringNrK   r   r   r   r	   rO      s   rO   c                   @   s   e Zd Zdd Zdd ZdS )NumbaTuplePrinterc                 C   s
   || _ d S r   r   r   r   r   r	   r
      s    zNumbaTuplePrinter.__init__c                 C   s>   g }| j j }|D ]}|t| j |j  qdd| S )N(%s)r*   )r   r    r!   r7   r.   rE   r?   )r   rH   r!   rD   r   r   r	   rJ      s
    zNumbaTuplePrinter.to_stringNrK   r   r   r   r	   rR      s   rR   c                   @   s   e Zd Zdd Zdd ZdS )NumbaUniTuplePrinterc                 C   s
   || _ d S r   r   r   r   r   r	   r
      s    zNumbaUniTuplePrinter.__init__c                 C   sX   | j j }|d j \}}g }t||d D ]}|t| j |  q0dd| S )Nr   r   rS   r*   )r   r    r!   r"   r7   r.   r?   )r   r!   r$   r%   rH   ir   r   r	   rJ      s    zNumbaUniTuplePrinter.to_stringNrK   r   r   r   r	   rT      s   rT   c                   @   s   e Zd Zdd Zdd ZdS )NumbaUnicodeTypePrinterc                 C   s
   || _ d S r   r   r   r   r   r	   r
      s    z NumbaUnicodeTypePrinter.__init__c                 C   sz   d}| j d }| j d }| j d }||krjt }|t||| }t|tr^t| }qr|d}nt	|}d| S )Nr   r   lengthkindzutf-8z'%s')
r   r:   r;   r<   r   
isinstance
memoryviewbytesdecoder.   )r   rB   r   ZnitemsrX   rF   rG   rH   r   r   r	   rJ      s    



z!NumbaUnicodeTypePrinter.to_stringNrK   r   r   r   r	   rV      s   rV   c                  C   sd   t jd} | ddt | ddt | ddt | dd	t | d
dt | ddt | S )NZNumbazNumba unaligned array printerz^unaligned array\(zNumba array printerz^array\(zNumba complex printerz^complex[0-9]+\ zNumba Tuple printerz^Tuple\(zNumba UniTuple printerz^UniTuple\(zNumba unicode_type printerz^unicode_type\s+\()	r:   printingZRegexpCollectionPrettyPrinterZadd_printerr   rO   rR   rT   rV   )printerr   r   r	   _create_printers   s$    r_   )__doc__r0   Zgdb.printingr:   r-   r   rO   rR   rT   rV   r_   r]   Zregister_pretty_printerZcurrent_objfiler   r   r   r	   <module>   s   s	