165 |
166 |
166 /* |
167 /* |
167 * Annotations produced during stage 1_2 |
168 * Annotations produced during stage 1_2 |
168 */ |
169 */ |
169 /* Points to the parent symbol in the AST, i.e. the symbol in the AST that will contain the current symbol */ |
170 /* Points to the parent symbol in the AST, i.e. the symbol in the AST that will contain the current symbol */ |
170 symbol_c *parent; |
171 symbol_c *parent; |
|
172 /* Some symbols may not be tokens, but may be clearly identified by a token. |
|
173 * For e.g., a FUNCTION declaration is not itself a token, but may be clearly identified by the |
|
174 * token_c object that contains it's name. Another example is an element in a STRUCT declaration, |
|
175 * where the structure_element_declaration_c is not itself a token, but can be clearly identified |
|
176 * by the structure_element_name |
|
177 * To make it easier to find these tokens from the top level object, we will have the stage1_2 populate this |
|
178 * token_c *token wherever it makes sense. |
|
179 * NOTE: This was a late addition to the AST. Not all objects may be currently so populated. |
|
180 * If you need this please make sure the bison code is populating it correctly for your use case. |
|
181 */ |
|
182 token_c *token; |
171 |
183 |
172 /* Line number for the purposes of error checking. */ |
184 /* Line number for the purposes of error checking. */ |
173 int first_line; |
185 int first_line; |
174 int first_column; |
186 int first_column; |
175 const char *first_file; /* filename referenced by first line/column */ |
187 const char *first_file; /* filename referenced by first line/column */ |
259 /* WARNING: only use this method for debugging purposes!! */ |
271 /* WARNING: only use this method for debugging purposes!! */ |
260 virtual const char *absyntax_cname(void) {return "list_c";}; |
272 virtual const char *absyntax_cname(void) {return "list_c";}; |
261 |
273 |
262 int c,n; /* c: current capacity of list (malloc'd memory); n: current number of elements in list */ |
274 int c,n; /* c: current capacity of list (malloc'd memory); n: current number of elements in list */ |
263 private: |
275 private: |
264 symbol_c **elements; |
276 // symbol_c **elements; |
|
277 typedef struct { |
|
278 const char *token_value; |
|
279 symbol_c *symbol; |
|
280 } element_entry_t; |
|
281 element_entry_t *elements; |
|
282 |
265 |
283 |
266 public: |
284 public: |
267 list_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
285 list_c(int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
268 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
286 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
269 ); |
287 ); |
272 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
290 int fl = 0, int fc = 0, const char *ffile = NULL /* filename */, long int forder=0, /* order in which it is read by lexcial analyser */ |
273 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
291 int ll = 0, int lc = 0, const char *lfile = NULL /* filename */, long int lorder=0 /* order in which it is read by lexcial analyser */ |
274 ); |
292 ); |
275 /* get element in position pos of the list */ |
293 /* get element in position pos of the list */ |
276 virtual symbol_c *get_element(int pos); |
294 virtual symbol_c *get_element(int pos); |
|
295 /* find element associated to token value */ |
|
296 virtual symbol_c *find_element(symbol_c *token); |
|
297 virtual symbol_c *find_element(const char *token_value); |
277 /* append a new element to the end of the list */ |
298 /* append a new element to the end of the list */ |
278 virtual void add_element(symbol_c *elem); |
299 virtual void add_element(symbol_c *elem); |
|
300 virtual void add_element(symbol_c *elem, symbol_c *token); |
|
301 virtual void add_element(symbol_c *elem, const char *token_value); |
279 /* insert a new element before position pos. */ |
302 /* insert a new element before position pos. */ |
280 /* To insert into the begining of list, call with pos=0 */ |
303 /* To insert into the begining of list, call with pos=0 */ |
281 /* To insert into the end of list, call with pos=list->n */ |
304 /* To insert into the end of list, call with pos=list->n */ |
282 virtual void insert_element(symbol_c *elem, int pos = 0); |
305 virtual void insert_element(symbol_c *elem, const char *token_value, int pos = 0); |
|
306 virtual void insert_element(symbol_c *elem, symbol_c *token, int pos = 0); |
|
307 virtual void insert_element(symbol_c *elem, int pos = 0); |
|
308 //virtual void insert_element(symbol_c *elem, int pos, std::string map_ref); |
283 /* remove element at position pos. */ |
309 /* remove element at position pos. */ |
284 virtual void remove_element(int pos = 0); |
310 virtual void remove_element(int pos = 0); |
285 /* remove all elements from list. Does not delete the elements in the list! */ |
311 /* remove all elements from list. Does not delete the elements in the list! */ |
286 virtual void clear(void); |
312 virtual void clear(void); |
287 }; |
313 }; |