summaryrefslogtreecommitdiff
path: root/include/printer
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-09-25 11:06:42 -0600
committerTuowen Zhao <ztuowen@gmail.com>2016-09-25 11:06:42 -0600
commit2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1 (patch)
tree51e83cb14c9ba846ff5e2b8dd6c017e9b57dea75 /include/printer
parent51c4aaaa21a124abafe3f950e12c3c25ddbe0812 (diff)
downloadchill-2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1.tar.gz
chill-2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1.tar.bz2
chill-2a5618583e1fdc8cde0308d3e5b1873bc94c5fb1.zip
staging
Diffstat (limited to 'include/printer')
-rw-r--r--include/printer/cfamily.h71
-rw-r--r--include/printer/dump.h10
-rw-r--r--include/printer/generic.h39
3 files changed, 77 insertions, 43 deletions
diff --git a/include/printer/cfamily.h b/include/printer/cfamily.h
index b36a873..f6e2284 100644
--- a/include/printer/cfamily.h
+++ b/include/printer/cfamily.h
@@ -9,46 +9,53 @@
/*!
* \file
- * \brief Print the AST for C like syntax, This replace the old print function
*/
namespace chill {
namespace printer{
+ /*!
+ * \brief Print the AST for C like syntax, This replace the old print function
+ * Custom multiplexer should not be needed. This version should calculate the correct precedence for expressions.
+ * Expression should be encapsulated in {} or () or ended with ; with heuristics at the parent node
+ */
class CFamily : public GenericPrinter {
public:
CFamily() {}
virtual int getPrec(chillAST_Node *n);
- virtual void print(std::string ident, chillAST_ArraySubscriptExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_BinaryOperator *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CallExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CompoundStmt *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CStyleAddressOf *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CStyleCastExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CudaFree *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CudaKernelCall *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CudaMalloc *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CudaMemcpy *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_CudaSyncthreads *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_DeclRefExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_FloatingLiteral *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_ForStmt *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_Free *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_FunctionDecl *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_ImplicitCastExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_MacroDefinition *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_Malloc *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_MemberExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_ParenExpr *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_Preprocessing *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_RecordDecl *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_ReturnStmt *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_Sizeof *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_SourceFile *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_TypedefDecl *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_TernaryOperator *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_UnaryOperator *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_VarDecl *n, std::ostringstream &o);
- virtual void print(string ident, chillAST_Node *n, ostringStream &o);
+ virtual void printS(std::string ident, chillAST_ArraySubscriptExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_BinaryOperator *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CallExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CompoundStmt *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CStyleAddressOf *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CStyleCastExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CudaFree *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CudaKernelCall *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CudaMalloc *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CudaMemcpy *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_CudaSyncthreads *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_DeclRefExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_FloatingLiteral *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_ForStmt *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_Free *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_FunctionDecl *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_IfStmt *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_IntegerLiteral *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_ImplicitCastExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_MacroDefinition *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_Malloc *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_MemberExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_NULL *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_NoOp *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_ParenExpr *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_Preprocessing *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_RecordDecl *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_ReturnStmt *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_Sizeof *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_SourceFile *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_TypedefDecl *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_TernaryOperator *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o);
+ virtual void printS(std::string ident, chillAST_VarDecl *n, std::ostream &o);
};
}
}
diff --git a/include/printer/dump.h b/include/printer/dump.h
index bf7168b..dd8a0e8 100644
--- a/include/printer/dump.h
+++ b/include/printer/dump.h
@@ -7,13 +7,13 @@
#include "printer/generic.h"
-/*!
- * \file
- * \brief this replace the old dump function in the chillAST
- */
-
namespace chill {
namespace printer {
+ /*!
+ * \brief this replace the old dump function in the chillAST
+ *
+ * Everthing is written in a Tree-like structure: (<NodeName> <Params>). No precedence calculation is needed.
+ */
class Dump : public GenericPrinter {
public:
Dump() {}
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<<")";
+ }
};
}
}