~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/gen_lex_hash.cc

Removed DBUG symbols and fixed TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2006 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
/**
21
17
  @file
81
77
*/
82
78
 
83
79
#define NO_YACC_SYMBOLS
84
 
#include "global.h"
85
 
#include <mysys/my_sys.h>
86
 
#include <mystrings/m_string.h>
 
80
#include "my_global.h"
 
81
#include "my_sys.h"
 
82
#include "m_string.h"
87
83
#ifndef __GNU_LIBRARY__
88
84
#define __GNU_LIBRARY__                         // Skip warnings in getopt.h
89
85
#endif
90
 
#include <mysys/my_getopt.h>
91
 
#include <drizzled/version.h>
 
86
#include <my_getopt.h>
 
87
#include "mysql_version.h"
92
88
#include "lex.h"
93
89
 
94
90
const char *default_dbug_option="d:t:o,/tmp/gen_lex_hash.trace";
95
91
 
96
92
struct my_option my_long_options[] =
97
93
{
 
94
#ifdef DBUG_OFF
 
95
  {"debug", '#', "This is a non-debug version. Catch this and exit",
 
96
   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
97
#else
 
98
  {"debug", '#', "Output debug log", (uchar**) &default_dbug_option,
 
99
   (uchar**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
100
#endif
98
101
  {"help", '?', "Display help and exit",
99
102
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
100
103
  {"version", 'V', "Output version information and exit",
144
147
    int index2= root->iresult;
145
148
    const char *name2= (index2 < 0 ? sql_functions[-index2-1] :
146
149
                        symbols[index2]).name + len_from_begin;
147
 
    root->first_char= (int) (unsigned char) name2[0];
 
150
    root->first_char= (int) (uchar) name2[0];
148
151
    root->last_char= (char) root->first_char;
149
152
    tails= (hash_lex_struct*)malloc(sizeof(hash_lex_struct));
150
153
    root->char_tails= tails;
166
169
    end= tails + new_size - real_size;
167
170
    for (cur= tails; cur<end; cur++)
168
171
      cur->first_char= 0;
169
 
    root->first_char= (int) (unsigned char) *name;
 
172
    root->first_char= (int) (uchar) *name;
170
173
  }
171
174
 
172
175
  if (root->last_char<(*name))
221
224
{
222
225
  SYMBOL *cur, *end= symbols + array_elements(symbols);
223
226
  for (cur= symbols; cur < end; cur++)
224
 
    cur->length=(unsigned char) strlen(cur->name);
 
227
    cur->length=(uchar) strlen(cur->name);
225
228
  end= sql_functions + array_elements(sql_functions);
226
229
  for (cur= sql_functions; cur<end; cur++)
227
 
    cur->length=(unsigned char) strlen(cur->name);
 
230
    cur->length=(uchar) strlen(cur->name);
228
231
}
229
232
 
230
233
void generate_find_structs()
265
268
                                     st->first_char == 0 ? 0 : st->last_char);
266
269
  if (st->first_char == -1)
267
270
  {
268
 
    hash_map[size_hash_map-2]= ((unsigned int)(int16_t)st->iresult)&255;
269
 
    hash_map[size_hash_map-1]= ((unsigned int)(int16_t)st->iresult)>>8;
 
271
    hash_map[size_hash_map-2]= ((unsigned int)(int16)st->iresult)&255;
 
272
    hash_map[size_hash_map-1]= ((unsigned int)(int16)st->iresult)>>8;
270
273
  }
271
274
  else if (st->first_char == 0)
272
275
  {
273
 
    hash_map[size_hash_map-2]= ((unsigned int)(int16_t)array_elements_func(symbols))&255;
274
 
    hash_map[size_hash_map-1]= ((unsigned int)(int16_t)array_elements(symbols))>>8;
 
276
    hash_map[size_hash_map-2]= ((unsigned int)(int16)array_elements_func(symbols))&255;
 
277
    hash_map[size_hash_map-1]= ((unsigned int)(int16)array_elements(symbols))>>8;
275
278
  }
276
279
}
277
280
 
309
312
  char *cur;
310
313
  int i;
311
314
 
312
 
  printf("static unsigned char %s[%d]= {\n",name,size_hash_map);
 
315
  printf("static uchar %s[%d]= {\n",name,size_hash_map);
313
316
  for (i=0, cur= hash_map; i<size_hash_map; i++, cur++)
314
317
  {
315
318
    switch(i%4){
319
322
      else
320
323
        printf("\'%c\', ",*cur);
321
324
      break;
322
 
    case 2: printf("%u, ",(uint)(unsigned char)*cur); break;
323
 
    case 3: printf("%u,\n",(uint)(unsigned char)*cur); break;
 
325
    case 2: printf("%u, ",(uint)(uchar)*cur); break;
 
326
    case 3: printf("%u,\n",(uint)(uchar)*cur); break;
324
327
    }
325
328
  }
326
329
  printf("};\n");
347
350
static void usage(int version)
348
351
{
349
352
  printf("%s  Ver 3.6 Distrib %s, for %s (%s)\n",
350
 
         my_progname, DRIZZLE_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
 
353
         my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
351
354
  if (version)
352
355
    return;
353
 
  puts("Copyright (C) 2008 Sun Microsystems, Inc.");
 
356
  puts("Copyright (C) 2001 MySQL AB, by VVA and Monty");
354
357
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
355
358
and you are welcome to modify and redistribute it under the GPL license\n");
356
359
  puts("This program generates a perfect hashing function for the sql_lex.cc");
359
362
}
360
363
 
361
364
 
362
 
extern "C" bool
 
365
extern "C" my_bool
363
366
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
364
367
               char *argument __attribute__((unused)))
365
368
{
371
374
  case '?':
372
375
    usage(0);
373
376
    exit(0);
 
377
  case '#':
 
378
    DBUG_PUSH(argument ? argument : default_dbug_option);
 
379
    break;
374
380
  }
375
381
  return 0;
376
382
}
443
449
int main(int argc,char **argv)
444
450
{
445
451
  MY_INIT(argv[0]);
 
452
  DBUG_PROCESS(argv[0]);
446
453
 
447
454
  if (get_options(argc,(char **) argv))
448
455
    exit(1);
450
457
  /* Broken up to indicate that it's not advice to you, gentle reader. */
451
458
  printf("/*\n\n  Do " "not " "edit " "this " "file " "directly!\n\n*/\n");
452
459
 
453
 
  printf("/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- \n"
454
 
         " *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab: \n"
455
 
         " * \n"
456
 
         " *  Copyright (C) 2008 Sun Microsystems \n"
457
 
         " * \n"
458
 
         " *  This program is free software; you can redistribute it and/or modify \n"
459
 
         " *  it under the terms of the GNU General Public License as published by \n"
460
 
         " *  the Free Software Foundation; version 2 of the License. \n"
461
 
         " * \n"
462
 
         " *  This program is distributed in the hope that it will be useful, \n"
463
 
         " *  but WITHOUT ANY WARRANTY; without even the implied warranty of \n"
464
 
         " *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the \n"
465
 
         " *  GNU General Public License for more details. \n"
466
 
         " * \n"
467
 
         " *  You should have received a copy of the GNU General Public License \n"
468
 
         " *  along with this program; if not, write to the Free Software \n"
469
 
         " *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA \n"
470
 
         " */\n");
 
460
  printf("\
 
461
/* Copyright (C) 2001-2004 MySQL AB\n\
 
462
\n\
 
463
   This program is free software; you can redistribute it and/or modify\n\
 
464
   it under the terms of the GNU General Public License as published by\n\
 
465
   the Free Software Foundation; version 2 of the License.\n\
 
466
\n\
 
467
   This program is distributed in the hope that it will be useful,\n\
 
468
   but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
 
469
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
 
470
   GNU General Public License for more details.\n\
 
471
\n\
 
472
   You should have received a copy of the GNU General Public License\n\
 
473
   along with this program; see the file COPYING. If not, write to the\n\
 
474
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston\n\
 
475
   MA  02110-1301  USA. */\n\
 
476
\n\
 
477
");
471
478
 
472
479
  /* Broken up to indicate that it's not advice to you, gentle reader. */
473
480
  printf("/* Do " "not " "edit " "this " "file!  This is generated by "
489
496
static SYMBOL *get_hash_symbol(const char *s,\n\
490
497
                               unsigned int len,bool function)\n\
491
498
{\n\
492
 
  register unsigned char *hash_map;\n\
 
499
  register uchar *hash_map;\n\
493
500
  register const char *cur_str= s;\n\
494
501
\n\
495
502
  if (len == 0) {\n\
 
503
    DBUG_PRINT(\"warning\", (\"get_hash_symbol() received a request for a zero-length symbol, which is probably a mistake.\"));\
496
504
    return(NULL);\n\
497
505
  }\n"
498
506
);
501
509
  if (function){\n\
502
510
    if (len>sql_functions_max_len) return 0;\n\
503
511
    hash_map= sql_functions_map;\n\
504
 
    register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
 
512
    register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
505
513
\n\
506
514
    for (;;){\n\
507
 
      register unsigned char first_char= (unsigned char)cur_struct;\n\
 
515
      register uchar first_char= (uchar)cur_struct;\n\
508
516
\n\
509
517
      if (first_char == 0)\n\
510
518
      {\n\
511
 
        register int16_t ires= (int16_t)(cur_struct>>16);\n\
 
519
        register int16 ires= (int16)(cur_struct>>16);\n\
512
520
        if (ires==array_elements(symbols)) return 0;\n\
513
521
        register SYMBOL *res;\n\
514
522
        if (ires>=0) \n\
515
523
          res= symbols+ires;\n\
516
524
        else\n\
517
525
          res= sql_functions-ires-1;\n\
518
 
        register uint32_t count= cur_str-s;\n\
 
526
        register uint count= cur_str-s;\n\
519
527
        return lex_casecmp(cur_str,res->name+count,len-count) ? 0 : res;\n\
520
528
      }\n\
521
529
\n\
522
 
      register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
 
530
      register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
523
531
      if (cur_char<first_char) return 0;\n\
524
532
      cur_struct>>=8;\n\
525
 
      if (cur_char>(unsigned char)cur_struct) return 0;\n\
 
533
      if (cur_char>(uchar)cur_struct) return 0;\n\
526
534
\n\
527
535
      cur_struct>>=8;\n\
528
536
      cur_struct= uint4korr(hash_map+\n\
529
 
                        (((uint16_t)cur_struct + cur_char - first_char)*4));\n\
 
537
                        (((uint16)cur_struct + cur_char - first_char)*4));\n\
530
538
      cur_str++;\n\
531
539
    }\n"
532
540
);
535
543
  }else{\n\
536
544
    if (len>symbols_max_len) return 0;\n\
537
545
    hash_map= symbols_map;\n\
538
 
    register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
 
546
    register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
539
547
\n\
540
548
    for (;;){\n\
541
 
      register unsigned char first_char= (unsigned char)cur_struct;\n\
 
549
      register uchar first_char= (uchar)cur_struct;\n\
542
550
\n\
543
551
      if (first_char==0){\n\
544
 
        register int16_t ires= (int16_t)(cur_struct>>16);\n\
 
552
        register int16 ires= (int16)(cur_struct>>16);\n\
545
553
        if (ires==array_elements(symbols)) return 0;\n\
546
554
        register SYMBOL *res= symbols+ires;\n\
547
 
        register uint32_t count= cur_str-s;\n\
 
555
        register uint count= cur_str-s;\n\
548
556
        return lex_casecmp(cur_str,res->name+count,len-count)!=0 ? 0 : res;\n\
549
557
      }\n\
550
558
\n\
551
 
      register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
 
559
      register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
552
560
      if (cur_char<first_char) return 0;\n\
553
561
      cur_struct>>=8;\n\
554
 
      if (cur_char>(unsigned char)cur_struct) return 0;\n\
 
562
      if (cur_char>(uchar)cur_struct) return 0;\n\
555
563
\n\
556
564
      cur_struct>>=8;\n\
557
565
      cur_struct= uint4korr(hash_map+\n\
558
 
                        (((uint16_t)cur_struct + cur_char - first_char)*4));\n\
 
566
                        (((uint16)cur_struct + cur_char - first_char)*4));\n\
559
567
      cur_str++;\n\
560
568
    }\n\
561
569
  }\n\