summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-12 14:48:04 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-12 14:48:04 +0300
commitba2a11d5be57d0b0bdfa67f4259060e6710865ac (patch)
treedfcf6ba7f8844d6b88e3840b02d11606ba0c36da
parentffd5dfd81458a1eb67c40f30aa6d9022a88f8269 (diff)
downloaddeheader-ba2a11d5be57d0b0bdfa67f4259060e6710865ac.tar.gz
deheader-ba2a11d5be57d0b0bdfa67f4259060e6710865ac.tar.bz2
deheader-ba2a11d5be57d0b0bdfa67f4259060e6710865ac.tar.xz
deheader-ba2a11d5be57d0b0bdfa67f4259060e6710865ac.zip
Add partial support for check each preprocessor block is it enabled or not.
Missing only actual compilation for changed file.
-rwxr-xr-xdeheader18
1 files changed, 17 insertions, 1 deletions
diff --git a/deheader b/deheader
index 857ed0e..35e0ffb 100755
--- a/deheader
+++ b/deheader
@@ -1277,10 +1277,12 @@ class InclusionMap:
seen = []
conditions = []
allow_parse_includes = True
+ cnt = -1
for line in open(sourcefile):
+ cnt = cnt + 1
c = match_preproc(["ifndef", "ifdef", "if"], line)
if c is not False:
- allow_parse_includes = False
+ allow_parse_includes = self.check_block(sourcefile, cnt)
conditions.append((c, allow_parse_includes))
elif match_preproc("else", line) is not False:
allow_parse_includes = not allow_parse_includes
@@ -1325,6 +1327,20 @@ class InclusionMap:
def remember(self, sourcefile, header):
"Undo forgetting of a dependency."
self.depends_on[sourcefile].append(header)
+ def check_block(self, sourcefile, cnt):
+ try:
+ with open(sourcefile, "r") as r:
+ with open(sourcefile + ".tmp", "wt") as w:
+ cnt2 = 0
+ for line in r:
+ w.write(line)
+ if cnt2 == cnt:
+ w.write("#error deheader\n")
+ cnt2 = cnt2 + 1
+ # here need try compile this file
+ finally:
+ os.remove(sourcefile + ".tmp")
+ return False
class SaveForModification:
"Prepare a file to be temporarily modified, with guaranteed reversion."