diff options
| author | Al Viro <viro@zeniv.linux.org.uk> | 2013-01-07 14:00:48 -0500 |
|---|---|---|
| committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-02-12 10:05:31 -0500 |
| commit | 959bd8973bfcfced69715a522007662929ae6d48 (patch) | |
| tree | 18c00b9c8fde48546638c613e4db9d0fa84d06c6 /expression.c | |
| parent | 15cfba61d99668e9c14782779766f48834490ead (diff) | |
| download | sparse-dev-959bd8973bfcfced69715a522007662929ae6d48.tar.gz | |
switch to delayed handling of escape sequences
#define A(x) #x
A('\12')
should *not* yield "'\\n'"; the problem is that we are doing the conversion
too early.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'expression.c')
| -rw-r--r-- | expression.c | 53 |
1 files changed, 5 insertions, 48 deletions
diff --git a/expression.c b/expression.c index b8fab8f3..482e2b17 100644 --- a/expression.c +++ b/expression.c @@ -26,6 +26,7 @@ #include "scope.h" #include "expression.h" #include "target.h" +#include "char.h" static int match_oplist(int op, ...) { @@ -217,48 +218,6 @@ static struct token *builtin_offsetof_expr(struct token *token, } } -static struct token *string_expression(struct token *token, struct expression *expr) -{ - struct string *string = token->string; - struct token *next = token->next; - int stringtype = token_type(token); - - if (token_type(next) == stringtype) { - int totlen = string->length-1; - char *data; - - do { - totlen += next->string->length-1; - next = next->next; - } while (token_type(next) == stringtype); - - if (totlen > MAX_STRING) { - warning(token->pos, "trying to concatenate %d-character string (%d bytes max)", totlen, MAX_STRING); - totlen = MAX_STRING; - } - - string = __alloc_string(totlen+1); - string->length = totlen+1; - data = string->data; - next = token; - do { - struct string *s = next->string; - int len = s->length-1; - - if (len > totlen) - len = totlen; - totlen -= len; - - next = next->next; - memcpy(data, s->data, len); - data += len; - } while (token_type(next) == stringtype); - *data = '\0'; - } - expr->string = string; - return next; -} - #ifndef ULLONG_MAX #define ULLONG_MAX (~0ULL) #endif @@ -399,12 +358,11 @@ struct token *primary_expression(struct token *token, struct expression **tree) struct expression *expr = NULL; switch (token_type(token)) { - case TOKEN_CHAR: - case TOKEN_WIDE_CHAR: + case TOKEN_CHAR ... TOKEN_WIDE_CHAR + 4: expr = alloc_expression(token->pos, EXPR_VALUE); expr->flags = Int_const_expr; - expr->ctype = token_type(token) == TOKEN_CHAR ? &int_ctype : &long_ctype; - expr->value = (unsigned char) token->character; + expr->ctype = token_type(token) < TOKEN_WIDE_CHAR ? &int_ctype : &long_ctype; + get_char_constant(token, &expr->value); token = token->next; break; @@ -469,8 +427,7 @@ struct token *primary_expression(struct token *token, struct expression **tree) case TOKEN_STRING: case TOKEN_WIDE_STRING: expr = alloc_expression(token->pos, EXPR_STRING); - expr->wide = token_type(token) == TOKEN_WIDE_STRING; - token = string_expression(token, expr); + token = get_string_constant(token, expr); break; case TOKEN_SPECIAL: |
