--- a/absyntax/absyntax.hh Tue Apr 04 10:41:11 2017 +0100
+++ b/absyntax/absyntax.hh Tue Apr 04 15:21:42 2017 +0100
@@ -154,7 +154,8 @@
{return (_int64.is_valid() || _uint64.is_valid() || _real64.is_valid() || _bool.is_valid());}
};
-
+// A forward declaration
+class token_c;
/* The base class of all symbols */
class symbol_c {
@@ -167,7 +168,18 @@
* Annotations produced during stage 1_2
*/
/* Points to the parent symbol in the AST, i.e. the symbol in the AST that will contain the current symbol */
- symbol_c *parent;
+ symbol_c *parent;
+ /* Some symbols may not be tokens, but may be clearly identified by a token.
+ * For e.g., a FUNCTION declaration is not itself a token, but may be clearly identified by the
+ * token_c object that contains it's name. Another example is an element in a STRUCT declaration,
+ * where the structure_element_declaration_c is not itself a token, but can be clearly identified
+ * by the structure_element_name
+ * To make it easier to find these tokens from the top level object, we will have the stage1_2 populate this
+ * token_c *token wherever it makes sense.
+ * NOTE: This was a late addition to the AST. Not all objects may be currently so populated.
+ * If you need this please make sure the bison code is populating it correctly for your use case.
+ */
+ token_c *token;
/* Line number for the purposes of error checking. */
int first_line;
@@ -261,7 +273,13 @@
int c,n; /* c: current capacity of list (malloc'd memory); n: current number of elements in list */
private:
- symbol_c **elements;
+// symbol_c **elements;
+ typedef struct {
+ const char *token_value;
+ symbol_c *symbol;
+ } element_entry_t;
+ element_entry_t *elements;
+
public:
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 */
@@ -274,12 +292,20 @@
);
/* get element in position pos of the list */
virtual symbol_c *get_element(int pos);
+ /* find element associated to token value */
+ virtual symbol_c *find_element(symbol_c *token);
+ virtual symbol_c *find_element(const char *token_value);
/* append a new element to the end of the list */
virtual void add_element(symbol_c *elem);
+ virtual void add_element(symbol_c *elem, symbol_c *token);
+ virtual void add_element(symbol_c *elem, const char *token_value);
/* insert a new element before position pos. */
/* To insert into the begining of list, call with pos=0 */
/* To insert into the end of list, call with pos=list->n */
- virtual void insert_element(symbol_c *elem, int pos = 0);
+ virtual void insert_element(symbol_c *elem, const char *token_value, int pos = 0);
+ virtual void insert_element(symbol_c *elem, symbol_c *token, int pos = 0);
+ virtual void insert_element(symbol_c *elem, int pos = 0);
+ //virtual void insert_element(symbol_c *elem, int pos, std::string map_ref);
/* remove element at position pos. */
virtual void remove_element(int pos = 0);
/* remove all elements from list. Does not delete the elements in the list! */