Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(915)

Side by Side Diff: Source/WebCore/bindings/dart/gyp/scripts/CodeGeneratorDart.pm

Issue 9288026: Switch to using dartdomgenerator.py for Dart interface and implementation generation. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Address comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 1 # Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com> 2 # Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com> 3 # Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org> 4 # Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
5 # Copyright (C) 2006 Apple Computer, Inc. 5 # Copyright (C) 2006 Apple Computer, Inc.
6 # Copyright (C) 2007, 2008, 2009 Google Inc. 6 # Copyright (C) 2007, 2008, 2009 Google Inc.
7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> 7 # Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
8 # Copyright (C) Research In Motion Limited 2010. All rights reserved. 8 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 # 10 #
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 bless($reference, $object); 95 bless($reference, $object);
96 return $reference; 96 return $reference;
97 } 97 }
98 98
99 sub GenerateModule 99 sub GenerateModule
100 { 100 {
101 my ($object, $dataNode) = @_; 101 my ($object, $dataNode) = @_;
102 } 102 }
103 103
104 my %overrideConstructorParameters = ( 104 my %overrideConstructorParameters = (
105 "Float32Array" => 3, 105 "Float32Array" => 1,
106 "Float64Array" => 3, 106 "Float64Array" => 1,
107 "Int8Array" => 3, 107 "Int8Array" => 1,
108 "Int16Array" => 3, 108 "Int16Array" => 1,
109 "Int32Array" => 3, 109 "Int32Array" => 1,
110 "Uint8Array" => 3, 110 "Uint8Array" => 1,
111 "Uint16Array" => 3, 111 "Uint16Array" => 1,
112 "Uint32Array" => 3, 112 "Uint32Array" => 1,
113 ); 113 );
114 114
115 sub ConstructorParameterCount 115 sub ConstructorParameterCount
116 { 116 {
117 my ($dataNode) = @_; 117 my ($dataNode) = @_;
118 return $overrideConstructorParameters{$dataNode->name} if (exists $overrideC onstructorParameters{$dataNode->name}); 118 return $overrideConstructorParameters{$dataNode->name} if (exists $overrideC onstructorParameters{$dataNode->name});
119 return $dataNode->extendedAttributes->{ConstructorParameters} if (exists $da taNode->extendedAttributes->{ConstructorParameters}); 119 return $dataNode->extendedAttributes->{ConstructorParameters} if (exists $da taNode->extendedAttributes->{ConstructorParameters});
120 return 0; 120 return 0;
121 } 121 }
122 122
(...skipping 15 matching lines...) Expand all
138 } else { 138 } else {
139 $object->GenerateSource($dataNode); 139 $object->GenerateSource($dataNode);
140 $object->GenerateHeader($dataNode); 140 $object->GenerateHeader($dataNode);
141 } 141 }
142 142
143 my $name = $dataNode->name; 143 my $name = $dataNode->name;
144 144
145 # Open files for writing 145 # Open files for writing
146 my $headerFileName = "$outputHeadersDir/Dart${name}.h"; 146 my $headerFileName = "$outputHeadersDir/Dart${name}.h";
147 my $implFileName = "$outputDir/Dart${name}.cpp"; 147 my $implFileName = "$outputDir/Dart${name}.cpp";
148 my $dartInterfaceFileName = "$outputHeadersDir/${name}.dart";
149 my $dartImplFileName = "$outputHeadersDir/${name}Implementation.dart";
150 148
151 open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName"; 149 open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName";
152 open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName "; 150 open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName ";
153 open($DART_INTERFACE, ">$dartInterfaceFileName") || die "Couldn't open file $dartInterfaceFileName";
154 open($DART_IMPL, ">$dartImplFileName") || die "Couldn't open file $dartImplF ileName";
155 151
156 $object->WriteData($dataNode); 152 $object->WriteData($dataNode);
157 } 153 }
158 154
159 # If the node has a [Conditional=XXX] attribute, returns an "ENABLE(XXX)" string for use in an #if. 155 # If the node has a [Conditional=XXX] attribute, returns an "ENABLE(XXX)" string for use in an #if.
160 # FIXME: common with CodeGeneratorV8 156 # FIXME: common with CodeGeneratorV8
161 sub GenerateConditionalStringForAttributes 157 sub GenerateConditionalStringForAttributes
162 { 158 {
163 my ($attributes,) = @_; 159 my ($attributes,) = @_;
164 160
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 my $parameterCount = @{$overload->parameters}; 205 my $parameterCount = @{$overload->parameters};
210 $maxParameterCount = $maxParameterCount > $parameterCount ? $maxParamete rCount : $parameterCount; 206 $maxParameterCount = $maxParameterCount > $parameterCount ? $maxParamete rCount : $parameterCount;
211 } 207 }
212 return $maxParameterCount; 208 return $maxParameterCount;
213 } 209 }
214 210
215 sub HasOptionalParameters 211 sub HasOptionalParameters
216 { 212 {
217 my ($function) = @_; 213 my ($function) = @_;
218 214
219 # FIXME: useCapture was marked as optional upstream, however native
220 # implementation still requires all three parameters. JavaScript bindings
221 # have custom generation for addEventListener and removeEventListener.
222 return 0 if $function->signature->name eq "addEventListener" || $function->s ignature->name eq "removeEventListener";
223
224 foreach my $parameter (@{$function->parameters}) { 215 foreach my $parameter (@{$function->parameters}) {
225 return 1 if IsParameterOptionalInWebKit($parameter); 216 return 1 if IsParameterOptionalInWebKit($parameter);
226 } 217 }
227 } 218 }
228 219
229 sub CanBeConstructed 220 sub CanBeConstructed
230 { 221 {
231 my ($dataNode) = @_; 222 my ($dataNode) = @_;
232 223
233 return $dataNode->extendedAttributes->{CanBeConstructed} || 224 return $dataNode->extendedAttributes->{CanBeConstructed} ||
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 my %nonWrapperTypes = ( 433 my %nonWrapperTypes = (
443 "CompareHow" => 1, 434 "CompareHow" => 1,
444 "EventListener" => 1, 435 "EventListener" => 1,
445 "EventTarget" => 1, 436 "EventTarget" => 1,
446 "MediaQueryListListener" => 1, 437 "MediaQueryListListener" => 1,
447 "OptionsObject" => 1, 438 "OptionsObject" => 1,
448 "VoidCallback" => 1, 439 "VoidCallback" => 1,
449 "WebKitFlags" => 1, 440 "WebKitFlags" => 1,
450 ); 441 );
451 442
443 sub DartInterfaceName
444 {
445 my ($interfaceName,) = @_;
446 return "DOMException" if $interfaceName eq "DOMCoreException";
447 return $interfaceName;
448 }
449
452 sub IsIDLTypeWithDartBindings 450 sub IsIDLTypeWithDartBindings
453 { 451 {
454 my ($idlType,) = @_; 452 my ($idlType,) = @_;
455 453
456 return 0 if exists $idlTypeToDart{$idlType}; 454 return 0 if exists $idlTypeToDart{$idlType};
457 return 0 if exists $primitiveDartTypes{$idlType}; 455 return 0 if exists $primitiveDartTypes{$idlType};
458 return 0 if !IsRefPtrType(IDLTypeToDart($idlType)); 456 return 0 if !IsRefPtrType(IDLTypeToDart($idlType));
459 return 0 if exists $nonWrapperTypes{$idlType}; 457 return 0 if exists $nonWrapperTypes{$idlType};
460 458
461 return 1; 459 return 1;
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 push(@defineInvocationParameters, <<END); 740 push(@defineInvocationParameters, <<END);
743 const $parameterAdapterType $name($adapterParameters); 741 const $parameterAdapterType $name($adapterParameters);
744 if (!$name.conversionSuccessful()) { 742 if (!$name.conversionSuccessful()) {
745 exception = $name.exception(); 743 exception = $name.exception();
746 goto fail; 744 goto fail;
747 } 745 }
748 END 746 END
749 } 747 }
750 @invocationParameters = (@invocationParameters, map { $_->name; } @{$paramet ers}); 748 @invocationParameters = (@invocationParameters, map { $_->name; } @{$paramet ers});
751 749
750 if ($functionName eq "addEventListener" or $functionName eq "removeEventList ener") {
751 # addEventListener's and removeEventListener's last argument is marked
752 # as optional in idl, but is not optional in c++ implementation.
753 push(@invocationParameters, "false") if (@invocationParameters == 2);
754 }
755
752 if ($attributes->{CustomArgumentHandling}) { 756 if ($attributes->{CustomArgumentHandling}) {
753 $implIncludes{"ScriptArguments.h"} = 1; 757 $implIncludes{"ScriptArguments.h"} = 1;
754 $implIncludes{"ScriptCallStack.h"} = 1; 758 $implIncludes{"ScriptCallStack.h"} = 1;
755 $implIncludes{"V8Proxy.h"} = 1; 759 $implIncludes{"V8Proxy.h"} = 1;
756 $implIncludes{"v8.h"} = 1; 760 $implIncludes{"v8.h"} = 1;
757 my $customArgument = $parameterCount + 1; 761 my $customArgument = $parameterCount + 1;
758 push(@defineInvocationParameters, <<END); 762 push(@defineInvocationParameters, <<END);
759 v8::HandleScope handleScope; 763 v8::HandleScope handleScope;
760 v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtilities::domWin dowForCurrentIsolate()->frame())); 764 v8::Context::Scope scope(V8Proxy::mainWorldContext(DartUtilities::domWin dowForCurrentIsolate()->frame()));
761 765
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 } 962 }
959 963
960 END 964 END
961 } 965 }
962 966
963 sub GenerateDartImplementationClassname 967 sub GenerateDartImplementationClassname
964 { 968 {
965 my ($interfaceName,) = @_; 969 my ($interfaceName,) = @_;
966 970
967 my $className = ClassName($interfaceName); 971 my $className = ClassName($interfaceName);
972 my $dartInterfaceName = DartInterfaceName($interfaceName);
968 973
969 push(@implContent, <<END); 974 push(@implContent, <<END);
970 975
971 const char* const ${className}::dartImplementationClassName = "${interfaceName}I mplementation"; 976 const char* const ${className}::dartImplementationClassName = "${dartInterfaceNa me}Implementation";
972 END 977 END
973 } 978 }
974 979
975 sub GenerateImplementationPrologue 980 sub GenerateImplementationPrologue
976 { 981 {
977 my ($dataNode) = @_; 982 my ($dataNode) = @_;
978 983
979 my $interfaceName = $dataNode->name; 984 my $interfaceName = $dataNode->name;
980 my $className = ClassName($interfaceName); 985 my $className = ClassName($interfaceName);
981 my $internalNamespaceName = "Dart${interfaceName}Internal"; 986 my $internalNamespaceName = "Dart${interfaceName}Internal";
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 sub DartAnonymousNamedOptionalParameters 1244 sub DartAnonymousNamedOptionalParameters
1240 { 1245 {
1241 my ($parameterCount) = @_; 1246 my ($parameterCount) = @_;
1242 return "" unless $parameterCount; 1247 return "" unless $parameterCount;
1243 return "[" . DartAnonymousArguments($parameterCount) . "]"; 1248 return "[" . DartAnonymousArguments($parameterCount) . "]";
1244 } 1249 }
1245 1250
1246 sub CreateFunctionNativeDescriptor 1251 sub CreateFunctionNativeDescriptor
1247 { 1252 {
1248 my ($interfaceName, $functionName, $argumentCount) = @_; 1253 my ($interfaceName, $functionName, $argumentCount) = @_;
1254
1255 my $dartInterfaceName = DartInterfaceName($interfaceName);
1249 my $descriptor = NativeBindingDescriptor->new( 1256 my $descriptor = NativeBindingDescriptor->new(
1250 cppCallbackName => "${functionName}Callback", 1257 cppCallbackName => "${functionName}Callback",
1251 nativeId => "${interfaceName}_${functionName}_Callback", 1258 nativeId => "${dartInterfaceName}_${functionName}_Callback",
1252 argumentCount => $argumentCount); 1259 argumentCount => $argumentCount);
1253 push(@dartNatives, $descriptor); 1260 push(@dartNatives, $descriptor);
1254 return $descriptor; 1261 return $descriptor;
1255 } 1262 }
1256 1263
1257 sub CreateGetterNativeDescriptor 1264 sub CreateGetterNativeDescriptor
1258 { 1265 {
1259 my ($interfaceName, $attributeName) = @_; 1266 my ($interfaceName, $attributeName) = @_;
1267 my $dartInterfaceName = DartInterfaceName($interfaceName);
1260 my $descriptor = NativeBindingDescriptor->new( 1268 my $descriptor = NativeBindingDescriptor->new(
1261 cppCallbackName => "${attributeName}Getter", 1269 cppCallbackName => "${attributeName}Getter",
1262 nativeId => "${interfaceName}_${attributeName}_Getter", 1270 nativeId => "${dartInterfaceName}_${attributeName}_Getter",
1263 argumentCount => 1); 1271 argumentCount => 1);
1264 push(@dartNatives, $descriptor); 1272 push(@dartNatives, $descriptor);
1265 return $descriptor; 1273 return $descriptor;
1266 } 1274 }
1267 1275
1268 sub CreateSetterNativeDescriptor 1276 sub CreateSetterNativeDescriptor
1269 { 1277 {
1270 my ($interfaceName, $attributeName) = @_; 1278 my ($interfaceName, $attributeName) = @_;
1279 my $dartInterfaceName = DartInterfaceName($interfaceName);
1271 my $descriptor = NativeBindingDescriptor->new( 1280 my $descriptor = NativeBindingDescriptor->new(
1272 cppCallbackName => "${attributeName}Setter", 1281 cppCallbackName => "${attributeName}Setter",
1273 nativeId => "${interfaceName}_${attributeName}_Setter", 1282 nativeId => "${dartInterfaceName}_${attributeName}_Setter",
1274 argumentCount => 2); 1283 argumentCount => 2);
1275 push(@dartNatives, $descriptor); 1284 push(@dartNatives, $descriptor);
1276 return $descriptor; 1285 return $descriptor;
1277 } 1286 }
1278 1287
1279 sub GenerateDartOptionalArgumentsResolver 1288 sub GenerateDartOptionalArgumentsResolver
1280 { 1289 {
1281 my ($interfaceName, $function) = @_; 1290 my ($interfaceName, $function) = @_;
1282 1291
1283 my $interfaceMethodDeclaration = DartInterfaceMethodDeclaration($interfaceNa me, $function); 1292 my $interfaceMethodDeclaration = DartInterfaceMethodDeclaration($interfaceNa me, $function);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 push(@dartImplContent, <<END); 1568 push(@dartImplContent, <<END);
1560 $implementationClassName.fromBuffer(ArrayBuffer buffer, [int start, int length ]) { 1569 $implementationClassName.fromBuffer(ArrayBuffer buffer, [int start, int length ]) {
1561 this._bind(buffer, start, length); 1570 this._bind(buffer, start, length);
1562 } 1571 }
1563 $implementationClassName.fromList(List<num> list) { 1572 $implementationClassName.fromList(List<num> list) {
1564 this._bind(list, null, null); 1573 this._bind(list, null, null);
1565 } 1574 }
1566 END 1575 END
1567 } 1576 }
1568 if (HasCustomConstructor($dataNode)) { 1577 if (HasCustomConstructor($dataNode)) {
1569 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, "cons tructor", 1 + $parameterCount); 1578 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, "cons tructor", $parameterCount);
1570 my $nativeId = $descriptor->nativeId; 1579 my $nativeId = $descriptor->nativeId;
1571 push(@dartImplContent, " void _bind($arguments) native \"$nativeId\" ;\n"); 1580 push(@dartImplContent, " void _bind($arguments) native \"$nativeId\" ;\n");
1572 } else { 1581 } else {
1573 push(@dartImplContent, " void _bind($arguments) { /* FIXME: bind to the real object */ throw 'Binding unimplemented'; }\n"); 1582 push(@dartImplContent, " void _bind($arguments) { /* FIXME: bind to the real object */ throw 'Binding unimplemented'; }\n");
1574 } 1583 }
1575 } 1584 }
1576 1585
1577 # Generate implementation support. 1586 # Generate implementation support.
1578 # FIXME: get rid of implementation support completely. 1587 # FIXME: get rid of implementation support completely.
1579 push(@dartImplContent, <<END); 1588 push(@dartImplContent, <<END);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 push(@dartInterfaceContent, " $subscriptOperatorDeclaration;\n"); 1688 push(@dartInterfaceContent, " $subscriptOperatorDeclaration;\n");
1680 push(@dartImplContent, " $subscriptOperatorDeclaration { return item($p arameters); }\n"); 1689 push(@dartImplContent, " $subscriptOperatorDeclaration { return item($p arameters); }\n");
1681 } 1690 }
1682 } 1691 }
1683 1692
1684 sub GenerateNativeBinding 1693 sub GenerateNativeBinding
1685 { 1694 {
1686 my ($interfaceName, $function, $parameters) = @_; 1695 my ($interfaceName, $function, $parameters) = @_;
1687 1696
1688 my $functionName = DartName($interfaceName, $function->signature->name); 1697 my $functionName = DartName($interfaceName, $function->signature->name);
1689 if (HasOverloads($function)) { 1698 my $index = 0;
1690 $functionName .= $function->{overloadIndex}; 1699 foreach my $overload (@{$function->{overloads}}) {
1700 $index += 1;
1701 last if $overload == $function;
1702 foreach my $parameter (@{$overload->parameters}) {
1703 $index += 1 if IsParameterOptionalInWebKit($parameter);
1704 }
1691 } 1705 }
1692 if (HasOptionalParameters($function)) { 1706 my $mandatoryParameterCount = 0;
1693 $functionName .= "_" . @$parameters; 1707 foreach my $parameter (@{$function->parameters}) {
1708 last if IsParameterOptionalInWebKit($parameter);
1709 $mandatoryParameterCount += 1;
1710 }
1711 $index += @{$parameters} - $mandatoryParameterCount;
1712 if ($index != 1) {
1713 $functionName .= "_" . $index;
1694 } 1714 }
1695 1715
1696 my $extendedAttributes = $function->signature->extendedAttributes; 1716 my $extendedAttributes = $function->signature->extendedAttributes;
1697 my $returnType = $function->signature->type; 1717 my $returnType = $function->signature->type;
1698 1718
1699 my $dartParameters = DartParameters($function, $parameters, 0); 1719 my $dartParameters = DartParameters($function, $parameters, 0);
1700 my $dartParameterCount = DartParameterCount($function, $parameters); 1720 my $dartParameterCount = DartParameterCount($function, $parameters);
1701 my $methodDeclaration = DartMethodDeclaration($functionName, $dartParameters , $returnType); 1721 my $methodDeclaration = DartMethodDeclaration($functionName, $dartParameters , $returnType);
1702 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, $functionNam e, 1 + $dartParameterCount); 1722 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, $functionNam e, 1 + $dartParameterCount);
1703 my $nativeId = $descriptor->nativeId; 1723 my $nativeId = $descriptor->nativeId;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1741 } 1761 }
1742 1762
1743 if (defined($HEADER)) { 1763 if (defined($HEADER)) {
1744 # Write content to file. 1764 # Write content to file.
1745 print $HEADER @headerContent; 1765 print $HEADER @headerContent;
1746 close($HEADER); 1766 close($HEADER);
1747 undef($HEADER); 1767 undef($HEADER);
1748 1768
1749 @headerContent = (); 1769 @headerContent = ();
1750 } 1770 }
1751
1752 if (defined($DART_INTERFACE)) {
1753 # Write content of Dart file.
1754 print $DART_INTERFACE @dartInterfaceContent;
1755 close($DART_INTERFACE);
1756 undef($DART_INTERFACE);
1757
1758 @dartInterfaceContent = ();
1759 }
1760
1761 if (defined($DART_IMPL)) {
1762 # Write content of Dart file.
1763 print $DART_IMPL @dartImplContent;
1764 close($DART_IMPL);
1765 undef($DART_IMPL);
1766
1767 @dartImplContent = ();
1768 }
1769 } 1771 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698