
    2h`                     4   d Z ddlmZ ddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlmZ ddlmZ ej        d         dk    Zd	 Zej        d
             Z G d dej                  Zd Zd Zd.dZd Zd Zd/dZd Zd Zd Z d Z! G d dej"                  Z# G d de#          Z$d0dZ%d/dZ&	 	 	 d1dZ'	 	 d2dZ(d3d Z)d/d!Z*ddd e+            fd"Z,d/d#Z-ddd e+            fd$Z.	 	 d4d&Z/d' Z0d5d(Z1d) Z2d* Z3d+ Z4d, Z5d- Z6dS )6z4
Shared __main__ method functionality for emitters.
    )absolute_import)print_functionN   )ast)clad   c           
          | d |                      dt          |                      d          d                             |z   S )N./r   )findmax)filesuffixs     P/home/metal/girl-os-victor/victor-clad/tools/message-buffers/clad/emitterutil.pyget_included_filer   &   s:    73DIIcNNA 6 677786AA    c              #      K   | V  d S N )contexts    r   _disable_withr   )   s      
MMMMMr   c                   p     e Zd Z G d de          Zd fd	Z fdZd Zd Z fd	Z	d
 Z
d ZddZ xZS )IndentedTextIOWrapperc                        e Zd Zd Zd Zd ZdS )%IndentedTextIOWrapper.DepthWithHelperc                 "    || _         || _        d S r   )wrapperdepth_delta)selfr   r   s      r   __init__z.IndentedTextIOWrapper.DepthWithHelper.__init__0   s    "DL*Dr   c                     d S r   r   )r   s    r   	__enter__z/IndentedTextIOWrapper.DepthWithHelper.__enter__4   s    Dr   c                 :    | j         xj        | j        z  c_        d S r   )r   depthr   )r   typevalue	tracebacks       r   __exit__z.IndentedTextIOWrapper.DepthWithHelper.__exit__8   s!    L$"22r   N)__name__
__module____qualname__r    r"   r(   r   r   r   DepthWithHelperr   /   sA        	+ 	+ 	+	 	 		3 	3 	3 	3 	3r   r,   r   	c                     t          t          |                               d           || _        || _        d| _        || _        d S )N
newlineF)superr   r    pathr$   ended_on_newlinetab_character)r   r3   r$   r5   	__class__s       r   r    zIndentedTextIOWrapper.__init__;   sI    #T**33D3AAA	
 %*r   c                     ||                                   t          t          |                               |||           d S r   )_write_to_filer2   r   r(   )r   r%   r&   r'   r6   s       r   r(   zIndentedTextIOWrapper.__exit__B   sC    <!!!#T**33D%KKKKKr   c                     t           j                            |          rt          j        |d           t          rt          ||d          S t          |d                    |                    S )Ni  r/   r0   z{mode}b)mode)osr3   existschmod_py3openformat)r   filenamer:   s      r   
_open_filez IndentedTextIOWrapper._open_fileG   sh    7>>(## 	'HXv&&& 	?$5555)"2"2"2"="=>>>r   c                    | j         |                     | j         d          5 }|                    |                                            d d d            n# 1 swxY w Y   t          j                             | j                   rt	          j        | j         d           d S d S t          j                            |                                            d S )Nwim  )	r3   rB   writegetvaluer;   r<   r=   sysstdout)r   outputs     r   r8   z$IndentedTextIOWrapper._write_to_fileO   s    9 C00 .FT]]__---. . . . . . . . . . . . . . .w~~di(( ,F+++++, , JT]]__-----s   (AAAc                    |sd S | j         r| j        dk    rd| j        z  |z   }|d         dk    | _         | j        dk    r>d|d d         v r2|d d                             ddd| j        z  z             |d         z   }|                    d| j                  }t          st          |d          }t          t          |                               |           d S )Nr   r-   r/   utf8)	r4   r$   replacer5   r>   unicoder2   r   rE   )r   r&   r6   s     r   rE   zIndentedTextIOWrapper.writeX   s     	F  	.TZ!^^4:%-E!&rd!2 :>>deCRCj00#2#J&&tTD4:4E-EFFrREdD$677 	+E6**E#T**0077777r   c                 N    | xj         |z  c_         |                     | |          S )zfStarts indenting text and returns an object that unindents if this method is called in a 'with' block.r$   r,   )r   r   s     r   indentzIndentedTextIOWrapper.indentm   s(    

k!

##D+666r   c                 L    | j         }d| _         |                     | |           S )zpReduces indent to 0 temporarily and returns an object that reindents if this method is called in a 'with' block.r   rP   )r   	old_depths     r   reset_indentz"IndentedTextIOWrapper.reset_indentr   s(    J	
##D9*555r   c           	        	 |sdS t          d |D                       		fd|D             }t          | }d |D             }|D ]}|rt          |dd                   D ]H\  }}|                     |           |                     d||         t	          |          z
  z             I|                     |d                    |                     d           dS )ag  
        Takes in a list of sequences of strings, then writes them all to the buffer as lines,
        adding whitespace to keep each column aligned.

        extra_whitespace -- extra space to join the strings with (1 would mean a space inbetween)

        [('int', ' foo', ' = 5;'), ('float', ' bar;')] ->
        int   foo  = 5;
        float bar;
        Nc              3   4   K   | ]}t          |          V  d S r   len).0sequences     r   	<genexpr>zFIndentedTextIOWrapper.write_with_aligned_whitespace.<locals>.<genexpr>   s(      !F!FH#h--!F!F!F!F!F!Fr   c                 Z    g | ]'}t          |          d t          |          z
  z  z   (S )) )tuplerX   )rY   rZ   max_sequence_lengths     r   
<listcomp>zGIndentedTextIOWrapper.write_with_aligned_whitespace.<locals>.<listcomp>   s6    fffT\h%+>X+N"OOfffr   c                 @    g | ]}t          d  |D                       S )c              3   4   K   | ]}t          |          V  d S r   rW   )rY   pieces     r   r[   zQIndentedTextIOWrapper.write_with_aligned_whitespace.<locals>.<listcomp>.<genexpr>   s(      ??uE

??????r   )r   )rY   columns     r   r`   zGIndentedTextIOWrapper.write_with_aligned_whitespace.<locals>.<listcomp>   s/    VVVFC???????VVVr   rK    r/   )r   zip	enumeraterE   rX   )
r   linesextra_whitespacerowscolumnsspace_per_columnrZ   irc   r_   s
            @r   write_with_aligned_whitespacez3IndentedTextIOWrapper.write_with_aligned_whitespacex   s     	F "!F!F!F!F!FFFffff`efff t*VVgVVV 	! 	!H ! )(3B3- 8 8 I IHAuJJu%%%JJs&6q&9CJJ&FGHHHH

