aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLinus Torvalds <torvalds@home.transmeta.com>2003-03-25 20:09:14 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 20:59:47 -0700
commit6093c190f23c24fbe55eae0fd233d14e6dfd1643 (patch)
tree5e859ac76e839e9cf2da18ded5fbe58fd68bb25a
parent38795344d7b03fc340b5cabb0a38e22d327836d9 (diff)
downloadsparse-dev-6093c190f23c24fbe55eae0fd233d14e6dfd1643.tar.gz
Add tree evaluation to a few more statement types (iterators,
switch and case-statements). Handle varying functions.
-rw-r--r--parse.c17
-rw-r--r--show-parse.c2
-rw-r--r--symbol.h2
-rw-r--r--test-parsing.c16
4 files changed, 28 insertions, 9 deletions
diff --git a/parse.c b/parse.c
index d9aec7f4..049e0644 100644
--- a/parse.c
+++ b/parse.c
@@ -326,7 +326,7 @@ static struct token *abstract_array_declarator(struct token *token, struct symbo
return token;
}
-static struct token *parameter_type_list(struct token *, struct symbol_list **);
+static struct token *parameter_type_list(struct token *, struct symbol *);
static struct token *declarator(struct token *token, struct symbol **tree, struct token **p);
static struct token *direct_declarator(struct token *token, struct symbol **tree, struct token **p)
@@ -364,7 +364,7 @@ static struct token *direct_declarator(struct token *token, struct symbol **tree
}
sym = indirect(token, *tree, SYM_FN);
- token = parameter_type_list(next, &sym->arguments);
+ token = parameter_type_list(next, sym);
token = expect(token, ')', "in function declarator");
continue;
}
@@ -675,16 +675,19 @@ struct token * statement_list(struct token *token, struct statement_list **list)
return token;
}
-static struct token *parameter_type_list(struct token *token, struct symbol_list **list)
+static struct token *parameter_type_list(struct token *token, struct symbol *fn)
{
+ struct symbol_list **list = &fn->arguments;
for (;;) {
struct symbol *sym = alloc_symbol(token, SYM_NODE);
if (match_op(token, SPECIAL_ELLIPSIS)) {
- sym->type = SYM_ELLIPSIS;
+ fn->variadic = 1;
token = token->next;
- } else
- token = parameter_declaration(token, &sym);
+ break;
+ }
+
+ token = parameter_declaration(token, &sym);
add_symbol(list, sym);
if (!match_op(token, ','))
break;
@@ -750,8 +753,6 @@ static void declare_argument(struct symbol *sym, void *data, int flags)
{
struct symbol *decl = data;
- if (sym->type == SYM_ELLIPSIS)
- return;
if (!sym->ident) {
warn(decl->token, "no identifier for function argument");
return;
diff --git a/show-parse.c b/show-parse.c
index b5d233da..bb0e20f8 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -192,6 +192,8 @@ void show_symbol(struct symbol *sym)
case SYM_FN:
printf("(");
show_symbol_list(type->arguments, ", ");
+ if (type->variadic)
+ printf(", ...");
printf(")\n");
show_statement(type->stmt);
return;
diff --git a/symbol.h b/symbol.h
index b8f02a58..d8cf70c1 100644
--- a/symbol.h
+++ b/symbol.h
@@ -42,7 +42,6 @@ enum type {
SYM_TYPEDEF,
SYM_MEMBER,
SYM_BITFIELD,
- SYM_ELLIPSIS,
};
struct ctype {
@@ -76,6 +75,7 @@ struct symbol {
struct symbol_list *symbol_list;
long long value; /* Initial value */
int fieldwidth;
+ int arg_count:10, variadic:1;
};
};
};
diff --git a/test-parsing.c b/test-parsing.c
index bc083979..b5ecb501 100644
--- a/test-parsing.c
+++ b/test-parsing.c
@@ -44,6 +44,22 @@ static void simplify_statement(struct statement *stmt, struct symbol *fn)
simplify_statement(stmt->if_true, fn);
simplify_statement(stmt->if_false, fn);
return;
+ case STMT_ITERATOR:
+ evaluate_expression(stmt->iterator_pre_condition);
+ evaluate_expression(stmt->iterator_post_condition);
+ simplify_statement(stmt->iterator_pre_statement, fn);
+ simplify_statement(stmt->iterator_statement, fn);
+ simplify_statement(stmt->iterator_post_statement, fn);
+ return;
+ case STMT_SWITCH:
+ evaluate_expression(stmt->switch_expression);
+ simplify_statement(stmt->switch_statement, fn);
+ return;
+ case STMT_CASE:
+ evaluate_expression(stmt->case_expression);
+ evaluate_expression(stmt->case_to);
+ simplify_statement(stmt->case_statement, fn);
+ return;
}
}