stage4/generate_c/generate_c.cc
changeset 852 efb44e892582
parent 816 dcd861dda04a
child 853 818c4ac5d64d
equal deleted inserted replaced
851:2c59c2b8fca4 852:efb44e892582
   332      *   WSTRING [ 42 ]
   332      *   WSTRING [ 42 ]
   333      */
   333      */
   334     void *visit(double_byte_string_var_declaration_c *symbol) {return NULL;}
   334     void *visit(double_byte_string_var_declaration_c *symbol) {return NULL;}
   335 };
   335 };
   336     
   336     
       
   337 
       
   338 /***********************************************************************/
       
   339 /***********************************************************************/
       
   340 /***********************************************************************/
       
   341 /***********************************************************************/
       
   342 
       
   343 /* A helper class that analyses if the datatype of a variable is 'complex'. */
       
   344 /* 'complex' means that it is either a strcuture or an array!               */
       
   345 class analyse_variable_c: public null_visitor_c {
       
   346   private:
       
   347     static analyse_variable_c *singleton_;
       
   348     bool   contains_complex_type_res;
       
   349 
       
   350   public:
       
   351     analyse_variable_c(void) {};
       
   352     
       
   353     static bool is_complex_type(symbol_c *symbol) {
       
   354       if (NULL == symbol)           ERROR;
       
   355       if (NULL == symbol->datatype) ERROR;
       
   356       return (   get_datatype_info_c::is_structure(symbol->datatype) 
       
   357               || get_datatype_info_c::is_array    (symbol->datatype) 
       
   358              );
       
   359     }
       
   360 
       
   361     /* returns true if a strcutured variable (e.g. fb1.fb2.strcut1.real) contains a structure or array */
       
   362     /* eg:
       
   363      *      fb1.fb2.fb3.real       returns FALSE
       
   364      *      fb1.fb2.struct1.real   returns TRUE
       
   365      *      struct1.real           returns TRUE
       
   366      */
       
   367     static bool contains_complex_type(symbol_c *symbol) {
       
   368       if (NULL == singleton_)       singleton_ = new analyse_variable_c();
       
   369       if (NULL == singleton_)       ERROR;
       
   370       if (NULL == symbol)           ERROR;
       
   371       if (NULL == symbol->datatype) ERROR;
       
   372       
       
   373       singleton_->contains_complex_type_res = false;
       
   374       symbol->accept(*singleton_);
       
   375       return singleton_->contains_complex_type_res;
       
   376     }
       
   377     
       
   378     
       
   379     /*************************************/
       
   380     /* B.1.4.2   Multi-element Variables */
       
   381     /*************************************/
       
   382     
       
   383     // SYM_REF2(structured_variable_c, record_variable, field_selector)
       
   384     void *visit(structured_variable_c *symbol) {
       
   385       symbol->record_variable->accept(*this);
       
   386       /* do not set the contains_complex_type_res to TRUE if this structured_variable_c is accessing a FB instance! */
       
   387       contains_complex_type_res |= get_datatype_info_c::is_structure(symbol->datatype);
       
   388       return NULL;
       
   389     }
       
   390     
       
   391     /*  subscripted_variable '[' subscript_list ']' */
       
   392     //SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
       
   393     void *visit(array_variable_c *symbol) {
       
   394       contains_complex_type_res |= true;
       
   395       return NULL;
       
   396     }
       
   397 
       
   398 };
       
   399 
       
   400 analyse_variable_c *analyse_variable_c::singleton_ = NULL;
   337 
   401 
   338 /***********************************************************************/
   402 /***********************************************************************/
   339 /***********************************************************************/
   403 /***********************************************************************/
   340 /***********************************************************************/
   404 /***********************************************************************/
   341 /***********************************************************************/
   405 /***********************************************************************/