naming changes

This commit is contained in:
Pedro 2014-10-27 11:23:31 +01:00
parent 0b9d10f726
commit f319a02a85
7 changed files with 44 additions and 44 deletions

View File

@ -246,7 +246,7 @@ literal:
; ;
star_expr: star_expr:
'*' { $$ = new Expr(eExprStar); } '*' { $$ = new Expr(kExprStar); }
; ;
@ -257,7 +257,7 @@ table_ref:
table_ref_atomic table_ref_atomic
| table_ref_atomic ',' table_ref_commalist { | table_ref_atomic ',' table_ref_commalist {
$3->push_back($1); $3->push_back($1);
auto tbl = new TableRef(eTableCrossProduct); auto tbl = new TableRef(kTableCrossProduct);
tbl->list = $3; tbl->list = $3;
$$ = tbl; $$ = tbl;
} }
@ -265,12 +265,12 @@ table_ref:
table_ref_atomic: table_ref_atomic:
table_name { table_name {
auto tbl = new TableRef(eTableName); auto tbl = new TableRef(kTableName);
tbl->name = $1; tbl->name = $1;
$$ = tbl; $$ = tbl;
} }
| '(' select_statement ')' { | '(' select_statement ')' {
auto tbl = new TableRef(eTableSelect); auto tbl = new TableRef(kTableSelect);
tbl->stmt = $2; tbl->stmt = $2;
$$ = tbl; $$ = tbl;
} }

View File

