diff options
-rw-r--r-- | include/chillAST/chillAST_def.hh | 1 | ||||
-rw-r--r-- | include/chillAST/chillAST_node.hh | 31 | ||||
-rw-r--r-- | include/chillAST/chillASTs.hh | 44 | ||||
-rwxr-xr-x | lib/chillcg/src/CG_chillBuilder.cc | 2 | ||||
-rw-r--r-- | src/ast/node.cpp | 8 | ||||
-rw-r--r-- | src/chillASTs.cc | 1 |
6 files changed, 62 insertions, 25 deletions
diff --git a/include/chillAST/chillAST_def.hh b/include/chillAST/chillAST_def.hh index 4ec60aa..ca90561 100644 --- a/include/chillAST/chillAST_def.hh +++ b/include/chillAST/chillAST_def.hh @@ -186,6 +186,7 @@ class chillAST_Preprocessing; typedef std::vector<chillAST_Node *> chillAST_NodeList; typedef std::vector<chillAST_VarDecl *> chillAST_SymbolTable; typedef std::vector<chillAST_TypedefDecl *> chillAST_TypedefTable; +typedef std::vector<chillAST_RecordDecl *> chillAST_RecordTable; chillAST_VarDecl *symbolTableFindName(chillAST_SymbolTable *table, const char *name); diff --git a/include/chillAST/chillAST_node.hh b/include/chillAST/chillAST_node.hh index 3ea29d9..b0e7622 100644 --- a/include/chillAST/chillAST_node.hh +++ b/include/chillAST/chillAST_node.hh @@ -4,9 +4,16 @@ #define _CHILLAST_NODE_H_ #include "chillAST_def.hh" +#include <stack> //! generic node of the actual chillAST, a multiway tree node. class chillAST_Node { +protected: + void gatherTypedef(std::map<std::string, std::stack<chillAST_TypedefDecl*>> map, chillAST_TypedefTable* tdt); + void gatherSymbol(std::map<std::string, std::stack<chillAST_VarDecl*>> map, chillAST_SymbolTable* tdt); + void gatherRecord(std::map<std::string, std::stack<chillAST_RecordDecl*>> map, chillAST_RecordTable *tdt); + void gatherOther(chillAST_SourceFile *s); + void fixReference(std::map<std::string, std::stack<chillAST_Node*>> map); public: // TODO decide how to hide some data //! this Node's parent @@ -19,6 +26,8 @@ public: chillAST_SymbolTable *symbolTable; //! typedef Scoping chillAST_TypedefTable *typedefTable; + //! recordDecl scoping + std::vector<chillAST_RecordDecl*> *recordTable; //! whether it is from a source file, when false it is from included files bool isFromSourceFile; //! the name of file this node from @@ -165,10 +174,22 @@ public: //! Recursive version that will go the parent node if not finding in this chillAST_TypedefDecl *findTypeDecleration(const char *t); - int getNumChildren() { return children.size(); }; - - chillAST_NodeList *getChildren() { return &children; }; // not usually useful - void setChildren(chillAST_NodeList &c) { children = c; }; // does not set parent. probably should + /*! + * \brief Get the number of subexpressions + * + * This will get multiplexed for different operation. Subexpression appear in the sourcefile order. + * @return The number of subexpressions + */ + virtual int getNumChildren() { return children.size(); }; + //! Deprecating, return the children as a list not eligible for multiplexing + chillAST_NodeList *getChildren() { return &children; }; + /*! + * \brief Get the which-th child + * + * This will get multiplexed in the same manner as \sa getNumChildren + * @param which + * @return The which-th node + */ chillAST_Node *getChild(int which) { return children[which]; }; void setChild(int which, chillAST_Node *n) { @@ -384,6 +405,8 @@ public: //! Emulation of the old print function to print C-family like syntax but using printer void print(int ident = 0, FILE *fp = stderr); + //! Public interface for fixing child info, which can be called from anynode. + void fixChildInfo(); }; diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 4ff70c9..b2cea3a 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -14,25 +14,26 @@ public: }; }; +// TODO doc and usage class chillAST_Preprocessing : public chillAST_Node { -public: - virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_PREPROCESSING; } - - // variables that are special for this type of node +private: CHILLAST_PREPROCESSING_POSITION position; CHILLAST_PREPROCESSING_TYPE pptype; char *blurb; +public: + virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_PREPROCESSING; } - // constructors - chillAST_Preprocessing(); // not sure what this is good for + chillAST_Preprocessing(); chillAST_Preprocessing(CHILLAST_PREPROCESSING_POSITION pos, CHILLAST_PREPROCESSING_TYPE t, char *text); - - // other methods particular to this type of node - - // required methods that I can't seem to get to inherit }; -//typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another. +/*! + * \brief A typedef declaration + * + * typedef is a keyword in the C and C++ programming languages. The purpose of typedef is to assign alternative names + * to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to + * vary from one implementation to another. + */ class chillAST_TypedefDecl : public chillAST_Node { private: bool isStruct; @@ -47,7 +48,7 @@ public: char *arraypart; // string like "[1234][56]" ?? chillAST_RecordDecl *rd; // if it's a struct, point to the recorddecl ?? - // TODO what if "typedef int[10] tenints; " ?? + // TODO what if "typedef int[10] tenints; " ?? void setStructInfo(chillAST_RecordDecl *arrdee) { rd = arrdee; }; chillAST_RecordDecl *getStructDef(); @@ -86,14 +87,18 @@ public: }; }; +//! A variable declaration node class chillAST_VarDecl : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_VARDECL; } char *vartype; // should probably be an enum, except it's used for unnamed structs too - chillAST_RecordDecl *vardef;// the thing that says what the struct looks like - chillAST_TypedefDecl *typedefinition; // NULL for float, int, etc. + //! Points to the recorddecl + chillAST_RecordDecl *vardef; + //! Typedef info if it is typedefed + chillAST_TypedefDecl *typedefinition; + chillAST_RecordDecl *getStructDef(); // TODO make vardef private? //bool insideAStruct; // this variable is itself part of a struct @@ -190,6 +195,7 @@ public: }; +//! referencing a previously defined node, Function or variable class chillAST_DeclRefExpr : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_DECLREFEXPR; } @@ -198,7 +204,6 @@ public: char *declarationType; char *declarationName; chillAST_Node *decl; // the declaration of this variable or function ... uhoh - //char *functionparameters; // TODO probably should split this node into 2 types, one for variables, one for functions // constructors chillAST_DeclRefExpr(const char *vartype, const char *variablename, chillAST_Node *dec); @@ -267,6 +272,7 @@ public: chillAST_Node *multibase2() { return (chillAST_Node *) multibase(); } }; +//! A basic block consists of multiple statements class chillAST_CompoundStmt : public chillAST_Node { public: virtual CHILLAST_NODE_TYPE getType() { return CHILLAST_NODE_COMPOUNDSTMT; } @@ -275,10 +281,7 @@ public: // constructors chillAST_CompoundStmt(); // never has any args ??? - // other methods particular to this type of node - - - // required methods + // required methods void replaceChild(chillAST_Node *old, chillAST_Node *newchild); chillAST_Node *constantFold(); @@ -310,7 +313,8 @@ public: void gatherStatements(std::vector<chillAST_Node *> &statements); }; -class chillAST_RecordDecl : public chillAST_Node { // declaration of the shape of a struct or union +//! Declaration of the shape of a struct or union +class chillAST_RecordDecl : public chillAST_Node { private: char *name; // could be NULL? for unnamed structs? char *originalname; diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index 9a9a414..7f13334 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -276,7 +276,7 @@ namespace omega { int numchildren = CS->getNumChildren(); for (int i=0; i<numchildren; i++) { - CS->setChild( i, substituteChill(oldvar, newvar, CS->getChild(i), CS )); + CS->setChild( i, substituteChill(oldvar, newvar, CS->getChild(i), CS )); } return CS; diff --git a/src/ast/node.cpp b/src/ast/node.cpp index ea74159..1b1995c 100644 --- a/src/ast/node.cpp +++ b/src/ast/node.cpp @@ -5,6 +5,14 @@ #include "chillAST.h" #include "printer/dump.h" #include "printer/cfamily.h" +#include <stack> + +void chillAST_Node::fixChildInfo(std::stack<chillAST_TypedefTable *> &tdt, std::stack<chillAST_SymbolTable *> &st, + chillAST_SourceFile *s) { + +} + +void chillAST_Node::fixChildInfo() {} void chillAST_Node::mergeChildInfo(chillAST_Node) { // TODO if (par) par->add to definition for vardecl/typedecl diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 7654ecf..31c6758 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -372,6 +372,7 @@ chillAST_RecordDecl::chillAST_RecordDecl(const char *nam, const char *orig) { else name = strdup("unknown"); // ?? originalname = NULL; + symbolTable = new chillAST_SymbolTable(); if (orig) originalname = strdup(orig); isStruct = isUnion = false; |