The world's most popular open source database
#include "my_global.h"#include "my_sys.h"#include "m_string.h"#include <my_getopt.h>#include "mysql_version.h"#include "lex.h"Include dependency graph for gen_lex_hash.cc:

Go to the source code of this file.
Classes | |
| struct | hash_lex_struct |
Defines | |
| #define | NO_YACC_SYMBOLS |
| #define | __GNU_LIBRARY__ |
Functions | |
| hash_lex_struct * | get_hash_struct_by_len (hash_lex_struct **root_by_len, int len, int *max_len) |
| void | insert_into_hash (hash_lex_struct *root, const char *name, int len_from_begin, int index, int function) |
| void | insert_symbols () |
| void | insert_sql_functions () |
| void | calc_length () |
| void | generate_find_structs () |
| void | add_struct_to_map (hash_lex_struct *st) |
| void | add_structs_to_map (hash_lex_struct *st, int len) |
| void | set_links (hash_lex_struct *st, int len) |
| void | print_hash_map (const char *name) |
| void | print_find_structs () |
| static void | usage (int version) |
| my_bool | get_one_option (int optid, const struct my_option *opt __attribute__((unused)), char *argument __attribute__((unused))) |
| static int | get_options (int argc, char **argv) |
| int | check_dup_symbols (SYMBOL *s1, SYMBOL *s2) |
| int | check_duplicates () |
| int | main (int argc, char **argv) |
Variables | |
| const char * | default_dbug_option = "d:t:o,/tmp/gen_lex_hash.trace" |
| my_option | my_long_options [] |
| hash_lex_struct * | root_by_len = 0 |
| int | max_len = 0 |
| hash_lex_struct * | root_by_len2 = 0 |
| int | max_len2 = 0 |
| char * | hash_map = 0 |
| int | size_hash_map = 0 |
| #define __GNU_LIBRARY__ |
Definition at line 80 of file gen_lex_hash.cc.
| #define NO_YACC_SYMBOLS |
Definition at line 75 of file gen_lex_hash.cc.
| void add_struct_to_map | ( | hash_lex_struct * | st | ) |
Definition at line 248 of file gen_lex_hash.cc.
References array_elements, hash_lex_struct::first_char, hash_map, int(), hash_lex_struct::iresult, hash_lex_struct::ithis, hash_lex_struct::last_char, realloc, size_hash_map, and symbols.
Referenced by add_structs_to_map().
00249 { 00250 st->ithis= size_hash_map/4; 00251 size_hash_map+= 4; 00252 hash_map= (char*)realloc((char*)hash_map,size_hash_map); 00253 hash_map[size_hash_map-4]= (char) (st->first_char == -1 ? 0 : 00254 st->first_char); 00255 hash_map[size_hash_map-3]= (char) (st->first_char == -1 || 00256 st->first_char == 0 ? 0 : st->last_char); 00257 if (st->first_char == -1) 00258 { 00259 hash_map[size_hash_map-2]= ((unsigned int)(int16)st->iresult)&255; 00260 hash_map[size_hash_map-1]= ((unsigned int)(int16)st->iresult)>>8; 00261 } 00262 else if (st->first_char == 0) 00263 { 00264 hash_map[size_hash_map-2]= ((unsigned int)(int16)array_elements(symbols))&255; 00265 hash_map[size_hash_map-1]= ((unsigned int)(int16)array_elements(symbols))>>8; 00266 } 00267 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void add_structs_to_map | ( | hash_lex_struct * | st, | |
| int | len | |||
| ) |
Definition at line 270 of file gen_lex_hash.cc.
References add_struct_to_map(), hash_lex_struct::char_tails, hash_lex_struct::first_char, and hash_lex_struct::last_char.
Referenced by print_find_structs().
00271 { 00272 hash_lex_struct *cur, *end= st+len; 00273 for (cur= st; cur<end; cur++) 00274 add_struct_to_map(cur); 00275 for (cur= st; cur<end; cur++) 00276 { 00277 if (cur->first_char && cur->first_char != -1) 00278 add_structs_to_map(cur->char_tails,cur->last_char-cur->first_char+1); 00279 } 00280 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void calc_length | ( | ) |
Definition at line 218 of file gen_lex_hash.cc.
References array_elements, st_symbol::length, st_symbol::name, sql_functions, strlen(), and symbols.
Referenced by main().
00219 { 00220 SYMBOL *cur, *end= symbols + array_elements(symbols); 00221 for (cur= symbols; cur < end; cur++) 00222 cur->length=(uchar) strlen(cur->name); 00223 end= sql_functions + array_elements(sql_functions); 00224 for (cur= sql_functions; cur<end; cur++) 00225 cur->length=(uchar) strlen(cur->name); 00226 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 389 of file gen_lex_hash.cc.
References st_symbol::length, and st_symbol::name.
Referenced by check_duplicates().
00390 { 00391 if (s1->length!=s2->length || strncmp(s1->name,s2->name,s1->length)) 00392 return 0; 00393 00394 const char *err_tmpl= "\ngen_lex_hash fatal error : \ 00395 Unfortunately gen_lex_hash can not generate a hash,\n since \ 00396 your lex.h has duplicate definition for a symbol \"%s\"\n\n"; 00397 printf (err_tmpl,s1->name); 00398 fprintf (stderr,err_tmpl,s1->name); 00399 00400 return 1; 00401 }
Here is the caller graph for this function:

| int check_duplicates | ( | ) |
Definition at line 404 of file gen_lex_hash.cc.
References array_elements, check_dup_symbols(), sql_functions, and symbols.
Referenced by main().
00405 { 00406 SYMBOL *cur1, *cur2, *s_end, *f_end; 00407 00408 s_end= symbols + array_elements(symbols); 00409 f_end= sql_functions + array_elements(sql_functions); 00410 00411 for (cur1= symbols; cur1<s_end; cur1++) 00412 { 00413 for (cur2= cur1+1; cur2<s_end; cur2++) 00414 { 00415 if (check_dup_symbols(cur1,cur2)) 00416 return 1; 00417 } 00418 for (cur2= sql_functions; cur2<f_end; cur2++) 00419 { 00420 if (check_dup_symbols(cur1,cur2)) 00421 return 1; 00422 } 00423 } 00424 00425 for (cur1= sql_functions; cur1<f_end; cur1++) 00426 { 00427 for (cur2= cur1+1; cur2< f_end; cur2++) 00428 { 00429 if (check_dup_symbols(cur1,cur2)) 00430 return 1; 00431 } 00432 } 00433 return 0; 00434 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void generate_find_structs | ( | ) |
Definition at line 228 of file gen_lex_hash.cc.
References insert_sql_functions(), insert_symbols(), max_len, max_len2, root_by_len, and root_by_len2.
Referenced by main().
00229 { 00230 root_by_len= 0; 00231 max_len=0; 00232 00233 insert_symbols(); 00234 00235 root_by_len2= root_by_len; 00236 max_len2= max_len; 00237 00238 root_by_len= 0; 00239 max_len= 0; 00240 00241 insert_symbols(); 00242 insert_sql_functions(); 00243 }
Here is the call graph for this function:

Here is the caller graph for this function:

| hash_lex_struct* get_hash_struct_by_len | ( | hash_lex_struct ** | root_by_len, | |
| int | len, | |||
| int * | max_len | |||
| ) |
Definition at line 115 of file gen_lex_hash.cc.
References hash_lex_struct::first_char, realloc, and root_by_len.
Referenced by insert_sql_functions(), and insert_symbols().
00117 { 00118 if (*max_len<len){ 00119 *root_by_len= (hash_lex_struct *)realloc((char*)*root_by_len, 00120 sizeof(hash_lex_struct)*len); 00121 hash_lex_struct *cur, *end= *root_by_len + len; 00122 for (cur= *root_by_len + *max_len; cur<end; cur++) 00123 cur->first_char= 0; 00124 *max_len= len; 00125 } 00126 return (*root_by_len)+(len-1); 00127 }
Here is the caller graph for this function:

| my_bool get_one_option | ( | int | optid, | |
| const struct my_option *opt | __attribute__((unused)), | |||
| char *argument | __attribute__((unused)) | |||
| ) |
Definition at line 354 of file gen_lex_hash.cc.
References DBUG_PUSH, default_dbug_option, exit, and usage().
00356 { 00357 switch(optid) { 00358 case 'V': 00359 usage(1); 00360 exit(0); 00361 case 'I': 00362 case '?': 00363 usage(0); 00364 exit(0); 00365 case '#': 00366 DBUG_PUSH(argument ? argument : default_dbug_option); 00367 break; 00368 } 00369 return 0; 00370 }
Here is the call graph for this function:

| static int get_options | ( | int | argc, | |
| char ** | argv | |||
| ) | [static] |
Definition at line 373 of file gen_lex_hash.cc.
References exit, get_one_option(), handle_options(), my_long_options, and usage().
00374 { 00375 int ho_error; 00376 00377 if ((ho_error= handle_options(&argc, &argv, my_long_options, get_one_option))) 00378 exit(ho_error); 00379 00380 if (argc >= 1) 00381 { 00382 usage(0); 00383 exit(1); 00384 } 00385 return(0); 00386 }
Here is the call graph for this function:

| void insert_into_hash | ( | hash_lex_struct * | root, | |
| const char * | name, | |||
| int | len_from_begin, | |||
| int | index, | |||
| int | function | |||
| ) |
Definition at line 129 of file gen_lex_hash.cc.
References hash_lex_struct::char_tails, hash_lex_struct::first_char, int(), hash_lex_struct::iresult, hash_lex_struct::last_char, malloc, memmove, realloc, sql_functions, and symbols.
Referenced by insert_sql_functions(), and insert_symbols().
00131 { 00132 hash_lex_struct *end, *cur, *tails; 00133 00134 if (!root->first_char) 00135 { 00136 root->first_char= -1; 00137 root->iresult= index; 00138 return; 00139 } 00140 00141 if (root->first_char == -1) 00142 { 00143 int index2= root->iresult; 00144 const char *name2= (index2 < 0 ? sql_functions[-index2-1] : 00145 symbols[index2]).name + len_from_begin; 00146 root->first_char= (int) (uchar) name2[0]; 00147 root->last_char= (char) root->first_char; 00148 tails= (hash_lex_struct*)malloc(sizeof(hash_lex_struct)); 00149 root->char_tails= tails; 00150 tails->first_char= -1; 00151 tails->iresult= index2; 00152 } 00153 00154 size_t real_size= (root->last_char-root->first_char+1); 00155 00156 if (root->first_char>(*name)) 00157 { 00158 size_t new_size= root->last_char-(*name)+1; 00159 if (new_size<real_size) printf("error!!!!\n"); 00160 tails= root->char_tails; 00161 tails= (hash_lex_struct*)realloc((char*)tails, 00162 sizeof(hash_lex_struct)*new_size); 00163 root->char_tails= tails; 00164 memmove(tails+(new_size-real_size),tails,real_size*sizeof(hash_lex_struct)); 00165 end= tails + new_size - real_size; 00166 for (cur= tails; cur<end; cur++) 00167 cur->first_char= 0; 00168 root->first_char= (int) (uchar) *name; 00169 } 00170 00171 if (root->last_char<(*name)) 00172 { 00173 size_t new_size= (*name)-root->first_char+1; 00174 if (new_size<real_size) printf("error!!!!\n"); 00175 tails= root->char_tails; 00176 tails= (hash_lex_struct*)realloc((char*)tails, 00177 sizeof(hash_lex_struct)*new_size); 00178 root->char_tails= tails; 00179 end= tails + new_size; 00180 for (cur= tails+real_size; cur<end; cur++) 00181 cur->first_char= 0; 00182 root->last_char= (*name); 00183 } 00184 00185 insert_into_hash(root->char_tails+(*name)-root->first_char, 00186 name+1,len_from_begin+1,index,function); 00187 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void insert_sql_functions | ( | ) |
Definition at line 207 of file gen_lex_hash.cc.
References array_elements, get_hash_struct_by_len(), insert_into_hash(), st_symbol::length, max_len, st_symbol::name, root_by_len, and sql_functions.
Referenced by generate_find_structs().
00208 { 00209 size_t i= 0; 00210 SYMBOL *cur; 00211 for (cur= sql_functions; i<array_elements(sql_functions); cur++, i++){ 00212 hash_lex_struct *root= 00213 get_hash_struct_by_len(&root_by_len,cur->length,&max_len); 00214 insert_into_hash(root,cur->name,0,-i-1,1); 00215 } 00216 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void insert_symbols | ( | ) |
Definition at line 196 of file gen_lex_hash.cc.
References array_elements, get_hash_struct_by_len(), insert_into_hash(), st_symbol::length, max_len, st_symbol::name, root_by_len, and symbols.
Referenced by generate_find_structs().
00197 { 00198 size_t i= 0; 00199 SYMBOL *cur; 00200 for (cur= symbols; i<array_elements(symbols); cur++, i++){ 00201 hash_lex_struct *root= 00202 get_hash_struct_by_len(&root_by_len,cur->length,&max_len); 00203 insert_into_hash(root,cur->name,0,i,0); 00204 } 00205 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 437 of file gen_lex_hash.cc.
References calc_length(), check_duplicates(), DBUG_PROCESS, exit, generate_find_structs(), get_options(), max_len, max_len2, my_end(), MY_INIT, and print_find_structs().
00438 { 00439 MY_INIT(argv[0]); 00440 DBUG_PROCESS(argv[0]); 00441 00442 if (get_options(argc,(char **) argv)) 00443 exit(1); 00444 00445 printf("/* Copyright (C) 2001-2004 MySQL AB\n\ 00446 This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ 00447 and you are welcome to modify and redistribute it under the GPL license\n\ 00448 \n*/\n\n"); 00449 00450 printf("/* This code is generated by gen_lex_hash.cc that seeks for\ 00451 a perfect\nhash function */\n\n"); 00452 printf("#include \"lex.h\"\n\n"); 00453 00454 calc_length(); 00455 00456 if (check_duplicates()) 00457 exit(1); 00458 00459 generate_find_structs(); 00460 print_find_structs(); 00461 00462 printf("\nstatic unsigned int sql_functions_max_len=%d;\n", max_len); 00463 printf("\nstatic unsigned int symbols_max_len=%d;\n\n", max_len2); 00464 00465 printf("\ 00466 static inline SYMBOL *get_hash_symbol(const char *s,\n\ 00467 unsigned int len,bool function)\n\ 00468 {\n\ 00469 register uchar *hash_map;\n\ 00470 register const char *cur_str= s;\n\ 00471 if (function){\n\ 00472 if (len>sql_functions_max_len) return 0;\n\ 00473 hash_map= sql_functions_map;\n\ 00474 register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\ 00475 \n\ 00476 for (;;){\n\ 00477 register uchar first_char= (uchar)cur_struct;\n\ 00478 \n\ 00479 if (first_char == 0)\n\ 00480 {\n\ 00481 register int16 ires= (int16)(cur_struct>>16);\n\ 00482 if (ires==array_elements(symbols)) return 0;\n\ 00483 register SYMBOL *res;\n\ 00484 if (ires>=0) \n\ 00485 res= symbols+ires;\n\ 00486 else\n\ 00487 res= sql_functions-ires-1;\n\ 00488 register uint count= cur_str-s;\n\ 00489 return lex_casecmp(cur_str,res->name+count,len-count) ? 0 : res;\n\ 00490 }\n\ 00491 \n\ 00492 register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\ 00493 if (cur_char<first_char) return 0;\n\ 00494 cur_struct>>=8;\n\ 00495 if (cur_char>(uchar)cur_struct) return 0;\n\ 00496 \n\ 00497 cur_struct>>=8;\n\ 00498 cur_struct= uint4korr(hash_map+\n\ 00499 (((uint16)cur_struct + cur_char - first_char)*4));\n\ 00500 cur_str++;\n\ 00501 }\n\ 00502 }else{\n\ 00503 if (len>symbols_max_len) return 0;\n\ 00504 hash_map= symbols_map;\n\ 00505 register uint32 cur_struct= uint4korr(hash_map+((len-1)*4));\n\ 00506 \n\ 00507 for (;;){\n\ 00508 register uchar first_char= (uchar)cur_struct;\n\ 00509 \n\ 00510 if (first_char==0){\n\ 00511 register int16 ires= (int16)(cur_struct>>16);\n\ 00512 if (ires==array_elements(symbols)) return 0;\n\ 00513 register SYMBOL *res= symbols+ires;\n\ 00514 register uint count= cur_str-s;\n\ 00515 return lex_casecmp(cur_str,res->name+count,len-count)!=0 ? 0 : res;\n\ 00516 }\n\ 00517 \n\ 00518 register uchar cur_char= (uchar)to_upper_lex[(uchar)*cur_str];\n\ 00519 if (cur_char<first_char) return 0;\n\ 00520 cur_struct>>=8;\n\ 00521 if (cur_char>(uchar)cur_struct) return 0;\n\ 00522 \n\ 00523 cur_struct>>=8;\n\ 00524 cur_struct= uint4korr(hash_map+\n\ 00525 (((uint16)cur_struct + cur_char - first_char)*4));\n\ 00526 cur_str++;\n\ 00527 }\n\ 00528 }\n\ 00529 }\n" 00530 ); 00531 my_end(0); 00532 exit(0); 00533 }
Here is the call graph for this function:

| void print_find_structs | ( | ) |
Definition at line 321 of file gen_lex_hash.cc.
References add_structs_to_map(), hash_map, max_len, max_len2, print_hash_map(), root_by_len, root_by_len2, set_links(), and size_hash_map.
Referenced by main().
00322 { 00323 add_structs_to_map(root_by_len,max_len); 00324 set_links(root_by_len,max_len); 00325 print_hash_map("sql_functions_map"); 00326 00327 hash_map= 0; 00328 size_hash_map= 0; 00329 00330 printf("\n"); 00331 00332 add_structs_to_map(root_by_len2,max_len2); 00333 set_links(root_by_len2,max_len2); 00334 print_hash_map("symbols_map"); 00335 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void print_hash_map | ( | const char * | name | ) |
Definition at line 298 of file gen_lex_hash.cc.
References hash_map, and size_hash_map.
Referenced by print_find_structs().
00299 { 00300 char *cur; 00301 int i; 00302 00303 printf("static uchar %s[%d]= {\n",name,size_hash_map); 00304 for (i=0, cur= hash_map; i<size_hash_map; i++, cur++) 00305 { 00306 switch(i%4){ 00307 case 0: case 1: 00308 if (!*cur) 00309 printf("0, "); 00310 else 00311 printf("\'%c\', ",*cur); 00312 break; 00313 case 2: printf("%u, ",(uint)(uchar)*cur); break; 00314 case 3: printf("%u,\n",(uint)(uchar)*cur); break; 00315 } 00316 } 00317 printf("};\n"); 00318 }
Here is the caller graph for this function:

| void set_links | ( | hash_lex_struct * | st, | |
| int | len | |||
| ) |
Definition at line 282 of file gen_lex_hash.cc.
References hash_lex_struct::char_tails, hash_lex_struct::first_char, hash_map, hash_lex_struct::ithis, and hash_lex_struct::last_char.
Referenced by print_find_structs().
00283 { 00284 hash_lex_struct *cur, *end= st+len; 00285 for (cur= st; cur<end; cur++) 00286 { 00287 if (cur->first_char != 0 && cur->first_char != -1) 00288 { 00289 int ilink= cur->char_tails->ithis; 00290 hash_map[cur->ithis*4+2]= ilink%256; 00291 hash_map[cur->ithis*4+3]= ilink/256; 00292 set_links(cur->char_tails,cur->last_char-cur->first_char+1); 00293 } 00294 } 00295 }
Here is the caller graph for this function:

| static void usage | ( | int | version | ) | [static] |
Definition at line 338 of file gen_lex_hash.cc.
References MACHINE_TYPE, my_long_options, my_print_help(), my_progname, MYSQL_SERVER_VERSION, and SYSTEM_TYPE.
00339 { 00340 printf("%s Ver 3.6 Distrib %s, for %s (%s)\n", 00341 my_progname, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); 00342 if (version) 00343 return; 00344 puts("Copyright (C) 2001 MySQL AB, by VVA and Monty"); 00345 puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ 00346 and you are welcome to modify and redistribute it under the GPL license\n"); 00347 puts("This program generates a perfect hashing function for the sql_lex.cc"); 00348 printf("Usage: %s [OPTIONS]\n\n", my_progname); 00349 my_print_help(my_long_options); 00350 }
Here is the call graph for this function:

| const char* default_dbug_option = "d:t:o,/tmp/gen_lex_hash.trace" |
Definition at line 86 of file gen_lex_hash.cc.
| char* hash_map = 0 |
Definition at line 245 of file gen_lex_hash.cc.
Referenced by add_struct_to_map(), get_hash_symbol(), print_find_structs(), print_hash_map(), and set_links().
| int max_len = 0 |
Definition at line 191 of file gen_lex_hash.cc.
Referenced by expand_var_part(), generate_find_structs(), NdbColumnImpl::get_var_length(), insert_sql_functions(), insert_symbols(), main(), and print_find_structs().
| int max_len2 = 0 |
Definition at line 194 of file gen_lex_hash.cc.
Referenced by generate_find_structs(), main(), and print_find_structs().
| struct my_option my_long_options[] |
Initial value:
{
{"debug", '#', "Output debug log", (gptr*) &default_dbug_option,
(gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"help", '?', "Display help and exit",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}
Definition at line 88 of file gen_lex_hash.cc.
Definition at line 190 of file gen_lex_hash.cc.
Referenced by generate_find_structs(), get_hash_struct_by_len(), insert_sql_functions(), insert_symbols(), and print_find_structs().
Definition at line 193 of file gen_lex_hash.cc.
Referenced by generate_find_structs(), and print_find_structs().
| int size_hash_map = 0 |
Definition at line 246 of file gen_lex_hash.cc.
Referenced by add_struct_to_map(), print_find_structs(), and print_hash_map().
1.4.7

