~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/gen_lex_hash.cc

  • Committer: Brian Aker
  • Date: 2008-07-01 23:01:40 UTC
  • mfrom: (28.1.27 libtool-patch)
  • Revision ID: brian@tangent.org-20080701230140-8bs081cfx1mxugp4
More Cleanup around dead files/GNU Makefile warnings (just a merge from me)

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()
247
250
char *hash_map= 0;
248
251
int size_hash_map= 0;
249
252
 
250
 
/* Ok. I honestly don't know why this has no problem and
251
 
 * array_elements macro doesn't. But it works.
252
 
 */
253
 
static inline uint32_t array_elements_func(SYMBOL * symbols) {
254
 
  return sizeof(symbols)/sizeof(symbols[0]);
255
 
}
256
 
 
257
253
void add_struct_to_map(hash_lex_struct *st)
258
254
{
259
255
  st->ithis= size_hash_map/4;
260
256
  size_hash_map+= 4;
261
257
  hash_map= (char*)realloc((char*)hash_map,size_hash_map);
262
258
  hash_map[size_hash_map-4]= (char) (st->first_char == -1 ? 0 :
263
 
                                     st->first_char);
 
259
                                     st->first_char);
264
260
  hash_map[size_hash_map-3]= (char) (st->first_char == -1 ||
265
 
                                     st->first_char == 0 ? 0 : st->last_char);
 
261
                                     st->first_char == 0 ? 0 : st->last_char);
266
262
  if (st->first_char == -1)
267
263
  {
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;
 
264
    hash_map[size_hash_map-2]= ((unsigned int)(int16)st->iresult)&255;
 
265
    hash_map[size_hash_map-1]= ((unsigned int)(int16)st->iresult)>>8;
270
266
  }
271
267
  else if (st->first_char == 0)
272
268
  {
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;
 
269
    hash_map[size_hash_map-2]= ((unsigned int)(int16)array_elements(symbols))&255;
 
270
    hash_map[size_hash_map-1]= ((unsigned int)(int16)array_elements(symbols))>>8;
275
271
  }
276
272
}
277
273
 
309
305
  char *cur;
310
306
  int i;
311
307
 
312
 
  printf("static unsigned char %s[%d]= {\n",name,size_hash_map);
 
308
  printf("static uchar %s[%d]= {\n",name,size_hash_map);
313
309
  for (i=0, cur= hash_map; i<size_hash_map; i++, cur++)
314
310
  {
315
311
    switch(i%4){
319
315
      else
320
316
        printf("\'%c\', ",*cur);
321
317
      break;
322
 
    case 2: printf("%u, ",(uint)(unsigned char)*cur); break;
323
 
    case 3: printf("%u,\n",(uint)(unsigned char)*cur); break;
 
318
    case 2: printf("%u, ",(uint)(uchar)*cur); break;
 
319
    case 3: printf("%u,\n",(uint)(uchar)*cur); break;
324
320
    }
325
321
  }
326
322
  printf("};\n");
347
343
static void usage(int version)
348
344
{
349
345
  printf("%s  Ver 3.6 Distrib %s, for %s (%s)\n",
350
 
         my_progname, DRIZZLE_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
 
346
         my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
351
347
  if (version)
352
348
    return;
353
 
  puts("Copyright (C) 2008 Sun Microsystems, Inc.");
 
349
  puts("Copyright (C) 2001 MySQL AB, by VVA and Monty");
354
350
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\
355
351
and you are welcome to modify and redistribute it under the GPL license\n");
356
352
  puts("This program generates a perfect hashing function for the sql_lex.cc");
359
355
}
360
356
 
361
357
 
362
 
extern "C" bool
 
358
extern "C" my_bool
363
359
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
364
360
               char *argument __attribute__((unused)))
365
361
{
371
367
  case '?':
372
368
    usage(0);
373
369
    exit(0);
 
370
  case '#':
 
371
    DBUG_PUSH(argument ? argument : default_dbug_option);
 
372
    break;
374
373
  }
375
374
  return 0;
