public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][pushed] gcc-changelog: Support multiline parentheses wrapping
@ 2021-01-13 16:24 Martin Liška
  0 siblings, 0 replies; only message in thread
From: Martin Liška @ 2021-01-13 16:24 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

Hello.

The patch is about supporting of the following ChangeLog entries:

gcc/ChangeLog:

	* config/i386/i386.md (*fix_trunc<mode>_i387_1, *add<mode>3_eq,
	*add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0, *add<mode>3_eq,
	*fist<mode>2_<rounding>_1, *<code><mode>3_1, *<code>di3_doubleword):
	Use ix86_pre_reload_split instead of can_create_pseudo_p in condition.
	* config/i386/sse.md
	(*fix_trunc<mode>_i387_1, *add<mode>3_eq,
	*add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0, *add<mode>3_eq,
	*fist<mode>2_<rounding>_1): This should also work.

I verified last 1000 git commits and found 3 valid violations.
The generated ChangeLog entries are identical.

Martin

contrib/ChangeLog:

	* gcc-changelog/git_commit.py: Support wrapping of functions
	in parentheses that can take multiple lines.
	* gcc-changelog/test_email.py: Add tests for it.
	* gcc-changelog/test_patches.txt: Add 2 patches.
---
  contrib/gcc-changelog/git_commit.py    | 32 ++++++++++++-
  contrib/gcc-changelog/test_email.py    |  8 ++++
  contrib/gcc-changelog/test_patches.txt | 62 ++++++++++++++++++++++++++
  3 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index 59f478670d7..e9dae0a838d 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -214,6 +214,7 @@ class ChangeLogEntry:
          self.lines = []
          self.files = []
          self.file_patterns = []
+        self.opened_parentheses = 0
  
      def parse_file_names(self):
          # Whether the content currently processed is between a star prefix the
@@ -223,8 +224,14 @@ class ChangeLogEntry:
          for line in self.lines:
              # If this line matches the star prefix, start the location
              # processing on the information that follows the star.
+            # Note that we need to skip macro names that can be in form of:
+            #
+            # * config/i386/i386.md (*fix_trunc<mode>_i387_1,
+            # *add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0,
+            # *fist<mode>2_<rounding>_1, *<code><mode>3_1):
+            #
              m = star_prefix_regex.match(line)
-            if m:
+            if m and len(m.group('spaces')) == 1:
                  in_location = True
                  line = m.group('content')
  
@@ -328,6 +335,7 @@ class GitCommit:
              self.parse_changelog()
              self.parse_file_names()
              self.check_for_empty_description()
+            self.check_for_broken_parentheses()
              self.deduce_changelog_locations()
              self.check_file_patterns()
              if not self.errors:
@@ -496,7 +504,8 @@ class GitCommit:
                  else:
                      m = star_prefix_regex.match(line)
                      if m:
-                        if len(m.group('spaces')) != 1:
+                        if (len(m.group('spaces')) != 1 and
+                                last_entry.opened_parentheses == 0):
                              msg = 'one space should follow asterisk'
                              self.errors.append(Error(msg, line))
                          else:
@@ -508,6 +517,7 @@ class GitCommit:
                                          msg = f'empty group "{needle}" found'
                                          self.errors.append(Error(msg, line))
                              last_entry.lines.append(line)
+                            self.process_parentheses(last_entry, line)
                      else:
                          if last_entry.is_empty:
                              msg = 'first line should start with a tab, ' \
@@ -515,6 +525,18 @@ class GitCommit:
                              self.errors.append(Error(msg, line))
                          else:
                              last_entry.lines.append(line)
+                            self.process_parentheses(last_entry, line)
+
+    def process_parentheses(self, last_entry, line):
+        for c in line:
+            if c == '(':
+                last_entry.opened_parentheses += 1
+            elif c == ')':
+                if last_entry.opened_parentheses == 0:
+                    msg = 'bad wrapping of parenthesis'
+                    self.errors.append(Error(msg, line))
+                else:
+                    last_entry.opened_parentheses -= 1
  
      def parse_file_names(self):
          for entry in self.changelog_entries:
