diff options
Diffstat (limited to 'include/chillAST')
-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 |
3 files changed, 19 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(); |