From 77c4d6c06a83f7d86471befb76a1be433dc2e3a3 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sat, 18 Nov 2000 23:18:36 +0000 Subject: c-decl.c (check_for_loop_decls): New function. * c-decl.c (check_for_loop_decls): New function. * c-parse.in (for_init_stmt): New. (select_or_iter_stmt): Use for_init_stmt. * c-tree.h (check_for_loop_decls): New declaration. testsuite: * gcc.dg/c90-fordecl-1.c, gcc.dg/c99-fordecl-1.c, gcc.dg/c99-fordecl-2.c: New tests. From-SVN: r37549 --- gcc/c-parse.in | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'gcc/c-parse.in') diff --git a/gcc/c-parse.in b/gcc/c-parse.in index ae47466..517b488 100644 --- a/gcc/c-parse.in +++ b/gcc/c-parse.in @@ -1868,19 +1868,18 @@ select_or_iter_stmt: | do_stmt_start error { } | FOR - '(' xexpr ';' - { stmt_count++; - $3 = build_stmt (EXPR_STMT, $3); - $$ = build_stmt (FOR_STMT, $3, NULL_TREE, + { $$ = build_stmt (FOR_STMT, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); - add_stmt ($$); - } + add_stmt ($$); } + '(' for_init_stmt + { stmt_count++; + RECHAIN_STMTS ($2, FOR_INIT_STMT ($2)); } xexpr ';' - { FOR_COND ($5) = $6; } + { FOR_COND ($2) = $6; } xexpr ')' - { FOR_EXPR ($5) = $9; } + { FOR_EXPR ($2) = $9; } c99_block_lineno_labeled_stmt - { RECHAIN_STMTS ($5, FOR_BODY ($5)); } + { RECHAIN_STMTS ($2, FOR_BODY ($2)); } | SWITCH '(' expr ')' { stmt_count++; $$ = c_start_case ($3); } @@ -1888,6 +1887,13 @@ select_or_iter_stmt: { c_finish_case (); } ; +for_init_stmt: + xexpr ';' + { add_stmt (build_stmt (EXPR_STMT, $1)); } + | decl + { check_for_loop_decls (); } + ; + /* Parse a single real statement, not including any labels. */ stmt: compstmt -- cgit v1.1