added doxygen documentation

This commit is contained in:
Pedro 2014-12-15 18:32:46 +01:00
parent 21503300ca
commit 85b9ed2cf2
20 changed files with 184 additions and 156 deletions

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
test:
@echo "Compiling..."
@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 "test/valid_queries.sql"
@./bin/tests
docs: FORCE
doxygen docs/doxy.conf
FORCE:

1
docs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__doxygen__/

21
docs/documentation.md Normal file
View File

@ -0,0 +1,21 @@
# Developer Documentation
This page contains information about how to extend this parser with new functionalities.
## Extending the Grammar
TODO
## Implementing Statement Class
TODO
## Implementing Tests
TODO

14
docs/doxy.conf Normal file
View File

@ -0,0 +1,14 @@
@PROJECT_NAME = "SQL Parser for Hyrise (C++)"
@OUTPUT_DIRECTORY = docs/__doxygen__/
@GENERATE_LATEX = NO
@GENERATE_HTML = YES
@INPUT = README.md \
docs/ \
src/parser/SQLParser.h \
src/parser/SQLParser.cpp \
src/lib/ \
@RECURSIVE = YES

View File

@ -1,9 +0,0 @@
#!/bin/sh
echo "Compiling..."
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 "test/valid_queries.sql"
./bin/tests

View File

