stage4/generate_c/generate_c_st.cc
changeset 146 eef5e62048c7
parent 145 72ae82e65dbc
child 149 05ca171a3d57
equal deleted inserted replaced
145:72ae82e65dbc 146:eef5e62048c7
   132       stl->accept(*this);
   132       stl->accept(*this);
   133     }
   133     }
   134 
   134 
   135   private:
   135   private:
   136 
   136 
       
   137 void *visit(eno_param_c *symbol) {
       
   138   if (this->is_variable_prefix_null()) {
       
   139     s4o.print("*");
       
   140   }
       
   141   else {
       
   142     this->print_variable_prefix();
       
   143   }
       
   144   s4o.print("ENO");
       
   145   return NULL;
       
   146 }
       
   147 
   137 /*********************/
   148 /*********************/
   138 /* B 1.4 - Variables */
   149 /* B 1.4 - Variables */
   139 /*********************/
   150 /*********************/
   140 void *visit(symbolic_variable_c *symbol) {
   151 void *visit(symbolic_variable_c *symbol) {
   141   unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   152   unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   445     
   456     
   446     function_call_param_iterator_c function_call_param_iterator(symbol);
   457     function_call_param_iterator_c function_call_param_iterator(symbol);
   447     
   458     
   448     int nb_param = ((list_c *)symbol->parameter_assignment_list)->n;
   459     int nb_param = ((list_c *)symbol->parameter_assignment_list)->n;
   449 
   460 
   450 #include "st_code_gen.c"
   461     #include "st_code_gen.c"
   451 
   462 
   452 #if 0
       
   453     for(int current_param = 0; current_param < nb_param; current_param++) {
       
   454       symbol_c *param_name = NULL;
       
   455       switch (current_function_type) {
       
   456         case function_add:
       
   457         case function_and:
       
   458         case function_or:
       
   459           param_name = generate_param_name("IN%d", current_param + 1);
       
   460           break;
       
   461         case function_sub:
       
   462           if (current_param < 2)
       
   463             param_name = generate_param_name("IN%d", current_param + 1);
       
   464           else
       
   465             ERROR;
       
   466           break;
       
   467         default: ERROR;
       
   468       }
       
   469       
       
   470       /* Get the value from a foo(<param_name> = <param_value>) style call */
       
   471       symbol_c *param_value = function_call_param_iterator.search(param_name);
       
   472       delete param_name;
       
   473       
       
   474       /* Get the value from a foo(<param_value>) style call */
       
   475       if (param_value == NULL)
       
   476         param_value = function_call_param_iterator.next();
       
   477       
       
   478       if (param_value == NULL) ERROR;
       
   479       
       
   480       switch (current_function_type) {
       
   481         case function_add:
       
   482           if (search_expression_type->is_time_type(function_return_type)) {
       
   483             if (current_param == 0) {
       
   484               s4o.print("__time_add(");
       
   485               param_value->accept(*this);
       
   486             }
       
   487             else if (current_param == 1) {
       
   488               s4o.print(", ");
       
   489               param_value->accept(*this);
       
   490               s4o.print(")");
       
   491             }
       
   492             else ERROR;
       
   493           }
       
   494           else {
       
   495             if (current_param == 0)
       
   496               s4o.print("(");
       
   497             else
       
   498               s4o.print(" + ");
       
   499             param_value->accept(*this);
       
   500             if (current_param == nb_param - 1)
       
   501               s4o.print(")");
       
   502           }
       
   503           break;
       
   504         case function_sub:
       
   505           if (search_expression_type->is_time_type(function_return_type)) {
       
   506             if (current_param == 0) {
       
   507               s4o.print("__time_sub(");
       
   508               param_value->accept(*this);
       
   509             }
       
   510             else if (current_param == 1) {
       
   511               s4o.print(", ");
       
   512               param_value->accept(*this);
       
   513               s4o.print(")");
       
   514             }
       
   515             else ERROR;
       
   516           }
       
   517           else {
       
   518             if (current_param == 0) {
       
   519               s4o.print("(");
       
   520               param_value->accept(*this);
       
   521             }
       
   522             else if (current_param == 1) {
       
   523               s4o.print(" - ");
       
   524               param_value->accept(*this);
       
   525               s4o.print(")");
       
   526             }
       
   527             else ERROR;
       
   528           }
       
   529           break;
       
   530         case function_and:
       
   531           if (current_param == 0)
       
   532             s4o.print("(");
       
   533           else
       
   534             if (search_expression_type->is_bool_type(function_return_type))
       
   535               s4o.print(" && ");
       
   536             else
       
   537               s4o.print(" & ");
       
   538           param_value->accept(*this);
       
   539           if (current_param == nb_param - 1)
       
   540             s4o.print(")");
       
   541           break;
       
   542         case function_or:
       
   543           if (current_param == 0)
       
   544             s4o.print("(");
       
   545           else
       
   546             if (search_expression_type->is_bool_type(function_return_type))
       
   547               s4o.print(" || ");
       
   548             else
       
   549               s4o.print(" | ");
       
   550           param_value->accept(*this);
       
   551           if (current_param == nb_param - 1)
       
   552             s4o.print(")");
       
   553           break;
       
   554         default: ERROR;
       
   555       }
       
   556     } /* for(...) */
       
   557 #endif
       
   558   }
   463   }
   559   else {
   464   else {
   560     /* loop through each function parameter, find the value we should pass
   465     /* loop through each function parameter, find the value we should pass
   561      * to it, and then output the c equivalent...
   466      * to it, and then output the c equivalent...
   562      */
   467      */
   607           break;
   512           break;
   608         case function_param_iterator_c::direction_out:
   513         case function_param_iterator_c::direction_out:
   609         case function_param_iterator_c::direction_inout:
   514         case function_param_iterator_c::direction_inout:
   610           current_param_is_pointer = true;
   515           current_param_is_pointer = true;
   611           if (param_value == NULL) {
   516           if (param_value == NULL) {
   612             /* no parameter value given, so we pass a previously declared temporary variable. */
   517             s4o.print("NULL");
   613             std::string *temp_var_name = temp_var_name_factory.new_name();
       
   614             s4o.print(*temp_var_name);
       
   615             delete temp_var_name;
       
   616           } else {
   518           } else {
   617             param_value->accept(*this);
   519             param_value->accept(*this);
   618           }
   520           }
   619           current_param_is_pointer = false;
   521           current_param_is_pointer = false;
   620           break;
   522           break;