absyntax_utils/array_dimension_iterator.cc
changeset 849 1f8885ae539a
parent 840 60cea9fea6e6
child 1041 56ebe2a31b5b
--- a/absyntax_utils/array_dimension_iterator.cc	Fri Jul 19 13:31:35 2013 +0100
+++ b/absyntax_utils/array_dimension_iterator.cc	Fri Aug 23 15:13:11 2013 +0100
@@ -82,12 +82,19 @@
  */
 array_dimension_iterator_c::array_dimension_iterator_c(symbol_c *symbol) {
   /* do some consistency check... */
-  array_specification_c* array_spec = dynamic_cast<array_specification_c*>(symbol);
-
-  if (NULL == array_spec) ERROR;
+  /* NOTE: We comment out the consistency check so the compiler does not bork when it encounters buggy source code.
+   *        e.g. Code that handles a non array variable as an array!
+   *               VAR  v1, v2: int; END_VAR
+   *               v1 := v2[33, 45];
+   *       The above error will be caught by the datatype checking algorithms!
+   */
+  array_spec_init_c    * array_spec_init = dynamic_cast<array_spec_init_c    *>(symbol); 
+  if (NULL != array_spec_init)    symbol = array_spec_init->array_specification;
+  array_specification_c* array_spec      = dynamic_cast<array_specification_c*>(symbol);
+  // if (NULL == array_spec) ERROR;
 
   /* OK. Now initialize this object... */
-  this->array_specification = symbol;
+  this->array_specification = array_spec; // Set to array_spec and not symbol => will be NULL if not an array_specification_c* !!
   reset();
 }
 
@@ -101,9 +108,9 @@
  * Returns the subrange symbol!
  */
 subrange_c *array_dimension_iterator_c::next(void) {
+  if (NULL == array_specification) return NULL; /* The source code probably has a bug which will be caught somewhere else! */
   void *res = array_specification->accept(*this);
-  if (res == NULL) 
-    return NULL;
+  if (NULL == res)                 return NULL;
 
   return current_array_dimension;
 }