diff options
author | Stefan Sauer <ensonic@users.sf.net> | 2019-07-24 19:12:36 +0200 |
---|---|---|
committer | Stefan Sauer <ensonic@users.sf.net> | 2019-07-24 21:53:47 +0200 |
commit | f19b91f2ae25f0fc2881e7414316d89a0678c9fb (patch) | |
tree | 7a50d4a0f1e4f97b22c0e2241e02f58097c66058 | |
parent | 2b40491bf8d37cd6766f289dd2c309f0d6a658d3 (diff) | |
download | gtk-doc-f19b91f2ae25f0fc2881e7414316d89a0678c9fb.tar.gz |
mkdb: fix skipping of inline function bodies
Add a bunch of tests for this.
Fixes #90
-rw-r--r-- | gtkdoc/scan.py | 19 | ||||
-rwxr-xr-x | tests/scan.py | 90 |
2 files changed, 97 insertions, 12 deletions
diff --git a/gtkdoc/scan.py b/gtkdoc/scan.py index a031905..15d73b6 100644 --- a/gtkdoc/scan.py +++ b/gtkdoc/scan.py @@ -791,13 +791,20 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options): in_declaration = 'union' logging.info('Union(_): "%s"', symbol) else: - logging.info('in decl: skip=%s %s', skip_block, line.strip()) + logging.info('in decl %s: skip=%s %s', in_declaration, skip_block, line.strip()) decl += line - if skip_block: + if skip_block and '{' in decl: (skip_block, decl) = remove_braced_content(decl) logging.info('in decl: skip=%s decl=[%s]', skip_block, decl) + pre_previous_line = previous_line + previous_line = line + + if skip_block: + logging.info('skipping, in decl %s, decl=[%s]', in_declaration, decl) + continue + if in_declaration == "g-declare": dm = re.search(r'\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*,\s*(\w+)\s*\).*$', decl) # FIXME the original code does s// stuff here and we don't. Is it necessary? @@ -928,9 +935,6 @@ def ScanHeaderContent(input_lines, decl_list, get_types, options): level -= line.count('}') logging.info('struct/union level : %d', level) - pre_previous_line = previous_line - previous_line = line - # here we want in_declaration=='', otherwise we have a partial declaration if in_declaration != '': raise RuntimeError('partial declaration (%s) : %s ' % (in_declaration, decl)) @@ -959,17 +963,18 @@ def remove_braced_content(decl): skip_block = True # Remove all nested pairs of curly braces. - brace_remover = r'{[^{]*}' + brace_remover = r'{[^{]*?}' bm = re.search(brace_remover, decl) while bm: decl = re.sub(brace_remover, '', decl) + logging.info('decl=[%s]' % decl) bm = re.search(brace_remover, decl) # If all '{' have been matched and removed, we're done bm = re.search(r'(.*?){', decl) if not bm: # this is a hack to detect the end of declaration - decl += ';' + decl = decl.rstrip() + ';' skip_block = False logging.info('skip_block done') diff --git a/tests/scan.py b/tests/scan.py index 98fddf7..77ddf3a 100755 --- a/tests/scan.py +++ b/tests/scan.py @@ -832,15 +832,95 @@ class SeparateSubSections(ScanHeaderContentTestCase): liststr.splitlines()) +class RemoveBracedContent(ScanHeaderContentTestCase): + + def test_OneLineFunctionBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int function(int a) { return a + a; }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual("static inline int function(int a);", decl) + self.assertEqual(skip, False) + + def test_SimpleFunctionBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int function(int a) { + return a + a; + }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual("static inline int function(int a);", decl) + self.assertEqual(skip, False) + + def test_SimpleFunctionWithNewlineBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int function(int a) + { + return a + a; + }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual("static inline int function(int a);", decl) + self.assertEqual(skip, False) + + def test_NestedFunctionBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int function(int a) { + if (a > 0) { + return a + a; + } else { + return a - a; + } + }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual("static inline int function(int a);", decl) + self.assertEqual(skip, False) + + def test_NestedFunctionWithNewlinesBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int function(int a) + { + if (a > 0) + { + return a + a; + } + else + { + return a - a; + } + }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual("static inline int function(int a);", decl) + self.assertEqual(skip, False) + + def test_SimpleFunctionWithParenthesisBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int + (function) (int a) + { + return a + a; + }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual("static inline int\n(function) (int a);", decl) + self.assertEqual(skip, False) + + def test_FunctionWithMultilineParamsBodyIsRemoved(self): + decl = textwrap.dedent("""\ + static inline int + function (int a, + int b) + { + return a + b; + }""") + (skip, decl) = scan.remove_braced_content(decl) + self.assertEqual( + "static inline int\nfunction (int a,\n int b);", decl) + self.assertEqual(skip, False) + + if __name__ == '__main__': from gtkdoc import common common.setup_logging() unittest.main() - # from gtkdoc import common - # common.setup_logging() - # - # t = ScanHeaderContentFunctions() + # t = RemoveBracedContent() # t.setUp() - # t.test_IgnoresInternalInlineFunction() + # t.test_NestedFunctionBodyIsRemoved() |