diff options
author | 2010-04-08 14:05:29 -0700 | |
---|---|---|
committer | 2010-04-08 14:39:53 -0700 | |
commit | 298c360ab0d1583585ea0fdefb9f9c96aefc64fe (patch) | |
tree | bbdf526fd03331c66332e8a46b018b6b674d4bd9 | |
parent | evaluate: check for NULL type inside typeof (diff) | |
download | sparse-298c360ab0d1583585ea0fdefb9f9c96aefc64fe.tar.gz sparse-298c360ab0d1583585ea0fdefb9f9c96aefc64fe.tar.bz2 sparse-298c360ab0d1583585ea0fdefb9f9c96aefc64fe.zip |
Allow parsing L'\0'
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.
Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r-- | expression.c | 3 | ||||
-rw-r--r-- | ident-list.h | 3 | ||||
-rw-r--r-- | pre-process.c | 1 | ||||
-rw-r--r-- | token.h | 1 | ||||
-rw-r--r-- | 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: { @@ -67,6 +67,7 @@ enum token_type { TOKEN_ZERO_IDENT, TOKEN_NUMBER, TOKEN_CHAR, + TOKEN_LONG_CHAR, TOKEN_STRING, TOKEN_SPECIAL, TOKEN_STREAMBEGIN, @@ -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; |