zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
U
O±d‰&ã@sâdZddgZddlZddlZddlZiZdZdd„Zdd    „Ze     d
¡Z
e     d ¡Z d d „Z e     d¡Z e     d¡Ze     d¡Ze     d¡Zdd„Ze     d¡Zdd„Zdd„Ze     dej¡Zdd„Zdd„Zdd„Zdd„Zed krÞeƒdS)!aX
takes templated file .xxx.src and produces .xxx file  where .xxx is
.i or .c or .h, using the following template rules
 
/**begin repeat  -- on a line by itself marks the start of a repeated code
                    segment
/**end repeat**/ -- on a line by itself marks it's end
 
After the /**begin repeat and before the */, all the named templates are placed
these should all have the same number of replacements
 
Repeat blocks can be nested, with each nested block labeled with its depth,
i.e.
/**begin repeat1
 *....
 */
/**end repeat1**/
 
When using nested loops, you can optionally exclude particular
combinations of the variables using (inside the comment portion of the inner loop):
 
 :exclude: var1=value1, var2=value2, ...
 
This will exclude the pattern where var1 is value1 and var2 is value2 when
the result is being generated.
 
 
In the main body each replace will use one entry from the list of named replacements
 
 Note that all #..# forms in a block must have the same number of
   comma-separated entries.
 
Example:
 
    An input file containing
 
        /**begin repeat
         * #a = 1,2,3#
         * #b = 1,2,3#
         */
 
        /**begin repeat1
         * #c = ted, jim#
         */
        @a@, @b@, @c@
        /**end repeat1**/
 
        /**end repeat**/
 
    produces
 
        line 1 "template.c.src"
 
        /*
         *********************************************************************
         **       This file was autogenerated from a template  DO NOT EDIT!!**
         **       Changes should be made to the original source (.src) file **
         *********************************************************************
         */
 
        #line 9
        1, 1, ted
 
        #line 9
        1, 1, jim
 
        #line 9
        2, 2, ted
 
        #line 9
        2, 2, jim
 
        #line 9
        3, 3, ted
 
        #line 9
        3, 3, jim
 
Ú process_strÚ process_fileéNaE
/*
 *****************************************************************************
 **       This file was autogenerated from a template  DO NOT EDIT!!!!      **
 **       Changes should be made to the original source (.src) file         **
 *****************************************************************************
 */
 
c CsÎ|dkrd}d}nd|}d|}d}d}g}| ||¡}|dkrDqÂ| d|¡}| d|¡}| ||¡}    | d|    ¡}
|| d||d    ¡7}| ||d    |    |
d    |f¡|| d|d    |
¡7}|
}q.| ¡|S)
    The returned line number is from the beginning of the string, starting
    at zero. Returns an empty list if no loops found.
 
    rz/**begin repeatz/**end repeat**/z/**begin repeat%dz/**end repeat%d**/éÿÿÿÿz*/Ú
é)ÚfindÚcountÚappendÚsort) ÚastrÚlevelZloopbegZloopendÚindÚlineZspanlistÚstartZstart2Zfini1Zfini2©rúTd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/distutils/conv_template.pyÚparse_structuregs*     rcCs(| d¡}| d¡}d |gt|ƒ¡S)Nréú,)ÚgroupÚjoinÚint)ÚobjZtorepZnumreprrrÚ
paren_repl‡s
 
rz\(([^)]*)\)\*(\d+)z([^*]+)\*(\d+)cCs0t t|¡}d dd„| d¡Dƒ¡}| d¡S)NrcSsg|]}t t| ¡¡‘qSr)ÚplainrepÚsubrÚstrip©Ú.0ÚxrrrÚ
<listcomp>•sÿz parse_values.<locals>.<listcomp>)ÚparenreprrrÚsplit)r rrrÚ parse_valuesŽs
 
ÿr#z\n\s*\*?z#\s*(\w*)\s*=([^#]*)#z (\w*)=(\w*)z    :exclude:cst d|¡}g}t |¡}d}|D]\}|d}t|dƒ}t|ƒ}|dkrP|}n ||krpd}t|||||fƒ‚| ||f¡q"g}    t     |¡D]D}
|
 
¡} |  d| d¡} || d| …} t  | ¡}|     t |ƒ¡qŽg}|dkrètdƒ‚t|ƒD] ‰‡fdd    „|Dƒ}| |¡qð|S)
a˜Find all named replacements in the header
 
    Returns a list of dictionaries, one for each loop iteration,
    where each key is a name to be substituted and the corresponding
    value is the replacement string.
 
    Also return a list of exclusions.  The exclusions are dictionaries
     of key value pairs. There can be more than one exclusion.
     [{'var1':'value1', 'var2', 'value2'[,...]}, ...]
 
    ÚNrrz.Mismatch in number of values, %d != %d