8B<(((

4   	! 	!r   )r   r-   )r   )r)   r*   r+   objectr,   r    r(   rB   r8   rE   rQ   rT   rn   __classcell__r6   s   @r   r   r   -   s        
3 
3 
3 
3 
3& 
3 
3 
3+ + + + + +L L L L L
? ? ?. . .8 8 8 8 8*7 7 7
6 6 6! ! ! ! ! ! ! !r   r   c                     | j         dk    r:t          j                            | j        | j                   }t          |d          S t          t          j                  S )N-r)	
input_filer;   r3   joininput_directoryr?   r   rG   stdin)options	real_paths     r   
_get_inputr{      sK    S  GLL!8':LMM	Is###SY'''r   c                 |    | j         r| j         dk    rdS | j         S | j        dk    rt          | j        |          S dS )Nrs   )output_fileru   r   )ry   r   s     r   get_output_filer~      sO     #%%3&&		s	"	" !3V<<<sr   Fc                    | dk    ru|dk    rot           j                            | |          }t          t           j                            |                     |rt          |d          S t          |d          S t          d d          S )Nrs   wb  )r5   )r;   r3   rv   mkdir_pdirnamer?   r   )output_directoryr}   binaryrz   s       r   
get_outputr      s    3;##5#5GLL!1;??		**+++ 	H	4(((($GGGG$T>>>>r   c                     t           j                            |           s,t          | d          5  	 ddd           dS # 1 swxY w Y   dS dS )zNCreates an empty file unless it already exists, in which case it does nothing.aN)r;   r3   r<   r?   r3   s    r   create_filer      s    7>>$ $__ 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   ?AAc                     	 t          j        |            d S # t          $ rA}|j        t          j        k    r t           j                            |           rn Y d }~d S d }~ww xY wr   )r;   makedirsOSErrorerrnoEEXISTr3   isdir)r3   excs     r   r   r      ss    
D   9$$t)<)<$ DDDDDs    
A#6AA#c                 6   |r<t           j                            t           j                            |                    }t           j                            t           j                            |                     } t           j                            | |          S )z:Does os.path.relpath, first resolving to an absolute path.)r;   r3   normpathabspathrelpath)r3   starts     r   make_path_relativer      sf     9  !7!7887BGOOD1122D7??4'''r   c                     t           j                            |           } t           j                            |           r| S |                     dd          S )z?Makes a path as portable if possible. Can't fix absolute paths.\r   )r;   r3   r   isabsrM   r   s    r   make_path_portabler      sF    7D!!D	w}}T <<c"""r   c                    | j         dk    r| j         }nd}t          t          j                  }d                    d |D                       }d                    |          d                    |          d	                    |
          gS )Nrs   z<stdin>re   c              3   >   K   | ]}t          j        |          V  d S r   )shlexquote)rY   args     r   r[   z$get_comment_lines.<locals>.<genexpr>   s,      AAEK,,AAAAAAr   z-Autogenerated {language} message buffer code.languagezSource: {source})sourcez!Full command line: {command_line})command_line)ru   _convert_abspaths_to_relpathsrG   argvrv   r@   )ry   r   r   rel_argsr   s        r   get_comment_linesr      s    S  #,SX66H88AAAAAAAL7>>>QQ!!!00+222MM r   c                 ~    t          j        dd|           } t          j        dd|                                           S )Nz([A-Za-z0-9])([A-Z][a-z]+)z\1_\2z([a-z0-9])([A-Z]))resublower)
