From 6876de5ca843e08b9826ba3a3f7afd7b37d30c15 Mon Sep 17 00:00:00 2001 From: Pedro Date: Mon, 20 Oct 2014 22:33:36 +0200 Subject: [PATCH] naming changes --- src/bison/bison_parser.y | 28 +++++++-------- src/lemon/lemon_parser.y | 2 +- src/lib/Statement.cpp | 4 +-- src/lib/Statement.h | 22 ++++++------ src/sql_execution.cpp | 16 ++++----- src/sql_parser_cli.cpp | 2 +- src/sql_tests.cpp | 73 +++++++++++++++++++++------------------- 7 files changed, 75 insertions(+), 72 deletions(-) diff --git a/src/bison/bison_parser.y b/src/bison/bison_parser.y index bd4b574..e6b73cb 100644 --- a/src/bison/bison_parser.y +++ b/src/bison/bison_parser.y @@ -20,8 +20,8 @@ int yyerror(Statement **expression, yyscan_t scanner, const char *msg) { %code requires { -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T +#ifndef YYtypeDEF_YY_SCANNER_T +#define YYtypeDEF_YY_SCANNER_T typedef void* yyscan_t; #endif @@ -66,7 +66,7 @@ typedef void* yyscan_t; %% -input: +input: statement opt_semicolon { *statement = $1; } ; @@ -83,12 +83,12 @@ statement: select_statement: SELECT expr_list from_clause where_clause group_clause - { + { SelectStatement* s = new SelectStatement(); - s->_select_list = $2; - s->_from_table = $3; - s->_where_clause = $4; - s->_group_by = $5; + s->select_list = $2; + s->from_table = $3; + s->where_clause = $4; + s->group_by = $5; $$ = s; } ; @@ -112,14 +112,14 @@ group_clause: table_exp: - table_ref_commalist { + table_ref_commalist { TableRef* t = new TableRef(eTableName); - t->_table_names = $1; + t->table_names = $1; $$ = t; } | '(' select_statement ')' { TableRef* t = new TableRef(eTableSelect); - t->_stmt = $2; + t->stmt = $2; $$ = t; } ; @@ -146,7 +146,7 @@ expr: /* Lists */ -expr_list: +expr_list: expr { $$ = new List($1); } | expr_list ',' expr { $1->push_back($3); $$ = $1; } ; @@ -180,7 +180,7 @@ scalar_exp: ; opt_semicolon: - ';' + ';' | /* empty */ ; -%% \ No newline at end of file +%% diff --git a/src/lemon/lemon_parser.y b/src/lemon/lemon_parser.y index 50c7749..dc08a3d 100644 --- a/src/lemon/lemon_parser.y +++ b/src/lemon/lemon_parser.y @@ -6,7 +6,7 @@ %syntax_error { printf("Lemon syntax error\n"); } %extra_argument { Statement** result } -%token_type {const char*} +%tokentype {const char*} %type expr {Statement*} %left PLUS MINUS . diff --git a/src/lib/Statement.cpp b/src/lib/Statement.cpp index dfc2e6d..8578522 100644 --- a/src/lib/Statement.cpp +++ b/src/lib/Statement.cpp @@ -8,8 +8,8 @@ #include -Statement::Statement(EStatementType type) : _type(type) {}; +Statement::Statement(EStatementType type) : type(type) {}; SelectStatement::SelectStatement() : Statement(eSelect) {}; -TableRef::TableRef(ETableRefType type) : _type(type) {}; +TableRef::TableRef(ETableRefType type) : type(type) {}; diff --git a/src/lib/Statement.h b/src/lib/Statement.h index 3707de5..c0a0b84 100644 --- a/src/lib/Statement.h +++ b/src/lib/Statement.h @@ -4,7 +4,7 @@ */ #ifndef __STATEMENT_H__ #define __STATEMENT_H__ - + #include "Expr.h" #include "List.h" @@ -23,7 +23,7 @@ class Statement { public: Statement(EStatementType type); - EStatementType _type; + EStatementType type; }; @@ -31,10 +31,10 @@ class SelectStatement : public Statement { public: SelectStatement(); - TableRef* _from_table; - List* _select_list; - List* _group_by; - Expr* _where_clause; + TableRef* from_table; + List* select_list; + List* group_by; + Expr* where_clause; }; @@ -51,11 +51,11 @@ class TableRef { public: TableRef(ETableRefType type); - ETableRefType _type; + ETableRefType type; - SelectStatement* _stmt; - List* _table_names; + SelectStatement* stmt; + List* table_names; }; - -#endif // __STATEMENT_H__ \ No newline at end of file + +#endif // __STATEMENT_H__ diff --git a/src/sql_execution.cpp b/src/sql_execution.cpp index ebece10..0841303 100644 --- a/src/sql_execution.cpp +++ b/src/sql_execution.cpp @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) { continue; } - if (stmt->_type == eSelect) { + if (stmt->type == eSelect) { executeSelect((SelectStatement*)stmt); } else { fprintf(stderr, "Only Supporting Select Statements!\n"); @@ -64,16 +64,16 @@ Table executeSelect(SelectStatement* stmt) { // Step 1: // Determine source table - TableRef* from_table = stmt->_from_table; + TableRef* from_table = stmt->from_table; Table source; - if (from_table->_type == eTableSelect) { + if (from_table->type == eTableSelect) { // Nested Select Statements - source = executeSelect(from_table->_stmt); + source = executeSelect(from_table->stmt); - } else if (from_table->_type == eTableName) { - if (from_table->_table_names->size() == 1) { - if (std::string(from_table->_table_names->at(0)).compare("table") == 0) { + } else if (from_table->type == eTableName) { + if (from_table->table_names->size() == 1) { + if (std::string(from_table->table_names->at(0)).compare("table") == 0) { source = TABLE; } else { fprintf(stderr, "Couldn't find table!\n"); @@ -88,7 +88,7 @@ Table executeSelect(SelectStatement* stmt) { // Step 2 // Check if group by - if (stmt->_group_by != NULL) { + if (stmt->group_by != NULL) { return executeGroupBySelect(stmt, source); } diff --git a/src/sql_parser_cli.cpp b/src/sql_parser_cli.cpp index e84cc40..2f72af2 100644 --- a/src/sql_parser_cli.cpp +++ b/src/sql_parser_cli.cpp @@ -39,7 +39,7 @@ void evaluate_statement(Statement* stmt) { printf("Statement at %p\n", stmt); if (stmt == NULL) return; - switch (stmt->_type) { + switch (stmt->type) { case eSelect: evaluate_select_statement((SelectStatement*) stmt); break; diff --git a/src/sql_tests.cpp b/src/sql_tests.cpp index 7180fa8..247d285 100644 --- a/src/sql_tests.cpp +++ b/src/sql_tests.cpp @@ -21,26 +21,26 @@ void SelectTest1() { const char* sql = "SELECT age, name, address from table WHERE age > 12.5;"; Statement* sqlStatement = SQLParser::parseSQL(sql); ASSERT(sqlStatement != NULL); - ASSERT(sqlStatement->_type == eSelect); + ASSERT(sqlStatement->type == eSelect); SelectStatement* stmt = (SelectStatement*) sqlStatement; - ASSERT(stmt->_select_list->size() == 3); - ASSERT_STR(stmt->_select_list->at(0)->name, "age"); - ASSERT_STR(stmt->_select_list->at(1)->name, "name"); - ASSERT_STR(stmt->_select_list->at(2)->name, "address"); + ASSERT(stmt->select_list->size() == 3); + ASSERT_STR(stmt->select_list->at(0)->name, "age"); + ASSERT_STR(stmt->select_list->at(1)->name, "name"); + ASSERT_STR(stmt->select_list->at(2)->name, "address"); - ASSERT(stmt->_from_table != NULL); - ASSERT(stmt->_from_table->_type == eTableName); - ASSERT_STR(stmt->_from_table->_table_names->at(0), "table"); + ASSERT(stmt->from_table != NULL); + ASSERT(stmt->from_table->type == eTableName); + ASSERT_STR(stmt->from_table->table_names->at(0), "table"); // WHERE - ASSERT(stmt->_where_clause != NULL); - ASSERT(stmt->_where_clause->expr->type == eExprColumnRef); - ASSERT_STR(stmt->_where_clause->expr->name, "age"); - ASSERT_STR(stmt->_where_clause->name, ">"); - ASSERT(stmt->_where_clause->expr2->type == eExprLiteralFloat); - ASSERT(stmt->_where_clause->expr2->float_literal == 12.5); + ASSERT(stmt->where_clause != NULL); + ASSERT(stmt->where_clause->expr->type == eExprColumnRef); + ASSERT_STR(stmt->where_clause->expr->name, "age"); + ASSERT_STR(stmt->where_clause->name, ">"); + ASSERT(stmt->where_clause->expr2->type == eExprLiteralFloat); + ASSERT(stmt->where_clause->expr2->float_literal == 12.5); printf("passed!\n"); } @@ -52,26 +52,27 @@ void SelectTest2() { const char* sql = "SELECT age, name, address FROM (SELECT age FROM table, table2);"; Statement* stmt = SQLParser::parseSQL(sql); ASSERT(stmt != NULL); - ASSERT(stmt->_type == eSelect); + ASSERT(stmt->type == eSelect); SelectStatement* select = (SelectStatement*) stmt; - ASSERT(select->_select_list->size() == 3); - ASSERT_STR(select->_select_list->at(0)->name, "age"); - ASSERT_STR(select->_select_list->at(1)->name, "name"); - ASSERT_STR(select->_select_list->at(2)->name, "address"); + ASSERT(select->select_list->size() == 3); + ASSERT_STR(select->select_list->at(0)->name, "age"); + ASSERT_STR(select->select_list->at(1)->name, "name"); + ASSERT_STR(select->select_list->at(2)->name, "address"); - ASSERT(select->_from_table != NULL); - ASSERT(select->_from_table->_type == eTableSelect); - ASSERT(select->_from_table->_stmt != NULL); - ASSERT(select->_from_table->_stmt->_select_list->size() == 1); - ASSERT_STR(select->_from_table->_stmt->_from_table->_table_names->at(0), "table"); - ASSERT_STR(select->_from_table->_stmt->_from_table->_table_names->at(1), "table2"); + ASSERT(select->from_table != NULL); + ASSERT(select->from_table->type == eTableSelect); + ASSERT(select->from_table->stmt != NULL); + ASSERT(select->from_table->stmt->select_list->size() == 1); + ASSERT_STR(select->from_table->stmt->from_table->table_names->at(0), "table"); + ASSERT_STR(select->from_table->stmt->from_table->table_names->at(1), "table2"); printf("passed!\n"); } -int parse_count = 0; +uint parse_count = 0; +uint conflicts = 0; void SelectTest3(bool print) { if (print) printf("Test: SelectTest3... "); fflush(stdout); @@ -81,24 +82,24 @@ void SelectTest3(bool print) { Statement* stmt = SQLParser::parseSQL(sql); - if (parse_count != 1) printf("+"); + if (parse_count != 1) conflicts++; parse_count--; ASSERT(stmt != NULL); - ASSERT(stmt->_type == eSelect); + ASSERT(stmt->type == eSelect); SelectStatement* select = (SelectStatement*) stmt; - ASSERT(select->_select_list->size() == 2); + ASSERT(select->select_list->size() == 2); - ASSERT(select->_select_list->at(0)->type == eExprColumnRef); - ASSERT(select->_select_list->at(1)->type == eExprFunctionRef); - ASSERT_STR("name", select->_select_list->at(0)->name); + ASSERT(select->select_list->at(0)->type == eExprColumnRef); + ASSERT(select->select_list->at(1)->type == eExprFunctionRef); + ASSERT_STR("name", select->select_list->at(0)->name); - ASSERT(select->_group_by != NULL); - ASSERT(select->_group_by->size() == 1); - ASSERT_STR("name", select->_group_by->at(0)->name); + ASSERT(select->group_by != NULL); + ASSERT(select->group_by->size() == 1); + ASSERT_STR("name", select->group_by->at(0)->name); if (print) printf("passed!\n"); } @@ -112,6 +113,7 @@ void multithreadTest(int numberOfRuns, int id) { } void ThreadSafeTest(uint numThreads, uint runsPerThread) { printf("Starting multithread-test... "); + conflicts = 0; std::thread* threads = new std::thread[numThreads]; for (int n = 0; n < numThreads; ++n) { threads[n] = std::thread(multithreadTest, runsPerThread, n); @@ -119,6 +121,7 @@ void ThreadSafeTest(uint numThreads, uint runsPerThread) { for (int n = 0; n < numThreads; ++n) { threads[n].join(); } + printf("there were %u concurrent parses... ", conflicts); printf("finished!\n"); }