stage4/generate_c/generate_c_st.cc
changeset 889 5f380b99e95e
parent 888 4893e6b11b25
child 897 8c3e91c385f5
--- a/stage4/generate_c/generate_c_st.cc	Fri Apr 04 16:21:55 2014 +0100
+++ b/stage4/generate_c/generate_c_st.cc	Tue Apr 08 14:35:31 2014 +0100
@@ -179,9 +179,11 @@
  
   if (fb_symbol == NULL) {
     unsigned int vartype = analyse_variable_c::first_nonfb_vardecltype(symbol, scope_);
+    symbol_c *first_nonfb = analyse_variable_c::find_first_nonfb(symbol);
+    if (first_nonfb == NULL) ERROR;
     if (vartype == search_var_instance_decl_c::external_vt) {
-      if (!get_datatype_info_c::is_type_valid    (symbol->datatype)) ERROR;
-      if ( get_datatype_info_c::is_function_block(symbol->datatype))
+      if (!get_datatype_info_c::is_type_valid    (first_nonfb->datatype)) ERROR;
+      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!)
         s4o.print(SET_EXTERNAL_FB);
       else
         s4o.print(SET_EXTERNAL);
@@ -329,18 +331,22 @@
 // SYM_REF2(structured_variable_c, record_variable, field_selector)
 void *visit(structured_variable_c *symbol) {
   TRACE("structured_variable_c");
-  bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable);
   switch (wanted_variablegeneration) {
     case complextype_base_vg:
       symbol->record_variable->accept(*this);
-      if (!type_is_complex) {
-        s4o.print(".");
+      if ( get_datatype_info_c::is_function_block(symbol->record_variable->datatype)) {
+        if (NULL == symbol->record_variable->scope) ERROR;
+        search_var_instance_decl_c search_var_instance_decl(symbol->record_variable->scope);
+        if (search_var_instance_decl_c::external_vt == search_var_instance_decl.get_vartype(get_var_name_c::get_last_field(symbol->record_variable)))
+          s4o.print("->");
+        else  
+          s4o.print(".");
         symbol->field_selector->accept(*this);
       }
       break;
     case complextype_suffix_vg:
       symbol->record_variable->accept(*this);
-      if (type_is_complex) {
+      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!
         s4o.print(".");
         symbol->field_selector->accept(*this);
       }