%s = %srzNo substitution variables foundcsi|]\}}||ˆ“qSrr)rÚnameÚvals©ÚirrÚ
<dictcomp>Îsz%parse_loop_header.<locals>.<dictcomp>)ÚstripastrÚnamed_reÚfindallr#ÚlenÚ
ValueErrorr    Ú
exclude_reÚfinditerÚspanrÚexclude_vars_reÚdictÚrange)ZloopheadÚnamesZrepsÚnsubÚrepr%r&ÚsizeÚmsgZexcludesrr1ÚendlineÚsubstrZex_namesZdlistÚtmprr'rÚparse_loop_headeržs8 
 
  r=z@(\w+)@c sVdˆ}‡‡fdd„}|g}t||ƒ}|r0d}|d}    |D]Ò}
|||
d…} ||
d|
d…} ||
d|
d…} |
d}ˆ|
d}| t || ¡¡z t| ƒ}Wn6tk
rà}zd    ||f}t|ƒ‚W5d}~XYnX|D]&}| ˆ¡t| ||    |ƒ}| |¡qæq<||d…}| t ||¡¡n| t ||¡¡| d
¡d      |¡S) Nz    #line %d
csF| d¡}z ˆ|}Wn*tk
r@dˆ|f}t|ƒd‚YnX|S)Nrz"line %d: no definition of key "%s")rÚKeyErrorr.)Úmatchr%Úvalr9©ÚenvrrrÚreplace×s
  zparse_string.<locals>.replacerrrééz line %d: %srr$)
rr    Ú
replace_rerr=r.ÚupdateÚ parse_stringÚextendr)r rBr rÚlinenorCÚcodeÚstructZoldendÚnewlevelrZprefÚheadÚtextÚnewlineZenvlistÚer9ZnewenvZnewcodeÚsuffrrArrHÓs8    
 
 
rHcCs$tg}| t|tddƒ¡d |¡S)Nrrr$)ÚheaderrIrHÚ global_namesr)r rKrrrrþsz7(\n|\A)#include\s*['\"](?P<name>[\w\d./\\]+[.]src)['\"]c    Cs–tj |¡}t|ƒx}g}|D]h}t |¡}|r|| d¡}tj |¡sTtj ||¡}tj     |¡rp| 
t |ƒ¡q†|  |¡q|  |¡qW5QRX|S)Nr%) ÚosÚpathÚdirnameÚopenÚinclude_src_rer?rÚisabsrÚisfilerIÚresolve_includesr    )ÚsourceÚdÚfidÚlinesrÚmÚfnrrrr\s 
 
 
   r\c
Cspt|ƒ}tj |¡ dd¡}ztd |¡ƒ}Wn4tk
rb}ztd||fƒd‚W5d}~XYnXd||fS)Nú\z\\r$zIn "%s" loop at %sz#line 1 "%s"
%s)r\rUrVÚnormcaserCrrr.)r]r`Z
sourcefilerKrQrrrrs$csLt| ¡ƒ}d}d‰|sHd ‡fdd„|Dƒ¡}||krBˆd7‰qd}q|S)NFrr$csg|]}|dˆ…‘qS)Nrr©Únrrr ,szunique_key.<locals>.<listcomp>T)ÚlistÚkeysr)ÚadictZallkeysÚdoneZnewkeyrrerÚ
unique_key#s 
rkc    
Cs°ztjd}Wn tk
r.tj}tj}Yn*Xt|dƒ}tj |¡\}}|}t|dƒ}|     ¡}z t
|ƒ}Wn4t k
r }zt d||fƒd‚W5d}~XYnX|  |¡dS)NrÚrÚwzIn %s loop at %s) ÚsysÚargvÚ
IndexErrorÚstdinÚstdoutrXrUrVÚsplitextÚreadrr.Úwrite)    Úfiler_ÚoutfileÚbaseÚextZnewnameZallstrÚwritestrrQrrrÚmain4s 
 
 $r{Ú__main__)Ú__doc__Ú__all__rUrnÚrerTrSrrÚcompiler!rr#r*r+r2r/r=rFrHrÚIrYr\rrkr{Ú__name__rrrrÚ<module>s:Pÿ  
 
 
 
 
 
4
+ÿ