From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: [PING^2] Re: [PATCH 1/2] Port Doxygen support script from Perl to Python; add unittests
Date: Fri, 26 May 2017 19:35:00 -0000 [thread overview]
Message-ID: <1495827156.9289.75.camel@redhat.com> (raw)
In-Reply-To: <1493417340.9106.160.camel@redhat.com>
Ping
On Fri, 2017-04-28 at 18:09 -0400, David Malcolm wrote:
> Ping for these two patches:
> - https://gcc.gnu.org/ml/gcc-patches/2017-03/msg00909.html
> - https://gcc.gnu.org/ml/gcc-patches/2017-03/msg00910.html
>
> On Thu, 2017-03-16 at 21:51 -0400, David Malcolm wrote:
> > It's possible to run GCC's sources through Doxygen by setting
> > INPUT_FILTER = contrib/filter_gcc_for_doxygen
> > within contrib/gcc.doxy and invoking doxygen on the latter file.
> >
> > The script filters out various preprocessor constructs from GCC
> > sources before Doxygen tries to parse them (e.g. GTY tags).
> >
> > As-is, the script has some limitations, so as enabling work for
> > fixing them, this patch reimplements the support script
> > contrib/filter_params.pl in Python, effectively using the same
> > regexes, but porting them from Perl to Python syntax, adding
> > comments,
> > and a unit-test suite.
> >
> > This is a revised version of a patch I posted ~3.5 years ago:
> > https://gcc.gnu.org/ml/gcc-patches/2013-10/msg02728.html
> > with the difference that in this patch I'm attempting to
> > faithfully reimplement the behavior of the Perl script, leaving
> > bugfixes to followups (in the earlier version I combined the
> > port with some behavior changes).
> >
> > I've tested it by running some source files through both scripts
> > and manually verifying that the output was identical for both
> > implementations. apart from the Python implementation adding a
> > harmless trailing newline at the end of the file.
> >
> > The unit tests pass for both Python 2 and Python 3 (tested
> > with 2.7.5 and 3.3.2).
> >
> > OK for trunk?
> >
> > contrib/
> > * filter_gcc_for_doxygen: Use filter_params.py rather than
> > filter_params.pl.
> > * filter_params.pl: Delete in favor of...
> > * filter_params.py: New, porting the perl script to python,
> > adding a test suite.
> > ---
> > contrib/filter_gcc_for_doxygen | 2 +-
> > contrib/filter_params.pl | 14 -----
> > contrib/filter_params.py | 130
> > +++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 131 insertions(+), 15 deletions(-)
> > delete mode 100755 contrib/filter_params.pl
> > create mode 100644 contrib/filter_params.py
> >
> > diff --git a/contrib/filter_gcc_for_doxygen
> > b/contrib/filter_gcc_for_doxygen
> > index 3787eeb..ca1db31 100755
> > --- a/contrib/filter_gcc_for_doxygen
> > +++ b/contrib/filter_gcc_for_doxygen
> > @@ -8,5 +8,5 @@
> > # process is put on stdout.
> >
> > dir=`dirname $0`
> > -perl $dir/filter_params.pl < $1 | perl $dir/filter_knr2ansi.pl
> > +python $dir/filter_params.py $1 | perl $dir/filter_knr2ansi.pl
> > exit 0
> > diff --git a/contrib/filter_params.pl b/contrib/filter_params.pl
> > deleted file mode 100755
> > index 22dae6c..0000000
> > --- a/contrib/filter_params.pl
> > +++ /dev/null
> > @@ -1,14 +0,0 @@
> > -#!/usr/bin/perl
> > -
> > -# Filters out some of the #defines used throughout the GCC
> > sources:
> > -# - GTY(()) marks declarations for gengtype.c
> > -# - PARAMS(()) is used for K&R compatibility. See ansidecl.h.
> > -
> > -while (<>) {
> > - s/^\/\* /\/\*\* \@verbatim /;
> > - s/\*\// \@endverbatim \*\//;
> > - s/GTY[ \t]*\(\(.*\)\)//g;
> > - s/[ \t]ATTRIBUTE_UNUSED//g;
> > - s/PARAMS[ \t]*\(\((.*?)\)\)/\($1\)/sg;
> > - print;
> > -}
> > diff --git a/contrib/filter_params.py b/contrib/filter_params.py
> > new file mode 100644
> > index 0000000..3c14121
> > --- /dev/null
> > +++ b/contrib/filter_params.py
> > @@ -0,0 +1,130 @@
> > +#!/usr/bin/python
> > +"""
> > +Filters out some of the #defines used throughout the GCC sources:
> > +- GTY(()) marks declarations for gengtype.c
> > +- PARAMS(()) is used for K&R compatibility. See ansidecl.h.
> > +
> > +When passed one or more filenames, acts on those files and prints
> > the
> > +results to stdout.
> > +
> > +When run without a filename, runs a unit-testing suite.
> > +"""
> > +import re
> > +import sys
> > +import unittest
> > +
> > +def filter_src(text):
> > + """
> > + str -> str. We operate on the whole of the source file at
> > once
> > + (rather than individual lines) so that we can have multiline
> > + regexes.
> > + """
> > +
> > + # Convert C comments from GNU coding convention of:
> > + # /* FIRST_LINE
> > + # NEXT_LINE
> > + # FINAL_LINE. */
> > + # to:
> > + # /** @verbatim FIRST_LINE
> > + # NEXT_LINE
> > + # FINAL_LINE. @endverbatim */
> > + # so that doxygen will parse them.
> > + #
> > + # Only comments that begin on the left-most column are
> > converted.
> > + text = re.sub(r'^/\* ',
> > + r'/** @verbatim ',
> > + text,
> > + flags=re.MULTILINE)
> > + text = re.sub(r'\*/',
> > + r' @endverbatim */',
> > + text)
> > +
> > + # Remove GTY markings:
> > + text = re.sub(r'GTY[ \t]*\(\(.*\)\)',
> > + '',
> > + text)
> > +
> > + # Strip out 'ATTRIBUTE_UNUSED'
> > + text = re.sub('[ \t]ATTRIBUTE_UNUSED',
> > + '',
> > + text)
> > +
> > + # PARAMS(()) is used for K&R compatibility. See ansidecl.h.
> > + text = re.sub(r'PARAMS[ \t]*\(\((.*?)\)\)',
> > + r'(\1)',
> > + text)
> > +
> > + return text
> > +
> > +class FilteringTests(unittest.TestCase):
> > + '''
> > + Unit tests for filter_src.
> > + '''
> > + def assert_filters_to(self, src_input, expected_result):
> > + # assertMultiLineEqual was added to unittest in 2.7/3.1
> > + if hasattr(self, 'assertMultiLineEqual'):
> > + assertion = self.assertMultiLineEqual
> > + else:
> > + assertion = self.assertEqual
> > + assertion(expected_result, filter_src(src_input))
> > +
> > + def test_comment_example(self):
> > + self.assert_filters_to(
> > + ('/* FIRST_LINE\n'
> > + ' NEXT_LINE\n'
> > + ' FINAL_LINE. */\n'),
> > + ('/** @verbatim FIRST_LINE\n'
> > + ' NEXT_LINE\n'
> > + ' FINAL_LINE. @endverbatim */\n'))
> > +
> > + def test_oneliner_comment(self):
> > + self.assert_filters_to(
> > + '/* Returns the string representing CLASS. */\n',
> > + ('/** @verbatim Returns the string representing CLASS.
> >
> > @endverbatim */\n'))
> > +
> > + def test_multiline_comment(self):
> > + self.assert_filters_to(
> > + ('/* The thread-local storage model associated with a
> > given VAR_DECL\n'
> > + " or SYMBOL_REF. This isn't used much, but both
> > trees and RTL refer\n"
> > + " to it, so it's here. */\n"),
> > + ('/** @verbatim The thread-local storage model
> > associated with a given VAR_DECL\n'
> > + " or SYMBOL_REF. This isn't used much, but both
> > trees and RTL refer\n"
> > + " to it, so it's here. @endverbatim */\n"))
> > +
> > + def test_GTY(self):
> > + self.assert_filters_to(
> > + ('typedef struct GTY(()) alias_pair {\n'
> > + ' tree decl;\n'
> > + ' tree target;\n'
> > + '} alias_pair;\n'),
> > + ('typedef struct alias_pair {\n'
> > + ' tree decl;\n'
> > + ' tree target;\n'
> > + '} alias_pair;\n'))
> > +
> > + def test_ATTRIBUTE_UNUSED(self):
> > + # Ensure that ATTRIBUTE_UNUSED is filtered out.
> > + self.assert_filters_to(
> > + ('static void\n'
> > + 'record_set (rtx dest, const_rtx set, void *data
> > ATTRIBUTE_UNUSED)\n'
> > + '{\n'),
> > + ('static void\n'
> > + 'record_set (rtx dest, const_rtx set, void *data)\n'
> > + '{\n'))
> > +
> > + def test_PARAMS(self):
> > + self.assert_filters_to(
> > + 'char *strcpy PARAMS ((char *dest, char *source));\n',
> > + 'char *strcpy (char *dest, char *source);\n')
> > +
> > +def act_on_files(argv):
> > + for filename in argv[1:]:
> > + with open(filename) as f:
> > + text = f.read()
> > + print(filter_src(text))
> > +
> > +if __name__ == '__main__':
> > + if len(sys.argv) > 1:
> > + act_on_files(sys.argv)
> > + else:
> > + unittest.main()
next prev parent reply other threads:[~2017-05-26 19:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-31 22:11 [PATCH] Support multiline GTY markers in Doxygen filter; " David Malcolm
2013-11-01 15:16 ` Diego Novillo
2017-03-17 1:21 ` [PATCH 1/2] Port Doxygen support script from Perl to Python; " David Malcolm
2017-03-17 1:21 ` [PATCH 2/2] filter_params.py: GTY fix and other cleanups David Malcolm
2017-04-28 12:25 ` [PATCH 1/2] Port Doxygen support script from Perl to Python; add unittests Martin Liška
2017-05-03 9:49 ` [PATCH] Doxygen: add default location for filters and output folder Martin Liška
2017-05-31 12:43 ` [PATCH 1/2] Port Doxygen support script from Perl to Python; add unittests Martin Liška
2017-04-28 12:30 ` [PATCH 1/2] Change comment style to one we normally use Martin Liška
2017-04-28 12:41 ` [PATCH 2/2] Doxygen: transform ENUM_BITFIELD and comments starting with '/**' Martin Liška
2017-04-29 2:57 ` [PING] Re: [PATCH 1/2] Port Doxygen support script from Perl to Python; add unittests David Malcolm
2017-05-19 9:14 ` Martin Liška
2017-05-26 19:35 ` David Malcolm [this message]
2017-05-31 14:07 ` [PATCH] " Martin Liška
2017-05-31 14:10 ` Martin Liška
2017-05-31 14:13 ` Martin Liška
2017-06-22 12:45 ` Martin Liška
2017-06-28 4:41 ` Jeff Law
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1495827156.9289.75.camel@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).