[Xcb] [PATCH proto 1/3] xml-xcb spec: describe switch-case

Ran Benita ran234 at gmail.com
Sat Aug 23 08:38:18 PDT 2014


On Tue, Aug 19, 2014 at 03:55:32PM +0200, Christian Linhart wrote:
> ---
>  doc/xml-xcb.txt | 35 +++++++++++++++++++++++++++--------
>  1 file changed, 27 insertions(+), 8 deletions(-)
> 
> diff --git a/doc/xml-xcb.txt b/doc/xml-xcb.txt
> index 97ce5bf..f93db7d 100644
> --- a/doc/xml-xcb.txt
> +++ b/doc/xml-xcb.txt
> @@ -239,26 +239,45 @@ enum; the value is restricted to one of the constants named in the enum.
>    defining the set of values included, and a list containing these values.
>    value-mask-type gives the type of the bitmask; this must be CARD16 or
>    CARD32.  value-mask-name gives the field name of the bitmask, and
>    value-list-name gives the field name of the list of values. Please use
>    <switch> instead for new protocol definitions.
>  
>  <switch name="identifier"> switch expression
> -    <bitcase> bitcase expression(s), fields </bitcase> </switch>
> +    <bitcase> bitcase expression(s), fields </bitcase>
> +    <case> case expression(s), fields </case>
> +</switch>
>  
>    This element represents conditional inclusion of fields. It can be viewed
> -  as sequence of multiple ifs: if ( switch expression & bitcase expression )
> -  is non-zero, bitcase fields are included in structure.  It can be used only
> -  as the last field of a structure.
> +  as sequence of multiple ifs:
>  
> -  When a bitcase includes multiple <enumref> clauses, the contents of the
> -  bitcase are only present once regardless of the number of bitcase expressions
> -  that match.
> +  <bitcase>:
> +    if ( switch expression & bitcase expression ) is non-zero,
> +    bitcase fields are included in structure.
> +
> +  <case>:
> +    if ( switch expression == case expression ) is true,
> +    then case fields are included in structure.

Initially this looked strange to me: why if-if-if-.. and not if-else
if-else if-...? But since you're allowing mixing case and bitcase (which
I agree why not?), and it makes the implementation easier, it is the
better choice.

I was curious if gcc -O2 is smart enough to skip the rest of the if's
after a successful match, in the case where all cases are exclusive so
it can know statically that it's safe. Looking at the disassembly of some
bitcases in xkb.o (xcb_xkb_select_events_details_serialize()), it seems
it isn't. But that's really minor.

So, the specified behavior of case looks good to me.

Ran

> +  It can be used only as the last field of a structure.
> +
> +  When a bitcase or case includes multiple <enumref> clauses, the contents
> +  of the bitcase or case are only present once regardless of the number of
> +  bitcase or case expressions that match.
> +
> +  A switch may contain multiple <bitcase> or <case> elements.
> +  Usually it will only contain <bitcase> elements
> +  or only contain <case> elements.
> +  That is, mixing of <case> and <bitcase> usually doesn't make any sense.
> +
> +  The same value may appear in multiple <case> or <bitcase> elements.
> +
> +  New protocol definitions should prefer to use this instead of <valueparam>
> +  and instead of <union>.
>  
> -  New protocol definitions should prefer to use this instead of <valueparam>.
>  
>  Expressions
>  -----------
>  
>    Expressions consist of a tree of <op> elements with leaves consisting of
>    <fieldref> or <value> elements.
>  
> -- 
> 2.0.1
> 
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb


More information about the Xcb mailing list