namespaced the library in namespace hsql

This commit is contained in:
Pedro 2014-10-31 18:36:02 +01:00
parent 3c69e33d5a
commit c1c5fba762
11 changed files with 52 additions and 14 deletions

View File

@ -3,9 +3,11 @@
#include "flex_lexer.h" #include "flex_lexer.h"
#include <stdio.h> #include <stdio.h>
int yyparse(Statement **expression, yyscan_t scanner); // int yyparse(Statement **expression, yyscan_t scanner);
namespace hsql {
SQLParser::SQLParser() { SQLParser::SQLParser() {
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n"); fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
} }
@ -34,4 +36,6 @@ Statement* SQLParser::parseSQLString(const char *text) {
hsql_lex_destroy(scanner); hsql_lex_destroy(scanner);
return stmt; return stmt;
} }
} // namespace hsql

View File

@ -4,6 +4,8 @@
#include "Statement.h" #include "Statement.h"
#include "bison_parser.h" #include "bison_parser.h"
namespace hsql {
class SQLParser { class SQLParser {
public: public:
static Statement* parseSQLString(const char* sql); static Statement* parseSQLString(const char* sql);
@ -12,6 +14,8 @@ private:
SQLParser(); SQLParser();
}; };
} // namespace hsql
#endif #endif

View File

@ -17,6 +17,8 @@
#include <stdio.h> #include <stdio.h>
using namespace hsql;
int yyerror(Statement **expression, yyscan_t scanner, const char *msg) { int yyerror(Statement **expression, yyscan_t scanner, const char *msg) {
fprintf(stderr, "[Error] SQL Parser: %s\n", msg); fprintf(stderr, "[Error] SQL Parser: %s\n", msg);
return 0; return 0;
@ -56,7 +58,7 @@ typedef void* yyscan_t;
%lex-param { yyscan_t scanner } %lex-param { yyscan_t scanner }
// Define additional parameters for yyparse // Define additional parameters for yyparse
%parse-param { Statement **statement } %parse-param { hsql::Statement **statement }
%parse-param { yyscan_t scanner } %parse-param { yyscan_t scanner }
@ -69,17 +71,17 @@ typedef void* yyscan_t;
char* sval; char* sval;
uint uval; uint uval;
Statement* statement; hsql::Statement* statement;
SelectStatement* select_statement; hsql::SelectStatement* select_statement;
TableRef* table; hsql::TableRef* table;
Expr* expr; hsql::Expr* expr;
OrderDescription* order; hsql::OrderDescription* order;
OrderType order_type; hsql::OrderType order_type;
LimitDescription* limit; hsql::LimitDescription* limit;
List<char*>* slist; hsql::List<char*>* slist;
List<Expr*>* explist; hsql::List<hsql::Expr*>* explist;
List<TableRef*>* tbllist; hsql::List<hsql::TableRef*>* tbllist;
} }

View File

@ -3,6 +3,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
namespace hsql {
char* substr(const char* source, int from, int to) { char* substr(const char* source, int from, int to) {
int len = to-from; int len = to-from;
char* copy = new char[len+1]; char* copy = new char[len+1];
@ -75,4 +77,6 @@ Expr* Expr::makeFunctionRef(char* func_name, Expr* expr) {
e->name = func_name; e->name = func_name;
e->expr = expr; e->expr = expr;
return e; return e;
} }
} // namespace hsql

View File

@ -3,6 +3,8 @@
#include <stdlib.h> #include <stdlib.h>
namespace hsql {
typedef enum { typedef enum {
kExprLiteralFloat, kExprLiteralFloat,
kExprLiteralString, kExprLiteralString,
@ -75,4 +77,6 @@ struct Expr {
*var = zero; \ *var = zero; \
} while(0) } while(0)
} // namespace hsql
#endif #endif

View File

@ -4,6 +4,8 @@
#include <vector> #include <vector>
#include <stdlib.h> #include <stdlib.h>
namespace hsql {
// TODO: try to replace the List wrapper by directly using std::vector // TODO: try to replace the List wrapper by directly using std::vector
template <typename _T> template <typename _T>
@ -25,4 +27,6 @@ public:
}; };
} // namespace hsql
#endif #endif

View File

@ -9,6 +9,7 @@
#include "List.h" #include "List.h"
#include "Table.h" #include "Table.h"
namespace hsql {
typedef enum { typedef enum {
kStmtSelect, kStmtSelect,
@ -93,5 +94,6 @@ struct CreateStatement : Statement {
// TODO // TODO
}; };
} // namespace hsql
#endif // __STATEMENT_H__ #endif // __STATEMENT_H__

View File

@ -1,6 +1,9 @@
#ifndef __TABLEREF_H__ #ifndef __TABLEREF_H__
#define __TABLEREF_H__ #define __TABLEREF_H__
namespace hsql {
class SelectStatement; class SelectStatement;
class JoinStatement; class JoinStatement;
@ -29,5 +32,6 @@ struct TableRef {
}; };
} // namespace hsql
#endif #endif

View File

@ -3,6 +3,8 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
namespace hsql {
void printExpression(Expr* expr, uint num_indent); void printExpression(Expr* expr, uint num_indent);
void printOperatorExpression(Expr* expr, uint num_indent); void printOperatorExpression(Expr* expr, uint num_indent);
@ -68,3 +70,6 @@ void printSelectStatementInfo(SelectStatement* stmt, uint num_indent) {
} else inprint("null", num_indent+2); } else inprint("null", num_indent+2);
} }
} // namespace hsql

View File

@ -5,7 +5,10 @@
#include "Statement.h" #include "Statement.h"
namespace hsql {
void printSelectStatementInfo(SelectStatement* stmt, uint num_indent); void printSelectStatementInfo(SelectStatement* stmt, uint num_indent);
} // namespace hsql
#endif #endif

View File

@ -4,6 +4,8 @@
#include "lib/sqlhelper.h" #include "lib/sqlhelper.h"
#include "SQLParser.h" #include "SQLParser.h"
using namespace hsql;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc <= 1) { if (argc <= 1) {
fprintf(stderr, "No SQL-Statement given!\n"); fprintf(stderr, "No SQL-Statement given!\n");