00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 00003 * 00004 * Copyright (C) 2008 Sun Microsystems, 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; version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #pragma once 00021 00036 namespace drizzled 00037 { 00038 00039 class Lex_input_stream 00040 { 00041 public: 00042 Lex_input_stream(Session *session, const char* buff, unsigned int length); 00043 ~Lex_input_stream(); 00044 00052 void set_echo(bool echo) 00053 { 00054 m_echo= echo; 00055 } 00056 00061 void skip_binary(int n) 00062 { 00063 if (m_echo) 00064 { 00065 memcpy(m_cpp_ptr, m_ptr, n); 00066 m_cpp_ptr += n; 00067 } 00068 m_ptr += n; 00069 } 00070 00075 char yyGet() 00076 { 00077 char c= *m_ptr++; 00078 if (m_echo) 00079 *m_cpp_ptr++ = c; 00080 return c; 00081 } 00082 00087 char yyGetLast() 00088 { 00089 return m_ptr[-1]; 00090 } 00091 00095 char yyPeek() 00096 { 00097 return m_ptr[0]; 00098 } 00099 00104 char yyPeekn(int n) 00105 { 00106 return m_ptr[n]; 00107 } 00108 00114 void yyUnget() 00115 { 00116 m_ptr--; 00117 if (m_echo) 00118 m_cpp_ptr--; 00119 } 00120 00124 void yySkip() 00125 { 00126 if (m_echo) 00127 *m_cpp_ptr++ = *m_ptr++; 00128 else 00129 m_ptr++; 00130 } 00131 00136 void yySkipn(int n) 00137 { 00138 if (m_echo) 00139 { 00140 memcpy(m_cpp_ptr, m_ptr, n); 00141 m_cpp_ptr += n; 00142 } 00143 m_ptr += n; 00144 } 00145 00150 bool eof() 00151 { 00152 return (m_ptr >= m_end_of_query); 00153 } 00154 00160 bool eof(int n) 00161 { 00162 return ((m_ptr + n) >= m_end_of_query); 00163 } 00164 00166 const char *get_buf() 00167 { 00168 return m_buf; 00169 } 00170 00172 const char *get_cpp_buf() 00173 { 00174 return m_cpp_buf; 00175 } 00176 00178 const char *get_end_of_query() 00179 { 00180 return m_end_of_query; 00181 } 00182 00184 void start_token() 00185 { 00186 m_tok_start_prev= m_tok_start; 00187 m_tok_start= m_ptr; 00188 m_tok_end= m_ptr; 00189 00190 m_cpp_tok_start_prev= m_cpp_tok_start; 00191 m_cpp_tok_start= m_cpp_ptr; 00192 m_cpp_tok_end= m_cpp_ptr; 00193 } 00194 00199 void restart_token() 00200 { 00201 m_tok_start= m_ptr; 00202 m_cpp_tok_start= m_cpp_ptr; 00203 } 00204 00206 const char *get_tok_start() 00207 { 00208 return m_tok_start; 00209 } 00210 00212 const char *get_cpp_tok_start() 00213 { 00214 return m_cpp_tok_start; 00215 } 00216 00218 const char *get_tok_end() 00219 { 00220 return m_tok_end; 00221 } 00222 00224 const char *get_cpp_tok_end() 00225 { 00226 return m_cpp_tok_end; 00227 } 00228 00230 const char *get_tok_start_prev() 00231 { 00232 return m_tok_start_prev; 00233 } 00234 00236 const char *get_ptr() 00237 { 00238 return m_ptr; 00239 } 00240 00242 const char *get_cpp_ptr() 00243 { 00244 return m_cpp_ptr; 00245 } 00246 00248 uint32_t yyLength() 00249 { 00250 /* 00251 The assumption is that the lexical analyser is always 1 character ahead, 00252 which the -1 account for. 00253 */ 00254 assert(m_ptr > m_tok_start); 00255 return (uint32_t) ((m_ptr - m_tok_start) - 1); 00256 } 00257 00259 const char *get_body_utf8_str() 00260 { 00261 return m_body_utf8; 00262 } 00263 00265 uint32_t get_body_utf8_length() 00266 { 00267 return m_body_utf8_ptr - m_body_utf8; 00268 } 00269 00270 void body_utf8_start(Session *session, const char *begin_ptr); 00271 void body_utf8_append(const char *ptr); 00272 void body_utf8_append(const char *ptr, const char *end_ptr); 00273 void body_utf8_append_literal(const LEX_STRING *txt, 00274 const char *end_ptr); 00275 00277 Session *m_session; 00278 00280 uint32_t yylineno; 00281 00283 uint32_t yytoklen; 00284 00286 LEX_YYSTYPE yylval; 00287 00289 int lookahead_token; 00290 00292 LEX_YYSTYPE lookahead_yylval; 00293 00294 private: 00296 const char *m_ptr; 00297 00299 const char *m_tok_start; 00300 00302 const char *m_tok_end; 00303 00305 const char *m_end_of_query; 00306 00308 const char *m_tok_start_prev; 00309 00311 const char *m_buf; 00312 00314 uint32_t m_buf_length; 00315 00317 bool m_echo; 00318 00320 char *m_cpp_buf; 00321 00323 char *m_cpp_ptr; 00324 00329 const char *m_cpp_tok_start; 00330 00335 const char *m_cpp_tok_start_prev; 00336 00341 const char *m_cpp_tok_end; 00342 00344 char *m_body_utf8; 00345 00347 char *m_body_utf8_ptr; 00348 00353 const char *m_cpp_utf8_processed_ptr; 00354 00355 public: 00356 00358 enum my_lex_states next_state; 00359 00361 unsigned char tok_bitmap; 00362 00364 bool ignore_space; 00365 00367 enum_comment_state in_comment; 00368 00375 const char *m_cpp_text_start; 00376 00383 const char *m_cpp_text_end; 00384 00385 }; 00386 00387 } /* namespace drizzled */ 00388