stage4/generate_c/generate_c_st.cc
changeset 1011 76175defb87b
parent 999 dd50a82ae8da
child 1012 1f2af384fb1f
equal deleted inserted replaced
1010:242907849850 1011:76175defb87b
   621 
   621 
   622 void *visit(equ_expression_c *symbol) {
   622 void *visit(equ_expression_c *symbol) {
   623   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   623   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   624       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   624       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   625       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   625       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   626     return print_compare_function("EQ_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   626     return print_compare_function("EQ", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   627   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
   627   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
   628 }
   628 }
   629 
   629 
   630 void *visit(notequ_expression_c *symbol) {
   630 void *visit(notequ_expression_c *symbol) {
   631   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   631   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   632       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   632       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   633       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   633       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   634     return print_compare_function("NE_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   634     return print_compare_function("NE", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   635   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
   635   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
   636 }
   636 }
   637 
   637 
   638 void *visit(lt_expression_c *symbol) {
   638 void *visit(lt_expression_c *symbol) {
   639   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   639   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   640       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   640       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   641       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   641       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   642     return print_compare_function("LT_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   642     return print_compare_function("LT", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   643   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
   643   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
   644 }
   644 }
   645 
   645 
   646 void *visit(gt_expression_c *symbol) {
   646 void *visit(gt_expression_c *symbol) {
   647   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   647   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   648       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   648       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   649       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   649       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   650     return print_compare_function("GT_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   650     return print_compare_function("GT", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   651   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
   651   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
   652 }
   652 }
   653 
   653 
   654 void *visit(le_expression_c *symbol) {
   654 void *visit(le_expression_c *symbol) {
   655   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   655   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   656       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   656       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   657       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   657       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   658     return print_compare_function("LE_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   658     return print_compare_function("LE", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   659   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
   659   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
   660 }
   660 }
   661 
   661 
   662 void *visit(ge_expression_c *symbol) {
   662 void *visit(ge_expression_c *symbol) {
   663   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   663   if (get_datatype_info_c::is_TIME_compatible      (symbol->l_exp->datatype) ||
   664       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   664       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->l_exp->datatype) ||
   665       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   665       get_datatype_info_c::is_ANY_STRING_compatible(symbol->l_exp->datatype))
   666     return print_compare_function("GE_", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   666     return print_compare_function("GE", symbol->l_exp->datatype, symbol->l_exp, symbol->r_exp);
   667   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
   667   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
   668 }
   668 }
   669 
   669 
   670 void *visit(add_expression_c *symbol) {
   670 void *visit(add_expression_c *symbol) {
   671 /*
       
   672   symbol_c *left_type  = symbol->l_exp->datatype;
       
   673   symbol_c *right_type = symbol->r_exp->datatype;
       
   674   if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
       
   675       (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(time_type_name_c)) ||
       
   676       (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(time_type_name_c)))
       
   677     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
       
   678 */
       
   679   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   671   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   680       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
   672       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
   681     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
   673     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
   682   return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
   674   return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
   683 }
   675 }
   684 
   676 
   685 void *visit(sub_expression_c *symbol) {
   677 void *visit(sub_expression_c *symbol) {
   686 /*
       
   687   symbol_c *left_type  = symbol->l_exp->datatype;
       
   688   symbol_c *right_type = symbol->r_exp->datatype;
       
   689   if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
       
   690       (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) ||
       
   691       (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(time_type_name_c)) ||
       
   692       (typeid(*left_type) == typeid(tod_type_name_c)  && typeid(*right_type) == typeid(tod_type_name_c))  ||
       
   693       (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(time_type_name_c)) ||
       
   694       (typeid(*left_type) == typeid(dt_type_name_c)   && typeid(*right_type) == typeid(dt_type_name_c)))
       
   695     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
       
   696 */  
       
   697   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   678   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype) ||
   698       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
   679       get_datatype_info_c::is_ANY_DATE_compatible  (symbol->datatype))
   699     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
   680     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
   700   return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
   681   return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
   701 }
   682 }
   702 
   683 
   703 void *visit(mul_expression_c *symbol) {
   684 void *visit(mul_expression_c *symbol) {
   704 /*
       
   705   symbol_c *left_type  = symbol->l_exp->datatype;
       
   706   symbol_c *right_type = symbol->r_exp->datatype;
       
   707   if ((typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_INT_compatible (right_type)) ||
       
   708       (typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_REAL_compatible(right_type)))
       
   709     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
       
   710 */  
       
   711   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype))
   685   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype))
   712     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
   686     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
   713   return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
   687   return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
   714 }
   688 }
   715 
   689 
   716 void *visit(div_expression_c *symbol) {
   690 void *visit(div_expression_c *symbol) {
   717 /*
       
   718   symbol_c *left_type  = symbol->l_exp->datatype;
       
   719   symbol_c *right_type = symbol->r_exp->datatype;
       
   720   if ((typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_INT_compatible (right_type)) ||
       
   721       (typeid(*left_type) == typeid(time_type_name_c) && get_datatype_info_c::is_ANY_REAL_compatible(right_type)))
       
   722     return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp);
       
   723 */
       
   724   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype))
   691   if (get_datatype_info_c::is_TIME_compatible      (symbol->datatype))
   725     return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp);
   692     return print_binary_function("__time_div", symbol->l_exp, symbol->r_exp);
   726   return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
   693   return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
   727 }
   694 }
   728 
   695 
   734   s4o.print(")");
   701   s4o.print(")");
   735   return NULL;
   702   return NULL;
   736 }
   703 }
   737 
   704 
   738 void *visit(power_expression_c *symbol) {
   705 void *visit(power_expression_c *symbol) {
   739   s4o.print("EXPT__LREAL__LREAL__LREAL((BOOL)__BOOL_LITERAL(TRUE),\n");
   706   s4o.print("__expt((LREAL)(");
   740   s4o.indent_right();
       
   741   s4o.print(s4o.indent_spaces + "NULL,\n");
       
   742   s4o.print(s4o.indent_spaces + "(LREAL)(");
       
   743   symbol->l_exp->accept(*this);
   707   symbol->l_exp->accept(*this);
   744   s4o.print("),\n");
   708   s4o.print("), (LREAL)(");
   745   s4o.print(s4o.indent_spaces + "(LREAL)(");
       
   746   symbol->r_exp->accept(*this);
   709   symbol->r_exp->accept(*this);
   747   s4o.print("))");
   710   s4o.print("))");
   748   return NULL;
   711   return NULL;
   749 }
   712 }
   750 
   713 
   893       f_decl->accept(overloaded_func_suf);
   856       f_decl->accept(overloaded_func_suf);
   894     }
   857     }
   895   }
   858   }
   896   s4o.print("(");
   859   s4o.print("(");
   897   s4o.indent_right();
   860   s4o.indent_right();
       
   861   s4o.print("\n"+s4o.indent_spaces);
   898   
   862   
   899   int nb_param = 0;
   863   int nb_param = 0;
   900   PARAM_LIST_ITERATOR() {
   864   PARAM_LIST_ITERATOR() {
   901     symbol_c *param_value = PARAM_VALUE;
   865     symbol_c *param_value = PARAM_VALUE;
   902     current_param_type = PARAM_TYPE;
   866     current_param_type = PARAM_TYPE;