stage4/generate_c/generate_c_st.cc
changeset 889 5f380b99e95e
parent 888 4893e6b11b25
child 897 8c3e91c385f5
equal deleted inserted replaced
888:4893e6b11b25 889:5f380b99e95e
   177         symbol_c* fb_symbol = NULL,
   177         symbol_c* fb_symbol = NULL,
   178         symbol_c* fb_value = NULL) {
   178         symbol_c* fb_value = NULL) {
   179  
   179  
   180   if (fb_symbol == NULL) {
   180   if (fb_symbol == NULL) {
   181     unsigned int vartype = analyse_variable_c::first_nonfb_vardecltype(symbol, scope_);
   181     unsigned int vartype = analyse_variable_c::first_nonfb_vardecltype(symbol, scope_);
       
   182     symbol_c *first_nonfb = analyse_variable_c::find_first_nonfb(symbol);
       
   183     if (first_nonfb == NULL) ERROR;
   182     if (vartype == search_var_instance_decl_c::external_vt) {
   184     if (vartype == search_var_instance_decl_c::external_vt) {
   183       if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
   185       if (!get_datatype_info_c::is_type_valid    (first_nonfb->datatype)) ERROR;
   184       if ( get_datatype_info_c::is_function_block(symbol->datatype))
   186       if ( get_datatype_info_c::is_function_block(first_nonfb->datatype)) // handle situation where we are copying a complete fb -> fb1.fb2.fb3 := fb4 (and fb3 is external!)
   185         s4o.print(SET_EXTERNAL_FB);
   187         s4o.print(SET_EXTERNAL_FB);
   186       else
   188       else
   187         s4o.print(SET_EXTERNAL);
   189         s4o.print(SET_EXTERNAL);
   188     }
   190     }
   189     else if (vartype == search_var_instance_decl_c::located_vt)
   191     else if (vartype == search_var_instance_decl_c::located_vt)
   327 /*************************************/
   329 /*************************************/
   328 
   330 
   329 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   331 // SYM_REF2(structured_variable_c, record_variable, field_selector)
   330 void *visit(structured_variable_c *symbol) {
   332 void *visit(structured_variable_c *symbol) {
   331   TRACE("structured_variable_c");
   333   TRACE("structured_variable_c");
   332   bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
       
   333   switch (wanted_variablegeneration) {
   334   switch (wanted_variablegeneration) {
   334     case complextype_base_vg:
   335     case complextype_base_vg:
   335       symbol->record_variable->accept(*this);
   336       symbol->record_variable->accept(*this);
   336       if (!type_is_complex) {
   337       if ( get_datatype_info_c::is_function_block(symbol->record_variable->datatype)) {
   337         s4o.print(".");
   338         if (NULL == symbol->record_variable->scope) ERROR;
       
   339         search_var_instance_decl_c search_var_instance_decl(symbol->record_variable->scope);
       
   340         if (search_var_instance_decl_c::external_vt == search_var_instance_decl.get_vartype(get_var_name_c::get_last_field(symbol->record_variable)))
       
   341           s4o.print("->");
       
   342         else  
       
   343           s4o.print(".");
   338         symbol->field_selector->accept(*this);
   344         symbol->field_selector->accept(*this);
   339       }
   345       }
   340       break;
   346       break;
   341     case complextype_suffix_vg:
   347     case complextype_suffix_vg:
   342       symbol->record_variable->accept(*this);
   348       symbol->record_variable->accept(*this);
   343       if (type_is_complex) {
   349       if (!get_datatype_info_c::is_function_block(symbol->record_variable->datatype)) { // if the record variable is not a FB, then it will certainly be a structure!
   344         s4o.print(".");
   350         s4o.print(".");
   345         symbol->field_selector->accept(*this);
   351         symbol->field_selector->accept(*this);
   346       }
   352       }
   347       break;
   353       break;
   348     default:
   354     default: