Bug 895728 part 3. Fix overload resolution to work with the new boolean/numeric/string setup. r=khuey

This commit is contained in:
Boris Zbarsky 2013-07-30 10:39:34 -07:00
parent 8bad2f9c1a
commit e66bdfb7fb
5 changed files with 89 additions and 30 deletions

View File

@ -4892,21 +4892,6 @@ class CGMethodCall(CGThing):
# Select the right overload from our set.
distinguishingArg = "args[%d]" % distinguishingIndex
def pickFirstSignature(condition, filterLambda):
sigs = filter(filterLambda, possibleSignatures)
assert len(sigs) < 2
if len(sigs) > 0:
if condition is None:
caseBody.append(
getPerSignatureCall(sigs[0], distinguishingIndex))
else:
caseBody.append(CGGeneric("if (" + condition + ") {"))
caseBody.append(CGIndenter(
getPerSignatureCall(sigs[0], distinguishingIndex)))
caseBody.append(CGGeneric("}"))
return True
return False
def tryCall(signature, indent, isDefinitelyObject=False,
isNullOrUndefined=False):
assert not isDefinitelyObject or not isNullOrUndefined
@ -5033,18 +5018,52 @@ class CGMethodCall(CGThing):
caseBody.append(CGGeneric("}"))
# The remaining cases are mutually exclusive. The
# pickFirstSignature calls are what change caseBody
# Check for strings or enums
if pickFirstSignature(None,
lambda s: (distinguishingType(s).isString() or
distinguishingType(s).isEnum())):
pass
# Check for primitives
elif pickFirstSignature(None,
lambda s: distinguishingType(s).isPrimitive()):
pass
# Now we only have to consider booleans, numerics, and strings. If
# we only have one of them, then we can just output it. But if not,
# then we need to output some of the cases conditionally: if we have
# a string overload, then boolean and numeric are conditional, and
# if not then boolean is conditional if we have a numeric overload.
def findUniqueSignature(filterLambda):
sigs = filter(filterLambda, possibleSignatures)
assert len(sigs) < 2
if len(sigs) > 0:
return sigs[0]
return None
stringSignature = findUniqueSignature(
lambda s: (distinguishingType(s).isString() or
distinguishingType(s).isEnum()))
numericSignature = findUniqueSignature(
lambda s: distinguishingType(s).isNumeric())
booleanSignature = findUniqueSignature(
lambda s: distinguishingType(s).isBoolean())
if stringSignature or numericSignature:
booleanCondition = "%s.isBoolean()"
else:
booleanCondition = None
if stringSignature:
numericCondition = "%s.isNumber()"
else:
numericCondition = None
def addCase(sig, condition):
sigCode = getPerSignatureCall(sig, distinguishingIndex)
if condition:
sigCode = CGIfWrapper(sigCode,
condition % distinguishingArg)
caseBody.append(sigCode)
if booleanSignature:
addCase(booleanSignature, booleanCondition)
if numericSignature:
addCase(numericSignature, numericCondition)
if stringSignature:
addCase(stringSignature, None)
if (not booleanSignature and not numericSignature and
not stringSignature):
# Just throw; we have no idea what we're supposed to
# do with this.
caseBody.append(CGGeneric(

View File

@ -564,14 +564,24 @@ public:
TestInterface* Overload1(const nsAString&, TestInterface&);
void Overload2(TestInterface&);
void Overload2(JSContext*, const Dict&);
void Overload2(bool);
void Overload2(const nsAString&);
void Overload2(Date);
void Overload3(TestInterface&);
void Overload3(const TestCallback&);
void Overload3(const nsAString&);
void Overload3(bool);
void Overload4(TestInterface&);
void Overload4(TestCallbackInterface&);
void Overload4(const nsAString&);
void Overload5(int32_t);
void Overload5(TestEnum);
void Overload6(int32_t);
void Overload6(bool);
void Overload7(int32_t);
void Overload7(bool);
void Overload7(const nsCString&);
void Overload8(int32_t);
void Overload8(TestInterface&);
// Variadic handling
void PassVariadicThirdArg(const nsAString&, int32_t,

View File

@ -513,14 +513,24 @@ interface TestInterface {
TestInterface overload1(DOMString strs, TestInterface arg);
void overload2(TestInterface arg);
void overload2(optional Dict arg);
void overload2(boolean arg);
void overload2(DOMString arg);
void overload2(Date arg);
void overload3(TestInterface arg);
void overload3(TestCallback arg);
void overload3(DOMString arg);
void overload3(boolean arg);
void overload4(TestInterface arg);
void overload4(TestCallbackInterface arg);
void overload4(DOMString arg);
void overload5(long arg);
void overload5(TestEnum arg);
void overload6(long arg);
void overload6(boolean arg);
void overload7(long arg);
void overload7(boolean arg);
void overload7(ByteString arg);
void overload8(long arg);
void overload8(TestInterface arg);
// Variadic handling
void passVariadicThirdArg(DOMString arg1, long arg2, TestInterface... arg3);

View File

@ -410,14 +410,24 @@ interface TestExampleInterface {
TestInterface overload1(DOMString strs, TestInterface arg);
void overload2(TestInterface arg);
void overload2(optional Dict arg);
void overload2(boolean arg);
void overload2(DOMString arg);
void overload2(Date arg);
void overload3(TestInterface arg);
void overload3(TestCallback arg);
void overload3(DOMString arg);
void overload3(boolean arg);
void overload4(TestInterface arg);
void overload4(TestCallbackInterface arg);
void overload4(DOMString arg);
void overload5(long arg);
void overload5(TestEnum arg);
void overload6(long arg);
void overload6(boolean arg);
void overload7(long arg);
void overload7(boolean arg);
void overload7(ByteString arg);
void overload8(long arg);
void overload8(TestInterface arg);
// Variadic handling
void passVariadicThirdArg(DOMString arg1, long arg2, TestInterface... arg3);

View File

@ -438,14 +438,24 @@ interface TestJSImplInterface {
TestJSImplInterface overload1(DOMString strs, TestJSImplInterface arg);
void overload2(TestJSImplInterface arg);
void overload2(optional Dict arg);
void overload2(boolean arg);
void overload2(DOMString arg);
void overload2(Date arg);
void overload3(TestJSImplInterface arg);
void overload3(MyTestCallback arg);
void overload3(DOMString arg);
void overload3(boolean arg);
void overload4(TestJSImplInterface arg);
void overload4(TestCallbackInterface arg);
void overload4(DOMString arg);
void overload5(long arg);
void overload5(MyTestEnum arg);
void overload6(long arg);
void overload6(boolean arg);
void overload7(long arg);
void overload7(boolean arg);
void overload7(ByteString arg);
void overload8(long arg);
void overload8(TestJSImplInterface arg);
// Variadic handling
void passVariadicThirdArg(DOMString arg1, long arg2, TestJSImplInterface... arg3);