~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/gen_lex_hash.cc

Removed dead variable, sorted authors file.

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 "drizzle_version.h"
92
88
#include "lex.h"
93
89
 
94
90
const char *default_dbug_option="d:t:o,/tmp/gen_lex_hash.trace";
144
140
    int index2= root->iresult;
145
141
    const char *name2= (index2 < 0 ? sql_functions[-index2-1] :
146
142
                        symbols[index2]).name + len_from_begin;
147
 
    root->first_char= (int) (unsigned char) name2[0];
 
143
    root->first_char= (int) (uchar) name2[0];
148
144
    root->last_char= (char) root->first_char;
149
145
    tails= (hash_lex_struct*)malloc(sizeof(hash_lex_struct));
150
146
    root->char_tails= tails;
166
162
    end= tails + new_size - real_size;
167
163
    for (cur= tails; cur<end; cur++)
168
164
      cur->first_char= 0;
169
 
    root->first_char= (int) (unsigned char) *name;
 
165
    root->first_char= (int) (uchar) *name;
170
166
  }
171
167
 
172
168
  if (root->last_char<(*name))
221
217
{
222
218
  SYMBOL *cur, *end= symbols + array_elements(symbols);
223
219
  for (cur= symbols; cur < end; cur++)
224
 
    cur->length=(unsigned char) strlen(cur->name);
 
220
    cur->length=(uchar) strlen(cur->name);
225
221
  end= sql_functions + array_elements(sql_functions);
226
222
  for (cur= sql_functions; cur<end; cur++)
227
 
    cur->length=(unsigned char) strlen(cur->name);
 
223
    cur->length=(uchar) strlen(cur->name);
228
224
}
229
225
 
230
226
void generate_find_structs()
265
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_func(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");
450
446
  /* Broken up to indicate that it's not advice to you, gentle reader. */
451
447
  printf("/*\n\n  Do " "not " "edit " "this " "file " "directly!\n\n*/\n");
452
448
 
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");
 
449
  printf("\
 
450
/* Copyright (C) 2001-2004 MySQL AB\n\
 
451
\n\
 
452
   This program is free software; you can redistribute it and/or modify\n\
 
453
   it under the terms of the GNU General Public License as published by\n\
 
454
   the Free Software Foundation; version 2 of the License.\n\
 
455
\n\
 
456
   This program is distributed in the hope that it will be useful,\n\
 
457
   but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
 
458
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n\
 
459
   GNU General Public License for more details.\n\
 
460
\n\
 
461
   You should have received a copy of the GNU General Public License\n\
 
462
   along with this program; see the file COPYING. If not, write to the\n\
 
463
   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston\n\
 
464
   MA  02110-1301  USA. */\n\
 
465
\n\
 
466
");
471
467
 
472
468
  /* Broken up to indicate that it's not advice to you, gentle reader. */
473
469
  printf("/* Do " "not " "edit " "this " "file!  This is generated by "
489
485
static SYMBOL *get_hash_symbol(const char *s,\n\
490
486
                               unsigned int len,bool function)\n\
491
487
{\n\
492
 
  register unsigned char *hash_map;\n\
 
488
  register uchar *hash_map;\n\
493
489
  register const char *cur_str= s;\n\
494
490
\n\
495
491
  if (len == 0) {\n\
501
497
  if (function){\n\
502
498
    if (len>sql_functions_max_len) return 0;\n\
503
499
    hash_map= sql_functions_map;\n\
504
 
    register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
 
500
    register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
505
501
\n\
506
502
    for (;;){\n\
507
 
      register unsigned char first_char= (unsigned char)cur_struct;\n\
 
503
      register uchar first_char= (uchar)cur_struct;\n\
508
504
\n\
509
505
      if (first_char == 0)\n\
510
506
      {\n\
511
 
        register int16_t ires= (int16_t)(cur_struct>>16);\n\
 
507
        register int16 ires= (int16)(cur_struct>>16);\n\
512
508
        if (ires==array_elements(symbols)) return 0;\n\
513
509
        register SYMBOL *res;\n\
514
510
        if (ires>=0) \n\
515
511
          res= symbols+ires;\n\
516
512
        else\n\
517
513
          res= sql_functions-ires-1;\n\
518
 
        register uint32_t count= cur_str-s;\n\
 
514
        register uint count= cur_str-s;\n\
519
515
        return lex_casecmp(cur_str,res->name+count,len-count) ? 0 : res;\n\
520
516
      }\n\
521
517
\n\
522
 
      register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
 
518
      register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
523
519
      if (cur_char<first_char) return 0;\n\
524
520
      cur_struct>>=8;\n\
525
 
      if (cur_char>(unsigned char)cur_struct) return 0;\n\
 
521
      if (cur_char>(uchar)cur_struct) return 0;\n\
526
522
\n\
527
523
      cur_struct>>=8;\n\
528
524
      cur_struct= uint4korr(hash_map+\n\
529
 
                        (((uint16_t)cur_struct + cur_char - first_char)*4));\n\
 
525
                        (((uint16)cur_struct + cur_char - first_char)*4));\n\
530
526
      cur_str++;\n\
531
527
    }\n"
532
528
);
535
531
  }else{\n\
536
532
    if (len>symbols_max_len) return 0;\n\
537
533
    hash_map= symbols_map;\n\
538
 
    register uint32_t cur_struct= uint4korr(hash_map+((len-1)*4));\n\
 
534
    register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\
539
535
\n\
540
536
    for (;;){\n\
541
 
      register unsigned char first_char= (unsigned char)cur_struct;\n\
 
537
      register uchar first_char= (uchar)cur_struct;\n\
542
538
\n\
543
539
      if (first_char==0){\n\
544
 
        register int16_t ires= (int16_t)(cur_struct>>16);\n\
 
540
        register int16 ires= (int16)(cur_struct>>16);\n\
545
541
        if (ires==array_elements(symbols)) return 0;\n\
546
542
        register SYMBOL *res= symbols+ires;\n\
547
 
        register uint32_t count= cur_str-s;\n\
 
543
        register uint count= cur_str-s;\n\
548
544
        return lex_casecmp(cur_str,res->name+count,len-count)!=0 ? 0 : res;\n\
549
545
      }\n\
550
546
\n\
551
 
      register unsigned char cur_char= (unsigned char)to_upper_lex[(unsigned char)*cur_str];\n\
 
547
      register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\
552
548
      if (cur_char<first_char) return 0;\n\
553
549
      cur_struct>>=8;\n\
554
 
      if (cur_char>(unsigned char)cur_struct) return 0;\n\
 
550
      if (cur_char>(uchar)cur_struct) return 0;\n\
555
551
\n\
556
552
      cur_struct>>=8;\n\
557
553
      cur_struct= uint4korr(hash_map+\n\
558
 
                        (((uint16_t)cur_struct + cur_char - first_char)*4));\n\
 
554
                        (((uint16)cur_struct + cur_char - first_char)*4));\n\
559
555
      cur_str++;\n\
560
556
    }\n\
561
557
  }\n\