identifiers    r    convert_camelcase_to_underscoresr      s7    4h
KKJ6%x<<BBDDDr   c                    | }t          j        dd|          }|                    d          }t          j        dd|          }t          |                                          }|pd}d                    |          }|S )	z(Creates a C-style macro inclusion guard.z[^A-Za-z0-9_./-]r]   z./-z[./-]_r   z__{guard}__)guard)r   r   stripr   upperr@   )r}   r   s     r   c_inclusion_guardr      s|    EF%r511EKKEF7C''E,U3399;;EOVE  u --ELr   c                   2     e Zd ZdZ fdZ fdZd Z xZS )SimpleArgumentParserat  
    The bare-minimum arguments for parsing. No output arguments.

    Calculates the following arguments and metavalues:
    input_file -- the filename of the file to read from (made portable)
    input_directory -- the directory to resolve includes from
    debug_yacc -- turn on yacc debug

    You may add your own arguments like a normal argparse.ArgumentParser.
    c           	           t          t          |           j        |i | |                     ddd           |                     ddddd	
           |                     ddddddd           |                     ddt          d           d S )Nru   z
input-filezThe .clad file to parse.metavarhelpz-Cz--input-directoryz./dirzThe input prefix directory.defaultr   r   z-Iz--include-directoryr   *include_directoriesz=Additional directories in which to search for included files.)r   r   nargsdestr   z--namespaceemitter_namespacez?Global namespace prefixed in front of all specified namespaces.)r   r%   r   )r2   r   r    add_argumentstr)r   argskwargsr6   s      r   r    zSimpleArgumentParser.__init__   s    2"D))2DCFCCC,+ 	 	- 	- 	-$ 3T5. 	 	0 	0 	0$ 5r51P 	 	R 	R 	R 	-1D3R 	 	T 	T 	T 	T 	Tr   c                     |                      dddd            t          t          |           j        |i |\  }}|                     |           ||fS )Nz-dz--debug-yacc
store_truezTurn on yacc debug.)actionr   )r   r2   r   parse_known_argspostprocess)r   r   r   r   r6   s       r   r   z%SimpleArgumentParser.parse_known_args  sq    $|& 	 	( 	( 	( HU/66GXQWXX
dTzr   c                 8    t          |j                  |_        d S r   )r   ru   )r   r   s     r   r   z SimpleArgumentParser.postprocess  s    ,T_==r   )r)   r*   r+   __doc__r    r   r   rp   rq   s   @r   r   r      so        	 	
T 
T 
T 
T 
T    > > > > > > >r   r   c                   .     e Zd ZdZd fd	Z fdZ xZS )StandardArgumentParserz
    An argparse.ArgumentParser used to parse arguments supported in every language.

    Calculates the additional arguments and metavalues:
    output_directory -- the directory to output to
    output_file (if permitted) -- the file to output to
    Fc           	         d                     |          } t          t          |           j        |d|i| || _        |rp|                                 }|                    ddddd                     |          	           |                    d
