Title: [207651] trunk/Source/WebCore
Revision
207651
Author
cdu...@apple.com
Date
2016-10-20 18:27:02 -0700 (Thu, 20 Oct 2016)

Log Message

[Bindings] Start using signature->idlType instead of signature->type in the overload resolution code
https://bugs.webkit.org/show_bug.cgi?id=163767

Reviewed by Darin Adler.

Start using signature->idlType instead of signature->type in the overload resolution code
to prepare for union type support.

* bindings/scripts/CodeGeneratorJS.pm:
(ComputeEffectiveOverloadSet):
(AreTypesDistinguishableForOverloadResolution):
(GetDistinguishingArgumentIndex):
(GetOverloadThatMatches):
(GenerateOverloadedFunctionOrConstructor):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (207650 => 207651)


--- trunk/Source/WebCore/ChangeLog	2016-10-21 01:19:24 UTC (rev 207650)
+++ trunk/Source/WebCore/ChangeLog	2016-10-21 01:27:02 UTC (rev 207651)
@@ -1,3 +1,20 @@
+2016-10-20  Chris Dumez  <cdu...@apple.com>
+
+        [Bindings] Start using signature->idlType instead of signature->type in the overload resolution code
+        https://bugs.webkit.org/show_bug.cgi?id=163767
+
+        Reviewed by Darin Adler.
+
+        Start using signature->idlType instead of signature->type in the overload resolution code
+        to prepare for union type support.
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (ComputeEffectiveOverloadSet):
+        (AreTypesDistinguishableForOverloadResolution):
+        (GetDistinguishingArgumentIndex):
+        (GetOverloadThatMatches):
+        (GenerateOverloadedFunctionOrConstructor):
+
 2016-10-20  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Implement WebGL2 bufferData() and bufferSubData() methods

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (207650 => 207651)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-10-21 01:19:24 UTC (rev 207650)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2016-10-21 01:27:02 UTC (rev 207651)
@@ -1914,7 +1914,7 @@
         my @o;
         my $isVariadic = 0;
         foreach my $parameter (@{$overload->parameters}) {
-            push(@t, $parameter->isNullable ? $parameter->type . "?" : $parameter->type);
+            push(@t, $parameter->idlType);
             if ($parameter->isOptional) {
                 push(@o, "optional");
             } elsif ($parameter->isVariadic) {
@@ -1950,7 +1950,7 @@
 # http://heycam.github.io/webidl/#dfn-distinguishable
 sub AreTypesDistinguishableForOverloadResolution
 {
-    my ($typeA, $typeB) = @_;
+    my ($idlTypeA, $idlTypeB) = @_;
 
     my $isDictionary = sub {
         my $type = shift;
@@ -1960,22 +1960,26 @@
         my $type = shift;
         return $codeGenerator->IsFunctionOnlyCallbackInterface($type) || &$isDictionary($type);
     };
+    
+    # FIXME: Add support for union types.
+    # idlTypeA and idlTypeB  are distinguishable if:
+    # - One type is a union type or nullable union type, the other is neither a union type nor a nullable
+    #   union type, and each member type of the first is distinguishable with the second.
+    # - Both types are either a union type or nullable union type, and each member type of the one is
+    #   distinguishable with each member type of the other.
 
     # FIXME: The WebIDL mandates this but this currently does not work because some of our IDL is wrong.
-    # return 0 if IsNullableType($typeA) && IsNullableType($typeB);
+    # return 0 if $idlTypeA->isNullable && $idlTypeB->isNullable;
 
-    $typeA = StripNullable($typeA);
-    $typeB = StripNullable($typeB);
-
-    return 0 if $typeA eq $typeB;
-    return 0 if $typeA eq "object" or $typeB eq "object";
-    return 0 if $codeGenerator->IsNumericType($typeA) && $codeGenerator->IsNumericType($typeB);
-    return 0 if $codeGenerator->IsStringOrEnumType($typeA) && $codeGenerator->IsStringOrEnumType($typeB);
-    return 0 if &$isDictionary($typeA) && &$isDictionary($typeB);
-    return 0 if $codeGenerator->IsCallbackInterface($typeA) && $codeGenerator->IsCallbackInterface($typeB);
-    return 0 if &$isCallbackFunctionOrDictionary($typeA) && &$isCallbackFunctionOrDictionary($typeB);
-    return 0 if $codeGenerator->IsSequenceOrFrozenArrayType($typeA) && $codeGenerator->IsSequenceOrFrozenArrayType($typeB);
-    # FIXME: return 0 if typeA and typeB are both exception types.
+    return 0 if $idlTypeA->name eq $idlTypeB->name;
+    return 0 if $idlTypeA->name eq "object" or $idlTypeB->name eq "object";
+    return 0 if $codeGenerator->IsNumericType($idlTypeA->name) && $codeGenerator->IsNumericType($idlTypeB->name);
+    return 0 if $codeGenerator->IsStringOrEnumType($idlTypeA->name) && $codeGenerator->IsStringOrEnumType($idlTypeB->name);
+    return 0 if &$isDictionary($idlTypeA->name) && &$isDictionary($idlTypeB->name);
+    return 0 if $codeGenerator->IsCallbackInterface($idlTypeA->name) && $codeGenerator->IsCallbackInterface($idlTypeB->name);
+    return 0 if &$isCallbackFunctionOrDictionary($idlTypeA->name) && &$isCallbackFunctionOrDictionary($idlTypeB->name);
+    return 0 if $codeGenerator->IsSequenceOrFrozenArrayType($idlTypeA->name) && $codeGenerator->IsSequenceOrFrozenArrayType($idlTypeB->name);
+    # FIXME: return 0 if $idlTypeA and $idlTypeB are both exception types.
     return 1;
 }
 
@@ -1988,12 +1992,12 @@
     my ($function, $S) = @_;
 
     # FIXME: Consider all the tuples, not just the 2 first ones?
-    my $firstTupleTypes = @{@{$S}[0]}[1];
-    my $secondTupleTypes = @{@{$S}[1]}[1];
-    for (my $index = 0; $index < scalar(@$firstTupleTypes); $index++) {
-        return $index if AreTypesDistinguishableForOverloadResolution(@{$firstTupleTypes}[$index], @{$secondTupleTypes}[$index]);
+    my $firstTupleIDLTypes = @{@{$S}[0]}[1];
+    my $secondTupleIDLTypes = @{@{$S}[1]}[1];
+    for (my $index = 0; $index < scalar(@$firstTupleIDLTypes); $index++) {
+        return $index if AreTypesDistinguishableForOverloadResolution(@{$firstTupleIDLTypes}[$index], @{$secondTupleIDLTypes}[$index]);
     }
-    die "Undistinguishable overloads for operation " . $function->signature->name . " with length: " . scalar(@$firstTupleTypes);
+    die "Undistinguishable overloads for operation " . $function->signature->name . " with length: " . scalar(@$firstTupleIDLTypes);
 }
 
 sub GetOverloadThatMatches
@@ -2001,10 +2005,9 @@
     my ($S, $parameterIndex, $matches) = @_;
 
     for my $tuple (@{$S}) {
-        my $type = @{@{$tuple}[1]}[$parameterIndex];
+        my $idlType = @{@{$tuple}[1]}[$parameterIndex];
         my $optionality = @{@{$tuple}[2]}[$parameterIndex];
-        my $isNullable = IsNullableType($type);
-        return @{$tuple}[0] if $matches->(StripNullable($type), $optionality, $isNullable);
+        return @{$tuple}[0] if $matches->($idlType, $optionality);
     }
 }
 
@@ -2050,60 +2053,60 @@
         push(@implContent, "#endif\n") if $conditionalString;
     };
     my $isOptionalParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
