diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-24 17:13:14 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-24 17:13:14 -0600 |
commit | b05825a90c3e175db3e1a2172fe52d51badafc5e (patch) | |
tree | f4839a1345fb950929d0c35d9e322ad549b42b4e /include | |
parent | ad7c7e7fc853f9f67f92ad9d59f3a4f48454e7f2 (diff) | |
download | chill-b05825a90c3e175db3e1a2172fe52d51badafc5e.tar.gz chill-b05825a90c3e175db3e1a2172fe52d51badafc5e.tar.bz2 chill-b05825a90c3e175db3e1a2172fe52d51badafc5e.zip |
add generic printer
Diffstat (limited to 'include')
-rw-r--r-- | include/chillAST/chillAST_def.hh | 6 | ||||
-rw-r--r-- | include/chillAST/chillAST_node.hh | 47 | ||||
-rw-r--r-- | include/chillAST/chillASTs.hh | 41 | ||||
-rw-r--r-- | include/printer.h | 202 | ||||
-rw-r--r-- | include/printers/cfamily.h | 56 | ||||
-rw-r--r-- | include/printers/dump.h | 62 |
6 files changed, 339 insertions, 75 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh index 59a7f95..665f7ff 100644 --- a/include/chillAST/chillAST_def.hh +++ b/include/chillAST/chillAST_def.hh @@ -12,7 +12,7 @@ #include <string.h> #include <stdlib.h> #include <assert.h> -#include <vector> // std::vector +#include <vector> // std::vector #include <ir_enums.hh> // for IR_CONDITION_* @@ -40,7 +40,7 @@ enum CHILLAST_NODE_TYPE { CHILLAST_NODE_IMPLICITCASTEXPR, CHILLAST_NODE_RETURNSTMT, CHILLAST_NODE_CALLEXPR, - CHILLAST_NODE_DECLSTMT, + //CHILLAST_NODE_DECLSTMT, not used CHILLAST_NODE_PARENEXPR, CHILLAST_NODE_CSTYLECASTEXPR, CHILLAST_NODE_CSTYLEADDRESSOF, @@ -143,6 +143,8 @@ class chillAST_FloatingLiteral; class chillAST_ImplicitCastExpr; +class chillAST_IfStmt; + class chillAST_CStyleCastExpr; class chillAST_CStyleAddressOf; diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index 9788588..2c4ee8d 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -4,15 +4,19 @@ #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; //! this node's children the only entity that holds childs/subexpressions chillAST_NodeList children; + //! The parameters that this nodes accept, which every elements is in the scope, but they are not defined in children + chillAST_SymbolTable *parameters; //! Symbol Scoping chillAST_SymbolTable *symbolTable; //! typedef Scoping @@ -40,9 +44,12 @@ public: filename = NULL; symbolTable = NULL; typedefTable = NULL; + parameters = NULL; } //! the type of this current node virtual CHILLAST_NODE_TYPE getType() {return CHILLAST_NODE_UNKNOWN;}; + //! Get the human readable type name + const char *getTypeString() { return ChillAST_Node_Names[getType()]; }; //! the precedence of the current node, 0 being the highest virtual int getPrec() {return INT8_MAX;} @@ -434,14 +441,11 @@ public: virtual void getTopLevelLoops(std::vector<chillAST_ForStmt *> &loops) { int n = children.size(); - //fprintf(stderr, "get_top_level_loops of a %s with %d children\n", getTypeString(), n); for (int i = 0; i < n; i++) { - //fprintf(stderr, "child %d is a %s\n", i, children[i]->getTypeString()); if (children[i]->isForStmt()) { loops.push_back(((chillAST_ForStmt *) (children[i]))); } } - //fprintf(stderr, "found %d top level loops\n", loops.size()); } @@ -495,7 +499,6 @@ public: } - const char *getTypeString() { return ChillAST_Node_Names[getType()]; }; void setParent(chillAST_Node *p) { parent = p; }; @@ -505,42 +508,28 @@ public: chillAST_SourceFile *getSourceFile() { if (isSourceFile()) return ((chillAST_SourceFile *) this); if (parent != NULL) return parent->getSourceFile(); - fprintf(stderr, "UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", - this, this->getTypeString()); + CHILL_ERROR("UHOH, getSourceFile() called on node %p %s that does not have a parent and is not a source file\n", this, this->getTypeString()); this->print(); - printf("\n\n"); - fflush(stdout); exit(-1); } - void walk_parents() { - fprintf(stderr, "wp: (%s) ", getTypeString()); - print(); - printf("\n"); - fflush(stdout); - if (isSourceFile()) { - fprintf(stderr, "(top sourcefile)\n\n"); - return; - } - - if (parent) parent->walk_parents(); - else fprintf(stderr, "UHOH, %s has no parent??\n", getTypeString()); - return; - } - + // TODO DOC virtual chillAST_Node *getEnclosingStatement(int level = 0); + // TODO DOC virtual chillAST_VarDecl *multibase() { fprintf(stderr, "(%s) forgot to implement multibase()\n", getTypeString()); exit(-1); } + // TODO DOC virtual chillAST_Node *multibase2() { fprintf(stderr, "(%s) forgot to implement multibase2()\n", getTypeString()); exit(-1); } + //! Get a vector of statements virtual void gatherStatements(std::vector<chillAST_Node *> &statements) { fprintf(stderr, "(%s) forgot to implement gatherStatements()\n", getTypeString()); dump(); @@ -549,19 +538,13 @@ public: fprintf(stderr, "\n\n"); } - - virtual bool isSameAs(chillAST_Node *other) { // for tree comparison - fprintf(stderr, "(%s) forgot to implement isSameAs()\n", getTypeString()); - dump(); - fflush(stdout); - print(); - fprintf(stderr, "\n\n"); - } - void printPreprocBEFORE(int indent, FILE *fp); void printPreprocAFTER(int indent, FILE *fp); + virtual chillAST_SymbolTable* getParameters() {return parameters;} + virtual chillAST_VarDecl* getParameter(const char * name); + virtual void addParameter(chillAST_VarDecl* name); }; diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 5c9010c..d61d183 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -18,11 +18,6 @@ public: fflush(fp); } - void dump(int indent = 0, FILE *fp = stderr) { - chillindent(indent, fp); - fprintf(fp, "(NULL statement) "); - fflush(fp); - } }; class chillAST_Preprocessing : public chillAST_Node { @@ -96,10 +91,6 @@ public: return underlyingtype; }; - void dump(int indent = 0, FILE *fp = stderr) { - fprintf(fp, "(TypedefDecl %s %s %s)\n", underlyingtype, newtype, arraypart); - }; - void print(int indent = 0, FILE *fp = stderr); }; @@ -248,7 +239,6 @@ public: // required methods that I can't seem to get to inherit void print(int indent = 0, FILE *fp = stderr); // print CODE - void dump(int indent = 0, FILE *fp = stderr); // print ast char *stringRep(int indent = 0); chillAST_Node *constantFold(); @@ -377,8 +367,6 @@ public: chillAST_VarDecl *findSubpartByType(const char *typ); - void dump(int indent = 0, FILE *fp = stderr); - void print(int indent = 0, FILE *fp = stderr); void printStructure(int indent = 0, FILE *fp = stderr); @@ -397,11 +385,6 @@ public: char *returnType; char *functionName; - //! parameters - int numParameters() { return symbolTable->size(); }; - // chillAST_TypedefTable *typedef_table; // TODO typedef here doesn't make sense - - //char *parametertypes; // a single string?? void printParameterTypes(FILE *fp); void setName(char *n) { functionName = strdup(n); /* probable memory leak */ }; @@ -427,8 +410,6 @@ public: chillAST_FunctionDecl(const char *rt, const char *fname, void *unique); - void addParameter(chillAST_VarDecl *p); - void addDecl(chillAST_VarDecl *vd); // just adds to symbol table?? TODO void addChild(chillAST_Node *node); // special because inserts into BODY @@ -439,7 +420,6 @@ public: chillAST_CompoundStmt *getBody() { return (body); } void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc - void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc void gatherVarDecls(std::vector<chillAST_VarDecl *> &decls); @@ -464,8 +444,6 @@ public: chillAST_Node *constantFold(); - chillAST_SymbolTable *getParameterTable() { return getSymbolTable(); } - void replaceChild(chillAST_Node *old, chillAST_Node *newchild) { body->replaceChild(old, newchild); } @@ -534,9 +512,6 @@ public: char *rhsString; // parameters - these will be odd, in that they HAVE NO TYPE - int numParameters() { return parameters.size(); }; - std::vector<chillAST_VarDecl *> parameters; - void setName(char *n) { macroName = strdup(n); /* probable memory leak */ }; void setRhsString(char *n) { rhsString = strdup(n); /* probable memory leak */ }; @@ -553,7 +528,6 @@ public: chillAST_Node *getBody() { return (body); } void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc - void dump(int indent = 0, FILE *fp = stderr); // in chill_ast.cc chillAST_Node *clone(); @@ -623,7 +597,6 @@ public: // required methods that I can't seem to get to inherit - 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 printControl(int indent = 0, FILE *fp = stderr); // print just for ( ... ) but not body @@ -889,8 +862,6 @@ public: void gatherStatements(std::vector<chillAST_Node *> &statements); // - bool isSameAs(chillAST_Node *other); - }; class chillAST_ArraySubscriptExpr : public chillAST_Node { @@ -998,7 +969,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(); @@ -1132,7 +1102,6 @@ public: bool forcesync = false) { return false; }; // no loops under here chillAST_Node *findref() { return this; };// find the SINGLE constant or data reference at this node or below - bool isSameAs(chillAST_Node *other); }; class chillAST_UnaryOperator : public chillAST_Node { @@ -1186,8 +1155,6 @@ public: int evalAsInt(); - bool isSameAs(chillAST_Node *other); - }; class chillAST_ImplicitCastExpr : public chillAST_Node { @@ -1209,7 +1176,6 @@ public: void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc void printonly(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc - void dump(int indent = 0, FILE *fp = stderr) { print(indent, fp); }; // print ast in chill_ast.cc chillAST_Node *constantFold(); chillAST_Node *clone(); @@ -1343,7 +1309,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(); @@ -1426,7 +1391,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(); @@ -1475,7 +1439,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(); @@ -1548,7 +1511,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(); @@ -1710,7 +1672,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() { chillAST_Node* n = new chillAST_NoOp(); n->setParent(parent); return n; }; // ?? @@ -1774,8 +1735,6 @@ public: }; // required methods that I can't seem to get to inherit - void dump(int indent = 0, FILE *fp = stderr); - void print(int indent = 0, FILE *fp = stderr); chillAST_Node *constantFold(); diff --git a/include/printer.h b/include/printer.h new file mode 100644 index 0000000..5930768 --- /dev/null +++ b/include/printer.h @@ -0,0 +1,202 @@ +// +// 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/printers/cfamily.h new file mode 100644 index 0000000..e979db7 --- /dev/null +++ b/include/printers/cfamily.h @@ -0,0 +1,56 @@ +// +// Created by ztuowen on 9/24/16. +// + +#ifndef CHILL_CFAMILY_H +#define CHILL_CFAMILY_H + +#include "printer.h" + +/*! + * \file + * \brief Print the AST for C like syntax, This replace the old print function + */ + +namespace chill { + namespace printer{ + 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); + }; + } +} + +#endif //CHILL_CFAMILY_H diff --git a/include/printers/dump.h b/include/printers/dump.h new file mode 100644 index 0000000..285de8e --- /dev/null +++ b/include/printers/dump.h @@ -0,0 +1,62 @@ +// +// 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 |