stage4/generate_c/generate_c_st.cc
changeset 668 90b6eb7f1775
parent 667 bd1360f29f15
child 693 51a2fa6441b9
equal deleted inserted replaced
667:bd1360f29f15 668:90b6eb7f1775
    76      * so we do not create an object instance when handling
    76      * so we do not create an object instance when handling
    77      * a function declaration.
    77      * a function declaration.
    78      */
    78      */
    79     search_fb_instance_decl_c *search_fb_instance_decl;
    79     search_fb_instance_decl_c *search_fb_instance_decl;
    80 
    80 
    81     /* When compiling st code, it becomes necessary to determine the
       
    82      * data type of st expressions. To do this, we must first find the
       
    83      * st operand's declaration, within the scope of the function block
       
    84      * or function currently being processed.
       
    85      * The following object does just that...
       
    86      * This object instance will then later be called while the
       
    87      * remaining st code is being handled.
       
    88      */
       
    89     search_expression_type_c *search_expression_type;
       
    90 
       
    91     search_varfb_instance_type_c *search_varfb_instance_type;
    81     search_varfb_instance_type_c *search_varfb_instance_type;
    92     search_var_instance_decl_c   *search_var_instance_decl;
    82     search_var_instance_decl_c   *search_var_instance_decl;
    93 
    83 
    94     search_base_type_c search_base_type;
    84     search_base_type_c search_base_type;
    95 
    85 
   105     casegeneration_t wanted_casegeneration;
    95     casegeneration_t wanted_casegeneration;
   106 
    96 
   107   public:
    97   public:
   108     generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
    98     generate_c_st_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL)
   109     : generate_c_typedecl_c(s4o_ptr) {
    99     : generate_c_typedecl_c(s4o_ptr) {
   110       search_fb_instance_decl = new search_fb_instance_decl_c(scope);
   100       search_fb_instance_decl    = new search_fb_instance_decl_c   (scope);
   111       search_expression_type = new search_expression_type_c(scope);
       
   112       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
   101       search_varfb_instance_type = new search_varfb_instance_type_c(scope);
   113       search_var_instance_decl   = new search_var_instance_decl_c(scope);
   102       search_var_instance_decl   = new search_var_instance_decl_c  (scope);
   114       
   103       
   115       this->set_variable_prefix(variable_prefix);
   104       this->set_variable_prefix(variable_prefix);
   116       current_array_type = NULL;
   105       current_array_type = NULL;
   117       current_param_type = NULL;
   106       current_param_type = NULL;
   118       fcall_number = 0;
   107       fcall_number = 0;
   121       wanted_casegeneration = none_cg;
   110       wanted_casegeneration = none_cg;
   122     }
   111     }
   123 
   112 
   124     virtual ~generate_c_st_c(void) {
   113     virtual ~generate_c_st_c(void) {
   125       delete search_fb_instance_decl;
   114       delete search_fb_instance_decl;
   126       delete search_expression_type;
       
   127       delete search_varfb_instance_type;
   115       delete search_varfb_instance_type;
   128       delete search_var_instance_decl;
   116       delete search_var_instance_decl;
   129     }
   117     }
   130 
   118 
   131 
   119 
   440 /***************************************/
   428 /***************************************/
   441 /***********************/
   429 /***********************/
   442 /* B 3.1 - Expressions */
   430 /* B 3.1 - Expressions */
   443 /***********************/
   431 /***********************/
   444 void *visit(or_expression_c *symbol) {
   432 void *visit(or_expression_c *symbol) {
   445   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   433   if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype))
   446   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   447   if (!search_expression_type->is_same_type(left_type, right_type))
       
   448       ERROR;
       
   449   if (search_expression_type->is_bool_type(left_type))
       
   450     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   434     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   451   if (search_expression_type->is_binary_type(left_type))
   435   if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype))
   452     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   436     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   453   ERROR;
   437   ERROR;
   454   return NULL;
   438   return NULL;
   455 }
   439 }
   456 
   440 
   457 void *visit(xor_expression_c *symbol) {
   441 void *visit(xor_expression_c *symbol) {
   458   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   442   if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype)) {
   459   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   460   if (!search_expression_type->is_same_type(left_type, right_type))
       
   461       ERROR;
       
   462   if (search_expression_type->is_bool_type(left_type)) {
       
   463     s4o.print("(");
   443     s4o.print("(");
   464     symbol->l_exp->accept(*this);
   444     symbol->l_exp->accept(*this);
   465     s4o.print(" && !");
   445     s4o.print(" && !");
   466     symbol->r_exp->accept(*this);
   446     symbol->r_exp->accept(*this);
   467     s4o.print(") || (!");
   447     s4o.print(") || (!");
   469     s4o.print(" && ");
   449     s4o.print(" && ");
   470     symbol->r_exp->accept(*this);
   450     symbol->r_exp->accept(*this);
   471     s4o.print(")");
   451     s4o.print(")");
   472     return NULL;
   452     return NULL;
   473   }
   453   }
   474   if (search_expression_type->is_binary_type(left_type))
   454   if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype))
   475     return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ ");
   455     return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ ");
   476   ERROR;
   456   ERROR;
   477   return NULL;
   457   return NULL;
   478 }
   458 }
   479 
   459 
   480 void *visit(and_expression_c *symbol) {
   460 void *visit(and_expression_c *symbol) {
   481   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   461   if (get_datatype_info_c::is_BOOL_compatible(symbol->datatype))
   482   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   483   if (!search_expression_type->is_same_type(left_type, right_type))
       
   484       ERROR;
       
   485   if (search_expression_type->is_bool_type(left_type))
       
   486     return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
   462     return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
   487   if (search_expression_type->is_binary_type(left_type))
   463   if (get_datatype_info_c::is_ANY_nBIT_compatible(symbol->datatype))
   488     return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
   464     return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
   489   ERROR;
   465   ERROR;
   490   return NULL;
   466 return NULL;
   491 }
   467 }
   492 
   468 
   493 void *visit(equ_expression_c *symbol) {
   469 void *visit(equ_expression_c *symbol) {
   494   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   470   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   495   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   471       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype) ||
   496   // if (!search_expression_type->is_same_type(left_type, right_type))    ERROR;  // This check is no longer needed!
   472       get_datatype_info_c::is_ANY_STRING_compatible(symbol->datatype))
   497   if (search_expression_type->is_time_type(left_type) ||
   473     return print_compare_function("EQ_", symbol->datatype, symbol->l_exp, symbol->r_exp);
   498       search_expression_type->is_string_type(left_type))
       
   499     return print_compare_function("EQ_", left_type, symbol->l_exp, symbol->r_exp);
       
   500   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
   474   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
   501 }
   475 }
   502 
   476 
   503 void *visit(notequ_expression_c *symbol) {
   477 void *visit(notequ_expression_c *symbol) {
   504   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   478   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   505   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   479       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype) ||
   506   // if (!search_expression_type->is_same_type(left_type, right_type))    ERROR;  // This check is no longer needed!
   480       get_datatype_info_c::is_ANY_STRING_compatible(symbol->datatype))
   507   if (search_expression_type->is_time_type(left_type) ||
   481     return print_compare_function("NE_", symbol->datatype, symbol->l_exp, symbol->r_exp);
   508       search_expression_type->is_string_type(left_type))
       
   509     return print_compare_function("NE_", left_type, symbol->l_exp, symbol->r_exp);
       
   510   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
   482   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
   511 }
   483 }
   512 
   484 
   513 void *visit(lt_expression_c *symbol) {
   485 void *visit(lt_expression_c *symbol) {
   514   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   486   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   515   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   487       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype) ||
   516   // if (!search_expression_type->is_same_type(left_type, right_type))    ERROR;  // This check is no longer needed!
   488       get_datatype_info_c::is_ANY_STRING_compatible(symbol->datatype))
   517   if (search_expression_type->is_time_type(left_type) ||
   489     return print_compare_function("LT_", symbol->datatype, symbol->l_exp, symbol->r_exp);
   518       search_expression_type->is_string_type(left_type))
       
   519     return print_compare_function("LT_", left_type, symbol->l_exp, symbol->r_exp);
       
   520   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
   490   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
   521 }
   491 }
   522 
   492 
   523 void *visit(gt_expression_c *symbol) {
   493 void *visit(gt_expression_c *symbol) {
   524   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   494   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   525   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   495       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype) ||
   526   // if (!search_expression_type->is_same_type(left_type, right_type))    ERROR;  // This check is no longer needed!
   496       get_datatype_info_c::is_ANY_STRING_compatible(symbol->datatype))
   527   if (search_expression_type->is_time_type(left_type) ||
   497     return print_compare_function("GT_", symbol->datatype, symbol->l_exp, symbol->r_exp);
   528       search_expression_type->is_string_type(left_type))
       
   529     return print_compare_function("GT_", left_type, symbol->l_exp, symbol->r_exp);
       
   530   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
   498   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
   531 }
   499 }
   532 
   500 
   533 void *visit(le_expression_c *symbol) {
   501 void *visit(le_expression_c *symbol) {
   534   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   502   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   535   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   503       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype) ||
   536   // if (!search_expression_type->is_same_type(left_type, right_type))    ERROR;  // This check is no longer needed!
   504       get_datatype_info_c::is_ANY_STRING_compatible(symbol->datatype))
   537   if (search_expression_type->is_time_type(left_type) ||
   505     return print_compare_function("LE_", symbol->datatype, symbol->l_exp, symbol->r_exp);
   538       search_expression_type->is_string_type(left_type))
       
   539     return print_compare_function("LE_", left_type, symbol->l_exp, symbol->r_exp);
       
   540   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
   506   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
   541 }
   507 }
   542 
   508 
   543 void *visit(ge_expression_c *symbol) {
   509 void *visit(ge_expression_c *symbol) {
   544   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   510   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   545   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   511       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype) ||
   546   // if (!search_expression_type->is_same_type(left_type, right_type))    ERROR;  // This check is no longer needed!
   512       get_datatype_info_c::is_ANY_STRING_compatible(symbol->datatype))
   547   if (search_expression_type->is_time_type(left_type) ||
   513     return print_compare_function("GE_", symbol->datatype, symbol->l_exp, symbol->r_exp);
   548       search_expression_type->is_string_type(left_type))
       
   549     return print_compare_function("GE_", left_type, symbol->l_exp, symbol->r_exp);
       
   550   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
   514   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
   551 }
   515 }
   552 
   516 
   553 void *visit(add_expression_c *symbol) {
   517 void *visit(add_expression_c *symbol) {
   554   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   518 /*
   555 	symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   519   symbol_c *left_type  = symbol->l_exp->datatype;
   556 	if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   520   symbol_c *right_type = symbol->r_exp->datatype;
   557       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   521   if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   558       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)))
   522       (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(time_type_name_c)) ||
       
   523       (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(time_type_name_c)))
   559     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
   524     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
   560   if (!search_expression_type->is_same_type(left_type, right_type))
   525 */
   561       ERROR;
   526   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   562   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   527       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
   563     return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
   528     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
   564   ERROR;
   529   return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
   565   return NULL;
       
   566 }
   530 }
   567 
   531 
   568 void *visit(sub_expression_c *symbol) {
   532 void *visit(sub_expression_c *symbol) {
   569   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   533 /*
   570   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   534   symbol_c *left_type  = symbol->l_exp->datatype;
       
   535   symbol_c *right_type = symbol->r_exp->datatype;
   571   if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   536   if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   572       (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) ||
   537       (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) ||
   573       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   538       (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(time_type_name_c)) ||
   574       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) ||
   539       (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(tod_type_name_c))  ||
   575       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   540       (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(time_type_name_c)) ||
   576       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)))
   541       (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(dt_type_name_c)))
   577     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
   542     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
   578   if (!search_expression_type->is_same_type(left_type, right_type))
   543 */  
   579       ERROR;
   544   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   580   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   545       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
   581     return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
   546     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
   582   ERROR;
   547   return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
   583   return NULL;
       
   584 }
   548 }
   585 
   549 
   586 void *visit(mul_expression_c *symbol) {
   550 void *visit(mul_expression_c *symbol) {
   587   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   551 /*
   588   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   552   symbol_c *left_type  = symbol->l_exp->datatype;
   589   if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) ||
   553   symbol_c *right_type = symbol->r_exp->datatype;
   590       (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type)))
   554   if ((typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_INT_compatible (right_type)) ||
       
   555       (typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_REAL_compatible(right_type)))
   591     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
   556     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
   592   if (!search_expression_type->is_same_type(left_type, right_type))
   557 */  
   593       ERROR;
   558   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype))
   594   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   559     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
   595     return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
   560   return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
   596   ERROR;
       
   597   return NULL;
       
   598 }
   561 }
   599 
   562 
   600 void *visit(div_expression_c *symbol) {
   563 void *visit(div_expression_c *symbol) {
   601   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   564 /*
   602   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   565   symbol_c *left_type  = symbol->l_exp->datatype;
   603   if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) ||
   566   symbol_c *right_type = symbol->r_exp->datatype;
   604       (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type)))
   567   if ((typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_INT_compatible (right_type)) ||
       
   568       (typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_REAL_compatible(right_type)))
   605     return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp);
   569     return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp);
   606   if (!search_expression_type->is_same_type(left_type, right_type))
   570 */
   607       ERROR;
   571   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype))
   608   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   572     return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp);
   609     return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
   573   return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
   610   ERROR;
       
   611   return NULL;
       
   612 }
   574 }
   613 
   575 
   614 void *visit(mod_expression_c *symbol) {
   576 void *visit(mod_expression_c *symbol) {
   615   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   577   s4o.print("((");
   616   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   578   symbol->r_exp->accept(*this);
   617   if (!search_expression_type->is_same_type(left_type, right_type))
   579   s4o.print(" == 0)?0:");
   618       ERROR;
   580   print_binary_expression(symbol->l_exp, symbol->r_exp, " % ");
   619   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) {
   581   s4o.print(")");
   620     s4o.print("((");
       
   621     symbol->r_exp->accept(*this);
       
   622     s4o.print(" == 0)?0:");
       
   623     print_binary_expression(symbol->l_exp, symbol->r_exp, " % ");
       
   624     s4o.print(")");
       
   625     return NULL;
       
   626   }
       
   627   ERROR;
       
   628   return NULL;
   582   return NULL;
   629 }
   583 }
   630 
   584 
   631 void *visit(power_expression_c *symbol) {
   585 void *visit(power_expression_c *symbol) {
   632   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   586   s4o.print("EXPT__LREAL__LREAL__LREAL((BOOL)__BOOL_LITERAL(TRUE),\n");
   633   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   587   s4o.indent_right();
   634   if (search_expression_type->is_real_type(left_type) && search_expression_type->is_num_type(right_type)) {
   588   s4o.print(s4o.indent_spaces + "NULL,\n");
   635 	s4o.print("EXPT__LREAL__LREAL__LREAL((BOOL)__BOOL_LITERAL(TRUE),\n");
   589   s4o.print(s4o.indent_spaces + "(LREAL)(");
   636 	s4o.indent_right();
   590   symbol->l_exp->accept(*this);
   637 	s4o.print(s4o.indent_spaces + "NULL,\n");
   591   s4o.print("),\n");
   638 	s4o.print(s4o.indent_spaces + "(LREAL)(");
   592   s4o.print(s4o.indent_spaces + "(LREAL)(");
   639 	symbol->l_exp->accept(*this);
   593   symbol->r_exp->accept(*this);
   640 	s4o.print("),\n");
   594   s4o.print("))");
   641 	s4o.print(s4o.indent_spaces + "(LREAL)(");
       
   642 	symbol->r_exp->accept(*this);
       
   643 	s4o.print("))");
       
   644     return NULL;
       
   645   }
       
   646   ERROR;
       
   647   return NULL;
   595   return NULL;
   648 }
   596 }
   649 
   597 
   650 void *visit(neg_expression_c *symbol) {
   598 void *visit(neg_expression_c *symbol) {
   651   return print_unary_expression(symbol->exp, " -");
   599   return print_unary_expression(symbol->exp, " -");
   652 }
   600 }
   653 
   601 
   654 void *visit(not_expression_c *symbol) {
   602 void *visit(not_expression_c *symbol) {
   655   symbol_c *exp_type = search_expression_type->get_type(symbol->exp);
   603   return print_unary_expression(symbol->exp, get_datatype_info_c::is_BOOL_compatible(symbol->datatype)?"!":"~");
   656   if (search_expression_type->is_binary_type(exp_type))
       
   657     return print_unary_expression(symbol->exp, search_expression_type->is_bool_type(exp_type)?"!":"~");
       
   658   ERROR;
       
   659   return NULL;
       
   660 }
   604 }
   661 
   605 
   662 void *visit(function_invocation_c *symbol) {
   606 void *visit(function_invocation_c *symbol) {
   663   symbol_c* function_name = NULL;
   607   symbol_c* function_name = NULL;
   664   DECLARE_PARAM_LIST()
   608   DECLARE_PARAM_LIST()
   804     symbol_c *param_value = PARAM_VALUE;
   748     symbol_c *param_value = PARAM_VALUE;
   805     current_param_type = PARAM_TYPE;
   749     current_param_type = PARAM_TYPE;
   806           
   750           
   807     switch (PARAM_DIRECTION) {
   751     switch (PARAM_DIRECTION) {
   808       case function_param_iterator_c::direction_in:
   752       case function_param_iterator_c::direction_in:
   809     	if (nb_param > 0)
   753         if (nb_param > 0)
   810     	  s4o.print(",\n"+s4o.indent_spaces);
   754           s4o.print(",\n"+s4o.indent_spaces);
   811     	if (param_value == NULL) {
   755         if (param_value == NULL) {
   812           /* If not, get the default value of this variable's type */
   756           /* If not, get the default value of this variable's type */
   813           param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance());
   757           param_value = (symbol_c *)current_param_type->accept(*type_initial_value_c::instance());
   814         }
   758         }
   815         if (param_value == NULL) ERROR;
   759         if (param_value == NULL) ERROR;
   816         s4o.print("(");
   760         s4o.print("(");
   817         if (search_expression_type->is_literal_integer_type(current_param_type))
   761         if      (get_datatype_info_c::is_ANY_INT_literal(current_param_type))
   818           search_expression_type->lint_type_name.accept(*this);
   762           search_constant_type_c::lint_type_name.accept(*this);
   819         else if (search_expression_type->is_literal_real_type(current_param_type))
   763         else if (get_datatype_info_c::is_ANY_REAL_literal(current_param_type))
   820           search_expression_type->lreal_type_name.accept(*this);
   764           search_constant_type_c::lreal_type_name.accept(*this);
   821         else
   765         else
   822           current_param_type->accept(*this);
   766           current_param_type->accept(*this);
   823         s4o.print(")");
   767         s4o.print(")");
   824         print_check_function(current_param_type, param_value);
   768         print_check_function(current_param_type, param_value);
   825         nb_param++;
   769         nb_param++;
   826         break;
   770         break;
   827       case function_param_iterator_c::direction_out:
   771       case function_param_iterator_c::direction_out:
   828       case function_param_iterator_c::direction_inout:
   772       case function_param_iterator_c::direction_inout:
   829     	if (!has_output_params) {
   773         if (!has_output_params) {
   830           if (nb_param > 0)
   774           if (nb_param > 0)
   831         	s4o.print(",\n"+s4o.indent_spaces);
   775             s4o.print(",\n"+s4o.indent_spaces);
   832     	  if (param_value == NULL)
   776           if (param_value == NULL)
   833             s4o.print("NULL");
   777             s4o.print("NULL");
   834           else {
   778           else {
   835             wanted_variablegeneration = fparam_output_vg;
   779             wanted_variablegeneration = fparam_output_vg;
   836             param_value->accept(*this);
   780             param_value->accept(*this);
   837             wanted_variablegeneration = expression_vg;
   781             wanted_variablegeneration = expression_vg;
   838           }
   782           }
   839     	  nb_param++;
   783           nb_param++;
   840     	}
   784         }
   841         break;
   785         break;
   842       case function_param_iterator_c::direction_extref:
   786       case function_param_iterator_c::direction_extref:
   843         /* TODO! */
   787         /* TODO! */
   844         ERROR;
   788         ERROR;
   845         break;
   789         break;
  1086   s4o.indent_left();
  1030   s4o.indent_left();
  1087   return NULL;
  1031   return NULL;
  1088 }
  1032 }
  1089 
  1033 
  1090 void *visit(case_statement_c *symbol) {
  1034 void *visit(case_statement_c *symbol) {
  1091   symbol_c *expression_type = search_expression_type->get_type(symbol->expression);
  1035   symbol_c *expression_type = symbol->expression->datatype;
  1092   s4o.print("{\n");
  1036   s4o.print("{\n");
  1093   s4o.indent_right();
  1037   s4o.indent_right();
  1094   s4o.print(s4o.indent_spaces);
  1038   s4o.print(s4o.indent_spaces);
  1095   if (search_expression_type->is_literal_integer_type(expression_type))
  1039   if      (get_datatype_info_c::is_ANY_INT_literal(expression_type))
  1096 	search_expression_type->lint_type_name.accept(*this);
  1040         search_constant_type_c::lint_type_name.accept(*this);
  1097   else if (search_expression_type->is_literal_real_type(expression_type))
  1041   else if (get_datatype_info_c::is_ANY_REAL_literal(expression_type))
  1098 	search_expression_type->lreal_type_name.accept(*this);
  1042         search_constant_type_c::lreal_type_name.accept(*this);
  1099   else
  1043   else
  1100     expression_type->accept(*this);
  1044     expression_type->accept(*this);
  1101   s4o.print(" __case_expression = ");
  1045   s4o.print(" __case_expression = ");
  1102   symbol->expression->accept(*this);
  1046   symbol->expression->accept(*this);
  1103   s4o.print(";\n" + s4o.indent_spaces + "switch (__case_expression) {\n");
  1047   s4o.print(";\n" + s4o.indent_spaces + "switch (__case_expression) {\n");
  1108   s4o.print(s4o.indent_spaces + "default:\n");
  1052   s4o.print(s4o.indent_spaces + "default:\n");
  1109   s4o.indent_right();
  1053   s4o.indent_right();
  1110   first_subrange_case_list = true;
  1054   first_subrange_case_list = true;
  1111   symbol->case_element_list->accept(*this);
  1055   symbol->case_element_list->accept(*this);
  1112   if (symbol->statement_list != NULL) {
  1056   if (symbol->statement_list != NULL) {
  1113 	if (!first_subrange_case_list) {
  1057     if (!first_subrange_case_list) {
  1114       s4o.print(s4o.indent_spaces + "else {\n");
  1058       s4o.print(s4o.indent_spaces + "else {\n");
  1115       s4o.indent_right();
  1059       s4o.indent_right();
  1116 	}
  1060     }
  1117     symbol->statement_list->accept(*this);
  1061     symbol->statement_list->accept(*this);
  1118     if (!first_subrange_case_list) {
  1062     if (!first_subrange_case_list) {
  1119       s4o.indent_left();
  1063       s4o.indent_left();
  1120       s4o.print(s4o.indent_spaces + "}\n");
  1064       s4o.print(s4o.indent_spaces + "}\n");
  1121     }
  1065     }