stage4/generate_c/generate_c_il.cc
changeset 382 ac6dfec701c9
parent 377 60b012b7793f
child 392 9b88b8b6bccd
equal deleted inserted replaced
381:2fd934b91ffd 382:ac6dfec701c9
   322       return NULL;
   322       return NULL;
   323     }
   323     }
   324 
   324 
   325     /* A helper function... */
   325     /* A helper function... */
   326     void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) {
   326     void *XXX_CAL_operator(const char *param_name, symbol_c *fb_name) {
       
   327       if (wanted_variablegeneration != expression_vg) {
       
   328         s4o.print(param_name);
       
   329         return NULL;
       
   330       }
       
   331 
   327       if (NULL == fb_name) ERROR;
   332       if (NULL == fb_name) ERROR;
   328       symbolic_variable_c *sv = dynamic_cast<symbolic_variable_c *>(fb_name);
   333       symbolic_variable_c *sv = dynamic_cast<symbolic_variable_c *>(fb_name);
   329       if (NULL == sv) ERROR;
   334       if (NULL == sv) ERROR;
   330       identifier_c *id = dynamic_cast<identifier_c *>(sv->var_name);
   335       identifier_c *id = dynamic_cast<identifier_c *>(sv->var_name);
   331       if (NULL == id) ERROR;
   336       if (NULL == id) ERROR;
   460     		symbol_c* value,
   465     		symbol_c* value,
   461     		symbol_c* fb_symbol = NULL,
   466     		symbol_c* fb_symbol = NULL,
   462     		symbol_c* fb_value = NULL,
   467     		symbol_c* fb_value = NULL,
   463     		bool negative = false) {
   468     		bool negative = false) {
   464       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   469       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
       
   470       bool type_is_complex = search_varfb_instance_type->type_is_complex();
   465       if (vartype == search_var_instance_decl_c::external_vt) {
   471       if (vartype == search_var_instance_decl_c::external_vt) {
   466         symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
   472         symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
   467         /* TODO Find a solution for forcing global complex variables */
   473         /* TODO Find a solution for forcing global complex variables */
   468         if (variable != NULL) {
   474         if (variable != NULL) {
   469           s4o.print(SET_EXTERNAL);
   475           s4o.print(SET_EXTERNAL);
   487       if (fb_symbol != NULL) {
   493       if (fb_symbol != NULL) {
   488         print_variable_prefix();
   494         print_variable_prefix();
   489         fb_symbol->accept(*this);
   495         fb_symbol->accept(*this);
   490         s4o.print(".");
   496         s4o.print(".");
   491       }
   497       }
       
   498       else if (type_is_complex)
       
   499         wanted_variablegeneration = complextype_base_vg;
   492       else
   500       else
   493         wanted_variablegeneration = complextype_base_vg;
   501         wanted_variablegeneration = assignment_vg;
       
   502 
   494       symbol->accept(*this);
   503       symbol->accept(*this);
   495       s4o.print(",");
   504       s4o.print(",");
   496       if (negative) {
   505       if (negative) {
   497 	    if (search_expression_type->is_bool_type(this->current_operand_type))
   506 	    if (search_expression_type->is_bool_type(this->current_operand_type))
   498 		  s4o.print("!");
   507 		  s4o.print("!");
   499 	    else
   508 	    else
   500 		  s4o.print("~");
   509 		  s4o.print("~");
   501       }
   510       }
   502       wanted_variablegeneration = expression_vg;
   511       wanted_variablegeneration = expression_vg;
   503       print_check_function(type, value, fb_value);
   512       print_check_function(type, value, fb_value);
   504       if (search_varfb_instance_type->type_is_complex()) {
   513       if (type_is_complex) {
   505         s4o.print(",");
   514         s4o.print(",");
   506         wanted_variablegeneration = complextype_suffix_vg;
   515         wanted_variablegeneration = complextype_suffix_vg;
   507         symbol->accept(*this);
   516         symbol->accept(*this);
   508       }
   517       }
   509       s4o.print(")");
   518       s4o.print(")");
   550 
   559 
   551 /********************************/
   560 /********************************/
   552 /* B 1.3.3 - Derived data types */
   561 /* B 1.3.3 - Derived data types */
   553 /********************************/
   562 /********************************/
   554 
   563 
       
   564 /*  signed_integer DOTDOT signed_integer */
       
   565 void *visit(subrange_c *symbol) {
       
   566   symbol->lower_limit->accept(*this);
       
   567   return NULL;
       
   568 }
       
   569 
   555 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
   570 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
   556 void *visit(array_specification_c *symbol) {
   571 void *visit(array_specification_c *symbol) {
   557   symbol->non_generic_type_name->accept(*this);
   572   symbol->non_generic_type_name->accept(*this);
   558   return NULL;
   573   return NULL;
   559 }
   574 }
   562 /* B 1.4 - Variables */
   577 /* B 1.4 - Variables */
   563 /*********************/
   578 /*********************/
   564 
   579 
   565 void *visit(symbolic_variable_c *symbol) {
   580 void *visit(symbolic_variable_c *symbol) {
   566   unsigned int vartype;
   581   unsigned int vartype;
   567   if (wanted_variablegeneration == complextype_base_vg)
   582   switch (wanted_variablegeneration) {
   568 	generate_c_base_c::visit(symbol);
   583     case complextype_base_vg:
   569   else if (wanted_variablegeneration == complextype_suffix_vg)
   584     case assignment_vg:
   570 	return NULL;
       
   571   else if (this->is_variable_prefix_null()) {
       
   572 	vartype = search_varfb_instance_type->get_vartype(symbol);
       
   573     if (wanted_variablegeneration == fparam_output_vg) {
       
   574       s4o.print("&(");
       
   575       generate_c_base_c::visit(symbol);
   585       generate_c_base_c::visit(symbol);
   576       s4o.print(")");
   586       break;
   577     }
   587     case complextype_suffix_vg:
   578     else {
   588 	  break;
   579       generate_c_base_c::visit(symbol);
   589     default:
   580     }
   590       if (this->is_variable_prefix_null()) {
   581   }
   591 	    vartype = search_varfb_instance_type->get_vartype(symbol);
   582   else
   592         if (wanted_variablegeneration == fparam_output_vg) {
   583     print_getter(symbol);
   593           s4o.print("&(");
       
   594           generate_c_base_c::visit(symbol);
       
   595           s4o.print(")");
       
   596         }
       
   597         else {
       
   598           generate_c_base_c::visit(symbol);
       
   599         }
       
   600       }
       
   601       else
       
   602         print_getter(symbol);
       
   603       break;
       
   604   }
   584   return NULL;
   605   return NULL;
   585 }
   606 }
   586 
   607 
   587 /********************************************/
   608 /********************************************/
   588 /* B.1.4.1   Directly Represented Variables */
   609 /* B.1.4.1   Directly Represented Variables */
   628   switch (wanted_variablegeneration) {
   649   switch (wanted_variablegeneration) {
   629     case complextype_base_vg:
   650     case complextype_base_vg:
   630       symbol->record_variable->accept(*this);
   651       symbol->record_variable->accept(*this);
   631       break;
   652       break;
   632     case complextype_suffix_vg:
   653     case complextype_suffix_vg:
       
   654     case assignment_vg:
   633       symbol->record_variable->accept(*this);
   655       symbol->record_variable->accept(*this);
   634       s4o.print(".");
   656       s4o.print(".");
   635       symbol->field_selector->accept(*this);
   657       symbol->field_selector->accept(*this);
   636       break;
   658       break;
   637     default:
   659     default:
  1552 /*******************/
  1574 /*******************/
  1553 /* B 2.2 Operators */
  1575 /* B 2.2 Operators */
  1554 /*******************/
  1576 /*******************/
  1555 
  1577 
  1556 void *visit(LD_operator_c *symbol)	{
  1578 void *visit(LD_operator_c *symbol)	{
       
  1579   if (wanted_variablegeneration != expression_vg) {
       
  1580     s4o.print("LD");
       
  1581     return NULL;
       
  1582   }
       
  1583 
  1557   /* the data type resulting from this operation... */
  1584   /* the data type resulting from this operation... */
  1558   this->default_variable_name.current_type = this->current_operand_type;
  1585   this->default_variable_name.current_type = this->current_operand_type;
  1559   XXX_operator(&(this->default_variable_name), " = ", this->current_operand);
  1586   XXX_operator(&(this->default_variable_name), " = ", this->current_operand);
  1560   return NULL;
  1587   return NULL;
  1561 }
  1588 }
  1615   /* the data type resulting from this operation is unchanged. */
  1642   /* the data type resulting from this operation is unchanged. */
  1616   return NULL;
  1643   return NULL;
  1617 }
  1644 }
  1618 
  1645 
  1619 void *visit(S_operator_c *symbol)	{
  1646 void *visit(S_operator_c *symbol)	{
       
  1647   if (wanted_variablegeneration != expression_vg) {
       
  1648     s4o.print("LD");
       
  1649     return NULL;
       
  1650   }
       
  1651 
  1620   if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR;
  1652   if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR;
  1621 
  1653 
  1622   C_modifier();
  1654   C_modifier();
  1623   this->current_operand->accept(*this);
  1655   this->current_operand->accept(*this);
  1624   s4o.print(" = __");
  1656   s4o.print(" = __");
  1633   /* the data type resulting from this operation is unchanged! */
  1665   /* the data type resulting from this operation is unchanged! */
  1634   return NULL;
  1666   return NULL;
  1635 }
  1667 }
  1636 
  1668 
  1637 void *visit(R_operator_c *symbol)	{
  1669 void *visit(R_operator_c *symbol)	{
       
  1670   if (wanted_variablegeneration != expression_vg) {
       
  1671     s4o.print("LD");
       
  1672     return NULL;
       
  1673   }
       
  1674 
  1638   if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR;
  1675   if ((NULL == this->current_operand) || (NULL == this->current_operand_type)) ERROR;
  1639 
  1676 
  1640   C_modifier();
  1677   C_modifier();
  1641   this->current_operand->accept(*this);
  1678   this->current_operand->accept(*this);
  1642   s4o.print(" = __");
  1679   s4o.print(" = __");