mariadb/pars/pars0sym.c
marko 1d1dc31a06 branches/zip: Introduce UNIV_INTERN, a linkage specifier for InnoDB-global
symbols.  Use it for all definitions of non-static variables and functions.

lexyy.c, make_flex.sh: Declare yylex as UNIV_INTERN, not static.  It is
referenced from pars0grm.c.

Actually, according to
	nm .libs/ha_innodb.so|grep -w '[ABCE-TVXYZ]'
the following symbols are still global:

* The vtable for class ha_innodb
* pars0grm.c: The function yyparse() and the variables yychar, yylval, yynerrs

The required changes to the Bison-generated file pars0grm.c will be addressed
in a separate commit, which will add a script similar to make_flex.sh.

The class ha_innodb is renamed from class ha_innobase by a #define.  Thus,
there will be no clash with the builtin InnoDB.  However, there will be some
overhead for invoking virtual methods of class ha_innodb.  Ideas for making
the vtable hidden are welcome.  -fvisibility=hidden is not available in GCC 3.
2008-02-06 14:17:36 +00:00

354 lines
7.5 KiB
C

/******************************************************
SQL parser symbol table
(c) 1997 Innobase Oy
Created 12/15/1997 Heikki Tuuri
*******************************************************/
#include "pars0sym.h"
#ifdef UNIV_NONINL
#include "pars0sym.ic"
#endif
#include "mem0mem.h"
#include "data0type.h"
#include "data0data.h"
#include "pars0grm.h"
#include "pars0pars.h"
#include "que0que.h"
#include "eval0eval.h"
#include "row0sel.h"
/**********************************************************************
Creates a symbol table for a single stored procedure or query. */
UNIV_INTERN
sym_tab_t*
sym_tab_create(
/*===========*/
/* out, own: symbol table */
mem_heap_t* heap) /* in: memory heap where to create */
{
sym_tab_t* sym_tab;
sym_tab = mem_heap_alloc(heap, sizeof(sym_tab_t));
UT_LIST_INIT(sym_tab->sym_list);
UT_LIST_INIT(sym_tab->func_node_list);
sym_tab->heap = heap;
return(sym_tab);
}
/**********************************************************************
Frees the memory allocated dynamically AFTER parsing phase for variables
etc. in the symbol table. Does not free the mem heap where the table was
originally created. Frees also SQL explicit cursor definitions. */
UNIV_INTERN
void
sym_tab_free_private(
/*=================*/
sym_tab_t* sym_tab) /* in, own: symbol table */
{
sym_node_t* sym;
func_node_t* func;
sym = UT_LIST_GET_FIRST(sym_tab->sym_list);
while (sym) {
eval_node_free_val_buf(sym);
if (sym->prefetch_buf) {
sel_col_prefetch_buf_free(sym->prefetch_buf);
}
if (sym->cursor_def) {
que_graph_free_recursive(sym->cursor_def);
}
sym = UT_LIST_GET_NEXT(sym_list, sym);
}
func = UT_LIST_GET_FIRST(sym_tab->func_node_list);
while (func) {
eval_node_free_val_buf(func);
func = UT_LIST_GET_NEXT(func_node_list, func);
}
}
/**********************************************************************
Adds an integer literal to a symbol table. */
UNIV_INTERN
sym_node_t*
sym_tab_add_int_lit(
/*================*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
ulint val) /* in: integer value */
{
sym_node_t* node;
byte* data;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
node->indirection = NULL;
dtype_set(dfield_get_type(&node->common.val), DATA_INT, 0, 4);
data = mem_heap_alloc(sym_tab->heap, 4);
mach_write_to_4(data, val);
dfield_set_data(&(node->common.val), data, 4);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->sym_table = sym_tab;
return(node);
}
/**********************************************************************
Adds a string literal to a symbol table. */
UNIV_INTERN
sym_node_t*
sym_tab_add_str_lit(
/*================*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
byte* str, /* in: string with no quotes around
it */
ulint len) /* in: string length */
{
sym_node_t* node;
byte* data;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
node->indirection = NULL;
dtype_set(dfield_get_type(&node->common.val),
DATA_VARCHAR, DATA_ENGLISH, 0);
if (len) {
data = mem_heap_alloc(sym_tab->heap, len);
ut_memcpy(data, str, len);
} else {
data = NULL;
}
dfield_set_data(&(node->common.val), data, len);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->sym_table = sym_tab;
return(node);
}
/**********************************************************************
Add a bound literal to a symbol table. */
UNIV_INTERN
sym_node_t*
sym_tab_add_bound_lit(
/*==================*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
const char* name, /* in: name of bound literal */
ulint* lit_type) /* out: type of literal (PARS_*_LIT) */
{
sym_node_t* node;
pars_bound_lit_t* blit;
ulint len = 0;
blit = pars_info_get_bound_lit(sym_tab->info, name);
ut_a(blit);
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
node->indirection = NULL;
switch (blit->type) {
case DATA_FIXBINARY:
len = blit->length;
*lit_type = PARS_FIXBINARY_LIT;
break;
case DATA_BLOB:
*lit_type = PARS_BLOB_LIT;
break;
case DATA_VARCHAR:
*lit_type = PARS_STR_LIT;
break;
case DATA_CHAR:
ut_a(blit->length > 0);
len = blit->length;
*lit_type = PARS_STR_LIT;
break;
case DATA_INT:
ut_a(blit->length > 0);
ut_a(blit->length <= 8);
len = blit->length;
*lit_type = PARS_INT_LIT;
break;
default:
ut_error;
}
dtype_set(dfield_get_type(&node->common.val),
blit->type, blit->prtype, len);
dfield_set_data(&(node->common.val), blit->address, blit->length);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->sym_table = sym_tab;
return(node);
}
/**********************************************************************
Adds an SQL null literal to a symbol table. */
UNIV_INTERN
sym_node_t*
sym_tab_add_null_lit(
/*=================*/
/* out: symbol table node */
sym_tab_t* sym_tab) /* in: symbol table */
{
sym_node_t* node;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = TRUE;
node->token_type = SYM_LIT;
node->indirection = NULL;
dfield_get_type(&node->common.val)->mtype = DATA_ERROR;
dfield_set_null(&node->common.val);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
node->sym_table = sym_tab;
return(node);
}
/**********************************************************************
Adds an identifier to a symbol table. */
UNIV_INTERN
sym_node_t*
sym_tab_add_id(
/*===========*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
byte* name, /* in: identifier name */
ulint len) /* in: identifier length */
{
sym_node_t* node;
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = FALSE;
node->indirection = NULL;
node->name = mem_heap_strdupl(sym_tab->heap, (char*) name, len);
node->name_len = len;
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
dfield_set_null(&node->common.val);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
node->sym_table = sym_tab;
return(node);
}
/**********************************************************************
Add a bound identifier to a symbol table. */
UNIV_INTERN
sym_node_t*
sym_tab_add_bound_id(
/*===========*/
/* out: symbol table node */
sym_tab_t* sym_tab, /* in: symbol table */
const char* name) /* in: name of bound id */
{
sym_node_t* node;
pars_bound_id_t* bid;
bid = pars_info_get_bound_id(sym_tab->info, name);
ut_a(bid);
node = mem_heap_alloc(sym_tab->heap, sizeof(sym_node_t));
node->common.type = QUE_NODE_SYMBOL;
node->resolved = FALSE;
node->indirection = NULL;
node->name = mem_heap_strdup(sym_tab->heap, bid->id);
node->name_len = strlen(node->name);
UT_LIST_ADD_LAST(sym_list, sym_tab->sym_list, node);
dfield_set_null(&node->common.val);
node->common.val_buf_size = 0;
node->prefetch_buf = NULL;
node->cursor_def = NULL;
node->sym_table = sym_tab;
return(node);
}