absyntax_utils/decompose_var_instance_name.cc
changeset 826 1e6bf9839ece
parent 825 6658fc039264
equal deleted inserted replaced
825:6658fc039264 826:1e6bf9839ece
    50 decompose_var_instance_name_c::decompose_var_instance_name_c(symbol_c *variable_instance_name) {
    50 decompose_var_instance_name_c::decompose_var_instance_name_c(symbol_c *variable_instance_name) {
    51   variable_name = variable_instance_name;
    51   variable_name = variable_instance_name;
    52   next_variable_name = NULL;
    52   next_variable_name = NULL;
    53   current_recursive_variable_name = NULL;
    53   current_recursive_variable_name = NULL;
    54   previously_returned_variable_name = NULL;
    54   previously_returned_variable_name = NULL;
       
    55   current_array_subscript_list = NULL;
    55 }
    56 }
    56 
    57 
    57 symbol_c *decompose_var_instance_name_c::next_part() {
    58 /* Get the next element in the strcutured variable */
       
    59 symbol_c *decompose_var_instance_name_c::get_next() {
    58   /* We must always start from the top!
    60   /* We must always start from the top!
    59    * See note in the structured_variable_c visitor
    61    * See note in the structured_variable_c visitor
    60    * to understand why...
    62    * to understand why...
    61    */
    63    */
       
    64   current_array_subscript_list = NULL;
    62   symbol_c *res = (symbol_c *)variable_name->accept(*this);
    65   symbol_c *res = (symbol_c *)variable_name->accept(*this);
    63   next_variable_name = current_recursive_variable_name;
    66   next_variable_name = current_recursive_variable_name;
    64 
    67 
    65   if (previously_returned_variable_name == res)
    68   if (previously_returned_variable_name == res)
    66     return NULL;
    69     return NULL;
    67   
    70   
    68   previously_returned_variable_name = res;
    71   previously_returned_variable_name = res;
    69   return res;
    72   return res;
    70 }
    73 }
       
    74 
       
    75 /* If the current element in the structured variable is an array, return its subscript_list, 
       
    76  * otherwise return NULL
       
    77  */
       
    78 list_c *decompose_var_instance_name_c::get_current_arraysubs_list(void) {return current_array_subscript_list;}
    71 
    79 
    72 /*************************/
    80 /*************************/
    73 /* B.1 - Common elements */
    81 /* B.1 - Common elements */
    74 /*************************/
    82 /*************************/
    75 /*******************************************/
    83 /*******************************************/
    92 /* B.1.4.2   Multi-element Variables */
   100 /* B.1.4.2   Multi-element Variables */
    93 /*************************************/
   101 /*************************************/
    94 /*  subscripted_variable '[' subscript_list ']' */
   102 /*  subscripted_variable '[' subscript_list ']' */
    95 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
   103 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
    96 void *decompose_var_instance_name_c::visit(array_variable_c *symbol) {
   104 void *decompose_var_instance_name_c::visit(array_variable_c *symbol) {
    97   /* NOTE: the subscripted_variable may itself be a structure!,
   105   if (NULL == symbol->subscript_list) ERROR; // array may not have an empty subscript list!
    98    * so we must recursevily visit!
   106   current_array_subscript_list = dynamic_cast<list_c *>(symbol->subscript_list);
       
   107   if (NULL == current_array_subscript_list) ERROR; // if it does not point to a subscript_list_c, then the abstract syntax tree has been changed, and this code needs to be fixed accordingly!
       
   108   
       
   109   /* NOTE: the subscripted_variable may itself be a structure or an array!, so we must recursevily visit! */
       
   110   /* the next line will call either:
       
   111    *   - visit(structured_variable_c *) or visit(array_variable_c *), if the array variable is itself an element of another array os structure
       
   112    *   - visit(symbolic_variable_c *) if it is a simple array variable
    99    */
   113    */
   100   return symbol->subscripted_variable->accept(*this);
   114   return symbol->subscripted_variable->accept(*this);
   101 }
   115 }
   102 
   116 
   103 /*  record_variable '.' field_selector */
   117 /*  record_variable '.' field_selector */
   128   /* The correct code, is therefore more complex... */
   142   /* The correct code, is therefore more complex... */
   129   if (next_variable_name == symbol) {
   143   if (next_variable_name == symbol) {
   130     return (void *)symbol->field_selector->accept(*this);
   144     return (void *)symbol->field_selector->accept(*this);
   131   }
   145   }
   132 
   146 
       
   147   current_array_subscript_list = NULL;
   133   current_recursive_variable_name = symbol;
   148   current_recursive_variable_name = symbol;
   134   return symbol->record_variable->accept(*this);
   149   /* the next line will call either:
       
   150    *   - visit(structured_variable_c *) or visit(array_variable_c *), if the record variable has more elements to visit
       
   151    *   - visit(symbolic_variable_c *) if it is the last element in the record variable
       
   152    */
       
   153   return symbol->record_variable->accept(*this); 
   135 }
   154 }
   136 
   155 
   137 /********************************/
   156 /********************************/
   138 /* B 2.2 - Operators */
   157 /* B 2.2 - Operators */
   139 /********************************/
   158 /********************************/