diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-10-07 18:43:39 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-10-07 18:43:39 -0600 |
commit | 7bbd1a207f65428283471f1cc956f3fda43fbe3e (patch) | |
tree | f8febd1c59ad6aa5f071aa8644a4961b163cfb77 /src/printer | |
parent | 79866eaaf708759db9458e60bb4ea51799608f2e (diff) | |
download | chill-7bbd1a207f65428283471f1cc956f3fda43fbe3e.tar.gz chill-7bbd1a207f65428283471f1cc956f3fda43fbe3e.tar.bz2 chill-7bbd1a207f65428283471f1cc956f3fda43fbe3e.zip |
fixes
Diffstat (limited to 'src/printer')
-rw-r--r-- | src/printer/cfamily.cpp | 18 | ||||
-rw-r--r-- | src/printer/dump.cpp | 4 | ||||
-rw-r--r-- | src/printer/generic.cpp | 2 |
3 files changed, 13 insertions, 11 deletions
diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp index 488c884..c328c67 100644 --- a/src/printer/cfamily.cpp +++ b/src/printer/cfamily.cpp @@ -59,7 +59,7 @@ void CFamily::printS(std::string ident, chillAST_BinaryOperator *n, std::ostream if (n->getLHS()) printPrec(ident, n->getLHS(), o, prec); else o << "(NULL)"; o << " " << n->op << " "; - if (n->getRHS()) printPrec(ident, n->getRHS(), o, prec); + if (n->getRHS()) printPrec(ident, n->getRHS(), o, prec-1); else o << "(NULL)"; } @@ -83,32 +83,32 @@ void CFamily::printS(std::string ident, chillAST_CallExpr *n, std::ostream &o) { FD = (chillAST_FunctionDecl *) n->getCallee(); else if (n->getCallee()->isMacroDefinition()) MD = (chillAST_MacroDefinition *) n->getCallee(); - if (FD) { - o << FD->functionName; + if (MD && n->getNumChildren()-1) + o << "("; + else { + print(ident,n->getCallee(),o); if (n->grid && n->block) o << "<<<" << n->grid->varname << "," << n->block->varname << ">>>"; o << "("; } - if (MD && n->getNumChildren()-1) - o << "("; for (int i = 1; i < n->getNumChildren(); ++i) { - if (i != 0) o << ", "; + if (i != 1) o << ", "; print(ident, n->getChild(i), o); } - if (FD || n->getNumChildren()-1) + if (!MD || n->getNumChildren()-1) o << ")"; } void CFamily::printS(std::string ident, chillAST_CompoundStmt *n, std::ostream &o) { chillAST_NodeList *c = n->getChildren(); string nid = ident + identSpace; - if (c->size() > 1) o << "{"; + if (c->size() > 1 || n->getParent()->isFunctionDecl()) o << "{"; for (int i = 0; i < c->size(); ++i) { o << "\n" << nid; print(nid, c->at(i), o); if (!ifSemicolonFree(c->at(i)->getType())) o << ";"; } - if (c->size() > 1) o << "\n" << ident << "}"; + if (c->size() > 1 || n->getParent()->isFunctionDecl()) o << "\n" << ident << "}"; } int CFamily::getPrecS(chillAST_CStyleAddressOf *n) { diff --git a/src/printer/dump.cpp b/src/printer/dump.cpp index cd4c316..ca208ab 100644 --- a/src/printer/dump.cpp +++ b/src/printer/dump.cpp @@ -24,6 +24,7 @@ void dumpVector(GenericPrinter *p, string ident, chillAST_TypedefTable *n, ostre } void Dump::print(string ident, chillAST_Node *n, ostream &o) { + if (!n) return; o << "(" << n->getTypeString() << " "; if (n->getParameters()) { o << "(Params: "; @@ -70,8 +71,7 @@ void Dump::printS(std::string ident, chillAST_BinaryOperator *n, std::ostream &o } void Dump::printS(std::string ident, chillAST_CallExpr *n, std::ostream &o) { - if (n->getCallee()) - print(ident, n->getCallee(), o); + dumpVector(this,ident,n->getChildren(),o); } void Dump::printS(std::string ident, chillAST_CompoundStmt *n, std::ostream &o) { diff --git a/src/printer/generic.cpp b/src/printer/generic.cpp index 79ee312..dcd5498 100644 --- a/src/printer/generic.cpp +++ b/src/printer/generic.cpp @@ -7,6 +7,7 @@ using namespace chill::printer; void GenericPrinter::print(std::string ident, chillAST_Node *n, std::ostream &o) { + if (!n) return; switch (n->getType()) { case CHILLAST_NODE_ARRAYSUBSCRIPTEXPR: printS(ident, dynamic_cast<chillAST_ArraySubscriptExpr *>(n), o); @@ -120,6 +121,7 @@ void GenericPrinter::print(std::string ident, chillAST_Node *n, std::ostream &o) } int GenericPrinter::getPrec(chillAST_Node *n) { + if (!n) return defGetPrecS(); switch (n->getType()) { case CHILLAST_NODE_ARRAYSUBSCRIPTEXPR: return getPrecS(dynamic_cast<chillAST_ArraySubscriptExpr *>(n)); |