HyriseSQLParser/src/lib/Expr.cpp

95 lines
1.6 KiB
C++
Raw Normal View History

#include "Expr.h"
2014-10-09 04:46:25 +02:00
#include <stdio.h>
2014-10-24 16:10:38 +02:00
#include <string.h>
namespace hsql {
2014-10-24 16:10:38 +02:00
char* substr(const char* source, int from, int to) {
int len = to-from;
char* copy = new char[len+1];
strncpy(copy, source+from, len);
copy[len] = '\0';
return copy;
}
2014-10-09 04:46:25 +02:00
2014-10-24 16:10:38 +02:00
Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {
2014-10-27 11:23:31 +01:00
ALLOC_EXPR(e, kExprOperator);
2014-10-24 16:10:38 +02:00
e->op_type = op;
e->expr = expr;
2014-10-24 17:17:40 +02:00
e->expr2 = NULL;
2014-10-24 16:10:38 +02:00
return e;
}
2014-10-27 13:54:16 +01:00
2014-10-24 16:10:38 +02:00
Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) {
2014-10-27 11:23:31 +01:00
ALLOC_EXPR(e, kExprOperator);
2014-10-24 16:10:38 +02:00
e->op_type = op;
e->op_char = 0;
e->expr = expr1;
e->expr2 = expr2;
return e;
}
Expr* Expr::makeOpBinary(Expr* expr1, char op, Expr* expr2) {
2014-10-27 11:23:31 +01:00
ALLOC_EXPR(e, kExprOperator);
e->op_type = SIMPLE_OP;
2014-10-24 16:10:38 +02:00
e->op_char = op;
e->expr = expr1;
e->expr2 = expr2;
return e;
2014-10-20 23:19:27 +02:00
}
2014-10-27 13:54:16 +01:00
Expr* Expr::makeLiteral(int64_t val) {
ALLOC_EXPR(e, kExprLiteralInt);
e->ival = val;
return e;
}
Expr* Expr::makeLiteral(double value) {
ALLOC_EXPR(e, kExprLiteralFloat);
2014-10-31 18:05:08 +01:00
e->fval = value;
2014-10-27 13:54:16 +01:00
return e;
}
Expr* Expr::makeLiteral(char* string) {
ALLOC_EXPR(e, kExprLiteralString);
e->name = string;
2014-10-27 13:54:16 +01:00
return e;
}
2014-10-31 18:05:08 +01:00
Expr* Expr::makeColumnRef(char* name) {
ALLOC_EXPR(e, kExprColumnRef);
e->name = name;
return e;
}
Expr* Expr::makeColumnRef(char* table, char* name) {
ALLOC_EXPR(e, kExprTableColumnRef);
e->name = name;
e->table = table;
return e;
}
2014-10-31 18:05:08 +01:00
Expr* Expr::makeFunctionRef(char* func_name, Expr* expr) {
ALLOC_EXPR(e, kExprFunctionRef);
e->name = func_name;
e->expr = expr;
return e;
}
2014-11-07 15:21:54 +01:00
Expr::~Expr() {
2014-11-10 23:32:27 +01:00
// delete expr;
// delete expr2;
// delete name;
// delete table;
2014-11-07 15:21:54 +01:00
}
} // namespace hsql