From: Christopher Li <sparse@chrisli.org>
To: Michael Stefaniuc <mstefani@redhat.com>
Cc: Yura Pakhuchiy <pakhuchiy@gmail.com>, linux-sparse@vger.kernel.org
Subject: Re: L'\0' handling
Date: Thu, 8 Apr 2010 13:19:56 -0700 [thread overview]
Message-ID: <r2q70318cbf1004081319yc4bf61ccw252798cb98bc760b@mail.gmail.com> (raw)
In-Reply-To: <4BBDFC28.4080304@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
On Thu, Apr 8, 2010 at 8:54 AM, Michael Stefaniuc <mstefani@redhat.com> wrote:
> I didn't assert that the feature shouldn't be implemented, just that it
> is a known missing feature that the normal sparse consumer didn't need
> until now.
Yura, do you want to give this patch a try?
It is nasty that L'\0' start from an identifier letter. I try my best
not to slow down the
hot path. The test is done inside get_one_identifier() after the ident
hash is built.
It look a little bit out of palace but faster than testing 'L' before hand.
Chris
[-- Attachment #2: 0005-Allow-parsing-L-0.patch --]
[-- Type: application/octet-stream, Size: 3585 bytes --]
From 6c8d9169ebe8198d8b994825ce9d4eb1b7339129 Mon Sep 17 00:00:00 2001
From: Christopher Li <sparse@chrisli.org>
Date: Thu, 8 Apr 2010 14:05:29 -0700
Subject: [PATCH 5/5] Allow parsing L'\0'
Signed-off-by: Christopher Li <sparse@chrisli.org>
---
expression.c | 3 ++-
ident-list.h | 3 +++
pre-process.c | 1 +
token.h | 1 +
tokenize.c | 12 ++++++++----
5 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/expression.c b/expression.c
index c9277da..67e05e7 100644
--- a/expression.c
+++ b/expression.c
@@ -397,9 +397,10 @@ struct token *primary_expression(struct token *token, struct expression **tree)
switch (token_type(token)) {
case TOKEN_CHAR:
+ case TOKEN_LONG_CHAR:
expr = alloc_expression(token->pos, EXPR_VALUE);
expr->flags = Int_const_expr;
- expr->ctype = &int_ctype;
+ expr->ctype = token_type(token) == TOKEN_CHAR ? &int_ctype : &long_ctype;
expr->value = (unsigned char) token->character;
token = token->next;
break;
diff --git a/ident-list.h b/ident-list.h
index 0ee81bc..b94aece 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -25,6 +25,9 @@ IDENT(__attribute); IDENT(__attribute__);
IDENT(volatile); IDENT(__volatile); IDENT(__volatile__);
IDENT(double);
+/* Special case for L'\t' */
+IDENT(L);
+
/* Extended gcc identifiers */
IDENT(asm); IDENT_RESERVED(__asm); IDENT_RESERVED(__asm__);
IDENT(alignof); IDENT_RESERVED(__alignof); IDENT_RESERVED(__alignof__);
diff --git a/pre-process.c b/pre-process.c
index 34b21ff..058f24b 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -864,6 +864,7 @@ static int token_different(struct token *t1, struct token *t2)
different = t1->argnum != t2->argnum;
break;
case TOKEN_CHAR:
+ case TOKEN_LONG_CHAR:
different = t1->character != t2->character;
break;
case TOKEN_STRING: {
diff --git a/token.h b/token.h
index ebc94b4..c527e78 100644
--- a/token.h
+++ b/token.h
@@ -67,6 +67,7 @@ enum token_type {
TOKEN_ZERO_IDENT,
TOKEN_NUMBER,
TOKEN_CHAR,
+ TOKEN_LONG_CHAR,
TOKEN_STRING,
TOKEN_SPECIAL,
TOKEN_STREAMBEGIN,
diff --git a/tokenize.c b/tokenize.c
index 93dd007..cf05826 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -145,7 +145,8 @@ const char *show_token(const struct token *token)
case TOKEN_SPECIAL:
return show_special(token->special);
- case TOKEN_CHAR: {
+ case TOKEN_CHAR:
+ case TOKEN_LONG_CHAR: {
char *ptr = buffer;
int c = token->character;
*ptr++ = '\'';
@@ -527,7 +528,7 @@ static int escapechar(int first, int type, stream_t *stream, int *valp)
return next;
}
-static int get_char_token(int next, stream_t *stream)
+static int get_char_token(int next, stream_t *stream, enum token_type type)
{
int value;
struct token *token;
@@ -540,7 +541,7 @@ static int get_char_token(int next, stream_t *stream)
}
token = stream->token;
- token_type(token) = TOKEN_CHAR;
+ token_type(token) = type;
token->character = value & 0xff;
add_token(stream);
@@ -702,7 +703,7 @@ static int get_one_special(int c, stream_t *stream)
case '"':
return get_string_token(next, stream);
case '\'':
- return get_char_token(next, stream);
+ return get_char_token(next, stream, TOKEN_CHAR);
case '/':
if (next == '/')
return drop_stream_eoln(stream);
@@ -880,6 +881,9 @@ static int get_one_identifier(int c, stream_t *stream)
ident = create_hashed_ident(buf, len, hash);
+ if (ident == &L_ident && next == '\'')
+ return get_char_token(nextchar(stream), stream, TOKEN_LONG_CHAR);
+
/* Pass it on.. */
token = stream->token;
token_type(token) = TOKEN_IDENT;
--
1.6.6.1
next prev parent reply other threads:[~2010-04-08 20:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-08 14:59 L'\0' handling Yura Pakhuchiy
2010-04-08 15:22 ` Michael Stefaniuc
2010-04-08 15:39 ` Yura Pakhuchiy
2010-04-08 15:54 ` Michael Stefaniuc
2010-04-08 20:19 ` Christopher Li [this message]
[not found] ` <1270758815.2167.13.camel@yura-tl>
2010-04-08 20:46 ` Christopher Li
2010-04-08 20:58 ` Michael Stefaniuc
2010-04-08 23:18 ` Christopher Li
2010-04-09 8:57 ` Michael Stefaniuc
2010-04-09 20:07 ` Christopher Li
2010-04-09 20:28 ` Michael Stefaniuc
2010-06-18 0:30 ` Christopher Li
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=r2q70318cbf1004081319yc4bf61ccw252798cb98bc760b@mail.gmail.com \
--to=sparse@chrisli.org \
--cc=linux-sparse@vger.kernel.org \
--cc=mstefani@redhat.com \
--cc=pakhuchiy@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).