+        my ($idlType, $optionality) = @_;
         return $optionality eq "optional";
     };
     my $isDictionaryParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $type eq "Dictionary" || $codeGenerator->IsDictionaryType($type);
+        my ($idlType, $optionality) = @_;
+        return $idlType->name eq "Dictionary" || $codeGenerator->IsDictionaryType($idlType->name);
     };
     my $isNullableOrDictionaryParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $isNullable || &$isDictionaryParameter($type, $optionality, $isNullable);
+        my ($idlType, $optionality) = @_;
+        return $idlType->isNullable || &$isDictionaryParameter($idlType, $optionality);
     };
     my $isRegExpOrObjectParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $type eq "RegExp" || $type eq "object";
+        my ($idlType, $optionality) = @_;
+        return $idlType->name eq "RegExp" || $idlType->name eq "object";
     };
     my $isObjectOrErrorParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $type eq "object" || $type eq "Error";
+        my ($idlType, $optionality) = @_;
+        return $idlType->name eq "object" || $idlType->name eq "Error";
     };
     my $isObjectOrErrorOrDOMExceptionParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return 1 if &$isObjectOrErrorParameter($type, $optionality, $isNullable);
-        return $type eq "DOMException";
+        my ($idlType, $optionality) = @_;
+        return 1 if &$isObjectOrErrorParameter($idlType, $optionality);
+        return $idlType->name eq "DOMException";
     };
     my $isObjectOrCallbackFunctionParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $type eq "object" || $codeGenerator->IsFunctionOnlyCallbackInterface($type);