dd                     |                     d S |                     ddddd                     |          	           d S )Nz+Generate {language} code from a .clad file.r   descriptionz-oz--output-directoryrs   r   z/The directory to output the {language} file to.r   z--output-filer   z.The file path to write the {language} file to.r   z2The directory to output the {language} file(s) to.)r@   r2   r   r    _allow_override_outputadd_mutually_exclusive_groupr   )r   r   allow_override_outputr   r   r   groupr6   s          r   r    zStandardArgumentParser.__init__  s5   CJJT\J]]4$d++4t^^W]^^^&;#  	e5577Et%93PUFMMW_M``  b b bELLV^L__  a a a a a d$8#uIPPZbPcc  e e e e er   c                     t          t          |                               |           | j        r!|j        rt          j                    |_        d S d |_        d S r   )r2   r   r   r   r}   r;   getcwdr   )r   r   r6   s     r   r   z"StandardArgumentParser.postprocess+  sY    $d++77===& 	$4+; 	$$&IKKD!!!#Dr   F)r)   r*   r+   r   r    r   rp   rq   s   @r   r   r     sf         e e e e e e$ $ $ $ $ $ $ $ $r   r   c                 f   t          |           5 }| j        g}|                    | j                   t	          j        || j        |          }|                                }	 |                    || j	        | j        |          }nZ# t          j
        $ rH}|j        d         }	|j        d         }
t          |
d                    |	                     Y d}~nd}~ww xY w| j        r/t          j        | j                  }|                    |           |cddd           S # 1 swxY w Y   dS )	zParses a clad input file.)yacc_optimize
yacc_debuginput_directories)rA   	directory
debuglevelr   r   zSyntax Error: {msg})msgN)
wrapper_ns)r{   rw   extendr   r   
CLADParser
debug_yaccreadparseru   
ParseErrorr   exit_at_coordr@   	namespacer   ASTNamespaceWrappervisit)ry   r   r   inputr   clad_parsertexttreeer   coordnsws               r   r   r   2  s   	G		 $45  !<===oM)=NP P Pzz||	H$$T +!1% % ' 'DD  	H 	H 	H&)CF1IE%!6!=!=#!=!F!FGGGGGGGG	H  	)W5FGGGCIIdOOO+                 s<   AD&$#BD&C>CD&C:D&&D*-D*c           
         |r>t           j                            |           t           j                            d           | t          j        k    rt           j                            d           | r	| j        s#|!t           j                            d           n| j        st           j                            d           | j        wt           j                            d                    | j                             | j        8t           j                            d                    | j        	                     t           j                            d           nt           j                            | j                   | j        wt           j                            d                    | j                             | j        8t           j                            d                    | j        	                     t           j                            d
           t          j
                            | j        | j                  }| j        t          j
                            |          rt          |d          5 }t          |          D ]\  }}|dz   }|| j        dz   k    r n|| j        dz
  k    rvt           j                            d                    t!          |                              dd          |                    d          || j        k    rdnd                     ddd           n# 1 swxY w Y   t          j        d           dS )z'Exits, specifying a coord as the cause.r/   z<located at builtin value>
Nz<unknown location>
z<unknown file>z line {line})linez col {column})rd   z:
rt   r   r   z{spacer}{line_number} {line}
re   z>>r   )line_numberr   spacer)rG   stderrrE   r   builtin_coordr   linenor@   rd   r;   r3   rv   r   r<   r?   rg   r   rjustrstripexit)r   
error_textr   real_file_pathdebug_inputrm   r   s          r   r   r   K  s9    
$$$
!!!
7888 U
 Ut|
/0000Z U
)***<#J^222EEFFF|'
  !7!7u|!7!L!LMMM
 	
$$$<#J^222EEFFF|'
  !7!7u|!7!L!LMMM
