summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/chillAST/chillAST_def.hh2
-rw-r--r--include/chillAST/chillAST_node.hh14
-rw-r--r--include/chillAST/chillASTs.hh20
-rw-r--r--include/printer.h202
-rw-r--r--include/printer/cfamily.h (renamed from include/printers/cfamily.h)2
-rw-r--r--include/printer/dump.h65
-rw-r--r--include/printer/generic.h125
-rw-r--r--include/printers/dump.h62
8 files changed, 196 insertions, 296 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh
index 665f7ff..f336e14 100644
--- a/include/chillAST/chillAST_def.hh
+++ b/include/chillAST/chillAST_def.hh
@@ -14,7 +14,7 @@
#include <assert.h>
#include <vector> // std::vector
-#include <ir_enums.hh> // for IR_CONDITION_*
+#include <ir_enums.hh> // for IR_CONDITION_*
enum CHILLAST_NODE_TYPE {
CHILLAST_NODE_UNKNOWN = 0,
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
index 2c4ee8d..80f1be4 100644
--- a/include/chillAST/chillAST_node.hh
+++ b/include/chillAST/chillAST_node.hh
@@ -4,12 +4,10 @@
#define _CHILLAST_NODE_H_
#include "chillAST_def.hh"
-#include "printer.h"
//! generic node of the actual chillAST, a multiway tree node.
class chillAST_Node {
public:
- friend class chill::printer::GenericPrinter;
// TODO decide how to hide some data
//! this Node's parent
chillAST_Node *parent;
@@ -121,8 +119,6 @@ public:
bool isCudaSYNCTHREADS() { return (getType() == CHILLAST_NODE_CUDASYNCTHREADS); };
- bool isDeclStmt() { return (getType() == CHILLAST_NODE_DECLSTMT); }; // doesn't exist
-
bool isConstant() {
return (getType() == CHILLAST_NODE_INTEGERLITERAL) || (getType() == CHILLAST_NODE_FLOATINGLITERAL);
}
@@ -168,7 +164,7 @@ public:
int getNumChildren() { return children.size(); };
- chillAST_NodeList& getChildren() { return children; }; // not usually useful
+ chillAST_NodeList* getChildren() { return &children; }; // not usually useful
void setChildren(chillAST_NodeList &c) { children = c; }; // does not set parent. probably should
chillAST_Node *getChild(int which) { return children[which]; };
@@ -406,12 +402,6 @@ public:
exit(-1);;
};
- //! Print AST
- virtual void dump(int indent = 0, FILE *fp = stderr) {
- fflush(fp);
- CHILL_ERROR("(%s) forgot to implement dump()\n", getTypeString());
- };// print ast
-
// TODO We might want to print the code a bit differently, This can be only a generic dump
//! Print CODE
virtual void print(int indent = 0, FILE *fp = stderr) {
@@ -546,6 +536,8 @@ public:
virtual chillAST_VarDecl* getParameter(const char * name);
virtual void addParameter(chillAST_VarDecl* name);
+ void dump(int indent=0,FILE *fp = stderr);
+
};
diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh
index d61d183..7e32a3a 100644
--- a/include/chillAST/chillASTs.hh
+++ b/include/chillAST/chillASTs.hh
@@ -166,8 +166,6 @@ public:
chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart);
- void dump(int indent = 0, FILE *fp = stderr);
-
void print(int indent = 0, FILE *fp = stderr);
void printName(int indent = 0, FILE *fp = stderr);
@@ -294,8 +292,6 @@ public:
// required methods
void replaceChild(chillAST_Node *old, chillAST_Node *newchild);
- void dump(int indent = 0, FILE *fp = stderr);
-
void print(int indent = 0, FILE *fp = stderr);
chillAST_Node *constantFold();
@@ -374,7 +370,7 @@ public:
class chillAST_FunctionDecl : public chillAST_Node {
private:
- chillAST_CompoundStmt *body; // always a compound statement?
+ chillAST_CompoundStmt *body; // always a compound statement?
CHILLAST_FUNCTION_TYPE function_type; // CHILLAST_FUNCTION_CPU or CHILLAST_FUNCTION_GPU
bool externfunc; // function is external
bool builtin; // function is a builtin
@@ -456,7 +452,6 @@ public:
// constructors
chillAST_SourceFile(const char *filename); // defined in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
void printToFile(char *filename = NULL);
@@ -715,7 +710,6 @@ public:
// required methods that I can't seem to get to inherit
- void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
void printonly(int indent = 0, FILE *fp = stderr);
@@ -825,7 +819,6 @@ public:
// required methods that I can't seem to get to inherit
- void dump(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
void printonly(int indent = 0, FILE *fp = stderr);
@@ -903,7 +896,6 @@ public:
void printonly(int indent = 0, FILE *fp = stderr);
void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
char *stringRep(int indent = 0);
chillAST_Node *constantFold();
@@ -1022,7 +1014,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1080,7 +1071,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1126,7 +1116,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1222,7 +1211,6 @@ public:
void replaceChild(chillAST_Node *old, chillAST_Node *newchild);
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1266,7 +1254,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1348,7 +1335,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1477,7 +1463,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
//chillAST_Node* constantFold() {};
//chillAST_Node* clone();
//void gatherArrayRefs( std::vector<chillAST_ArraySubscriptExpr*> &refs, bool writtento ){};
@@ -1555,7 +1540,6 @@ public:
chillAST_Node *constantFold();
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
void gatherArrayRefs(std::vector<chillAST_ArraySubscriptExpr *> &refs, bool writtento);
void gatherScalarRefs(std::vector<chillAST_DeclRefExpr *> &refs, bool writtento);
@@ -1593,7 +1577,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1637,7 +1620,6 @@ public:
// required methods that I can't seem to get to inherit
void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
- void dump(int indent = 0, FILE *fp = stderr); // print ast in chill_ast.cc
chillAST_Node *constantFold();
chillAST_Node *clone();
diff --git a/include/printer.h b/include/printer.h
deleted file mode 100644
index 5930768..0000000
--- a/include/printer.h
+++ /dev/null
@@ -1,202 +0,0 @@
-//
-// Created by ztuowen on 9/24/16.
-//
-
-#ifndef CHILL_PRINTER_H_H
-#define CHILL_PRINTER_H_H
-
-#include "chillAST.h"
-#include "chillAST/chillAST_node.hh"
-#include <string>
-#include <sstream>
-
-/*!
- * \file
- * \brief this is a generic AST printer that prints the code out to a C-family like syntax
- */
-namespace chill {
- namespace printer {
- class GenericPrinter {
- private:
- std::string indentSpace;
- public:
- GenericPrinter() { indentSpace = " "; }
-
- void setIndentSpace(int numspaces) {
- indentSpace = "";
- for (int i = 0; i < numspaces; ++i)
- indentSpace += " ";
- }
- //! return the Precedence of the corresponding AST node
- /*!
- * @param n the chillAST_Node
- * @return a int representing the subnodes's precedence, 0 being the highest, INT8_MAX being the default
- */
- virtual int getPrec(chillAST_Node *n) { return INT8_MAX; }
- virtual void print(std::string ident, chillAST_ArraySubscriptExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_BinaryOperator *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CallExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CompoundStmt *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CStyleAddressOf *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CStyleCastExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CudaFree *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CudaKernelCall *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CudaMalloc *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CudaMemcpy *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_CudaSyncthreads *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_DeclRefExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_FloatingLiteral *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_ForStmt *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_Free *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_FunctionDecl *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_IfStmt *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_IntegerLiteral *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_ImplicitCastExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_MacroDefinition *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_Malloc *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_MemberExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_NULL *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_NoOp *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_ParenExpr *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_Preprocessing *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_RecordDecl *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_ReturnStmt *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_Sizeof *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_SourceFile *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_TypedefDecl *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_TernaryOperator *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_UnaryOperator *n, std::ostringstream &o)=0;
- virtual void print(std::string ident, chillAST_VarDecl *n, std::ostringstream &o)=0;
- //! Print the AST to string stream
- /*!
- * @param ident indentation of the node
- * @param n the chillAST_Node
- * @param o the string stream
- */
- virtual void print(std::string ident, chillAST_Node *n, std::ostringstream &o){
- switch (n->getType()) {
- case CHILLAST_NODE_ARRAYSUBSCRIPTEXPR:
- print(ident, dynamic_cast<chillAST_ArraySubscriptExpr*>(n),o);
- break;
- case CHILLAST_NODE_BINARYOPERATOR:
- print(ident, dynamic_cast<chillAST_BinaryOperator*>(n),o);
- break;
- case CHILLAST_NODE_CALLEXPR:
- print(ident, dynamic_cast<chillAST_CallExpr*>(n),o);
- break;
- case CHILLAST_NODE_COMPOUNDSTMT:
- print(ident, dynamic_cast<chillAST_CompoundStmt*>(n),o);
- break;
- case CHILLAST_NODE_CSTYLEADDRESSOF:
- print(ident, dynamic_cast<chillAST_CStyleAddressOf*>(n),o);
- break;
- case CHILLAST_NODE_CSTYLECASTEXPR:
- print(ident, dynamic_cast<chillAST_CStyleCastExpr*>(n),o);
- break;
- case CHILLAST_NODE_CUDAFREE:
- print(ident, dynamic_cast<chillAST_CudaFree*>(n),o);
- break;
- case CHILLAST_NODE_CUDAKERNELCALL:
- print(ident, dynamic_cast<chillAST_CudaKernelCall*>(n),o);
- break;
- case CHILLAST_NODE_CUDAMALLOC:
- print(ident, dynamic_cast<chillAST_CudaMalloc*>(n),o);
- break;
- case CHILLAST_NODE_CUDAMEMCPY:
- print(ident, dynamic_cast<chillAST_CudaMemcpy*>(n),o);
- break;
- case CHILLAST_NODE_CUDASYNCTHREADS:
- print(ident, dynamic_cast<chillAST_CudaSyncthreads*>(n),o);
- break;
- case CHILLAST_NODE_DECLREFEXPR:
- print(ident, dynamic_cast<chillAST_DeclRefExpr*>(n),o);
- break;
- case CHILLAST_NODE_FLOATINGLITERAL:
- print(ident, dynamic_cast<chillAST_FloatingLiteral*>(n),o);
- break;
- case CHILLAST_NODE_LOOP:
- case CHILLAST_NODE_FORSTMT:
- print(ident, dynamic_cast<chillAST_ForStmt*>(n),o);
- break;
- case CHILLAST_NODE_FREE:
- print(ident, dynamic_cast<chillAST_Free*>(n),o);
- break;
- case CHILLAST_NODE_FUNCTIONDECL:
- print(ident, dynamic_cast<chillAST_FunctionDecl*>(n),o);
- break;
- case CHILLAST_NODE_IFSTMT:
- print(ident, dynamic_cast<chillAST_IfStmt*>(n),o);
- break;
- case CHILLAST_NODE_IMPLICITCASTEXPR:
- print(ident, dynamic_cast<chillAST_ImplicitCastExpr*>(n),o);
- break;
- case CHILLAST_NODE_INTEGERLITERAL:
- print(ident, dynamic_cast<chillAST_IntegerLiteral*>(n),o);
- break;
- case CHILLAST_NODE_MACRODEFINITION:
- print(ident, dynamic_cast<chillAST_MacroDefinition*>(n),o);
- break;
- case CHILLAST_NODE_MALLOC:
- print(ident, dynamic_cast<chillAST_Malloc*>(n),o);
- break;
- case CHILLAST_NODE_MEMBEREXPR:
- print(ident, dynamic_cast<chillAST_MemberExpr*>(n),o);
- break;
- case CHILLAST_NODE_NOOP:
- print(ident, dynamic_cast<chillAST_NoOp*>(n),o);
- break;
- case CHILLAST_NODE_NULL:
- print(ident, dynamic_cast<chillAST_NULL*>(n),o);
- break;
- case CHILLAST_NODE_PARENEXPR:
- print(ident, dynamic_cast<chillAST_ParenExpr*>(n),o);
- break;
- case CHILLAST_NODE_PREPROCESSING:
- print(ident, dynamic_cast<chillAST_Preprocessing*>(n),o);
- break;
- case CHILLAST_NODE_RECORDDECL:
- print(ident, dynamic_cast<chillAST_RecordDecl*>(n),o);
- break;
- case CHILLAST_NODE_RETURNSTMT:
- print(ident, dynamic_cast<chillAST_ReturnStmt*>(n),o);
- break;
- case CHILLAST_NODE_SIZEOF:
- print(ident, dynamic_cast<chillAST_Sizeof*>(n),o);
- break;
- case CHILLAST_NODE_TRANSLATIONUNIT:
- case CHILLAST_NODE_SOURCEFILE:
- print(ident, dynamic_cast<chillAST_SourceFile*>(n),o);
- break;
- case CHILLAST_NODE_TERNARYOPERATOR:
- print(ident, dynamic_cast<chillAST_TernaryOperator*>(n),o);
- break;
- case CHILLAST_NODE_TYPEDEFDECL:
- print(ident, dynamic_cast<chillAST_TypedefDecl*>(n),o);
- break;
- case CHILLAST_NODE_UNARYOPERATOR:
- print(ident, dynamic_cast<chillAST_UnaryOperator*>(n),o);
- break;
- case CHILLAST_NODE_VARDECL:
- print(ident, dynamic_cast<chillAST_VarDecl*>(n),o);
- break;
- case CHILLAST_NODE_UNKNOWN:
- default:
- CHILL_ERROR("Printing an unknown type of Node: %s\n", n->getTypeString());
- }
- }
- //! Print the AST to string, overload the print function
- /*!
- * @param ident indentation of the node
- * @param n the chillAST_Node
- * @return a string of the corresponding code
- */
- virtual std::string print(std::string ident, chillAST_Node *n) {
- std::ostringstream os;
- print(ident, n, os);
- return os.str();
- }
- };
- }
-}
-
-#endif //CHILL_PRINTER_H_H
diff --git a/include/printers/cfamily.h b/include/printer/cfamily.h
index e979db7..b36a873 100644
--- a/include/printers/cfamily.h
+++ b/include/printer/cfamily.h
@@ -5,7 +5,7 @@
#ifndef CHILL_CFAMILY_H
#define CHILL_CFAMILY_H
-#include "printer.h"
+#include "printer/generic.h"
/*!
* \file
diff --git a/include/printer/dump.h b/include/printer/dump.h
new file mode 100644
index 0000000..bf7168b
--- /dev/null
+++ b/include/printer/dump.h
@@ -0,0 +1,65 @@
+//
+// Created by ztuowen on 9/24/16.
+//
+
+#ifndef CHILL_DUMP_H
+#define CHILL_DUMP_H
+
+#include "printer/generic.h"
+
+/*!
+ * \file
+ * \brief this replace the old dump function in the chillAST
+ */
+
+namespace chill {
+ namespace printer {
+ class Dump : public GenericPrinter {
+ public:
+ Dump() {}
+ 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);
+ /*!
+ * Just prints everything. Indent is igored due to need to limit the number of output
+ * @param ident
+ * @param n
+ * @param o
+ */
+ virtual void print(std::string ident, chillAST_Node *n, std::ostream &o);
+ };
+ }
+}
+
+#endif //CHILL_DUMP_H
diff --git a/include/printer/generic.h b/include/printer/generic.h
new file mode 100644
index 0000000..f3fd8f2
--- /dev/null
+++ b/include/printer/generic.h
@@ -0,0 +1,125 @@
+//
+// Created by ztuowen on 9/24/16.
+//
+
+#ifndef CHILL_PRINTER_H_H
+#define CHILL_PRINTER_H_H
+
+#include "chillAST.h"
+#include <string>
+#include <sstream>
+
+/*!
+ * \file
+ * \brief this is a generic AST printSer that printSs the code out to a C-family like syntax
+ */
+namespace chill {
+ namespace printer {
+ class GenericPrinter {
+ private:
+ std::string indentSpace;
+ public:
+ GenericPrinter() { indentSpace = " "; }
+
+ void setIndentSpace(int numspaces) {
+ indentSpace = "";
+ for (int i = 0; i < numspaces; ++i)
+ indentSpace += " ";
+ }
+ virtual int getPrecS(chillAST_ArraySubscriptExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_BinaryOperator *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CallExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CompoundStmt *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CStyleAddressOf *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CStyleCastExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CudaFree *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CudaKernelCall *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CudaMalloc *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CudaMemcpy *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_CudaSyncthreads *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_DeclRefExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_FloatingLiteral *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_ForStmt *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_Free *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_FunctionDecl *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_IfStmt *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_IntegerLiteral *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_ImplicitCastExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_MacroDefinition *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_Malloc *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_MemberExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_NULL *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_NoOp *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_ParenExpr *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_Preprocessing *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_RecordDecl *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_ReturnStmt *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_Sizeof *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_SourceFile *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_TypedefDecl *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_TernaryOperator *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_UnaryOperator *n) { return INT8_MAX; }
+ virtual int getPrecS(chillAST_VarDecl *n) { return INT8_MAX; }
+ //! return the Precedence of the corresponding AST node
+ /*!
+ * @param n the chillAST_Node
+ * @return a int representing the subnodes's precedence, 0 being the highest, INT8_MAX being the default
+ */
+ virtual int getPrec(chillAST_Node *n);
+ virtual void printS(std::string ident, chillAST_ArraySubscriptExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_BinaryOperator *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CallExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CompoundStmt *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CStyleAddressOf *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CStyleCastExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CudaFree *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CudaKernelCall *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CudaMalloc *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CudaMemcpy *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_CudaSyncthreads *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_DeclRefExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_FloatingLiteral *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_ForStmt *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_Free *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_FunctionDecl *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_IfStmt *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_IntegerLiteral *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_ImplicitCastExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_MacroDefinition *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_Malloc *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_MemberExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_NULL *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_NoOp *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_ParenExpr *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_Preprocessing *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_RecordDecl *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_ReturnStmt *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_Sizeof *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_SourceFile *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_TypedefDecl *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_TernaryOperator *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_UnaryOperator *n, std::ostream &o)=0;
+ virtual void printS(std::string ident, chillAST_VarDecl *n, std::ostream &o)=0;
+ //! Print the AST to string stream, multiplexer
+ /*!
+ * @param ident indentation of the node
+ * @param n the chillAST_Node
+ * @param o the string stream
+ */
+ virtual void print(std::string ident, chillAST_Node *n, std::ostream &o);
+ //! Print the AST to string, overload the printS function
+ /*!
+ * @param ident indentation of the node
+ * @param n the chillAST_Node
+ * @return a string of the corresponding code
+ */
+ virtual std::string print(std::string ident, chillAST_Node *n) {
+ std::ostringstream os;
+ print(ident, n, os);
+ return os.str();
+ }
+ };
+ }
+}
+
+#endif //CHILL_PRINTER_H_H
diff --git a/include/printers/dump.h b/include/printers/dump.h
deleted file mode 100644
index 285de8e..0000000
--- a/include/printers/dump.h
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-// Created by ztuowen on 9/24/16.
-//
-
-#ifndef CHILL_DUMP_H
-#define CHILL_DUMP_H
-/*!
- * \file
- * \brief this replace the old dump function in the chillAST
- */
-
-namespace chill {
- namespace printer{
- class Dump : public GenericPrinter {
- public:
- Dump() {}
- 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_IfStmt *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_IntegerLiteral *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_NULL *n, std::ostringstream &o);
- virtual void print(std::string ident, chillAST_NoOp *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);
- /*!
- * Just prints everything. Indent is igored due to need to limit the number of output
- * @param ident
- * @param n
- * @param o
- */
- virtual void print(string ident, chillAST_Node *n, ostringStream &o);
- };
- }
-}
-
-#endif //CHILL_DUMP_H