[gtk-doc] scan: fix handling of deprecated sections
- From: Stefan Sauer <stefkost src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-doc] scan: fix handling of deprecated sections
- Date: Sun, 27 Jan 2019 12:21:17 +0000 (UTC)
commit 324f98d616477c97523e79b0d029851315d93f5a
Author: Stefan Sauer <ensonic users sf net>
Date: Sun Jan 27 13:17:56 2019 +0100
scan: fix handling of deprecated sections
When adding a comment on the end of a deprecated section, we might start a
new one.
Fixes #72.
gtkdoc/scan.py | 7 +++----
tests/scan.py | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/gtkdoc/scan.py b/gtkdoc/scan.py
index 8ff4dbb..8cc7056 100644
--- a/gtkdoc/scan.py
+++ b/gtkdoc/scan.py
@@ -544,21 +544,20 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options):
elif re.search(r'^\s*#\sif', line):
if deprecated_conditional_nest >= 1:
deprecated_conditional_nest += 1
-
if ignore_conditional_nest > 0:
ignore_conditional_nest += 1
elif re.search(r'^\s*#endif', line):
if deprecated_conditional_nest >= 1:
deprecated_conditional_nest -= 1
-
if ignore_conditional_nest > 0:
ignore_conditional_nest -= 1
# If we find a line containing _DEPRECATED, we hope that this is
# attribute based deprecation and also treat this as a deprecation
- # guard, unless it's a macro definition.
+ # guard, unless it's a macro definition or the end of a deprecation
+ # section (#endif /* XXX_DEPRECATED */
if deprecated_conditional_nest == 0 and '_DEPRECATED' in line:
- m = re.search(r'^\s*#\s*(if*|define)', line)
+ m = re.search(r'^\s*#\s*(if*|define|endif)', line)
if not (m or in_declaration == 'enum'):
logging.info('Found deprecation annotation (decl: "%s"): "%s"',
in_declaration, line.strip())
diff --git a/tests/scan.py b/tests/scan.py
index 7a399b7..da00988 100755
--- a/tests/scan.py
+++ b/tests/scan.py
@@ -133,6 +133,41 @@ class ScanHeaderContent(ScanHeaderContentTestCase):
#endif""".splitlines(keepends=True))
self.assertNoDeclFound(slist)
+ def test_AddDeprecatedFlagForSymbolsWithinDeprecationGuards(self):
+ header = textwrap.dedent("""\
+ #ifndef GTKDOC_TESTER_DISABLE_DEPRECATED
+ /**
+ * SYMBOL:
+ *
+ * Deprecated: 1.1. Use NEW_SYMBOL instead.
+ */
+ #define SYMBOL "value"
+ #endif /* GTKDOC_TESTER_DISABLE_DEPRECATED */""")
+ slist, doc_comments = self.scanHeaderContent(
+ header.splitlines(keepends=True))
+ self.assertEqual(1, len(self.decls))
+ self.assertIn('<DEPRECATED/>', self.decls[0])
+
+ def test_NoDeprecatedFlagForSymbolsOutsideDeprecationGuards(self):
+ header = textwrap.dedent("""\
+ #ifndef GTKDOC_TESTER_DISABLE_DEPRECATED
+ /**
+ * SYMBOL1:
+ *
+ * Deprecated: 1.1. Use NEW_SYMBOL1 instead.
+ */
+ #define SYMBOL1 "value"
+ #endif /* GTKDOC_TESTER_DISABLE_DEPRECATED */
+ /**
+ * SYMBOL2:
+ */
+ #define SYMBOL2 "value"
+ """)
+ slist, doc_comments = self.scanHeaderContent(
+ header.splitlines(keepends=True))
+ self.assertEqual(2, len(self.decls))
+ self.assertNotIn('<DEPRECATED/>', self.decls[1])
+
class ScanHeaderContentEnum(ScanHeaderContentTestCase):
"""Test parsing of enum declarations."""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]