aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2000-11-13 14:20:04 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2000-11-13 14:20:04 +0000
commitb74384156ad5f011dd72171c329732806ae23736 (patch)
tree2eac56e1517f787b5e2a6759c18bb2bfd56e6a5c /gcc
parent19552aa5728591fdd2913ef54422e869af46852e (diff)
downloadgcc-b74384156ad5f011dd72171c329732806ae23736.zip
gcc-b74384156ad5f011dd72171c329732806ae23736.tar.gz
gcc-b74384156ad5f011dd72171c329732806ae23736.tar.bz2
c-parse.in (ends_in_label): Remove from %union and %type.
* c-parse.in (ends_in_label): Remove from %union and %type. (decls, stmts, lineno_stmt_or_labels, xstmts, lineno_stmt_or_label, stmt_or_label): Remove. (stmts_and_decls, lineno_stmt_decl_or_labels_ending_stmt, lineno_stmt_decl_or_labels_ending_decl, lineno_stmt_decl_or_labels_ending_label, lineno_stmt_decl_or_labels_ending_error, lineno_stmt_decl_or_labels, compstmt_contents_nonempty, lineno_stmt, lineno_label): New. (compstmt_nostart): Use compstmt_contents_nonempty. testsuite: * gcc.dg/c99-mixdecl-1.c, gcc.dg/c90-mixdecl-1.c: New tests. From-SVN: r37429
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/c-parse.in103
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/c90-mixdecl-1.c13
-rw-r--r--gcc/testsuite/gcc.dg/c99-mixdecl-1.c25
5 files changed, 113 insertions, 45 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 08d2edf..9335c5e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,18 @@
2000-11-13 Joseph S. Myers <jsm28@cam.ac.uk>
+ * c-parse.in (ends_in_label): Remove from %union and %type.
+ (decls, stmts, lineno_stmt_or_labels, xstmts,
+ lineno_stmt_or_label, stmt_or_label): Remove.
+ (stmts_and_decls, lineno_stmt_decl_or_labels_ending_stmt,
+ lineno_stmt_decl_or_labels_ending_decl,
+ lineno_stmt_decl_or_labels_ending_label,
+ lineno_stmt_decl_or_labels_ending_error,
+ lineno_stmt_decl_or_labels, compstmt_contents_nonempty,
+ lineno_stmt, lineno_label): New.
+ (compstmt_nostart): Use compstmt_contents_nonempty.
+
+2000-11-13 Joseph S. Myers <jsm28@cam.ac.uk>
+
* c-common.c (boolean_increment): New function.
* c-common.h (enum c_tree_index): Add CTI_C_BOOL_TYPE,
CTI_C_BOOL_TRUE and CTI_C_BOOL_FALSE.
diff --git a/gcc/c-parse.in b/gcc/c-parse.in
index e4daad6..0f3d2ab 100644
--- a/gcc/c-parse.in
+++ b/gcc/c-parse.in
@@ -79,7 +79,7 @@ end ifc
%start program
%union {long itype; tree ttype; enum tree_code code;
- const char *filename; int lineno; int ends_in_label; }
+ const char *filename; int lineno; }
/* All identifiers that are not reserved words
and are not declared typedefs in the current block */
@@ -194,8 +194,6 @@ end ifc
%type <itype> setspecs
-%type <ends_in_label> lineno_stmt_or_label lineno_stmt_or_labels stmt_or_label
-
%type <filename> save_filename
%type <lineno> save_lineno
@@ -824,13 +822,6 @@ lineno_decl:
{ }
;
-decls:
- lineno_decl
- | errstmt
- | decls lineno_decl
- | lineno_decl errstmt
- ;
-
/* records the type and storage class specs to use for processing
the declarators that follow.
Maintains a stack of outer-level values of current_declspecs,
@@ -1582,29 +1573,58 @@ absdcl1: /* a nonempty absolute declarator */
{ $$ = $3; }
;
-/* at least one statement, the first of which parses without error. */
-/* stmts is used only after decls, so an invalid first statement
- is actually regarded as an invalid decl and part of the decls. */
+/* A nonempty series of declarations and statements (possibly followed by
+ some labels) that can form the body of a compound statement.
+ NOTE: we don't allow labels on declarations; this might seem like a
+ natural extension, but there would be a conflict between attributes
+ on the label and prefix attributes on the declaration. */
-stmts:
- lineno_stmt_or_labels
+stmts_and_decls:
+ lineno_stmt_decl_or_labels_ending_stmt
+ | lineno_stmt_decl_or_labels_ending_decl
+ | lineno_stmt_decl_or_labels_ending_label
{
- if (pedantic && $1)
+ if (pedantic)
pedwarn ("ISO C forbids label at end of compound statement");
}
+ | lineno_stmt_decl_or_labels_ending_error
;
-lineno_stmt_or_labels:
- lineno_stmt_or_label
- | lineno_stmt_or_labels lineno_stmt_or_label
- { $$ = $2; }
- | lineno_stmt_or_labels errstmt
- { $$ = 0; }
+lineno_stmt_decl_or_labels_ending_stmt:
+ lineno_stmt
+ | lineno_stmt_decl_or_labels_ending_stmt lineno_stmt
+ | lineno_stmt_decl_or_labels_ending_decl lineno_stmt
+ | lineno_stmt_decl_or_labels_ending_label lineno_stmt
+ | lineno_stmt_decl_or_labels_ending_error lineno_stmt
;
-xstmts:
- /* empty */
- | stmts
+lineno_stmt_decl_or_labels_ending_decl:
+ lineno_decl
+ | lineno_stmt_decl_or_labels_ending_stmt lineno_decl
+ { if (pedantic && !flag_isoc99)
+ pedwarn ("ISO C89 forbids mixed declarations and code"); }
+ | lineno_stmt_decl_or_labels_ending_decl lineno_decl
+ | lineno_stmt_decl_or_labels_ending_error lineno_decl
+ ;
+
+lineno_stmt_decl_or_labels_ending_label:
+ lineno_label
+ | lineno_stmt_decl_or_labels_ending_stmt lineno_label
+ | lineno_stmt_decl_or_labels_ending_decl lineno_label
+ | lineno_stmt_decl_or_labels_ending_label lineno_label
+ | lineno_stmt_decl_or_labels_ending_error lineno_label
+ ;
+
+lineno_stmt_decl_or_labels_ending_error:
+ errstmt
+ | lineno_stmt_decl_or_labels errstmt
+ ;
+
+lineno_stmt_decl_or_labels:
+ lineno_stmt_decl_or_labels_ending_stmt
+ | lineno_stmt_decl_or_labels_ending_decl
+ | lineno_stmt_decl_or_labels_ending_label
+ | lineno_stmt_decl_or_labels_ending_error
;
errstmt: error ';'
@@ -1697,23 +1717,18 @@ compstmt_start: '{' { compstmt_count++;
compstmt_nostart: '}'
{ $$ = convert (void_type_node, integer_zero_node); }
- | pushlevel maybe_label_decls decls xstmts '}' poplevel
- { $$ = poplevel (1, 1, 0);
- SCOPE_STMT_BLOCK (TREE_PURPOSE ($6))
- = SCOPE_STMT_BLOCK (TREE_VALUE ($6))
- = $$; }
- | pushlevel maybe_label_decls error '}' poplevel
- { $$ = poplevel (kept_level_p (), 0, 0);
- SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
- = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
- = $$; }
- | pushlevel maybe_label_decls stmts '}' poplevel
- { $$ = poplevel (kept_level_p (), 0, 0);
+ | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
+ { $$ = poplevel (kept_level_p (), 1, 0);
SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
= SCOPE_STMT_BLOCK (TREE_VALUE ($5))
= $$; }
;
+compstmt_contents_nonempty:
+ stmts_and_decls
+ | error
+ ;
+
compstmt_primary_start:
'(' '{'
{ if (current_function_decl == 0)
@@ -1807,16 +1822,14 @@ c99_block_lineno_labeled_stmt:
RECHAIN_STMTS ($1, COMPOUND_BODY ($1)); }
;
-lineno_stmt_or_label:
- save_filename save_lineno stmt_or_label
- { $$ = $3; }
+lineno_stmt:
+ save_filename save_lineno stmt
+ { }
;
-stmt_or_label:
- stmt
- { $$ = 0; }
- | label
- { $$ = 1; }
+lineno_label:
+ save_filename save_lineno label
+ { }
;
select_or_iter_stmt:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 30345b6..2ef2702 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2000-11-13 Joseph S. Myers <jsm28@cam.ac.uk>
+ * gcc.dg/c99-mixdecl-1.c, gcc.dg/c90-mixdecl-1.c: New tests.
+
+2000-11-13 Joseph S. Myers <jsm28@cam.ac.uk>
+
* gcc.dg/c99-bool-1.c: New test.
2000-11-13 Joseph S. Myers <jsm28@cam.ac.uk>
diff --git a/gcc/testsuite/gcc.dg/c90-mixdecl-1.c b/gcc/testsuite/gcc.dg/c90-mixdecl-1.c
new file mode 100644
index 0000000..b07ab26
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c90-mixdecl-1.c
@@ -0,0 +1,13 @@
+/* Test for C99 mixed declarations and code: not in C90. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */
+
+void
+foo (void)
+{
+ int i;
+ i = 0;
+ int j; /* { dg-bogus "warning" "warning in place of error" } */
+ /* { dg-error "mix|parse" "mixed declarations and code not in C90" { target *-*-* } 11 } */
+}
diff --git a/gcc/testsuite/gcc.dg/c99-mixdecl-1.c b/gcc/testsuite/gcc.dg/c99-mixdecl-1.c
new file mode 100644
index 0000000..cfedad4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c99-mixdecl-1.c
@@ -0,0 +1,25 @@
+/* Test for C99 mixed declarations and code. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do run } */
+/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
+
+extern void abort (void);
+extern void exit (int);
+
+int
+main (void)
+{
+ int i = 0;
+ if (i != 0)
+ abort ();
+ i++;
+ if (i != 1)
+ abort ();
+ int j = i;
+ if (j != 1)
+ abort ();
+ struct foo { int i0; } k = { 4 };
+ if (k.i0 != 4)
+ abort ();
+ exit (0);
+}