minor renaming and namespacing

This commit is contained in:
Pedro 2014-10-31 18:05:08 +01:00
parent 794a17c04c
commit 16dbe70ea4
4 changed files with 57 additions and 58 deletions

View File

@ -231,8 +231,8 @@ scalar_expr:
;
unary_expr:
'-' expr { $$ = Expr::makeOpUnary(UMINUS, $2); }
| NOT expr { $$ = Expr::makeOpUnary(NOT, $2); }
'-' expr { $$ = Expr::makeOpUnary(Expr::UMINUS, $2); }
| NOT expr { $$ = Expr::makeOpUnary(Expr::NOT, $2); }
;
binary_expr:
@ -241,26 +241,26 @@ binary_expr:
| expr '+' expr { $$ = Expr::makeOpBinary($1, '+', $3); }
| expr '/' expr { $$ = Expr::makeOpBinary($1, '/', $3); }
| expr '*' expr { $$ = Expr::makeOpBinary($1, '*', $3); }
| expr AND expr { $$ = Expr::makeOpBinary($1, AND, $3); }
| expr OR expr { $$ = Expr::makeOpBinary($1, OR, $3); }
| expr AND expr { $$ = Expr::makeOpBinary($1, Expr::AND, $3); }
| expr OR expr { $$ = Expr::makeOpBinary($1, Expr::OR, $3); }
;
comp_expr:
expr EQUALS expr { $$ = Expr::makeOpBinary($1, '=', $3); }
| expr NOTEQUALS expr { $$ = Expr::makeOpBinary($1, NOT_EQUALS, $3); }
| expr NOTEQUALS expr { $$ = Expr::makeOpBinary($1, Expr::NOT_EQUALS, $3); }
| expr LESS expr { $$ = Expr::makeOpBinary($1, '<', $3); }
| expr GREATER expr { $$ = Expr::makeOpBinary($1, '>', $3); }
| expr LESSEQ expr { $$ = Expr::makeOpBinary($1, LESS_EQ, $3); }
| expr GREATEREQ expr { $$ = Expr::makeOpBinary($1, GREATER_EQ, $3); }
| expr LESSEQ expr { $$ = Expr::makeOpBinary($1, Expr::LESS_EQ, $3); }
| expr GREATEREQ expr { $$ = Expr::makeOpBinary($1, Expr::GREATER_EQ, $3); }
;
function_expr:
NAME '(' expr ')' { $$ = makeFunctionRef($1, $3); }
NAME '(' expr ')' { $$ = Expr::makeFunctionRef($1, $3); }
;
column_name:
NAME { $$ = makeColumnRef($1); }
NAME { $$ = Expr::makeColumnRef($1); }
;
literal:

View File

@ -11,18 +11,6 @@ char* substr(const char* source, int from, int to) {
return copy;
}
Expr* makeColumnRef(char* name) {
ALLOC_EXPR(e, kExprColumnRef);
e->name = name;
return e;
}
Expr* makeFunctionRef(char* func_name, Expr* expr) {
ALLOC_EXPR(e, kExprFunctionRef);
e->name = func_name;
e->expr = expr;
return e;
}
@ -64,7 +52,7 @@ Expr* Expr::makeLiteral(int64_t val) {
Expr* Expr::makeLiteral(double value) {
ALLOC_EXPR(e, kExprLiteralFloat);
e->float_literal = value;
e->fval = value;
return e;
}
@ -75,3 +63,16 @@ Expr* Expr::makeLiteral(char* string) {
return e;
}
Expr* Expr::makeColumnRef(char* name) {
ALLOC_EXPR(e, kExprColumnRef);
e->name = name;
return e;
}
Expr* Expr::makeFunctionRef(char* func_name, Expr* expr) {
ALLOC_EXPR(e, kExprFunctionRef);
e->name = func_name;
e->expr = expr;
return e;
}

View File

@ -3,8 +3,6 @@
#include <stdlib.h>
typedef enum {
kExprLiteralFloat,
kExprLiteralString,
@ -15,14 +13,17 @@ typedef enum {
kExprOperator
} ExprType;
typedef struct Expr Expr;
/**
struct Expr {
/**
* Operator types. These are important for expressions of type kExprOperator
* Trivial types are those that can be descriped by a sigle character e.g:
* + - * / < > = %
* Non-trivial are:
* <> <= >= LIKE ISNULL NOT
*/
typedef enum {
typedef enum {
SIMPLE_OP,
// Binary
NOT_EQUALS,
@ -35,12 +36,10 @@ typedef enum {
NOT,
UMINUS,
ISNULL
} OperatorType;
} OperatorType;
typedef struct Expr Expr;
struct Expr {
Expr(ExprType type) : type(type) {};
ExprType type;
@ -48,7 +47,7 @@ struct Expr {
Expr* expr;
Expr* expr2;
char* name;
float float_literal;
float fval;
int64_t ival;
OperatorType op_type;
@ -61,6 +60,9 @@ struct Expr {
static Expr* makeLiteral(int64_t val);
static Expr* makeLiteral(double val);
static Expr* makeLiteral(char* val);
static Expr* makeColumnRef(char* name);
static Expr* makeFunctionRef(char* func_name, Expr* expr);
};
// Zero initializes an Expr object and assigns it to a space in the heap
@ -73,8 +75,4 @@ struct Expr {
*var = zero; \
} while(0)
Expr* makeColumnRef(char* name);
Expr* makeFunctionRef(char* func_name, Expr* expr);
#endif

View File

@ -31,10 +31,10 @@ void printOperatorExpression(Expr* expr, uint num_indent) {
if (expr == NULL) { inprint("null", num_indent); return; }
switch (expr->op_type) {
case SIMPLE_OP: inprintC(expr->op_char, num_indent); break;
case AND: inprint("AND", num_indent); break;
case OR: inprint("OR", num_indent); break;
case NOT: inprint("NOT", 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);
@ -45,7 +45,7 @@ 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 kExprLiteralFloat: inprint(expr->float_literal, 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: /* todo */ break;