Mercurial > codeOptimizer
view codeOptimizer.py @ 2:10f1d7de9bc3
New module for reading configurations.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Sun, 16 Sep 2012 21:29:22 +0200 |
| parents | a1224150b8f6 |
| children | f65c2d63ab66 |
line wrap: on
line source
#!/usr/bin/env python -O import sys from Compilable import Compilable from DepGraph import DepGraph from Options import Config def isHppfile(name): if name.endswith(".hpp"): return True if name.endswith(".h"): return True return False def isCppfile(name): if name.endswith(".cpp"): return True return False try: options = Config(sys.argv[1]) except: print sys.argv[1] + ' is not a valid xml file' infiles = sys.argv[2:] files = {} unknown = [] for file in infiles: if isHppfile(file) or isCppfile(file): c = Compilable(file) c.setFlags(options.getCxxflags(file)) files[file] = c else: unknown.append(file) if len(unknown) > 0: str = ", " raise SystemExit(str.join(unknown) + " are of unknown filetype") depgraph = DepGraph() for file in files: depgraph.add(files[file]) for file in files: depgraph.addDependency(files[file], files[file].dependencies()) files = depgraph.directedGraph() for file in files: if not file.worksWithoutModifications(): print file.path raise SystemExit(file.path + " does not compile at all") for file in files: removable = file.removeRemovableIncludes() if removable: print 'Removable lines in ' + file.path for r in removable: print str(r) + ' : ' + file.lines[r].rstrip() replacable = file.replaceIncludes(dict.fromkeys(removable, '\n')) if replacable: print 'Replacable lines in ' + file.path for r in replacable: print str(r) + ' : ' + file.lines[r].rstrip()
