stage3/narrow_candidate_datatypes.cc
changeset 425 c8e6cf57324a
parent 424 43d73e28eca8
child 426 78f31e12fc52
equal deleted inserted replaced
424:43d73e28eca8 425:c8e6cf57324a
    52 }
    52 }
    53 
    53 
    54 narrow_candidate_datatypes_c::~narrow_candidate_datatypes_c(void) {
    54 narrow_candidate_datatypes_c::~narrow_candidate_datatypes_c(void) {
    55 }
    55 }
    56 
    56 
       
    57 
       
    58 /* Only set the symbol's desired datatype to 'datatype' if that datatype is in the candidate_datatype list */
       
    59 static void set_datatype(symbol_c *datatype, symbol_c *symbol) {
       
    60 	symbol->datatype = NULL;   
       
    61 	if (search_in_datatype_list(datatype, symbol->candidate_datatypes) >= 0)
       
    62 		symbol->datatype = datatype;  
       
    63 }
       
    64 
       
    65 
       
    66 
       
    67 
    57 bool narrow_candidate_datatypes_c::is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]) {
    68 bool narrow_candidate_datatypes_c::is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]) {
    58 	for (int k = 0; NULL != widen_table[k].left;  k++) {
    69 	for (int k = 0; NULL != widen_table[k].left;  k++) {
    59 		if        ((typeid(*left_type)   == typeid(*widen_table[k].left))
    70 		if        ((typeid(*left_type)   == typeid(*widen_table[k].left))
    60 		        && (typeid(*right_type)  == typeid(*widen_table[k].right))
    71 		        && (typeid(*right_type)  == typeid(*widen_table[k].right))
    61 				&& (typeid(*result_type) == typeid(*widen_table[k].result))) {
    72 				&& (typeid(*result_type) == typeid(*widen_table[k].result))) {
    93 
   104 
    94 		/* Set the desired datatype for this parameter, and call it recursively. */
   105 		/* Set the desired datatype for this parameter, and call it recursively. */
    95 		/* Note that if the call has more parameters than those declared in the function/FB declaration,
   106 		/* Note that if the call has more parameters than those declared in the function/FB declaration,
    96 		 * we may be setting this to NULL!
   107 		 * we may be setting this to NULL!
    97 		 */
   108 		 */
    98 		call_param_value->datatype = base_type(fp_iterator.param_type());
   109 		symbol_c *desired_datatype = base_type(fp_iterator.param_type());
    99 		if ((NULL != param_name) && (NULL == call_param_value->datatype)) ERROR;
   110 		if ((NULL != param_name) && (NULL == desired_datatype)) ERROR;
   100 		if ((NULL == param_name) && (NULL != call_param_value->datatype)) ERROR;
   111 		if ((NULL == param_name) && (NULL != desired_datatype)) ERROR;
       
   112 
       
   113 		set_datatype(desired_datatype, call_param_value);
   101 		call_param_value->accept(*this);
   114 		call_param_value->accept(*this);
   102 
   115 
   103 		if (NULL != param_name) 
   116 		if (NULL != param_name) 
   104 			if (extensible_parameter_highest_index < fp_iterator.extensible_param_index())
   117 			if (extensible_parameter_highest_index < fp_iterator.extensible_param_index())
   105 				extensible_parameter_highest_index = fp_iterator.extensible_param_index();
   118 				extensible_parameter_highest_index = fp_iterator.extensible_param_index();
   143 		/* Set the desired datatype for this parameter, and call it recursively. */
   156 		/* Set the desired datatype for this parameter, and call it recursively. */
   144 		/* NOTE: When handling a FB call, this narrow_formal_call() may be called to analyse
   157 		/* NOTE: When handling a FB call, this narrow_formal_call() may be called to analyse
   145 		 *       an invalid FB call (call with parameters that do not exist on the FB declaration).
   158 		 *       an invalid FB call (call with parameters that do not exist on the FB declaration).
   146 		 *       For this reason, the param_name may come out as NULL!
   159 		 *       For this reason, the param_name may come out as NULL!
   147 		 */
   160 		 */
   148 		call_param_value->datatype = base_type(fp_iterator.param_type());
   161 		symbol_c *desired_datatype = base_type(fp_iterator.param_type());
   149 		if ((NULL != param_name) && (NULL == call_param_value->datatype)) ERROR;
   162 		if ((NULL != param_name) && (NULL == desired_datatype)) ERROR;
   150 		if ((NULL == param_name) && (NULL != call_param_value->datatype)) ERROR;
   163 		if ((NULL == param_name) && (NULL != desired_datatype)) ERROR;
   151 
   164 
       
   165 		set_datatype(desired_datatype, call_param_value);
   152 		call_param_value->accept(*this);
   166 		call_param_value->accept(*this);
   153 
   167 
   154 		if (NULL != param_name) 
   168 		if (NULL != param_name) 
   155 			if (extensible_parameter_highest_index < fp_iterator.extensible_param_index())
   169 			if (extensible_parameter_highest_index < fp_iterator.extensible_param_index())
   156 				extensible_parameter_highest_index = fp_iterator.extensible_param_index();
   170 				extensible_parameter_highest_index = fp_iterator.extensible_param_index();