+        my ($idlType, $optionality) = @_;
+        return $idlType->name eq "object" || $codeGenerator->IsFunctionOnlyCallbackInterface($idlType->name);
     };
     my $isSequenceOrFrozenArrayParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $codeGenerator->IsSequenceOrFrozenArrayType($type);
+        my ($idlType, $optionality) = @_;
+        return $codeGenerator->IsSequenceOrFrozenArrayType($idlType->name);
     };
     my $isDictionaryOrObjectOrCallbackInterfaceParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return 1 if &$isDictionaryParameter($type, $optionality, $isNullable);
-        return 1 if $type eq "object";
-        return 1 if $codeGenerator->IsCallbackInterface($type) && !$codeGenerator->IsFunctionOnlyCallbackInterface($type);
+        my ($idlType, $optionality) = @_;
+        return 1 if &$isDictionaryParameter($idlType, $optionality);
+        return 1 if $idlType->name eq "object";
+        return 1 if $codeGenerator->IsCallbackInterface($idlType->name) && !$codeGenerator->IsFunctionOnlyCallbackInterface($idlType->name);
         return 0;
     };
     my $isBooleanParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $type eq "boolean";
+        my ($idlType, $optionality) = @_;
+        return $idlType->name eq "boolean";
     };
     my $isNumericParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $codeGenerator->IsNumericType($type);
+        my ($idlType, $optionality) = @_;
+        return $codeGenerator->IsNumericType($idlType->name);
     };
     my $isStringOrEnumParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $codeGenerator->IsStringOrEnumType($type);
+        my ($idlType, $optionality) = @_;
+        return $codeGenerator->IsStringOrEnumType($idlType->name);
     };
     my $isAnyParameter = sub {
-        my ($type, $optionality, $isNullable) = @_;
-        return $type eq "any";
+        my ($idlType, $optionality) = @_;
+        return $idlType->name eq "any";
     };
 
     my $maxArgCount = LengthOfLongestFunctionParameterList($function->{overloads});
@@ -2141,7 +2144,8 @@
 
             for my $tuple (@{$S}) {
                 my $overload = @{$tuple}[0];
-                my $type = StripNullable(@{@{$tuple}[1]}[$d]);
+                my $idlType = @{@{$tuple}[1]}[$d];
+                my $type = $idlType->name;
                 if ($codeGenerator->IsWrapperType($type) || $codeGenerator->IsTypedArrayType($type)) {
                     if ($type eq "DOMWindow") {
                         AddToImplIncludes("JSDOMWindowShell.h");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to