add astyle formatting
This commit is contained in:
parent
57b8cdd31b
commit
7d1c56d0aa
|
@ -31,3 +31,6 @@ lib-test/
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
|
*.cpp.orig
|
||||||
|
*.h.orig
|
9
Makefile
9
Makefile
|
@ -9,6 +9,9 @@ LIBCPP = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(S
|
||||||
LIBOBJ = $(LIBCPP:%.cpp=%.o)
|
LIBOBJ = $(LIBCPP:%.cpp=%.o)
|
||||||
TESTCPP = $(shell find test/lib/ -name '*.cpp')
|
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
|
# compile & link flages
|
||||||
CC = g++
|
CC = g++
|
||||||
CFLAGS = -std=c++11 -Wall -fPIC
|
CFLAGS = -std=c++11 -Wall -fPIC
|
||||||
|
@ -48,6 +51,10 @@ cleanall: clean cleanparser
|
||||||
install:
|
install:
|
||||||
cp $(TARGET) $(INSTALL)/lib/$(TARGET)
|
cp $(TARGET) $(INSTALL)/lib/$(TARGET)
|
||||||
|
|
||||||
|
format:
|
||||||
|
astyle --options=astyle.options $(ALLLIB)
|
||||||
|
astyle --options=astyle.options $(ALLTEST)
|
||||||
|
|
||||||
############
|
############
|
||||||
### Test ###
|
### Test ###
|
||||||
############
|
############
|
||||||
|
@ -63,5 +70,3 @@ $(BIN)/sql_tests: library
|
||||||
$(BIN)/sql_grammar_test: library
|
$(BIN)/sql_grammar_test: library
|
||||||
@mkdir -p $(BIN)/
|
@mkdir -p $(BIN)/
|
||||||
$(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser
|
$(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
# indentation
|
||||||
|
--indent=spaces=4
|
||||||
|
--indent-namespaces
|
||||||
|
|
||||||
|
--style=java
|
||||||
|
--style=attach
|
||||||
|
-A2
|
|
@ -87,16 +87,28 @@ struct Expr {
|
||||||
/**
|
/**
|
||||||
* Convenience accessor methods
|
* Convenience accessor methods
|
||||||
*/
|
*/
|
||||||
inline bool isType(ExprType e_type) { return e_type == type; }
|
inline bool isType(ExprType e_type) {
|
||||||
inline bool isLiteral() { return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || isType(kExprLiteralString) || isType(kExprPlaceholder); }
|
return e_type == type;
|
||||||
inline bool hasAlias() { return alias != NULL; }
|
}
|
||||||
inline bool hasTable() { return table != NULL; }
|
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() {
|
inline char* getName() {
|
||||||
if (alias != NULL) return alias;
|
if (alias != NULL) return alias;
|
||||||
else return name;
|
else return name;
|
||||||
}
|
}
|
||||||
inline bool isSimpleOp() { return op_type == SIMPLE_OP; }
|
inline bool isSimpleOp() {
|
||||||
inline bool isSimpleOp(char op) { return isSimpleOp() && op_char == op; }
|
return op_type == SIMPLE_OP;
|
||||||
|
}
|
||||||
|
inline bool isSimpleOp(char op) {
|
||||||
|
return isSimpleOp() && op_char == op;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,7 +32,9 @@ namespace hsql {
|
||||||
|
|
||||||
virtual ~SQLStatement() {}
|
virtual ~SQLStatement() {}
|
||||||
|
|
||||||
virtual StatementType type() { return _type; }
|
virtual StatementType type() {
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StatementType _type;
|
StatementType _type;
|
||||||
|
|
|
@ -54,7 +54,9 @@ struct TableRef {
|
||||||
/**
|
/**
|
||||||
* Convenience accessor methods
|
* Convenience accessor methods
|
||||||
*/
|
*/
|
||||||
inline bool hasSchema() { return schema != NULL; }
|
inline bool hasSchema() {
|
||||||
|
return schema != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
inline char* getName() {
|
inline char* getName() {
|
||||||
if (alias != NULL) return alias;
|
if (alias != NULL) return alias;
|
||||||
|
|
|
@ -7,13 +7,27 @@ namespace hsql {
|
||||||
|
|
||||||
void printOperatorExpression(Expr* expr, uint num_indent);
|
void printOperatorExpression(Expr* expr, uint num_indent);
|
||||||
|
|
||||||
std::string indent(uint num_indent) { return std::string(num_indent, '\t'); }
|
std::string indent(uint num_indent) {
|
||||||
void inprint(int64_t val, uint num_indent) { printf("%s%ld \n", indent(num_indent).c_str(), val); }
|
return std::string(num_indent, '\t');
|
||||||
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(int64_t val, uint num_indent) {
|
||||||
void inprint(const char* val, const char* val2, uint num_indent) { printf("%s%s->%s\n", indent(num_indent).c_str(), val, val2); }
|
printf("%s%ld \n", indent(num_indent).c_str(), val);
|
||||||
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 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) {
|
void printTableRefInfo(TableRef* table, uint num_indent) {
|
||||||
switch (table->type) {
|
switch (table->type) {
|
||||||
|
@ -43,14 +57,27 @@ void printTableRefInfo(TableRef* table, uint num_indent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void printOperatorExpression(Expr* expr, 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) {
|
switch (expr->op_type) {
|
||||||
case Expr::SIMPLE_OP: inprintC(expr->op_char, num_indent); break;
|
case Expr::SIMPLE_OP:
|
||||||
case Expr::AND: inprint("AND", num_indent); break;
|
inprintC(expr->op_char, num_indent);
|
||||||
case Expr::OR: inprint("OR", num_indent); break;
|
break;
|
||||||
case Expr::NOT: inprint("NOT", num_indent); break;
|
case Expr::AND:
|
||||||
default: inprintU(expr->op_type, num_indent); break;
|
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);
|
printExpression(expr->expr, num_indent+1);
|
||||||
if (expr->expr2 != NULL) printExpression(expr->expr2, 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) {
|
void printExpression(Expr* expr, uint num_indent) {
|
||||||
switch (expr->type) {
|
switch (expr->type) {
|
||||||
case kExprStar: inprint("*", num_indent); break;
|
case kExprStar:
|
||||||
case kExprColumnRef: inprint(expr->name, num_indent); break;
|
inprint("*", num_indent);
|
||||||
|
break;
|
||||||
|
case kExprColumnRef:
|
||||||
|
inprint(expr->name, num_indent);
|
||||||
|
break;
|
||||||
// case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break;
|
// case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break;
|
||||||
case kExprLiteralFloat: inprint(expr->fval, num_indent); break;
|
case kExprLiteralFloat:
|
||||||
case kExprLiteralInt: inprint(expr->ival, num_indent); break;
|
inprint(expr->fval, num_indent);
|
||||||
case kExprLiteralString: inprint(expr->name, num_indent); break;
|
break;
|
||||||
case kExprFunctionRef: inprint(expr->name, num_indent); inprint(expr->expr->name, num_indent+1); break;
|
case kExprLiteralInt:
|
||||||
case kExprOperator: printOperatorExpression(expr, num_indent); break;
|
inprint(expr->ival, num_indent);
|
||||||
default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); return;
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue