stage4/generate_c/generate_c_st.cc
changeset 873 dea39ef02847
parent 864 300c27c08753
child 877 c25346eac788
equal deleted inserted replaced
872:3d682f87c870 873:dea39ef02847
   454 /* B.3 - Language ST (Structured Text) */
   454 /* B.3 - Language ST (Structured Text) */
   455 /***************************************/
   455 /***************************************/
   456 /***********************/
   456 /***********************/
   457 /* B 3.1 - Expressions */
   457 /* B 3.1 - Expressions */
   458 /***********************/
   458 /***********************/
       
   459 void *visit(ref_expression_c *symbol) {
       
   460   s4o.print("((IEC_UDINT)");  
       
   461   if (this->is_variable_prefix_null()) {  
       
   462     /* For code in FUNCTIONs */
       
   463     s4o.print("&(");  
       
   464     symbol->exp->accept(*this);    
       
   465     s4o.print(")");  
       
   466   } else {
       
   467     /* For code in FBs, and PROGRAMS... */
       
   468     s4o.print("(");  
       
   469     unsigned int vartype = analyse_variable_c::first_nonfb_vardecltype(symbol->exp, scope_);
       
   470     if (vartype == search_var_instance_decl_c::external_vt) {
       
   471       if (!get_datatype_info_c::is_type_valid    (symbol->exp->datatype)) ERROR;
       
   472       if ( get_datatype_info_c::is_function_block(symbol->exp->datatype))
       
   473         s4o.print(GET_EXTERNAL_FB_REF);
       
   474       else
       
   475         s4o.print(GET_EXTERNAL_REF);
       
   476     }
       
   477     else if (vartype == search_var_instance_decl_c::located_vt)
       
   478       s4o.print(GET_LOCATED_REF);
       
   479     else
       
   480       s4o.print(GET_VAR_REF);
       
   481     
       
   482     variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; 
       
   483     s4o.print("(");
       
   484     wanted_variablegeneration = complextype_base_vg;
       
   485     symbol->exp->accept(*this);
       
   486     s4o.print(",");
       
   487     wanted_variablegeneration = complextype_suffix_vg;
       
   488     symbol->exp->accept(*this);
       
   489     s4o.print(")");
       
   490     wanted_variablegeneration = old_wanted_variablegeneration;
       
   491     
       
   492     s4o.print(")");  
       
   493   }
       
   494   s4o.print(")");  
       
   495 
       
   496   return NULL;
       
   497 }
       
   498 
       
   499 
   459 void *visit(or_expression_c *symbol) {
   500 void *visit(or_expression_c *symbol) {
   460   if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype))
   501   if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype))
   461     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   502     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   462   if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype))
   503   if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype))
   463     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   504     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");