stage3/fill_candidate_datatypes.cc
changeset 419 6384168a8e95
parent 418 2ac41d2cba91
child 420 866eb35e4e14
equal deleted inserted replaced
418:2ac41d2cba91 419:6384168a8e95
  1666 void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {
  1666 void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {
  1667 	function_declaration_c *f_decl;
  1667 	function_declaration_c *f_decl;
  1668 	list_c *parameter_list;
  1668 	list_c *parameter_list;
  1669 	list_c *parameter_candidate_datatypes;
  1669 	list_c *parameter_candidate_datatypes;
  1670 	symbol_c *parameter_type;
  1670 	symbol_c *parameter_type;
  1671 	int error_count;
       
  1672 	function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
  1671 	function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
  1673 	function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name);
  1672 	function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name);
  1674 
  1673 	/* If the name of the function being called is not found in the function symbol table, then this is an invalid call */
       
  1674 	/* Since the lexical parser already checks for this, then if this occurs then we have an internal compiler error. */
       
  1675 	if (lower == function_symtable.end()) ERROR;
       
  1676 	
  1675 	if (NULL != symbol->formal_param_list)
  1677 	if (NULL != symbol->formal_param_list)
  1676 		parameter_list = (list_c *)symbol->formal_param_list;
  1678 		parameter_list = (list_c *)symbol->formal_param_list;
  1677 	else if (NULL != symbol->nonformal_param_list)
  1679 	else if (NULL != symbol->nonformal_param_list)
  1678 		parameter_list = (list_c *)symbol->nonformal_param_list;
  1680 		parameter_list = (list_c *)symbol->nonformal_param_list;
  1679 	else ERROR;
  1681 	else ERROR;
       
  1682 	
  1680 	if (debug) std::cout << "function()\n";
  1683 	if (debug) std::cout << "function()\n";
  1681 	parameter_list->accept(*this);
  1684 	parameter_list->accept(*this);
  1682 	for(; lower != upper; lower++) {
  1685 	for(; lower != upper; lower++) {
       
  1686 		int error_count = 0;
  1683 		f_decl = function_symtable.get_value(lower);
  1687 		f_decl = function_symtable.get_value(lower);
  1684 		error_count = 0;
       
  1685 		/* Check if function declaration in symbol_table is compatible with parameters */
  1688 		/* Check if function declaration in symbol_table is compatible with parameters */
  1686 		if (NULL != symbol->nonformal_param_list)
  1689 		if (NULL != symbol->nonformal_param_list)  match_nonformal_call(symbol, f_decl, &error_count);
  1687 			/* nonformal parameter function call */
  1690 		if (NULL != symbol->   formal_param_list)     match_formal_call(symbol, f_decl, &error_count);
  1688 			match_nonformal_call(symbol, f_decl, &error_count);
       
  1689 		else
       
  1690 			/* formal parameter function call */
       
  1691 			match_formal_call (symbol, f_decl, &error_count);
       
  1692 		if (0 == error_count) {
  1691 		if (0 == error_count) {
  1693 			/* Add basetype matching function only if not present */
  1692 			/* Add basetype matching function only if not present */
  1694 			unsigned int k;
  1693 			unsigned int k;
  1695 			parameter_type = base_type(f_decl->type_name);
  1694 			parameter_type = base_type(f_decl->type_name);
  1696 			for(k = 0; k < symbol->candidate_datatypes.size(); k++) {
  1695 			for(k = 0; k < symbol->candidate_datatypes.size(); k++) {