stage4/generate_cc/generate_cc_st.cc
changeset 32 289256ec66f1
parent 26 fd67f54e64e1
child 33 4507beb2aac6
equal deleted inserted replaced
31:c6959b0f539d 32:289256ec66f1
   149 /* B 3.1 - Expressions */
   149 /* B 3.1 - Expressions */
   150 /***********************/
   150 /***********************/
   151 void *visit(or_expression_c *symbol) {
   151 void *visit(or_expression_c *symbol) {
   152   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   152   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   153   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   153   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   154   if (search_expression_type->is_bool_type(left_type) && search_expression_type->is_bool_type(right_type)) {
   154   if (!search_expression_type->is_same_type(left_type, right_type))
       
   155       ERROR;
       
   156   if (search_expression_type->is_bool_type(left_type))
   155     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   157     return print_binary_expression(symbol->l_exp, symbol->r_exp, " || ");
   156   }
   158   if (search_expression_type->is_binary_type(left_type))
   157   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
       
   158     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   159     return print_binary_expression(symbol->l_exp, symbol->r_exp, " | ");
   159   }
       
   160   ERROR;
   160   ERROR;
   161   return NULL;
   161   return NULL;
   162 }
   162 }
   163 
   163 
   164 void *visit(xor_expression_c *symbol) {
   164 void *visit(xor_expression_c *symbol) {
   165   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   165   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
   166   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   166   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
   167   if (search_expression_type->is_bool_type(left_type) && search_expression_type->is_bool_type(right_type)) {
   167   if (!search_expression_type->is_same_type(left_type, right_type))
       
   168       ERROR;
       
   169   if (search_expression_type->is_bool_type(left_type)) {
   168     s4o.print("(");
   170     s4o.print("(");
   169     symbol->l_exp->accept(*this);
   171     symbol->l_exp->accept(*this);
   170     s4o.print(" && !");
   172     s4o.print(" && !");
   171     symbol->r_exp->accept(*this);
   173     symbol->r_exp->accept(*this);
   172     s4o.print(") || (!");
   174     s4o.print(") || (!");
   173     symbol->l_exp->accept(*this);
   175     symbol->l_exp->accept(*this);
   174     s4o.print(" && ");
   176     s4o.print(" && ");
   175     symbol->r_exp->accept(*this);
   177     symbol->r_exp->accept(*this);
   176     s4o.print(")");
   178     s4o.print(")");
   177   }
   179   }
   178   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
   180   if (search_expression_type->is_binary_type(left_type))
   179     return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ ");
   181     return print_binary_expression(symbol->l_exp, symbol->r_exp, " ^ ");
       
   182   ERROR;
       
   183   return NULL;
       
   184 }
       
   185 
       
   186 void *visit(and_expression_c *symbol) {
       
   187   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   188   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   189   if (!search_expression_type->is_same_type(left_type, right_type))
       
   190       ERROR;
       
   191   if (search_expression_type->is_bool_type(left_type))
       
   192     return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
       
   193   if (search_expression_type->is_binary_type(left_type))
       
   194     return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
       
   195   ERROR;
       
   196   return NULL;
       
   197 }
       
   198 
       
   199 void *visit(equ_expression_c *symbol) {
       
   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);
       
   202   if (!search_expression_type->is_same_type(left_type, right_type))
       
   203       ERROR;
       
   204   if (search_expression_type->is_time_type(left_type))
       
   205     return print_compare_function("__compare_timespec", "==", symbol->l_exp, symbol->r_exp);
       
   206   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
       
   207 }
       
   208 
       
   209 void *visit(notequ_expression_c *symbol) {
       
   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);
       
   212   if (!search_expression_type->is_same_type(left_type, right_type))
       
   213       ERROR;
       
   214   if (search_expression_type->is_time_type(left_type))
       
   215     return print_compare_function("__compare_timespec", "!=", symbol->l_exp, symbol->r_exp);
       
   216   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
       
   217 }
       
   218 
       
   219 void *visit(lt_expression_c *symbol) {
       
   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);
       
   222   if (!search_expression_type->is_same_type(left_type, right_type))
       
   223       ERROR;
       
   224   if (search_expression_type->is_time_type(left_type))
       
   225     return print_compare_function("__compare_timespec", "<", symbol->l_exp, symbol->r_exp);
       
   226   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
       
   227 }
       
   228 
       
   229 void *visit(gt_expression_c *symbol) {
       
   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);
       
   232   if (!search_expression_type->is_same_type(left_type, right_type))
       
   233       ERROR;
       
   234   if (search_expression_type->is_time_type(left_type))
       
   235     return print_compare_function("__compare_timespec", ">", symbol->l_exp, symbol->r_exp);
       
   236   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
       
   237 }
       
   238 
       
   239 void *visit(le_expression_c *symbol) {
       
   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);
       
   242   if (!search_expression_type->is_same_type(left_type, right_type))
       
   243       ERROR;
       
   244   if (search_expression_type->is_time_type(left_type))
       
   245     return print_compare_function("__compare_timespec", "<=", symbol->l_exp, symbol->r_exp);
       
   246   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
       
   247 }
       
   248 
       
   249 void *visit(ge_expression_c *symbol) {
       
   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);
       
   252   if (!search_expression_type->is_same_type(left_type, right_type))
       
   253       ERROR;
       
   254   if (search_expression_type->is_time_type(left_type))
       
   255     return print_compare_function("__compare_timespec", ">=", symbol->l_exp, symbol->r_exp);
       
   256   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
       
   257 }
       
   258 
       
   259 void *visit(add_expression_c *symbol) {
       
   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);
       
   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)) ||
       
   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);
       
   266   if (!search_expression_type->is_same_type(left_type, right_type))
       
   267       ERROR;
       
   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, " + ");
       
   270   ERROR;
       
   271   return NULL;
       
   272 }
       
   273 
       
   274 void *visit(sub_expression_c *symbol) {
       
   275   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   276   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   277   if ((typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_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)) ||
       
   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)) ||
       
   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);
       
   284   if (!search_expression_type->is_same_type(left_type, right_type))
       
   285       ERROR;
       
   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, " - ");
       
   288   ERROR;
       
   289   return NULL;
       
   290 }
       
   291 
       
   292 void *visit(mul_expression_c *symbol) {
       
   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);
       
   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)))
       
   297     return print_binary_function("__mul_timespec", symbol->l_exp, symbol->r_exp);
       
   298   if (!search_expression_type->is_same_type(left_type, right_type))
       
   299       ERROR;
       
   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, " * ");
       
   302   ERROR;
       
   303   return NULL;
       
   304 }
       
   305 
       
   306 void *visit(div_expression_c *symbol) {
       
   307   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   308   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   309   if (!search_expression_type->is_same_type(left_type, right_type))
       
   310       ERROR;
       
   311   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type))
       
   312     return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");
       
   313   ERROR;
       
   314   return NULL;
       
   315 }
       
   316 
       
   317 void *visit(mod_expression_c *symbol) {
       
   318   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   319   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   320   if (!search_expression_type->is_same_type(left_type, right_type))
       
   321       ERROR;
       
   322   if (search_expression_type->is_integer_type(left_type) || search_expression_type->is_real_type(left_type)) {
       
   323     s4o.print("((");
       
   324     symbol->r_exp->accept(*this);
       
   325     s4o.print(" == 0)?0:");
       
   326     print_binary_expression(symbol->l_exp, symbol->r_exp, " % ");
       
   327     s4o.print(")");
       
   328     return NULL;
   180   }
   329   }
   181   ERROR;
   330   ERROR;
   182   return NULL;
       
   183 }
       
   184 
       
   185 void *visit(and_expression_c *symbol) {
       
   186   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   187   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   188   if (search_expression_type->is_bool_type(left_type) && search_expression_type->is_bool_type(right_type)) {
       
   189     return print_binary_expression(symbol->l_exp, symbol->r_exp, " && ");
       
   190   }
       
   191   if (search_expression_type->is_numeric_compatible(left_type) && search_expression_type->is_numeric_compatible(right_type)) {
       
   192     return print_binary_expression(symbol->l_exp, symbol->r_exp, " & ");
       
   193   }
       
   194   ERROR;
       
   195   return NULL;
       
   196 }
       
   197 
       
   198 void *visit(equ_expression_c *symbol) {
       
   199   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   200   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   201   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   202     return print_compare_function("__compare_timespec", "==", symbol->l_exp, symbol->r_exp);
       
   203   }
       
   204   return print_binary_expression(symbol->l_exp, symbol->r_exp, " == ");
       
   205 }
       
   206 
       
   207 void *visit(notequ_expression_c *symbol) {
       
   208   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   209   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   210   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   211     return print_compare_function("__compare_timespec", "!=", symbol->l_exp, symbol->r_exp);
       
   212   }
       
   213   return print_binary_expression(symbol->l_exp, symbol->r_exp, " != ");
       
   214 }
       
   215 
       
   216 void *visit(lt_expression_c *symbol) {
       
   217   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   218   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   219   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   220     return print_compare_function("__compare_timespec", "<", symbol->l_exp, symbol->r_exp);
       
   221   }
       
   222   return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");
       
   223 }
       
   224 
       
   225 void *visit(gt_expression_c *symbol) {
       
   226   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   227   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   228   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   229     return print_compare_function("__compare_timespec", ">", symbol->l_exp, symbol->r_exp);
       
   230   }
       
   231   return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");
       
   232 }
       
   233 
       
   234 void *visit(le_expression_c *symbol) {
       
   235   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   236   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   237   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   238     return print_compare_function("__compare_timespec", "<=", symbol->l_exp, symbol->r_exp);
       
   239   }
       
   240   return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");
       
   241 }
       
   242 
       
   243 void *visit(ge_expression_c *symbol) {
       
   244   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   245   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   246   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   247     return print_compare_function("__compare_timespec", ">=", symbol->l_exp, symbol->r_exp);
       
   248   }
       
   249   return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");
       
   250 }
       
   251 
       
   252 void *visit(add_expression_c *symbol) {
       
   253   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   254 	symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   255 	if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   256 		return print_binary_function("__add_timespec", symbol->l_exp, symbol->r_exp);
       
   257 	}
       
   258 	return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");
       
   259 }
       
   260 
       
   261 void *visit(sub_expression_c *symbol) {
       
   262   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   263   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   264   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   265     return print_binary_function("__sub_timespec", symbol->l_exp, symbol->r_exp);
       
   266   }
       
   267   return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");
       
   268 }
       
   269 
       
   270 void *visit(mul_expression_c *symbol) {
       
   271   symbol_c *left_type = search_expression_type->get_type(symbol->l_exp);
       
   272   symbol_c *right_type = search_expression_type->get_type(symbol->r_exp);
       
   273   if (search_expression_type->is_time_compatible(left_type) && search_expression_type->is_time_compatible(right_type)) {
       
   274     return print_binary_function("__mul_timespec", symbol->l_exp, symbol->r_exp);
       
   275   }
       
   276   return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");
       
   277 }
       
   278 
       
   279 void *visit(div_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");}
       
   280 void *visit(mod_expression_c *symbol) {
       
   281   s4o.print("((");
       
   282   symbol->r_exp->accept(*this);
       
   283   s4o.print(" == 0)?0:");
       
   284   print_binary_expression(symbol->l_exp, symbol->r_exp, " % ");
       
   285   s4o.print(")");
       
   286   return NULL;
   331   return NULL;
   287 }
   332 }
   288 
   333 
   289 /* TODO: power expression... */
   334 /* TODO: power expression... */
   290 void *visit(power_expression_c *symbol) {ERROR; return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");}
   335 void *visit(power_expression_c *symbol) {ERROR; return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");}
   291 void *visit(neg_expression_c *symbol) {return print_unary_expression(symbol->exp, " -");}
   336 void *visit(neg_expression_c *symbol) {return print_unary_expression(symbol->exp, " -");}
   292 void *visit(not_expression_c *symbol) {return print_unary_expression(symbol->exp, "!");}
   337 void *visit(not_expression_c *symbol) {return print_unary_expression(symbol->exp, "!");}
   293 
   338 
   294 void *visit(function_invocation_c *symbol) {
   339 void *visit(function_invocation_c *symbol) {
   295   function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
   340   function_declaration_c *f_decl = function_symtable.find_value(symbol->function_name);
   296 
   341   
   297   if (f_decl == function_symtable.end_value())
   342   if (f_decl == function_symtable.end_value()) {
   298     /* should never occur. The function being called MUST be in the symtable... */
   343     /* The function called is not in the symtable, so we test if it is a
   299     ERROR;
   344      * standard function defined in standard */
   300 
   345     
   301   symbol->function_name->accept(*this);
   346     function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
   302   s4o.print("(");
   347     if (current_function_type == function_none) ERROR;
   303 
   348     
   304   /* loop through each function parameter, find the value we should pass
   349     symbol_c *function_return_type = search_expression_type->get_type(symbol);
   305    * to it, and then output the c equivalent...
   350     
   306    */
   351     function_call_param_iterator_c function_call_param_iterator(symbol);
   307 
   352     
   308   function_param_iterator_c fp_iterator(f_decl);
   353     int nb_param = ((list_c *)symbol->parameter_assignment_list)->n;
   309   identifier_c *param_name;
   354     for(int current_param = 0; current_param < nb_param; current_param++) {
   310   function_call_param_iterator_c function_call_param_iterator(symbol);
   355       symbol_c *param_name = NULL;
   311   for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
   356       switch (current_function_type) {
   312     if (i != 1)
   357         case function_add:
   313       s4o.print(", ");
   358         case function_and:
   314 
   359         case function_or:
   315     symbol_c *param_type = fp_iterator.param_type();
   360           param_name = generate_param_name("IN%d", current_param + 1);
   316     if (param_type == NULL) ERROR;
   361           break;
   317 
   362         case function_sub:
   318     function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
   363           if (current_param < 2)
   319 
   364             param_name = generate_param_name("IN%d", current_param + 1);
   320     /* Get the value from a foo(<param_name> = <param_value>) style call */
   365           else
   321     symbol_c *param_value = function_call_param_iterator.search(param_name);
   366             ERROR;
   322 
   367           break;
   323     /* Get the value from a foo(<param_value>) style call */
   368         default: ERROR;
   324     if (param_value == NULL)
   369       }
   325       param_value = function_call_param_iterator.next();
   370       
   326 
   371       /* Get the value from a foo(<param_name> = <param_value>) style call */
   327     switch (param_direction) {
   372       symbol_c *param_value = function_call_param_iterator.search(param_name);
   328       case function_param_iterator_c::direction_in:
   373       delete param_name;
   329         if (param_value == NULL) {
   374       
   330           /* No value given for parameter, so we must use the default... */
   375       /* Get the value from a foo(<param_value>) style call */
   331           /* First check whether default value specified in function declaration...*/
   376       if (param_value == NULL)
   332           param_value = fp_iterator.default_value();
   377         param_value = function_call_param_iterator.next();
   333         }
   378       
   334         if (param_value == NULL) {
   379       if (param_value == NULL) ERROR;
   335           /* If not, get the default value of this variable's type */
   380       
   336           param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance());
   381       switch (current_function_type) {
   337         }
   382         case function_add:
   338         if (param_value == NULL) ERROR;
   383           if (search_expression_type->is_time_type(function_return_type)) {
   339         param_value->accept(*this);
   384             if (current_param == 0) {
   340 	break;
   385               s4o.print("__add_timespec(");
   341       case function_param_iterator_c::direction_out:
   386               param_value->accept(*this);
   342       case function_param_iterator_c::direction_inout:
   387             }
   343         if (param_value == NULL) {
   388             else if (current_param == 1) {
   344 	  /* no parameter value given, so we pass a previously declared temporary variable. */
   389               s4o.print(", ");
   345           std::string *temp_var_name = temp_var_name_factory.new_name();
   390               param_value->accept(*this);
   346           s4o.print(*temp_var_name);
   391               s4o.print(")");
   347           delete temp_var_name;
   392             }
   348 	} else {
   393             else ERROR;
       
   394           }
       
   395           else {
       
   396             if (current_param == 0)
       
   397               s4o.print("(");
       
   398             else
       
   399               s4o.print(" + ");
       
   400             param_value->accept(*this);
       
   401             if (current_param == nb_param - 1)
       
   402               s4o.print(")");
       
   403           }
       
   404           break;
       
   405         case function_sub:
       
   406           if (search_expression_type->is_time_type(function_return_type)) {
       
   407             if (current_param == 0) {
       
   408               s4o.print("__sub_timespec(");
       
   409               param_value->accept(*this);
       
   410             }
       
   411             else if (current_param == 1) {
       
   412               s4o.print(", ");
       
   413               param_value->accept(*this);
       
   414               s4o.print(")");
       
   415             }
       
   416             else ERROR;
       
   417           }
       
   418           else {
       
   419             if (current_param == 0) {
       
   420               s4o.print("(");
       
   421               param_value->accept(*this);
       
   422             }
       
   423             else if (current_param == 1) {
       
   424               s4o.print(" - ");
       
   425               param_value->accept(*this);
       
   426               s4o.print(")");
       
   427             }
       
   428             else ERROR;
       
   429           }
       
   430           break;
       
   431         case function_and:
       
   432           if (current_param == 0)
       
   433             s4o.print("(");
       
   434           else
       
   435             if (search_expression_type->is_bool_type(function_return_type))
       
   436               s4o.print(" && ");
       
   437             else
       
   438               s4o.print(" & ");
   349           param_value->accept(*this);
   439           param_value->accept(*this);
   350 	}
   440           if (current_param == nb_param - 1)
   351 	break;
   441             s4o.print(")");
   352       case function_param_iterator_c::direction_extref:
   442           break;
   353         /* TODO! */
   443         case function_or:
   354         ERROR;
   444           if (current_param == 0)
   355         break;
   445             s4o.print("(");
   356     } /* switch */
   446           else
   357   } /* for(...) */
   447             if (search_expression_type->is_bool_type(function_return_type))
   358 
   448               s4o.print(" || ");
   359   // symbol->parameter_assignment->accept(*this);
   449             else
   360   s4o.print(")");
   450               s4o.print(" | ");
       
   451           param_value->accept(*this);
       
   452           if (current_param == nb_param - 1)
       
   453             s4o.print(")");
       
   454           break;
       
   455         default: ERROR;
       
   456       }
       
   457     } /* for(...) */
       
   458   }
       
   459   else {
       
   460     /* loop through each function parameter, find the value we should pass
       
   461      * to it, and then output the c equivalent...
       
   462      */
       
   463     function_param_iterator_c fp_iterator(f_decl);
       
   464   
       
   465     symbol->function_name->accept(*this);
       
   466     s4o.print("(");
       
   467   
       
   468     identifier_c *param_name;
       
   469     function_call_param_iterator_c function_call_param_iterator(symbol);
       
   470     for(int i = 1; (param_name = fp_iterator.next()) != NULL; i++) {
       
   471       if (i != 1)
       
   472         s4o.print(", ");
       
   473   
       
   474       function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
       
   475   
       
   476       /* Get the value from a foo(<param_name> = <param_value>) style call */
       
   477       symbol_c *param_value = function_call_param_iterator.search(param_name);
       
   478   
       
   479       /* Get the value from a foo(<param_value>) style call */
       
   480       if (param_value == NULL)
       
   481         param_value = function_call_param_iterator.next();
       
   482   
       
   483       symbol_c *param_type = fp_iterator.param_type();
       
   484       if (param_type == NULL) ERROR;
       
   485   
       
   486       switch (param_direction) {
       
   487         case function_param_iterator_c::direction_in:
       
   488           if (param_value == NULL) {
       
   489             /* No value given for parameter, so we must use the default... */
       
   490             /* First check whether default value specified in function declaration...*/
       
   491             param_value = fp_iterator.default_value();
       
   492           }
       
   493           if (param_value == NULL) {
       
   494             /* If not, get the default value of this variable's type */
       
   495             param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance());
       
   496           }
       
   497           if (param_value == NULL) ERROR;
       
   498           param_value->accept(*this);
       
   499           break;
       
   500         case function_param_iterator_c::direction_out:
       
   501         case function_param_iterator_c::direction_inout:
       
   502           if (param_value == NULL) {
       
   503             /* no parameter value given, so we pass a previously declared temporary variable. */
       
   504             std::string *temp_var_name = temp_var_name_factory.new_name();
       
   505             s4o.print(*temp_var_name);
       
   506             delete temp_var_name;
       
   507           } else {
       
   508             param_value->accept(*this);
       
   509           }
       
   510           break;
       
   511         case function_param_iterator_c::direction_extref:
       
   512           /* TODO! */
       
   513           ERROR;
       
   514           break;
       
   515       } /* switch */
       
   516     } /* for(...) */
       
   517     // symbol->parameter_assignment->accept(*this);
       
   518     s4o.print(")");
       
   519   }
       
   520 
   361   return NULL;
   521   return NULL;
   362 }
   522 }
   363 
   523 
   364 /********************/
   524 /********************/
   365 /* B 3.2 Statements */
   525 /* B 3.2 Statements */