On 01/22/2017 04:52 PM, Martin Sebor wrote:
The substance of the attached change set is to lay the groundwork
of consolidating the handling of format directives and conversion
specifications.

1) Extend (and rename) struct conversion_spec used thus far to
represent a format conversion specification (the part of the format
string that starts with the percent character) to struct directive.
A directive can be either a conversion specification or a sequence
of plain characters that do not include the percent sign.  This
change significantly simplifies the handling of the whole format
string.

2) Separate code that parses a directive from code that subsequently
processes it.  This makes both the parsing and the processing logic
cleaner and easier to follow and modify.

3) Consolidate the code that extracts width and precision specified
by the asterisk (as in "%*.*i") from all of the directive-specific
format_xxx functions into a single function (parse_directive).
This reduces code duplication and lets the width and precision be
treated consistently in all directives.

4) Split single character handling from format_string and into its
own function.  The handling, while similar enough at first, has
diverged to the point that the conditionals to differentiate one
from the other were obscuring the logic for handling each.

None of these changes affects the tests.

gcc-78703-1.diff


commit a469182f012696107759cfe590cad3a06bd8a416
Author: Martin Sebor <mse...@redhat.com>
Date:   Thu Jan 19 16:47:02 2017 -0700

    2017-01-19  Martin Sebor  <mse...@redhat.com>

        * gimple-ssa-sprintf.c (pass_sprintf_length::gate): Adjust formatting.
        (fmtresult::operator+=): Outlined.
        (struct fmtresult): Add ctors.
        (struct conversion_spec): Rename...
        (struct directive): ...to this.  Add and remove data members.
        (directive::set_width, directive::set_precision): New functions.
        (format_percent): Use ftresult ctor.
        (get_width_and_precision): Remove.
        (format_integer): Make naming changes.  Avoid computing width and
        precision.
        (format_floating): Same.  Adjust indentation.
        (format_character): New function.
        (format_string): Moved character handling to format_character.
        (format_directive): Remove arguments, change return type.
        (parse_directive): New function.
        (pass_sprintf_length::compute_format_length): Move directive
        parsing to parse_directive.
Please add a regression marker for 78703. This is infrastructure that you need in place to address that BZ in a reasonable manner.

If this has been bootstrapped and regression tested, then I would go ahead and install it now. That way you don't have to carry this refactoring patch around if I'm unable to get through all 5 patches quickly.

jeff

ps. This really does help -- most of the changes were very easy to work through and give a high level looksie and spot check here and there. parse_directive/compute_format_length was a bit painful, but even that wasn't terrible.

Reply via email to