stage4/generate_c/generate_c_inlinefcall.cc
changeset 345 894c0e6d951c
parent 337 9a2262fb7994
child 346 620fd98a021d
equal deleted inserted replaced
344:8f71c46a0a55 345:894c0e6d951c
   243     }
   243     }
   244 
   244 
   245   private:
   245   private:
   246 
   246 
   247     /* A helper function... */
   247     /* A helper function... */
   248 	void *CMP_operator_result_type() {
   248 	void CMP_operator_result_type() {
   249 	  /* the data type resulting from this operation... */
   249 	  /* the data type resulting from this operation... */
   250 	  this->default_variable_name.current_type = &(this->bool_type);
   250 	  this->default_variable_name.current_type = &(this->bool_type);
   251 	  return NULL;
       
   252 	}
   251 	}
   253 
   252 
   254 	/* A helper function... */
   253 	/* A helper function... */
   255     void *BYTE_operator_result_type(void) {
   254     void BYTE_operator_result_type(void) {
   256 	  if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
   255 	  if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) {
   257 		if (search_expression_type->is_literal_integer_type(this->current_operand_type))
   256 		if (search_expression_type->is_literal_integer_type(this->current_operand_type))
   258 		  this->default_variable_name.current_type = &(this->lword_type);
   257 		  this->default_variable_name.current_type = &(this->lword_type);
   259 		else
   258 		else
   260 		  this->default_variable_name.current_type = this->current_operand_type;
   259 		  this->default_variable_name.current_type = this->current_operand_type;
   261 	  }
   260 	  }
   262 	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type))
   261 	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type))
   263 		  this->current_operand_type = this->default_variable_name.current_type;
   262 		  this->current_operand_type = this->default_variable_name.current_type;
   264 	  return NULL;
       
   265 	}
   263 	}
   266 
   264 
   267     /* A helper function... */
   265     /* A helper function... */
   268     void *NUM_operator_result_type(void) {
   266     void NUM_operator_result_type(void) {
   269 	  if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) {
   267 	  if (search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) {
   270 		if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
   268 		if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
   271 			search_expression_type->is_literal_real_type(this->current_operand_type))
   269 			search_expression_type->is_literal_real_type(this->current_operand_type))
   272 		  this->default_variable_name.current_type = &(this->lreal_type);
   270 		  this->default_variable_name.current_type = &(this->lreal_type);
   273 		else
   271 		else
   282 		  this->default_variable_name.current_type = this->current_operand_type;
   280 		  this->default_variable_name.current_type = this->current_operand_type;
   283 	  }
   281 	  }
   284 	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
   282 	  else if (search_expression_type->is_literal_integer_type(this->current_operand_type) ||
   285 			   search_expression_type->is_literal_real_type(this->current_operand_type))
   283 			   search_expression_type->is_literal_real_type(this->current_operand_type))
   286 		this->current_operand_type = this->default_variable_name.current_type;
   284 		this->current_operand_type = this->default_variable_name.current_type;
   287 	  return NULL;
       
   288 	}
   285 	}
   289 
   286 
   290     void *print_getter(symbol_c *symbol) {
   287     void *print_getter(symbol_c *symbol) {
   291       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   288       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
   292       if (vartype == search_var_instance_decl_c::external_vt)
   289       if (vartype == search_var_instance_decl_c::external_vt)
   776     void *visit(ADD_operator_c *symbol)	{
   773     void *visit(ADD_operator_c *symbol)	{
   777       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   774       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   778           search_expression_type->is_time_type(this->current_operand_type)) {
   775           search_expression_type->is_time_type(this->current_operand_type)) {
   779         /* the data type resulting from this operation... */
   776         /* the data type resulting from this operation... */
   780         this->default_variable_name.current_type = this->current_operand_type;
   777         this->default_variable_name.current_type = this->current_operand_type;
   781         return NULL;
   778       }
   782       }
   779       else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   783       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
       
   784           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   780           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   785         return NUM_operator_result_type();
   781         NUM_operator_result_type();
   786       }
   782       }
   787       ERROR;
   783       else {ERROR;}
   788       return NULL;
   784       return NULL;
   789     }
   785     }
   790 
   786 
   791     void *visit(SUB_operator_c *symbol)	{
   787     void *visit(SUB_operator_c *symbol)	{
   792       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   788       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   793           search_expression_type->is_time_type(this->current_operand_type)) {
   789           search_expression_type->is_time_type(this->current_operand_type)) {
   794         /* the data type resulting from this operation... */
   790         /* the data type resulting from this operation... */
   795         this->default_variable_name.current_type = this->current_operand_type;
   791         this->default_variable_name.current_type = this->current_operand_type;
   796         return NULL;
   792       }
   797       }
   793       else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   798       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
       
   799           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   794           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   800     	return NUM_operator_result_type();
   795     	NUM_operator_result_type();
   801       }
   796       }
   802       ERROR;
   797       else {ERROR;}
   803       return NULL;
   798       return NULL;
   804     }
   799     }
   805 
   800 
   806     void *visit(MUL_operator_c *symbol)	{
   801     void *visit(MUL_operator_c *symbol)	{
   807       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   802       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   808           search_expression_type->is_integer_type(this->current_operand_type)) {
   803           search_expression_type->is_integer_type(this->current_operand_type)) {
   809         return NULL;
   804         /* the data type resulting from this operation is unchanged! */
   810       }
   805       }
   811       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   806       else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   812           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   807           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   813     	return NUM_operator_result_type();
   808     	NUM_operator_result_type();
   814       }
   809       }
   815       ERROR;
   810       else {ERROR;}
   816       return NULL;
   811       return NULL;
   817     }
   812     }
   818 
   813 
   819     void *visit(DIV_operator_c *symbol)	{
   814     void *visit(DIV_operator_c *symbol)	{
   820       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   815       if (search_expression_type->is_time_type(this->default_variable_name.current_type) &&
   821           search_expression_type->is_integer_type(this->current_operand_type)) {
   816           search_expression_type->is_integer_type(this->current_operand_type)) {
   822         return NULL;
   817         /* the data type resulting from this operation is unchanged! */
   823       }
   818       }
   824       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   819       else if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   825           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   820           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   826         return NUM_operator_result_type();
   821         NUM_operator_result_type();
   827       }
   822       }
   828       ERROR;
   823       else {ERROR;}
   829       return NULL;
   824       return NULL;
   830     }
   825     }
   831 
   826 
   832     void *visit(MOD_operator_c *symbol)	{
   827     void *visit(MOD_operator_c *symbol)	{
   833       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   828       if (search_expression_type->is_num_type(this->default_variable_name.current_type) &&
   834           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   829           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   835         return NUM_operator_result_type();
   830         NUM_operator_result_type();
   836       }
   831       }
   837       ERROR;
   832       else {ERROR;}
   838       return NULL;
   833       return NULL;
   839     }
   834     }
   840 
   835 
   841     void *visit(GT_operator_c *symbol)	{
   836     void *visit(GT_operator_c *symbol)	{
   842       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   837       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   843           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
   838           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   844         return CMP_operator_result_type();
   839         CMP_operator_result_type();
   845       ERROR;
   840       }
       
   841       else {ERROR;}
   846       return NULL;
   842       return NULL;
   847     }
   843     }
   848 
   844 
   849     void *visit(GE_operator_c *symbol)	{
   845     void *visit(GE_operator_c *symbol)	{
   850       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   846       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   851           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
   847           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   852         return CMP_operator_result_type();
   848         CMP_operator_result_type();
   853       ERROR;
   849       }
       
   850       else {ERROR;}
   854       return NULL;
   851       return NULL;
   855     }
   852     }
   856 
   853 
   857     void *visit(EQ_operator_c *symbol)	{
   854     void *visit(EQ_operator_c *symbol)	{
   858       if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
   855       if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   859         return CMP_operator_result_type();
   856         CMP_operator_result_type();
   860       ERROR;
   857       }
       
   858       else {ERROR;}
   861       return NULL;
   859       return NULL;
   862     }
   860     }
   863 
   861 
   864     void *visit(LT_operator_c *symbol)	{
   862     void *visit(LT_operator_c *symbol)	{
   865       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   863       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   866           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
   864           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   867         return CMP_operator_result_type();
   865         CMP_operator_result_type();
       
   866       }
       
   867       else {ERROR;}
   868       return NULL;
   868       return NULL;
   869     }
   869     }
   870 
   870 
   871     void *visit(LE_operator_c *symbol)	{
   871     void *visit(LE_operator_c *symbol)	{
   872       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   872       if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) &&
   873           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
   873           search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   874         return CMP_operator_result_type();
   874         CMP_operator_result_type();
   875       ERROR;
   875       }
       
   876       else {ERROR;}
   876       return NULL;
   877       return NULL;
   877     }
   878     }
   878 
   879 
   879     void *visit(NE_operator_c *symbol)	{
   880     void *visit(NE_operator_c *symbol)	{
   880       if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type))
   881       if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) {
   881         return CMP_operator_result_type();
   882         CMP_operator_result_type();
   882       ERROR;
   883       }
       
   884       else {ERROR;}
   883       return NULL;
   885       return NULL;
   884     }
   886     }
   885 
   887 
   886     /***************************************/
   888     /***************************************/
   887     /* B.3 - Language ST (Structured Text) */
   889     /* B.3 - Language ST (Structured Text) */