diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-25 11:06:42 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-25 11:06:42 -0600 |
commit | 2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1 (patch) | |
tree | 51e83cb14c9ba846ff5e2b8dd6c017e9b57dea75 /include/printer/generic.h | |
parent | 51c4aaaa21a124abafe3f950e12c3c25ddbe0812 (diff) | |
download | chill-2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1.tar.gz chill-2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1.tar.bz2 chill-2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1.zip |
staging
Diffstat (limited to 'include/printer/generic.h')
-rw-r--r-- | include/printer/generic.h | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/include/printer/generic.h b/include/printer/generic.h index f3fd8f2..70ebb41 100644 --- a/include/printer/generic.h +++ b/include/printer/generic.h @@ -11,20 +11,25 @@ /*! * \file - * \brief this is a generic AST printSer that printSs the code out to a C-family like syntax + * \brief this is a generic AST printSer that prints the code out to a C-family like syntax */ namespace chill { namespace printer { class GenericPrinter { private: - std::string indentSpace; + std::string identSpace; public: - GenericPrinter() { indentSpace = " "; } - + GenericPrinter() { identSpace = " "; } + //! Set the indentation for print + /*! + * Some subclass has indentation unused, like Dump. Also, only spaces is supported, + * so it is a number of the spaces in the indentaion. + * @param numspaces number of spaces for the indentation + */ void setIndentSpace(int numspaces) { - indentSpace = ""; + identSpace = ""; for (int i = 0; i < numspaces; ++i) - indentSpace += " "; + identSpace += " "; } virtual int getPrecS(chillAST_ArraySubscriptExpr *n) { return INT8_MAX; } virtual int getPrecS(chillAST_BinaryOperator *n) { return INT8_MAX; } @@ -118,6 +123,28 @@ namespace chill { print(ident, n, os); return os.str(); } + //! Print the AST to stdout + /*! + * @param ident indentation of the node, the one inherited from the parent + * @param n the chillAST_Node + */ + virtual void printOut(std::string ident, chillAST_Node *n) { + print(ident,n,std::cout); + } + //! Print the AST to stdErr + /*! + * @param ident indentation of the node + * @param n the chillAST_Node + */ + virtual void printErr(std::string ident, chillAST_Node *n) { + print(ident,n,std::cerr); + } + //! Print the subexpression with precedence + virtual void printPrec(std::string ident,chillAST_Node *n,std::ostream &o, int prec) { + if (getPrec(n) > prec) o<<"("; + print(ident,n,prec); + if (getPrec(n) > prec) o<<")"; + } }; } } |