From 5046c6477f509bc76aaab1767b2e4a9447619094 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 23 Dec 2015 16:01:08 +0100 Subject: [PATCH] restructured source code and build dynamic library --- .gitignore | 2 + Makefile | 57 ++++++++++++++----- bin/.gitignore | 2 - src/.gitignore | 8 --- src/Makefile | 41 ------------- src/{parser => }/SQLParser.cpp | 5 +- src/{parser => }/SQLParser.h | 3 +- src/lib/sqllib.h | 16 ------ src/parser/.gitignore | 5 ++ src/parser/Makefile | 2 +- src/parser/bison_parser.y | 2 +- src/parser/flex_lexer.l | 2 +- src/{lib/statements => sql}/CreateStatement.h | 0 src/{lib/statements => sql}/DeleteStatement.h | 0 src/{lib/statements => sql}/DropStatement.h | 0 .../statements => sql}/ExecuteStatement.h | 0 src/{lib => sql}/Expr.cpp | 0 src/{lib => sql}/Expr.h | 0 src/{lib/statements => sql}/ImportStatement.h | 0 src/{lib/statements => sql}/InsertStatement.h | 0 .../statements => sql}/PrepareStatement.h | 0 src/{lib/statements => sql}/SQLStatement.h | 0 src/{lib/statements => sql}/SelectStatement.h | 0 src/{lib => sql}/Table.h | 0 src/{lib/statements => sql}/UpdateStatement.h | 0 src/{lib/statements => sql}/destruct.cpp | 0 src/{lib => }/sqlhelper.cpp | 0 src/{lib => }/sqlhelper.h | 2 +- src/sqltypes.h | 16 ++++++ {src => test}/sql_grammar_test.cpp | 0 {src => test}/sql_tests.cpp | 0 {src => test}/tests/helper.h | 0 {src => test}/tests/select.cpp | 0 {src => test}/tests/test.cpp | 0 {src => test}/tests/test.h | 0 {src => test}/tests/valid_queries.sql | 0 36 files changed, 73 insertions(+), 90 deletions(-) delete mode 100644 bin/.gitignore delete mode 100644 src/.gitignore delete mode 100644 src/Makefile rename src/{parser => }/SQLParser.cpp (91%) rename src/{parser => }/SQLParser.h (87%) delete mode 100644 src/lib/sqllib.h rename src/{lib/statements => sql}/CreateStatement.h (100%) rename src/{lib/statements => sql}/DeleteStatement.h (100%) rename src/{lib/statements => sql}/DropStatement.h (100%) rename src/{lib/statements => sql}/ExecuteStatement.h (100%) rename src/{lib => sql}/Expr.cpp (100%) rename src/{lib => sql}/Expr.h (100%) rename src/{lib/statements => sql}/ImportStatement.h (100%) rename src/{lib/statements => sql}/InsertStatement.h (100%) rename src/{lib/statements => sql}/PrepareStatement.h (100%) rename src/{lib/statements => sql}/SQLStatement.h (100%) rename src/{lib/statements => sql}/SelectStatement.h (100%) rename src/{lib => sql}/Table.h (100%) rename src/{lib/statements => sql}/UpdateStatement.h (100%) rename src/{lib/statements => sql}/destruct.cpp (100%) rename src/{lib => }/sqlhelper.cpp (100%) rename src/{lib => }/sqlhelper.h (93%) create mode 100644 src/sqltypes.h rename {src => test}/sql_grammar_test.cpp (100%) rename {src => test}/sql_tests.cpp (100%) rename {src => test}/tests/helper.h (100%) rename {src => test}/tests/select.cpp (100%) rename {src => test}/tests/test.cpp (100%) rename {src => test}/tests/test.h (100%) rename {src => test}/tests/valid_queries.sql (100%) diff --git a/.gitignore b/.gitignore index 330b188..655dafc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ build/ utils/ +bin/ +lib-test/ # Compiled Object files *.slo diff --git a/Makefile b/Makefile index 9aedadd..3cee86a 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,51 @@ +# +# make source (build the source code into build/) +# +# make library +# +# +# +# + +# directories +BIN = bin +SRC = src +SRCSQL = src/lib/sql +SRCPARSER = src/parser + +# files +PARSERFILES = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp +LIBCPP = $(shell find $(SRC)/ -name '*.cpp' -not -path "$(SRCPARSER)/*") $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp +LIBOBJ = $(LIBCPP:%.cpp=%.o) +LIBHEADERS = $(shell find $(SRCSQL)/ -name '*.h') $(SRC)/SQLParser.h + +# compile & link flages +CC = g++ +CFLAGS = -std=c++11 -Wall -fPIC +LIBFLAGS = -shared +TARGET = libsqlparser.so - -test: FORCE - @echo "\nCompiling the SQL parser and the tests...\n" - @make clean -C src/ >/dev/null || exit 1 - @make tests -C src/ >/dev/null || exit 1 - @make grammar_test -C src/ >/dev/null || exit 1 - @echo "Running tests..." - @./bin/grammar_test -f "src/tests/valid_queries.sql" - @./bin/tests +all: library -build: FORCE - @echo "\nBuilding the SQL parser... (Run tests with 'make test')" - @echo "Build directory: build/\n" - make -C src/ +library: $(LIBOBJ) + $(CC) $(LIBFLAGS) -o $(TARGET) $(LIBOBJ) -docs: FORCE - doxygen docs/doxy.conf +%.o: %.cpp $(PARSERFILES) + $(CC) $(CFLAGS) -c -o $@ $< +$(SRCPARSER)/bison_parser.cpp: parser +$(SRCPARSER)/flex_lexer.cpp: parser + +parser: + make -C $(SRCPARSER)/ + +clean: + find $(SRC) -type f -name '*.o' -delete + +cleanparser: + make -C $(SRCPARSER)/ clean FORCE: diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index c96a04f..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 5e65d69..0000000 --- a/src/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -build/ -flex_lexer.c* -flex_lexer.h -bison_parser.c* -bison_parser.h -*.o -*.output -copy*.sh diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index d97d665..0000000 --- a/src/Makefile +++ /dev/null @@ -1,41 +0,0 @@ - - -BUILD_DIR = ../build/ -BIN_DIR = ../bin - -CC = g++ -CFLAGS = -O3 -I./ -Ilib/ -Ilib/statements/ -Iparser/ -std=c++11 -pthread -Wall -g - -LIB_HEADERS = $(shell find lib/ -name '*.h') parser/bison_parser.h parser/flex_lexer.h parser/SQLParser.h parser/parser_typedef.h -LIB_SOURCES = $(shell find lib/ -name '*.cpp') parser/bison_parser.cpp parser/flex_lexer.cpp parser/SQLParser.cpp -TEST_SOURCES = $(shell find tests/ -name '*.cpp') - - -build: clean - make -C parser/ - mkdir $(BUILD_DIR) - cp $(LIB_SOURCES) $(BUILD_DIR) - cp $(LIB_HEADERS) $(BUILD_DIR) - - -grammar_test: $(LIB_SOURCES) sql_grammar_test.cpp - $(CC) $(CFLAGS) $(LIB_SOURCES) sql_grammar_test.cpp -o $(BIN_DIR)/grammar_test - - -tests: $(LIB_SOURCES) $(TEST_SOURCES) sql_tests.cpp - $(CC) $(CFLAGS) $(LIB_SOURCES) $(TEST_SOURCES) sql_tests.cpp -o $(BIN_DIR)/tests - - -parser/bison_parser.cpp: - make -C parser/ - - -clean: - rm -f *.o *~ $(BIN_DIR)/analysis $(TESTS_BIN) $(BIN_DIR)/grammar_test $(BIN_DIR)/tests - rm -rf $(BUILD_DIR) - make clean -C parser/ - - -test: tests grammar_test - @./$(BIN_DIR)/grammar_test -f ../test/valid_queries.sql - @./$(BIN_DIR)/tests \ No newline at end of file diff --git a/src/parser/SQLParser.cpp b/src/SQLParser.cpp similarity index 91% rename from src/parser/SQLParser.cpp rename to src/SQLParser.cpp index 55ee766..e3039e1 100644 --- a/src/parser/SQLParser.cpp +++ b/src/SQLParser.cpp @@ -1,6 +1,7 @@ + #include "SQLParser.h" -#include "bison_parser.h" -#include "flex_lexer.h" +#include "parser/bison_parser.h" +#include "parser/flex_lexer.h" #include #include diff --git a/src/parser/SQLParser.h b/src/SQLParser.h similarity index 87% rename from src/parser/SQLParser.h rename to src/SQLParser.h index ae8d330..3d82b8a 100644 --- a/src/parser/SQLParser.h +++ b/src/SQLParser.h @@ -1,8 +1,7 @@ #ifndef __SQLPARSER_H_ #define __SQLPARSER_H_ -#include "sqllib.h" -#include "bison_parser.h" +#include "sqltypes.h" namespace hsql { diff --git a/src/lib/sqllib.h b/src/lib/sqllib.h deleted file mode 100644 index 632fe3f..0000000 --- a/src/lib/sqllib.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __SQLLIB_H__ -#define __SQLLIB_H__ - -typedef unsigned int uint; - -#include "SelectStatement.h" -#include "ImportStatement.h" -#include "CreateStatement.h" -#include "InsertStatement.h" -#include "UpdateStatement.h" -#include "DeleteStatement.h" -#include "DropStatement.h" -#include "PrepareStatement.h" -#include "ExecuteStatement.h" - -#endif \ No newline at end of file diff --git a/src/parser/.gitignore b/src/parser/.gitignore index e69de29..19c7633 100644 --- a/src/parser/.gitignore +++ b/src/parser/.gitignore @@ -0,0 +1,5 @@ +flex_lexer.c* +flex_lexer.h +bison_parser.c* +bison_parser.h +*.output \ No newline at end of file diff --git a/src/parser/Makefile b/src/parser/Makefile index ce92703..4bd46f1 100644 --- a/src/parser/Makefile +++ b/src/parser/Makefile @@ -8,4 +8,4 @@ flex_lexer.cpp: flex_lexer.l flex flex_lexer.l clean: - rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h \ No newline at end of file + rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h *.output \ No newline at end of file diff --git a/src/parser/bison_parser.y b/src/parser/bison_parser.y index 90bd532..54616bd 100644 --- a/src/parser/bison_parser.y +++ b/src/parser/bison_parser.y @@ -11,7 +11,7 @@ ** Section 1: C Declarations *********************************/ -#include "sqllib.h" +#include "../sqltypes.h" #include "bison_parser.h" #include "flex_lexer.h" diff --git a/src/parser/flex_lexer.l b/src/parser/flex_lexer.l index 941104e..44d955b 100644 --- a/src/parser/flex_lexer.l +++ b/src/parser/flex_lexer.l @@ -10,7 +10,7 @@ ***************************/ %{ -#include "sqllib.h" +#include "../sqltypes.h" #include "bison_parser.h" #include diff --git a/src/lib/statements/CreateStatement.h b/src/sql/CreateStatement.h similarity index 100% rename from src/lib/statements/CreateStatement.h rename to src/sql/CreateStatement.h diff --git a/src/lib/statements/DeleteStatement.h b/src/sql/DeleteStatement.h similarity index 100% rename from src/lib/statements/DeleteStatement.h rename to src/sql/DeleteStatement.h diff --git a/src/lib/statements/DropStatement.h b/src/sql/DropStatement.h similarity index 100% rename from src/lib/statements/DropStatement.h rename to src/sql/DropStatement.h diff --git a/src/lib/statements/ExecuteStatement.h b/src/sql/ExecuteStatement.h similarity index 100% rename from src/lib/statements/ExecuteStatement.h rename to src/sql/ExecuteStatement.h diff --git a/src/lib/Expr.cpp b/src/sql/Expr.cpp similarity index 100% rename from src/lib/Expr.cpp rename to src/sql/Expr.cpp diff --git a/src/lib/Expr.h b/src/sql/Expr.h similarity index 100% rename from src/lib/Expr.h rename to src/sql/Expr.h diff --git a/src/lib/statements/ImportStatement.h b/src/sql/ImportStatement.h similarity index 100% rename from src/lib/statements/ImportStatement.h rename to src/sql/ImportStatement.h diff --git a/src/lib/statements/InsertStatement.h b/src/sql/InsertStatement.h similarity index 100% rename from src/lib/statements/InsertStatement.h rename to src/sql/InsertStatement.h diff --git a/src/lib/statements/PrepareStatement.h b/src/sql/PrepareStatement.h similarity index 100% rename from src/lib/statements/PrepareStatement.h rename to src/sql/PrepareStatement.h diff --git a/src/lib/statements/SQLStatement.h b/src/sql/SQLStatement.h similarity index 100% rename from src/lib/statements/SQLStatement.h rename to src/sql/SQLStatement.h diff --git a/src/lib/statements/SelectStatement.h b/src/sql/SelectStatement.h similarity index 100% rename from src/lib/statements/SelectStatement.h rename to src/sql/SelectStatement.h diff --git a/src/lib/Table.h b/src/sql/Table.h similarity index 100% rename from src/lib/Table.h rename to src/sql/Table.h diff --git a/src/lib/statements/UpdateStatement.h b/src/sql/UpdateStatement.h similarity index 100% rename from src/lib/statements/UpdateStatement.h rename to src/sql/UpdateStatement.h diff --git a/src/lib/statements/destruct.cpp b/src/sql/destruct.cpp similarity index 100% rename from src/lib/statements/destruct.cpp rename to src/sql/destruct.cpp diff --git a/src/lib/sqlhelper.cpp b/src/sqlhelper.cpp similarity index 100% rename from src/lib/sqlhelper.cpp rename to src/sqlhelper.cpp diff --git a/src/lib/sqlhelper.h b/src/sqlhelper.h similarity index 93% rename from src/lib/sqlhelper.h rename to src/sqlhelper.h index a34f453..dfc3f98 100644 --- a/src/lib/sqlhelper.h +++ b/src/sqlhelper.h @@ -3,7 +3,7 @@ #define __SQLHELPER_H__ -#include "sqllib.h" +#include "sqltypes.h" namespace hsql { diff --git a/src/sqltypes.h b/src/sqltypes.h new file mode 100644 index 0000000..e81e6f8 --- /dev/null +++ b/src/sqltypes.h @@ -0,0 +1,16 @@ +#ifndef __SQLLIB_H__ +#define __SQLLIB_H__ + +typedef unsigned int uint; + +#include "sql/SelectStatement.h" +#include "sql/ImportStatement.h" +#include "sql/CreateStatement.h" +#include "sql/InsertStatement.h" +#include "sql/UpdateStatement.h" +#include "sql/DeleteStatement.h" +#include "sql/DropStatement.h" +#include "sql/PrepareStatement.h" +#include "sql/ExecuteStatement.h" + +#endif \ No newline at end of file diff --git a/src/sql_grammar_test.cpp b/test/sql_grammar_test.cpp similarity index 100% rename from src/sql_grammar_test.cpp rename to test/sql_grammar_test.cpp diff --git a/src/sql_tests.cpp b/test/sql_tests.cpp similarity index 100% rename from src/sql_tests.cpp rename to test/sql_tests.cpp diff --git a/src/tests/helper.h b/test/tests/helper.h similarity index 100% rename from src/tests/helper.h rename to test/tests/helper.h diff --git a/src/tests/select.cpp b/test/tests/select.cpp similarity index 100% rename from src/tests/select.cpp rename to test/tests/select.cpp diff --git a/src/tests/test.cpp b/test/tests/test.cpp similarity index 100% rename from src/tests/test.cpp rename to test/tests/test.cpp diff --git a/src/tests/test.h b/test/tests/test.h similarity index 100% rename from src/tests/test.h rename to test/tests/test.h diff --git a/src/tests/valid_queries.sql b/test/tests/valid_queries.sql similarity index 100% rename from src/tests/valid_queries.sql rename to test/tests/valid_queries.sql