@@ -538,6 +560,12 @@ class GitCommit:
                      msg = 'missing description of a change'
                      self.errors.append(Error(msg, line))
  
+    def check_for_broken_parentheses(self):
+        for entry in self.changelog_entries:
+            if entry.opened_parentheses != 0:
+                msg = 'bad parentheses wrapping'
+                self.errors.append(Error(msg, entry.lines[0]))
+
      def get_file_changelog_location(self, changelog_file):
          for file in self.info.modified_files:
              if file[0] == changelog_file:
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py
index 532ed6a7983..b81548f2033 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -408,3 +408,11 @@ class TestGccChangelog(unittest.TestCase):
      def test_modification_of_old_changelog(self):
          email = self.from_patch_glob('0001-fix-old-ChangeLog.patch')
          assert not email.errors
+
+    def test_multiline_parentheses(self):
+        email = self.from_patch_glob('0001-Add-macro.patch')
+        assert not email.errors
+
+    def test_multiline_bad_parentheses(self):
+        email = self.from_patch_glob('0002-Wrong-macro-changelog.patch')
+        assert email.errors[0].message == 'bad parentheses wrapping'
diff --git a/contrib/gcc-changelog/test_patches.txt b/contrib/gcc-changelog/test_patches.txt
index 6b75e488903..9de28972556 100644
--- a/contrib/gcc-changelog/test_patches.txt
+++ b/contrib/gcc-changelog/test_patches.txt
@@ -3418,4 +3418,66 @@ index 6553720acad..2c170ef014a 100644
   
  --
  2.29.2
+=== 0001-Add-macro.patch ===
+From 9b7eedc932fe594547fb060b36dfd9e4178c4f9b Mon Sep 17 00:00:00 2001
+From: Martin Liska <mliska@suse.cz>
+Date: Wed, 13 Jan 2021 16:26:45 +0100
+Subject: [PATCH 1/2] Add macro.
+
+gcc/ChangeLog:
+
+	* config/i386/i386.md (*fix_trunc<mode>_i387_1, *add<mode>3_eq,
+	*add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0, *add<mode>3_eq,
+	*fist<mode>2_<rounding>_1, *<code><mode>3_1, *<code>di3_doubleword):
+	Use ix86_pre_reload_split instead of can_create_pseudo_p in condition.
+	* config/i386/sse.md
+	(*fix_trunc<mode>_i387_1, *add<mode>3_eq,
+	*add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0, *add<mode>3_eq,
+	*fist<mode>2_<rounding>_1): This should also work.
+---
+ gcc/config/i386/i386.md | 1 +
+ gcc/config/i386/sse.md  | 1 +
+ 2 files changed, 2 insertions(+)
  
+diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
+index b60784a2908..ac63591b33f 100644
+--- a/gcc/config/i386/i386.md
++++ b/gcc/config/i386/i386.md
+@@ -1 +1,2 @@
+
++
+
+diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
+index 7f03fc491c3..0e17997db26 100644
+--- a/gcc/config/i386/sse.md
++++ b/gcc/config/i386/sse.md
+@@ -1 +1,2 @@
+
++
+
+--
+2.29.2
+
+=== 0002-Wrong-macro-changelog.patch ===
+From 3542802111d4c6752ac7233ef96655b7fb78aae4 Mon Sep 17 00:00:00 2001
+From: Martin Liska <mliska@suse.cz>
+Date: Wed, 13 Jan 2021 16:54:58 +0100
+Subject: [PATCH 2/2] Wrong macro changelog
+
+gcc/ChangeLog:
+
+	* config/i386/i386.md (*fix_trunc<mode>_i387_1,
+	(foo): Change it.
+---
+ gcc/config/i386/i386.md | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
+index ac63591b33f..ff4d61764e7 100644
+--- a/gcc/config/i386/i386.md
++++ b/gcc/config/i386/i386.md
+@@ -1 +1,2 @@
+
++
+--
+2.29.2
-- 
2.29.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-13 16:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-13 16:24 [PATCH][pushed] gcc-changelog: Support multiline parentheses wrapping Martin Liška

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).