eouzBB<#)G)G#nc** 	Uk(55 U UGAt"#a%K"U\A%555$q(888
(()I)P)P(+K(8(8(>(>q#(F(F!%T!2!2,75<,G,GDDT *Q *T *T U U U	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U HQKKKKKs   B/L==MMc	           
      >   t          | |          }	|r|	                    ddd           |	                                }
|r|
j        t	          |
          t          |
          }t          |
|           }fd}t          |
j        |||||||           dS )a  
    Entry point for a simple C-like language.

    language -- C, C++, C#
    extension -- .h, .cs
    emitter_types -- a list of emitters to have visit the ast
    use_inclusion_guards -- put inclusion guards around the header file
    system_headers -- a list of headers: #include <foo>
    local_headers -- a list of headers: #include "foo"
    usings -- a list of namespaces: using foo;
    z--header-output-extensionextzOThe extension to use for header files. (Helps work around a CMake Xcode issue.)r   c                 R    D ]"} ||                                           #d S )N)include_extensionr   )rI   emitter_typeemitter_types	extensionr   s     r   output_callbackzc_main.<locals>.output_callback  sF    ) 	J 	JLL9===CCDIIII	J 	Jr   N)	r   r   
parse_argsheader_output_extensionr   r~   r   write_c_filer   )r   r  r  allow_custom_extensionr   use_inclusion_guardssystem_headerslocal_headersusingsoption_parserry   main_output_filecomment_linesr  r   s    ``           @r   c_mainr  v  s      +85JKKM d""#>	[`b 	# 	d 	d 	d&&((G 43	>>D&w	::%gx88MJ J J J J J J )+;_+v/ / / / /r   c                    t          | |          5 }|rG|                    d                    d |D                                  |                    d           |rat          |          }	|                    d                    |	                     |                    d                    |	                     |rPt          |          D ]+}
|                    d                    |
                     ,|                    d           |rPt          |          D ]+}
|                    d	                    |
                     ,|                    d           |rPt          |          D ]+}|                    d
                    |                     ,|                    d            ||           |r)|                    d                    |	                     d d d            d S # 1 swxY w Y   d S )Nr/   c              3   @   K   | ]}d                      |          V  dS z// {0}Nr@   rY   r   s     r   r[   zwrite_c_file.<locals>.<genexpr>  .      "S"ST8??4#8#8"S"S"S"S"S"Sr   

z#ifndef {inclusion_guard}
)inclusion_guardz#define {inclusion_guard}

z#include <{header}>
)headerz#include "{header}"
zusing {using};
)usingz#endif // {inclusion_guard}
)r   rE   rv   r   r@   sorted)r   r}   r  r  r  r  r  r  rI   r  r  r  s               r   r
  r
    sy    
$k	2	2 bf 	!LL"S"S]"S"S"SSSTTTLL    	b/<<OLL6==o=^^___LL8??P_?``aaa 	 00 L L4;;6;JJKKKKLL 	 // L L4;;6;JJKKKKLL 	 E E/66U6CCDDDDLL 	bLL8??P_?``aaa5b b b b b b b b b b b b b b b b b bs   GG77G;>G;c           
      4    t          | |||dd d |           d S )NF)r  r  r  r  )r
  )r   r}   r  r  r  s        r   write_cs_filer     s<    !;E4@ @ @ @ @ @r   c                     t          |          t          |d          }t          |d          } fd}t                      }| ||                                         t          |j        ||||j        |           d S )Nz.goGoc                 D     |                                           d S r   r  rI   emitterr   s    r   r  z go_main.<locals>.output_callback  %    d#####r   r  package
properties)r   r~   r   dictr   write_go_filer   r(  r%  ry   scannerr  r  r  r)  r   s   `      @r   go_mainr.        >>D&w66%gt44M$ $ $ $ $ $ J
!!$''''*,<o#W_U U U U U Ur   c                    g }|                     dd          r|                    d           |                     dd          r|                    d           |                     dd          r|                    d           |                     dd          r|                    d	           |                     d
d          r|                    d           |d k    ryt          j                            | |          }t          j                            t          j                            t          j                            |                              }t          | |          5 }	|rG|		                    d                    d |D                                  |		                    d           |		                    d
                    |                     |		                    d           d |D             }|		                    d                    |                     |		                    d            ||	           d d d            d S # 1 swxY w Y   d S )N	use_bytesTbytes
use_binaryencoding/binary
use_errorserrorsuse_clad	anki/claduse_fmtfmtr/   c              3   @   K   | ]}d                      |          V  dS r  r  r  s     r   r[   z write_go_file.<locals>.<genexpr>  r  r   r  zpackage {}

z	import (
c                     g | ]
}d |z   dz   S )z	"z"
r   )rY   xs     r   r`   z!write_go_file.<locals>.<listcomp>  s!    888!EAI%888r   r]   z)

