cpplib.c (read_line_number): New fn, split out of...
authorJason Merrill <jason@yorick.cygnus.com>
Sat, 14 Aug 1999 00:42:07 +0000 (00:42 +0000)
committerJason Merrill <jason@gcc.gnu.org>
Sat, 14 Aug 1999 00:42:07 +0000 (20:42 -0400)
* cpplib.c (read_line_number): New fn, split out of...
(do_line): Here.

From-SVN: r28707

gcc/ChangeLog
gcc/cpplib.c

index eaed975..0db08ba 100644 (file)
@@ -1,3 +1,8 @@
+Fri Aug 13 17:41:55 1999  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * cpplib.c (read_line_number): New fn, split out of...
+       (do_line): Here.
+
 Fri Aug 13 14:18:27 1999  Gavin Romig-Koch  <gavin@cygnus.com>
 
        tree.c (lang_unsave_expr_now) : New.
index f2fadf2..06b1717 100644 (file)
@@ -1208,6 +1208,34 @@ do_include (pfile, keyword)
   return 0;
 }
 
+/* Subroutine of do_line.  Read next token from PFILE without adding it to
+   the output buffer.  If it is a number between 1 and 4, store it in *NUM
+   and return 1; otherwise, return 0 and complain if we aren't at the end
+   of the directive.  */
+
+static int
+read_line_number (pfile, num)
+     cpp_reader *pfile;
+     int *num;
+{
+  long save_written = CPP_WRITTEN (pfile);
+  U_CHAR *p = pfile->token_buffer + save_written;
+  enum cpp_token token = get_directive_token (pfile);
+  CPP_SET_WRITTEN (pfile, save_written);
+
+  if (token == CPP_NUMBER && *p >= '1' && *p <= '4' && p[1] == '\0')
+    {
+      *num = p[0] - '0';
+      return 1;
+    }
+  else
+    {
+      if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
+       cpp_error (pfile, "invalid format `#line' command");
+      return 0;
+    }
+}
+
 /* Interpret #line command.
    Note that the filename string (if any) is treated as if it were an
    include filename.  That means no escape handling.  */
@@ -1249,41 +1277,32 @@ do_line (pfile, keyword)
     {
       U_CHAR *fname = pfile->token_buffer + old_written + 1;
       U_CHAR *end_name = CPP_PWRITTEN (pfile) - 1;
-      long num_start = CPP_WRITTEN (pfile);
+      int action_number = 0;
 
-      token = get_directive_token (pfile);
-      if (token != CPP_VSPACE && token != CPP_EOF && token != CPP_POP)
+      if (read_line_number (pfile, &action_number))
        {
-         U_CHAR *p = pfile->token_buffer + num_start;
          if (CPP_PEDANTIC (pfile))
            cpp_pedwarn (pfile, "garbage at end of `#line' command");
 
-         if (token != CPP_NUMBER || *p < '0' || *p > '4' || p[1] != '\0')
+         if (action_number == 1)
+           {
+             file_change = enter_file;
+             read_line_number (pfile, &action_number);
+           }
+         else if (action_number == 2)
            {
-             cpp_error (pfile, "invalid format `#line' command");
-             goto bad_line_directive;
+             file_change = leave_file;
+             read_line_number (pfile, &action_number);
            }
-         if (*p == '1')
-           file_change = enter_file;
-         else if (*p == '2')
-           file_change = leave_file;
-         else if (*p == '3')
-           ip->system_header_p = 1;
-         else /* if (*p == '4') */
-           ip->system_header_p = 2;
-
-         CPP_SET_WRITTEN (pfile, num_start);
-         token = get_directive_token (pfile);
-         p = pfile->token_buffer + num_start;
-         if (token == CPP_NUMBER && p[1] == '\0' && (*p == '3' || *p== '4'))
+         if (action_number == 3)
            {
-             ip->system_header_p = *p == '3' ? 1 : 2;
-             token = get_directive_token (pfile);
+             ip->system_header_p = 1;
+             read_line_number (pfile, &action_number);
            }
-         if (token != CPP_VSPACE)
+         if (action_number == 4)
            {
-             cpp_error (pfile, "invalid format `#line' command");
-             goto bad_line_directive;
+             ip->system_header_p = 2;
+             read_line_number (pfile, &action_number);
            }
        }