ct_common  1.0.1
Common library for combinatorial testing
src/ct_common/file_parse/location.hh
Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.5.  */
00002 
00003 /* Locations for Bison parsers in C++
00004    
00005       Copyright (C) 2002-2007, 2009-2011 Free Software Foundation, Inc.
00006    
00007    This program is free software: you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation, either version 3 of the License, or
00010    (at your option) any later version.
00011    
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016    
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 /* As a special exception, you may create a larger work that contains
00021    part or all of the Bison parser skeleton and distribute that work
00022    under terms of your choice, so long as that work isn't itself a
00023    parser generator using the skeleton or a modified version thereof
00024    as a parser skeleton.  Alternatively, if you modify or redistribute
00025    the parser skeleton itself, you may (at your option) remove this
00026    special exception, which will cause the skeleton and the resulting
00027    Bison output files to be licensed under the GNU General Public
00028    License without this special exception.
00029    
00030    This special exception was added by the Free Software Foundation in
00031    version 2.2 of Bison.  */
00032 
00038 #ifndef BISON_LOCATION_HH
00039 # define BISON_LOCATION_HH
00040 
00041 # include <iostream>
00042 # include <string>
00043 # include "position.hh"
00044 
00045 
00046 namespace yy {
00047 
00048 /* Line 162 of location.cc  */
00049 #line 50 "location.hh"
00050 
00052   class location
00053   {
00054   public:
00055 
00057     location ()
00058       : begin (), end ()
00059     {
00060     }
00061 
00062 
00064     inline void initialize (std::string* fn)
00065     {
00066       begin.initialize (fn);
00067       end = begin;
00068     }
00069 
00072   public:
00074     inline void step ()
00075     {
00076       begin = end;
00077     }
00078 
00080     inline void columns (unsigned int count = 1)
00081     {
00082       end += count;
00083     }
00084 
00086     inline void lines (unsigned int count = 1)
00087     {
00088       end.lines (count);
00089     }
00093   public:
00095     position begin;
00097     position end;
00098   };
00099 
00101   inline const location operator+ (const location& begin, const location& end)
00102   {
00103     location res = begin;
00104     res.end = end.end;
00105     return res;
00106   }
00107 
00109   inline const location operator+ (const location& begin, unsigned int width)
00110   {
00111     location res = begin;
00112     res.columns (width);
00113     return res;
00114   }
00115 
00117   inline location& operator+= (location& res, unsigned int width)
00118   {
00119     res.columns (width);
00120     return res;
00121   }
00122 
00124   inline bool
00125   operator== (const location& loc1, const location& loc2)
00126   {
00127     return loc1.begin == loc2.begin && loc1.end == loc2.end;
00128   }
00129 
00131   inline bool
00132   operator!= (const location& loc1, const location& loc2)
00133   {
00134     return !(loc1 == loc2);
00135   }
00136 
00143   inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
00144   {
00145     position last = loc.end - 1;
00146     ostr << loc.begin;
00147     if (last.filename
00148         && (!loc.begin.filename
00149             || *loc.begin.filename != *last.filename))
00150       ostr << '-' << last;
00151     else if (loc.begin.line != last.line)
00152       ostr << '-' << last.line  << '.' << last.column;
00153     else if (loc.begin.column != last.column)
00154       ostr << '-' << last.column;
00155     return ostr;
00156   }
00157 
00158 
00159 } // yy
00160 
00161 /* Line 271 of location.cc  */
00162 #line 163 "location.hh"
00163 
00164 #endif // not BISON_LOCATION_HH
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines