OSDN Git Service

* config/i386/i386.c (ix86_expand_prologue): Use
[pf3gnuchains/gcc-fork.git] / gcc / cpplex.c
index edb765d..3701415 100644 (file)
@@ -21,8 +21,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
 #include "system.h"
-#include "coretypes.h"
-#include "tm.h"
 #include "cpplib.h"
 #include "cpphash.h"
 
@@ -90,8 +88,8 @@ add_line_note (cpp_buffer *buffer, const uchar *pos, unsigned int type)
   if (buffer->notes_used == buffer->notes_cap)
     {
       buffer->notes_cap = buffer->notes_cap * 2 + 200;
-      buffer->notes = (_cpp_line_note *)
-       xrealloc (buffer->notes, buffer->notes_cap * sizeof (_cpp_line_note));
+      buffer->notes = xrealloc (buffer->notes,
+                               buffer->notes_cap * sizeof (_cpp_line_note));
     }
 
   buffer->notes[buffer->notes_used].pos = pos;
@@ -116,7 +114,57 @@ _cpp_clean_line (cpp_reader *pfile)
 
   if (!buffer->from_stage3)
     {
-      d = (uchar *) s;
+      /* Short circuit for the common case of an un-escaped line with
+        no trigraphs.  The primary win here is by not writing any
+        data back to memory until we have to.  */
+      for (;;)
+       {
+         c = *++s;
+         if (c == '\n' || c == '\r')
+           {
+             d = (uchar *) s;
+
+             if (s == buffer->rlimit)
+               goto done;
+
+             /* DOS line ending? */
+             if (c == '\r' && s[1] == '\n')
+               s++;
+
+             if (s == buffer->rlimit)
+               goto done;
+
+             /* check for escaped newline */
+             p = d;
+             while (p != buffer->next_line && is_nvspace (p[-1]))
+               p--;
+             if (p == buffer->next_line || p[-1] != '\\')
+               goto done;
+
+             /* Have an escaped newline; process it and proceed to
+                the slow path.  */
+             add_line_note (buffer, p - 1, p != d ? ' ' : '\\');
+             d = p - 2;
+             buffer->next_line = p - 1;
+             break;
+           }
+         if (c == '?' && s[1] == '?' && _cpp_trigraph_map[s[2]])
+           {
+             /* Have a trigraph.  We may or may not have to convert
+                it.  Add a line note regardless, for -Wtrigraphs.  */
+             add_line_note (buffer, s, s[2]);
+             if (CPP_OPTION (pfile, trigraphs))
+               {
+                 /* We do, and that means we have to switch to the
+                    slow path.  */
+                 d = (uchar *) s;
+                 *d = _cpp_trigraph_map[s[2]];
+                 s += 2;
+                 break;
+               }
+           }
+       }
+
 
       for (;;)
        {
@@ -166,6 +214,7 @@ _cpp_clean_line (cpp_reader *pfile)
        s++;
     }
 
+ done:
   *d = '\n';
   /* A sentinel note that should never be processed.  */
   add_line_note (buffer, d + 1, '\n');
@@ -246,9 +295,12 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment)
                                     note->type,
                                     (int) _cpp_trigraph_map[note->type]);
              else
-               cpp_error_with_line (pfile, DL_WARNING, pfile->line, col,
-                                    "trigraph ??%c ignored",
-                                    note->type);
+               {
+                 cpp_error_with_line 
+                   (pfile, DL_WARNING, pfile->line, col,
+                    "trigraph ??%c ignored, use -trigraphs to enable",
+                    note->type);
+               }
            }
        }
       else
@@ -265,43 +317,49 @@ bool
 _cpp_skip_block_comment (cpp_reader *pfile)
 {
   cpp_buffer *buffer = pfile->buffer;
-  cppchar_t c;
+  const uchar *cur = buffer->cur;
+  uchar c;
 
-  buffer->cur++;
-  if (*buffer->cur == '/')
-    buffer->cur++;
+  cur++;
+  if (*cur == '/')
+    cur++;
 
   for (;;)
     {
-      c = *buffer->cur++;
-
       /* People like decorating comments with '*', so check for '/'
         instead for efficiency.  */
+      c = *cur++;
+
       if (c == '/')
        {
-         if (buffer->cur[-2] == '*')
+         if (cur[-2] == '*')
            break;
 
          /* Warn about potential nested comments, but not if the '/'
             comes immediately before the true comment delimiter.
             Don't bother to get it right across escaped newlines.  */
          if (CPP_OPTION (pfile, warn_comments)
-             && buffer->cur[0] == '*' && buffer->cur[1] != '/')
-           cpp_error_with_line (pfile, DL_WARNING,
-                                pfile->line, CPP_BUF_COL (buffer),
-                                "\"/*\" within comment");
+             && cur[0] == '*' && cur[1] != '/')
+           {
+             buffer->cur = cur;
+             cpp_error_with_line (pfile, DL_WARNING,
+                                  pfile->line, CPP_BUF_COL (buffer),
+                                  "\"/*\" within comment");
+           }
        }
       else if (c == '\n')
        {
-         buffer->cur--;
+         buffer->cur = cur - 1;
          _cpp_process_line_notes (pfile, true);
          if (buffer->next_line >= buffer->rlimit)
            return true;
          _cpp_clean_line (pfile);
          pfile->line++;
+         cur = buffer->cur;
        }
     }
 
+  buffer->cur = cur;
   _cpp_process_line_notes (pfile, true);
   return false;
 }
@@ -718,16 +776,9 @@ _cpp_get_fresh_line (cpp_reader *pfile)
                               "no newline at end of file");
        }
  
-      if (!buffer->prev)
-       return false;
-
-      if (buffer->return_at_eof)
-       {
-         _cpp_pop_buffer (pfile);
-         return false;
-       }
-
       _cpp_pop_buffer (pfile);
+      if (pfile->buffer == NULL)
+       return false;
     }
 }
 
@@ -761,7 +812,8 @@ _cpp_lex_direct (cpp_reader *pfile)
 
  fresh_line:
   result->flags = 0;
-  if (pfile->buffer->need_line)
+  buffer = pfile->buffer;
+  if (buffer->need_line)
     {
       if (!_cpp_get_fresh_line (pfile))
        {
@@ -1422,8 +1474,7 @@ _cpp_extend_buff (cpp_reader *pfile, _cpp_buff **pbuff, size_t min_extra)
 
 /* Free a chain of buffers starting at BUFF.  */
 void
-_cpp_free_buff (buff)
-     _cpp_buff *buff;
+_cpp_free_buff (_cpp_buff *buff)
 {
   _cpp_buff *next;