SimpleParser.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:2k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include <common/common.hpp>
  14. #include <NdbMutex.h>
  15. #include <common/StmtArea.hpp>
  16. #include <FlexLexer.h>
  17. #include "SimpleParser.hpp"
  18. SimpleParser::~SimpleParser()
  19. {
  20. }
  21. #ifdef NDB_WIN32
  22. static NdbMutex & parse_mutex = * NdbMutex_Create();
  23. #else
  24. static NdbMutex parse_mutex = NDB_MUTEX_INITIALIZER;
  25. #endif
  26. void
  27. SimpleParser::yyparse()
  28. {
  29.     Ctx& ctx = this->ctx();
  30.     NdbMutex_Lock(&parse_mutex);
  31.     ctx_log2(("parse: %s", stmtArea().sqlText().c_str()));
  32. #if YYDEBUG
  33.     SimpleParser_yydebug = (m_ctx.logLevel() >= 5);
  34. #endif
  35.     SimpleParser_yyparse((void*)this);
  36.     NdbMutex_Unlock(&parse_mutex);
  37. }
  38. void
  39. SimpleParser::pushState(int sc)
  40. {
  41.     yy_push_state(sc);
  42.     m_stacksize++;
  43. }
  44. void
  45. SimpleParser::popState()
  46. {
  47.     ctx_assert(m_stacksize > 0);
  48.     yy_pop_state();
  49.     m_stacksize--;
  50. }
  51. void
  52. SimpleParser::parseError(const char* msg)
  53. {
  54.     ctx().pushStatus(Sqlstate::_42000, Error::Gen, "%s at '%*s' position %u", msg, yyleng, yytext, m_parsePos - yyleng);
  55. }
  56. int
  57. SimpleParser::LexerInput(char* buf, int max_size)
  58. {
  59.     const BaseString& text = stmtArea().sqlText();
  60.     int n = 0;
  61.     const char* const t = text.c_str();
  62.     const unsigned m = text.length();
  63.     while (n < max_size && m_textPos < m) {
  64. buf[n++] = t[m_textPos++];
  65. m_parsePos++; // XXX simple hack
  66. break;
  67.     }
  68.     return n;
  69. }
  70. // XXX just a catch-all (scanner should match all input)
  71. void
  72. SimpleParser::LexerOutput(const char* buf, int size)
  73. {
  74.     if (! ctx().ok())
  75. return;
  76.     const char* msg = "unrecognized input";
  77.     ctx().pushStatus(Sqlstate::_42000, Error::Gen, "%s at '%*s' position %u", msg, size, buf, m_parsePos);
  78. }
  79. void
  80. SimpleParser::LexerError(const char* msg)
  81. {
  82.     ctx().pushStatus(Sqlstate::_42000, Error::Gen, "%s at '%*s' position %u", msg, yyleng, yytext, m_parsePos);
  83. }