~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

Namespace the parser just a bit, and update our call for the type of parser
we want.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/* A lexical scanner on a temporary buffer with a yacc interface */
18
18
 
19
19
#include "config.h"
 
20
 
20
21
#define DRIZZLE_LEX 1
 
22
 
 
23
#include "drizzled/sql_reserved_words.h"
 
24
 
21
25
#include "drizzled/configmake.h"
22
26
#include "drizzled/item/num.h"
23
27
#include "drizzled/error.h"
25
29
#include "drizzled/sql_base.h"
26
30
#include "drizzled/lookup_symbol.h"
27
31
#include "drizzled/index_hint.h"
 
32
#include <drizzled/select_result.h>
28
33
 
29
34
#include <cstdio>
30
35
#include <ctype.h>
32
37
using namespace std;
33
38
 
34
39
/* Stay outside of the namespace because otherwise bison goes nuts */
35
 
int DRIZZLElex(void *arg, void *yysession);
 
40
int base_sql_lex(void *arg, void *yysession);
36
41
 
37
42
namespace drizzled
38
43
{
45
50
static bool add_to_list(Session *session, SQL_LIST &list, Item *item, bool asc)
46
51
{
47
52
  Order *order;
48
 
  if (!(order = (Order *) session->alloc(sizeof(Order))))
49
 
    return(1);
 
53
 
 
54
  if (!(order = (Order *) session->getMemRoot()->allocate(sizeof(Order))))
 
55
    return true;
 
56
 
50
57
  order->item_ptr= item;
51
58
  order->item= &order->item_ptr;
52
59
  order->asc = asc;
53
60
  order->free_me=0;
54
61
  order->used=0;
55
62
  order->counter_used= 0;
56
 
  list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
57
 
  return(0);
 
63
  list.link_in_list((unsigned char*) order, (unsigned char**) &order->next);
 
64
 
 
65
  return false;
58
66
}
59
67
 
60
68
/**
64
72
 
65
73
Lex_input_stream::Lex_input_stream(Session *session,
66
74
                                   const char* buffer,
67
 
                                   unsigned int length)
68
 
: m_session(session),
 
75
                                   unsigned int length) :
 
76
  m_session(session),
69
77
  yylineno(1),
70
78
  yytoklen(0),
71
79
  yylval(NULL),
88
96
  ignore_space(1),
89
97
  in_comment(NO_COMMENT)
90
98
{
91
 
  m_cpp_buf= (char*) session->alloc(length + 1);
 
99
  m_cpp_buf= (char*) session->getMemRoot()->allocate(length + 1);
92
100
  m_cpp_ptr= m_cpp_buf;
93
101
}
94
102
 
115
123
    (m_buf_length / default_charset_info->mbminlen) *
116
124
    my_charset_utf8_bin.mbmaxlen;
117
125
 
118
 
  m_body_utf8= (char *) session->alloc(body_utf8_length + 1);
 
126
  m_body_utf8= (char *) session->getMemRoot()->allocate(body_utf8_length + 1);
119
127
  m_body_utf8_ptr= m_body_utf8;
120
128
  *m_body_utf8_ptr= 0;
121
129
 
242
250
  lex->derived_tables= 0;
243
251
  lex->lock_option= TL_READ;
244
252
  lex->leaf_tables_insert= 0;
 
253
  lex->var_list.clear();
245
254
  lex->select_lex.select_number= 1;
246
255
  lex->length=0;
247
256
  lex->select_lex.in_sum_expr=0;
261
270
  lex->nest_level=0 ;
262
271
  lex->allow_sum_func= 0;
263
272
  lex->in_sum_func= NULL;
 
273
  lex->type= 0;
264
274
 
265
275
  lex->is_lex_started= true;
266
276
  lex->statement= NULL;
267
277
  
268
278
  lex->is_cross= false;
269
 
 
270
279
  lex->reset();
271
280
}
272
281
 
281
290
  }
282
291
 
283
292
  delete result;
 
293
  delete _create_table;
 
294
  _create_table= NULL;
 
295
  _create_field= NULL;
284
296
 
285
297
  result= 0;
286
298
  setCacheable(true);
347
359
  char *to;
348
360
  lip->yyUnget();                       // ptr points now after last token char
349
361
  tmp.length= lip->yytoklen=length;
350
 
  tmp.str=(char*) lip->m_session->alloc(tmp.length+1);
 
362
  tmp.str=(char*) lip->m_session->getMemRoot()->allocate(tmp.length+1);
351
363
  from= lip->get_tok_start() + skip;
352
364
  to= tmp.str;
353
365
  end= to+length;
423
435
      end-= post_skip;
424
436
      assert(end >= str);
425
437
 
426
 
      if (!(start= (char*) lip->m_session->alloc((uint32_t) (end-str)+1)))
 
438
      if (!(start= (char*) lip->m_session->getMemRoot()->allocate((uint32_t) (end-str)+1)))
427
439
        return (char*) "";              // memory::SqlAlloc has set error flag
428
440
 
429
441
      lip->m_cpp_text_start= lip->get_cpp_tok_start() + pre_skip;
589
601
 
590
602
} /* namespace drizzled */
591
603
/*
592
 
  DRIZZLElex remember the following states from the following DRIZZLElex()
 
604
  base_sql_lex remember the following states from the following sql_baselex()
593
605
 
594
606
  - MY_LEX_EOQ                  Found end of query
595
607
  - MY_LEX_OPERATOR_OR_IDENT    Last state was an ident, text or number
596
608
                                (which can't be followed by a signed number)
597
609
*/
598
 
int DRIZZLElex(void *arg, void *yysession)
 
610
int base_sql_lex(void *arg, void *yysession)
599
611
{
600
612
  drizzled::Session *session= (drizzled::Session *)yysession;
601
613
  drizzled::Lex_input_stream *lip= session->m_lip;
1386
1398
  select_limit= 0;      /* denotes the default limit = HA_POS_ERROR */
1387
1399
  offset_limit= 0;      /* denotes the default offset = 0 */
1388
1400
  with_sum_func= 0;
 
1401
  is_cross= false;
1389
1402
  is_correlated= 0;
1390
1403
  cur_pos_in_select_list= UNDEF_POS;
1391
1404
  non_agg_fields.empty();
1701
1714
    return false;
1702
1715
 
1703
1716
  return (ref_pointer_array=
1704
 
          (Item **)session->alloc(sizeof(Item*) * (n_child_sum_items +
 
1717
          (Item **)session->getMemRoot()->allocate(sizeof(Item*) * (n_child_sum_items +
1705
1718
                                                 item_list.elements +
1706
1719
                                                 select_n_having_items +
1707
1720
                                                 select_n_where_fields +
1801
1814
  }
1802
1815
}
1803
1816
 
1804
 
/**
1805
 
  @brief Restore the LEX and Session in case of a parse error.
1806
 
 
1807
 
  This is a clean up call that is invoked by the Bison generated
1808
 
  parser before returning an error from DRIZZLEparse. If your
1809
 
  semantic actions manipulate with the global thread state (which
1810
 
  is a very bad practice and should not normally be employed) and
1811
 
  need a clean-up in case of error, and you can not use %destructor
1812
 
  rule in the grammar file itself, this function should be used
1813
 
  to implement the clean up.
1814
 
*/
1815
 
void LEX::cleanup_lex_after_parse_error(Session *)
 
1817
LEX::~LEX()
1816
1818
{
 
1819
  delete _create_table;
1817
1820
}
1818
1821
 
1819
1822
/*
1863
1866
    statement parsing. On should use lex_start() function to prepare LEX
1864
1867
    for this.
1865
1868
*/
1866
 
LEX::LEX()
1867
 
  :
 
1869
LEX::LEX() :
1868
1870
    result(0), 
1869
1871
    yacc_yyss(0), 
1870
1872
    yacc_yyvs(0),
 
1873
    session(NULL),
1871
1874
    charset(NULL),
 
1875
    var_list(),
1872
1876
    sql_command(SQLCOM_END), 
 
1877
    statement(NULL),
1873
1878
    option_type(OPT_DEFAULT), 
1874
1879
    is_lex_started(0),
1875
1880
    cacheable(true),
1876
 
    sum_expr_used(false)
 
1881
    sum_expr_used(false),
 
1882
    _create_table(NULL),
 
1883
    _create_field(NULL),
 
1884
    _exists(false)
1877
1885
{
1878
1886
  reset_query_tables_list(true);
1879
 
  statement= NULL;
1880
1887
}
1881
1888
 
1882
1889
/**
2152
2159
                                            str, length));
2153
2160
}
2154
2161
 
 
2162
bool check_for_sql_keyword(drizzled::lex_string_t const& string)
 
2163
{
 
2164
  if (sql_reserved_words::in_word_set(string.str, string.length))
 
2165
      return true;
 
2166
 
 
2167
  return false;
 
2168
}
 
2169
 
 
2170
bool check_for_sql_keyword(drizzled::st_lex_symbol const& string)
 
2171
{
 
2172
  if (sql_reserved_words::in_word_set(string.str, string.length))
 
2173
      return true;
 
2174
 
 
2175
  return false;
 
2176
}
 
2177
 
 
2178
 
2155
2179
} /* namespace drizzled */