aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@penguin.transmeta.com>2003-06-02 14:35:51 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:00:49 -0700
commit13ae3d014537752efff7fa5c964b83b747ac5d76 (patch)
tree6a8c20a21a3897a23c2ff1f81278beda51b1c3a1
parentb336a10387671477e4cc23d1d629c0da4d494280 (diff)
downloadsparse-13ae3d014537752efff7fa5c964b83b747ac5d76.tar.gz
sparse-13ae3d014537752efff7fa5c964b83b747ac5d76.tar.xz
sparse-13ae3d014537752efff7fa5c964b83b747ac5d76.zip
Cleanup: factor out function body parsing into a function of its own.
Make the argument declaration use a proper iterator loop, instead of the old "symbol_iterate()" function pointer thing.
-rw-r--r--parse.c58
1 files changed, 34 insertions, 24 deletions
diff --git a/parse.c b/parse.c
index b38cf2e..4e4ace9 100644
--- a/parse.c
+++ b/parse.c
@@ -1044,17 +1044,45 @@ struct token *initializer(struct expression **tree, struct token *token)
return assignment_expression(token, tree);
}
-static void declare_argument(struct symbol *sym, void *data, int flags)
+static void declare_argument(struct symbol *sym, struct symbol *fn)
{
- struct symbol *decl = data;
-
if (!sym->ident) {
- warn(decl->pos, "no identifier for function argument");
+ warn(sym->pos, "no identifier for function argument");
return;
}
bind_symbol(sym, sym->ident, NS_SYMBOL);
}
+static struct token *parse_function_body(struct token *token, struct symbol *decl,
+ struct symbol_list **list)
+{
+ struct symbol *base_type = decl->ctype.base_type;
+ struct statement *stmt;
+ struct symbol *arg;
+
+ if (decl->ctype.modifiers & MOD_EXTERN) {
+ if (!(decl->ctype.modifiers & MOD_INLINE))
+ warn(decl->pos, "function with external linkage has definition");
+ }
+ if (!(decl->ctype.modifiers & MOD_STATIC))
+ decl->ctype.modifiers |= MOD_EXTERN;
+
+ stmt = start_function(decl);
+
+ base_type->stmt = stmt;
+ FOR_EACH_PTR (base_type->arguments, arg) {
+ declare_argument(arg, base_type);
+ } END_FOR_EACH_PTR;
+
+ token = compound_statement(token->next, stmt);
+
+ end_function(decl);
+ if (!(decl->ctype.modifiers & MOD_INLINE))
+ add_symbol(list, decl);
+ check_declaration(decl);
+ return expect(token, '}', "at end of function");
+}
+
static struct token *external_declaration(struct token *token, struct symbol_list **list)
{
struct ident *ident = NULL;
@@ -1089,27 +1117,9 @@ static struct token *external_declaration(struct token *token, struct symbol_lis
base_type = decl->ctype.base_type;
if (!is_typedef && base_type && base_type->type == SYM_FN) {
- if (match_op(token, '{')) {
- struct statement *stmt;
- if (decl->ctype.modifiers & MOD_EXTERN) {
- if (!(decl->ctype.modifiers & MOD_INLINE))
- warn(decl->pos, "function with external linkage has definition");
- }
- if (!(decl->ctype.modifiers & MOD_STATIC))
- decl->ctype.modifiers |= MOD_EXTERN;
-
- stmt = start_function(decl);
+ if (match_op(token, '{'))
+ return parse_function_body(token, decl, list);
- base_type->stmt = stmt;
- symbol_iterate(base_type->arguments, declare_argument, decl);
- token = compound_statement(token->next, stmt);
-
- end_function(decl);
- if (!(decl->ctype.modifiers & MOD_INLINE))
- add_symbol(list, decl);
- check_declaration(decl);
- return expect(token, '}', "at end of function");
- }
if (!(decl->ctype.modifiers & MOD_STATIC))
decl->ctype.modifiers |= MOD_EXTERN;
}