getappendr;   r3   rv   basenamer   r   r   rE   r@   
r   r}   r  r  r(  importsr)  includes	full_pathrI   s
             r   r+  r+    sc    H~~k4(( !   ~~lD)) +)***~~lD)) "!!!~~j$'' %$$$~~i&& $GLL!1;??	'""27#3#3BGOOI4N4N#O#OPP	$k	2	2 
 f 	!LL"S"S]"S"S"SSSTTTLL   %,,W55666\"""88x888RWWX&&'''W
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
 s   )CIIIc                     t          |          t          |d          }t          |d          } fd}t                      }| ||                                         t          |j        ||||j        |           d S )Nz.jsJSc                 D     |                                           d S r   r  r$  s    r   r  z js_main.<locals>.output_callback  r&  r   r'  )r   r~   r   r*  r   write_js_filer   r(  r,  s   `      @r   js_mainrJ    r/  r   c                     g }|                     dd          r|                    d           |                     dd          r|                    d           |                     dd          r|                    d           |                     dd          r|                    d	           |                     d
d          r|                    d           |d k    ryt          j                            | |          }t          j                            t          j                            t          j                            |                              }t          | |          5 }	|rG|		                    d                    d |D                                  |		                    d           |		                    d
                    |                      ||	           d d d            d S # 1 swxY w Y   d S )Nr1  Tr2  r3  r4  r5  r6  r7  r8  r9  r:  r/   c              3   @   K   | ]}d                      |          V  dS r  r  r  s     r   r[   z write_js_file.<locals>.<genexpr>  r  r   r  z<const {{ Clad, CladBuffer }} = require('./cladConfig.js');

r>  rB  s
             r   rI  rI    s    H~~k4(( !   ~~lD)) +)***~~lD)) "!!!~~j$'' %$$$~~i&& $GLL!1;??	'""27#3#3BGOOI4N4N#O#OPP	$k	2	2  f 	!LL"S"S]"S"S"SSSTTTLL   W^^_fgghhh                                   s   )A=G33G7:G7r   r   c                 Z   t          | |          5 }|r\|                    d           |                    d                    d |D                                  |                    d           |rC|D ]+}|                    d                    |                     ,|                    d           |t          j        k    r| g|pg z   }|r/t          |t          j                            | |          |           |r|D ]p}	t          |	t                    r0|	\  }
}|                    d                    |
|                     G|                    d	                    |	
                     q|                    d            ||           d d d            d S # 1 swxY w Y   d S )Nz"""