@ -12,26 +12,26 @@ char* substr(const char* source, int from, int to) {
} }
Expr* makeColumnRef(char* name) { Expr* makeColumnRef(char* name) {
ALLOC_EXPR(e, eExprColumnRef); ALLOC_EXPR(e, kExprColumnRef);
e->name = name; e->name = name;
return e; return e;
} }
Expr* makeFunctionRef(char* func_name, Expr* expr) { Expr* makeFunctionRef(char* func_name, Expr* expr) {
ALLOC_EXPR(e, eExprFunctionRef); ALLOC_EXPR(e, kExprFunctionRef);
e->name = func_name; e->name = func_name;
e->expr = expr; e->expr = expr;
return e; return e;
} }
Expr* makeFloatLiteral(float value) { Expr* makeFloatLiteral(float value) {
ALLOC_EXPR(e, eExprLiteralFloat); ALLOC_EXPR(e, kExprLiteralFloat);
e->float_literal = value; e->float_literal = value;
return e; return e;
} }
Expr* makeStringLiteral(char* string) { Expr* makeStringLiteral(char* string) {
ALLOC_EXPR(e, eExprLiteralString); ALLOC_EXPR(e, kExprLiteralString);
e->name = substr(string, 1, strlen(string)-1); e->name = substr(string, 1, strlen(string)-1);
delete string; delete string;
return e; return e;
@ -39,7 +39,7 @@ Expr* makeStringLiteral(char* string) {
Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) { Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {
ALLOC_EXPR(e, eExprOperator); ALLOC_EXPR(e, kExprOperator);
e->op_type = op; e->op_type = op;
e->expr = expr; e->expr = expr;
e->expr2 = NULL; e->expr2 = NULL;
@ -47,7 +47,7 @@ Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {
} }
Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) { Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) {
ALLOC_EXPR(e, eExprOperator); ALLOC_EXPR(e, kExprOperator);
e->op_type = op; e->op_type = op;
e->op_char = 0; e->op_char = 0;
e->expr = expr1; e->expr = expr1;
@ -56,8 +56,8 @@ Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) {
} }
Expr* Expr::makeOpBinary(Expr* expr1, char op, Expr* expr2) { Expr* Expr::makeOpBinary(Expr* expr1, char op, Expr* expr2) {
ALLOC_EXPR(e, eExprOperator); ALLOC_EXPR(e, kExprOperator);
e->op_type = TRIVIAL_OP; e->op_type = SIMPLE_OP;
e->op_char = op; e->op_char = op;
e->expr = expr1; e->expr = expr1;
e->expr2 = expr2; e->expr2 = expr2;

View File

@ -6,12 +6,12 @@
typedef enum { typedef enum {
eExprLiteralFloat, kExprLiteralFloat,
eExprLiteralString, kExprLiteralString,
eExprStar, kExprStar,
eExprColumnRef, kExprColumnRef,
eExprFunctionRef, kExprFunctionRef,
eExprOperator kExprOperator
} ExprType; } ExprType;
@ -22,7 +22,7 @@ typedef enum {
* <> <= >= LIKE ISNULL NOT * <> <= >= LIKE ISNULL NOT
*/ */
typedef enum { typedef enum {
TRIVIAL_OP, SIMPLE_OP,
// Binary // Binary
NOT_EQUALS, NOT_EQUALS,
LESS_EQ, LESS_EQ,

View File

@ -10,22 +10,22 @@
#include "Table.h" #include "Table.h"
typedef enum { typedef enum {
eSelect, kStmtSelect,
eDelete, kStmtDelete,
eInsert, kStmtInsert,
eCreate kStmtCreate
} EStatementType; } StatementType;
struct Statement { struct Statement {
Statement(EStatementType type) : type(type) {}; Statement(StatementType type) : type(type) {};
EStatementType type; StatementType type;
}; };
struct SelectStatement : Statement { struct SelectStatement : Statement {
SelectStatement() : Statement(eSelect) {}; SelectStatement() : Statement(kStmtSelect) {};
TableRef* from_table; TableRef* from_table;
List<Expr*>* select_list; List<Expr*>* select_list;

View File

@ -8,17 +8,17 @@ class SelectStatement;
* Holds reference to tables. Can be either table names or a select statement. * Holds reference to tables. Can be either table names or a select statement.
*/ */
typedef enum { typedef enum {
eTableName, kTableName,
eTableSelect, kTableSelect,
eTableCrossProduct kTableCrossProduct
} ETableRefType; } TableRefType;
typedef struct TableRef TableRef; typedef struct TableRef TableRef;
struct TableRef { struct TableRef {
TableRef(ETableRefType type) : type(type) {} TableRef(TableRefType type) : type(type) {}
ETableRefType type; TableRefType type;
char* name; char* name;
SelectStatement* stmt; SelectStatement* stmt;

View File

@ -14,13 +14,13 @@ void inprint(char val, uint num_indent) { printf("%s%c\n", indent(num_indent), v
void printTableRefInfo(TableRef* table, uint num_indent) { void printTableRefInfo(TableRef* table, uint num_indent) {
switch (table->type) { switch (table->type) {
case eTableName: case kTableName:
inprint(table->name, num_indent); inprint(table->name, num_indent);
break; break;
case eTableSelect: case kTableSelect:
printSelectStatementInfo(table->stmt, num_indent); printSelectStatementInfo(table->stmt, num_indent);
break; break;
case eTableCrossProduct: case kTableCrossProduct:
for (TableRef* tbl : table->list->_vector) printTableRefInfo(tbl, num_indent); for (TableRef* tbl : table->list->_vector) printTableRefInfo(tbl, num_indent);
break; break;
} }
@ -30,7 +30,7 @@ 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 TRIVIAL_OP: inprint(expr->op_char, num_indent); break; case SIMPLE_OP: inprint(expr->op_char, num_indent); break;
case AND: inprint("AND", num_indent); break; case AND: inprint("AND", num_indent); break;
case OR: inprint("OR", num_indent); break; case OR: inprint("OR", num_indent); break;
case NOT: inprint("NOT", num_indent); break; case NOT: inprint("NOT", num_indent); break;
@ -42,12 +42,12 @@ 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 eExprStar: inprint("*", num_indent); break; case kExprStar: inprint("*", num_indent); break;
case eExprColumnRef: inprint(expr->name, num_indent); break; case kExprColumnRef: inprint(expr->name, num_indent); break;
case eExprLiteralFloat: inprint(expr->float_literal, num_indent); break; case kExprLiteralFloat: inprint(expr->float_literal, num_indent); break;
case eExprLiteralString: inprint(expr->name, num_indent); break; case kExprLiteralString: inprint(expr->name, num_indent); break;
case eExprFunctionRef: /* todo */ break; case kExprFunctionRef: /* todo */ break;
case eExprOperator: printOperatorExpression(expr, num_indent); break; case kExprOperator: printOperatorExpression(expr, num_indent); break;
default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); break; default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); break;
} }
} }

View File

@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
continue; continue;
} }
if (stmt->type == eSelect) { if (stmt->type == kStmtSelect) {
printSelectStatementInfo((SelectStatement*) stmt, 0); printSelectStatementInfo((SelectStatement*) stmt, 0);
} else { } else {
fprintf(stderr, "Only Supporting Select Statements!\n"); fprintf(stderr, "Only Supporting Select Statements!\n");