All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH v3 4/7] add a method to external_declaration()
Date: Sun, 5 Mar 2017 22:04:01 +0800	[thread overview]
Message-ID: <CANeU7Qk34VzZ6Q2oxEcFrreK=NOwmpSGbiVgvyckpp154xWJaQ@mail.gmail.com> (raw)
In-Reply-To: <20170228100403.33184-5-luc.vanoostenryck@gmail.com>

On Tue, Feb 28, 2017 at 6:04 PM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> The changes are made up of:
> - extract the part 'add local symbols to the list' to a separate
>   function: default_process_decl() as preparatory step to make
> - replace the part 'add local symbols to the list' by a call
>   to a new function pointer given in argument,
>
> Also, to make the change non-invasive for others files:
> - rename 'external_declaration()' into 'external_decl()'
> - make 'external_declaration()' a small helper calling
>   'external_decl()' with 'default_process_decl()' as the method.

I will apply this patch in the sparse-next with some minor comment.
Mostly naming the function.

> ---
>  parse.c | 27 ++++++++++++++++++++-------
>  1 file changed, 20 insertions(+), 7 deletions(-)
>
> diff --git a/parse.c b/parse.c
> index d07b27a21..b9b8d1ae0 100644
> --- a/parse.c
> +++ b/parse.c
> @@ -48,6 +48,9 @@ static struct symbol_list **function_symbol_list;
>  struct symbol_list *function_computed_target_list;
>  struct statement_list *function_computed_goto_list;
>
> +typedef void (*process_decl_t)(struct symbol_list **list, struct symbol *decl);
> +static struct token *external_decl(struct token *, process_decl_t, struct symbol_list **);
> +
>  static struct token *statement(struct token *token, struct statement **tree);
>  static struct token *handle_attributes(struct token *token, struct decl_state *ctx, unsigned int keywords);
>
> @@ -2797,7 +2800,8 @@ static struct token *toplevel_asm_declaration(struct token *token, struct symbol
>         return token;
>  }
>
> -struct token *external_declaration(struct token *token, struct symbol_list **list)
> +static struct token *external_decl(struct token *token, process_decl_t process_decl,
> +               struct symbol_list **list)

I am fine with the code logic change. However, I wish function has better names.
It just looking at the function name, "external_decl" vs "external_declaration",
it is hard to guess which function is lower level than the other.

> -               }
> +               if (!is_typedef)
> +                       process_decl(list, decl);

I think here better check the process_decl is not NULL.
The caller might issue NULL call back which means it is not
interested in adding the symbol to a list.
> +
> +static void default_process_decl(struct symbol_list **list, struct symbol *decl)
> +{
> +       if (!(decl->ctype.modifiers & (MOD_EXTERN | MOD_INLINE))) {
> +               add_symbol(list, decl);
> +               fn_local_symbol(decl);
> +       }

Again, if I look at just pure function name "default_process_decl", it is
very hard to me to guess what should happen in this function.
After all, "process a declare" is very generic, it can mean any thing.

I suggest a more meaningful name related what the code does.
e.g. "track_local_declaration". I don't know, I want to find a better name.
You are welcome to suggest a better one.

> +}
> +
> +struct token *external_declaration(struct token *token, struct symbol_list **list)
> +{
> +       return external_decl(token, default_process_decl, list);
> +}

If I don't have a better function name for external_decl, I might just not use
the wrapper function at all.

Chris

  reply	other threads:[~2017-03-05 14:04 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-18 20:30 [PATCH 0/5] more validation of C99 for-loop initializers Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 1/5] replace test for c99 " Luc Van Oostenryck
2017-02-18 22:37   ` Ramsay Jones
2017-02-19  1:10     ` Luc Van Oostenryck
2017-02-19 20:58       ` Ramsay Jones
2017-02-20  7:20         ` [PATCH v2 0/5] more validation of C99 " Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 1/5] replace test for c99 " Luc Van Oostenryck
2017-02-20 14:05             ` Ramsay Jones
2017-02-20  7:20           ` [PATCH v2 2/5] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 3/5] add test cases for storage of c99 " Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 4/5] add a method to external_declaration() Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 5/5] check the storage of C99 for-loop initializers Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 2/5] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 3/5] add test cases for storage of c99 " Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 4/5] add a method to external_declaration() Luc Van Oostenryck
2017-02-27 15:37   ` Christopher Li
2017-02-27 21:34     ` Luc Van Oostenryck
2017-02-28  9:46     ` Luc Van Oostenryck
2017-02-28 10:03       ` [PATCH v3 0/7] more validation of C99 for-loop initializers Luc Van Oostenryck
2017-02-28 10:03         ` [PATCH v3 1/7] replace test for c99 " Luc Van Oostenryck
2017-02-28 10:03         ` [PATCH v3 2/7] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-02-28 10:03         ` [PATCH v3 3/7] add test cases for storage of c99 " Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 4/7] add a method to external_declaration() Luc Van Oostenryck
2017-03-05 14:04           ` Christopher Li [this message]
2017-03-05 15:12             ` Luc Van Oostenryck
2017-03-06  1:13               ` Christopher Li
2017-03-05 19:21             ` [PATCH v4 0/6] more validation of C99 for-loop initializers Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 1/6] replace test for c99 " Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 2/6] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 3/6] add test cases for storage of c99 " Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 4/6] add an optional validation method to external_declaration() Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 5/6] check the storage of C99 for-loop initializers Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 6/6] move 'extern with initializer' validation after the validate method Luc Van Oostenryck
2017-03-06  0:59               ` [PATCH v4 0/6] more validation of C99 for-loop initializers Christopher Li
2017-03-06  1:08                 ` Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 5/7] check the storage " Luc Van Oostenryck
2017-03-05 14:26           ` Christopher Li
2017-03-05 15:24             ` Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 6/7] make process_decl() aware of the presence of an initializer Luc Van Oostenryck
2017-03-05 14:49           ` Christopher Li
2017-03-05 15:29             ` Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 7/7] move check extern with initializer to default_process_decl() Luc Van Oostenryck
2017-02-28 16:34         ` [PATCH v3 0/7] more validation of C99 for-loop initializers Christopher Li
2017-02-28 16:40           ` Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 5/5] check the storage " Luc Van Oostenryck

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='CANeU7Qk34VzZ6Q2oxEcFrreK=NOwmpSGbiVgvyckpp154xWJaQ@mail.gmail.com' \
    --to=sparse@chrisli.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.