[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ comparison operators for location
From: |
Joel E. Denny |
Subject: |
Re: C++ comparison operators for location |
Date: |
Thu, 22 Jun 2006 15:49:28 -0400 (EDT) |
On Wed, 21 Jun 2006, Joel E. Denny wrote:
> On Wed, 21 Jun 2006, Akim Demaille wrote:
>
> > Yes. For a start, as a simple Boolean (%define
> > "define_position_comparison"), until we find something smarter.
>
> How about define_location_comparison? I see location as the more general
> concept (maybe it's just me), and this boolean will affect both location
> and position.
I went ahead and committed this. We can adjust the name later if need be.
I'm not sure how you want to handle %define booleans in general. For now,
`1' is the only true value.
Joel
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1510
diff -p -u -r1.1510 ChangeLog
--- ChangeLog 21 Jun 2006 01:37:00 -0000 1.1510
+++ ChangeLog 22 Jun 2006 19:24:20 -0000
@@ -1,3 +1,22 @@
+2006-06-22 Joel E. Denny <address@hidden>
+
+ Add comparison operators for C++ location classes. Discussed at
+ <http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00092.html>.
+ * data/c++.m4 (b4_define_location_comparison): New boolean %define
+ declaration indicating whether filename_type has an operator==. If
+ filename_type is `std::string', it defaults to `1', `0' otherwise.
+ * data/location.cc: Iff b4_define_location_comparison is `1', add
+ operator== and operator!= for class position and for class location.
+
+ Some minor fixes.
+ * src/scan-action.l: Remove unused file.
+ * src/symtab.c (symbol_printer_set): Use printer_location not
+ destructor_location.
+ * src/symtab.h (struct symbol): Replace incorrect source comment for
+ printer members.
+ * tests/input.at (Incompatible Aliases): Update output with correct
+ printer location.
+
2006-06-20 Joel E. Denny <address@hidden>
Don't put the pre-prologue in the header file. For the yacc.c code
Index: data/c++.m4
===================================================================
RCS file: /sources/bison/bison/data/c++.m4,v
retrieving revision 1.7
diff -p -u -r1.7 c++.m4
--- data/c++.m4 20 Jun 2006 11:32:19 -0000 1.7
+++ data/c++.m4 22 Jun 2006 19:24:20 -0000
@@ -30,6 +30,8 @@ m4_define_default([b4_parser_class_name]
m4_define_default([b4_location_type], [location])
m4_define_default([b4_filename_type], [std::string])
m4_define_default([b4_namespace], m4_defn([b4_prefix]))
+m4_define_default([b4_define_location_comparison],
+ m4_if(b4_filename_type, [std::string], [1], [0]))
# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
Index: data/location.cc
===================================================================
RCS file: /sources/bison/bison/data/location.cc,v
retrieving revision 1.11
diff -p -u -r1.11 location.cc
--- data/location.cc 20 Jun 2006 11:32:19 -0000 1.11
+++ data/location.cc 22 Jun 2006 19:24:20 -0000
@@ -119,7 +119,24 @@ namespace ]b4_namespace[
{
return begin + -width;
}
+]m4_if(b4_define_location_comparison, [1], [[
+ /// Compare two position objects.
+ inline bool
+ operator== (const position& pos1, const position& pos2)
+ {
+ return
+ (pos1.filename == pos2.filename
+ || pos1.filename && pos2.filename && *pos1.filename == *pos2.filename)
+ && pos1.line == pos2.line && pos1.column == pos2.column;
+ }
+ /// Compare two position objects.
+ inline bool
+ operator!= (const position& pos1, const position& pos2)
+ {
+ return !(pos1 == pos2);
+ }
+]])[
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param pos a reference to the position to redirect
@@ -224,7 +241,21 @@ namespace ]b4_namespace[
res.columns (width);
return res;
}
+]m4_if(b4_define_location_comparison, [1], [[
+ /// Compare two location objects.
+ inline bool
+ operator== (const location& loc1, const location& loc2)
+ {
+ return loc1.begin == loc2.begin && loc1.end == loc2.end;
+ }
+ /// Compare two location objects.
+ inline bool
+ operator!= (const location& loc1, const location& loc2)
+ {
+ return !(loc1 == loc2);
+ }
+]])[
/** \brief Intercept output stream redirection.
** \param ostr the destination output stream
** \param loc a reference to the location to redirect
Index: src/symtab.c
===================================================================
RCS file: /sources/bison/bison/src/symtab.c,v
retrieving revision 1.71
diff -p -u -r1.71 symtab.c
--- src/symtab.c 20 Jun 2006 11:39:22 -0000 1.71
+++ src/symtab.c 22 Jun 2006 19:24:20 -0000
@@ -158,7 +158,7 @@ symbol_printer_set (symbol *sym, const c
if (printer)
{
if (sym->printer)
- redeclaration (sym, "%printer", sym->destructor_location, loc);
+ redeclaration (sym, "%printer", sym->printer_location, loc);
sym->printer = printer;
sym->printer_location = loc;
}
Index: src/symtab.h
===================================================================
RCS file: /sources/bison/bison/src/symtab.h,v
retrieving revision 1.60
diff -p -u -r1.60 symtab.h
--- src/symtab.h 20 Jun 2006 11:39:22 -0000 1.60
+++ src/symtab.h 22 Jun 2006 19:24:20 -0000
@@ -64,7 +64,7 @@ struct symbol
const char *destructor;
location destructor_location;
- /* Does not own the memory. */
+ /* Printer. */
const char *printer;
location printer_location;
Index: tests/input.at
===================================================================
RCS file: /sources/bison/bison/tests/input.at,v
retrieving revision 1.45
diff -p -u -r1.45 input.at
--- tests/input.at 7 Jun 2006 07:09:32 -0000 1.45
+++ tests/input.at 22 Jun 2006 19:24:20 -0000
@@ -163,7 +163,7 @@ input.y:3.7-11: first declaration
input.y:10.13-17: %destructor redeclaration for foo
input.y:5.13-17: first declaration
input.y:9.10-14: %printer redeclaration for foo
-input.y:10.13-17: first declaration
+input.y:4.10-14: first declaration
input.y:11.1-5: %left redeclaration for foo
input.y:6.1-5: first declaration
]])