[PATCH wayland 2/2] scanner: Make emit_structs more explicit

Marek Chalupa mchqwerty at gmail.com
Mon Aug 11 01:04:01 PDT 2014


The code looks clearer, seems working and I haven't found any issue in the
code, therefore:

Reviewed-by: Marek Chalupa <mchqwerty at gmail.com>

For both patches


On 9 August 2014 00:22, Jasper St. Pierre <jstpierre at mecheye.net> wrote:

> "is_interface" is a really terrible name for the client or server
> variants, and instead of checking whether we were passed the requests or
> the events, just pass an argument through.
> ---
>  src/scanner.c | 25 ++++++++++++-------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/src/scanner.c b/src/scanner.c
> index 51ecb55..72fd3e8 100644
> --- a/src/scanner.c
> +++ b/src/scanner.c
> @@ -851,16 +851,15 @@ emit_enumerations(struct interface *interface)
>  }
>
>  static void
> -emit_structs(struct wl_list *message_list, struct interface *interface)
> +emit_structs(struct wl_list *message_list, struct interface *interface,
> enum side side)
>  {
>         struct message *m;
>         struct arg *a;
> -       int is_interface, n;
> +       int n;
>
>         if (wl_list_empty(message_list))
>                 return;
>
> -       is_interface = message_list == &interface->request_list;
>         if (interface->description) {
>                 struct description *desc = interface->description;
>                 printf("/**\n");
> @@ -876,7 +875,7 @@ emit_structs(struct wl_list *message_list, struct
> interface *interface)
>                 printf(" */\n");
>         }
>         printf("struct %s_%s {\n", interface->name,
> -              is_interface ? "interface" : "listener");
> +              (side == SERVER) ? "interface" : "listener");
>
>         wl_list_for_each(m, message_list, link) {
>                 struct description *mdesc = m->description;
> @@ -886,7 +885,7 @@ emit_structs(struct wl_list *message_list, struct
> interface *interface)
>                           "\t * %s - ", m->name);
>                 wl_list_for_each(a, &m->arg_list, link) {
>
> -                       if (is_interface && a->type == NEW_ID &&
> +                       if (side == SERVER && a->type == NEW_ID &&
>                             a->interface_name == NULL)
>                                 printf("\t * @interface: name of the
> objects interface\n"
>                                        "\t * @version: version of the
> objects interface\n");
> @@ -906,7 +905,7 @@ emit_structs(struct wl_list *message_list, struct
> interface *interface)
>                 printf("\tvoid (*%s)(", m->name);
>
>                 n = strlen(m->name) + 17;
> -               if (is_interface) {
> +               if (side == SERVER) {
>                         printf("struct wl_client *client,\n"
>                                "%sstruct wl_resource *resource",
>                                indent(n));
> @@ -919,14 +918,14 @@ emit_structs(struct wl_list *message_list, struct
> interface *interface)
>                 wl_list_for_each(a, &m->arg_list, link) {
>                         printf(",\n%s", indent(n));
>
> -                       if (is_interface && a->type == OBJECT)
> +                       if (side == SERVER && a->type == OBJECT)
>                                 printf("struct wl_resource *");
> -                       else if (is_interface && a->type == NEW_ID &&
> a->interface_name == NULL)
> +                       else if (side == SERVER && a->type == NEW_ID &&
> a->interface_name == NULL)
>                                 printf("const char *interface, uint32_t
> version, uint32_t ");
> -                       else if (!is_interface && a->type == OBJECT &&
> a->interface_name == NULL)
> +                       else if (side == CLIENT && a->type == OBJECT &&
> a->interface_name == NULL)
>                                 printf("void *");
>
> -                       else if (!is_interface && a->type == NEW_ID)
> +                       else if (side == CLIENT && a->type == NEW_ID)
>                                 printf("struct %s *", a->interface_name);
>                         else
>                                 emit_type(a);
> @@ -939,7 +938,7 @@ emit_structs(struct wl_list *message_list, struct
> interface *interface)
>
>         printf("};\n\n");
>
> -       if (!is_interface) {
> +       if (side == CLIENT) {
>             printf("static inline int\n"
>                    "%s_add_listener(struct %s *%s,\n"
>                    "%sconst struct %s_listener *listener, void *data)\n"
> @@ -1019,12 +1018,12 @@ emit_header(struct protocol *protocol, enum side
> side)
>                 emit_enumerations(i);
>
>                 if (side == SERVER) {
> -                       emit_structs(&i->request_list, i);
> +                       emit_structs(&i->request_list, i, side);
>                         emit_opcodes(&i->event_list, i);
>                         emit_opcode_versions(&i->event_list, i);
>                         emit_event_wrappers(&i->event_list, i);
>                 } else {
> -                       emit_structs(&i->event_list, i);
> +                       emit_structs(&i->event_list, i, side);
>                         emit_opcodes(&i->request_list, i);
>                         emit_stubs(&i->request_list, i);
>                 }
> --
> 2.0.4
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>

Regards,
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20140811/5bb17b4d/attachment.html>


More information about the wayland-devel mailing list