diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-06-12 14:48:04 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-06-12 14:48:04 +0300 |
commit | ba2a11d5be57d0b0bdfa67f4259060e6710865ac (patch) | |
tree | dfcf6ba7f8844d6b88e3840b02d11606ba0c36da | |
parent | ffd5dfd81458a1eb67c40f30aa6d9022a88f8269 (diff) | |
download | deheader-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-x | deheader | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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." |