OSDN Git Service

* unwind-dw2-fde.c (__deregister_frame_info): Stringize use
[pf3gnuchains/gcc-fork.git] / gcc / cpplib.c
index 5a523e0..96d296f 100644 (file)
@@ -311,7 +311,32 @@ _cpp_handle_directive (pfile, indented)
 
       /* If we are rescanning preprocessed input, only directives tagged
         with IN_I are honored, and the warnings below are suppressed.  */
-      if (! CPP_OPTION (pfile, preprocessed) || dir->flags & IN_I)
+      if (CPP_OPTION (pfile, preprocessed))
+       {
+         /* Kluge alert.  In order to be sure that code like this
+            #define HASH #
+            HASH define foo bar
+            does not cause '#define foo bar' to get executed when
+            compiled with -save-temps, we recognize directives in
+            -fpreprocessed mode only if the # is in column 1 and the
+            directive name starts in column 2.  This output can only
+            be generated by the directive callbacks in cppmain.c (see
+            also the special case in scan_buffer).  */
+         if (dir->flags & IN_I && !indented && !(dname.flags & PREV_WHITE))
+           (*dir->handler) (pfile);
+         /* That check misses '# 123' linemarkers.  Let them through too.  */
+         else if (dname.type == CPP_NUMBER)
+           (*dir->handler) (pfile);
+         else
+           {
+             /* We don't want to process this directive.  Put back the
+                tokens so caller will see them (and issue an error,
+                probably).  */
+             _cpp_push_token (pfile, &dname, &pfile->directive_pos);
+             skip = 0;
+           }
+       }
+      else
        {
          /* Traditionally, a directive is ignored unless its # is in
             column 1.  Therefore in code intended to work with K+R
@@ -429,7 +454,7 @@ lex_macro_node (pfile)
       else if (token.flags & NAMED_OP)
        cpp_error (pfile,
                   "\"%s\" cannot be used as a macro name as it is an operator in C++",
-                  token.val.node->name);
+                  NODE_NAME (token.val.node));
       else
        cpp_error (pfile, "macro names must be identifiers");
     }
@@ -439,8 +464,9 @@ lex_macro_node (pfile)
 
       /* In Objective C, some keywords begin with '@', but general
         identifiers do not, and you're not allowed to #define them.  */
-      if (node == pfile->spec_nodes.n_defined || node->name[0] == '@')
-       cpp_error (pfile, "\"%s\" cannot be used as a macro name", node->name);
+      if (node == pfile->spec_nodes.n_defined || NODE_NAME (node)[0] == '@')
+       cpp_error (pfile, "\"%s\" cannot be used as a macro name",
+                  NODE_NAME (node));
       else if (!(node->flags & NODE_POISONED))
        return node;
     }
@@ -478,7 +504,7 @@ do_undef (pfile)
        (*pfile->cb.undef) (pfile, node);
 
       if (node->flags & NODE_WARN)
-       cpp_warning (pfile, "undefining \"%s\"", node->name);
+       cpp_warning (pfile, "undefining \"%s\"", NODE_NAME (node));
 
       _cpp_free_definition (node);
     }
@@ -729,12 +755,7 @@ do_line (pfile)
   cpp_get_token (pfile, &token);
   if (token.type == CPP_STRING)
     {
-      char *fname;
-      unsigned int len = token.val.str.len + 1;
-
-      fname = (char *) _cpp_pool_alloc (&pfile->ident_pool, len);
-      memcpy (fname, token.val.str.text, len);
-      _cpp_simplify_pathname (fname);
+      const char *fname = (const char *) token.val.str.text;
 
       /* Only accept flags for the # 55 form.  */
       if (! pfile->state.line_extension)
@@ -779,6 +800,7 @@ do_line (pfile)
                {
                  cpp_pop_buffer (pfile);
                  buffer = pfile->buffer;
+#ifdef ENABLE_CHECKING
                  if (strcmp (buffer->nominal_fname, fname))
                    cpp_warning (pfile, "expected to return to file \"%s\"",
                                 buffer->nominal_fname);
@@ -788,6 +810,7 @@ do_line (pfile)
                  if (buffer->sysp != sysp)
                    cpp_warning (pfile, "header flags for \"%s\" have changed",
                                 buffer->nominal_fname);
+#endif
                }
            }
          buffer->sysp = sysp;
@@ -879,7 +902,8 @@ static void
 do_warning (pfile)
      cpp_reader *pfile;
 {
-  do_diagnostic (pfile, WARNING, 1);
+  /* We want #warning diagnostics to be emitted in system headers too.  */
+  do_diagnostic (pfile, WARNING_SYSHDR, 1);
 }
 
 /* Report program identification.  */
