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 <stdio.h>
int yyparse(Statement **expression, yyscan_t scanner);
// int yyparse(Statement **expression, yyscan_t scanner);
namespace hsql {
SQLParser::SQLParser() {
fprintf(stderr, "SQLParser only has static methods atm! Do not initialize!\n");
}
@ -35,3 +37,5 @@ Statement* SQLParser::parseSQLString(const char *text) {
hsql_lex_destroy(scanner);
return stmt;
}
} // namespace hsql

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,6 +3,8 @@
#include <stdio.h>
#include <string>
namespace hsql {
void printExpression(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);
}
} // namespace hsql

View File

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

View File

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