1 #ifndef DYNAMITEexprtreeHEADERFILE 2 #define DYNAMITEexprtreeHEADERFILE 3 #ifdef _cplusplus 4 extern "C" { 5 #endif 6 #include "wisebase.h" 7 8 /* 9 * 10 11 Expr Tree is about the yacc parse tree. Each node in the 12 tree is going to be ExprTree *. The children of each node 13 are in the child array, the number of children are in the 14 nochild field. 15 16 Each node has a type, and this is the critical layout of 17 the node. Each type will layout its children in a particular 18 way: 19 20 ETR_NUMBER - has no children. The number is word 21 ETR_OPERATOR - has no children. The operator character is in word 22 ETR_EXPRESSION - has potentially any number of children, but 23 the yacc parser restricts it to (possible_tag) (operator) (possible_tag). 24 Don't rely on this though. Generally allowed types in possible_tag 25 are NUMBEr, TAG, METHOD or EXPRESSION 26 27 ETR_STATEMENT - is the top level tag. It only has one child which must 28 be an ETR_EXPRESSION 29 30 ETR_NAME - is for absolute variable names (or method names). It has no 31 children. The actual name is in the word 32 33 ETR_ARRAY - has 2 children. The first must be a "TAG" type and is what 34 is indexed, the second must be an EXPRESSION and is what indexes it. 35 36 ETR_TAG - has any number of children to build up a TAG from NAMES, 37 ->,. (struct refs) or * (REFERNECES). 38 39 ETR_STRUCTREF - -> or . constructions. It has 3 children: 1st is the 40 TAG to the left of the STRUCTREF, second holds either . or -> in word 41 and third is the tag to the right. 42 43 ETR_REFERENCE - * or & constructions. It has two children. 1st is * or & in 44 word, the second is the tag which is it is acting on. 45 46 ETR_METHOD - function calls. It has one or two children. The first is a tag (hence 47 could be a pointer to a function, or similar). If it is a void function 48 it has no other children the second is a commalist. 49 50 ETR_COMMALIST - can only be found in methods. Any number of children, each being 51 an argument of the method 52 53 */ 54 55 56 57 58 59 60 enum types { 61 ETR_NUMBER = 0, 62 ETR_OPERATOR, 63 ETR_EXPRESSION, 64 ETR_STATEMENT, 65 ETR_ARRAY, 66 ETR_NAME, 67 ETR_REFERENCE, 68 ETR_STRUCTREF, 69 ETR_METHOD, 70 ETR_COMMALIST, 71 ETR_DECL_VARIABLE, 72 ETR_DECL_METHOD, 73 ETR_DECL_LIST, 74 ETR_TAG 75 }; 76 77 #define EXPRTREE_MAXCHILD 128 78 79 #define IS_DECLARED 2 80 #define IS_TOPLEVEL 4 81 82 83 struct ExprTree { 84 int dynamite_hard_link; 85 #ifdef PTHREAD 86 pthread_mutex_t dynamite_mutex; 87 #endif 88 struct ExprTree * child[EXPRTREE_MAXCHILD]; 89 int nochild; 90 char token; 91 char * word; 92 int type; 93 int attrib; 94 struct ExprTree * parent; 95 int position_in_parent; 96 } ; 97 /* ExprTree defined */ 98 #ifndef DYNAMITE_DEFINED_ExprTree 99 typedef struct ExprTree ExprTree; 100 #define DYNAMITE_DEFINED_ExprTree 101 #endif 102 103 104 105 106 /***************************************************/ 107 /* Callable functions */ 108 /* These are the functions you are expected to use */ 109 /***************************************************/ 110 111 112 113 /* Function: hard_link_ExprTree(obj) 114 * 115 * Descrip: Bumps up the reference count of the object 116 * Meaning that multiple pointers can 'own' it 117 * 118 * 119 * Arg: obj [UNKN ] Object to be hard linked [ExprTree *] 120 * 121 * Return [UNKN ] Undocumented return value [ExprTree *] 122 * 123 */ 124 ExprTree * hard_link_ExprTree(ExprTree * obj); 125 126 127 /* Function: ExprTree_alloc(void) 128 * 129 * Descrip: Allocates structure: assigns defaults if given 130 * 131 * 132 * 133 * Return [UNKN ] Undocumented return value [ExprTree *] 134 * 135 */ 136 ExprTree * ExprTree_alloc(void); 137 138 139 /* Function: free_ExprTree(obj) 140 * 141 * Descrip: Free Function: removes the memory held by obj 142 * Will chain up to owned members and clear all lists 143 * 144 * 145 * Arg: obj [UNKN ] Object that is free'd [ExprTree *] 146 * 147 * Return [UNKN ] Undocumented return value [ExprTree *] 148 * 149 */ 150 ExprTree * free_ExprTree(ExprTree * obj); 151 152 153 /* Unplaced functions */ 154 /* There has been no indication of the use of these functions */ 155 void parentfy_ExprTree(ExprTree * et); 156 void declared_ExprTree(ExprTree * et); 157 void find_toplevel_name(ExprTree * et); 158 void strcat_ExprTree(ExprTree * ExprTree,char * buffer); 159 void print_ExprTree(ExprTree * ExprTree); 160 ExprTree * new_ExprTree_decl_method(ExprTree * name,ExprTree * list); 161 ExprTree * new_ExprTree_decl_variable(ExprTree * type,ExprTree * name); 162 ExprTree * add_to_decl_list_ExprTree(ExprTree * list,ExprTree * add); 163 ExprTree * new_ExprTree_decl_list(ExprTree * start); 164 ExprTree * new_ExprTree_struct_ref(ExprTree * left, ExprTree * ref,ExprTree * right); 165 ExprTree * new_ExprTree_ref(char op,ExprTree * right); 166 ExprTree * add_to_commalist_ExprTree(ExprTree * list,ExprTree * add); 167 ExprTree * new_ExprTree_commalist(ExprTree * start); 168 ExprTree * new_ExprTree_method(ExprTree * one,ExprTree * other); 169 ExprTree * new_ExprTree_tag_from_name(ExprTree * name); 170 ExprTree * new_ExprTree_array(ExprTree * tag,ExprTree * expr) ; 171 ExprTree * new_ExprTree_binary_expr(ExprTree * left,char op,ExprTree * rgt); 172 ExprTree * new_ExprTree_token(char t); 173 boolean add_ExprTree(ExprTree * one,ExprTree * child); 174 ExprTree * new_ExprTree(void); 175 176 177 /***************************************************/ 178 /* Internal functions */ 179 /* you are not expected to have to call these */ 180 /***************************************************/ 181 182 #ifdef _cplusplus 183 } 184 #endif 185 186 #endif 187