bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

#line %foo


From: Akim Demaille
Subject: #line %foo
Date: 06 Nov 2002 09:01:18 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

I'm installing the following patch.  I'm using #line in another
project, and now it does work (at least for  my usage).  The question
is how we want to free the mememory associated to file names.  We
could have a list of them, but I was thinking about having a hash that
makes all the strings unique.  This hash would share all the strings,
including those for identifiers etc. i.e., symtab would be on top of
it.  Then we simply have to free the hash at the end.

I'm OK with implementing this, I just need an agreement on the plan.

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        
        * src/main.c (main): Free `infile'.
        * src/scan-gram.l (directive, handle_syncline): New.
        When it starts with `%', complain about the whole directive, not
        just that `invalid character: %'.
        Recognize `#line'.
        * src/output.c (user_actions_output, symbol_destructors_output)
        (symbol_printers_output): Use the location's file name, not
        infile.
        * src/reader.c (prologue_augment, epilogue_set): Likewise.
        
Index: NEWS
--- NEWS Sun, 03 Nov 2002 18:04:59 +0100 akim
+++ NEWS Wed, 06 Nov 2002 08:51:08 +0100 akim
@@ -16,6 +16,9 @@
   In addition, they provide a means for yyerror to remain pure, and
   to access to the current location.
 
+* #line
+  Bison now recognize #line in its input, and forwards them.
+
 Changes in version 1.75, 2002-10-14:
 
 * Bison should now work on 64-bit hosts.
Index: TODO
--- TODO Tue, 05 Nov 2002 21:52:14 +0100 akim
+++ TODO Wed, 06 Nov 2002 08:51:24 +0100 akim
@@ -185,10 +185,6 @@ parsing: Theory and Practice' is impossi
 ** tests/pure-parser.at        []
 New tests.
 
-* input synclines
-Some users create their foo.y files, and equip them with #line.  Bison
-should recognize these, and preserve them.
-
 * BTYacc
 See if we can integrate backtracking in Bison.  Charles-Henri de
 Boysson <address@hidden> is working on this, and already has some
Index: src/getargs.c
--- src/getargs.c Sun, 27 Oct 2002 13:07:36 +0100 akim
+++ src/getargs.c Tue, 05 Nov 2002 22:42:38 +0100 akim
@@ -419,5 +419,5 @@ Output:\n\
       usage (EXIT_FAILURE);
     }
 
-  infile = argv[optind];
+  infile = xstrdup (argv[optind]);
 }
Index: src/main.c
--- src/main.c Sun, 27 Oct 2002 13:07:36 +0100 akim
+++ src/main.c Wed, 06 Nov 2002 09:01:19 +0100 akim
@@ -158,6 +158,8 @@
   reduce_free ();
   conflicts_free ();
   grammar_free ();
+  /* FIXME: We are leaking all the other file names.  */
+  free (infile);
 
   /* The scanner memory cannot be released right after parsing, as it
      contains things such as user actions, prologue, epilogue etc.  */
Index: src/output.c
--- src/output.c Sun, 03 Nov 2002 13:26:54 +0100 akim
+++ src/output.c Wed, 06 Nov 2002 07:47:07 +0100 akim
@@ -280,7 +280,7 @@
          fprintf (out, muscle_find ("linef"),
                   rules[r].action_location.first_line,
                   quotearg_style (c_quoting_style,
-                                  muscle_find ("filename")));
+                                  rules[r].action_location.file));
        fprintf (out, "    %s\n    break;\n\n",
                 rules[r].action);
       }
@@ -381,7 +381,8 @@
           destructor, typename. */
        fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
                 first ? "" : ",\n",
-                infile, symbol->destructor_location.first_line,
+                symbol->destructor_location.file,
+                symbol->destructor_location.first_line,
                 symbol->tag,
                 symbol->number,
                 symbol->destructor,
@@ -414,7 +415,8 @@
           printer, typename. */
        fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
                 first ? "" : ",\n",
-                infile, symbol->printer_location.first_line,
+                symbol->printer_location.file,
+                symbol->printer_location.first_line,
                 symbol->tag,
                 symbol->number,
                 symbol->printer,
Index: src/reader.c
--- src/reader.c Tue, 05 Nov 2002 21:52:14 +0100 akim
+++ src/reader.c Tue, 05 Nov 2002 23:34:08 +0100 akim
@@ -74,7 +74,7 @@
       obstack_fgrow2 (oout, muscle_find ("linef"),
                      location.first_line,
                      quotearg_style (c_quoting_style,
-                                     muscle_find ("filename")));
+                                     location.file));
     }
   obstack_sgrow (oout, prologue);
 }
@@ -94,7 +94,7 @@
       obstack_fgrow2 (&muscle_obstack, muscle_find ("linef"),
                      location.first_line,
                      quotearg_style (c_quoting_style,
-                                     muscle_find ("filename")));
+                                     location.file));
     }
   obstack_sgrow (&muscle_obstack, epilogue);
   obstack_1grow (&muscle_obstack, 0);
Index: src/scan-gram.l
--- src/scan-gram.l Tue, 05 Nov 2002 21:52:14 +0100 akim
+++ src/scan-gram.l Wed, 06 Nov 2002 08:58:31 +0100 akim
@@ -178,6 +178,7 @@
                           char *cp, location_t location);
 static void handle_at (braced_code_t code_kind,
                       char *cp, location_t location);
+static void handle_syncline (char *args, location_t *location);
 static int convert_ucn_to_byte (char const *hex_text);
 
 %}
@@ -186,9 +187,10 @@
 %x SC_ESCAPED_STRING SC_ESCAPED_CHARACTER
 %x SC_BRACED_CODE SC_PROLOGUE SC_EPILOGUE
 
-letter  [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
-id      {letter}({letter}|[0-9])*
-int     [0-9]+
+letter   [.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
+id       {letter}({letter}|[0-9])*
+directive %{letter}({letter}|[0-9]|-)*
+int      [0-9]+
 
 /* POSIX says that a tag must be both an id and a C union member, but
    historically almost any character is allowed in a tag.  We disallow
@@ -247,6 +249,13 @@
   "%verbose"              return PERCENT_VERBOSE;
   "%yacc"                 return PERCENT_YACC;
 
+  {directive}             {
+    complain_at (*yylloc, _("invalid directive: %s"), quote (yytext));
+    YY_STEP;
+  }
+
+  ^"#line "{int}" \""[^\"]*"\"\n"   handle_syncline (yytext + strlen ("#line 
"), yylloc); YY_STEP;
+
   "="                     return EQUAL;
   ":"                     rule_length = 0; return COLON;
   "|"                     rule_length = 0; return PIPE;
@@ -887,6 +896,24 @@
   return code;
 }
 
+
+/*----------------------------------------------------------------.
+| Handle `#line INT "FILE"'.  ARGS has already skipped `#line '.  |
+`----------------------------------------------------------------*/
+
+static void
+handle_syncline (char *args, location_t *location)
+{
+  int lineno = strtol (args, &args, 10);
+  const char *file = NULL;
+  file = strchr (args, '"') + 1;
+  *strchr (file, '"') = 0;
+  /* FIXME: Leaking...  Can't free, as some locations are still
+     pointing to the old file name.  */
+  infile = xstrdup (file);
+  location->file = infile;
+  location->last_line = lineno;
+}
 
 /*-------------------------.
 | Initialize the scanner.  |




reply via email to

[Prev in Thread] Current Thread [Next in Thread]