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

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: Created 8 years, 11 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 # Commit changes! 102 # Commit changes!
103 $object->WriteData(); 103 $object->WriteData();
104 } 104 }
105 105
106 sub GenerateModule 106 sub GenerateModule
107 { 107 {
108 my ($object, $dataNode) = @_; 108 my ($object, $dataNode) = @_;
109 } 109 }
110 110
111 my %overrideConstructorParameters = ( 111 my %overrideConstructorParameters = (
112 "Float32Array" => 3, 112 "Float32Array" => 1,
antonm 2012/01/25 18:56:40 hmm?
podivilov 2012/01/25 19:04:05 See client/dom/src/_FactoryProviders.dart
Anton Muhin 2012/01/26 12:13:35 Sorry, may you elaborate? If this knowledge is hi
podivilov 2012/01/30 18:27:54 TypedArray constructors are declared with a single
antonm 2012/01/31 10:48:02 Sorry, I wasn't clear enough. I believe those exc
113 "Float64Array" => 3, 113 "Float64Array" => 1,
114 "Int8Array" => 3, 114 "Int8Array" => 1,
115 "Int16Array" => 3, 115 "Int16Array" => 1,
116 "Int32Array" => 3, 116 "Int32Array" => 1,
117 "Uint8Array" => 3, 117 "Uint8Array" => 1,
118 "Uint16Array" => 3, 118 "Uint16Array" => 1,
119 "Uint32Array" => 3, 119 "Uint32Array" => 1,
120 ); 120 );
121 121
122 sub ConstructorParameterCount 122 sub ConstructorParameterCount
123 { 123 {
124 my ($dataNode) = @_; 124 my ($dataNode) = @_;
125 return $overrideConstructorParameters{$dataNode->name} if (exists $overrideC onstructorParameters{$dataNode->name}); 125 return $overrideConstructorParameters{$dataNode->name} if (exists $overrideC onstructorParameters{$dataNode->name});
126 return $dataNode->extendedAttributes->{ConstructorParameters} if (exists $da taNode->extendedAttributes->{ConstructorParameters}); 126 return $dataNode->extendedAttributes->{ConstructorParameters} if (exists $da taNode->extendedAttributes->{ConstructorParameters});
127 return 0; 127 return 0;
128 } 128 }
129 129
(...skipping 15 matching lines...) Expand all
145 } else { 145 } else {
146 $object->GenerateSource($dataNode); 146 $object->GenerateSource($dataNode);
147 $object->GenerateHeader($dataNode); 147 $object->GenerateHeader($dataNode);
148 } 148 }
149 149
150 my $name = $dataNode->name; 150 my $name = $dataNode->name;
151 151
152 # Open files for writing 152 # Open files for writing
153 my $headerFileName = "$outputHeadersDir/Dart${name}.h"; 153 my $headerFileName = "$outputHeadersDir/Dart${name}.h";
154 my $implFileName = "$outputDir/Dart${name}.cpp"; 154 my $implFileName = "$outputDir/Dart${name}.cpp";
155 my $dartInterfaceFileName = "$outputHeadersDir/${name}.dart";
156 my $dartImplFileName = "$outputHeadersDir/${name}Implementation.dart";
157 155
158 open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName"; 156 open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName";
159 open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName "; 157 open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName ";
160 open($DART_INTERFACE, ">$dartInterfaceFileName") || die "Couldn't open file $dartInterfaceFileName";
161 open($DART_IMPL, ">$dartImplFileName") || die "Couldn't open file $dartImplF ileName";
162 } 158 }
163 159
164 # If the node has a [Conditional=XXX] attribute, returns an "ENABLE(XXX)" string for use in an #if. 160 # If the node has a [Conditional=XXX] attribute, returns an "ENABLE(XXX)" string for use in an #if.
165 # FIXME: common with CodeGeneratorV8 161 # FIXME: common with CodeGeneratorV8
166 sub GenerateConditionalStringForAttributes 162 sub GenerateConditionalStringForAttributes
167 { 163 {
168 my ($attributes,) = @_; 164 my ($attributes,) = @_;
169 165
170 my $conditional = $attributes->{Conditional}; 166 my $conditional = $attributes->{Conditional};
171 if ($conditional) { 167 if ($conditional) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 my $parameterCount = @{$overload->parameters}; 210 my $parameterCount = @{$overload->parameters};
215 $maxParameterCount = $maxParameterCount > $parameterCount ? $maxParamete rCount : $parameterCount; 211 $maxParameterCount = $maxParameterCount > $parameterCount ? $maxParamete rCount : $parameterCount;
216 } 212 }
217 return $maxParameterCount; 213 return $maxParameterCount;
218 } 214 }
219 215
220 sub HasOptionalParameters 216 sub HasOptionalParameters
221 { 217 {
222 my ($function) = @_; 218 my ($function) = @_;
223 219
224 # FIXME: useCapture was marked as optional upstream, however native
225 # implementation still requires all three parameters. JavaScript bindings
226 # have custom generation for addEventListener and removeEventListener.
227 return 0 if $function->signature->name eq "addEventListener" || $function->s ignature->name eq "removeEventListener";
228
229 foreach my $parameter (@{$function->parameters}) { 220 foreach my $parameter (@{$function->parameters}) {
230 return 1 if IsParameterOptionalInWebKit($parameter); 221 return 1 if IsParameterOptionalInWebKit($parameter);
231 } 222 }
232 } 223 }
233 224
234 sub CanBeConstructed 225 sub CanBeConstructed
235 { 226 {
236 my ($dataNode) = @_; 227 my ($dataNode) = @_;
237 228
238 return $dataNode->extendedAttributes->{CanBeConstructed} || 229 return $dataNode->extendedAttributes->{CanBeConstructed} ||
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 my %nonWrapperTypes = ( 438 my %nonWrapperTypes = (
448 "CompareHow" => 1, 439 "CompareHow" => 1,
449 "EventListener" => 1, 440 "EventListener" => 1,
450 "EventTarget" => 1, 441 "EventTarget" => 1,
451 "MediaQueryListListener" => 1, 442 "MediaQueryListListener" => 1,
452 "OptionsObject" => 1, 443 "OptionsObject" => 1,
453 "VoidCallback" => 1, 444 "VoidCallback" => 1,
454 "WebKitFlags" => 1, 445 "WebKitFlags" => 1,
455 ); 446 );
456 447
448 sub DartInterfaceName
449 {
450 my ($interfaceName,) = @_;
451 return "DOMException" if $interfaceName eq "DOMCoreException";
452 return $interfaceName;
453 }
454
457 sub IsIDLTypeWithDartBindings 455 sub IsIDLTypeWithDartBindings
458 { 456 {
459 my ($idlType,) = @_; 457 my ($idlType,) = @_;
460 458
461 return 0 if exists $idlTypeToDart{$idlType}; 459 return 0 if exists $idlTypeToDart{$idlType};
462 return 0 if exists $primitiveDartTypes{$idlType}; 460 return 0 if exists $primitiveDartTypes{$idlType};
463 return 0 if !IsRefPtrType(IDLTypeToDart($idlType)); 461 return 0 if !IsRefPtrType(IDLTypeToDart($idlType));
464 return 0 if exists $nonWrapperTypes{$idlType}; 462 return 0 if exists $nonWrapperTypes{$idlType};
465 463
466 return 1; 464 return 1;
(...skipping 275 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 } 961 }
958 962
959 END 963 END
960 } 964 }
961 965
962 sub GenerateDartImplementationClassname 966 sub GenerateDartImplementationClassname
963 { 967 {
964 my ($interfaceName,) = @_; 968 my ($interfaceName,) = @_;
965 969
966 my $className = ClassName($interfaceName); 970 my $className = ClassName($interfaceName);
971 my $dartInterfaceName = DartInterfaceName($interfaceName);
967 972
968 push(@implContent, <<END); 973 push(@implContent, <<END);
969 974
970 const char* const ${className}::dartImplementationClassName = "${interfaceName}I mplementation"; 975 const char* const ${className}::dartImplementationClassName = "${dartInterfaceNa me}Implementation";
971 END 976 END
972 } 977 }
973 978
974 sub GenerateImplementationPrologue 979 sub GenerateImplementationPrologue
975 { 980 {
976 my ($dataNode) = @_; 981 my ($dataNode) = @_;
977 982
978 my $interfaceName = $dataNode->name; 983 my $interfaceName = $dataNode->name;
979 my $className = ClassName($interfaceName); 984 my $className = ClassName($interfaceName);
980 my $internalNamespaceName = "Dart${interfaceName}Internal"; 985 my $internalNamespaceName = "Dart${interfaceName}Internal";
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 sub DartAnonymousNamedOptionalParameters 1243 sub DartAnonymousNamedOptionalParameters
1239 { 1244 {
1240 my ($parameterCount) = @_; 1245 my ($parameterCount) = @_;
1241 return "" unless $parameterCount; 1246 return "" unless $parameterCount;
1242 return "[" . DartAnonymousArguments($parameterCount) . "]"; 1247 return "[" . DartAnonymousArguments($parameterCount) . "]";
1243 } 1248 }
1244 1249
1245 sub CreateFunctionNativeDescriptor 1250 sub CreateFunctionNativeDescriptor
1246 { 1251 {
1247 my ($interfaceName, $functionName, $argumentCount) = @_; 1252 my ($interfaceName, $functionName, $argumentCount) = @_;
1253
1254 my $dartInterfaceName = DartInterfaceName($interfaceName);
1248 my $descriptor = NativeBindingDescriptor->new( 1255 my $descriptor = NativeBindingDescriptor->new(
1249 cppCallbackName => "${functionName}Callback", 1256 cppCallbackName => "${functionName}Callback",
1250 nativeId => "${interfaceName}_${functionName}_Callback", 1257 nativeId => "${dartInterfaceName}_${functionName}_Callback",
1251 argumentCount => $argumentCount); 1258 argumentCount => $argumentCount);
1252 push(@dartNatives, $descriptor); 1259 push(@dartNatives, $descriptor);
1253 return $descriptor; 1260 return $descriptor;
1254 } 1261 }
1255 1262
1256 sub CreateGetterNativeDescriptor 1263 sub CreateGetterNativeDescriptor
1257 { 1264 {
1258 my ($interfaceName, $attributeName) = @_; 1265 my ($interfaceName, $attributeName) = @_;
1266 my $dartInterfaceName = DartInterfaceName($interfaceName);
1259 my $descriptor = NativeBindingDescriptor->new( 1267 my $descriptor = NativeBindingDescriptor->new(
1260 cppCallbackName => "${attributeName}Getter", 1268 cppCallbackName => "${attributeName}Getter",
1261 nativeId => "${interfaceName}_${attributeName}_Getter", 1269 nativeId => "${dartInterfaceName}_${attributeName}_Getter",
1262 argumentCount => 1); 1270 argumentCount => 1);
1263 push(@dartNatives, $descriptor); 1271 push(@dartNatives, $descriptor);
1264 return $descriptor; 1272 return $descriptor;
1265 } 1273 }
1266 1274
1267 sub CreateSetterNativeDescriptor 1275 sub CreateSetterNativeDescriptor
1268 { 1276 {
1269 my ($interfaceName, $attributeName) = @_; 1277 my ($interfaceName, $attributeName) = @_;
1278 my $dartInterfaceName = DartInterfaceName($interfaceName);
1270 my $descriptor = NativeBindingDescriptor->new( 1279 my $descriptor = NativeBindingDescriptor->new(
1271 cppCallbackName => "${attributeName}Setter", 1280 cppCallbackName => "${attributeName}Setter",
1272 nativeId => "${interfaceName}_${attributeName}_Setter", 1281 nativeId => "${dartInterfaceName}_${attributeName}_Setter",
1273 argumentCount => 2); 1282 argumentCount => 2);
1274 push(@dartNatives, $descriptor); 1283 push(@dartNatives, $descriptor);
1275 return $descriptor; 1284 return $descriptor;
1276 } 1285 }
1277 1286
1278 sub GenerateDartOptionalArgumentsResolver 1287 sub GenerateDartOptionalArgumentsResolver
1279 { 1288 {
1280 my ($interfaceName, $function) = @_; 1289 my ($interfaceName, $function) = @_;
1281 1290
1282 my $interfaceMethodDeclaration = DartInterfaceMethodDeclaration($interfaceNa me, $function); 1291 my $interfaceMethodDeclaration = DartInterfaceMethodDeclaration($interfaceNa me, $function);
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 my $parameterCount = ConstructorParameterCount($dataNode); 1550 my $parameterCount = ConstructorParameterCount($dataNode);
1542 my $parameters = DartAnonymousNamedOptionalParameters($parameterCount); 1551 my $parameters = DartAnonymousNamedOptionalParameters($parameterCount);
1543 my $arguments = DartAnonymousArguments($parameterCount); 1552 my $arguments = DartAnonymousArguments($parameterCount);
1544 push(@dartInterfaceContent, " $w3cInterfaceName($parameters);\n"); 1553 push(@dartInterfaceContent, " $w3cInterfaceName($parameters);\n");
1545 push(@dartImplContent, <<END); 1554 push(@dartImplContent, <<END);
1546 $implementationClassName($parameters) { 1555 $implementationClassName($parameters) {
1547 this._bind($arguments); 1556 this._bind($arguments);
1548 } 1557 }
1549 END 1558 END
1550 if (HasCustomConstructor($dataNode)) { 1559 if (HasCustomConstructor($dataNode)) {
1551 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, "cons tructor", 1 + $parameterCount); 1560 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, "cons tructor", $parameterCount);
1552 my $nativeId = $descriptor->nativeId; 1561 my $nativeId = $descriptor->nativeId;
1553 push(@dartImplContent, " void _bind($arguments) native \"$nativeId\" ;\n"); 1562 push(@dartImplContent, " void _bind($arguments) native \"$nativeId\" ;\n");
1554 } else { 1563 } else {
1555 push(@dartImplContent, " void _bind($arguments) { /* FIXME: bind to the real object */ throw 'Binding unimplemented'; }\n"); 1564 push(@dartImplContent, " void _bind($arguments) { /* FIXME: bind to the real object */ throw 'Binding unimplemented'; }\n");
1556 } 1565 }
1557 } 1566 }
1558 1567
1559 # Generate implementation support. 1568 # Generate implementation support.
1560 # FIXME: get rid of implementation support completely. 1569 # FIXME: get rid of implementation support completely.
1561 push(@dartImplContent, <<END); 1570 push(@dartImplContent, <<END);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 push(@dartInterfaceContent, " $subscriptOperatorDeclaration;\n"); 1670 push(@dartInterfaceContent, " $subscriptOperatorDeclaration;\n");
1662 push(@dartImplContent, " $subscriptOperatorDeclaration { return item($p arameters); }\n"); 1671 push(@dartImplContent, " $subscriptOperatorDeclaration { return item($p arameters); }\n");
1663 } 1672 }
1664 } 1673 }
1665 1674
1666 sub GenerateNativeBinding 1675 sub GenerateNativeBinding
1667 { 1676 {
1668 my ($interfaceName, $function, $parameters) = @_; 1677 my ($interfaceName, $function, $parameters) = @_;
1669 1678
1670 my $functionName = DartName($interfaceName, $function->signature->name); 1679 my $functionName = DartName($interfaceName, $function->signature->name);
1671 if (HasOverloads($function)) { 1680 my $index = 0;
1672 $functionName .= $function->{overloadIndex}; 1681 foreach my $overload (@{$function->{overloads}}) {
1682 $index += 1;
1683 last if $overload == $function;
1684 foreach my $parameter (@{$overload->parameters}) {
1685 $index += 1 if IsParameterOptionalInWebKit($parameter);
1686 }
1673 } 1687 }
1674 if (HasOptionalParameters($function)) { 1688 my $mandatoryParameterCount = 0;
1675 $functionName .= "_" . @$parameters; 1689 foreach my $parameter (@{$function->parameters}) {
1690 last if IsParameterOptionalInWebKit($parameter);
1691 $mandatoryParameterCount += 1;
1692 }
1693 $index += @{$parameters} - $mandatoryParameterCount;
1694 if ($index != 1) {
1695 $functionName .= "_" . $index;
1676 } 1696 }
1677 1697
1678 my $extendedAttributes = $function->signature->extendedAttributes; 1698 my $extendedAttributes = $function->signature->extendedAttributes;
1679 my $returnType = $function->signature->type; 1699 my $returnType = $function->signature->type;
1680 1700
1681 my $dartParameters = DartParameters($function, $parameters, 0); 1701 my $dartParameters = DartParameters($function, $parameters, 0);
1682 my $dartParameterCount = DartParameterCount($function, $parameters); 1702 my $dartParameterCount = DartParameterCount($function, $parameters);
1683 my $methodDeclaration = DartMethodDeclaration($functionName, $dartParameters , $returnType); 1703 my $methodDeclaration = DartMethodDeclaration($functionName, $dartParameters , $returnType);
1684 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, $functionNam e, 1 + $dartParameterCount); 1704 my $descriptor = CreateFunctionNativeDescriptor($interfaceName, $functionNam e, 1 + $dartParameterCount);
1685 my $nativeId = $descriptor->nativeId; 1705 my $nativeId = $descriptor->nativeId;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 } 1743 }
1724 1744
1725 if (defined($HEADER)) { 1745 if (defined($HEADER)) {
1726 # Write content to file. 1746 # Write content to file.
1727 print $HEADER @headerContent; 1747 print $HEADER @headerContent;
1728 close($HEADER); 1748 close($HEADER);
1729 undef($HEADER); 1749 undef($HEADER);
1730 1750
1731 @headerContent = (); 1751 @headerContent = ();
1732 } 1752 }
1733
1734 if (defined($DART_INTERFACE)) {
antonm 2012/01/25 18:56:40 is it the only piece of this file which can R.I.P?
podivilov 2012/01/25 19:04:05 Don't want to add extra noise. Let's delete this s
1735 # Write content of Dart file.
1736 print $DART_INTERFACE @dartInterfaceContent;
1737 close($DART_INTERFACE);
1738 undef($DART_INTERFACE);
1739
1740 @dartInterfaceContent = ();
1741 }
1742
1743 if (defined($DART_IMPL)) {
1744 # Write content of Dart file.
1745 print $DART_IMPL @dartImplContent;
1746 close($DART_IMPL);
1747 undef($DART_IMPL);
1748
1749 @dartImplContent = ();
1750 }
1751 } 1753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698