summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-15 16:39:46 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-15 16:39:46 +0300
commitb259e9981e2ab22b8133f6837017323113525acb (patch)
treef830677b085ba9f89da51f50eac6c1383eccf1d2
parent92f29a5926d52efea128ffabcf9b45b58039fc63 (diff)
downloaddeheader-b259e9981e2ab22b8133f6837017323113525acb.tar.gz
deheader-b259e9981e2ab22b8133f6837017323113525acb.tar.bz2
deheader-b259e9981e2ab22b8133f6837017323113525acb.tar.xz
deheader-b259e9981e2ab22b8133f6837017323113525acb.zip
Fix false positive in preprocessor block #else, if this block will be not processed by compilation.
-rw-r--r--.gitlab-ci.yml9
-rwxr-xr-xdeheader16
-rw-r--r--tools/ci/samples/test14.cpp14
-rw-r--r--tools/ci/samples/test14.h6
4 files changed, 39 insertions, 6 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7bdbd1a..d62666f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -182,6 +182,15 @@ test12_h:
tags:
- docker
+test14_cpp:
+ stage: build
+ script:
+ - ./tools/ci/jobs/deheader.sh "g++-5" "" test14.cpp
+ - ./tools/ci/jobs/deheaderok.sh
+ image: debian:unstable
+ tags:
+ - docker
+
# reports
success:
diff --git a/deheader b/deheader
index dc4c5e8..cc04265 100755
--- a/deheader
+++ b/deheader
@@ -1286,14 +1286,13 @@ class InclusionMap:
allow_parse_includes = self.check_block(sourcefile, cnt, compiler, "", defines + " " + std, maker, verbosity, showerrs, subdir)
conditions.append((c, allow_parse_includes))
elif match_preproc("else", line) is not False:
- allow_parse_includes = not allow_parse_includes
+ if self.get_prev_flag(conditions) == True:
+ allow_parse_includes = not allow_parse_includes
+ else:
+ allow_parse_includes = False
elif match_preproc("endif", line) is not False:
conditions.pop()
- if len(conditions) == 0:
- allow_parse_includes = True
- else:
- sz = len(conditions)
- allow_parse_includes = conditions[sz - 1][1]
+ allow_parse_includes = self.get_prev_flag(conditions)
else:
f = match_preproc("include", line)
if f is not False:
@@ -1322,6 +1321,11 @@ class InclusionMap:
for ref in trimmedcount:
if trimmedcount[ref] > 1:
print("deheader: %s has more than one inclusion of %s" % (sourcefile, ref))
+ def get_prev_flag(self, conditions):
+ if len(conditions) == 0:
+ return True
+ else:
+ return conditions[len(conditions) - 1][1]
def forget(self, sourcefile, header):
"Forget a header dependency."
self.depends_on[sourcefile].remove(header)
diff --git a/tools/ci/samples/test14.cpp b/tools/ci/samples/test14.cpp
new file mode 100644
index 0000000..5632789
--- /dev/null
+++ b/tools/ci/samples/test14.cpp
@@ -0,0 +1,14 @@
+#include "test14.h"
+
+#ifdef QQQ
+#ifdef ZZZ
+#include <vector>
+#else
+#include <string>
+#endif
+#endif
+
+int function1()
+{
+ return 0;
+}
diff --git a/tools/ci/samples/test14.h b/tools/ci/samples/test14.h
new file mode 100644
index 0000000..c36b0ab
--- /dev/null
+++ b/tools/ci/samples/test14.h
@@ -0,0 +1,6 @@
+#ifndef TEST14
+#define TEST14
+
+int function1();
+
+#endif // TEST14 \ No newline at end of file