376
375
}
443
442
int main(int argc,char **argv)
444
443
{
445
444
  MY_INIT(argv[0]);
 
445
  DBUG_PROCESS(argv[0]);
446
446
 
447
447
  if (get_options(argc,(char **) argv))
448
448
    exit(1);
450
450
  /* Broken up to indicate that it's not advice to you, gentle reader. */
451
451
  printf("/*\n\n  Do " "not " "edit " "this " "file " "directly!\n\n*/\n");
452
452
 
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");
 
453
  printf("\
 
454
/* Copyright (C) 2001-2004 MySQL AB\n\
 
455
\n\
 
456
   This program is free software; you can redistribute it and/or modify\n\
 
457
   it under the terms of the GNU General Public License as published by\n\
 
458
   the Free Software Foundation; version 2 of the License.\n\
 
459
\n\
 
460
   This program is distributed in the hope that it will be useful,\n\
 
461
   but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
 
462
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
 
463
   GNU General Public License for more details.\n\
 
464
\n\
 
465
   You should have received a copy of the GNU General Public License\n\
 
466
   along with this program; see the file COPYING. If not, write to the\n\
 
467
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston\n\
 
468
   MA  02110-1301  USA. */\n\
 
469
\n\
 
470
");
471
471
 
472
472
  /* Broken up to indicate that it's not advice to you, gentle reader. */
473
473
  printf("/* Do " "not " "edit " "this " "file!  This is generated by "
489
489
static SYMBOL *get_hash_symbol(const char *s,\n\
490
490
                               unsigned int len,bool function)\n\
491
491
{\n\
492
 
  register unsigned char *hash_map;\n\
 
492
  register uchar *hash_map;\n\
493
493
  register const char *cur_str= s;\n\
494
494
\n\
495
495
  if (len == 0) {\n\
 
496
    DBUG_PRINT(\"warning\", (\"get_hash_symbol() received a request for a zero-length symbol, which is probably a mistake.\"));\
496
497
    return(NULL);\n\
497
498
  }\n"
498
499
);
501
502
  if (function){\n\
502
503
    if (len>sql_functions_max_len) return 0;\n\
503
504
    hash_map= sql_functions_map;\n\
504
 
    register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
 
505
    register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
505
506
\n\
506
507
    for (;;){\n\
507
 
      register unsigned char first_char= (unsigned char)cur_struct;\n\
 
508
      register uchar first_char= (uchar)cur_struct;\n\
508
509
\n\
509
510
      if (first_char == 0)\n\
510
511
      {\n\
511
 
        register int16_t ires= (int16_t)(cur_struct>>16);\n\
 
512
        register int16 ires= (int16)(cur_struct>>16);\n\
512
513
        if (ires==array_elements(symbols)) return 0;\n\
513
514
        register SYMBOL *res;\n\
514
515
        if (ires>=0) \n\
515
516
          res= symbols+ires;\n\
516
517
        else\n\
517
518
          res= sql_functions-ires-1;\n\
518
 
        register uint32_t count= cur_str-s;\n\
 
519
        register uint count= cur_str-s;\n\
519
520
        return lex_casecmp(cur_str,res->name+count,len-count) ? 0 : res;\n\
520
521
      }\n\
521
522
\n\
522
 
      register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
 
523
      register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
523
524
      if (cur_char<first_char) return 0;\n\
524
525
      cur_struct>>=8;\n\
525
 
      if (cur_char>(unsigned char)cur_struct) return 0;\n\
 
526
      if (cur_char>(uchar)cur_struct) return 0;\n\
526
527
\n\
527
528
      cur_struct>>=8;\n\
528
529
      cur_struct= uint4korr(hash_map+\n\
529
 
                        (((uint16_t)cur_struct + cur_char - first_char)*4));\n\
 
530
                        (((uint16)cur_struct + cur_char - first_char)*4));\n\
530
531
      cur_str++;\n\
531
532
    }\n"
532
533
);
535
536
  }else{\n\
536
537
    if (len>symbols_max_len) return 0;\n\
537
538
    hash_map= symbols_map;\n\
538
 
    register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
 
539
    register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
539
540
\n\
540
541
    for (;;){\n\
541
 
      register unsigned char first_char= (unsigned char)cur_struct;\n\
 
542
      register uchar first_char= (uchar)cur_struct;\n\
542
543
\n\
543
544
      if (first_char==0){\n\
544
 
        register int16_t ires= (int16_t)(cur_struct>>16);\n\
 
545
        register int16 ires= (int16)(cur_struct>>16);\n\
545
546
        if (ires==array_elements(symbols)) return 0;\n\
546
547
        register SYMBOL *res= symbols+ires;\n\
547
 
        register uint32_t count= cur_str-s;\n\
 
548
        register uint count= cur_str-s;\n\
548
549
        return lex_casecmp(cur_str,res->name+count,len-count)!=0 ? 0 : res;\n\
549
550
      }\n\
550
551
\n\
551
 
      register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
 
552
      register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
552
553
      if (cur_char<first_char) return 0;\n\
553
554
      cur_struct>>=8;\n\
554
 
      if (cur_char>(unsigned char)cur_struct) return 0;\n\
 
555
      if (cur_char>(uchar)cur_struct) return 0;\n\
555
556
\n\
556
557
      cur_struct>>=8;\n\
557
558
      cur_struct= uint4korr(hash_map+\n\
558
 
                        (((uint16_t)cur_struct + cur_char - first_char)*4));\n\
 
559
                        (((uint16)cur_struct + cur_char - first_char)*4));\n\
559
560
      cur_str++;\n\
560
561
    }\n\
561
562
  }\n\