Get rid of some redundant parser types.

This commit is contained in:
Mike McCormack 2005-05-29 20:17:16 +00:00 committed by Alexandre Julliard
parent 309ae27805
commit d1a55eb3f8
7 changed files with 85 additions and 112 deletions

View File

@ -44,7 +44,7 @@ typedef struct tagMSICREATEVIEW
MSIDATABASE *db;
LPWSTR name;
BOOL bIsTemp;
create_col_info *col_info;
column_info *col_info;
} MSICREATEVIEW;
static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
@ -59,7 +59,7 @@ static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT
static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
{
MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
create_col_info *col;
column_info *col;
UINT r, nField, row, table_val, column_val;
static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
@ -122,8 +122,8 @@ static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
if( r )
goto err;
column_val = msi_addstringW( cv->db->strings, 0, col->colname, -1, 1 );
TRACE("New string %s -> %d\n", debugstr_w( col->colname ), column_val );
column_val = msi_addstringW( cv->db->strings, 0, col->column, -1, 1 );
TRACE("New string %s -> %d\n", debugstr_w( col->column ), column_val );
if( column_val < 0 )
break;
@ -226,7 +226,7 @@ MSIVIEWOPS create_ops =
};
UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
create_col_info *col_info, BOOL temp )
column_info *col_info, BOOL temp )
{
MSICREATEVIEW *cv = NULL;

View File

@ -255,7 +255,7 @@ MSIVIEWOPS insert_ops =
};
UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
string_list *columns, value_list *values, BOOL temp )
column_info *columns, value_list *values, BOOL temp )
{
MSIINSERTVIEW *iv = NULL;
UINT r;

View File

@ -302,11 +302,11 @@ static UINT ORDER_AddColumn( MSIORDERVIEW *ov, LPCWSTR name )
}
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns )
column_info *columns )
{
MSIORDERVIEW *ov = NULL;
UINT count = 0, r;
string_list *x;
column_info *x;
TRACE("%p\n", ov );
@ -332,7 +332,7 @@ UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
*view = (MSIVIEW*) ov;
for( x = columns; x ; x = x->next )
ORDER_AddColumn( ov, x->string );
ORDER_AddColumn( ov, x->column );
return ERROR_SUCCESS;
}

View File

@ -59,11 +59,14 @@ struct sql_str {
INT len;
};
typedef struct _string_list
typedef struct _column_info
{
LPWSTR string;
struct _string_list *next;
} string_list;
LPCWSTR table;
LPCWSTR column;
UINT type;
struct expr *val;
struct _column_info *next;
} column_info;
struct complex_expr
{
@ -80,56 +83,42 @@ struct expr
struct complex_expr expr;
INT ival;
UINT uval;
LPWSTR sval;
LPWSTR column;
LPCWSTR sval;
LPCWSTR column;
UINT col_number;
} u;
};
typedef struct _create_col_info
{
LPWSTR colname;
UINT type;
struct _create_col_info *next;
} create_col_info;
typedef struct _value_list
{
struct expr *val;
struct _value_list *next;
} value_list;
typedef struct _column_assignment
{
string_list *col_list;
value_list *val_list;
} column_assignment;
UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phview,
struct list *mem );
UINT TABLE_CreateView( MSIDATABASE *db, LPCWSTR name, MSIVIEW **view );
UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns );
column_info *columns );
UINT DISTINCT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns );
column_info *columns );
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
struct expr *cond );
UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
create_col_info *col_info, BOOL temp );
column_info *col_info, BOOL temp );
UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
string_list *columns, value_list *values, BOOL temp );
column_info *columns, value_list *values, BOOL temp );
UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **, LPWSTR table,
column_assignment *list, struct expr *expr );
column_info *list, struct expr *expr );
UINT DELETE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );

View File

