stage4/generate_c/generate_c_il.cc
changeset 123 a9b4af71cfa4
parent 98 d0cdf1d00b74
child 146 eef5e62048c7
equal deleted inserted replaced
122:9e57c6d79398 123:a9b4af71cfa4
   819       param_value = function_call_param_iterator.next();
   819       param_value = function_call_param_iterator.next();
   820 
   820 
   821     symbol_c *param_type = fp_iterator.param_type();
   821     symbol_c *param_type = fp_iterator.param_type();
   822     if (param_type == NULL) ERROR;
   822     if (param_type == NULL) ERROR;
   823     
   823     
   824     search_base_type.explore_type(param_type);    
   824         /* now output the value assignment */
   825 
       
   826     /* now output the value assignment */
       
   827     if (param_value != NULL)
   825     if (param_value != NULL)
   828       if ((param_direction == function_param_iterator_c::direction_in) ||
   826       if ((param_direction == function_param_iterator_c::direction_in) ||
   829           (param_direction == function_param_iterator_c::direction_inout)) {
   827           (param_direction == function_param_iterator_c::direction_inout)) {
   830         symbol->fb_name->accept(*this);
   828         symbol->fb_name->accept(*this);
   831         s4o.print(".");
   829         s4o.print(".");
   832         param_name->accept(*this);
   830         param_name->accept(*this);
   833         s4o.print(" = ");
   831         s4o.print(" = ");
   834         if (search_base_type.base_is_subrange()) {
   832         if (search_base_type.type_is_subrange(param_type)) {
   835           s4o.print("__CHECK_");
   833           s4o.print("__CHECK_");
   836           param_type->accept(*this);
   834           param_type->accept(*this);
   837           s4o.print("(");
   835           s4o.print("(");
   838         }
   836         }
   839         param_value->accept(*this);
   837         param_value->accept(*this);
   840         if (search_base_type.base_is_subrange())
   838         if (search_base_type.type_is_subrange(param_type))
   841           s4o.print(")");
   839           s4o.print(")");
   842         s4o.print(";\n" + s4o.indent_spaces);
   840         s4o.print(";\n" + s4o.indent_spaces);
   843       }
   841       }
   844   } /* for(...) */
   842   } /* for(...) */
   845 
   843 
   868     /* now output the value assignment */
   866     /* now output the value assignment */
   869     if (param_value != NULL)
   867     if (param_value != NULL)
   870       if ((param_direction == function_param_iterator_c::direction_out) ||
   868       if ((param_direction == function_param_iterator_c::direction_out) ||
   871           (param_direction == function_param_iterator_c::direction_inout)) {
   869           (param_direction == function_param_iterator_c::direction_inout)) {
   872         symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false);
   870         symbol_c *param_type = search_varfb_instance_type->get_type(param_value, false);
   873         search_base_type.explore_type(param_type);
       
   874         
   871         
   875         s4o.print(";\n"+ s4o.indent_spaces);
   872         s4o.print(";\n"+ s4o.indent_spaces);
   876         param_value->accept(*this);
   873         param_value->accept(*this);
   877         s4o.print(" = ");
   874         s4o.print(" = ");
   878         if (search_base_type.base_is_subrange()) {
   875         if (search_base_type.type_is_subrange(param_type)) {
   879           s4o.print("__CHECK_");
   876           s4o.print("__CHECK_");
   880           param_type->accept(*this);
   877           param_type->accept(*this);
   881           s4o.print("(");
   878           s4o.print("(");
   882         }
   879         }
   883         symbol->fb_name->accept(*this);
   880         symbol->fb_name->accept(*this);
   884         s4o.print(".");
   881         s4o.print(".");
   885         param_name->accept(*this);
   882         param_name->accept(*this);
   886         if (search_base_type.base_is_subrange())
   883         if (search_base_type.type_is_subrange(param_type))
   887           s4o.print(")");
   884           s4o.print(")");
   888       }
   885       }
   889   } /* for(...) */
   886   } /* for(...) */
   890 
   887 
   891   s4o.print(";\n");
   888   s4o.print(";\n");
   941      * with the function calling code in generate_c_st_c, which does require
   938      * with the function calling code in generate_c_st_c, which does require
   942      * the following line...
   939      * the following line...
   943      */
   940      */
   944     if (param_value == NULL)
   941     if (param_value == NULL)
   945       param_value = function_call_param_iterator.next();
   942       param_value = function_call_param_iterator.next();
   946 
       
   947     search_base_type.explore_type(param_type);
       
   948 
   943 
   949     switch (param_direction) {
   944     switch (param_direction) {
   950       case function_param_iterator_c::direction_in:
   945       case function_param_iterator_c::direction_in:
   951         if (param_value == NULL) {
   946         if (param_value == NULL) {
   952           /* No value given for parameter, so we must use the default... */
   947           /* No value given for parameter, so we must use the default... */
   956         if (param_value == NULL) {
   951         if (param_value == NULL) {
   957           /* If not, get the default value of this variable's type */
   952           /* If not, get the default value of this variable's type */
   958           param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance());
   953           param_value = (symbol_c *)param_type->accept(*type_initial_value_c::instance());
   959         }
   954         }
   960         if (param_value == NULL) ERROR;
   955         if (param_value == NULL) ERROR;
   961         if (search_base_type.base_is_subrange()) {
   956         if (search_base_type.type_is_subrange(param_type)) {
   962           s4o.print("__CHECK_");
   957           s4o.print("__CHECK_");
   963           param_type->accept(*this);
   958           param_type->accept(*this);
   964           s4o.print("(");
   959           s4o.print("(");
   965         }
   960         }
   966         param_value->accept(*this);
   961         param_value->accept(*this);
   967         if (search_base_type.base_is_subrange())
   962         if (search_base_type.type_is_subrange(param_type))
   968           s4o.print(")");
   963           s4o.print(")");
   969 	break;
   964 	break;
   970       case function_param_iterator_c::direction_out:
   965       case function_param_iterator_c::direction_out:
   971       case function_param_iterator_c::direction_inout:
   966       case function_param_iterator_c::direction_inout:
   972         if (param_value == NULL) {
   967         if (param_value == NULL) {
  1130   return NULL;
  1125   return NULL;
  1131 }
  1126 }
  1132 
  1127 
  1133 void *visit(ST_operator_c *symbol)	{
  1128 void *visit(ST_operator_c *symbol)	{
  1134   symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false);
  1129   symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false);
  1135   search_base_type.explore_type(operand_type);
  1130   
  1136 
       
  1137   this->current_operand->accept(*this);
  1131   this->current_operand->accept(*this);
  1138   s4o.print(" = ");
  1132   s4o.print(" = ");
  1139   if (search_base_type.base_is_subrange()) {
  1133   if (search_base_type.type_is_subrange(operand_type)) {
  1140     s4o.print("__CHECK_");
  1134     s4o.print("__CHECK_");
  1141     operand_type->accept(*this);
  1135     operand_type->accept(*this);
  1142     s4o.print("(");
  1136     s4o.print("(");
  1143   }
  1137   }
  1144   this->default_variable_name.accept(*this);
  1138   this->default_variable_name.accept(*this);
  1145   if (search_base_type.base_is_subrange())
  1139   if (search_base_type.type_is_subrange(operand_type))
  1146     s4o.print(")");
  1140     s4o.print(")");
  1147   /* the data type resulting from this operation is unchamged. */
  1141   /* the data type resulting from this operation is unchamged. */
  1148   return NULL;
  1142   return NULL;
  1149 }
  1143 }
  1150 
  1144 
  1151 void *visit(STN_operator_c *symbol)	{
  1145 void *visit(STN_operator_c *symbol)	{
  1152   symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false);
  1146   symbol_c *operand_type = search_varfb_instance_type->get_type(this->current_operand, false);
  1153   search_base_type.explore_type(operand_type);
  1147   
  1154 
       
  1155   this->current_operand->accept(*this);
  1148   this->current_operand->accept(*this);
  1156   s4o.print(" = ");
  1149   s4o.print(" = ");
  1157   if (search_base_type.base_is_subrange()) {
  1150   if (search_base_type.type_is_subrange(operand_type)) {
  1158     s4o.print("__CHECK_");
  1151     s4o.print("__CHECK_");
  1159     operand_type->accept(*this);
  1152     operand_type->accept(*this);
  1160     s4o.print("(");
  1153     s4o.print("(");
  1161   }
  1154   }
  1162   if (search_expression_type->is_bool_type(this->current_operand_type))
  1155   if (search_expression_type->is_bool_type(this->current_operand_type))
  1163     s4o.print("!");
  1156     s4o.print("!");
  1164   else
  1157   else
  1165     s4o.print("~");
  1158     s4o.print("~");
  1166   this->default_variable_name.accept(*this);
  1159   this->default_variable_name.accept(*this);
  1167   if (search_base_type.base_is_subrange())
  1160   if (search_base_type.type_is_subrange(operand_type))
  1168     s4o.print(")");
  1161     s4o.print(")");
  1169   /* the data type resulting from this operation is unchamged. */
  1162   /* the data type resulting from this operation is unchamged. */
  1170   return NULL;
  1163   return NULL;
  1171 }
  1164 }
  1172 
  1165 
  1360   else {ERROR;}
  1353   else {ERROR;}
  1361   return NULL;
  1354   return NULL;
  1362 }
  1355 }
  1363 
  1356 
  1364 void *visit(GT_operator_c *symbol)	{
  1357 void *visit(GT_operator_c *symbol)	{
  1365   return CMP_operator(this->current_operand, "__gt_");
  1358   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
       
  1359       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
       
  1360     return CMP_operator(this->current_operand, "__gt_");
       
  1361   ERROR;
       
  1362   return NULL;
  1366 }
  1363 }
  1367 
  1364 
  1368 void *visit(GE_operator_c *symbol)	{
  1365 void *visit(GE_operator_c *symbol)	{
  1369   return CMP_operator(this->current_operand, "__ge_");
  1366   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
       
  1367       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
       
  1368     return CMP_operator(this->current_operand, "__ge_");
       
  1369   ERROR;
       
  1370   return NULL;
  1370 }
  1371 }
  1371 
  1372 
  1372 void *visit(EQ_operator_c *symbol)	{
  1373 void *visit(EQ_operator_c *symbol)	{
  1373   return CMP_operator(this->current_operand, "__eq_");
  1374   if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
       
  1375     return CMP_operator(this->current_operand, "__eq_");
       
  1376   ERROR;
       
  1377   return NULL;
  1374 }
  1378 }
  1375 
  1379 
  1376 void *visit(LT_operator_c *symbol)	{
  1380 void *visit(LT_operator_c *symbol)	{
  1377   return CMP_operator(this->current_operand, "__lt_");
  1381   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
       
  1382       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
       
  1383     return CMP_operator(this->current_operand, "__lt_");
       
  1384   ERROR;
       
  1385   return NULL;
  1378 }
  1386 }
  1379 
  1387 
  1380 void *visit(LE_operator_c *symbol)	{
  1388 void *visit(LE_operator_c *symbol)	{
  1381   return CMP_operator(this->current_operand, "__le_");
  1389   if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
       
  1390       search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
       
  1391     return CMP_operator(this->current_operand, "__le_");
       
  1392   ERROR;
       
  1393   return NULL;
  1382 }
  1394 }
  1383 
  1395 
  1384 void *visit(NE_operator_c *symbol)	{
  1396 void *visit(NE_operator_c *symbol)	{
  1385   return CMP_operator(this->current_operand, "__ne_");
  1397   if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
       
  1398     return CMP_operator(this->current_operand, "__ne_");
       
  1399   ERROR;
       
  1400   return NULL;
  1386 }
  1401 }
  1387 
  1402 
  1388 
  1403 
  1389 //SYM_REF0(CAL_operator_c)
  1404 //SYM_REF0(CAL_operator_c)
  1390 // This method will be called from within the il_fb_call_c visitor method
  1405 // This method will be called from within the il_fb_call_c visitor method