r/   c              3   @   K   | ]}d                      |          V  dS )z{0}Nr  r  s     r   r[   z$write_python_file.<locals>.<genexpr>  s.      "P"P$5<<#5#5"P"P"P"P"P"Pr   z
"""

z!from __future__ import {feature}
)featurezfrom {source} import {target}
)r   targetzimport {module}
)module)r   rE   rv   r@   rG   rH   _write_python_modify_pathr;   r3   
isinstancer^   )r   r}   r  r  future_featuresadditional_pathsimport_modulesrI   rP  rR  r   rQ  s               r   write_python_filerX    s%    
$k	2	2  f 	&LL!!!LL"P"P-"P"P"PPPQQQLL%%% 	* [ [AHHQXHYYZZZZLLSZ 015E5KL 	W%%5{CCEUW W W  	( L Lfe,, L%+NFFLL!B!I!IQW`f!I!g!ghhhhLL!4!;!;6!;!J!JKKKKLL5                                   s   FF  F$'F$c                 X      fdt          dt                     d          D             S )Nc                 F    g | ]}t          ||d z            d          S )      )int)rY   rm   strings     r   r`   z%decode_hex_string.<locals>.<listcomp>7  s/    EEEqCq1ur""EEEr   r   r[  )rangerX   r^  s   `r   decode_hex_stringra  6  s/    EEEEE!S[[!,D,DEEEEr   c                 n   |s|                      d           d S |dz   }|                      d           |D ]Q}|                      d|z             |                      t          |                     |                      d           R|                      d|z             |                      d           d S )Nz[]r   z[
r-   z,
])rE   repr)rI   pathsr$   inner_depthr3   s        r   _pretty_print_listrg  9  s     
TaiU 	  	 DLL+,,,LLd$$$LLTE\"""Sr   c                 D   | t           j        k    r.t          j                            |          fd|D             }nd |D             }|                     t          j        d                     t          | |d           |                     d           | t           j        k    r|                     d           |                     d           | t           j        k    r|                     d	           |                     t          j        d
                     d S )Nc                 0    g | ]}t          |          S r   )r   )rY   r3   currentpaths     r   r`   z-_write_python_modify_path.<locals>.<listcomp>J  s$    ___d.t[AA___r   c                     g | ]>}t           j                            t           j                            |                    ?S r   )r;   r3   r   r   )rY   r3   s     r   r`   z-_write_python_modify_path.<locals>.<listcomp>L  s6    aaaBG,,RW__T-B-BCCaaar   zU        def _modify_path():
        	import inspect, os, sys
        	search_paths = r   )r$   r/   zY	currentpath = os.path.abspath(os.path.dirname(inspect.getfile(inspect.currentframe())))
z"	for search_path in search_paths:
zl		search_path = os.path.normpath(os.path.abspath(os.path.realpath(os.path.join(currentpath, search_path))))
zu        		if search_path not in sys.path:
        			sys.path.insert(0, search_path)
        _modify_path()

        )	rG   rH   r;   r3   r   rE   textwrapdedentrg  )rI   r}   rV  rj  s      @r   rS  rS  F  s;   gook22____N^___aaP`aaa
LL "      v/q9999
LLrsss
LL7888  G  	H  	H  	H
LL "       r   c                     |                                  D ]_}t          |d          rMt          |j        d          r8|j        j        }t          |d          r
|j        s dS t          |          s dS `dS )zRecursively traverses all members of an ast.Node and returns true if all of them have a default
       constructor. Returns false if any members don't have a default constructor. NOTE: does not check 'node'
       itself
    r%   	type_decldefault_constructorFT)membershasattrr%   ro  rp  (_do_all_members_have_default_constructor)nodememberchilds      r   rs  rs  d  s     ,,..  66"" 	wv{K'H'H 	K)E 566 .uu;EBB uu4r   c                 |    t          t          j        d|                     }d|v r|                    d           |S )z@Splits the string on the characters '*', '/', '+', '-', ' '
    z[*+/ -]r]   )setr   splitremove)r^  ry  s     r   _split_string_on_operatorsr{  u  s=     F++,,E	U{{RLr   c                 X    | r'| d d                                          | dd          z   ndS )Nr   r]   )r   r`  s    r   _lower_first_char_of_stringr}  }  s3    .4<6"1":qrr
**"<r   c                     d | D             }t           j                            t           j                            |                    fd| D             }|S )zReturns a list of args with absolute paths replaced by relative paths
       using the longest common path. Absolute paths are detected using os.path.isabs(path).
       Non-path and relative-path args are not modified.
    c                 P    g | ]#}t           j                            |          !|$S r   )r;   r3   r   )rY   r   s     r   r`   z1_convert_abspaths_to_relpaths.<locals>.<listcomp>  s+    333Aq!1!13a333r   c                     g | ]C}t           j                            |          r t           j                            |          n|DS r   )r;   r3   r   r   )rY   r   lcps     r   r`   z1_convert_abspaths_to_relpaths.<locals>.<listcomp>  sA    QQQq27==+;+;B3'''QQQr   )r;   r3   r   commonprefix)r   re  r   r  s      @r   r   r     s[    
 43333E '//"'..u55
6
6CQQQQDQQQHOr   r   r   )Fr   )FFFNNN)NFNNN)NN)NrM  NN)r   )7r   
__future__r   r   argparse
contextlibr   inspectior;   r   r   rG   rl  r]   r   r   version_infor>   r   contextmanagerr   StringIOr   r{   r~   r   r   r   r   r   r   r   r   ArgumentParserr   r   r   r   r  r
  r   r.  r*  r+  rJ  rI  rX  ra  rg  rS  rs  r{  r}  r   r   r   r   <module>r     s    ' & & & & & % % % % % %        				 				  				 



             
aB B B   g! g! g! g! g!BK g! g! g!R( ( (	 	 	? ? ? ?    ( ( ( (# # #  E E E	 	 	"> "> "> "> ">82 "> "> ">H$ $ $ $ $1 $ $ $>   2( ( ( (X =B"8<"/ "/ "/ "/J 278<b b b b@@ @ @ @U U U U QU^bTTVV       <U U U U QU^bTTVV       6 -R.2       @F F F     <  "  = = =
 
 
 
 
r   