@ -210,7 +210,7 @@ MSIVIEWOPS select_ops =
SELECT_delete
};
static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPWSTR name )
static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name )
{
UINT r, n=0;
MSIVIEW *table;
@ -245,7 +245,7 @@ static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPWSTR name )
}
UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns )
column_info *columns )
{
MSISELECTVIEW *sv = NULL;
UINT count = 0, r;
@ -273,7 +273,7 @@ UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
while( columns )
{
r = SELECT_AddColumn( sv, columns->string );
r = SELECT_AddColumn( sv, columns->column );
if( r )
break;
columns = columns->next;

View File

@ -55,11 +55,12 @@ static INT SQL_getint( void *info );
static int SQL_lex( void *SQL_lval, SQL_input *info );
static void *parser_alloc( void *info, unsigned int sz );
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column );
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols, string_list *keys);
static BOOL SQL_MarkPrimaryKeys( column_info *cols, column_info *keys);
static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct expr *r );
static struct expr * EXPR_column( void *info, LPWSTR column );
static struct expr * EXPR_column( void *info, column_info *column );
static struct expr * EXPR_ival( void *info, struct sql_str *, int sign );
static struct expr * EXPR_sval( void *info, struct sql_str * );
static struct expr * EXPR_wildcard( void *info );
@ -72,13 +73,11 @@ static struct expr * EXPR_wildcard( void *info );
{
struct sql_str str;
LPWSTR string;
string_list *column_list;
column_info *column_list;
value_list *val_list;
MSIVIEW *query;
struct expr *expr;
USHORT column_type;
create_col_info *column_info;
column_assignment update_col_info;
}
%token TK_ABORT TK_AFTER TK_AGG_FUNCTION TK_ALL TK_AND TK_AS TK_ASC
@ -125,15 +124,14 @@ static struct expr * EXPR_wildcard( void *info );
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
COLUMN AGG_FUNCTION.
%type <string> column table id
%type <column_list> selcollist
%type <query> query from fromtable unorderedsel selectfrom
%type <string> table id
%type <column_list> selcollist column column_and_type column_def table_def
%type <column_list> column_assignment update_assign_list
%type <query> query from fromtable selectfrom unorderedsel
%type <query> oneupdate onedelete oneselect onequery onecreate oneinsert
%type <expr> expr val column_val const_val
%type <column_type> column_type data_type data_type_l data_count
%type <column_info> column_def table_def
%type <val_list> constlist
%type <update_col_info> column_assignment update_assign_list
%%
@ -210,7 +208,7 @@ oneupdate:
SQL_input* sql = (SQL_input*) info;
MSIVIEW *update = NULL;
UPDATE_CreateView( sql->db, &update, $2, &$4, $6 );
UPDATE_CreateView( sql->db, &update, $2, $4, $6 );
if( !update )
YYABORT;
$$ = update;
@ -241,33 +239,27 @@ table_def:
;
column_def:
column_def TK_COMMA column column_type
column_def TK_COMMA column_and_type
{
create_col_info *ci;
column_info *ci;
for( ci = $1; ci->next; ci = ci->next )
;
ci->next = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
if( !ci->next )
{
/* FIXME: free $1 */
YYABORT;
}
ci->next->colname = $3;
ci->next->type = $4;
ci->next->next = NULL;
ci->next = $3;
$$ = $1;
}
| column column_type
| column_and_type
{
$$ = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
if( ! $$ )
YYABORT;
$$->colname = $1;
$$ = $1;
}
;
column_and_type:
column column_type
{
$$ = $1;
$$->type = $2;
$$->next = NULL;
}
;
@ -386,30 +378,9 @@ selectfrom:
selcollist:
column
{
string_list *list;
list = HeapAlloc( GetProcessHeap(), 0, sizeof *list );
if( !list )
YYABORT;
list->string = $1;
list->next = NULL;
$$ = list;
TRACE("Collist %s\n",debugstr_w($$->string));
}
| column TK_COMMA selcollist
{
string_list *list;
list = HeapAlloc( GetProcessHeap(), 0, sizeof *list );
if( !list )
YYABORT;
list->string = $1;
list->next = $3;
$$ = list;
TRACE("From table: %s\n",debugstr_w($$->string));
$1->next = $3;
}
| TK_STAR
{
@ -553,25 +524,16 @@ update_assign_list:
column_assignment
| column_assignment TK_COMMA update_assign_list
{
$1.col_list->next = $3.col_list;
$1.val_list->next = $3.val_list;
$$ = $1;
$$->next = $3;
}
;
column_assignment:
column TK_EQ const_val
{
$$.col_list = HeapAlloc( GetProcessHeap(), 0, sizeof *$$.col_list );
if( !$$.col_list )
YYABORT;
$$.col_list->string = $1;
$$.col_list->next = NULL;
$$.val_list = HeapAlloc( GetProcessHeap(), 0, sizeof *$$.val_list );
if( !$$.val_list )
YYABORT;
$$.val_list->val = $3;
$$.val_list->next = 0;
$$ = $1;
$$->val = $3;
}
;
@ -614,11 +576,15 @@ column_val:
column:
table TK_DOT id
{
$$ = $3; /* FIXME */
$$ = parser_alloc_column( info, $1, $3 );
if( !$$ )
YYABORT;
}
| id
{
$$ = $1;
$$ = parser_alloc_column( info, NULL, $1 );
if( !$$ )
YYABORT;
}
;
@ -650,6 +616,23 @@ static void *parser_alloc( void *info, unsigned int sz )
return &mem[1];
}
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column )
{
column_info *col;
col = parser_alloc( info, sizeof (*col) );
if( col )
{
col->table = table;
col->column = column;
col->val = NULL;
col->type = 0;
col->next = NULL;
}
return col;
}
int SQL_lex( void *SQL_lval, SQL_input *sql )
{
int token;
@ -733,13 +716,13 @@ static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct e
return e;
}
static struct expr * EXPR_column( void *info, LPWSTR column )
static struct expr * EXPR_column( void *info, column_info *column )
{
struct expr *e = parser_alloc( info, sizeof *e );
if( e )
{
e->type = EXPR_COLUMN;
e->u.sval = column;
e->u.sval = column->column;
}
return e;
}
@ -766,19 +749,20 @@ static struct expr * EXPR_sval( void *info, struct sql_str *str )
return e;
}
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols, string_list *keys)
static BOOL SQL_MarkPrimaryKeys( column_info *cols,
column_info *keys )
{
string_list *k;
column_info *k;
BOOL found = TRUE;
for( k = keys; k && found; k = k->next )
{
create_col_info *c;
column_info *c;
found = FALSE;
for( c = cols; c && !found; c = c->next )
{
if( lstrcmpW( k->string, c->colname ) )
if( lstrcmpW( k->column, c->column ) )
continue;
c->type |= MSITYPE_KEY;
found = TRUE;

View File

@ -43,7 +43,7 @@ typedef struct tagMSIUPDATEVIEW
MSIVIEW view;
MSIDATABASE *db;
MSIVIEW *wv;
value_list *vals;
column_info *vals;
} MSIUPDATEVIEW;
static UINT UPDATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
@ -193,7 +193,7 @@ static MSIVIEWOPS update_ops =
};
UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
column_assignment *list, struct expr *expr )
column_info *columns, struct expr *expr )
{
MSIUPDATEVIEW *uv = NULL;
UINT r;
@ -215,7 +215,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
}
/* then select the columns we want */
r = SELECT_CreateView( db, &sv, wv, list->col_list );
r = SELECT_CreateView( db, &sv, wv, columns );
if( r != ERROR_SUCCESS )
{
if( tv )
@ -231,7 +231,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
uv->view.ops = &update_ops;
msiobj_addref( &db->hdr );
uv->db = db;
uv->vals = list->val_list;
uv->vals = columns;
uv->wv = sv;
*view = (MSIVIEW*) uv;