Skip to content

Commit ef1dd89

Browse files
committed
reduce: cleanups
1 parent 1dac166 commit ef1dd89

1 file changed

Lines changed: 12 additions & 76 deletions

File tree

tools/reduce.py

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -156,48 +156,10 @@ def combinelines(filedata):
156156
fd2 = filedata[line+1].lstrip()
157157
replaceandrun2('combine lines', filedata, line, fd1+fd2, '')
158158

159-
def removeline(filedata):
160-
stmt = True
161-
for i in range(len(filedata)):
162-
line = filedata[i]
163-
strippedline = line.strip()
164-
165-
if len(strippedline) == 0:
166-
continue
167-
168-
if stmt and strippedline[-1]==';' and checkpar(line) and line.find('{')<0 and line.find('}')<0:
169-
replaceandrun('remove line', filedata, i, '')
170-
171-
elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1:
172-
replaceandrun('remove line', filedata, i, '')
173-
174-
if ';{}'.find(strippedline[-1]) >= 0:
175-
stmt = True
176-
else:
177-
stmt = False
178-
179-
180-
def removeincludes(filedata):
159+
def removedirectives(filedata):
181160
for i in range(len(filedata)):
182-
if filedata[i].startswith('#include '):
183-
replaceandrun('remove #include', filedata, i, '')
184-
185-
def removeemptyblocks(filedata):
186-
if len(filedata) < 3:
187-
return
188-
189-
i = 0
190-
while i < len(filedata):
191-
if filedata[i].strip() == '':
192-
filedata.pop(i)
193-
else:
194-
i = i + 1
195-
196-
for i in range(len(filedata)-1):
197-
fd1 = filedata[i].rstrip()
198-
fd2 = filedata[i+1].strip()
199-
if checkpar(fd1) and fd1.endswith('{') and fd2 == '}':
200-
replaceandrun2('remove block', filedata, i, '', '')
161+
if filedata[i].lstrip().startswith('#'):
162+
replaceandrun('remove preprocessor directive', filedata, i, '')
201163

202164
def removeblocks(filedata):
203165
if len(filedata) < 3:
@@ -235,46 +197,26 @@ def removeblocks(filedata):
235197

236198
return filedata
237199

238-
239-
def removenamespaces(filedata):
240-
if len(filedata) < 3:
241-
return filedata
242-
200+
def removeline(filedata):
243201
stmt = True
244-
245202
for i in range(len(filedata)):
246203
line = filedata[i]
247204
strippedline = line.strip()
248205

249206
if len(strippedline) == 0:
250207
continue
251208

252-
stmt1 = stmt
209+
if stmt and strippedline[-1]==';' and checkpar(line) and line.find('{')<0 and line.find('}')<0:
210+
replaceandrun('remove line', filedata, i, '')
211+
212+
elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1:
213+
replaceandrun('remove line', filedata, i, '')
214+
253215
if ';{}'.find(strippedline[-1]) >= 0:
254216
stmt = True
255217
else:
256218
stmt = False
257219

258-
if stmt1 == False:
259-
continue
260-
261-
if strippedline.find('}') < 0 and strippedline.find('{') == len(strippedline)-1:
262-
i2 = i + 1
263-
indent = 1
264-
while i2 < len(filedata) and indent > 0:
265-
#print(str(i2)+':'+str(level)+':'+filedata[i2])
266-
for c in filedata[i2]:
267-
if c == '}':
268-
indent = indent - 1
269-
if indent <= 0:
270-
break
271-
elif c == '{':
272-
indent = indent + 1
273-
i2 = i2 + 1
274-
if indent == 0 and (filedata[i2-1].strip().endswith('}') or filedata[i2-1].strip().endswith('};')):
275-
#print(str(i)+';'+str(i2))
276-
filedata = clearandrun('remove codeblock', filedata, i, i2-1)
277-
return filedata
278220

279221
# reduce..
280222
print('Make sure error can be reproduced...')
@@ -294,21 +236,15 @@ def removenamespaces(filedata):
294236
print('remove comments...')
295237
removecomments(filedata)
296238

297-
print('remove includes...')
298-
removeincludes(filedata)
299-
300-
print('remove empty blocks...')
301-
removeemptyblocks(filedata)
239+
print('remove preprocessor directives...')
240+
removedirectives(filedata)
302241

303242
print('remove blocks...')
304243
filedata = removeblocks(filedata)
305244

306245
print('combine lines..')
307246
combinelines(filedata)
308247

309-
print('remove namespaces...')
310-
filedata = removenamespaces(filedata)
311-
312248
print('remove line...')
313249
removeline(filedata)
314250

0 commit comments

Comments
 (0)