absyntax/absyntax.cc
changeset 936 0f7bcc160568
parent 889 5f380b99e95e
child 958 7474d2cd1d6e
equal deleted inserted replaced
935:be4373d07201 936:0f7bcc160568
    54   this->first_order  = first_order;
    54   this->first_order  = first_order;
    55   this->last_file    = lfile,
    55   this->last_file    = lfile,
    56   this->last_line    = last_line;
    56   this->last_line    = last_line;
    57   this->last_column  = last_column;
    57   this->last_column  = last_column;
    58   this->last_order   = last_order;
    58   this->last_order   = last_order;
       
    59   this->parent       = NULL;
    59   this->datatype     = NULL;
    60   this->datatype     = NULL;
    60   this->scope        = NULL;
    61   this->scope        = NULL;
    61   this->const_value._real64.status   = cs_undefined;
    62   this->const_value._real64.status   = cs_undefined;
    62   this->const_value._int64.status    = cs_undefined;
    63   this->const_value._int64.status    = cs_undefined;
    63   this->const_value._uint64.status   = cs_undefined;
    64   this->const_value._uint64.status   = cs_undefined;
   108     if (!(elements=(symbol_c**)realloc(elements,(c+=LIST_CAP_INCR)*sizeof(symbol_c *))))
   109     if (!(elements=(symbol_c**)realloc(elements,(c+=LIST_CAP_INCR)*sizeof(symbol_c *))))
   109       ERROR_MSG("out of memory");
   110       ERROR_MSG("out of memory");
   110   elements[n++] = elem;
   111   elements[n++] = elem;
   111  
   112  
   112   if (NULL == elem) return;
   113   if (NULL == elem) return;
       
   114   /* Sometimes add_element() is called in stage3 or stage4 to temporarily add an AST symbol to the list.
       
   115    * Since this symbol already belongs in some other place in the aST, it will have the 'parent' pointer set, 
       
   116    * and so we must not overwrite it. We only set the 'parent' pointer on new symbols that have the 'parent'
       
   117    * pointer still set to NULL.
       
   118    */
       
   119   if (NULL == elem->parent) elem->parent = this;  
   113 
   120 
   114   /* adjust the location parameters, taking into account the new element. */
   121   /* adjust the location parameters, taking into account the new element. */
   115   if (NULL == first_file) {
   122   if (NULL == first_file) {
   116     first_file = elem->first_file;
   123     first_file = elem->first_file;
   117     first_line = elem->first_line;
   124     first_line = elem->first_line;
   197 class_name_c::class_name_c(symbol_c *ref1,							\
   204 class_name_c::class_name_c(symbol_c *ref1,							\
   198                            int fl, int fc, const char *ffile, long int forder,			\
   205                            int fl, int fc, const char *ffile, long int forder,			\
   199                            int ll, int lc, const char *lfile, long int lorder)			\
   206                            int ll, int lc, const char *lfile, long int lorder)			\
   200 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   207 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   201   this->ref1 = ref1;										\
   208   this->ref1 = ref1;										\
       
   209   if  (NULL != ref1)   ref1->parent = this;							\
   202 }												\
   210 }												\
   203 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   211 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   204 
   212 
   205 
   213 
   206 #define SYM_REF2(class_name_c, ref1, ref2, ...)							\
   214 #define SYM_REF2(class_name_c, ref1, ref2, ...)							\
   209                            int fl, int fc, const char *ffile, long int forder,			\
   217                            int fl, int fc, const char *ffile, long int forder,			\
   210                            int ll, int lc, const char *lfile, long int lorder)			\
   218                            int ll, int lc, const char *lfile, long int lorder)			\
   211 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   219 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   212   this->ref1 = ref1;										\
   220   this->ref1 = ref1;										\
   213   this->ref2 = ref2;										\
   221   this->ref2 = ref2;										\
       
   222   if  (NULL != ref1)   ref1->parent = this;							\
       
   223   if  (NULL != ref2)   ref2->parent = this;										\
   214 }												\
   224 }												\
   215 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   225 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   216 
   226 
   217 
   227 
   218 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)						\
   228 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)						\
   223                            int ll, int lc, const char *lfile, long int lorder)			\
   233                            int ll, int lc, const char *lfile, long int lorder)			\
   224 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   234 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   225   this->ref1 = ref1;										\
   235   this->ref1 = ref1;										\
   226   this->ref2 = ref2;										\
   236   this->ref2 = ref2;										\
   227   this->ref3 = ref3;										\
   237   this->ref3 = ref3;										\
       
   238   if  (NULL != ref1)   ref1->parent = this;							\
       
   239   if  (NULL != ref2)   ref2->parent = this;							\
       
   240   if  (NULL != ref3)   ref3->parent = this;							\
   228 }												\
   241 }												\
   229 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   242 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   230 
   243 
   231 
   244 
   232 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)					\
   245 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)					\
   239 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   252 			  :symbol_c(fl, fc, ffile, forder, ll, lc, lfile, lorder) {		\
   240   this->ref1 = ref1;										\
   253   this->ref1 = ref1;										\
   241   this->ref2 = ref2;										\
   254   this->ref2 = ref2;										\
   242   this->ref3 = ref3;										\
   255   this->ref3 = ref3;										\
   243   this->ref4 = ref4;										\
   256   this->ref4 = ref4;										\
       
   257   if  (NULL != ref1)   ref1->parent = this;							\
       
   258   if  (NULL != ref2)   ref2->parent = this;							\
       
   259   if  (NULL != ref3)   ref3->parent = this;							\
       
   260   if  (NULL != ref4)   ref4->parent = this;							\
   244 }												\
   261 }												\
   245 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   262 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   246 
   263 
   247 
   264 
   248 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)				\
   265 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)				\
   257   this->ref1 = ref1;										\
   274   this->ref1 = ref1;										\
   258   this->ref2 = ref2;										\
   275   this->ref2 = ref2;										\
   259   this->ref3 = ref3;										\
   276   this->ref3 = ref3;										\
   260   this->ref4 = ref4;										\
   277   this->ref4 = ref4;										\
   261   this->ref5 = ref5;										\
   278   this->ref5 = ref5;										\
       
   279   if  (NULL != ref1)   ref1->parent = this;							\
       
   280   if  (NULL != ref2)   ref2->parent = this;							\
       
   281   if  (NULL != ref3)   ref3->parent = this;							\
       
   282   if  (NULL != ref4)   ref4->parent = this;							\
       
   283   if  (NULL != ref5)   ref5->parent = this;							\
   262 }												\
   284 }												\
   263 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   285 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   264 
   286 
   265 
   287 
   266 
   288 
   278   this->ref2 = ref2;										\
   300   this->ref2 = ref2;										\
   279   this->ref3 = ref3;										\
   301   this->ref3 = ref3;										\
   280   this->ref4 = ref4;										\
   302   this->ref4 = ref4;										\
   281   this->ref5 = ref5;										\
   303   this->ref5 = ref5;										\
   282   this->ref6 = ref6;										\
   304   this->ref6 = ref6;										\
       
   305   if  (NULL != ref1)   ref1->parent = this;							\
       
   306   if  (NULL != ref2)   ref2->parent = this;							\
       
   307   if  (NULL != ref3)   ref3->parent = this;							\
       
   308   if  (NULL != ref4)   ref4->parent = this;							\
       
   309   if  (NULL != ref5)   ref5->parent = this;							\
       
   310   if  (NULL != ref6)   ref6->parent = this;							\
   283 }												\
   311 }												\
   284 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   312 void *class_name_c::accept(visitor_c &visitor) {return visitor.visit(this);}
   285 
   313 
   286 
   314 
   287 
   315