absyntax_utils/function_param_iterator.cc
changeset 424 43d73e28eca8
parent 350 2c3c4dc34979
child 426 78f31e12fc52
equal deleted inserted replaced
423:f4a2d400ddbd 424:43d73e28eca8
   204 void function_param_iterator_c::reset(void) {
   204 void function_param_iterator_c::reset(void) {
   205   next_param = param_count = 0;
   205   next_param = param_count = 0;
   206   _first_extensible_param_index = -1;
   206   _first_extensible_param_index = -1;
   207   current_param_is_extensible = false;
   207   current_param_is_extensible = false;
   208   current_param_name = NULL;
   208   current_param_name = NULL;
   209   current_param_type = current_param_default_value = NULL;
   209   current_param_type = NULL;
       
   210   current_param_default_value = NULL;
       
   211   last_returned_parameter = NULL; /* the last parameter returned by search() or next() */
   210 }
   212 }
   211 
   213 
   212 
   214 
   213 /* initialise the iterator object.
   215 /* initialise the iterator object.
   214  * We must be given a reference to one of the following
   216  * We must be given a reference to one of the following
   246   if (current_param_is_extensible) {
   248   if (current_param_is_extensible) {
   247     current_extensible_param_index++;
   249     current_extensible_param_index++;
   248     return current_param_name;
   250     return current_param_name;
   249   }
   251   }
   250   
   252   
       
   253   last_returned_parameter = NULL; 
   251   param_count = 0;
   254   param_count = 0;
   252   en_eno_param_implicit = false;
   255   en_eno_param_implicit = false;
   253   next_param++;
   256   next_param++;
   254   current_operation = function_param_iterator_c::iterate_op;
   257   current_operation = function_param_iterator_c::iterate_op;
   255   res = f_decl->accept(*this);
   258   res = f_decl->accept(*this);
   266   }
   269   }
   267   identifier = dynamic_cast<identifier_c *>(sym);
   270   identifier = dynamic_cast<identifier_c *>(sym);
   268   if (identifier == NULL)
   271   if (identifier == NULL)
   269     ERROR;
   272     ERROR;
   270   current_param_name = identifier;
   273   current_param_name = identifier;
       
   274   last_returned_parameter = current_param_name; 
   271   return current_param_name;
   275   return current_param_name;
   272 }
   276 }
   273 
   277 
   274 /* Search for the value passed to the parameter named <param_name>...  */
   278 /* Search for the value passed to the parameter named <param_name>...  */
   275 identifier_c *function_param_iterator_c::search(symbol_c *param_name) {
   279 identifier_c *function_param_iterator_c::search(symbol_c *param_name) {
   279   en_eno_param_implicit = false;
   283   en_eno_param_implicit = false;
   280   current_param_is_extensible = false;
   284   current_param_is_extensible = false;
   281   current_operation = function_param_iterator_c::search_op;
   285   current_operation = function_param_iterator_c::search_op;
   282   void *res = f_decl->accept(*this);
   286   void *res = f_decl->accept(*this);
   283   identifier_c *res_param_name = dynamic_cast<identifier_c *>((symbol_c *)res);
   287   identifier_c *res_param_name = dynamic_cast<identifier_c *>((symbol_c *)res);
       
   288   last_returned_parameter = res_param_name; 
   284   return res_param_name;
   289   return res_param_name;
   285 }
   290 }
   286 
   291 
   287 /* Returns the currently referenced parameter's default value,
   292 /* Returns the currently referenced parameter's default value,
   288  * or NULL if none is specified in the function declrataion itself.
   293  * or NULL if none is specified in the function declrataion itself.
   289  */
   294  */
   290 symbol_c *function_param_iterator_c::default_value(void) {
   295 symbol_c *function_param_iterator_c::default_value(void) {
       
   296   if (NULL == last_returned_parameter) 
       
   297     return NULL;
   291   return current_param_default_value;
   298   return current_param_default_value;
   292 }
   299 }
   293 
   300 
   294 /* Returns the currently referenced parameter's type name. */
   301 /* Returns the currently referenced parameter's type name. */
   295 symbol_c *function_param_iterator_c::param_type(void) {
   302 symbol_c *function_param_iterator_c::param_type(void) {
       
   303   if (NULL == last_returned_parameter) 
       
   304     return NULL;
   296   return current_param_type;
   305   return current_param_type;
   297 }
   306 }
   298 
   307 
   299 /* Returns if currently referenced parameter is an implicit defined EN/ENO parameter. */
   308 /* Returns if currently referenced parameter is an implicit defined EN/ENO parameter. */
   300 bool function_param_iterator_c::is_en_eno_param_implicit(void) {
   309 bool function_param_iterator_c::is_en_eno_param_implicit(void) {
       
   310   if (NULL == last_returned_parameter) 
       
   311     ERROR;
   301   return en_eno_param_implicit;
   312   return en_eno_param_implicit;
   302 }
   313 }
   303 
   314 
   304 /* Returns if currently referenced parameter is an extensible parameter. */
   315 /* Returns if currently referenced parameter is an extensible parameter. */
   305 /* extensible paramters only occur in some standard functions, e.g. AND(word#34, word#44, word#65); */
   316 /* extensible paramters only occur in some standard functions, e.g. AND(word#34, word#44, word#65); */
   306 bool function_param_iterator_c::is_extensible_param(void) {
   317 bool function_param_iterator_c::is_extensible_param(void) {
       
   318   if (NULL == last_returned_parameter) 
       
   319     ERROR;
   307   return current_param_is_extensible;
   320   return current_param_is_extensible;
   308 }
   321 }
   309 
   322 
   310 /* Returns the index of the current extensible parameter. */             
   323 /* Returns the index of the current extensible parameter. */             
   311 /* If the current parameter is not an extensible paramter, returns -1 */
   324 /* If the current parameter is not an extensible paramter, returns -1 */
   312 int function_param_iterator_c::extensible_param_index(void) {
   325 int function_param_iterator_c::extensible_param_index(void) {
       
   326   if (NULL == last_returned_parameter) 
       
   327     ERROR;
   313   return (current_param_is_extensible? current_extensible_param_index : -1);
   328   return (current_param_is_extensible? current_extensible_param_index : -1);
   314 }
   329 }
   315 
   330 
   316 /* Returns the index of the first extensible parameter, or -1 if no extensible parameter found. */             
   331 /* Returns the index of the first extensible parameter, or -1 if no extensible parameter found. */             
   317 /* WARNING: Will only return the correct value _after_ an extensible parameter has been found! */
   332 /* WARNING: Will only return the correct value _after_ an extensible parameter has been found! */
   321 
   336 
   322 /* Returns the currently referenced parameter's data passing direction.
   337 /* Returns the currently referenced parameter's data passing direction.
   323  * i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT
   338  * i.e. VAR_INPUT, VAR_OUTPUT or VAR_INOUT
   324  */
   339  */
   325 function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) {
   340 function_param_iterator_c::param_direction_t function_param_iterator_c::param_direction(void) {
       
   341   if (NULL == last_returned_parameter) 
       
   342     ERROR;
   326   return current_param_direction;
   343   return current_param_direction;
   327 }
   344 }
   328 
   345 
   329 void *function_param_iterator_c::visit(implicit_definition_c *symbol) {
   346 void *function_param_iterator_c::visit(implicit_definition_c *symbol) {
   330 	en_eno_param_implicit = true;
   347 	en_eno_param_implicit = true;