absyntax_utils/array_dimension_iterator.cc
changeset 830 6f45ec6ed011
parent 596 4efb11e44065
child 840 60cea9fea6e6
equal deleted inserted replaced
829:6e39eea5f5d0 830:6f45ec6ed011
    80 /* initialize the iterator object.
    80 /* initialize the iterator object.
    81  * We must be given a reference to a array_specification_c that will be analyzed...
    81  * We must be given a reference to a array_specification_c that will be analyzed...
    82  */
    82  */
    83 array_dimension_iterator_c::array_dimension_iterator_c(symbol_c *symbol) {
    83 array_dimension_iterator_c::array_dimension_iterator_c(symbol_c *symbol) {
    84   /* do some consistency check... */
    84   /* do some consistency check... */
       
    85   /* NOTE: We comment out the consistency check so the compiler does not bork when it encounters buggy source code.
       
    86    *        e.g. Code that handles a non array variable as an array!
       
    87    *               VAR  v1, v2: int; END_VAR
       
    88    *               v1 := v2[33, 45];
       
    89    *       The above error will be caught by the datatype checking algorithms!
       
    90    */
    85   array_specification_c* array_spec = dynamic_cast<array_specification_c*>(symbol);
    91   array_specification_c* array_spec = dynamic_cast<array_specification_c*>(symbol);
    86 
    92   // if (NULL == array_spec) ERROR;
    87   if (NULL == array_spec) ERROR;
       
    88 
    93 
    89   /* OK. Now initialize this object... */
    94   /* OK. Now initialize this object... */
    90   this->array_specification = symbol;
    95   this->array_specification = array_spec; // Set to array_spec and not symbol => will be NULL if not an array_specification_c* !!
    91   reset();
    96   reset();
    92 }
    97 }
    93 
    98 
    94 
    99 
    95 
   100 
    99  * reference the first subrange...
   104  * reference the first subrange...
   100  *
   105  *
   101  * Returns the subrange symbol!
   106  * Returns the subrange symbol!
   102  */
   107  */
   103 subrange_c *array_dimension_iterator_c::next(void) {
   108 subrange_c *array_dimension_iterator_c::next(void) {
       
   109   if (NULL == array_specification) return NULL; /* The source code probably has a bug which will be caught somewhere else! */
   104   void *res = array_specification->accept(*this);
   110   void *res = array_specification->accept(*this);
   105   if (res == NULL) 
   111   if (NULL == res)                 return NULL;
   106     return NULL;
       
   107 
   112 
   108   return current_array_dimension;
   113   return current_array_dimension;
   109 }
   114 }
   110 
   115 
   111 /********************************/
   116 /********************************/