reduce: cleanups
This commit is contained in:
parent
1dac1664be
commit
ef1dd89d72
|
@ -156,48 +156,10 @@ def combinelines(filedata):
|
||||||
fd2 = filedata[line+1].lstrip()
|
fd2 = filedata[line+1].lstrip()
|
||||||
replaceandrun2('combine lines', filedata, line, fd1+fd2, '')
|
replaceandrun2('combine lines', filedata, line, fd1+fd2, '')
|
||||||
|
|
||||||
def removeline(filedata):
|
def removedirectives(filedata):
|
||||||
stmt = True
|
|
||||||
for i in range(len(filedata)):
|
for i in range(len(filedata)):
|
||||||
line = filedata[i]
|
if filedata[i].lstrip().startswith('#'):
|
||||||
strippedline = line.strip()
|
replaceandrun('remove preprocessor directive', filedata, i, '')
|
||||||
|
|
||||||
if len(strippedline) == 0:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if stmt and strippedline[-1]==';' and checkpar(line) and line.find('{')<0 and line.find('}')<0:
|
|
||||||
replaceandrun('remove line', filedata, i, '')
|
|
||||||
|
|
||||||
elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1:
|
|
||||||
replaceandrun('remove line', filedata, i, '')
|
|
||||||
|
|
||||||
if ';{}'.find(strippedline[-1]) >= 0:
|
|
||||||
stmt = True
|
|
||||||
else:
|
|
||||||
stmt = False
|
|
||||||
|
|
||||||
|
|
||||||
def removeincludes(filedata):
|
|
||||||
for i in range(len(filedata)):
|
|
||||||
if filedata[i].startswith('#include '):
|
|
||||||
replaceandrun('remove #include', filedata, i, '')
|
|
||||||
|
|
||||||
def removeemptyblocks(filedata):
|
|
||||||
if len(filedata) < 3:
|
|
||||||
return
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
while i < len(filedata):
|
|
||||||
if filedata[i].strip() == '':
|
|
||||||
filedata.pop(i)
|
|
||||||
else:
|
|
||||||
i = i + 1
|
|
||||||
|
|
||||||
for i in range(len(filedata)-1):
|
|
||||||
fd1 = filedata[i].rstrip()
|
|
||||||
fd2 = filedata[i+1].strip()
|
|
||||||
if checkpar(fd1) and fd1.endswith('{') and fd2 == '}':
|
|
||||||
replaceandrun2('remove block', filedata, i, '', '')
|
|
||||||
|
|
||||||
def removeblocks(filedata):
|
def removeblocks(filedata):
|
||||||
if len(filedata) < 3:
|
if len(filedata) < 3:
|
||||||
|
@ -235,13 +197,8 @@ def removeblocks(filedata):
|
||||||
|
|
||||||
return filedata
|
return filedata
|
||||||
|
|
||||||
|
def removeline(filedata):
|
||||||
def removenamespaces(filedata):
|
|
||||||
if len(filedata) < 3:
|
|
||||||
return filedata
|
|
||||||
|
|
||||||
stmt = True
|
stmt = True
|
||||||
|
|
||||||
for i in range(len(filedata)):
|
for i in range(len(filedata)):
|
||||||
line = filedata[i]
|
line = filedata[i]
|
||||||
strippedline = line.strip()
|
strippedline = line.strip()
|
||||||
|
@ -249,32 +206,17 @@ def removenamespaces(filedata):
|
||||||
if len(strippedline) == 0:
|
if len(strippedline) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
stmt1 = stmt
|
if stmt and strippedline[-1]==';' and checkpar(line) and line.find('{')<0 and line.find('}')<0:
|
||||||
|
replaceandrun('remove line', filedata, i, '')
|
||||||
|
|
||||||
|
elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1:
|
||||||
|
replaceandrun('remove line', filedata, i, '')
|
||||||
|
|
||||||
if ';{}'.find(strippedline[-1]) >= 0:
|
if ';{}'.find(strippedline[-1]) >= 0:
|
||||||
stmt = True
|
stmt = True
|
||||||
else:
|
else:
|
||||||
stmt = False
|
stmt = False
|
||||||
|
|
||||||
if stmt1 == False:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if strippedline.find('}') < 0 and strippedline.find('{') == len(strippedline)-1:
|
|
||||||
i2 = i + 1
|
|
||||||
indent = 1
|
|
||||||
while i2 < len(filedata) and indent > 0:
|
|
||||||
#print(str(i2)+':'+str(level)+':'+filedata[i2])
|
|
||||||
for c in filedata[i2]:
|
|
||||||
if c == '}':
|
|
||||||
indent = indent - 1
|
|
||||||
if indent <= 0:
|
|
||||||
break
|
|
||||||
elif c == '{':
|
|
||||||
indent = indent + 1
|
|
||||||
i2 = i2 + 1
|
|
||||||
if indent == 0 and (filedata[i2-1].strip().endswith('}') or filedata[i2-1].strip().endswith('};')):
|
|
||||||
#print(str(i)+';'+str(i2))
|
|
||||||
filedata = clearandrun('remove codeblock', filedata, i, i2-1)
|
|
||||||
return filedata
|
|
||||||
|
|
||||||
# reduce..
|
# reduce..
|
||||||
print('Make sure error can be reproduced...')
|
print('Make sure error can be reproduced...')
|
||||||
|
@ -294,11 +236,8 @@ while True:
|
||||||
print('remove comments...')
|
print('remove comments...')
|
||||||
removecomments(filedata)
|
removecomments(filedata)
|
||||||
|
|
||||||
print('remove includes...')
|
print('remove preprocessor directives...')
|
||||||
removeincludes(filedata)
|
removedirectives(filedata)
|
||||||
|
|
||||||
print('remove empty blocks...')
|
|
||||||
removeemptyblocks(filedata)
|
|
||||||
|
|
||||||
print('remove blocks...')
|
print('remove blocks...')
|
||||||
filedata = removeblocks(filedata)
|
filedata = removeblocks(filedata)
|
||||||
|
@ -306,9 +245,6 @@ while True:
|
||||||
print('combine lines..')
|
print('combine lines..')
|
||||||
combinelines(filedata)
|
combinelines(filedata)
|
||||||
|
|
||||||
print('remove namespaces...')
|
|
||||||
filedata = removenamespaces(filedata)
|
|
||||||
|
|
||||||
print('remove line...')
|
print('remove line...')
|
||||||
removeline(filedata)
|
removeline(filedata)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue