Implement new, simpler function overload resolution algorithm.

We now give each conversion a cost and then find the minimum sum
of costs for all of the possible overloads.

Fixes issue #194.
This commit is contained in:
Matt Pharr
2012-03-27 13:25:11 -07:00
parent 247775d1ec
commit f8a39402a2
6 changed files with 214 additions and 269 deletions

22
expr.h
View File

@@ -651,20 +651,26 @@ public:
function overloading, this method resolves which actual function
the arguments match best. If the argCouldBeNULL parameter is
non-NULL, each element indicates whether the corresponding argument
is the number zero, indicating that it could be a NULL pointer.
This parameter may be NULL (for cases where overload resolution is
being done just given type information without the parameter
argument expressions being available. It returns true on success.
is the number zero, indicating that it could be a NULL pointer, and
if argIsConstant is non-NULL, each element indicates whether the
corresponding argument is a compile-time constant value. Both of
these parameters may be NULL (for cases where overload resolution
is being done just given type information without the parameter
argument expressions being available. This function returns true
on success.
*/
bool ResolveOverloads(SourcePos argPos,
const std::vector<const Type *> &argTypes,
const std::vector<bool> *argCouldBeNULL = NULL);
const std::vector<bool> *argCouldBeNULL = NULL,
const std::vector<bool> *argIsConstant = NULL);
Symbol *GetMatchingFunction();
private:
bool tryResolve(int (*matchFunc)(const Type *, const Type *),
SourcePos argPos, const std::vector<const Type *> &argTypes,
const std::vector<bool> *argCouldBeNULL);
std::vector<Symbol *> getCandidateFunctions(int argCount) const;
static int computeOverloadCost(const FunctionType *ftype,
const std::vector<const Type *> &argTypes,
const std::vector<bool> *argCouldBeNULL,
const std::vector<bool> *argIsConstant);
/** Name of the function that is being called. */
std::string name;