[2/2] filter_params.py: GTY fix and other cleanups

Submitted by David Malcolm on March 17, 2017, 1:51 a.m.

Details

Message ID 1489715500-63153-2-git-send-email-dmalcolm@redhat.com
State New
Headers show

Commit Message

David Malcolm March 17, 2017, 1:51 a.m.
This patch updates the removal of GTY tags in the Doxygen support
script so that it can cope with multiline tags, such as that for
class symtab_node.

It also makes some tweaks to regexes to make them more idiomatic
for Python (and stripping some whitespace).

Tested via unit test suite, and by running Doxygen on the gcc
source tree and verifying that it handles class symtab_node
(and its subclasses).

OK for trunk?

contrib/ChangeLog:
	* filter_params.py (OPT_WS): New.
	(filter_src): Use OPT_WS in two places.  Remove trailing
	whitespace after GTY tag.  Make GTY tag handle multiline
	arguments.  Use \s for ATTRIBUTE_UNUSED.
	(FilteringTests.test_GTY): Update expected result.
	(FilteringTests.test_multiline_GTY): New test case.
---
 contrib/filter_params.py | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/contrib/filter_params.py b/contrib/filter_params.py
index 3c14121..f94d201 100644
--- a/contrib/filter_params.py
+++ b/contrib/filter_params.py
@@ -13,6 +13,9 @@  import re
 import sys
 import unittest
 
+# Optional whitespace
+OPT_WS = '\s*'
+
 def filter_src(text):
     """
     str -> str.  We operate on the whole of the source file at once
@@ -39,18 +42,19 @@  def filter_src(text):
                   r' @endverbatim */',
                   text)
 
-    # Remove GTY markings:
-    text = re.sub(r'GTY[ \t]*\(\(.*\)\)',
+    # Remove GTY markings (potentially multiline ones):
+    text = re.sub('GTY' + OPT_WS + r'\(\(.*?\)\)\s+',
                   '',
-                  text)
+                  text,
+                  flags=(re.MULTILINE|re.DOTALL))
 
     # Strip out 'ATTRIBUTE_UNUSED'
-    text = re.sub('[ \t]ATTRIBUTE_UNUSED',
+    text = re.sub('\sATTRIBUTE_UNUSED',
                   '',
                   text)
 
     # PARAMS(()) is used for K&R compatibility. See ansidecl.h.
-    text = re.sub(r'PARAMS[ \t]*\(\((.*?)\)\)',
+    text = re.sub('PARAMS' + OPT_WS + r'\(\((.*?)\)\)',
                   r'(\1)',
                   text)
 
@@ -97,11 +101,21 @@  class FilteringTests(unittest.TestCase):
              '  tree decl;\n'
              '  tree target;\n'
              '} alias_pair;\n'),
-            ('typedef struct  alias_pair {\n'
+            ('typedef struct alias_pair {\n'
              '  tree decl;\n'
              '  tree target;\n'
              '} alias_pair;\n'))
 
+    def test_multiline_GTY(self):
+        # Ensure that a multiline GTY is filtered out.
+        self.assert_filters_to(
+            ('class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL"),\n'
+             '\t   chain_next ("%h.next"), chain_prev ("%h.previous")))\n'
+             '  symtab_node_base\n'
+             '{\n'),
+            ('class symtab_node_base\n'
+             '{\n'))
+
     def test_ATTRIBUTE_UNUSED(self):
         # Ensure that ATTRIBUTE_UNUSED is filtered out.
         self.assert_filters_to(