]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-lang.c (lang_init_options): Update call to cpp_reader_init.
authorNeil Booth <neilb@earthling.net>
Mon, 20 Nov 2000 18:27:32 +0000 (18:27 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Mon, 20 Nov 2000 18:27:32 +0000 (18:27 +0000)
* c-lang.c (lang_init_options): Update call to
cpp_reader_init.
* cppmain.c (main): Similarly.
* fix-header.c (read_scan_file): Similarly.
* cp/lex.c (lang_init_options): Similarly.
* objc/objc-act.c (lang_init_options): Similarly.
* cppexp.c (parse_number): Only warn for unextended C89.
* cppinit.c (set_lang): New function.
(cpp_reader_init): Take a LANG argument and pass it to set_lang.
(COMMAND_LINE_OPTIONS): New option std=c++98.
(cpp_handle_option): Use set_lang.
* cpplib.h (enum_c_lang): New enumeration.  Update comments.

From-SVN: r37587

gcc/ChangeLog
gcc/c-lang.c
gcc/cp/lex.c
gcc/cppexp.c
gcc/cppinit.c
gcc/cpplib.h
gcc/cppmain.c
gcc/fix-header.c
gcc/objc/objc-act.c

index 200ecc5a144c9dfab8dc790b0db410dd9fed64f1..6bc280d66b2cdaa3fb44978f92ff818bb5894b6a 100644 (file)
@@ -1,3 +1,19 @@
+2000-11-20  Neil Booth  <neilb@earthling.net>
+
+       * c-lang.c (lang_init_options): Update call to
+       cpp_reader_init.
+       * cppmain.c (main): Similarly.
+       * fix-header.c (read_scan_file): Similarly.
+       * cp/lex.c (lang_init_options): Similarly.
+       * objc/objc-act.c (lang_init_options): Similarly.
+       * cppexp.c (parse_number): Only warn for unextended C89.
+       * cppinit.c (set_lang): New function.
+       (cpp_reader_init): Take a LANG argument and pass it to set_lang.
+       (COMMAND_LINE_OPTIONS): New option std=c++98.
+       (cpp_handle_option): Use set_lang.
+       * cpplex.c (_cpp_lex_token): Warn pedantically if not C99.
+       * cppib.h (enum_c_lang): New enumeration.  Update comments.
+
 2000-11-20  Will Cohen  <wcohen@redhat.com>
 
        * calls.c (expand_call): Clear target only when target is in
index 7259429b10a631a334aa72f2f0f51a3207c19c04..1c9fe38f1337bcb43892828ca6f173639475f92a 100644 (file)
@@ -58,7 +58,7 @@ lang_init_options ()
 {
 #if USE_CPPLIB
   cpp_init ();
-  cpp_reader_init (&parse_in);
+  cpp_reader_init (&parse_in, CLK_GNUC89);
 #endif
   /* Mark as "unspecified".  */
   flag_bounds_check = -1;
index b0553e0434f5b62024140f7b59f2ba270137d121..7e7da03865b3f06ea4a484a6c796cc8ba2582447 100644 (file)
@@ -254,7 +254,7 @@ lang_init_options ()
 {
 #if USE_CPPLIB
   cpp_init ();
-  cpp_reader_init (&parse_in);
+  cpp_reader_init (&parse_in, CLK_GNUC89);
 #endif
 
   /* Default exceptions on.  */
index 98bd94e202929a3c26e0e2d512eafae93c43cbec..6665380c3a80c3a42d15a880e2cc7c85a88fe9b5 100644 (file)
@@ -205,7 +205,9 @@ parse_number (pfile, tok)
 
       if (CPP_WTRADITIONAL (pfile) && sufftab[i].u)
        cpp_warning (pfile, "traditional C rejects the `U' suffix");
-      if (CPP_OPTION (pfile, c89) && sufftab[i].l == 2)
+      if (CPP_OPTION (pfile, c89)
+         && sufftab[i].l == 2
+         && pfile->spec_nodes.n__STRICT_ANSI__->type == NT_MACRO)
        SYNTAX_ERROR ("too many 'l' suffixes in integer constant");
     }
   
index 095e6d4c8fb40388da7028165579e78ab7bd5eac..f8394e4a70857105e4526235a83b7a3966598b33 100644 (file)
@@ -105,6 +105,7 @@ static void merge_include_chains    PARAMS ((cpp_reader *));
 static void do_includes                        PARAMS ((cpp_reader *,
                                                 struct pending_option *,
                                                 int));
+static void set_lang                   PARAMS ((cpp_reader *, enum c_lang));
 static void initialize_dependency_output PARAMS ((cpp_reader *));
 static void initialize_standard_includes PARAMS ((cpp_reader *));
 static void new_pending_directive      PARAMS ((struct cpp_pending *,
@@ -421,10 +422,111 @@ cpp_init ()
   cpp_init_completed = 1;
 }
 
+/* Sets internal flags correctly for a given language, and defines
+   macros if necessary.  */
+static void
+set_lang (pfile, lang)
+     cpp_reader *pfile;
+     enum c_lang lang;
+{
+  struct cpp_pending *pend = CPP_OPTION (pfile, pending);
+
+  /* Default to zero.  */
+  CPP_OPTION (pfile, lang_asm) = 0;
+  CPP_OPTION (pfile, objc) = 0;
+  CPP_OPTION (pfile, cplusplus) = 0;
+
+  switch (lang)
+    {
+      /* GNU C.  */
+    case CLK_GNUC99:
+      CPP_OPTION (pfile, trigraphs) = 0;
+      CPP_OPTION (pfile, dollars_in_ident) = 1;
+      CPP_OPTION (pfile, cplusplus_comments) = 1;
+      CPP_OPTION (pfile, digraphs) = 1;
+      CPP_OPTION (pfile, c89) = 0;
+      CPP_OPTION (pfile, c99) = 1;
+      new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
+      break;
+    case CLK_GNUC89:
+      CPP_OPTION (pfile, trigraphs) = 0;
+      CPP_OPTION (pfile, dollars_in_ident) = 1;
+      CPP_OPTION (pfile, cplusplus_comments) = 1;
+      CPP_OPTION (pfile, digraphs) = 1;
+      CPP_OPTION (pfile, c89) = 1;
+      CPP_OPTION (pfile, c99) = 0;
+      break;
+
+      /* ISO C.  */
+    case CLK_STDC94:
+      new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
+    case CLK_STDC89:
+      CPP_OPTION (pfile, trigraphs) = 1;
+      CPP_OPTION (pfile, dollars_in_ident) = 0;
+      CPP_OPTION (pfile, cplusplus_comments) = 0;
+      CPP_OPTION (pfile, digraphs) = lang == CLK_STDC94;
+      CPP_OPTION (pfile, c89) = 1;
+      CPP_OPTION (pfile, c99) = 0;
+      new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
+      break;
+    case CLK_STDC99:
+      CPP_OPTION (pfile, trigraphs) = 1;
+      CPP_OPTION (pfile, dollars_in_ident) = 0;
+      CPP_OPTION (pfile, cplusplus_comments) = 1;
+      CPP_OPTION (pfile, digraphs) = 1;
+      CPP_OPTION (pfile, c89) = 0;
+      CPP_OPTION (pfile, c99) = 1;
+      new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
+      new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
+      break;
+
+      /* Objective C.  */
+    case CLK_OBJCXX:
+      new_pending_directive (pend, "__cplusplus", cpp_define);
+      CPP_OPTION (pfile, cplusplus) = 1;
+    case CLK_OBJC:
+      CPP_OPTION (pfile, trigraphs) = 0;
+      CPP_OPTION (pfile, dollars_in_ident) = 1;
+      CPP_OPTION (pfile, cplusplus_comments) = 1;
+      CPP_OPTION (pfile, digraphs) = 1;
+      CPP_OPTION (pfile, c89) = 0;
+      CPP_OPTION (pfile, c99) = 0;
+      CPP_OPTION (pfile, objc) = 1;
+      new_pending_directive (pend, "__OBJC__", cpp_define);
+      break;
+
+      /* C++.  */
+    case CLK_GNUCXX:
+    case CLK_CXX98:
+      CPP_OPTION (pfile, cplusplus) = 1;
+      CPP_OPTION (pfile, trigraphs) = lang == CLK_CXX98;
+      CPP_OPTION (pfile, dollars_in_ident) = lang == CLK_GNUCXX;
+      CPP_OPTION (pfile, cplusplus_comments) = 1;
+      CPP_OPTION (pfile, digraphs) = 1;
+      CPP_OPTION (pfile, c89) = 0;
+      CPP_OPTION (pfile, c99) = 0;
+      new_pending_directive (pend, "__cplusplus", cpp_define);
+      break;
+
+      /* Assembler.  */
+    case CLK_ASM:
+      CPP_OPTION (pfile, trigraphs) = 0;
+      CPP_OPTION (pfile, dollars_in_ident) = 0;        /* Maybe not?  */
+      CPP_OPTION (pfile, cplusplus_comments) = 1;
+      CPP_OPTION (pfile, digraphs) = 0; 
+     CPP_OPTION (pfile, c89) = 0;
+      CPP_OPTION (pfile, c99) = 0;
+      CPP_OPTION (pfile, lang_asm) = 1;
+      new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
+      break;
+    }
+}
+
 /* Initialize a cpp_reader structure. */
 void
-cpp_reader_init (pfile)
+cpp_reader_init (pfile, lang)
      cpp_reader *pfile;
+     enum c_lang lang;
 {
   struct spec_nodes *s;
 
@@ -439,11 +541,9 @@ cpp_reader_init (pfile)
       cpp_init ();
     }
 
-  CPP_OPTION (pfile, dollars_in_ident) = 1;
-  CPP_OPTION (pfile, cplusplus_comments) = 1;
+  set_lang (pfile, lang);
   CPP_OPTION (pfile, warn_import) = 1;
   CPP_OPTION (pfile, warn_paste) = 1;
-  CPP_OPTION (pfile, digraphs) = 1;
   CPP_OPTION (pfile, discard_comments) = 1;
   CPP_OPTION (pfile, show_column) = 1;
   CPP_OPTION (pfile, tabstop) = 8;
@@ -1077,6 +1177,7 @@ new_pending_directive (pend, text, handler)
   DEF_OPT("pedantic",                 0,      OPT_pedantic)                   \
   DEF_OPT("pedantic-errors",          0,      OPT_pedantic_errors)            \
   DEF_OPT("remap",                    0,      OPT_remap)                      \
+  DEF_OPT("std=c++98",                0,      OPT_std_cplusplus98)            \
   DEF_OPT("std=c89",                  0,      OPT_std_c89)                    \
   DEF_OPT("std=c99",                  0,      OPT_std_c99)                    \
   DEF_OPT("std=c9x",                  0,      OPT_std_c9x)                    \
@@ -1324,93 +1425,52 @@ cpp_handle_option (pfile, argc, argv)
          CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
          break;
        case OPT_lang_c:
-         CPP_OPTION (pfile, cplusplus) = 0;
-         CPP_OPTION (pfile, cplusplus_comments) = 1;
-         CPP_OPTION (pfile, c89) = 0;
-         CPP_OPTION (pfile, c99) = 1;
-         CPP_OPTION (pfile, digraphs) = 1;
-         CPP_OPTION (pfile, objc) = 0;
+         set_lang (pfile, CLK_GNUC89);
          break;
        case OPT_lang_cplusplus:
-         CPP_OPTION (pfile, cplusplus) = 1;
-         CPP_OPTION (pfile, cplusplus_comments) = 1;
-         CPP_OPTION (pfile, c89) = 0;
-         CPP_OPTION (pfile, c99) = 0;
-         CPP_OPTION (pfile, objc) = 0;
-         CPP_OPTION (pfile, digraphs) = 1;
-         new_pending_directive (pend, "__cplusplus", cpp_define);
+         set_lang (pfile, CLK_GNUCXX);
          break;
-       case OPT_lang_objcplusplus:
-         CPP_OPTION (pfile, cplusplus) = 1;
-         new_pending_directive (pend, "__cplusplus", cpp_define);
-         /* fall through */
        case OPT_lang_objc:
-         CPP_OPTION (pfile, cplusplus_comments) = 1;
-         CPP_OPTION (pfile, c89) = 0;
-         CPP_OPTION (pfile, c99) = 0;
-         CPP_OPTION (pfile, objc) = 1;
-         new_pending_directive (pend, "__OBJC__", cpp_define);
+         set_lang (pfile, CLK_OBJC);
          break;
-       case OPT_lang_asm:
-         CPP_OPTION (pfile, lang_asm) = 1;
-         CPP_OPTION (pfile, dollars_in_ident) = 0;
-         new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
+       case OPT_lang_objcplusplus:
+         set_lang (pfile, CLK_OBJCXX);
          break;
-       case OPT_nostdinc:
-         /* -nostdinc causes no default include directories.
-            You must specify all include-file directories with -I.  */
-         CPP_OPTION (pfile, no_standard_includes) = 1;
+       case OPT_lang_asm:
+         set_lang (pfile, CLK_ASM);
          break;
-       case OPT_nostdincplusplus:
-         /* -nostdinc++ causes no default C++-specific include directories. */
-         CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
+       case OPT_std_cplusplus98:
+         set_lang (pfile, CLK_CXX98);
          break;
        case OPT_std_gnu89:
-         CPP_OPTION (pfile, cplusplus) = 0;
-         CPP_OPTION (pfile, cplusplus_comments) = 1;
-         CPP_OPTION (pfile, c89) = 1;
-         CPP_OPTION (pfile, c99) = 0;
-         CPP_OPTION (pfile, objc) = 0;
-         CPP_OPTION (pfile, digraphs) = 1;
+         set_lang (pfile, CLK_GNUC89);
          break;
        case OPT_std_gnu9x:
        case OPT_std_gnu99:
-         CPP_OPTION (pfile, cplusplus) = 0;
-         CPP_OPTION (pfile, cplusplus_comments) = 1;
-         CPP_OPTION (pfile, c89) = 0;
-         CPP_OPTION (pfile, c99) = 1;
-         CPP_OPTION (pfile, digraphs) = 1;
-         CPP_OPTION (pfile, objc) = 0;
-         new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
+         set_lang (pfile, CLK_GNUC99);
          break;
        case OPT_std_iso9899_199409:
-         new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
-         /* Fall through */
+         set_lang (pfile, CLK_STDC94);
+         break;
        case OPT_std_iso9899_1990:
        case OPT_std_c89:
        case OPT_lang_c89:
-         CPP_OPTION (pfile, cplusplus) = 0;
-         CPP_OPTION (pfile, cplusplus_comments) = 0;
-         CPP_OPTION (pfile, c89) = 1;
-         CPP_OPTION (pfile, c99) = 0;
-         CPP_OPTION (pfile, objc) = 0;
-         CPP_OPTION (pfile, digraphs) = opt_code == OPT_std_iso9899_199409;
-         CPP_OPTION (pfile, trigraphs) = 1;
-         new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
+         set_lang (pfile, CLK_STDC89);
          break;
        case OPT_std_iso9899_199x:
        case OPT_std_iso9899_1999:
        case OPT_std_c9x:
        case OPT_std_c99:
-         CPP_OPTION (pfile, cplusplus) = 0;
-         CPP_OPTION (pfile, cplusplus_comments) = 1;
-         CPP_OPTION (pfile, c89) = 0;
-         CPP_OPTION (pfile, c99) = 1;
-         CPP_OPTION (pfile, objc) = 0;
-         CPP_OPTION (pfile, digraphs) = 1;
-         CPP_OPTION (pfile, trigraphs) = 1;
-         new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
-         new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
+         set_lang (pfile, CLK_STDC99);
+         break;
+       case OPT_nostdinc:
+         /* -nostdinc causes no default include directories.
+            You must specify all include-file directories with -I.  */
+         CPP_OPTION (pfile, no_standard_includes) = 1;
+         break;
+       case OPT_nostdincplusplus:
+         /* -nostdinc++ causes no default C++-specific include directories. */
+         CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
          break;
        case OPT_o:
          if (CPP_OPTION (pfile, out_fname) != NULL)
index 8c1a439b16fb73fdcd42bab4257536035937e3d4..5922f94290f1f2f0f8dfe130cceeacea7e641fcb 100644 (file)
@@ -152,6 +152,10 @@ enum cpp_ttype
 #undef OP
 #undef TK
 
+/* C language kind, used when calling cpp_reader_init.  */
+enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99,
+            CLK_GNUCXX, CLK_CXX98, CLK_OBJC, CLK_OBJCXX, CLK_ASM};
+
 /* Multiple-include optimisation.  */
 enum mi_state {MI_FAILED = 0, MI_OUTSIDE};
 enum mi_ind {MI_IND_NONE = 0, MI_IND_NOT};
@@ -168,7 +172,7 @@ struct cpp_string
 #define DIGRAPH                (1 << 1) /* If it was a digraph.  */
 #define STRINGIFY_ARG  (1 << 2) /* If macro argument to be stringified.  */
 #define PASTE_LEFT     (1 << 3) /* If on LHS of a ## operator.  */
-#define NAMED_OP       (1 << 4) /* C++ named operators, also "defined".  */
+#define NAMED_OP       (1 << 4) /* C++ named operators.  */
 #define NO_EXPAND      (1 << 5) /* Do not macro-expand this token.  */
 
 /* A preprocessing token.  This has been carefully packed and should
@@ -518,7 +522,7 @@ struct spec_nodes
   cpp_hashnode *n__VA_ARGS__;          /* C99 vararg macros */
 };
 
-/* a cpp_reader encapsulates the "state" of a pre-processor run.
+/* A cpp_reader encapsulates the "state" of a pre-processor run.
    Applying cpp_get_token repeatedly yields a stream of pre-processor
    tokens.  Usually, there is only one cpp_reader object active.  */
 
@@ -711,33 +715,34 @@ union tree_node;
 
 struct cpp_hashnode
 {
-  const unsigned char *name;           /* null-terminated name */
-  unsigned int hash;                   /* cached hash value */
-  unsigned short length;               /* length of name excluding null */
-  unsigned short arg_index;            /* macro argument index */
-  unsigned char directive_index;       /* index into directive table.  */
-  ENUM_BITFIELD(node_type) type : 8;   /* node type.  */
-  unsigned char flags;                 /* node flags.  */
+  const unsigned char *name;           /* Null-terminated name.  */
+  unsigned int hash;                   /* Cached hash value.  */
+  unsigned short length;               /* Length of name excluding null.  */
+  unsigned short arg_index;            /* Macro argument index.  */
+  unsigned char directive_index;       /* Index into directive table.  */
+  ENUM_BITFIELD(node_type) type : 8;   /* Node type.  */
+  unsigned char flags;                 /* Node flags.  */
 
   union
   {
-    cpp_macro *macro;                  /* a macro.  */
-    struct answer *answers;            /* answers to an assertion.  */
-    enum cpp_ttype operator;           /* code for a named operator.  */
-    enum builtin_type builtin;         /* code for a builtin macro.  */
+    cpp_macro *macro;                  /* If a macro.  */
+    struct answer *answers;            /* Answers to an assertion.  */
+    enum cpp_ttype operator;           /* Code for a named operator.  */
+    enum builtin_type builtin;         /* Code for a builtin macro.  */
   } value;
 
-  union tree_node *fe_value;           /* front end value */
+  union tree_node *fe_value;           /* Front end value.  */
 };
 
 extern unsigned int cpp_token_len PARAMS ((const cpp_token *));
-extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *, const cpp_token *));
+extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *,
+                                                const cpp_token *));
 extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *,
                                               unsigned char *));
 extern void cpp_init PARAMS ((void));
 extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
 extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
