#include <ast.h>
Inheritance diagram for AST::Node:
Public Member Functions | |
Node (string new_name) | |
Constructor -> subclassed to a parameterless construct that sets this name according to their type -> (If, Identifier). | |
virtual void | to3ACFile (FILE *f)=0 |
convert me to 3ac - subclassed | |
void | toASTFile (FILE *f) |
recursively dump me and my child nodes to a file | |
void | set_attribute (string attributeName, Node *child) |
create a new attribute pointing to another node | |
void | set_attribute (string attributeName, string value) |
create a new attribute pointing to a new leaf node with str as its value | |
void | set_attribute (string attributeName, vector< Node * > vec_nodes) |
create a new attribute pointing to a new list who has child nodes containing vec_nodes | |
AttributeProxy | operator[] (string attributeName) |
allows node['hello'] = something | |
const char * | get_name () |
Protected Types | |
enum | { NODE_BRANCH, NODE_LIST, NODE_LEAF, NODE_ID, NODE_CONSTANT } |
Used for effecient type checking of subclassed nodes we only need to identify the special children, so this does not contain all the subclasses. More... | |
Protected Member Functions | |
AttributeProxy | addAttribute (const char *attributeName) |
declare that this class requires a particular attributeproxy -> also determines the order in which they are saved | |
Protected Attributes | |
enum AST::Node:: { ... } | nodeType |
Used for effecient type checking of subclassed nodes we only need to identify the special children, so this does not contain all the subclasses. | |
map< string, Node * > | attributes |
maps attribute's from name to objects | |
string | name |
Private Attributes | |
vector< string > | orderedAttributes |
ordered list of attributes to save to file |
Definition at line 17 of file ast.h.
|
Used for effecient type checking of subclassed nodes we only need to identify the special children, so this does not contain all the subclasses.
Definition at line 24 of file ast.h. 00024 { 00025 NODE_BRANCH, 00026 NODE_LIST, 00027 NODE_LEAF, 00028 NODE_ID, 00029 NODE_CONSTANT, 00030 } nodeType;
|
|
Constructor -> subclassed to a parameterless construct that sets this name according to their type -> (If, Identifier).
Definition at line 33 of file ast.h. 00033 : 00034 name(new_name), 00035 nodeType(NODE_BRANCH) 00036 { 00037 } public:
|
|
declare that this class requires a particular attributeproxy -> also determines the order in which they are saved Called by sublcasses to declare the attributes they need Also defines the order in which attributes are saved to file
Definition at line 151 of file ast.cc. References operator[](), and orderedAttributes. 00151 { 00152 this->orderedAttributes.push_back(attributeName); 00153 return this->operator[](attributeName); 00154 }
|
|
Definition at line 45 of file ast.h. References name. 00045 { return this->name.c_str(); }
|
|
allows node['hello'] = something Returns an attribute proxy for more convienent attribute setting
Definition at line 142 of file ast.cc. Referenced by addAttribute(). 00142 { 00143 return AttributeProxy(this, attributeName); 00144 }
|
|
create a new attribute pointing to a new list who has child nodes containing vec_nodes Instantiate a new AST::List node containing the list of nodes
Definition at line 134 of file ast.cc. References attributes. 00134 { 00135 printf("%s.%s = %i\n", this->name.c_str(), attributeName.c_str(), vec_nodes.size()); 00136 this->attributes[attributeName] = new List(vec_nodes); 00137 }
|
|
create a new attribute pointing to a new leaf node with str as its value instantiate a Leaf node containing the string value and set it as the child
Definition at line 126 of file ast.cc. References attributes. 00126 { 00127 printf("%s.%s = %s\n", this->name.c_str(), attributeName.c_str(), value.c_str()); 00128 this->attributes[attributeName] = new Leaf(value); 00129 }
|
|
create a new attribute pointing to another node Set this attribute to point to some other child node Definition at line 118 of file ast.cc. References attributes, and name. Referenced by AST::AttributeProxy::operator=(). 00118 { 00119 printf("%s.%s = %s\n", this->name.c_str(), attributeName.c_str(), child->name.c_str()); 00120 this->attributes[attributeName] = child; 00121 }
|
|
convert me to 3ac - subclassed
Implemented in AST::List, AST::Leaf, AST::Program, AST::Def_Function, AST::Def_Struct, AST::If, AST::Jump, AST::Loop, AST::Return, AST::Op_Unary, AST::Op_Binary, AST::Op_Ternary, AST::Assignment, AST::Constant, AST::FunctionCall, AST::Identifier, AST::Op_Bracket, AST::Op_Dot, AST::Def_Var, and AST::Def_Array. |
|
recursively dump me and my child nodes to a file Dump all the data representing this AST into a file This will be a recursive call, with some clever outputing to deal with the shortcuts
Definition at line 160 of file ast.cc. References attributes, ifprintf(), indent(), AST::List::list, NODE_BRANCH, NODE_CONSTANT, NODE_ID, NODE_LEAF, NODE_LIST, nodeType, orderedAttributes, outdent(), and AST::Leaf::value. Referenced by main(). 00160 { 00161 ifprintf(f, "%s\n", this->name.c_str()); 00162 for(int i = 0; i < this->orderedAttributes.size(); i++){ 00163 string attributeName = orderedAttributes[i]; 00164 Node* node = this->attributes[attributeName]; 00165 if( node == NULL) 00166 ifprintf(f, "%s NULL\n", attributeName.c_str()); 00167 else { 00168 switch(node->nodeType){ 00169 case NODE_BRANCH: { 00170 ifprintf(f, "%s {\n", attributeName.c_str()); 00171 indent(); 00172 this->attributes[attributeName]->toASTFile(f); 00173 outdent(); 00174 ifprintf(f, "}\n"); 00175 } 00176 break; 00177 case NODE_LIST:{ 00178 List* listNode = (List*) node; 00179 ifprintf(f, "%s [\n", attributeName.c_str()); 00180 indent(); 00181 for(int i = 0; i < listNode->list.size(); i ++){ 00182 Node* childNode = listNode->list[i]; 00183 ifprintf(f, "{\n"); 00184 indent(); 00185 listNode->list[i]->toASTFile(f); 00186 outdent(); 00187 ifprintf(f, "}\n"); 00188 } 00189 outdent(); 00190 ifprintf(f, "]\n"); 00191 } 00192 break; 00193 case NODE_LEAF:{ 00194 Leaf* leafNode = (Leaf*) node; 00195 ifprintf(f, "%s %s\n", attributeName.c_str(), leafNode->value.c_str()); 00196 } 00197 break; 00198 case NODE_ID:{ 00199 Identifier* idNode = (Identifier*) node; 00200 Leaf* idNodeHandle = (Leaf*) idNode->attributes["handle"]; 00201 ifprintf(f, "%s id:%s\n", attributeName.c_str(), idNodeHandle->value.c_str()); 00202 } 00203 break; 00204 case NODE_CONSTANT:{ 00205 Identifier* idNode = (Identifier*) node; 00206 Leaf* idNodeType = (Leaf*) idNode->attributes["type"]; 00207 Leaf* idNodeValue = (Leaf*) idNode->attributes["value"]; 00208 ifprintf(f, "%s const:%s:%s\n", attributeName.c_str(), idNodeType->value.c_str(), idNodeValue->value.c_str()); 00209 } 00210 break; 00211 } 00212 } 00213 } 00214 }
|
|
maps attribute's from name to objects
Definition at line 51 of file ast.h. Referenced by set_attribute(), and toASTFile(). |
|
Definition at line 52 of file ast.h. Referenced by get_name(), and set_attribute(). |
|
Used for effecient type checking of subclassed nodes we only need to identify the special children, so this does not contain all the subclasses.
Referenced by AST::Constant::Constant(), AST::Identifier::Identifier(), AST::Leaf::Leaf(), AST::List::List(), and toASTFile(). |
|
ordered list of attributes to save to file
Definition at line 54 of file ast.h. Referenced by addAttribute(), and toASTFile(). |