aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-03-30 22:30:28 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 20:59:55 -0700
commit9d2258c5def38d3c161e8c2750b6e9fe62449bb3 (patch)
tree1c07cd993957263d15f36b4122e85d103ff4c294 /expression.c
parentA structure member is just an identifier, not a random token. (diff)
downloadsparse-9d2258c5def38d3c161e8c2750b6e9fe62449bb3.tar.gz
sparse-9d2258c5def38d3c161e8c2750b6e9fe62449bb3.tar.bz2
sparse-9d2258c5def38d3c161e8c2750b6e9fe62449bb3.zip
Start doing constant strings right: do proper concatenation of strings,
and evaluate their type to be arrays of char rather than just a pointer.
Diffstat (limited to 'expression.c')
-rw-r--r--expression.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/expression.c b/expression.c
index aff176b..e2d41cc 100644
--- a/expression.c
+++ b/expression.c
@@ -53,6 +53,37 @@ struct token *parens_expression(struct token *token, struct expression **expr, c
return expect(token, ')', where);
}
+static struct token *string_expression(struct token *token, struct expression *expr)
+{
+ struct string *string = token->string;
+ struct token *next = token->next;
+
+ if (token_type(next) == TOKEN_STRING) {
+ int totlen = string->length;
+ char *data;
+
+ do {
+ totlen += next->string->length-1;
+ next = next->next;
+ } while (token_type(next) == TOKEN_STRING);
+
+ string = __alloc_string(totlen);
+ string->length = totlen;
+ data = string->data;
+ next = token;
+ do {
+ struct string *s = next->string;
+ int len = s->length;
+
+ next = next->next;
+ memcpy(data, s->data, len);
+ data += len-1;
+ } while (token_type(next) == TOKEN_STRING);
+ }
+ expr->string = string;
+ return next;
+}
+
struct token *primary_expression(struct token *token, struct expression **tree)
{
struct expression *expr = NULL;
@@ -74,13 +105,11 @@ struct token *primary_expression(struct token *token, struct expression **tree)
break;
}
- case TOKEN_STRING:
- expr = alloc_expression(token->pos, EXPR_CONSTANT);
- expr->token = token;
- do {
- token = token->next;
- } while (token_type(token) == TOKEN_STRING);
+ case TOKEN_STRING: {
+ expr = alloc_expression(token->pos, EXPR_STRING);
+ token = string_expression(token, expr);
break;
+ }
case TOKEN_SPECIAL:
if (token->special == '(') {