summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/chillAST/chillAST_node.hh11
-rw-r--r--include/chillAST/chillASTs.hh40
-rw-r--r--include/printer/cfamily.h71
-rw-r--r--include/printer/dump.h10
-rw-r--r--include/printer/generic.h39
5 files changed, 81 insertions, 90 deletions
diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh
index 80f1be4..bed2f22 100644
--- a/include/chillAST/chillAST_node.hh
+++ b/include/chillAST/chillAST_node.hh
@@ -25,7 +25,6 @@ public:
char *filename;
//! for compiler internals, formerly a comment
char *metacomment;
- std::vector<chillAST_Preprocessing *> preprocessinginfo;
//! for manufactured scalars
static int chill_scalar_counter;
@@ -418,7 +417,7 @@ public:
fprintf(fp, "(%s) forgot to implement printName()\n", getTypeString());
};// print CODE
- //! The AST's print version
+ //! The AST's print version, for reason unknown and incorrect
virtual char *stringRep(int indent = 0) {
fflush(stdout);
// TODO chillindent(indent, fp);
@@ -426,9 +425,6 @@ public:
exit(-1);
}
-
- virtual void printonly(int indent = 0, FILE *fp = stderr) { print(indent, fp); };
-
virtual void getTopLevelLoops(std::vector<chillAST_ForStmt *> &loops) {
int n = children.size();
for (int i = 0; i < n; i++) {
@@ -528,14 +524,11 @@ public:
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);
+ //! Emulation of the old dump function but using printer instead of hardcoded heuritics
void dump(int indent=0,FILE *fp = stderr);
};
diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh
index a84b820..36442ee 100644
--- a/include/chillAST/chillASTs.hh
+++ b/include/chillAST/chillASTs.hh
@@ -11,13 +11,6 @@ public:
virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_NULL;}
chillAST_NULL() {
};
-
- void print(int indent = 0, FILE *fp = stderr) {
- chillindent(indent, fp);
- fprintf(fp, "/* (NULL statement); */ ");
- fflush(fp);
- }
-
};
class chillAST_Preprocessing : public chillAST_Node {
@@ -90,9 +83,6 @@ public:
fprintf(stderr, "TypedefDecl getUnderLyingType()\n");
return underlyingtype;
};
-
- void print(int indent = 0, FILE *fp = stderr);
-
};
class chillAST_VarDecl : public chillAST_Node {
@@ -166,8 +156,6 @@ public:
chillAST_VarDecl(chillAST_RecordDecl *astruct, const char *n, const char *arraypart);
- void print(int indent = 0, FILE *fp = stderr);
-
void printName(int indent = 0, FILE *fp = stderr);
bool isParmVarDecl() { return (isAParameter == 1); };
@@ -446,13 +434,13 @@ public:
}; // end FunctionDecl
class chillAST_SourceFile : public chillAST_Node {
+ // TODO included source file
public:
virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_SOURCEFILE;}
// constructors
chillAST_SourceFile(const char *filename); // defined in chill_ast.cc
- void print(int indent = 0, FILE *fp = stderr); // print CODE in chill_ast.cc
void printToFile(char *filename = NULL);
char *SourceFileName; // where this originated
@@ -522,8 +510,6 @@ public:
chillAST_Node *getBody() { return (body); }
- void print(int indent = 0, FILE *fp = stderr); // in chill_ast.cc
-
chillAST_Node *clone();
// none of these make sense for macros
@@ -592,7 +578,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 printControl(int indent = 0, FILE *fp = stderr); // print just for ( ... ) but not body
chillAST_Node *constantFold();
@@ -711,7 +696,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 printonly(int indent = 0, FILE *fp = stderr);
chillAST_Node *constantFold();
@@ -820,7 +804,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 printonly(int indent = 0, FILE *fp = stderr);
char *stringRep(int indent = 0);
@@ -892,9 +875,6 @@ public:
void replaceChild(chillAST_Node *old, chillAST_Node *newchild); // will examine index
// 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 printonly(int indent = 0, FILE *fp = stderr);
-
void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
char *stringRep(int indent = 0);
@@ -957,10 +937,6 @@ public:
bool operator==(const chillAST_MemberExpr &);
// 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 printonly(int indent = 0, FILE *fp = stderr);
-
- void print(int indent = 0, FILE *fp = stderr) const; // print CODE in chill_ast.cc
char *stringRep(int indent = 0);
chillAST_Node *constantFold();
@@ -1013,7 +989,6 @@ public:
int evalAsInt() { return value; }
// 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
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1151,8 +1126,6 @@ public:
// required methods that I can't seem to get to inherit
void replaceChild(chillAST_Node *old, chillAST_Node *newchild);
- 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
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1352,19 +1325,15 @@ class chillAST_Malloc : public chillAST_Node { // malloc( sizeof(int) * 2048 )
public:
virtual CHILLAST_NODE_TYPE getType(){return CHILLAST_NODE_MALLOC;}
// variables that are special for this type of node
- //! to void if this is null , sizeof(thing) if it is not
- char *thing;
//! The subexpression calculating bytes
chillAST_Node *sizeexpr; // bytes
// constructors
- chillAST_Malloc(char *thething, chillAST_Node *numthings); // malloc (sizeof(int) *1024)
+ chillAST_Malloc(chillAST_Node *numthings); // malloc (sizeof(int) *1024)
// other methods particular to this type of node
-
// 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
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1412,7 +1381,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
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1607,7 +1575,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
chillAST_Node *constantFold();
chillAST_Node *clone();
@@ -1641,7 +1608,6 @@ public:
chillAST_NoOp(); // { parent = p; };
// 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
chillAST_Node *constantFold() {};
chillAST_Node *clone() { chillAST_Node* n = new chillAST_NoOp(); n->setParent(parent); return n; }; // ??
@@ -1746,8 +1712,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
};
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<<")";
+ }
};
}
}