@@ -1008,9 +1032,6 @@ do_pragma (pfile)
 {
   const struct pragma_entry *p;
   cpp_token tok;
-  const cpp_hashnode *node;
-  const U_CHAR *name;
-  size_t len;
   int drop = 0;
 
   p = pfile->pragmas;
@@ -1021,12 +1042,13 @@ do_pragma (pfile)
   cpp_get_token (pfile, &tok);
   if (tok.type == CPP_NAME)
     {
-      node = tok.val.node;
-      name = node->name;
-      len = node->length;
+      const cpp_hashnode *node = tok.val.node;
+      size_t len = NODE_LEN (node);
+
       while (p)
        {
-         if (strlen (p->name) == len && !memcmp (p->name, name, len))
+         if (strlen (p->name) == len
+             && !memcmp (p->name, NODE_NAME (node), len))
            {
              if (p->isnspace)
                {
@@ -1091,7 +1113,7 @@ do_pragma_poison (pfile)
        continue;
 
       if (hp->type == NT_MACRO)
-       cpp_warning (pfile, "poisoning existing macro \"%s\"", hp->name);
+       cpp_warning (pfile, "poisoning existing macro \"%s\"", NODE_NAME (hp));
       _cpp_free_definition (hp);
       hp->flags |= NODE_POISONED | NODE_DIAGNOSTIC;
     }
@@ -1381,7 +1403,7 @@ do_endif (pfile)
 
       buffer->if_stack = ifs->next;
       buffer->was_skipping = ifs->was_skipping;
-      obstack_free (pfile->buffer_ob, ifs);
+      obstack_free (&pfile->buffer_ob, ifs);
     }
 
   check_eol (pfile);
@@ -1401,7 +1423,7 @@ push_conditional (pfile, skip, type, cmacro)
   struct if_stack *ifs;
   cpp_buffer *buffer = pfile->buffer;
 
-  ifs = xobnew (pfile->buffer_ob, struct if_stack);
+  ifs = xobnew (&pfile->buffer_ob, struct if_stack);
   ifs->pos = pfile->directive_pos;
   ifs->next = buffer->if_stack;
   ifs->was_skipping = buffer->was_skipping;
@@ -1519,12 +1541,12 @@ parse_assertion (pfile, answerp, type)
     cpp_error (pfile, "predicate must be an identifier");
   else if (parse_answer (pfile, answerp, type) == 0)
     {
-      unsigned int len = predicate.val.node->length;
+      unsigned int len = NODE_LEN (predicate.val.node);
       unsigned char *sym = alloca (len + 1);
 
       /* Prefix '#' to get it out of macro namespace.  */
       sym[0] = '#';
-      memcpy (sym + 1, predicate.val.node->name, len);
+      memcpy (sym + 1, NODE_NAME (predicate.val.node), len);
       result = cpp_lookup (pfile, sym, len + 1);
     }
 
@@ -1597,7 +1619,7 @@ do_assert (pfile)
        {
          if (*find_answer (node, new_answer))
            {
-             cpp_warning (pfile, "\"%s\" re-asserted", node->name + 1);
+             cpp_warning (pfile, "\"%s\" re-asserted", NODE_NAME (node) + 1);
              return;
            }
          new_answer->next = node->value.answers;
@@ -1782,7 +1804,7 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
      enum cpp_buffer_type type;
      const char *filename;
 {
-  cpp_buffer *new = xobnew (pfile->buffer_ob, cpp_buffer);
+  cpp_buffer *new = xobnew (&pfile->buffer_ob, cpp_buffer);
 
   if (type == BUF_FAKE)
     {
@@ -1817,7 +1839,10 @@ cpp_push_buffer (pfile, buffer, len, type, filename)
       pfile->lexer_pos.output_line = 1;
     }
 
-  new->nominal_fname = filename;
+  if (*filename == '\0')
+    new->nominal_fname = _("<stdin>");
+  else
+    new->nominal_fname = filename;
   new->type = type;
   new->prev = pfile->buffer;
   new->pfile = pfile;
@@ -1880,22 +1905,17 @@ cpp_pop_buffer (pfile)
                   buffer->nominal_fname);
     }
 
-  obstack_free (pfile->buffer_ob, buffer);
+  obstack_free (&pfile->buffer_ob, buffer);
   return pfile->buffer;
 }
 
-#define obstack_chunk_alloc xmalloc
-#define obstack_chunk_free free
 void
-_cpp_init_stacks (pfile)
+_cpp_init_directives (pfile)
      cpp_reader *pfile;
 {
   unsigned int i;
   cpp_hashnode *node;
 
-  pfile->buffer_ob = xnew (struct obstack);
-  obstack_init (pfile->buffer_ob);
-
   /* Register the directives.  */
   for (i = 0; i < (unsigned int) N_DIRECTIVES; i++)
     {
@@ -1903,11 +1923,3 @@ _cpp_init_stacks (pfile)
       node->directive_index = i + 1;
     }
 }
-
-void
-_cpp_cleanup_stacks (pfile)
-     cpp_reader *pfile;
-{
-  obstack_free (pfile->buffer_ob, 0);
-  free (pfile->buffer_ob);
-}