-extern void cpp_reader_init PARAMS ((cpp_reader *));
+extern void cpp_reader_init PARAMS ((cpp_reader *, enum c_lang));
 
 extern void cpp_register_pragma PARAMS ((cpp_reader *,
                                         const char *, const char *,
index ca966fc220e66e6598e4ae6c2a7b4dcc70d84ff2..d530e7d8427e268e881c4b172264cfa7e856a2bf 100644 (file)
@@ -87,7 +87,8 @@ main (argc, argv)
   (void) textdomain (PACKAGE);
 
   cpp_init ();
-  cpp_reader_init (pfile);
+  /* Default language is GNU C89.  */
+  cpp_reader_init (pfile, CLK_GNUC89);
   
   argi += cpp_handle_options (pfile, argc - argi , argv + argi);
   if (argi < argc && ! CPP_FATAL_ERRORS (pfile))
index be377de6b7acdaacbdf7d360aa51984a8dce80fa..b3138488086a63b51ab21a0b1c4ebfa6bc369027 100644 (file)
@@ -611,7 +611,7 @@ read_scan_file (in_fname, argc, argv)
   obstack_init (&scan_file_obstack); 
 
   cpp_init ();                 /* Initialize cpplib.   */
-  cpp_reader_init (&scan_in);
+  cpp_reader_init (&scan_in, CLK_GNUC89);
 
   /* We are going to be scanning a header file out of its proper context,
      so ignore warnings and errors.  */
index bea5844937321280a5c47f22b93566fb7ba9e5c4..b1b0279fbd7283bef9ef86c63b582e7a398a648e 100644 (file)
@@ -700,7 +700,7 @@ lang_init_options ()
 {
 #if USE_CPPLIB
   cpp_init ();
-  cpp_reader_init (&parse_in);
+  cpp_reader_init (&parse_in, CLK_GNUC89);
 #endif
 }