Add capability of returning array subscript list while decomposing a struct/array variable.
authormjsousa
Mon, 05 Aug 2013 15:57:00 +0100
changeset 826 1e6bf9839ece
parent 825 6658fc039264
child 827 e3800aff352c
Add capability of returning array subscript list while decomposing a struct/array variable.
absyntax_utils/decompose_var_instance_name.cc
absyntax_utils/decompose_var_instance_name.hh
stage3/lvalue_check.cc
--- a/absyntax_utils/decompose_var_instance_name.cc	Mon Aug 05 08:26:30 2013 +0100
+++ b/absyntax_utils/decompose_var_instance_name.cc	Mon Aug 05 15:57:00 2013 +0100
@@ -52,13 +52,16 @@
   next_variable_name = NULL;
   current_recursive_variable_name = NULL;
   previously_returned_variable_name = NULL;
+  current_array_subscript_list = NULL;
 }
 
-symbol_c *decompose_var_instance_name_c::next_part() {
+/* Get the next element in the strcutured variable */
+symbol_c *decompose_var_instance_name_c::get_next() {
   /* We must always start from the top!
    * See note in the structured_variable_c visitor
    * to understand why...
    */
+  current_array_subscript_list = NULL;
   symbol_c *res = (symbol_c *)variable_name->accept(*this);
   next_variable_name = current_recursive_variable_name;
 
@@ -69,6 +72,11 @@
   return res;
 }
 
+/* If the current element in the structured variable is an array, return its subscript_list, 
+ * otherwise return NULL
+ */
+list_c *decompose_var_instance_name_c::get_current_arraysubs_list(void) {return current_array_subscript_list;}
+
 /*************************/
 /* B.1 - Common elements */
 /*************************/
@@ -94,8 +102,14 @@
 /*  subscripted_variable '[' subscript_list ']' */
 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
 void *decompose_var_instance_name_c::visit(array_variable_c *symbol) {
-  /* NOTE: the subscripted_variable may itself be a structure!,
-   * so we must recursevily visit!
+  if (NULL == symbol->subscript_list) ERROR; // array may not have an empty subscript list!
+  current_array_subscript_list = dynamic_cast<list_c *>(symbol->subscript_list);
+  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!
+  
+  /* NOTE: the subscripted_variable may itself be a structure or an array!, so we must recursevily visit! */
+  /* the next line will call either:
+   *   - visit(structured_variable_c *) or visit(array_variable_c *), if the array variable is itself an element of another array os structure
+   *   - visit(symbolic_variable_c *) if it is a simple array variable
    */
   return symbol->subscripted_variable->accept(*this);
 }
@@ -130,8 +144,13 @@
     return (void *)symbol->field_selector->accept(*this);
   }
 
+  current_array_subscript_list = NULL;
   current_recursive_variable_name = symbol;
-  return symbol->record_variable->accept(*this);
+  /* the next line will call either:
+   *   - visit(structured_variable_c *) or visit(array_variable_c *), if the record variable has more elements to visit
+   *   - visit(symbolic_variable_c *) if it is the last element in the record variable
+   */
+  return symbol->record_variable->accept(*this); 
 }
 
 /********************************/
--- a/absyntax_utils/decompose_var_instance_name.hh	Mon Aug 05 08:26:30 2013 +0100
+++ b/absyntax_utils/decompose_var_instance_name.hh	Mon Aug 05 15:57:00 2013 +0100
@@ -74,11 +74,14 @@
     symbol_c *next_variable_name;
     symbol_c *current_recursive_variable_name;
     symbol_c *previously_returned_variable_name;
+    list_c   *current_array_subscript_list;
 
   public:
     decompose_var_instance_name_c(symbol_c *variable_instance_name);
-
-    symbol_c *next_part(void);
+    /* Get the next element in the strcutured variable */
+    symbol_c *get_next(void);
+    /* If the current element in the structured variable is an array, return its subscript_list, otherwise return NULL */
+    list_c *get_current_arraysubs_list(void);
 
   private:
   /*************************/
--- a/stage3/lvalue_check.cc	Mon Aug 05 08:26:30 2013 +0100
+++ b/stage3/lvalue_check.cc	Mon Aug 05 15:57:00 2013 +0100
@@ -114,7 +114,7 @@
 	 * when an expression is found, we may replace this check with an assertion...
 	 * if (NULL == struct_elem) ERROR;
 	 */
-	symbol_c *struct_elem = decompose_lvalue.next_part();
+	symbol_c *struct_elem = decompose_lvalue.get_next();
 	if (NULL == struct_elem) return;
 	
 	symbol_c *type_decl   = search_var_instance_decl->get_decl(struct_elem);
@@ -135,7 +135,7 @@
 	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(basetype_id);
 	if (function_block_type_symtable.end_value() == fb_decl) return;
 
-	while (NULL != (struct_elem = decompose_lvalue.next_part())) {
+	while (NULL != (struct_elem = decompose_lvalue.get_next())) {
 		search_var_instance_decl_c   fb_search_var_instance_decl(fb_decl);
 		if (search_var_instance_decl_c::output_vt == fb_search_var_instance_decl.get_vartype(struct_elem)) {
 			STAGE3_ERROR(0, struct_elem, struct_elem, "Assignment to FB output variable is not allowed.");