spot  0.8.1
position.hh
Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.4.3.  */
00002 
00003 /* Positions for Bison parsers in C++
00004    
00005       Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software
00006    Foundation, Inc.
00007    
00008    This program is free software: you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation, either version 3 of the License, or
00011    (at your option) any later version.
00012    
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017    
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 /* As a special exception, you may create a larger work that contains
00022    part or all of the Bison parser skeleton and distribute that work
00023    under terms of your choice, so long as that work isn't itself a
00024    parser generator using the skeleton or a modified version thereof
00025    as a parser skeleton.  Alternatively, if you modify or redistribute
00026    the parser skeleton itself, you may (at your option) remove this
00027    special exception, which will cause the skeleton and the resulting
00028    Bison output files to be licensed under the GNU General Public
00029    License without this special exception.
00030    
00031    This special exception was added by the Free Software Foundation in
00032    version 2.2 of Bison.  */
00033 
00039 #ifndef BISON_POSITION_HH
00040 # define BISON_POSITION_HH
00041 
00042 # include <iostream>
00043 # include <string>
00044 # include <algorithm>
00045 
00046 
00047 namespace eltlyy {
00048 
00049 /* Line 38 of location.cc  */
00050 #line 51 "position.hh"
00051 
00052   class position
00053   {
00054   public:
00055 
00057     position ()
00058       : filename (0), line (1), column (1)
00059     {
00060     }
00061 
00062 
00064     inline void initialize (std::string* fn)
00065     {
00066       filename = fn;
00067       line = 1;
00068       column = 1;
00069     }
00070 
00073   public:
00075     inline void lines (int count = 1)
00076     {
00077       column = 1;
00078       line += count;
00079     }
00080 
00082     inline void columns (int count = 1)
00083     {
00084       column = std::max (1u, column + count);
00085     }
00088   public:
00090     std::string* filename;
00092     unsigned int line;
00094     unsigned int column;
00095   };
00096 
00098   inline const position&
00099   operator+= (position& res, const int width)
00100   {
00101     res.columns (width);
00102     return res;
00103   }
00104 
00106   inline const position
00107   operator+ (const position& begin, const int width)
00108   {
00109     position res = begin;
00110     return res += width;
00111   }
00112 
00114   inline const position&
00115   operator-= (position& res, const int width)
00116   {
00117     return res += -width;
00118   }
00119 
00121   inline const position
00122   operator- (const position& begin, const int width)
00123   {
00124     return begin + -width;
00125   }
00126 
00128   inline bool
00129   operator== (const position& pos1, const position& pos2)
00130   {
00131     return (pos1.line == pos2.line
00132             && pos1.column == pos2.column
00133             && (pos1.filename == pos2.filename
00134                 || (pos1.filename && pos2.filename
00135                     && *pos1.filename == *pos2.filename)));
00136   }
00137 
00139   inline bool
00140   operator!= (const position& pos1, const position& pos2)
00141   {
00142     return !(pos1 == pos2);
00143   }
00144 
00149   inline std::ostream&
00150   operator<< (std::ostream& ostr, const position& pos)
00151   {
00152     if (pos.filename)
00153       ostr << *pos.filename << ':';
00154     return ostr << pos.line << '.' << pos.column;
00155   }
00156 
00157 
00158 } // eltlyy
00159 
00160 /* Line 145 of location.cc  */
00161 #line 162 "position.hh"
00162 #endif // not BISON_POSITION_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Sun Dec 18 2011 12:57:15 for spot by doxygen 1.7.6.1