add astyle formatting

This commit is contained in:
Pedro 2016-02-27 15:01:06 +01:00
parent 57b8cdd31b
commit 7d1c56d0aa
27 changed files with 928 additions and 851 deletions

3
.gitignore vendored
View File

@ -31,3 +31,6 @@ lib-test/
*.exe
*.out
*.app
*.cpp.orig
*.h.orig

View File

@ -9,6 +9,9 @@ LIBCPP = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(S
LIBOBJ = $(LIBCPP:%.cpp=%.o)
TESTCPP = $(shell find test/lib/ -name '*.cpp')
ALLLIB = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*")
ALLTEST = $(shell find test/lib/ -name '*.cpp') $(shell find test/lib/ -name '*.h')
# compile & link flages
CC = g++
CFLAGS = -std=c++11 -Wall -fPIC
@ -48,6 +51,10 @@ cleanall: clean cleanparser
install:
cp $(TARGET) $(INSTALL)/lib/$(TARGET)
format:
astyle --options=astyle.options $(ALLLIB)
astyle --options=astyle.options $(ALLTEST)
############
### Test ###
############
@ -63,5 +70,3 @@ $(BIN)/sql_tests: library
$(BIN)/sql_grammar_test: library
@mkdir -p $(BIN)/
$(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser

8
astyle.options Normal file
View File

@ -0,0 +1,8 @@
# indentation
--indent=spaces=4
--indent-namespaces
--style=java
--style=attach
-A2

View File

@ -87,16 +87,28 @@ struct Expr {
/**
* Convenience accessor methods
*/
inline bool isType(ExprType e_type) { return e_type == type; }
inline bool isLiteral() { return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || isType(kExprLiteralString) || isType(kExprPlaceholder); }
inline bool hasAlias() { return alias != NULL; }
inline bool hasTable() { return table != NULL; }
inline bool isType(ExprType e_type) {
return e_type == type;
}
inline bool isLiteral() {
return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || isType(kExprLiteralString) || isType(kExprPlaceholder);
}
inline bool hasAlias() {
return alias != NULL;
}
inline bool hasTable() {
return table != NULL;
}
inline char* getName() {
if (alias != NULL) return alias;
else return name;
}
inline bool isSimpleOp() { return op_type == SIMPLE_OP; }
inline bool isSimpleOp(char op) { return isSimpleOp() && op_char == op; }
inline bool isSimpleOp() {
return op_type == SIMPLE_OP;
}
inline bool isSimpleOp(char op) {
return isSimpleOp() && op_char == op;
}
/**

View File

@ -32,7 +32,9 @@ namespace hsql {
virtual ~SQLStatement() {}
virtual StatementType type() { return _type; }
virtual StatementType type() {
return _type;
}
private:
StatementType _type;

View File

@ -54,7 +54,9 @@ struct TableRef {
/**
* Convenience accessor methods
*/
inline bool hasSchema() { return schema != NULL; }
inline bool hasSchema() {
return schema != NULL;
}
inline char* getName() {
if (alias != NULL) return alias;

View File

@ -7,13 +7,27 @@ namespace hsql {
void printOperatorExpression(Expr* expr, uint num_indent);
std::string indent(uint num_indent) { return std::string(num_indent, '\t'); }
void inprint(int64_t val, uint num_indent) { printf("%s%ld \n", indent(num_indent).c_str(), val); }
void inprint(float val, uint num_indent) { printf("%s%f\n", indent(num_indent).c_str(), val); }
void inprint(const char* val, uint num_indent) { printf("%s%s\n", indent(num_indent).c_str(), val); }
void inprint(const char* val, const char* val2, uint num_indent) { printf("%s%s->%s\n", indent(num_indent).c_str(), val, val2); }
void inprintC(char val, uint num_indent) { printf("%s%c\n", indent(num_indent).c_str(), val); }
void inprintU(uint64_t val, uint num_indent) { printf("%s%lu\n", indent(num_indent).c_str(), val); }
std::string indent(uint num_indent) {
return std::string(num_indent, '\t');
}
void inprint(int64_t val, uint num_indent) {
printf("%s%ld \n", indent(num_indent).c_str(), val);
}
void inprint(float val, uint num_indent) {
printf("%s%f\n", indent(num_indent).c_str(), val);
}
void inprint(const char* val, uint num_indent) {
printf("%s%s\n", indent(num_indent).c_str(), val);
}
void inprint(const char* val, const char* val2, uint num_indent) {
printf("%s%s->%s\n", indent(num_indent).c_str(), val, val2);
}
void inprintC(char val, uint num_indent) {
printf("%s%c\n", indent(num_indent).c_str(), val);
}
void inprintU(uint64_t val, uint num_indent) {
printf("%s%lu\n", indent(num_indent).c_str(), val);
}
void printTableRefInfo(TableRef* table, uint num_indent) {
switch (table->type) {
@ -43,14 +57,27 @@ void printTableRefInfo(TableRef* table, uint num_indent) {
}
void printOperatorExpression(Expr* expr, uint num_indent) {
if (expr == NULL) { inprint("null", num_indent); return; }
if (expr == NULL) {
inprint("null", num_indent);
return;
}
switch (expr->op_type) {
case Expr::SIMPLE_OP: inprintC(expr->op_char, num_indent); break;
case Expr::AND: inprint("AND", num_indent); break;
case Expr::OR: inprint("OR", num_indent); break;
case Expr::NOT: inprint("NOT", num_indent); break;
default: inprintU(expr->op_type, num_indent); break;
case Expr::SIMPLE_OP:
inprintC(expr->op_char, num_indent);
break;
case Expr::AND:
inprint("AND", num_indent);
break;
case Expr::OR:
inprint("OR", num_indent);
break;
case Expr::NOT:
inprint("NOT", num_indent);
break;
default:
inprintU(expr->op_type, num_indent);
break;
}
printExpression(expr->expr, num_indent+1);
if (expr->expr2 != NULL) printExpression(expr->expr2, num_indent+1);
@ -58,18 +85,36 @@ void printOperatorExpression(Expr* expr, uint num_indent) {
void printExpression(Expr* expr, uint num_indent) {
switch (expr->type) {
case kExprStar: inprint("*", num_indent); break;
case kExprColumnRef: inprint(expr->name, num_indent); break;
case kExprStar:
inprint("*", num_indent);
break;
case kExprColumnRef:
inprint(expr->name, num_indent);
break;
// case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break;
case kExprLiteralFloat: inprint(expr->fval, num_indent); break;
case kExprLiteralInt: inprint(expr->ival, num_indent); break;
case kExprLiteralString: inprint(expr->name, num_indent); break;
case kExprFunctionRef: inprint(expr->name, num_indent); inprint(expr->expr->name, num_indent+1); break;
case kExprOperator: printOperatorExpression(expr, num_indent); break;
default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); return;
case kExprLiteralFloat:
inprint(expr->fval, num_indent);
break;
case kExprLiteralInt:
inprint(expr->ival, num_indent);
break;
case kExprLiteralString:
inprint(expr->name, num_indent);
break;
case kExprFunctionRef:
inprint(expr->name, num_indent);
inprint(expr->expr->name, num_indent+1);
break;
case kExprOperator:
printOperatorExpression(expr, num_indent);
break;
default:
fprintf(stderr, "Unrecognized expression type %d\n", expr->type);
return;
}
if (expr->alias != NULL) {
inprint("Alias", num_indent+1); inprint(expr->alias, num_indent+2);
inprint("Alias", num_indent+1);
inprint(expr->alias, num_indent+2);
}
}