absyntax/visitor.cc
changeset 680 df783da3ebe2
parent 417 d48f53715f77
child 738 e47cc8c954db
equal deleted inserted replaced
679:2f5618c0039a 680:df783da3ebe2
   116 
   116 
   117 
   117 
   118 
   118 
   119 
   119 
   120 
   120 
   121 /**********************/
   121 
   122 /* iterator_visitor_c */
   122 /*******************/
   123 /**********************/
   123 /* fcall_visitor_c */
   124 
   124 /*******************/
   125 iterator_visitor_c::~iterator_visitor_c(void) {return;}
   125 
   126 
   126 //fcall_visitor_c::~fcall_visitor_c(void) {return;};
   127 
   127 
   128 void *iterator_visitor_c::visit_list(list_c *list) {
   128 
   129   for(int i = 0; i < list->n; i++) {
   129 // void fcall_visitor_c::fcall(symbol_c *symbol) {return;};
   130     list->elements[i]->accept(*this);
   130 
   131   }
   131 #define VISIT_METHOD {fcall(symbol); return NULL;}
   132   return NULL;
   132 
   133 }
   133 #define SYM_LIST(class_name_c, ...)                                             void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   134 
   134 #define SYM_TOKEN(class_name_c, ...)                                            void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   135 
   135 #define SYM_REF0(class_name_c, ...)                                             void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   136 #define SYM_LIST(class_name_c)	\
   136 #define SYM_REF1(class_name_c, ref1, ...)                                       void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   137   void *iterator_visitor_c::visit(class_name_c *symbol) {return visit_list(symbol);}
   137 #define SYM_REF2(class_name_c, ref1, ref2, ...)                                 void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   138 
   138 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)                           void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   139 #define SYM_TOKEN(class_name_c, ...)	\
   139 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)                     void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   140   void *iterator_visitor_c::visit(class_name_c *symbol) {return NULL;}
   140 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)               void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   141 
   141 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6, ...)         void *fcall_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
   142 #define SYM_REF0(class_name_c, ...)	\
   142 
   143   void *iterator_visitor_c::visit(class_name_c *symbol) {return NULL;}
   143 #include "../absyntax/absyntax.def"
   144 
   144 
   145 #define SYM_REF1(class_name_c, ref1, ...)			\
   145 #undef VISIT_METHOD
   146 void *iterator_visitor_c::visit(class_name_c *symbol) {	\
       
   147   if (symbol->ref1!=NULL) symbol->ref1->accept(*this);	\
       
   148   return NULL;						\
       
   149 }
       
   150 
       
   151 #define SYM_REF2(class_name_c, ref1, ref2, ...)		\
       
   152 void *iterator_visitor_c::visit(class_name_c *symbol) {	\
       
   153   if (symbol->ref1!=NULL) symbol->ref1->accept(*this);	\
       
   154   if (symbol->ref2!=NULL) symbol->ref2->accept(*this);	\
       
   155   return NULL;						\
       
   156 }
       
   157 
       
   158 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)			\
       
   159 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
       
   160   if (symbol->ref1) symbol->ref1->accept(*this);			\
       
   161   if (symbol->ref2) symbol->ref2->accept(*this);			\
       
   162   if (symbol->ref3) symbol->ref3->accept(*this);			\
       
   163   return NULL;								\
       
   164 }
       
   165 
       
   166 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)		\
       
   167 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
       
   168   if (symbol->ref1) symbol->ref1->accept(*this);			\
       
   169   if (symbol->ref2) symbol->ref2->accept(*this);			\
       
   170   if (symbol->ref3) symbol->ref3->accept(*this);			\
       
   171   if (symbol->ref4) symbol->ref4->accept(*this);			\
       
   172   return NULL;								\
       
   173 }
       
   174 
       
   175 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)	\
       
   176 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
       
   177   if (symbol->ref1) symbol->ref1->accept(*this);			\
       
   178   if (symbol->ref2) symbol->ref2->accept(*this);			\
       
   179   if (symbol->ref3) symbol->ref3->accept(*this);			\
       
   180   if (symbol->ref4) symbol->ref4->accept(*this);			\
       
   181   if (symbol->ref5) symbol->ref5->accept(*this);			\
       
   182   return NULL;								\
       
   183 }
       
   184 
       
   185 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6, ...)	\
       
   186 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
       
   187   if (symbol->ref1) symbol->ref1->accept(*this);			\
       
   188   if (symbol->ref2) symbol->ref2->accept(*this);			\
       
   189   if (symbol->ref3) symbol->ref3->accept(*this);			\
       
   190   if (symbol->ref4) symbol->ref4->accept(*this);			\
       
   191   if (symbol->ref5) symbol->ref5->accept(*this);			\
       
   192   if (symbol->ref6) symbol->ref6->accept(*this);			\
       
   193   return NULL;								\
       
   194 }
       
   195 
       
   196 
       
   197 
       
   198 #include "absyntax.def"
       
   199 
       
   200 
       
   201 
   146 
   202 #undef SYM_LIST
   147 #undef SYM_LIST
   203 #undef SYM_TOKEN
   148 #undef SYM_TOKEN
   204 #undef SYM_REF0
   149 #undef SYM_REF0
   205 #undef SYM_REF1
   150 #undef SYM_REF1
   212 
   157 
   213 
   158 
   214 
   159 
   215 
   160 
   216 
   161 
   217 
   162 /**********************/
   218 
   163 /* iterator_visitor_c */
   219 
   164 /**********************/
   220 
   165 
   221 /********************/
   166 iterator_visitor_c::~iterator_visitor_c(void) {return;}
   222 /* search_visitor_c */
   167 
   223 /********************/
   168 
   224 
   169 void *iterator_visitor_c::visit_list(list_c *list) {
   225 search_visitor_c::~search_visitor_c(void) {return;}
       
   226 
       
   227 
       
   228 void *search_visitor_c::visit_list(list_c *list) {
       
   229   for(int i = 0; i < list->n; i++) {
   170   for(int i = 0; i < list->n; i++) {
   230     void *res = list->elements[i]->accept(*this);
   171     list->elements[i]->accept(*this);
   231     if (res != NULL)
       
   232       return res;
       
   233   }
   172   }
   234   return NULL;
   173   return NULL;
   235 }
   174 }
   236 
   175 
   237 
   176 
   238 #define SYM_LIST(class_name_c)	\
   177 #define SYM_LIST(class_name_c)	\
   239   void *search_visitor_c::visit(class_name_c *symbol) {return visit_list(symbol);}
   178   void *iterator_visitor_c::visit(class_name_c *symbol) {return visit_list(symbol);}
   240 
   179 
   241 #define SYM_TOKEN(class_name_c, ...)	\
   180 #define SYM_TOKEN(class_name_c, ...)	\
   242   void *search_visitor_c::visit(class_name_c *symbol) {return NULL;}
   181   void *iterator_visitor_c::visit(class_name_c *symbol) {return NULL;}
   243 
   182 
   244 #define SYM_REF0(class_name_c, ...)	\
   183 #define SYM_REF0(class_name_c, ...)	\
   245   void *search_visitor_c::visit(class_name_c *symbol) {return NULL;}
   184   void *iterator_visitor_c::visit(class_name_c *symbol) {return NULL;}
   246 
   185 
   247 #define SYM_REF1(class_name_c, ref1, ...)				\
   186 #define SYM_REF1(class_name_c, ref1, ...)			\
   248 void *search_visitor_c::visit(class_name_c *symbol) {		\
   187 void *iterator_visitor_c::visit(class_name_c *symbol) {	\
   249   if (symbol->ref1) return symbol->ref1->accept(*this);		\
   188   if (symbol->ref1!=NULL) symbol->ref1->accept(*this);	\
   250   return NULL;							\
   189   return NULL;						\
   251 }
   190 }
   252 
   191 
   253 #define SYM_REF2(class_name_c, ref1, ref2, ...)			\
   192 #define SYM_REF2(class_name_c, ref1, ref2, ...)		\
   254 void *search_visitor_c::visit(class_name_c *symbol) {		\
   193 void *iterator_visitor_c::visit(class_name_c *symbol) {	\
   255   void *res = NULL;						\
   194   if (symbol->ref1!=NULL) symbol->ref1->accept(*this);	\
   256   if (symbol->ref1) res =  symbol->ref1->accept(*this);		\
   195   if (symbol->ref2!=NULL) symbol->ref2->accept(*this);	\
   257   if (res != NULL)  return res;					\
   196   return NULL;						\
   258   if (symbol->ref2) return symbol->ref2->accept(*this);		\
   197 }
   259   return NULL;							\
   198 
   260 }
   199 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)			\
   261 
   200 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
   262 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)		\
   201   if (symbol->ref1) symbol->ref1->accept(*this);			\
   263 void *search_visitor_c::visit(class_name_c *symbol) {		\
   202   if (symbol->ref2) symbol->ref2->accept(*this);			\
   264   void *res = NULL;						\
   203   if (symbol->ref3) symbol->ref3->accept(*this);			\
   265   if (symbol->ref1) res =  symbol->ref1->accept(*this);		\
   204   return NULL;								\
   266   if (res != NULL)  return res;					\
       
   267   if (symbol->ref2) res =  symbol->ref2->accept(*this);		\
       
   268   if (res != NULL)  return res;					\
       
   269   if (symbol->ref3) return symbol->ref3->accept(*this);		\
       
   270   return NULL;							\
       
   271 }
   205 }
   272 
   206 
   273 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)		\
   207 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)		\
   274 void *search_visitor_c::visit(class_name_c *symbol) {		\
   208 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
   275   void *res = NULL;						\
   209   if (symbol->ref1) symbol->ref1->accept(*this);			\
   276   if (symbol->ref1) res =  symbol->ref1->accept(*this);		\
   210   if (symbol->ref2) symbol->ref2->accept(*this);			\
   277   if (res != NULL)  return res;					\
   211   if (symbol->ref3) symbol->ref3->accept(*this);			\
   278   if (symbol->ref2) res =  symbol->ref2->accept(*this);		\
   212   if (symbol->ref4) symbol->ref4->accept(*this);			\
   279   if (res != NULL)  return res;					\
   213   return NULL;								\
   280   if (symbol->ref3) res =  symbol->ref3->accept(*this);		\
   214 }
   281   if (res != NULL)  return res;					\
   215 
   282   if (symbol->ref4) return symbol->ref4->accept(*this);		\
   216 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)	\
   283   return NULL;							\
   217 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
   284 }
   218   if (symbol->ref1) symbol->ref1->accept(*this);			\
   285 
   219   if (symbol->ref2) symbol->ref2->accept(*this);			\
   286 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)		\
   220   if (symbol->ref3) symbol->ref3->accept(*this);			\
   287 void *search_visitor_c::visit(class_name_c *symbol) {			\
   221   if (symbol->ref4) symbol->ref4->accept(*this);			\
   288   void *res = NULL;							\
   222   if (symbol->ref5) symbol->ref5->accept(*this);			\
   289   if (symbol->ref1) res =  symbol->ref1->accept(*this);			\
       
   290   if (res != NULL)  return res;						\
       
   291   if (symbol->ref2) res =  symbol->ref2->accept(*this);			\
       
   292   if (res != NULL)  return res;						\
       
   293   if (symbol->ref3) res =  symbol->ref3->accept(*this);			\
       
   294   if (res != NULL)  return res;						\
       
   295   if (symbol->ref4) res =  symbol->ref4->accept(*this);			\
       
   296   if (res != NULL)  return res;						\
       
   297   if (symbol->ref5) return symbol->ref5->accept(*this);			\
       
   298   return NULL;								\
   223   return NULL;								\
   299 }
   224 }
   300 
   225 
   301 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6, ...)	\
   226 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6, ...)	\
   302 void *search_visitor_c::visit(class_name_c *symbol) {			\
   227 void *iterator_visitor_c::visit(class_name_c *symbol) {			\
   303   void *res = NULL;							\
   228   if (symbol->ref1) symbol->ref1->accept(*this);			\
   304   if (symbol->ref1) res =  symbol->ref1->accept(*this);			\
   229   if (symbol->ref2) symbol->ref2->accept(*this);			\
   305   if (res != NULL)  return res;						\
   230   if (symbol->ref3) symbol->ref3->accept(*this);			\
   306   if (symbol->ref2) res =  symbol->ref2->accept(*this);			\
   231   if (symbol->ref4) symbol->ref4->accept(*this);			\
   307   if (res != NULL)  return res;						\
   232   if (symbol->ref5) symbol->ref5->accept(*this);			\
   308   if (symbol->ref3) res =  symbol->ref3->accept(*this);			\
   233   if (symbol->ref6) symbol->ref6->accept(*this);			\
   309   if (res != NULL)  return res;						\
       
   310   if (symbol->ref4) res =  symbol->ref4->accept(*this);			\
       
   311   if (res != NULL)  return res;						\
       
   312   if (symbol->ref5) res =  symbol->ref5->accept(*this);			\
       
   313   if (res != NULL)  return res;						\
       
   314   if (symbol->ref6) return symbol->ref6->accept(*this);			\
       
   315   return NULL;								\
   234   return NULL;								\
   316 }
   235 }
   317 
   236 
   318 
   237 
   319 
   238 
   333 
   252 
   334 
   253 
   335 
   254 
   336 
   255 
   337 
   256 
   338 
   257 /****************************/
   339 
   258 /* fcall_iterator_visitor_c */
   340 
   259 /****************************/
   341 
   260 
   342 
   261 fcall_iterator_visitor_c::~fcall_iterator_visitor_c(void) {return;};
   343 
   262 
   344 
   263 void fcall_iterator_visitor_c::prefix_fcall(symbol_c *symbol) {return;};
       
   264 void fcall_iterator_visitor_c::suffix_fcall(symbol_c *symbol) {return;};
       
   265 
       
   266 #define VISIT_METHOD {\
       
   267   prefix_fcall(symbol);                \
       
   268   iterator_visitor_c::visit(symbol);   \
       
   269   suffix_fcall(symbol);                \
       
   270   return NULL;                         \
       
   271 }
       
   272 
       
   273 #define SYM_LIST(class_name_c, ...)                                             void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   274 #define SYM_TOKEN(class_name_c, ...)                                            void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   275 #define SYM_REF0(class_name_c, ...)                                             void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   276 #define SYM_REF1(class_name_c, ref1, ...)                                       void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   277 #define SYM_REF2(class_name_c, ref1, ref2, ...)                                 void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   278 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)                           void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   279 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)                     void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   280 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)               void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   281 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6, ...)         void *fcall_iterator_visitor_c::visit(class_name_c *symbol) VISIT_METHOD;
       
   282 
       
   283 #include "../absyntax/absyntax.def"
       
   284 
       
   285 #undef VISIT_METHOD
       
   286 
       
   287 #undef SYM_LIST
       
   288 #undef SYM_TOKEN
       
   289 #undef SYM_REF0
       
   290 #undef SYM_REF1
       
   291 #undef SYM_REF2
       
   292 #undef SYM_REF3
       
   293 #undef SYM_REF4
       
   294 #undef SYM_REF5
       
   295 #undef SYM_REF6
       
   296 
       
   297 
       
   298 
       
   299 
       
   300 
       
   301 
       
   302 
       
   303 
       
   304 /********************/
       
   305 /* search_visitor_c */
       
   306 /********************/
       
   307 
       
   308 search_visitor_c::~search_visitor_c(void) {return;}
       
   309 
       
   310 
       
   311 void *search_visitor_c::visit_list(list_c *list) {
       
   312   for(int i = 0; i < list->n; i++) {
       
   313     void *res = list->elements[i]->accept(*this);
       
   314     if (res != NULL)
       
   315       return res;
       
   316   }
       
   317   return NULL;
       
   318 }
       
   319 
       
   320 
       
   321 #define SYM_LIST(class_name_c)	\
       
   322   void *search_visitor_c::visit(class_name_c *symbol) {return visit_list(symbol);}
       
   323 
       
   324 #define SYM_TOKEN(class_name_c, ...)	\
       
   325   void *search_visitor_c::visit(class_name_c *symbol) {return NULL;}
       
   326 
       
   327 #define SYM_REF0(class_name_c, ...)	\
       
   328   void *search_visitor_c::visit(class_name_c *symbol) {return NULL;}
       
   329 
       
   330 #define SYM_REF1(class_name_c, ref1, ...)				\
       
   331 void *search_visitor_c::visit(class_name_c *symbol) {		\
       
   332   if (symbol->ref1) return symbol->ref1->accept(*this);		\
       
   333   return NULL;							\
       
   334 }
       
   335 
       
   336 #define SYM_REF2(class_name_c, ref1, ref2, ...)			\
       
   337 void *search_visitor_c::visit(class_name_c *symbol) {		\
       
   338   void *res = NULL;						\
       
   339   if (symbol->ref1) res =  symbol->ref1->accept(*this);		\
       
   340   if (res != NULL)  return res;					\
       
   341   if (symbol->ref2) return symbol->ref2->accept(*this);		\
       
   342   return NULL;							\
       
   343 }
       
   344 
       
   345 #define SYM_REF3(class_name_c, ref1, ref2, ref3, ...)		\
       
   346 void *search_visitor_c::visit(class_name_c *symbol) {		\
       
   347   void *res = NULL;						\
       
   348   if (symbol->ref1) res =  symbol->ref1->accept(*this);		\
       
   349   if (res != NULL)  return res;					\
       
   350   if (symbol->ref2) res =  symbol->ref2->accept(*this);		\
       
   351   if (res != NULL)  return res;					\
       
   352   if (symbol->ref3) return symbol->ref3->accept(*this);		\
       
   353   return NULL;							\
       
   354 }
       
   355 
       
   356 #define SYM_REF4(class_name_c, ref1, ref2, ref3, ref4, ...)		\
       
   357 void *search_visitor_c::visit(class_name_c *symbol) {		\
       
   358   void *res = NULL;						\
       
   359   if (symbol->ref1) res =  symbol->ref1->accept(*this);		\
       
   360   if (res != NULL)  return res;					\
       
   361   if (symbol->ref2) res =  symbol->ref2->accept(*this);		\
       
   362   if (res != NULL)  return res;					\
       
   363   if (symbol->ref3) res =  symbol->ref3->accept(*this);		\
       
   364   if (res != NULL)  return res;					\
       
   365   if (symbol->ref4) return symbol->ref4->accept(*this);		\
       
   366   return NULL;							\
       
   367 }
       
   368 
       
   369 #define SYM_REF5(class_name_c, ref1, ref2, ref3, ref4, ref5, ...)		\
       
   370 void *search_visitor_c::visit(class_name_c *symbol) {			\
       
   371   void *res = NULL;							\
       
   372   if (symbol->ref1) res =  symbol->ref1->accept(*this);			\
       
   373   if (res != NULL)  return res;						\
       
   374   if (symbol->ref2) res =  symbol->ref2->accept(*this);			\
       
   375   if (res != NULL)  return res;						\
       
   376   if (symbol->ref3) res =  symbol->ref3->accept(*this);			\
       
   377   if (res != NULL)  return res;						\
       
   378   if (symbol->ref4) res =  symbol->ref4->accept(*this);			\
       
   379   if (res != NULL)  return res;						\
       
   380   if (symbol->ref5) return symbol->ref5->accept(*this);			\
       
   381   return NULL;								\
       
   382 }
       
   383 
       
   384 #define SYM_REF6(class_name_c, ref1, ref2, ref3, ref4, ref5, ref6, ...)	\
       
   385 void *search_visitor_c::visit(class_name_c *symbol) {			\
       
   386   void *res = NULL;							\
       
   387   if (symbol->ref1) res =  symbol->ref1->accept(*this);			\
       
   388   if (res != NULL)  return res;						\
       
   389   if (symbol->ref2) res =  symbol->ref2->accept(*this);			\
       
   390   if (res != NULL)  return res;						\
       
   391   if (symbol->ref3) res =  symbol->ref3->accept(*this);			\
       
   392   if (res != NULL)  return res;						\
       
   393   if (symbol->ref4) res =  symbol->ref4->accept(*this);			\
       
   394   if (res != NULL)  return res;						\
       
   395   if (symbol->ref5) res =  symbol->ref5->accept(*this);			\
       
   396   if (res != NULL)  return res;						\
       
   397   if (symbol->ref6) return symbol->ref6->accept(*this);			\
       
   398   return NULL;								\
       
   399 }
       
   400 
       
   401 
       
   402 
       
   403 #include "absyntax.def"
       
   404 
       
   405 
       
   406 
       
   407 #undef SYM_LIST
       
   408 #undef SYM_TOKEN
       
   409 #undef SYM_REF0
       
   410 #undef SYM_REF1
       
   411 #undef SYM_REF2
       
   412 #undef SYM_REF3
       
   413 #undef SYM_REF4
       
   414 #undef SYM_REF5
       
   415 #undef SYM_REF6
       
   416 
       
   417 
       
   418 
       
   419 
       
   420 
       
   421 
       
   422 
       
   423 
       
   424 
       
   425 
       
   426 
       
   427