MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gen_pfs_lex_token.cc
1 /*
2  Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software Foundation,
15  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
16 
17 #include <my_global.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 
22 /* We only need the tokens here */
23 #define YYSTYPE_IS_DECLARED
24 #include <../sql/sql_yacc.h>
25 #include <lex.h>
26 
27 #include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
28 
29 /*
30  This is a tool used during build only,
31  so MY_MAX_TOKEN does not need to be exact,
32  only big enough to hold:
33  - 256 character terminal tokens
34  - YYNTOKENS named terminal tokens
35  from bison.
36  See also YYMAXUTOK.
37 */
38 #define MY_MAX_TOKEN 1000
40 {
41  const char *m_token_string;
42  int m_token_length;
43 };
44 
45 gen_lex_token_string compiled_token_array[MY_MAX_TOKEN];
46 int max_token_seen= 0;
47 
48 char char_tokens[256];
49 
50 int tok_pfs_generic_value= 0;
51 int tok_pfs_generic_value_list= 0;
52 int tok_pfs_row_single_value= 0;
53 int tok_pfs_row_single_value_list= 0;
54 int tok_pfs_row_multiple_value= 0;
55 int tok_pfs_row_multiple_value_list= 0;
56 int tok_pfs_unused= 0;
57 
58 void set_token(int tok, const char *str)
59 {
60  if (tok <= 0)
61  {
62  fprintf(stderr, "Bad token found\n");
63  exit(1);
64  }
65 
66  if (tok > max_token_seen)
67  {
68  max_token_seen= tok;
69  }
70 
71  if (max_token_seen >= MY_MAX_TOKEN)
72  {
73  fprintf(stderr, "Added that many new keywords ? Increase MY_MAX_TOKEN\n");
74  exit(1);
75  }
76 
77  compiled_token_array[tok].m_token_string= str;
78  compiled_token_array[tok].m_token_length= strlen(str);
79 }
80 
81 void compute_tokens()
82 {
83  int tok;
84  unsigned int i;
85  char *str;
86 
87  /*
88  Default value.
89  */
90  for (tok= 0; tok < MY_MAX_TOKEN; tok++)
91  {
92  compiled_token_array[tok].m_token_string= "(unknown)";
93  compiled_token_array[tok].m_token_length= 9;
94  }
95 
96  /*
97  Tokens made of just one terminal character
98  */
99  for (tok=0; tok < 256; tok++)
100  {
101  str= & char_tokens[tok];
102  str[0]= (char) tok;
103  compiled_token_array[tok].m_token_string= str;
104  compiled_token_array[tok].m_token_length= 1;
105  }
106 
107  max_token_seen= 255;
108 
109  /*
110  String terminal tokens, used in sql_yacc.yy
111  */
112  set_token(NEG, "~");
113  set_token(TABLE_REF_PRIORITY, "TABLE_REF_PRIORITY");
114 
115  /*
116  Tokens hard coded in sql_lex.cc
117  */
118 
119  set_token(WITH_CUBE_SYM, "WITH CUBE");
120  set_token(WITH_ROLLUP_SYM, "WITH ROLLUP");
121  set_token(NOT2_SYM, "!");
122  set_token(OR2_SYM, "|");
123  set_token(PARAM_MARKER, "?");
124  set_token(SET_VAR, ":=");
125  set_token(UNDERSCORE_CHARSET, "(_charset)");
126  set_token(END_OF_INPUT, "");
127 
128  /*
129  Values.
130  These tokens are all normalized later,
131  so this strings will never be displayed.
132  */
133  set_token(BIN_NUM, "(bin)");
134  set_token(DECIMAL_NUM, "(decimal)");
135  set_token(FLOAT_NUM, "(float)");
136  set_token(HEX_NUM, "(hex)");
137  set_token(LEX_HOSTNAME, "(hostname)");
138  set_token(LONG_NUM, "(long)");
139  set_token(NUM, "(num)");
140  set_token(TEXT_STRING, "(text)");
141  set_token(NCHAR_STRING, "(nchar)");
142  set_token(ULONGLONG_NUM, "(ulonglong)");
143 
144  /*
145  Identifiers.
146  */
147  set_token(IDENT, "(id)");
148  set_token(IDENT_QUOTED, "(id_quoted)");
149 
150  /*
151  Unused tokens
152  */
153  set_token(LOCATOR_SYM, "LOCATOR");
154  set_token(SERVER_OPTIONS, "SERVER_OPTIONS");
155  set_token(UDF_RETURNS_SYM, "UDF_RETURNS");
156 
157  /*
158  See symbols[] in sql/lex.h
159  */
160  for (i= 0; i< sizeof(symbols)/sizeof(symbols[0]); i++)
161  {
162  set_token(symbols[i].tok, symbols[i].name);
163  }
164 
165  /*
166  See sql_functions[] in sql/lex.h
167  */
168  for (i= 0; i< sizeof(sql_functions)/sizeof(sql_functions[0]); i++)
169  {
170  set_token(sql_functions[i].tok, sql_functions[i].name);
171  }
172 
173  /*
174  Additional FAKE tokens,
175  used internally to normalize a digest text.
176  */
177 
178  max_token_seen++;
179  tok_pfs_generic_value= max_token_seen;
180  set_token(tok_pfs_generic_value, "?");
181 
182  max_token_seen++;
183  tok_pfs_generic_value_list= max_token_seen;
184  set_token(tok_pfs_generic_value_list, "?, ...");
185 
186  max_token_seen++;
187  tok_pfs_row_single_value= max_token_seen;
188  set_token(tok_pfs_row_single_value, "(?)");
189 
190  max_token_seen++;
191  tok_pfs_row_single_value_list= max_token_seen;
192  set_token(tok_pfs_row_single_value_list, "(?) /* , ... */");
193 
194  max_token_seen++;
195  tok_pfs_row_multiple_value= max_token_seen;
196  set_token(tok_pfs_row_multiple_value, "(...)");
197 
198  max_token_seen++;
199  tok_pfs_row_multiple_value_list= max_token_seen;
200  set_token(tok_pfs_row_multiple_value_list, "(...) /* , ... */");
201 
202  max_token_seen++;
203  tok_pfs_unused= max_token_seen;
204  set_token(tok_pfs_unused, "UNUSED");
205 }
206 
207 void print_tokens()
208 {
209  int tok;
210 
211  printf("lex_token_string lex_token_array[]=\n");
212  printf("{\n");
213  printf("/* PART 1: character tokens. */\n");
214 
215  for (tok= 0; tok<256; tok++)
216  {
217  printf("/* %03d */ { \"\\x%02x\", 1},\n", tok, tok);
218  }
219 
220  printf("/* PART 2: named tokens. */\n");
221 
222  for (tok= 256; tok<= max_token_seen; tok++)
223  {
224  printf("/* %03d */ { \"%s\", %d},\n",
225  tok,
226  compiled_token_array[tok].m_token_string,
227  compiled_token_array[tok].m_token_length);
228  }
229 
230  printf("/* DUMMY */ { \"\", 0}\n");
231  printf("};\n");
232 
233  printf("/* PFS specific tokens. */\n");
234  printf("#define TOK_PFS_GENERIC_VALUE %d\n", tok_pfs_generic_value);
235  printf("#define TOK_PFS_GENERIC_VALUE_LIST %d\n", tok_pfs_generic_value_list);
236  printf("#define TOK_PFS_ROW_SINGLE_VALUE %d\n", tok_pfs_row_single_value);
237  printf("#define TOK_PFS_ROW_SINGLE_VALUE_LIST %d\n", tok_pfs_row_single_value_list);
238  printf("#define TOK_PFS_ROW_MULTIPLE_VALUE %d\n", tok_pfs_row_multiple_value);
239  printf("#define TOK_PFS_ROW_MULTIPLE_VALUE_LIST %d\n", tok_pfs_row_multiple_value_list);
240  printf("#define TOK_PFS_UNUSED %d\n", tok_pfs_unused);
241 }
242 
243 int main(int argc,char **argv)
244 {
245  puts("/*");
246  puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2011"));
247  puts("*/");
248 
249  printf("/*\n");
250  printf(" This file is generated, do not edit.\n");
251  printf(" See file storage/perfschema/gen_pfs_lex_token.cc.\n");
252  printf("*/\n");
253  printf("struct lex_token_string\n");
254  printf("{\n");
255  printf(" const char *m_token_string;\n");
256  printf(" int m_token_length;\n");
257  printf("};\n");
258  printf("typedef struct lex_token_string lex_token_string;\n");
259 
260  compute_tokens();
261  print_tokens();
262 
263  return 0;
264 }
265