Skip to content

Commit 1ff308e

Browse files
author
p12
committed
Transform/DDG: track the number of lines taken by the entries during debugging
1 parent 4c2d3e8 commit 1ff308e

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

index2ddg.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
if len(sys.argv) > 3:
4545
debug_ident = sys.argv[3]
4646

47+
# track the statistics of number of lines used by the entries
48+
debug_num_lines = [0 for i in range(40)]
49+
4750
index_file = sys.argv[1]
4851
output_file = sys.argv[2]
4952

@@ -161,14 +164,16 @@ def get_version(decls):
161164

162165
def build_abstract(decls, desc):
163166
line_limit = MAX_CODE_LINES
167+
global debug_num_lines
168+
num_lines = 0
164169

165170
limited = False
166171
all_code = ''
167172

168173
for i,(code,ver) in enumerate(decls):
169174
code = code.strip()
170175
code = '<pre><code>' + code + '</code></pre>'
171-
num_lines = code.count('\n') + 1
176+
code_num_lines = code.count('\n') + 1
172177

173178
# limit the number of code snippets to be included so that total number
174179
# of lines is less than MAX_CODE_LINES. The limit becomes active only
@@ -178,21 +183,41 @@ def build_abstract(decls, desc):
178183

179184
if not first:
180185
if last:
181-
if num_lines > line_limit:
186+
if code_num_lines > line_limit:
182187
limited = True
183188
break
184189
else:
185-
if num_lines > line_limit - 1:
190+
if code_num_lines > line_limit - 1:
186191
# -1 because we need to take into account
187192
# <more overloads omitted> message
188193
limited = True
189194
break
190195

191196
all_code += code
192-
line_limit -= num_lines
197+
num_lines += 1
198+
line_limit -= code_num_lines
193199

194200
if limited:
195201
all_code += '<pre><code> &lt;...&gt; </code></pre>'
202+
203+
204+
# count the number of lines used
205+
num_lines += all_code.count('\n')
206+
if len(desc) > 110:
207+
num_lines += 2
208+
else:
209+
num_lines += 1
210+
if limited:
211+
num_lines += 1
212+
213+
debug_num_lines[num_lines] += 1
214+
215+
if debug and num_lines >= 10:
216+
print("# error : large number of lines: ")
217+
print("# BEGIN ======")
218+
print(all_code + desc)
219+
print("# END ========")
220+
196221
return all_code + desc
197222

198223
if debug:
@@ -275,3 +300,9 @@ def build_abstract(decls, desc):
275300
if debug:
276301
line = '# error (' + str(err) + "): " + link + ": " + item_ident + "\n"
277302
out.write(line)
303+
304+
if debug:
305+
print('=============================')
306+
print('Numbers of lines used:')
307+
for i,l in enumerate(debug_num_lines):
308+
print(str(i) + ': ' + str(l) + ' line(s)')

0 commit comments

Comments
 (0)