comparison codeOptimizer.py @ 1:a1224150b8f6

Cleanup and making code easier to read.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Sun, 16 Sep 2012 10:35:39 +0200
parents 28b636105ed6
children 10f1d7de9bc3
comparison
equal deleted inserted replaced
0:28b636105ed6 1:a1224150b8f6
1 #!/usr/bin/env python -O 1 #!/usr/bin/env python -O
2 2
3 import sys, string, os, subprocess 3 import sys
4 4
5 from Compilable import Compilable 5 from Compilable import Compilable
6 from DepGraph import DepGraph 6 from DepGraph import DepGraph
7 7
8 8
20 return False 20 return False
21 21
22 22
23 infiles = sys.argv[1:] 23 infiles = sys.argv[1:]
24 24
25 cppfiles = {} 25 files = {}
26 unknown = [] 26 unknown = []
27 27
28 flags = '-DHAS_BOOST -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_XML_LIB -DQT_SQL_LIB -O3 -Wall -I/opt/local/include -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include -F/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/lib -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtOpenGL -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtXml -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtSql -I/Users/bfg/projects/dedupe' 28 flags = '-DHAS_BOOST -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_XML_LIB -DQT_SQL_LIB -O3 -Wall -I/opt/local/include -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include -F/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/lib -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtOpenGL -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtXml -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtSql -I/Users/bfg/projects/dedupe'
29 29
30 for file in infiles: 30 for file in infiles:
31 if isHppfile(file) or isCppfile(file): 31 if isHppfile(file) or isCppfile(file):
32 c = Compilable(file) 32 c = Compilable(file)
33 c.setFlags(flags) 33 c.setFlags(flags)
34 cppfiles[file] = c 34 files[file] = c
35 else: 35 else:
36 unknown.append(file) 36 unknown.append(file)
37 37
38 if len(unknown) > 0: 38 if len(unknown) > 0:
39 str = ", " 39 str = ", "
40 raise SystemExit(str.join(unknown) + " are of unknown filetype") 40 raise SystemExit(str.join(unknown) + " are of unknown filetype")
41
42 files = cppfiles
43 41
44 depgraph = DepGraph() 42 depgraph = DepGraph()
45 43
46 for file in files: 44 for file in files:
47 depgraph.add(files[file]) 45 depgraph.add(files[file])
60 removable = file.removeRemovableIncludes() 58 removable = file.removeRemovableIncludes()
61 if removable: 59 if removable:
62 print 'Removable lines in ' + file.path 60 print 'Removable lines in ' + file.path
63 for r in removable: 61 for r in removable:
64 print str(r) + ' : ' + file.lines[r].rstrip() 62 print str(r) + ' : ' + file.lines[r].rstrip()
65 63
66 replacable = file.replaceIncludes() 64 replacable = file.replaceIncludes(dict.fromkeys(removable, '\n'))
67 if replacable: 65 if replacable:
68 print 'Replacable lines in ' + file.path 66 print 'Replacable lines in ' + file.path
69 for r in replacable: 67 for r in replacable:
70 print str(r) + ' : ' + file.lines[r].rstrip() 68 print str(r) + ' : ' + file.lines[r].rstrip()