[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C++ comparison operators for location
From: |
Joel E. Denny |
Subject: |
C++ comparison operators for location |
Date: |
Wed, 21 Jun 2006 01:49:13 -0400 (EDT) |
Akim, what do you think of this (uncommitted) patch?
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 21 Jun 2006 05:43:10 -0000
@@ -1,3 +1,9 @@
+2006-06-21 Joel E. Denny <address@hidden>
+
+ data/location.cc: If filename_type is std::string so that the filename
+ member of class position can be compared, add operator== and
+ operator!= to class position and to class 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/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 21 Jun 2006 05:43:12 -0000
@@ -119,7 +119,24 @@ namespace ]b4_namespace[
{
return begin + -width;
}
+]m4_if(b4_filename_type, [std::string], [[
+ /// 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_filename_type, [std::string], [[
+ /// 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
- C++ comparison operators for location,
Joel E. Denny <=