Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

location.hh

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 1.875d.  */
00002 
00003 /* Location class for Bison C++ parsers,
00004    Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.  */
00020 
00026 #ifndef BISON_LOCATION_HH
00027 # define BISON_LOCATION_HH
00028 
00029 # include <iostream>
00030 # include <string>
00031 # include "position.hh"
00032 
00033 namespace yy
00034 {
00035 
00037   class Location
00038   {
00041   public:
00043     Location (void) :
00044       begin (),
00045       end ()
00046     {
00047     }
00053   public:
00055     inline void step (void)
00056     {
00057       begin = end;
00058     }
00059 
00061     inline void columns (unsigned int count = 1)
00062     {
00063       end += count;
00064     }
00065 
00067     inline void lines (unsigned int count = 1)
00068     {
00069       end.lines (count);
00070     }
00074   public:
00076     Position begin;
00078     Position end;
00079   };
00080 
00082   inline const Location operator+ (const Location& begin, const Location& end)
00083   {
00084     Location res = begin;
00085     res.end = end.end;
00086     return res;
00087   }
00088 
00090   inline const Location operator+ (const Location& begin, unsigned int width)
00091   {
00092     Location res = begin;
00093     res.columns (width);
00094     return res;
00095   }
00096 
00098   inline Location &operator+= (Location& res, unsigned int width)
00099   {
00100     res.columns (width);
00101     return res;
00102   }
00103 
00110   inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
00111   {
00112     Position last = loc.end - 1;
00113     ostr << loc.begin;
00114     if (loc.begin.filename != last.filename)
00115       ostr << '-' << last;
00116     else if (loc.begin.line != last.line)
00117       ostr << '-' << last.line  << '.' << last.column;
00118     else if (loc.begin.column != last.column)
00119       ostr << '-' << last.column;
00120     return ostr;
00121   }
00122 
00123 }
00124 
00125 #endif // not BISON_LOCATION_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Jan 31 12:54:24 2005 for spot by doxygen 1.4.0