aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Booth <neilb@earthling.net>2000-07-13 10:12:08 +0000
committerNeil Booth <neil@gcc.gnu.org>2000-07-13 10:12:08 +0000
commit530d0ba53bd732d20f274308da997fdb12697602 (patch)
tree6423ad7e017ab296f5b561a41b556c8d5df89411
parent1920d8c7ae57b6874b91502bc8f3ba920a85ec50 (diff)
downloadgcc-530d0ba53bd732d20f274308da997fdb12697602.zip
gcc-530d0ba53bd732d20f274308da997fdb12697602.tar.gz
gcc-530d0ba53bd732d20f274308da997fdb12697602.tar.bz2
c-common.h (flag_digraphs): New.
* c-common.h (flag_digraphs): New. * c-decl.c (c_decode_option): Set flag_digraphs as appropriate. * c-lex.c (yylex): Use flag_digraphs to decide whether to honour digraphs. * testsuite/gcc.dg/cpp/digraph1.c, testsuite/gcc.dg/cpp/digraph2.c, testsuite/gcc.dg/cpp/digraphs.c: New tests. From-SVN: r35010
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-common.h4
-rw-r--r--gcc/c-decl.c16
-rw-r--r--gcc/c-lex.c15
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/cpp/digraph1.c17
-rw-r--r--gcc/testsuite/gcc.dg/cpp/digraph2.c19
-rw-r--r--gcc/testsuite/gcc.dg/cpp/digraphs.c30
8 files changed, 106 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b4dff54..ff2140e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2000-07-13 Neil Booth <NeilB@earthling.net>
+
+ * c-common.h (flag_digraphs): New.
+ * c-decl.c (c_decode_option): Set flag_digraphs as appropriate.
+ * c-lex.c (yylex): Use flag_digraphs to decide whether to
+ honour digraphs.
+
2000-07-13 Zack Weinberg <zack@wolery.cumb.org>
* gcc.c (do_spec_1): Add new %B operator.
diff --git a/gcc/c-common.h b/gcc/c-common.h
index b65b495..ba5d0fa 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -181,6 +181,10 @@ extern int flag_traditional;
extern int flag_isoc99;
+/* Nonzero means accept digraphs. */
+
+extern int flag_digraphs;
+
/* Nonzero means warn about suggesting putting in ()'s. */
extern int warn_parentheses;
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index f212e18..b759fd5 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -330,6 +330,10 @@ int flag_traditional;
int flag_isoc99 = 0;
+/* Nonzero means accept digraphs. */
+
+int flag_digraphs = 1;
+
/* Nonzero means that we have builtin functions, and main is an int */
int flag_hosted = 1;
@@ -491,6 +495,7 @@ c_decode_option (argc, argv)
{
flag_traditional = 1;
flag_writable_strings = 1;
+ flag_digraphs = 0;
}
else if (!strcmp (p, "-fallow-single-precision"))
flag_allow_single_precision = 1;
@@ -511,6 +516,7 @@ c_decode_option (argc, argv)
{
flag_traditional = 0;
flag_writable_strings = 0;
+ flag_digraphs = 1;
}
else if (!strncmp (p, "-std=", 5))
{
@@ -530,6 +536,8 @@ c_decode_option (argc, argv)
|| !strcmp (argstart, "c89"))
{
iso_1990:
+ flag_digraphs = 0;
+ iso_1990_digraphs:
flag_traditional = 0;
flag_writable_strings = 0;
flag_no_asm = 1;
@@ -538,8 +546,9 @@ c_decode_option (argc, argv)
}
else if (!strcmp (argstart, "iso9899:199409"))
{
- /* ??? The changes since ISO C 1990 are not supported. */
- goto iso_1990;
+ flag_digraphs = 1;
+ /* ??? The other changes since ISO C 1990 are not supported. */
+ goto iso_1990_digraphs;
}
else if (!strcmp (argstart, "iso9899:199x")
|| !strcmp (argstart, "iso9899:1999")
@@ -551,6 +560,7 @@ c_decode_option (argc, argv)
flag_no_asm = 1;
flag_no_nonansi_builtin = 1;
flag_isoc99 = 1;
+ flag_digraphs = 1;
}
else if (!strcmp (argstart, "gnu89"))
{
@@ -559,6 +569,7 @@ c_decode_option (argc, argv)
flag_no_asm = 0;
flag_no_nonansi_builtin = 0;
flag_isoc99 = 0;
+ flag_digraphs = 1;
}
else if (!strcmp (argstart, "gnu9x") || !strcmp (argstart, "gnu99"))
{
@@ -567,6 +578,7 @@ c_decode_option (argc, argv)
flag_no_asm = 0;
flag_no_nonansi_builtin = 0;
flag_isoc99 = 1;
+ flag_digraphs = 1;
}
else
error ("unknown C standard `%s'", argstart);
diff --git a/gcc/c-lex.c b/gcc/c-lex.c
index e38b807..f47ddac 100644
--- a/gcc/c-lex.c
+++ b/gcc/c-lex.c
@@ -2385,17 +2385,20 @@ yylex ()
/* digraphs */
case ':':
- if (c1 == '>')
+ if (c1 == '>' && flag_digraphs)
{ value = ']'; goto done; }
break;
case '<':
- if (c1 == '%')
- { value = '{'; indent_level++; goto done; }
- if (c1 == ':')
- { value = '['; goto done; }
+ if (flag_digraphs)
+ {
+ if (c1 == '%')
+ { value = '{'; indent_level++; goto done; }
+ if (c1 == ':')
+ { value = '['; goto done; }
+ }
break;
case '%':
- if (c1 == '>')
+ if (c1 == '>' && flag_digraphs)
{ value = '}'; indent_level--; goto done; }
break;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e915fd2..05211a8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2000-07-13 Neil Booth <NeilB@earthling.net>
+
+ * testsuite/gcc.dg/cpp/digraph1.c,
+ testsuite/gcc.dg/cpp/digraph2.c,
+ testsuite/gcc.dg/cpp/digraphs.c: New tests.
+
2000-07-12 David Billinghurst <David Billinghurst@riotinto.com.au>
* g77.f-torture/compile/20000630-2.f: New test.
diff --git a/gcc/testsuite/gcc.dg/cpp/digraph1.c b/gcc/testsuite/gcc.dg/cpp/digraph1.c
new file mode 100644
index 0000000..e098d68
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/digraph1.c
@@ -0,0 +1,17 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc. */
+
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:199409" } */
+
+/* Just simple check that digraphs are on under c94, for both
+ preprocessor and compiler. digraphs.c is the general test. */
+
+%:define glue
+#ifndef glue
+#error glue not defined!
+#endif
+
+int main (int argc, char *argv<::>)
+<%
+ return 0;
+%>
diff --git a/gcc/testsuite/gcc.dg/cpp/digraph2.c b/gcc/testsuite/gcc.dg/cpp/digraph2.c
new file mode 100644
index 0000000..e67ec53
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/digraph2.c
@@ -0,0 +1,19 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc. */
+
+/* { dg-do compile } */
+/* { dg-options "-std=c89" } */
+
+/* Just simple check that digraphs are not on in c89, for both
+ preprocessor and compiler. digraphs.c is the general test. */
+
+int main (int argc, char *argv[])
+{
+ return 0;
+%> /* { dg-error "parse error" } */
+
+/* Place this after main () so we get to test both the compiler above
+ and the preprocessor below. */
+%:define glue
+#ifdef glue
+#error glue is defined!
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/digraphs.c b/gcc/testsuite/gcc.dg/cpp/digraphs.c
new file mode 100644
index 0000000..e4ae0e0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/digraphs.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc. */
+
+/* { dg-do run } */
+/* { dg-options "-std=c99" } */
+
+/* Fully test the 6 digraphs under c99 assumptions. Four are pasted,
+ to check that digraph pasting works. */
+
+extern int strcmp (const char *, const char *);
+extern void abort (void);
+#define err(str) do { puts(str); abort(); } while (0)
+
+%:define glue(x, y) x %:%: y /* #define glue(x, y) x ## y. */
+#ifndef glue
+#error glue not defined!
+#endif
+%:define str(x) %:x /* #define str(x) #x */
+
+int main (int argc, char *argv<::>) /* argv[] */
+glue (<, %) /* { */
+ /* di_str[] = */
+ const char di_str glue(<, :)glue(:, >) = str(%:%:<::><%%>%:);
+
+ /* Check the glue macro actually pastes, and that the spelling of
+ all digraphs is preserved. */
+ if (glue(str, cmp) (di_str, "%:%:<::><%%>%:"))
+ err ("Digraph spelling not preserved!");
+
+ return 0;
+glue (%, >) /* } */