diff --git a/src/bison/SQLParser.cpp b/src/bison/SQLParser.cpp index 17c738d..058299c 100644 --- a/src/bison/SQLParser.cpp +++ b/src/bison/SQLParser.cpp @@ -3,9 +3,11 @@ #include "flex_lexer.h" #include -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"); } @@ -34,4 +36,6 @@ Statement* SQLParser::parseSQLString(const char *text) { hsql_lex_destroy(scanner); return stmt; -} \ No newline at end of file +} + +} // namespace hsql \ No newline at end of file diff --git a/src/bison/SQLParser.h b/src/bison/SQLParser.h index 9465ea9..e320efa 100644 --- a/src/bison/SQLParser.h +++ b/src/bison/SQLParser.h @@ -4,6 +4,8 @@ #include "Statement.h" #include "bison_parser.h" +namespace hsql { + class SQLParser { public: static Statement* parseSQLString(const char* sql); @@ -12,6 +14,8 @@ private: SQLParser(); }; + +} // namespace hsql #endif \ No newline at end of file diff --git a/src/bison/bison_parser.y b/src/bison/bison_parser.y index 01559c0..33b47f5 100644 --- a/src/bison/bison_parser.y +++ b/src/bison/bison_parser.y @@ -17,6 +17,8 @@ #include +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* slist; - List* explist; - List* tbllist; + hsql::List* slist; + hsql::List* explist; + hsql::List* tbllist; } diff --git a/src/lib/Expr.cpp b/src/lib/Expr.cpp index 0f20b57..23f527a 100644 --- a/src/lib/Expr.cpp +++ b/src/lib/Expr.cpp @@ -3,6 +3,8 @@ #include #include +namespace hsql { + char* substr(const char* source, int from, int to) { int len = to-from; char* copy = new char[len+1]; @@ -75,4 +77,6 @@ Expr* Expr::makeFunctionRef(char* func_name, Expr* expr) { e->name = func_name; e->expr = expr; return e; -} \ No newline at end of file +} + +} // namespace hsql \ No newline at end of file diff --git a/src/lib/Expr.h b/src/lib/Expr.h index 4d4b071..f010d6d 100644 --- a/src/lib/Expr.h +++ b/src/lib/Expr.h @@ -3,6 +3,8 @@ #include +namespace hsql { + typedef enum { kExprLiteralFloat, kExprLiteralString, @@ -75,4 +77,6 @@ struct Expr { *var = zero; \ } while(0) +} // namespace hsql + #endif diff --git a/src/lib/List.h b/src/lib/List.h index 9935dcd..c031678 100644 --- a/src/lib/List.h +++ b/src/lib/List.h @@ -4,6 +4,8 @@ #include #include +namespace hsql { + // TODO: try to replace the List wrapper by directly using std::vector template @@ -25,4 +27,6 @@ public: }; +} // namespace hsql + #endif diff --git a/src/lib/Statement.h b/src/lib/Statement.h index fa350cb..fa503bc 100644 --- a/src/lib/Statement.h +++ b/src/lib/Statement.h @@ -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__ diff --git a/src/lib/Table.h b/src/lib/Table.h index fe61058..fa25956 100644 --- a/src/lib/Table.h +++ b/src/lib/Table.h @@ -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 diff --git a/src/lib/sqlhelper.cpp b/src/lib/sqlhelper.cpp index 4f6d572..2887934 100644 --- a/src/lib/sqlhelper.cpp +++ b/src/lib/sqlhelper.cpp @@ -3,6 +3,8 @@ #include #include +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 \ No newline at end of file diff --git a/src/lib/sqlhelper.h b/src/lib/sqlhelper.h index 35919bb..5613754 100644 --- a/src/lib/sqlhelper.h +++ b/src/lib/sqlhelper.h @@ -5,7 +5,10 @@ #include "Statement.h" +namespace hsql { + void printSelectStatementInfo(SelectStatement* stmt, uint num_indent); +} // namespace hsql #endif \ No newline at end of file diff --git a/src/sql_execution.cpp b/src/sql_execution.cpp index 5f411d9..295ce7e 100644 --- a/src/sql_execution.cpp +++ b/src/sql_execution.cpp @@ -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");