Commit 4606e228 authored by Reiner Herrmann's avatar Reiner Herrmann

Merge tag 'upstream/1.2'

Upstream version 1.2
parents 15d2e822 fc77b853
......@@ -44,3 +44,6 @@ dist: deheader-$(VERS).tar.gz
release: deheader-$(VERS).tar.gz deheader.html
shipper version=$(VERS) | sh -e -x
refresh: deheader.html
shipper -N -w version=$(VERS) | sh -e -x
deheader project news
1.2 @ 2015-07-18
Notice preprocessor directives with whitespace after the hash-mark
1.1 @ 2015-01-26
Allow --version on the command line. Fix up the regression tests.
......
......@@ -3,25 +3,23 @@
Package: deheader
Description: find (optionally remove) unneeded includes in C or C++ sourcefiles.
Description: Find and optionally remove unneeded includes in C or C++ sourcefiles.
deheader analyzes C and C++ files to determine which header inclusions can be
removed while still allowing them to compile. This may result in substantial
improvements in compilation time, especially on large C++ projects; it also
sometimes exposes dependencies and cohesions of which developers were unaware.
XBS-Destinations: freecode
Homepage: http://www.catb.org/~esr/deheader
XBS-HTML-Target: index.html
Gitorious-URL: https://gitorious.org/deheader
XBS-Repository-URL: https://gitlab.com/esr/deheader
OpenHub-URL: https://www.ohloh.net/p/deheader/
XBS-Logo: deheader-logo.png
XBS-Freecode-Tags: development tools, optimization, C, C++
#XBS-Project-Tags: development tools, optimization, C, C++
XBS-VC-Tag-Template: %(version)s
......
......@@ -36,7 +36,7 @@ BATON_DEBUG = 1
PROGRESS_DEBUG = 2
COMMAND_DEBUG = 3
version = "1.1"
version = "1.2"
# Difference in various compiler implementations and OSes mean that for cross-
# platform compatibility you sometimes want to leave "unneeded" headers alone
......@@ -1269,26 +1269,25 @@ class InclusionMap:
seen = []
conditions = []
for line in open(sourcefile):
if line.startswith("#ifndef"):
conditions.append(line[7:].strip())
elif line.startswith("#ifdef"):
conditions.append(line[6:].strip())
elif line.startswith("#if"):
conditions.append(line[3:].strip())
elif line.startswith("#endif"):
c = match_preproc(["ifndef", "ifdef", "if"], line)
if c is not False:
conditions.append(c)
elif match_preproc("endif", line) is not False:
conditions.pop()
elif line.startswith("#include"):
if verbosity >= PROGRESS_DEBUG:
name = trim(line)
print "deheader: %s includes %s" % (sourcefile, name)
if ignore and ignore.search(line):
else:
f = match_preproc("include", line)
if f is not False:
if verbosity >= PROGRESS_DEBUG:
print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
continue
if not conditions or conditions == ["S_SPLINT_S"]:
includes.append(line)
elif verbose > 1:
print "deheader: ignoring %s (conditional inclusion)" % name
name = trim(f)
print "deheader: %s includes %s" % (sourcefile, name)
if ignore and ignore.search(line):
if verbosity >= PROGRESS_DEBUG:
print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
continue
if not conditions or conditions == ["S_SPLINT_S"]:
includes.append(line)
elif verbose > 1:
print "deheader: ignoring %s (conditional inclusion)" % name
for (r, c, h) in compiled:
if c.search(line):
if not set(h).issubset(set(seen)):
......@@ -1335,9 +1334,18 @@ class SaveForModification:
pass
os.rename(self.original, self.filename)
def match_preproc(directives, line):
if not isinstance(directives, list):
directives = [directives]
regexp = "|".join(["#\s*" + d for d in directives])
m = re.match(regexp, line)
if m:
return line[m.span()[1]:].strip()
return False
def trim(line):
"Get file reference from an #include, retaining <> if a system header."
trimmed = line[9:].strip()
trimmed = re.sub("^#\s*include", "", line).strip()
if trimmed[0] in '"':
return '"' + trimmed.split('"')[1] + '"'
elif trimmed[0] == '<':
......@@ -1453,10 +1461,11 @@ class Summary:
(len(self.filenames), len(self.includes), len(self.unneeded))
if __name__ == "__main__":
(options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:rvx:V",
(options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:qrvx:V",
["help", "ignore",
"maker", "quiet",
"remove", "verbose",
"version"])
"exclude", "version"])
maker = "make"
verbose = 0
quiet = False
......
deheader-logo.png

959 Bytes | W: | H:

deheader-logo.png

995 Bytes | W: | H:

deheader-logo.png
deheader-logo.png
deheader-logo.png
deheader-logo.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment