You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
MCOL-05 Modify the DDL parser to not use (even more) global variables.
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include "sqlparser.h"
|
||||
#include "ddlpkg.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@ -29,8 +30,9 @@
|
||||
#include "ddl-gram.h"
|
||||
#endif
|
||||
|
||||
using namespace ddlpackage;
|
||||
int lineno = 1;
|
||||
void ddlerror(yyscan_t yyscanner, char *s);
|
||||
void ddlerror(struct pass_to_bison* x, char const *s);
|
||||
|
||||
static char* scanner_copy(char *str, yyscan_t yyscanner);
|
||||
|
||||
@ -173,15 +175,14 @@ VARBINARY {return VARBINARY;}
|
||||
|
||||
%%
|
||||
|
||||
void ddlerror(yyscan_t yyscanner, char const *s)
|
||||
void ddlerror(struct pass_to_bison* x, char const *s)
|
||||
{
|
||||
printf("yyerror: %d: %s at %s\n", lineno, s, ddlget_text(yyscanner));
|
||||
printf("yyerror: %d: %s at %s\n", lineno, s, ddlget_text(x->scanner));
|
||||
}
|
||||
|
||||
typedef std::vector<char*> valbuf_t;
|
||||
|
||||
#include <pthread.h>
|
||||
#include "sqlparser.h"
|
||||
using namespace ddlpackage;
|
||||
|
||||
/*
|
||||
|
@ -56,21 +56,20 @@
|
||||
#include "ddl-gram.h"
|
||||
#endif
|
||||
|
||||
#define scanner x->scanner
|
||||
|
||||
using namespace std;
|
||||
using namespace ddlpackage;
|
||||
|
||||
/* The user is expect to pass a ParseTree* to grammar_init */
|
||||
static ParseTree* parseTree;
|
||||
static std::string db_schema;
|
||||
int ddllex(YYSTYPE* ddllval, void* yyscanner);
|
||||
void ddlerror (void* yyscanner, char const *error);
|
||||
void ddlerror(struct pass_to_bison* x, char const *s);
|
||||
char* copy_string(const char *str);
|
||||
%}
|
||||
|
||||
%expect 15
|
||||
%pure-parser
|
||||
%lex-param {void * scanner}
|
||||
%parse-param {void * scanner}
|
||||
%parse-param {struct pass_to_bison * x}
|
||||
%debug
|
||||
|
||||
/* Bison uses this to generate a C union definition. This is used to
|
||||
@ -203,7 +202,7 @@ VARYING WITH ZONE DOUBLE IDB_FLOAT REAL CHARSET IDB_IF EXISTS CHANGE TRUNCATE
|
||||
%type <sqlStmt> trunc_table_statement
|
||||
|
||||
%%
|
||||
stmtblock: stmtmulti { parseTree = $1; }
|
||||
stmtblock: stmtmulti { x->fParseTree = $1; }
|
||||
;
|
||||
|
||||
|
||||
@ -220,11 +219,9 @@ stmtmulti:
|
||||
}
|
||||
| stmt
|
||||
{
|
||||
/* The user is supposed to supply a ParseTree* via grammar_init.
|
||||
So, it is already there. */
|
||||
if ($1 != NULL)
|
||||
{
|
||||
$$ = parseTree;
|
||||
$$ = x->fParseTree;
|
||||
$$->push_back($1);
|
||||
}
|
||||
else
|
||||
@ -601,8 +598,8 @@ table_name:
|
||||
qualified_name:
|
||||
IDENT '.' IDENT {$$ = new QualifiedName($1, $3);}
|
||||
| IDENT {
|
||||
if (db_schema.size())
|
||||
$$ = new QualifiedName((char*)db_schema.c_str(), $1);
|
||||
if (x->fDBSchema.size())
|
||||
$$ = new QualifiedName((char*)x->fDBSchema.c_str(), $1);
|
||||
else
|
||||
$$ = new QualifiedName($1);
|
||||
}
|
||||
@ -1065,15 +1062,4 @@ opt_column:
|
||||
|
||||
%%
|
||||
|
||||
void grammar_init(ParseTree *_parseTree, bool debug)
|
||||
{
|
||||
parseTree = _parseTree;
|
||||
|
||||
if(debug)
|
||||
yydebug = 1;
|
||||
}
|
||||
|
||||
void set_schema(std::string schema)
|
||||
{
|
||||
db_schema = schema;
|
||||
}
|
||||
|
@ -37,17 +37,17 @@
|
||||
|
||||
void scanner_finish(void* yyscanner);
|
||||
void scanner_init(const char *str, void* yyscanner);
|
||||
void grammar_init(ddlpackage::ParseTree *ptree, bool);
|
||||
int ddllex_init_extra(void* user_defined,void** yyscanner);
|
||||
int ddllex_destroy(void* yyscanner);
|
||||
int ddlparse(void* yyscanner);
|
||||
int ddlparse(ddlpackage::pass_to_bison* x);
|
||||
void set_schema(std::string schema);
|
||||
namespace ddlpackage {
|
||||
using namespace std;
|
||||
|
||||
SqlParser::SqlParser() :
|
||||
fStatus(-1),
|
||||
fDebug(false)
|
||||
fDebug(false),
|
||||
x(&fParseTree)
|
||||
{
|
||||
}
|
||||
|
||||
@ -59,15 +59,14 @@ namespace ddlpackage {
|
||||
|
||||
void SqlParser::setDefaultSchema(std::string schema)
|
||||
{
|
||||
set_schema(schema);
|
||||
x.fDBSchema=schema;
|
||||
}
|
||||
|
||||
int SqlParser::Parse(const char* sqltext)
|
||||
{
|
||||
ddllex_init_extra(&scanData, &scanner);
|
||||
scanner_init(sqltext, scanner);
|
||||
grammar_init(&fParseTree, fDebug);
|
||||
fStatus = ddlparse(scanner);
|
||||
ddllex_init_extra(&scanData, &x.scanner);
|
||||
scanner_init(sqltext, x.scanner);
|
||||
fStatus = ddlparse(&x);
|
||||
return fStatus;
|
||||
}
|
||||
|
||||
@ -89,8 +88,8 @@ namespace ddlpackage {
|
||||
|
||||
SqlParser::~SqlParser()
|
||||
{
|
||||
scanner_finish(scanner); // free scanner allocated memory
|
||||
ddllex_destroy(scanner);
|
||||
scanner_finish(x.scanner); // free scanner allocated memory
|
||||
ddllex_destroy(x.scanner);
|
||||
}
|
||||
|
||||
|
||||
@ -104,7 +103,6 @@ namespace ddlpackage {
|
||||
{
|
||||
fStatus = -1;
|
||||
|
||||
int ddlparse();
|
||||
ifstream ifsql;
|
||||
ifsql.open(sqlfile.c_str());
|
||||
if(!ifsql.is_open()) {
|
||||
|
@ -81,6 +81,14 @@ struct scan_data
|
||||
valbuf_t valbuf;
|
||||
};
|
||||
|
||||
struct pass_to_bison {
|
||||
ParseTree* fParseTree;
|
||||
std::string fDBSchema;
|
||||
void* scanner;
|
||||
|
||||
pass_to_bison(ParseTree* pt) : fParseTree(pt), scanner(NULL) {};
|
||||
};
|
||||
|
||||
class SqlParser
|
||||
{
|
||||
public:
|
||||
@ -113,10 +121,11 @@ public:
|
||||
|
||||
protected:
|
||||
ParseTree fParseTree;
|
||||
std::string fDBSchema;
|
||||
int fStatus; ///< return from yyparse() stored here.
|
||||
bool fDebug; ///< Turn on bison debugging.
|
||||
void* scanner; // yyscan_t * needed for re-entrant flex scanner
|
||||
scan_data scanData;
|
||||
pass_to_bison x;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user