OSDN Git Service

* Makefile.in (c-lex.o): Wrap long lines. Depend on debug.h.
[pf3gnuchains/gcc-fork.git] / gcc / f / lex.c
index 19cef88..70f666a 100644 (file)
@@ -1,6 +1,6 @@
 /* Implementation of Fortran lexer
-   Copyright (C) 1995-1998 Free Software Foundation, Inc.
-   Contributed by James Craig Burley (burley@gnu.org).
+   Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+   Contributed by James Craig Burley.
 
 This file is part of GNU Fortran.
 
@@ -26,21 +26,15 @@ the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "lex.h"
 #include "malloc.h"
 #include "src.h"
+#include "debug.h"
 #if FFECOM_targetCURRENT == FFECOM_targetGCC
-#include "flags.j"
-#include "input.j"
-#include "toplev.j"
-#include "tree.j"
-#include "output.j"  /* Must follow tree.j so TREE_CODE is defined! */
+#include "flags.h"
+#include "input.h"
+#include "toplev.h"
+#include "output.h"
+#include "ggc.h"
 #endif
 
-#ifdef DWARF_DEBUGGING_INFO
-void dwarfout_resume_previous_source_file (register unsigned);
-void dwarfout_start_new_source_file (register char *);
-void dwarfout_define (register unsigned, register char *);
-void dwarfout_undef (register unsigned, register char *);
-#endif DWARF_DEBUGGING_INFO
-
 static void ffelex_append_to_token_ (char c);
 static int ffelex_backslash_ (int c, ffewhereColumnNumber col);
 static void ffelex_bad_1_ (ffebad errnum, ffewhereLineNumber ln0,
@@ -806,7 +800,7 @@ ffelex_cfelex_ (ffelexToken *xtoken, FILE *finput, int c)
 
            case EOF:
            case '\n':
-             fatal ("Badly formed directive -- no closing quote");
+             error ("Badly formed directive -- no closing quote");
              done = TRUE;
              break;
 
@@ -855,7 +849,7 @@ ffelex_cfelex_ (ffelexToken *xtoken, FILE *finput, int c)
 
 #if FFECOM_targetCURRENT == FFECOM_targetGCC
 static void
-ffelex_file_pop_ (char *input_filename)
+ffelex_file_pop_ (const char *input_filename)
 {
   if (input_file_stack->next)
     {
@@ -863,11 +857,8 @@ ffelex_file_pop_ (char *input_filename)
       input_file_stack = p->next;
       free (p);
       input_file_stack_tick++;
-#ifdef DWARF_DEBUGGING_INFO
-      if (debug_info_level == DINFO_LEVEL_VERBOSE
-         && write_symbols == DWARF_DEBUG)
-       dwarfout_resume_previous_source_file (input_file_stack->line);
-#endif /* DWARF_DEBUGGING_INFO */
+      if (write_symbols == DWARF_DEBUG)
+       (*debug_hooks->end_source_file) (input_file_stack->line);
     }
   else
     error ("#-lines for entering and leaving files don't match");
@@ -881,7 +872,7 @@ ffelex_file_pop_ (char *input_filename)
 #endif
 #if FFECOM_targetCURRENT == FFECOM_targetGCC
 static void
-ffelex_file_push_ (int old_lineno, char *input_filename)
+ffelex_file_push_ (int old_lineno, const char *input_filename)
 {
   struct file_stack *p
     = (struct file_stack *) xmalloc (sizeof (struct file_stack));
@@ -891,11 +882,9 @@ ffelex_file_push_ (int old_lineno, char *input_filename)
   p->name = input_filename;
   input_file_stack = p;
   input_file_stack_tick++;
-#ifdef DWARF_DEBUGGING_INFO
-  if (debug_info_level == DINFO_LEVEL_VERBOSE
-      && write_symbols == DWARF_DEBUG)
-    dwarfout_start_new_source_file (input_filename);
-#endif /* DWARF_DEBUGGING_INFO */
+
+  if (write_symbols == DWARF_DEBUG)
+    (*debug_hooks->start_source_file) (0, input_filename);
 
   /* Now that we've pushed or popped the input stack,
      update the name in the top element.  */
@@ -1039,7 +1028,7 @@ ffelex_get_directive_line_ (char **text, FILE *finput)
          || c == EOF)
        {
          if (looking_for != 0)
-           fatal ("Bad directive -- missing close-quote");
+           error ("Bad directive -- missing close-quote");
 
          *p++ = '\0';
          *text = directive_buffer;
@@ -1126,8 +1115,9 @@ ffelex_hash_ (FILE *finput)
              static char buffer [128];
              char * buff = buffer;
 
-             /* Read the pragma name into a buffer.  */
-             while (isspace (c = getc (finput)))
+             /* Read the pragma name into a buffer.
+                ISSPACE() may evaluate its argument more than once!  */
+             while (((c = getc (finput)), ISSPACE(c)))
                continue;
              
              do
@@ -1135,7 +1125,7 @@ ffelex_hash_ (FILE *finput)
                  * buff ++ = c;
                  c = getc (finput);
                }
-             while (c != EOF && ! isspace (c) && c != '\n'
+             while (c != EOF && ! ISSPACE (c) && c != '\n'
                     && buff < buffer + 128);
 
              pragma_ungetc (c);
@@ -1175,11 +1165,9 @@ ffelex_hash_ (FILE *finput)
 
              c = ffelex_get_directive_line_ (&text, finput);
 
-#ifdef DWARF_DEBUGGING_INFO
              if ((debug_info_level == DINFO_LEVEL_VERBOSE)
                  && (write_symbols == DWARF_DEBUG))
-               dwarfout_define (lineno, text);
-#endif /* DWARF_DEBUGGING_INFO */
+               (*debug_hooks->define) (lineno, text);
 
              goto skipline;
            }
@@ -1197,11 +1185,9 @@ ffelex_hash_ (FILE *finput)
 
              c = ffelex_get_directive_line_ (&text, finput);
 
-#ifdef DWARF_DEBUGGING_INFO
              if ((debug_info_level == DINFO_LEVEL_VERBOSE)
                  && (write_symbols == DWARF_DEBUG))
-               dwarfout_undef (lineno, text);
-#endif /* DWARF_DEBUGGING_INFO */
+               (*debug_hooks->undef) (lineno, text);
 
              goto skipline;
            }
@@ -1222,7 +1208,7 @@ ffelex_hash_ (FILE *finput)
              && getc (finput) == 't'
              && ((c = getc (finput)) == ' ' || c == '\t'))
            {
-             /* #ident.  The pedantic warning is now in cccp.c.  */
+             /* #ident.  The pedantic warning is now in cpp.  */
 
              /* Here we have just seen `#ident '.
                 A string constant should follow.  */
@@ -1280,7 +1266,7 @@ ffelex_hash_ (FILE *finput)
       && (ffelex_token_type (token) == FFELEX_typeNUMBER))
     {
       int old_lineno = lineno;
-      char *old_input_filename = input_filename;
+      const char *old_input_filename = input_filename;
       ffewhereFile wf;
 
       /* subtract one, because it is the following line that
@@ -1319,7 +1305,7 @@ ffelex_hash_ (FILE *finput)
       lineno = l;
 
       if (ffelex_kludge_flag_)
-       input_filename = ffelex_token_text (token);
+       input_filename = ggc_strdup (ffelex_token_text (token));
       else
        {
          wf = ffewhere_file_new (ffelex_token_text (token),
@@ -1368,7 +1354,7 @@ ffelex_hash_ (FILE *finput)
            {
              lineno = 1;
              input_filename = old_input_filename;
-             fatal ("Use `#line ...' instead of `# ...' in first line");
+             error ("Use `#line ...' instead of `# ...' in first line");
            }
 
          if (num == 1)
@@ -1412,7 +1398,13 @@ ffelex_hash_ (FILE *finput)
        {
          lineno = 1;
          input_filename = old_input_filename;
-         fatal ("Use `#line ...' instead of `# ...' in first line");
+         error ("Use `#line ...' instead of `# ...' in first line");
+       }
+      if (c == '\n' || c == EOF)
+       {
+         if (token != NULL && !ffelex_kludge_flag_)
+           ffelex_token_kill (token);
+         return c;
        }
     }
   else
@@ -1552,7 +1544,7 @@ ffelex_include_ ()
     = ffewhere_line_filelinenum (current_wl);
 #if FFECOM_targetCURRENT == FFECOM_targetGCC
   int old_lineno = lineno;
-  char *old_input_filename = input_filename;
+  const char *old_input_filename = input_filename;
 #endif
 
   if (card_length != 0)
@@ -1751,10 +1743,10 @@ ffelex_token_new_ ()
   return t;
 }
 
-static char *
+static const char *
 ffelex_type_string_ (ffelexType type)
 {
-  static char *types[] = {
+  static const char *types[] = {
     "FFELEX_typeNONE",
     "FFELEX_typeCOMMENT",
     "FFELEX_typeEOS",
@@ -4546,7 +4538,7 @@ ffelex_token_names_from_names (ffelexToken t, ffeTokenLength start,
 /* Make a new CHARACTER token.  */
 
 ffelexToken
-ffelex_token_new_character (char *s, ffewhereLine l, ffewhereColumn c)
+ffelex_token_new_character (const char *s, ffewhereLine l, ffewhereColumn c)
 {
   ffelexToken t;
 
@@ -4581,7 +4573,7 @@ ffelex_token_new_eof ()
 /* Make a new NAME token.  */
 
 ffelexToken
-ffelex_token_new_name (char *s, ffewhereLine l, ffewhereColumn c)
+ffelex_token_new_name (const char *s, ffewhereLine l, ffewhereColumn c)
 {
   ffelexToken t;
 
@@ -4602,7 +4594,7 @@ ffelex_token_new_name (char *s, ffewhereLine l, ffewhereColumn c)
 /* Make a new NAMES token.  */
 
 ffelexToken
-ffelex_token_new_names (char *s, ffewhereLine l, ffewhereColumn c)
+ffelex_token_new_names (const char *s, ffewhereLine l, ffewhereColumn c)
 {
   ffelexToken t;
 
@@ -4631,7 +4623,7 @@ ffelex_token_new_names (char *s, ffewhereLine l, ffewhereColumn c)
    in the original string.  */
 
 ffelexToken
-ffelex_token_new_number (char *s, ffewhereLine l, ffewhereColumn c)
+ffelex_token_new_number (const char *s, ffewhereLine l, ffewhereColumn c)
 {
   ffelexToken t;
   ffeTokenLength len;