"L. Spiro Engine"
|
00001 /* A Bison parser, made by GNU Bison 2.4.2. */ 00002 00003 /* Positions for Bison parsers in C++ 00004 00005 Copyright (C) 2002-2007, 2009-2010 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 __LSG_SHADERPARSERPOSITION_H__ 00039 # define __LSG_SHADERPARSERPOSITION_H__ 00040 00041 # include <iostream> 00042 # include <string> 00043 # include <algorithm> 00044 00045 using namespace ::std; 00046 00047 namespace yy { 00048 00050 class position 00051 { 00052 public: 00053 00055 position () 00056 : filename (0), line (1), column (1) 00057 { 00058 } 00059 00060 00062 inline void initialize (std::string* fn) 00063 { 00064 filename = fn; 00065 line = 1; 00066 column = 1; 00067 } 00068 00071 public: 00073 inline void lines (int count = 1) 00074 { 00075 column = 1; 00076 line += count; 00077 } 00078 00080 inline void columns (int count = 1) 00081 { 00082 column = max (1u, column + count); 00083 } 00086 public: 00088 std::string* filename; 00090 unsigned int line; 00092 unsigned int column; 00093 }; 00094 00096 inline const position& 00097 operator+= (position& res, const int width) 00098 { 00099 res.columns (width); 00100 return res; 00101 } 00102 00104 inline const position 00105 operator+ (const position& begin, const int width) 00106 { 00107 position res = begin; 00108 return res += width; 00109 } 00110 00112 inline const position& 00113 operator-= (position& res, const int width) 00114 { 00115 return res += -width; 00116 } 00117 00119 inline const position 00120 operator- (const position& begin, const int width) 00121 { 00122 return begin + -width; 00123 } 00124 00126 inline bool 00127 operator== (const position& pos1, const position& pos2) 00128 { 00129 return (pos1.line == pos2.line 00130 && pos1.column == pos2.column 00131 && (pos1.filename == pos2.filename 00132 || (pos1.filename && pos2.filename 00133 && *pos1.filename == *pos2.filename))); 00134 } 00135 00137 inline bool 00138 operator!= (const position& pos1, const position& pos2) 00139 { 00140 return !(pos1 == pos2); 00141 } 00142 00147 inline std::ostream& 00148 operator<< (std::ostream& ostr, const position& pos) 00149 { 00150 if (pos.filename) 00151 ostr << *pos.filename << ':'; 00152 return ostr << pos.line << '.' << pos.column; 00153 } 00154 00155 00156 } // yy 00157 00158 #endif // not __LSG_SHADERPARSERPOSITION_H__