linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Tomas Klacko <tomas.klacko@gmail.com>
Cc: Christopher Li <sparse@chrisli.org>,
	Josh Triplett <josh@joshtriplett.org>,
	linux-sparse@vger.kernel.org
Subject: Re: including sparse headers in C++ code
Date: Tue, 19 Oct 2010 22:31:09 +0100	[thread overview]
Message-ID: <20101019213109.GV19804@ZenIV.linux.org.uk> (raw)
In-Reply-To: <AANLkTinuRiaMZExudng5ECeunmF4s2ptnfaE=fYBft=i@mail.gmail.com>

On Tue, Oct 19, 2010 at 10:03:42PM +0200, Tomas Klacko wrote:
> @@ -188,7 +188,7 @@ static struct symbol_op char_op = {
>  	.type = KW_SPECIFIER,
>  	.test = Set_T|Set_Long|Set_Short,
>  	.set = Set_T|Set_Char,
> -	.class = CChar,
> +	.klass = CChar,
>  };

Egads...  Why not "kC1455", while you are at it?  Seriously, if you feel the
need to rename that, at least use something more palatable.  Hell, even
adjust_type would be better...

The only thing using that field is parsing of declaration specifiers.  We
keep track of what's acceptable after the prefix we'd seen (and report
conflicts).  We remember if we'd seen a speficier that doesn't combine with
anything (struct/union/enum/void/_Bool/typeof/__builtin_va_list) and for
numeric ones we are using a bit of trick: assign them pairs of integers as
below and add those up.
	int: (0,0)
	short: (-1,0)
	long: (1,0)
	signed: (0,1)
	unsigned: (0,2)
	double: (0, 3)
	float: (-1, 3)
	char: (0, 4)
Then the sum will be sufficient to discriminate between the resulting types
of acceptable sequences of numeric specifiers.  Namely, if the sum is (s,t),
the type we have is
   |  s = -1          |  0          |  1              |  2                   |
t=0|short int         |int          |long int         |long long int         |
t=1|short signed int  |signed int   |long signed int  |long long signed int  |
t=2|short unsigned int|unsigned int |long unsigned int|long long unsigned int|
t=3|float             |double       |long double      |                      |
t=4|                  |char         |                 |                      |
t=5|                  |signed char  |                 |                      |
t=6|                  |unsigned char|                 |                      |
and neither reordering the sequence nor omitting int affect the sum.

The first component of pair is encoded in ->type (KW_SHORT and KW_LONG bits),
the second is stored in ->class.  ->test and ->set drive the rejection of
unacceptable sequences.  For the sake of completeness, meanings of the bits
in these are:
Set_T		seen int/char/double/float/any non-combinable
Set_S		seen any non-combinable
Set_{Char,Int,Double,Float,Signed,Unsigned,Short,Long}	obvious
Set_Vlong	seen either long twice or both long and double
We could conflate e.g. Set_Signed with Set_Unsigned, but we'd have harder
time generating error messages that way.  ->test is "reject if we'd already
seen..." and ->set is "we've just seen...".  The only things not covered by
the above are
	* double long and long double are OK, but triple long and long long
double should be rejected
	* if we'd already seen any type specifiers by the time we run into
a typedef name, the sequence ends just before that typedef name (i.e.
typedef char T; int f(long T) is OK and declares f as int(long int)).
That's it...

>  static inline int match_op(struct token *token, int op)
>  {
> -	return token->pos.type == TOKEN_SPECIAL && token->special == op;
> +	return token->pos.type == TOKEN_SPECIAL && token->special == (unsigned int)op;

What was that one for?

  reply	other threads:[~2010-10-19 21:31 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-09 16:40 including sparse headers in C++ code Tomas Klacko
2010-10-09 20:59 ` Josh Triplett
2010-10-09 21:46   ` Christopher Li
2010-10-10 11:41     ` Bernd Petrovitsch
2010-10-10 11:52       ` Kamil Dudka
2010-10-11  9:44         ` Bernd Petrovitsch
2010-10-11 16:04           ` Christopher Li
2010-10-11 19:12             ` Josh Triplett
2010-10-13 14:45               ` Bernd Petrovitsch
2010-10-18 18:43                 ` Christopher Li
2010-10-20  7:29                 ` Al Viro
2010-10-20  9:39                   ` Bernd Petrovitsch
2010-10-20 15:34                     ` Christopher Li
2010-10-29 13:22                       ` Bernd Petrovitsch
2010-11-05  0:57                         ` Christopher Li
2010-11-09 13:28                           ` Bernd Petrovitsch
2010-11-09 22:52                             ` Christopher Li
2010-11-10 10:52                               ` Bernd Petrovitsch
2010-10-11 22:33     ` Tomas Klacko
2010-10-11 22:46       ` Al Viro
2010-10-11 23:01         ` Christopher Li
2010-10-12 22:45           ` Tomas Klacko
2010-10-13  0:37             ` Christopher Li
2010-10-13 11:39               ` Bernd Petrovitsch
2010-10-16 16:03               ` Tomas Klacko
2010-10-16 19:11                 ` Josh Triplett
2010-10-17 10:31                   ` Tomas Klacko
2010-10-18  4:13                     ` Christopher Li
2010-10-18  5:39                     ` Josh Triplett
2010-10-18 18:37                       ` Christopher Li
2010-10-19 20:03                         ` Tomas Klacko
2010-10-19 21:31                           ` Al Viro [this message]
2010-10-19 21:46                             ` David Malcolm
2010-10-19 22:12                               ` Al Viro
2010-10-19 22:49                             ` Tomas Klacko
2010-10-20 10:19                               ` Bernd Petrovitsch
2010-10-19 23:07                             ` Christopher Li
2010-10-20  7:40                               ` Al Viro
2010-10-18  3:16                   ` Christopher Li
2010-10-11 23:37       ` Josh Triplett
2010-10-12 10:42         ` Bernd Petrovitsch

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=20101019213109.GV19804@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=josh@joshtriplett.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    --cc=tomas.klacko@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 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 NNTP newsgroup(s).