diff options
| author | Linus Torvalds <torvalds@penguin.transmeta.com> | 2003-03-25 16:32:24 -0700 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 20:59:46 -0700 |
| commit | 8bb77b3c4c9829d2c195eed52889ec9bd022e8ef (patch) | |
| tree | 251d86f1c34362d4178ab24dd0aa4e2be8538b2b | |
| parent | ea3907e1228b5ec9ce7e62b0861b6d4d7fb43266 (diff) | |
| download | sparse-dev-8bb77b3c4c9829d2c195eed52889ec9bd022e8ef.tar.gz | |
Fix typename parsing (incorrect ctype usage), and correct
handling of 'long' and 'long long' types. Fix cast parsing
and evaluate casts.
| -rw-r--r-- | evaluate.c | 5 | ||||
| -rw-r--r-- | expression.c | 4 | ||||
| -rw-r--r-- | parse.c | 6 | ||||
| -rw-r--r-- | show-parse.c | 41 |
4 files changed, 30 insertions, 26 deletions
@@ -214,6 +214,11 @@ int evaluate_expression(struct expression *expr) if (!evaluate_expression(expr->unop)) return 1; return evaluate_postop(expr); + case EXPR_CAST: + if (!evaluate_expression(expr->cast_expression)) + return 1; + expr->ctype = expr->cast_type; + return 1; default: break; } diff --git a/expression.c b/expression.c index f4e88a48..0ca6c19e 100644 --- a/expression.c +++ b/expression.c @@ -199,8 +199,10 @@ static struct token *cast_expression(struct token *token, struct expression **tr struct token *next = token->next; if (lookup_type(next)) { struct expression *cast = alloc_expression(next, EXPR_CAST); + struct symbol *sym; - token = typename(next, &cast->cast_type); + token = typename(next, &sym); + cast->cast_type = sym->ctype.base_type; token = expect(token, ')', "at end of cast operator"); if (match_op(token, '{')) return initializer(token, &cast->cast_type->ctype); @@ -304,6 +304,9 @@ static struct token *declaration_specifiers(struct token *next, struct ctype *ct } /* Turn the "virtual types" into real types with real sizes etc */ + if (!ctype->base_type && (ctype->modifiers & MOD_SPECIFIER)) + ctype->base_type = &int_type; + if (ctype->base_type == &int_type) { ctype->base_type = ctype_integer(ctype->modifiers & MOD_SPECIFIER); ctype->modifiers &= ~MOD_SPECIFIER; @@ -467,10 +470,9 @@ static struct token *parameter_declaration(struct token *token, struct symbol ** struct token *typename(struct token *token, struct symbol **p) { - struct ctype ctype = { 0, }; struct symbol *sym = alloc_symbol(token, SYM_NODE); *p = sym; - token = declaration_specifiers(token, &ctype); + token = declaration_specifiers(token, &sym->ctype); return declarator(token, &sym, NULL); } diff --git a/show-parse.c b/show-parse.c index 4854edef..06eeef78 100644 --- a/show-parse.c +++ b/show-parse.c @@ -30,10 +30,10 @@ const char *modifier_string(unsigned long mod) char *p = buffer; const char *res,**ptr, *names[] = { "auto", "register", "static", "extern", - "const", "volatile", "signed", "unsigned", - "char", "short", "long", "long", - "typdef", "structof", "unionof", "enum", - "typeof", "attribute", + "const", "volatile", "[signed]", "[unsigned]", + "[char]", "[short]", "[long]", "[long]", + "[typdef]", "[structof]", "[unionof]", "[enum]", + "[typeof]", "[attribute]", NULL }; ptr = names; @@ -151,38 +151,33 @@ void show_type(struct symbol *sym) printf("enum %s", show_token(sym->token)); return; - case SYM_NODE: - printf("node '%s' of type ", show_token(sym->token)); - break; + case SYM_NODE: { + struct symbol *type = sym->ctype.base_type; + if (!type) + printf("notype"); + else + show_type(type); + printf(": %s", show_token(sym->token)); + return; + } default: printf("strange type %d '%s' of type ", sym->type, show_token(sym->token)); - break; + show_type(sym->ctype.base_type); + return; } - show_type(sym->ctype.base_type); } void show_symbol(struct symbol *sym) { - if (!sym) { - printf("<anon symbol>"); - return; - } - switch (sym->type) { - case SYM_FN: - printf("%s: ", show_token(sym->token)); - show_type(sym); + + show_type(sym); + if (sym->type == SYM_FN) { printf("\n"); show_statement(sym->stmt); - break; - default: - show_type(sym); - printf(": %s", show_token(sym->token)); - break; } } - /* * Print out a statement */ |
