Uh, Updates?

This commit is contained in:
Michael Fabian Dirks
2016-10-03 17:11:15 +02:00
parent aa3cf453e5
commit 581c640149
62 changed files with 469 additions and 489 deletions
+65 -65
View File
@@ -13,7 +13,7 @@ ExprNode *ExprNode::castTo(Type *ty, Environ *e) {
ex("Illegal type conversion");
}
ExprNode *cast = d_new CastNode(this, ty);
ExprNode *cast = new CastNode(this, ty);
cast->semant(e);
return cast;
}
@@ -25,9 +25,9 @@ ExprNode *CastNode::semant(Environ *e) {
if (ConstNode *c = expr->constNode()) {
ExprNode *e;
if (type == Type::int_type) e = d_new IntConstNode(c->intValue());
else if (type == Type::float_type) e = d_new FloatConstNode(c->floatValue());
else e = d_new StringConstNode(c->stringValue());
if (type == Type::int_type) e = new IntConstNode(c->intValue());
else if (type == Type::float_type) e = new FloatConstNode(c->floatValue());
else e = new StringConstNode(c->stringValue());
delete this;
return e;
}
@@ -43,11 +43,11 @@ TNode *CastNode::translate(Codegen *g) {
TNode *t = expr->translate(g);
if (expr->sem_type == Type::float_type && sem_type == Type::int_type) {
//float->int
return d_new TNode(IR_CAST, t, 0);
return new TNode(IR_CAST, t, 0);
}
if (expr->sem_type == Type::int_type && sem_type == Type::float_type) {
//int->float
return d_new TNode(IR_FCAST, t, 0);
return new TNode(IR_FCAST, t, 0);
}
if (expr->sem_type == Type::string_type && sem_type == Type::int_type) {
//str->int
@@ -92,17 +92,17 @@ TNode *ExprSeqNode::translate(Codegen *g, bool cfunc) {
if (ty->stringType()) {
q = call("__bbStrToCStr", q);
} else if (ty->structType()) {
q = d_new TNode(IR_MEM, q);
q = new TNode(IR_MEM, q);
} else if (ty == Type::void_type) {
q = d_new TNode(IR_MEM, add(q, iconst(4)));
q = new TNode(IR_MEM, add(q, iconst(4)));
}
}
TNode *p;
p = d_new TNode(IR_ARG, 0, 0, k * 4);
p = d_new TNode(IR_MEM, p, 0);
p = d_new TNode(IR_MOVE, q, p);
p = d_new TNode(IR_SEQ, p, 0);
p = new TNode(IR_ARG, 0, 0, k * 4);
p = new TNode(IR_MEM, p, 0);
p = new TNode(IR_MOVE, q, p);
p = new TNode(IR_SEQ, p, 0);
if (l) l->r = p;
else t = p;
l = p;
@@ -167,14 +167,14 @@ TNode *CallNode::translate(Codegen *g) {
TNode *r = exprs->translate(g, f->cfunc);
if (f->userlib) {
l = d_new TNode(IR_MEM, l);
l = new TNode(IR_MEM, l);
usedfuncs.insert(ident);
}
if (sem_type == Type::float_type) {
t = d_new TNode(IR_FCALL, l, r, exprs->size() * 4);
t = new TNode(IR_FCALL, l, r, exprs->size() * 4);
} else {
t = d_new TNode(IR_CALL, l, r, exprs->size() * 4);
t = new TNode(IR_CALL, l, r, exprs->size() * 4);
}
if (f->returnType->stringType()) {
@@ -209,7 +209,7 @@ IntConstNode::IntConstNode(int n) :value(n) {
}
TNode *IntConstNode::translate(Codegen *g) {
return d_new TNode(IR_CONST, 0, 0, value);
return new TNode(IR_CONST, 0, 0, value);
}
int IntConstNode::intValue() {
@@ -232,7 +232,7 @@ FloatConstNode::FloatConstNode(float f) :value(f) {
}
TNode *FloatConstNode::translate(Codegen *g) {
return d_new TNode(IR_CONST, 0, 0, *(int*)&value);
return new TNode(IR_CONST, 0, 0, *(int*)&value);
}
int FloatConstNode::intValue() {
@@ -291,17 +291,17 @@ ExprNode *UniExprNode::semant(Environ *e) {
ExprNode *e;
if (sem_type == Type::int_type) {
switch (op) {
case '+':e = d_new IntConstNode(+c->intValue()); break;
case '-':e = d_new IntConstNode(-c->intValue()); break;
case ABS:e = d_new IntConstNode(c->intValue() >= 0 ? c->intValue() : -c->intValue()); break;
case SGN:e = d_new IntConstNode(c->intValue() > 0 ? 1 : (c->intValue() < 0 ? -1 : 0)); break;
case '+':e = new IntConstNode(+c->intValue()); break;
case '-':e = new IntConstNode(-c->intValue()); break;
case ABS:e = new IntConstNode(c->intValue() >= 0 ? c->intValue() : -c->intValue()); break;
case SGN:e = new IntConstNode(c->intValue() > 0 ? 1 : (c->intValue() < 0 ? -1 : 0)); break;
}
} else {
switch (op) {
case '+':e = d_new FloatConstNode(+c->floatValue()); break;
case '-':e = d_new FloatConstNode(-c->floatValue()); break;
case ABS:e = d_new FloatConstNode(c->floatValue() >= 0 ? c->floatValue() : -c->floatValue()); break;
case SGN:e = d_new FloatConstNode(c->floatValue() > 0 ? 1 : (c->floatValue() < 0 ? -1 : 0)); break;
case '+':e = new FloatConstNode(+c->floatValue()); break;
case '-':e = new FloatConstNode(-c->floatValue()); break;
case ABS:e = new FloatConstNode(c->floatValue() >= 0 ? c->floatValue() : -c->floatValue()); break;
case SGN:e = new FloatConstNode(c->floatValue() > 0 ? 1 : (c->floatValue() < 0 ? -1 : 0)); break;
}
}
delete this;
@@ -328,7 +328,7 @@ TNode *UniExprNode::translate(Codegen *g) {
case SGN:return fcall("__bbFSgn", l);
}
}
return d_new TNode(n, l, 0);
return new TNode(n, l, 0);
}
/////////////////////////////////////////////////////
@@ -341,12 +341,12 @@ ExprNode *BinExprNode::semant(Environ *e) {
if (lc && rc) {
ExprNode *expr = nullptr;
switch (op) {
case AND:expr = d_new IntConstNode(lc->intValue() & rc->intValue()); break;
case OR: expr = d_new IntConstNode(lc->intValue() | rc->intValue()); break;
case XOR:expr = d_new IntConstNode(lc->intValue() ^ rc->intValue()); break;
case SHL:expr = d_new IntConstNode(lc->intValue() << rc->intValue()); break;
case SHR:expr = d_new IntConstNode((unsigned)lc->intValue() >> rc->intValue()); break;
case SAR:expr = d_new IntConstNode(lc->intValue() >> rc->intValue()); break;
case AND:expr = new IntConstNode(lc->intValue() & rc->intValue()); break;
case OR: expr = new IntConstNode(lc->intValue() | rc->intValue()); break;
case XOR:expr = new IntConstNode(lc->intValue() ^ rc->intValue()); break;
case SHL:expr = new IntConstNode(lc->intValue() << rc->intValue()); break;
case SHR:expr = new IntConstNode((unsigned)lc->intValue() >> rc->intValue()); break;
case SAR:expr = new IntConstNode(lc->intValue() >> rc->intValue()); break;
}
delete this;
return expr;
@@ -363,7 +363,7 @@ TNode *BinExprNode::translate(Codegen *g) {
case AND:n = IR_AND; break; case OR:n = IR_OR; break; case XOR:n = IR_XOR; break;
case SHL:n = IR_SHL; break; case SHR:n = IR_SHR; break; case SAR:n = IR_SAR; break;
}
return d_new TNode(n, l, r);
return new TNode(n, l, r);
}
///////////////////////////
@@ -397,23 +397,23 @@ ExprNode *ArithExprNode::semant(Environ *e) {
if (lc && rc) {
ExprNode *expr = nullptr;
if (sem_type == Type::string_type) {
expr = d_new StringConstNode(lc->stringValue() + rc->stringValue());
expr = new StringConstNode(lc->stringValue() + rc->stringValue());
} else if (sem_type == Type::int_type) {
switch (op) {
case '+':expr = d_new IntConstNode(lc->intValue() + rc->intValue()); break;
case '-':expr = d_new IntConstNode(lc->intValue() - rc->intValue()); break;
case '*':expr = d_new IntConstNode(lc->intValue()*rc->intValue()); break;
case '/':expr = d_new IntConstNode(lc->intValue() / rc->intValue()); break;
case MOD:expr = d_new IntConstNode(lc->intValue() % rc->intValue()); break;
case '+':expr = new IntConstNode(lc->intValue() + rc->intValue()); break;
case '-':expr = new IntConstNode(lc->intValue() - rc->intValue()); break;
case '*':expr = new IntConstNode(lc->intValue()*rc->intValue()); break;
case '/':expr = new IntConstNode(lc->intValue() / rc->intValue()); break;
case MOD:expr = new IntConstNode(lc->intValue() % rc->intValue()); break;
}
} else {
switch (op) {
case '+':expr = d_new FloatConstNode(lc->floatValue() + rc->floatValue()); break;
case '-':expr = d_new FloatConstNode(lc->floatValue() - rc->floatValue()); break;
case '*':expr = d_new FloatConstNode(lc->floatValue()*rc->floatValue()); break;
case '/':expr = d_new FloatConstNode(lc->floatValue() / rc->floatValue()); break;
case MOD:expr = d_new FloatConstNode(fmod(lc->floatValue(), rc->floatValue())); break;
case '^':expr = d_new FloatConstNode(pow(lc->floatValue(), rc->floatValue())); break;
case '+':expr = new FloatConstNode(lc->floatValue() + rc->floatValue()); break;
case '-':expr = new FloatConstNode(lc->floatValue() - rc->floatValue()); break;
case '*':expr = new FloatConstNode(lc->floatValue()*rc->floatValue()); break;
case '/':expr = new FloatConstNode(lc->floatValue() / rc->floatValue()); break;
case MOD:expr = new FloatConstNode(fmod(lc->floatValue(), rc->floatValue())); break;
case '^':expr = new FloatConstNode(pow(lc->floatValue(), rc->floatValue())); break;
}
}
delete this;
@@ -443,7 +443,7 @@ TNode *ArithExprNode::translate(Codegen *g) {
case '^':return fcall("__bbFPow", l, r);
}
}
return d_new TNode(n, l, r);
return new TNode(n, l, r);
}
/////////////////////////
@@ -470,30 +470,30 @@ ExprNode *RelExprNode::semant(Environ *e) {
ExprNode *expr = nullptr;
if (opType == Type::string_type) {
switch (op) {
case '<':expr = d_new IntConstNode(lc->stringValue() < rc->stringValue()); break;
case '=':expr = d_new IntConstNode(lc->stringValue() == rc->stringValue()); break;
case '>':expr = d_new IntConstNode(lc->stringValue() > rc->stringValue()); break;
case LE: expr = d_new IntConstNode(lc->stringValue() <= rc->stringValue()); break;
case NE: expr = d_new IntConstNode(lc->stringValue() != rc->stringValue()); break;
case GE: expr = d_new IntConstNode(lc->stringValue() >= rc->stringValue()); break;
case '<':expr = new IntConstNode(lc->stringValue() < rc->stringValue()); break;
case '=':expr = new IntConstNode(lc->stringValue() == rc->stringValue()); break;
case '>':expr = new IntConstNode(lc->stringValue() > rc->stringValue()); break;
case LE: expr = new IntConstNode(lc->stringValue() <= rc->stringValue()); break;
case NE: expr = new IntConstNode(lc->stringValue() != rc->stringValue()); break;
case GE: expr = new IntConstNode(lc->stringValue() >= rc->stringValue()); break;
}
} else if (opType == Type::float_type) {
switch (op) {
case '<':expr = d_new IntConstNode(lc->floatValue() < rc->floatValue()); break;
case '=':expr = d_new IntConstNode(lc->floatValue() == rc->floatValue()); break;
case '>':expr = d_new IntConstNode(lc->floatValue() > rc->floatValue()); break;
case LE: expr = d_new IntConstNode(lc->floatValue() <= rc->floatValue()); break;
case NE: expr = d_new IntConstNode(lc->floatValue() != rc->floatValue()); break;
case GE: expr = d_new IntConstNode(lc->floatValue() >= rc->floatValue()); break;
case '<':expr = new IntConstNode(lc->floatValue() < rc->floatValue()); break;
case '=':expr = new IntConstNode(lc->floatValue() == rc->floatValue()); break;
case '>':expr = new IntConstNode(lc->floatValue() > rc->floatValue()); break;
case LE: expr = new IntConstNode(lc->floatValue() <= rc->floatValue()); break;
case NE: expr = new IntConstNode(lc->floatValue() != rc->floatValue()); break;
case GE: expr = new IntConstNode(lc->floatValue() >= rc->floatValue()); break;
}
} else {
switch (op) {
case '<':expr = d_new IntConstNode(lc->intValue() < rc->intValue()); break;
case '=':expr = d_new IntConstNode(lc->intValue() == rc->intValue()); break;
case '>':expr = d_new IntConstNode(lc->intValue() > rc->intValue()); break;
case LE: expr = d_new IntConstNode(lc->intValue() <= rc->intValue()); break;
case NE: expr = d_new IntConstNode(lc->intValue() != rc->intValue()); break;
case GE: expr = d_new IntConstNode(lc->intValue() >= rc->intValue()); break;
case '<':expr = new IntConstNode(lc->intValue() < rc->intValue()); break;
case '=':expr = new IntConstNode(lc->intValue() == rc->intValue()); break;
case '>':expr = new IntConstNode(lc->intValue() > rc->intValue()); break;
case LE: expr = new IntConstNode(lc->intValue() <= rc->intValue()); break;
case NE: expr = new IntConstNode(lc->intValue() != rc->intValue()); break;
case GE: expr = new IntConstNode(lc->intValue() >= rc->intValue()); break;
}
}
delete this;
@@ -591,7 +591,7 @@ ExprNode *NullNode::semant(Environ *e) {
}
TNode *NullNode::translate(Codegen *g) {
return d_new TNode(IR_CONST, 0, 0, 0);
return new TNode(IR_CONST, 0, 0, 0);
}
/////////////////