2014-10-09 04:26:38 +02:00
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
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:26:38 +02:00
|
|
|
|
|
|
|
Expr* makeColumnRef(char* name) {
|
|
|
|
ALLOC_EXPR(e, eExprColumnRef);
|
|
|
|
e->name = name;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr* makeFunctionRef(char* func_name, Expr* expr) {
|
|
|
|
ALLOC_EXPR(e, eExprFunctionRef);
|
|
|
|
e->name = func_name;
|
2014-10-09 04:46:25 +02:00
|
|
|
e->expr = expr;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr* makeFloatLiteral(float value) {
|
|
|
|
ALLOC_EXPR(e, eExprLiteralFloat);
|
|
|
|
e->float_literal = value;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr* makeStringLiteral(char* string) {
|
|
|
|
ALLOC_EXPR(e, eExprLiteralString);
|
2014-10-24 16:10:38 +02:00
|
|
|
e->name = substr(string, 1, strlen(string)-1);
|
|
|
|
delete string;
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {
|
|
|
|
ALLOC_EXPR(e, eExprOperator);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) {
|
|
|
|
ALLOC_EXPR(e, eExprOperator);
|
|
|
|
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) {
|
|
|
|
ALLOC_EXPR(e, eExprOperator);
|
|
|
|
e->op_type = TRIVIAL_OP;
|
|
|
|
e->op_char = op;
|
|
|
|
e->expr = expr1;
|
|
|
|
e->expr2 = expr2;
|
2014-10-09 04:26:38 +02:00
|
|
|
return e;
|
2014-10-20 23:19:27 +02:00
|
|
|
}
|