stage4/generate_cc/generate_cc_st.cc
changeset 41 8998c8b24b60
parent 33 4507beb2aac6
child 42 b45c7f34dec1
equal deleted inserted replaced
40:873a5b60a7ea 41:8998c8b24b60
   200   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   200   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   201   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   201   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   202   if (!search_expression_type->is_same_type(left_type, right_type))
   202   if (!search_expression_type->is_same_type(left_type, right_type))
   203       ERROR;
   203       ERROR;
   204   if (search_expression_type->is_time_type(left_type))
   204   if (search_expression_type->is_time_type(left_type))
   205     return print_compare_function("__compare_timespec", "==", symbol->l_exp, symbol->r_exp);
   205     return print_compare_function("__eq_", left_type, symbol->l_exp, symbol->r_exp);
   206   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
   206   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
   207 }
   207 }
   208 
   208 
   209 void *visit(notequ_expression_c *symbol) {
   209 void *visit(notequ_expression_c *symbol) {
   210   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   210   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   211   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   211   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   212   if (!search_expression_type->is_same_type(left_type, right_type))
   212   if (!search_expression_type->is_same_type(left_type, right_type))
   213       ERROR;
   213       ERROR;
   214   if (search_expression_type->is_time_type(left_type))
   214   if (search_expression_type->is_time_type(left_type))
   215     return print_compare_function("__compare_timespec", "!=", symbol->l_exp, symbol->r_exp);
   215     return print_compare_function("__ne_", left_type, symbol->l_exp, symbol->r_exp);
   216   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
   216   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
   217 }
   217 }
   218 
   218 
   219 void *visit(lt_expression_c *symbol) {
   219 void *visit(lt_expression_c *symbol) {
   220   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   220   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   221   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   221   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   222   if (!search_expression_type->is_same_type(left_type, right_type))
   222   if (!search_expression_type->is_same_type(left_type, right_type))
   223       ERROR;
   223       ERROR;
   224   if (search_expression_type->is_time_type(left_type))
   224   if (search_expression_type->is_time_type(left_type))
   225     return print_compare_function("__compare_timespec", "<", symbol->l_exp, symbol->r_exp);
   225     return print_compare_function("__lt_", left_type, symbol->l_exp, symbol->r_exp);
   226   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
   226   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
   227 }
   227 }
   228 
   228 
   229 void *visit(gt_expression_c *symbol) {
   229 void *visit(gt_expression_c *symbol) {
   230   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   230   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   231   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   231   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   232   if (!search_expression_type->is_same_type(left_type, right_type))
   232   if (!search_expression_type->is_same_type(left_type, right_type))
   233       ERROR;
   233       ERROR;
   234   if (search_expression_type->is_time_type(left_type))
   234   if (search_expression_type->is_time_type(left_type))
   235     return print_compare_function("__compare_timespec", ">", symbol->l_exp, symbol->r_exp);
   235     return print_compare_function("__gt_", left_type, symbol->l_exp, symbol->r_exp);
   236   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
   236   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
   237 }
   237 }
   238 
   238 
   239 void *visit(le_expression_c *symbol) {
   239 void *visit(le_expression_c *symbol) {
   240   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   240   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   241   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   241   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   242   if (!search_expression_type->is_same_type(left_type, right_type))
   242   if (!search_expression_type->is_same_type(left_type, right_type))
   243       ERROR;
   243       ERROR;
   244   if (search_expression_type->is_time_type(left_type))
   244   if (search_expression_type->is_time_type(left_type))
   245     return print_compare_function("__compare_timespec", "<=", symbol->l_exp, symbol->r_exp);
   245     return print_compare_function("__le_", left_type, symbol->l_exp, symbol->r_exp);
   246   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
   246   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
   247 }
   247 }
   248 
   248 
   249 void *visit(ge_expression_c *symbol) {
   249 void *visit(ge_expression_c *symbol) {
   250   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   250   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   251   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   251   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   252   if (!search_expression_type->is_same_type(left_type, right_type))
   252   if (!search_expression_type->is_same_type(left_type, right_type))
   253       ERROR;
   253       ERROR;
   254   if (search_expression_type->is_time_type(left_type))
   254   if (search_expression_type->is_time_type(left_type))
   255     return print_compare_function("__compare_timespec", ">=", symbol->l_exp, symbol->r_exp);
   255     return print_compare_function("__ge_", left_type, symbol->l_exp, symbol->r_exp);
   256   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
   256   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
   257 }
   257 }
   258 
   258 
   259 void *visit(add_expression_c *symbol) {
   259 void *visit(add_expression_c *symbol) {
   260   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   260   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   261 	symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   261 	symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   262 	if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   262 	if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   263       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   263       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   264       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)))
   264       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)))
   265     return print_binary_function("__add_timespec", symbol->l_exp, symbol->r_exp);
   265     return print_binary_function("__time_add", symbol->l_exp, symbol->r_exp);
   266   if (!search_expression_type->is_same_type(left_type, right_type))
   266   if (!search_expression_type->is_same_type(left_type, right_type))
   267       ERROR;
   267       ERROR;
   268   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   268   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   269     return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
   269     return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
   270   ERROR;
   270   ERROR;
   278       (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) ||
   278       (typeid(*left_type) == typeid(date_type_name_c) && typeid(*right_type) == typeid(date_type_name_c)) ||
   279       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   279       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   280       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) ||
   280       (typeid(*left_type) == typeid(tod_type_name_c) && typeid(*right_type) == typeid(tod_type_name_c)) ||
   281       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   281       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(time_type_name_c)) ||
   282       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)))
   282       (typeid(*left_type) == typeid(dt_type_name_c) && typeid(*right_type) == typeid(dt_type_name_c)))
   283     return print_binary_function("__sub_timespec", symbol->l_exp, symbol->r_exp);
   283     return print_binary_function("__time_sub", symbol->l_exp, symbol->r_exp);
   284   if (!search_expression_type->is_same_type(left_type, right_type))
   284   if (!search_expression_type->is_same_type(left_type, right_type))
   285       ERROR;
   285       ERROR;
   286   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   286   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   287     return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
   287     return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
   288   ERROR;
   288   ERROR;
   292 void *visit(mul_expression_c *symbol) {
   292 void *visit(mul_expression_c *symbol) {
   293   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   293   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   294   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   294   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   295   if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) ||
   295   if ((typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_integer_type(right_type)) ||
   296       (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type)))
   296       (typeid(*left_type) == typeid(time_type_name_c) && search_expression_type->is_real_type(right_type)))
   297     return print_binary_function("__mul_timespec", symbol->l_exp, symbol->r_exp);
   297     return print_binary_function("__time_mul", symbol->l_exp, symbol->r_exp);
   298   if (!search_expression_type->is_same_type(left_type, right_type))
   298   if (!search_expression_type->is_same_type(left_type, right_type))
   299       ERROR;
   299       ERROR;
   300   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   300   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
   301     return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
   301     return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
   302   ERROR;
   302   ERROR;
   384       
   384       
   385       switch (current_function_type) {
   385       switch (current_function_type) {
   386         case function_add:
   386         case function_add:
   387           if (search_expression_type->is_time_type(function_return_type)) {
   387           if (search_expression_type->is_time_type(function_return_type)) {
   388             if (current_param == 0) {
   388             if (current_param == 0) {
   389               s4o.print("__add_timespec(");
   389               s4o.print("__time_add(");
   390               param_value->accept(*this);
   390               param_value->accept(*this);
   391             }
   391             }
   392             else if (current_param == 1) {
   392             else if (current_param == 1) {
   393               s4o.print(", ");
   393               s4o.print(", ");
   394               param_value->accept(*this);
   394               param_value->accept(*this);
   407           }
   407           }
   408           break;
   408           break;
   409         case function_sub:
   409         case function_sub:
   410           if (search_expression_type->is_time_type(function_return_type)) {
   410           if (search_expression_type->is_time_type(function_return_type)) {
   411             if (current_param == 0) {
   411             if (current_param == 0) {
   412               s4o.print("__sub_timespec(");
   412               s4o.print("__time_sub(");
   413               param_value->accept(*this);
   413               param_value->accept(*this);
   414             }
   414             }
   415             else if (current_param == 1) {
   415             else if (current_param == 1) {
   416               s4o.print(", ");
   416               s4o.print(", ");
   417               param_value->accept(*this);
   417               param_value->accept(*this);
   593   } /* for(...) */
   593   } /* for(...) */
   594 
   594 
   595   /* now call the function... */
   595   /* now call the function... */
   596   function_block_type_name->accept(*this);
   596   function_block_type_name->accept(*this);
   597   s4o.print(FB_FUNCTION_SUFFIX);
   597   s4o.print(FB_FUNCTION_SUFFIX);
   598   s4o.print("(");
   598   s4o.print("(&");
   599   print_variable_prefix();
   599   print_variable_prefix();
   600   symbol->fb_name->accept(*this);
   600   symbol->fb_name->accept(*this);
   601   s4o.print(")");
   601   s4o.print(")");
   602 
   602 
   603   /* loop through each function parameter, find the variable to which
   603   /* loop through each function parameter, find the variable to which