@ -24,6 +24,10 @@ typedef enum {
typedef struct Expr Expr;
/**
* @class Expr
* @brief Represents SQL expressions (i.e. literals, operators, column_refs)
*/
struct Expr {
/**
* Operator types. These are important for expressions of type kExprOperator

View File

@ -8,6 +8,10 @@ namespace hsql {
// TODO: try to replace the List wrapper by directly using std::vector
/**
* @class List
* @brief Classed interface to std::vector (may be replaced with std::vector)
*/
template <typename _T>
class List {
public:

View File

@ -9,9 +9,10 @@ struct SelectStatement;
struct JoinDefinition;
struct TableRef;
/**
* TableRef
* Holds reference to tables. Can be either table names or a select statement.
* @enum TableRefType
* Types table references
*/
typedef enum {
kTableName,
@ -21,8 +22,10 @@ typedef enum {
} TableRefType;
/**
* @struct TableRef
* @brief Holds reference to tables. Can be either table names or a select statement.
*/
struct TableRef {
TableRef(TableRefType type) :
type(type),
@ -33,7 +36,12 @@ struct TableRef {
list(NULL),
join(NULL) {}
virtual ~TableRef(); // defined in destructors.cpp
virtual ~TableRef() {
delete name;
delete alias;
delete select;
delete list;
}
TableRefType type;
@ -59,9 +67,9 @@ struct TableRef {
/**
* Following are definitions needed to specify join tables
* @enum JoinType
* Types of joins
*/
typedef enum {
kJoinInner,
kJoinOuter,
@ -69,8 +77,10 @@ typedef enum {
kJoinRight,
} JoinType;
/**
* Definition of a join table
* @struct JoinDefinition
* @brief Definition of a join table
*/
struct JoinDefinition {
JoinDefinition() :
@ -79,7 +89,11 @@ struct JoinDefinition {
condition(NULL),
type(kJoinInner) {}
virtual ~JoinDefinition(); // defined in destructors.cpp
virtual ~JoinDefinition() {
delete left;
delete right;
delete condition;
}
TableRef* left;
TableRef* right;

View File

@ -1,106 +0,0 @@
#include "sqllib.h"
namespace hsql {
/**
* SQLStatement.h
*/
SQLStatement::~SQLStatement() { /* empty */ }
SQLStatementList::~SQLStatementList() {
delete parser_msg;
}
/**
* ImportStatement.h
*/
ImportStatement::~ImportStatement() {
delete file_path;
delete table_name;
}
/**
* InsertStatement.h
*/
InsertStatement::~InsertStatement() {
delete table_name;
delete columns;
delete values;
delete select;
}
/**
* DeleteStatement.h
*/
DeleteStatement::~DeleteStatement() {
delete table_name;
delete expr;
}
/**
* UpdateStatement.h
*/
UpdateStatement::~UpdateStatement() {
delete table;
delete updates;
delete where;
}
/**
* SelectStatement.h
*/
SelectStatement::~SelectStatement() {
delete from_table;
delete select_list;
delete where_clause;
delete group_by;
delete order;
delete limit;
}
OrderDescription::~OrderDescription() {
delete expr;
}
/**
* CreateStatement.h
*/
CreateStatement::~CreateStatement() {
delete columns;
delete file_path;
delete table_name;
}
ColumnDefinition::~ColumnDefinition() {
delete name;
}
PrepareStatement::~PrepareStatement() {
delete stmt;
delete name;
}
ExecuteStatement::~ExecuteStatement() {
delete name;
delete parameters;
}
/**
* Table.h
*/
TableRef::~TableRef() {
delete name;
delete alias;
delete select;
delete list;
}
JoinDefinition::~JoinDefinition() {
delete left;
delete right;
delete condition;
}
} // namespace hsql

View File

@ -5,9 +5,9 @@
namespace hsql {
/**
* @struct ColumnDefinition
* @brief Represents definition of a table column
*/
struct ColumnDefinition {
enum DataType {
@ -20,16 +20,18 @@ struct ColumnDefinition {
name(name),
type(type) {}
virtual ~ColumnDefinition(); // defined in destructors.cpp
virtual ~ColumnDefinition() {
delete name;
}
char* name;
DataType type;
};
/**
* @struct CreateStatement
* CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)
* CREATE TABLE students FROM TBL FILE 'test/students.tbl'
* @brief Represents "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)"
*/
struct CreateStatement : SQLStatement {
enum CreateType {
@ -45,7 +47,11 @@ struct CreateStatement : SQLStatement {
file_path(NULL),
table_name(NULL) {};
virtual ~CreateStatement(); // defined in destructors.cpp
virtual ~CreateStatement() {
delete columns;
delete file_path;
delete table_name;
}
CreateType type;
bool if_not_exists;

View File

@ -8,8 +8,7 @@ namespace hsql {
/**
* @struct DeleteStatement
* DELETE FROM students WHERE grade > 3.0
* DELETE FROM students <=> TRUNCATE students
* @brief Represents "DELETE FROM students WHERE grade > 3.0"
*
* If expr == NULL => delete all rows (truncate)
*/
@ -19,7 +18,11 @@ struct DeleteStatement : SQLStatement {
table_name(NULL),
expr(NULL) {};
virtual ~DeleteStatement(); // defined in destructors.cpp
virtual ~DeleteStatement() {
delete table_name;
delete expr;
}
char* table_name;
Expr* expr;

View File

@ -5,6 +5,11 @@
namespace hsql {
/**
* @struct DropStatement
* @brief Represents "DROP TABLE"
*/
struct DropStatement : SQLStatement {
enum EntityType {
kTable,
@ -19,14 +24,13 @@ struct DropStatement : SQLStatement {
type(type),
name(NULL) {}
EntityType type;
const char* name;
virtual ~DropStatement() {
delete name;
}
EntityType type;
const char* name;
};

View File

@ -8,7 +8,7 @@ namespace hsql {
/**
* @struct ExecuteStatement
*
* @brief Represents "EXECUTE ins_prep(100, "test", 2.3);"
*/
struct ExecuteStatement : SQLStatement {
ExecuteStatement() :
@ -16,7 +16,10 @@ struct ExecuteStatement : SQLStatement {
name(NULL),
parameters(NULL) {}
virtual ~ExecuteStatement(); // defined in destructors.cpp
virtual ~ExecuteStatement() {
delete name;
delete parameters;
}
const char* name;
List<Expr*>* parameters;

View File

@ -10,6 +10,7 @@ namespace hsql {
/**
* @struct ImportStatement
* @brief Represents "IMPORT"
*/
struct ImportStatement : SQLStatement {
enum ImportType {
@ -24,7 +25,11 @@ struct ImportStatement : SQLStatement {
file_path(NULL),
table_name(NULL) {};
virtual ~ImportStatement(); // defined in destructors.cpp
virtual ~ImportStatement() {
delete file_path;
delete table_name;
}
ImportType type;
const char* file_path;

View File

@ -9,8 +9,7 @@ namespace hsql {
/**
* @struct InsertStatement
* INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)
* INSERT INTO employees SELECT * FROM stundents
* @brief Represents "INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)"
*/
struct InsertStatement : SQLStatement {
enum InsertType {
@ -26,7 +25,12 @@ struct InsertStatement : SQLStatement {
values(NULL),
select(NULL) {}
virtual ~InsertStatement(); // defined in destructors.cpp
virtual ~InsertStatement() {
delete table_name;
delete columns;
delete values;
delete select;
}
InsertType type;
const char* table_name;

View File

@ -9,7 +9,7 @@ namespace hsql {
/**
* @struct PrepareStatement
*
* @brief Represents "PREPARE ins_prep: SELECT * FROM t1 WHERE c1 = ? AND c2 = ?"
*/
struct PrepareStatement : SQLStatement {
PrepareStatement() :
@ -17,7 +17,10 @@ struct PrepareStatement : SQLStatement {
name(NULL),
stmt(NULL) {}
virtual ~PrepareStatement(); // defined in destructors.cpp
virtual ~PrepareStatement() {
delete stmt;
delete name;
}
const char* name;
SQLStatement* stmt;

View File

@ -21,28 +21,33 @@ typedef enum {
kStmtDrop,
kStmtPrepare,
kStmtExecute,
// Following types are not supported yet
kStmtExport,
kStmtRename,
kStmtAlter
} StatementType;
/**
* @struct SQLStatement
* @brief Base class for every SQLStatement
*/
struct SQLStatement {
SQLStatement(StatementType type) :
_type(type) {};
virtual ~SQLStatement(); // defined in destructors.cpp
virtual ~SQLStatement() {}
virtual StatementType type() { return _type; }
private:
StatementType _type;
};
/**
* @struct SQLStatementList
* @brief Represents the result of the SQLParser. If parsing was successful it is a list of SQLStatement.
*/
class SQLStatementList : public List<SQLStatement*> {
public:
SQLStatementList() :
@ -55,7 +60,9 @@ public:
isValid(true),
parser_msg(NULL) {};
virtual ~SQLStatementList(); // defined in destructors.cpp
virtual ~SQLStatementList() {
delete parser_msg;
}
bool isValid;
const char* parser_msg;

View File

@ -9,9 +9,11 @@
namespace hsql {
/**
* @struct OrderDescription
* Description of the order by clause within a select statement
* @brief Description of the order by clause within a select statement
*
* TODO: hold multiple expressions to be sorted by
*/
typedef enum {
@ -24,7 +26,9 @@ struct OrderDescription {
type(type),
expr(expr) {}
virtual ~OrderDescription(); // defined in destructors.cpp
virtual ~OrderDescription() {
delete expr;
}
OrderType type;
Expr* expr;
@ -32,7 +36,7 @@ struct OrderDescription {
/**
* @struct LimitDescription
* Description of the limit clause within a select statement
* @brief Description of the limit clause within a select statement
*/
const int64_t kNoLimit = -1;
const int64_t kNoOffset = -1;
@ -47,7 +51,8 @@ struct LimitDescription {
/**
* @struct SelectStatement
* Representation of a full select statement.
* @brief Representation of a full select statement.
*
* TODO: add union_order and union_limit
*/
struct SelectStatement : SQLStatement {
@ -61,7 +66,14 @@ struct SelectStatement : SQLStatement {
order(NULL),
limit(NULL) {};
virtual ~SelectStatement(); // defined in destructors.cpp
virtual ~SelectStatement() {
delete from_table;
delete select_list;
delete where_clause;
delete group_by;
delete order;
delete limit;
}
TableRef* from_table;
List<Expr*>* select_list;

View File

@ -5,11 +5,21 @@
namespace hsql {
/**
* @struct UpdateClause
* @brief Represents "column = value" expressions
*/
struct UpdateClause {
char* column;
Expr* value;
};
/**
* @struct UpdateStatement
* @brief Represents "UPDATE"
*/
struct UpdateStatement : SQLStatement {
UpdateStatement() :
SQLStatement(kStmtUpdate),
@ -17,7 +27,11 @@ struct UpdateStatement : SQLStatement {
updates(NULL),
where(NULL) {}
virtual ~UpdateStatement(); // defined in destructors.cpp
virtual ~UpdateStatement() {
delete table;
delete updates;
delete where;
}
// TODO: switch to char* instead of TableRef
TableRef* table;

View File

@ -6,6 +6,13 @@
namespace hsql {
/*!
* \mainpage SQLParser (C++)
*/
/*!
* @brief Main class for parsing SQL strings
*/
class SQLParser {
public:
static SQLStatementList* parseSQLString(const char* sql);