OSDN Git Service

Merge from pch-branch up to tag pch-commit-20020603.
[pf3gnuchains/gcc-fork.git] / gcc / cppinit.c
index 4f2cc8e..580ef35 100644 (file)
@@ -98,6 +98,7 @@ static void path_include              PARAMS ((cpp_reader *,
                                                 char *, int));
 static void init_library               PARAMS ((void));
 static void init_builtins              PARAMS ((cpp_reader *));
+static void mark_named_operators       PARAMS ((cpp_reader *));
 static void append_include_chain       PARAMS ((cpp_reader *,
                                                 char *, int, int));
 static struct search_path * remove_dup_dir     PARAMS ((cpp_reader *,
@@ -206,7 +207,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
      cpp_reader *pfile;
      char *dir;
      int path;
-     int cxx_aware ATTRIBUTE_UNUSED;
+     int cxx_aware;
 {
   struct cpp_pending *pend = CPP_OPTION (pfile, pending);
   struct search_path *new;
@@ -251,11 +252,7 @@ append_include_chain (pfile, dir, path, cxx_aware)
      include files since these two lists are really just a concatenation
      of one "system" list.  */
   if (path == SYSTEM || path == AFTER)
-#ifdef NO_IMPLICIT_EXTERN_C
-    new->sysp = 1;
-#else
     new->sysp = cxx_aware ? 1 : 2;
-#endif
   else
     new->sysp = 0;
   new->name_map = NULL;
@@ -303,7 +300,7 @@ remove_dup_dirs (pfile, head)
   for (cur = head; cur; cur = cur->next)
     {
       for (other = head; other != cur; other = other->next)
-        if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
+       if (INO_T_EQ (cur->ino, other->ino) && cur->dev == other->dev)
          {
            if (cur->sysp && !other->sysp)
              {
@@ -419,7 +416,7 @@ set_lang (pfile, lang)
      enum c_lang lang;
 {
   const struct lang_flags *l = &lang_defaults[(int) lang];
-  
+
   CPP_OPTION (pfile, lang) = lang;
 
   CPP_OPTION (pfile, c99)               = l->c99;
@@ -495,12 +492,11 @@ cpp_create_reader (lang)
 
   /* Default CPP arithmetic to something sensible for the host for the
      benefit of dumb users like fix-header.  */
-#define BITS_PER_HOST_WIDEST_INT (CHAR_BIT * sizeof (HOST_WIDEST_INT))
-  CPP_OPTION (pfile, precision) = BITS_PER_HOST_WIDEST_INT;
+  CPP_OPTION (pfile, precision) = CHAR_BIT * sizeof (long);
   CPP_OPTION (pfile, char_precision) = CHAR_BIT;
   CPP_OPTION (pfile, wchar_precision) = CHAR_BIT * sizeof (int);
   CPP_OPTION (pfile, int_precision) = CHAR_BIT * sizeof (int);
-  CPP_OPTION (pfile, unsigned_char) = !DEFAULT_SIGNED_CHAR;
+  CPP_OPTION (pfile, unsigned_char) = 0;
   CPP_OPTION (pfile, unsigned_wchar) = 1;
 
   /* It's simplest to just create this struct whether or not it will
@@ -664,6 +660,23 @@ static const struct builtin operator_array[] =
 };
 #undef B
 
+/* Mark the C++ named operators in the hash table.  */
+static void
+mark_named_operators (pfile)
+     cpp_reader *pfile;
+{
+  const struct builtin *b;
+
+  for (b = operator_array;
+       b < (operator_array + ARRAY_SIZE (operator_array));
+       b++)
+    {
+      cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
+      hp->flags |= NODE_OPERATOR;
+      hp->value.operator = b->value;
+    }
+}
+
 /* Subroutine of cpp_read_main_file; reads the builtins table above and
    enters them, and language-specific macros, into the hash table.  */
 static void
@@ -682,37 +695,18 @@ init_builtins (pfile)
       hp->value.builtin = b->value;
     }
 
-  if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
-    for (b = operator_array;
-        b < (operator_array + ARRAY_SIZE (operator_array));
-        b++)
-      {
-       cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
-       hp->flags |= NODE_OPERATOR;
-       hp->value.operator = b->value;
-      }
-
   if (CPP_OPTION (pfile, cplusplus))
     _cpp_define_builtin (pfile, "__cplusplus 1");
-
-  if (CPP_OPTION (pfile, objc))
+  else if (CPP_OPTION (pfile, objc))
     _cpp_define_builtin (pfile, "__OBJC__ 1");
+  else if (CPP_OPTION (pfile, lang) == CLK_ASM)
+    _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
 
   if (CPP_OPTION (pfile, lang) == CLK_STDC94)
     _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
   else if (CPP_OPTION (pfile, c99))
     _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
 
-  if (CPP_OPTION (pfile, unsigned_char))
-    _cpp_define_builtin (pfile, "__CHAR_UNSIGNED__ 1");
-
-  if (CPP_OPTION (pfile, lang) == CLK_STDC89
-      || CPP_OPTION (pfile, lang) == CLK_STDC94
-      || CPP_OPTION (pfile, lang) == CLK_STDC99)
-    _cpp_define_builtin (pfile, "__STRICT_ANSI__ 1");
-  else if (CPP_OPTION (pfile, lang) == CLK_ASM)
-    _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
-
   if (pfile->cb.register_builtins)
     (*pfile->cb.register_builtins) (pfile);
 }
@@ -849,39 +843,44 @@ static void sanity_checks (pfile)
      cpp_reader *pfile;
 {
   cppchar_t test = 0;
+  size_t max_precision = 2 * CHAR_BIT * sizeof (cpp_num_part);
 
   /* Sanity checks for assumptions about CPP arithmetic and target
      type precisions made by cpplib.  */
   test--;
   if (test < 1)
-    cpp_error (pfile, DL_FATAL, "cppchar_t must be an unsigned type");
+    cpp_error (pfile, DL_ICE, "cppchar_t must be an unsigned type");
 
-  if (CPP_OPTION (pfile, precision) > BITS_PER_HOST_WIDEST_INT)
-    cpp_error (pfile, DL_FATAL,
+  if (CPP_OPTION (pfile, precision) > max_precision)
+    cpp_error (pfile, DL_ICE,
               "preprocessor arithmetic has maximum precision of %lu bits; target requires %lu bits",
-              (unsigned long)BITS_PER_HOST_WIDEST_INT,
-              (unsigned long)CPP_OPTION (pfile, precision));
+              (unsigned long) max_precision,
+              (unsigned long) CPP_OPTION (pfile, precision));
 
   if (CPP_OPTION (pfile, precision) < CPP_OPTION (pfile, int_precision))
-    cpp_error (pfile, DL_FATAL,
+    cpp_error (pfile, DL_ICE,
               "CPP arithmetic must be at least as precise as a target int");
 
   if (CPP_OPTION (pfile, char_precision) < 8)
-    cpp_error (pfile, DL_FATAL, "target char is less than 8 bits wide");
+    cpp_error (pfile, DL_ICE, "target char is less than 8 bits wide");
 
   if (CPP_OPTION (pfile, wchar_precision) < CPP_OPTION (pfile, char_precision))
-    cpp_error (pfile, DL_FATAL,
+    cpp_error (pfile, DL_ICE,
               "target wchar_t is narrower than target char");
 
   if (CPP_OPTION (pfile, int_precision) < CPP_OPTION (pfile, char_precision))
-    cpp_error (pfile, DL_FATAL,
+    cpp_error (pfile, DL_ICE,
               "target int is narrower than target char");
 
+  /* This is assumed in eval_token() and could be fixed if necessary.  */
+  if (sizeof (cppchar_t) > sizeof (cpp_num_part))
+    cpp_error (pfile, DL_ICE, "CPP half-integer narrower than CPP character");
+
   if (CPP_OPTION (pfile, wchar_precision) > BITS_PER_CPPCHAR_T)
-    cpp_error (pfile, DL_FATAL,
+    cpp_error (pfile, DL_ICE,
               "CPP on this host cannot handle wide character constants over %lu bits, but the target requires %lu bits",
-              (unsigned long)BITS_PER_CPPCHAR_T,
-              (unsigned long)CPP_OPTION (pfile, wchar_precision));
+              (unsigned long) BITS_PER_CPPCHAR_T,
+              (unsigned long) CPP_OPTION (pfile, wchar_precision));
 }
 #else
 # define sanity_checks(PFILE)
@@ -985,6 +984,10 @@ void
 cpp_finish_options (pfile)
      cpp_reader *pfile;
 {
+  /* Mark named operators before handling command line macros.  */
+  if (CPP_OPTION (pfile, cplusplus) && CPP_OPTION (pfile, operator_names))
+    mark_named_operators (pfile);
+
   /* Install builtins and process command line macros etc. in the order
      they appeared, but only if not already preprocessed.  */
   if (! CPP_OPTION (pfile, preprocessed))
@@ -1022,7 +1025,7 @@ _cpp_maybe_push_include_file (pfile)
   if (pfile->next_include_file)
     {
       struct pending_option *head = *pfile->next_include_file;
-  
+
       while (head && !push_include (pfile, head))
        head = head->next;
 
@@ -1070,7 +1073,7 @@ output_deps (pfile)
   if (deps_stream != stdout)
     {
       if (ferror (deps_stream) || fclose (deps_stream) != 0)
-       cpp_error (pfile, DL_FATAL, "I/O error on output");
+       cpp_error (pfile, DL_ERROR, "I/O error on output");
     }
 }
 
@@ -1158,9 +1161,7 @@ new_pending_directive (pend, text, handler)
   DEF_OPT("fno-show-column",          0,      OPT_fno_show_column)            \
   DEF_OPT("fpreprocessed",            0,      OPT_fpreprocessed)              \
   DEF_OPT("fshow-column",             0,      OPT_fshow_column)               \
-  DEF_OPT("fsigned-char",             0,      OPT_fsigned_char)               \
   DEF_OPT("ftabstop=",                no_num, OPT_ftabstop)                   \
-  DEF_OPT("funsigned-char",           0,      OPT_funsigned_char)             \
   DEF_OPT("h",                        0,      OPT_h)                          \
   DEF_OPT("idirafter",                no_dir, OPT_idirafter)                  \
   DEF_OPT("imacros",                  no_fil, OPT_imacros)                    \
@@ -1311,7 +1312,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
       else if (CPP_OPTION (pfile, out_fname) == NULL)
        CPP_OPTION (pfile, out_fname) = argv[i];
       else
-       cpp_error (pfile, DL_FATAL,
+       cpp_error (pfile, DL_ERROR,
                   "too many filenames. Type %s --help for usage info",
                   progname);
     }
@@ -1339,7 +1340,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
              arg = argv[++i];
              if (!arg)
                {
-                 cpp_error (pfile, DL_FATAL,
+                 cpp_error (pfile, DL_ERROR,
                             cl_options[opt_index].msg, argv[i - 1]);
                  return argc;
                }
@@ -1365,12 +1366,6 @@ cpp_handle_option (pfile, argc, argv, ignore)
        case OPT_fno_show_column:
          CPP_OPTION (pfile, show_column) = 0;
          break;
-       case OPT_fsigned_char:
-         CPP_OPTION (pfile, unsigned_char) = 0;
-         break;
-       case OPT_funsigned_char:
-         CPP_OPTION (pfile, unsigned_char) = 1;
-         break;
        case OPT_ftabstop:
          /* Silently ignore empty string, non-longs and silly values.  */
          if (arg[0] != '\0')
@@ -1390,10 +1385,10 @@ cpp_handle_option (pfile, argc, argv, ignore)
          CPP_OPTION (pfile, help_only) = 1;
          break;
        case OPT_target__help:
-          /* Print if any target specific options. cpplib has none, but
+         /* Print if any target specific options. cpplib has none, but
             make sure help_only gets set.  */
          CPP_OPTION (pfile, help_only) = 1;
-          break;
+         break;
 
          /* --version inhibits compilation, -version doesn't. -v means
             verbose and -version.  Historical reasons, don't ask.  */
@@ -1432,11 +1427,11 @@ cpp_handle_option (pfile, argc, argv, ignore)
          CPP_OPTION (pfile, pedantic_errors) = 1;
          /* fall through */
        case OPT_pedantic:
-         CPP_OPTION (pfile, pedantic) = 1;
+         CPP_OPTION (pfile, pedantic) = 1;
          CPP_OPTION (pfile, warn_endif_labels) = 1;
          break;
        case OPT_trigraphs:
-         CPP_OPTION (pfile, trigraphs) = 1;
+         CPP_OPTION (pfile, trigraphs) = 1;
          break;
        case OPT_remap:
          CPP_OPTION (pfile, remap) = 1;
@@ -1498,7 +1493,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
            CPP_OPTION (pfile, out_fname) = arg;
          else
            {
-             cpp_error (pfile, DL_FATAL, "output filename specified twice");
+             cpp_error (pfile, DL_ERROR, "output filename specified twice");
              return argc;
            }
          break;
@@ -1506,13 +1501,13 @@ cpp_handle_option (pfile, argc, argv, ignore)
          /* Args to -d specify what parts of macros to dump.
             Silently ignore unrecognised options; they may
             be aimed at the compiler proper.  */
-         {
+         {
            char c;
 
            while ((c = *arg++) != '\0')
-             switch (c)
-               {
-               case 'M':
+             switch (c)
+               {
+               case 'M':
                  CPP_OPTION (pfile, dump_macros) = dump_only;
                  break;
                case 'N':
@@ -1546,7 +1541,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
        case OPT_MF:
          CPP_OPTION (pfile, deps_file) = arg;
          break;
-       case OPT_MP:
+       case OPT_MP:
          CPP_OPTION (pfile, deps_phony_targets) = 1;
          break;
        case OPT_MQ:
@@ -1592,7 +1587,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
          break;
        case OPT_I:           /* Add directory to path for includes.  */
          if (!strcmp (arg, "-"))
-           {
+           {
              /* -I- means:
                 Use the preceding -I directories for #include "..."
                 but not #include <...>.
@@ -1609,11 +1604,11 @@ cpp_handle_option (pfile, argc, argv, ignore)
                }
              else
                {
-                 cpp_error (pfile, DL_FATAL, "-I- specified twice");
+                 cpp_error (pfile, DL_ERROR, "-I- specified twice");
                  return argc;
                }
-           }
-         else
+           }
+         else
            append_include_chain (pfile, xstrdup (arg), BRACKET, 0);
          break;
        case OPT_isystem:
@@ -1718,7 +1713,7 @@ cpp_handle_option (pfile, argc, argv, ignore)
          else if (! ignore)
            return i;
          break;
-       }
+       }
     }
   return i + 1;
 }
@@ -1775,6 +1770,11 @@ cpp_post_options (pfile)
   if (CPP_OPTION (pfile, cplusplus))
     CPP_OPTION (pfile, warn_traditional) = 0;
 
+  /* The compiler front ends override this, but I think this is the
+     appropriate setting for the library.  */
+  CPP_OPTION (pfile, warn_long_long) = (CPP_OPTION (pfile, pedantic)
+                                       && !CPP_OPTION (pfile, c99));
+
   /* Permanently disable macro expansion if we are rescanning
      preprocessed text.  Read preprocesed source in ISO mode.  */
   if (CPP_OPTION (pfile, preprocessed))
@@ -1813,7 +1813,7 @@ cpp_post_options (pfile)
       (CPP_OPTION (pfile, print_deps_missing_files)
        || CPP_OPTION (pfile, deps_file)
        || CPP_OPTION (pfile, deps_phony_targets)))
-    cpp_error (pfile, DL_FATAL,
+    cpp_error (pfile, DL_ERROR,
               "you must additionally specify either -M or -MM");
 }