bison-patches
[Top][All Lists]
Advanced

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

[PATCH 3/6] java: use full locations for diagnostics about destructors


From: Akim Demaille
Subject: [PATCH 3/6] java: use full locations for diagnostics about destructors
Date: Wed, 3 Apr 2019 19:17:05 +0200

Currently we use the syncline to report errors about a symbol's
destructor/printer.  This is not accurate (only file and line), and
this is incorrect: the file name is double quotes (a recent change,
needed to make sure we escape properly double quotes in it).  And
worst of all: with --no-line, b4_syncline expands to nothing.

Rather, push the locations into the backend, and use them.

* src/muscle-tab.h, src/muscle-tab.c (muscle_location_grow): Make it
public.
* src/output.c (prepare_symbol_definitions): Use it to pubish the
location of the printer and destructor.
* data/skeletons/lalr1.java: Use complain_at instead of complain.
* tests/java.at (Java invalid directives): Adjust expectations.
* data/skeletons/bison.m4 (b4_symbol_action_location): Remove.
We should not use b4_syncline this way.
---
 data/README.md            | 3 ++-
 data/skeletons/bison.m4   | 7 -------
 data/skeletons/lalr1.java | 8 +++-----
 src/muscle-tab.c          | 6 +-----
 src/muscle-tab.h          | 5 +++++
 src/output.c              | 3 +++
 tests/java.at             | 6 ++++--
 7 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/data/README.md b/data/README.md
index ed217365..94e9891b 100644
--- a/data/README.md
+++ b/data/README.md
@@ -138,9 +138,10 @@ The macro `b4_symbol(NUM, FIELD)` gives access to the 
following FIELDS:
 - `printer`: string
 - `printer_file`: string
 - `printer_line`: integer
+- `printer_loc`: location
   If the symbol has a printer, everything about it.
 
-- `has_destructor`, `destructor`, `destructor_file`, `destructor_line`
+- `has_destructor`, `destructor`, `destructor_file`, `destructor_line`, 
`destructor_loc`
   Likewise.
 
 ### `b4_symbol_value(VAL, [SYMBOL-NUM], [TYPE-TAG])`
diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index cefe6a91..fd4c2836 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -438,13 +438,6 @@ m4_define([b4_symbol_tag_comment],
 ])
 
 
-# b4_symbol_action_location(SYMBOL-NUM, KIND)
-# -------------------------------------------
-# Report the location of the KIND action as FILE:LINE.
-m4_define([b4_symbol_action_location],
-[b4_symbol([$1], [$2_file]):b4_syncline([b4_symbol([$1], [$2_line])])])
-
-
 # b4_symbol_action(SYMBOL-NUM, KIND)
 # ----------------------------------
 # Run the action KIND (destructor or printer) for SYMBOL-NUM.
diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 0356d46d..62ae80da 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -17,8 +17,7 @@
 
 m4_include(b4_skeletonsdir/[java.m4])
 
-b4_defines_if([b4_complain([%s: %%defines does not make sense in Java],
-              [b4_skeleton])])
+b4_defines_if([b4_complain([%defines does not make sense in Java])])
 
 # We do not depend on %debug in Java, but pacify warnings about
 # non-used flags.
@@ -26,9 +25,8 @@ b4_parse_trace_if([0], [0])
 
 m4_define([b4_symbol_no_destructor_assert],
 [b4_symbol_if([$1], [has_destructor],
-              [b4_complain([%s: %s: %%destructor does not make sense in Java],
-                        [b4_skeleton],
-                        [b4_symbol_action_location([$1], [destructor])])])])
+              [b4_complain_at(m4_unquote(b4_symbol([$1], [destructor_loc])),
+                              [%destructor does not make sense in Java])])])
 b4_symbol_foreach([b4_symbol_no_destructor_assert])
 
 # Setup some macros for api.push-pull.
diff --git a/src/muscle-tab.c b/src/muscle-tab.c
index 8a1b00fc..118dbf23 100644
--- a/src/muscle-tab.c
+++ b/src/muscle-tab.c
@@ -282,11 +282,7 @@ muscle_boundary_grow (char const *key, boundary bound)
 }
 
 
-/* In the format '[[file_name:line.column]], [[file_name:line.column]]',
-   append LOC to MUSCLE.  Use digraphs for special characters in each
-   file name.  */
-
-static void
+void
 muscle_location_grow (char const *key, location loc)
 {
   muscle_boundary_grow (key, loc.start);
diff --git a/src/muscle-tab.h b/src/muscle-tab.h
index 70c45db5..1aefdf3d 100644
--- a/src/muscle-tab.h
+++ b/src/muscle-tab.h
@@ -119,6 +119,11 @@ void muscle_pair_list_grow (const char *muscle,
 void muscle_user_name_list_grow (char const *key, char const *user_name,
                                  location loc);
 
+/* In the format '[[file_name:line.column]], [[file_name:line.column]]',
+   append LOC to MUSCLE.  Use digraphs for special characters in each
+   file name.  */
+void muscle_location_grow (char const *key, location loc);
+
 /* Indicates whether a variable's value was specified with -D/--define, with
    -F/--force-define, or in the grammar file.  */
 typedef enum {
diff --git a/src/output.c b/src/output.c
index a1f83413..5f965846 100644
--- a/src/output.c
+++ b/src/output.c
@@ -478,6 +478,9 @@ prepare_symbol_definitions (void)
               SET_KEY2 (pname, "line");
               MUSCLE_INSERT_INT (key, p->location.start.line);
 
+              SET_KEY2 (pname, "loc");
+              muscle_location_grow (key, p->location);
+
               SET_KEY (pname);
               MUSCLE_INSERT_STRING_RAW (key, p->code);
             }
diff --git a/tests/java.at b/tests/java.at
index e732f1d3..ee2bf082 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -33,8 +33,10 @@ exp:
 ])
 
 AT_BISON_CHECK([[-fcaret YYParser.y]], [1], [],
-[[YYParser.y: error: "lalr1.java": %defines does not make sense in Java
-YYParser.y: error: "lalr1.java": "YYParser.y":/* :4  */: %destructor does not 
make sense in Java
+[[YYParser.y: error: %defines does not make sense in Java
+YYParser.y:4.13-30: error: %destructor does not make sense in Java
+ %destructor { /* Nothing. */ } exp
+             ^~~~~~~~~~~~~~~~~~
 ]])
 
 AT_CLEANUP
-- 
2.21.0




reply via email to

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