diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/chillASTs.cc | 70 | ||||
-rwxr-xr-x | src/ir_clang.cc | 2 | ||||
-rw-r--r-- | src/printer/cfamily.cpp | 2 | ||||
-rw-r--r-- | src/printer/dump.cpp | 2 |
4 files changed, 22 insertions, 54 deletions
diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 2f57197..edbe221 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -2070,45 +2070,43 @@ chillAST_Node *chillAST_FloatingLiteral::clone() { return newone; } -chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub) { +chillAST_UnaryOperator::chillAST_UnaryOperator() { + children.push_back(NULL); +} + +chillAST_UnaryOperator::chillAST_UnaryOperator(const char *oper, bool pre, chillAST_Node *sub):chillAST_UnaryOperator() { op = strdup(oper); prefix = pre; - subexpr = sub; - subexpr->setParent(this); + setSubExpr(sub); isFromSourceFile = true; // default filename = NULL; } void chillAST_UnaryOperator::gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool w) { - subexpr->gatherArrayRefs(refs, isAssignmentOp()); // + getSubExpr()->gatherArrayRefs(refs, isAssignmentOp()); // } void chillAST_UnaryOperator::gatherVarLHSUsage(vector<chillAST_VarDecl *> &decls) { - if ((!strcmp("++", op)) || (!strcmp("--", op))) { - subexpr->gatherVarUsage(decls); // do all unary modify the subexpr? (no, - ) + if (isAssignmentOp()) { + getSubExpr()->gatherVarUsage(decls); // do all unary modify the subexpr? (no, - ) } } chillAST_Node *chillAST_UnaryOperator::constantFold() { - //fprintf(stderr, "chillAST_UnaryOperator::constantFold() "); - //print(); fprintf(stderr, "\n"); + chillAST_Node::constantFold(); - subexpr = subexpr->constantFold(); chillAST_Node *returnval = this; - if (subexpr->isConstant()) { - //fprintf(stderr, "unary op folding constants\n"); - //print(0,stderr); fprintf(stderr, "\n"); - + if (getSubExpr()->isConstant()) { if (streq(op, "-")) { - if (subexpr->isIntegerLiteral()) { - int intval = ((chillAST_IntegerLiteral *) subexpr)->value; + if (getSubExpr()->isIntegerLiteral()) { + int intval = ((chillAST_IntegerLiteral *) getSubExpr())->value; chillAST_IntegerLiteral *I = new chillAST_IntegerLiteral(-intval); I->setParent(parent); returnval = I; //fprintf(stderr, "integer -%d becomes %d\n", intval, I->value); } else { - chillAST_FloatingLiteral *FL = (chillAST_FloatingLiteral *) subexpr; + chillAST_FloatingLiteral *FL = (chillAST_FloatingLiteral *) getSubExpr(); chillAST_FloatingLiteral *F = new chillAST_FloatingLiteral(FL); // clone F->parent = FL->parent; @@ -2125,48 +2123,18 @@ chillAST_Node *chillAST_UnaryOperator::constantFold() { class chillAST_Node *chillAST_UnaryOperator::clone() { - chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, subexpr->clone()); + chillAST_UnaryOperator *UO = new chillAST_UnaryOperator(op, prefix, getSubExpr()->clone()); UO->setParent(parent); UO->isFromSourceFile = isFromSourceFile; if (filename) UO->filename = strdup(filename); return UO; } - -void chillAST_UnaryOperator::gatherVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherVarDecls(decls); -} - - -void chillAST_UnaryOperator::gatherScalarVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherScalarVarDecls(decls); -} - - -void chillAST_UnaryOperator::gatherArrayVarDecls(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherArrayVarDecls(decls); -} - - -void chillAST_UnaryOperator::gatherDeclRefExprs(vector<chillAST_DeclRefExpr *> &refs) { - subexpr->gatherDeclRefExprs(refs); -} - - -void chillAST_UnaryOperator::gatherVarUsage(vector<chillAST_VarDecl *> &decls) { - subexpr->gatherVarUsage(decls); -} - -void chillAST_UnaryOperator::replaceVarDecls(chillAST_VarDecl *olddecl, chillAST_VarDecl *newdecl) { - subexpr->replaceVarDecls(olddecl, newdecl); -} - - int chillAST_UnaryOperator::evalAsInt() { - if (!strcmp("+", op)) return subexpr->evalAsInt(); - if (!strcmp("-", op)) return -subexpr->evalAsInt(); - if (!strcmp("++", op)) return 1 + subexpr->evalAsInt(); - if (!strcmp("--", op)) return subexpr->evalAsInt() - 1; + if (!strcmp("+", op)) return getSubExpr()->evalAsInt(); + if (!strcmp("-", op)) return -getSubExpr()->evalAsInt(); + if (!strcmp("++", op)) return 1 + getSubExpr()->evalAsInt(); + if (!strcmp("--", op)) return getSubExpr()->evalAsInt() - 1; fprintf(stderr, "chillAST_UnaryOperator::evalAsInt() unhandled op '%s'\n", op); exit(-1); diff --git a/src/ir_clang.cc b/src/ir_clang.cc index b5634af..cb4cbb8 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -3085,7 +3085,7 @@ std::vector<omega::CG_outputRepr *> IR_clangCode::QueryExpOperand(const omega::C chillAST_UnaryOperator *uop = (chillAST_UnaryOperator *) e; char *op = uop->op; // TODO enum if (!strcmp(op, "+") || !strcmp(op, "-")) { - v.push_back(new omega::CG_chillRepr(uop->subexpr)); + v.push_back(new omega::CG_chillRepr(uop->getSubExpr())); } else { CHILL_ERROR("ir_clang.cc IR_clangCode::QueryExpOperand() Unary Operator UNHANDLED op (%s)\n", op); exit(-1); diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp index 8aa6e62..5c56bd7 100644 --- a/src/printer/cfamily.cpp +++ b/src/printer/cfamily.cpp @@ -373,7 +373,7 @@ int CFamily::getPrecS(chillAST_UnaryOperator *n) { void CFamily::printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o) { int prec = getPrec(n); if (n->prefix) o << n->op; - printPrec(ident, n->subexpr, o, prec); + printPrec(ident, n->getSubExpr(), o, prec); if (!n->prefix) o << n->op; } diff --git a/src/printer/dump.cpp b/src/printer/dump.cpp index 066a2fe..059e56f 100644 --- a/src/printer/dump.cpp +++ b/src/printer/dump.cpp @@ -217,7 +217,7 @@ void Dump::printS(std::string ident, chillAST_TernaryOperator *n, std::ostream & void Dump::printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o) { if (n->prefix) o << "prefix "; else o << "postfix "; - print(ident, n->subexpr, o); + print(ident, n->getSubExpr(), o); } void Dump::printS(std::string ident, chillAST_VarDecl *n, std::ostream &o) { |