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

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

Issue 9231022: WebGL support. (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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
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 = (
112 "Float32Array" => 3,
113 "Float64Array" => 3,
114 "Int8Array" => 3,
115 "Int16Array" => 3,
116 "Int32Array" => 3,
117 "Uint8Array" => 3,
118 "Uint16Array" => 3,
119 "Uint32Array" => 3,
120 );
121
111 sub GenerateInterface 122 sub GenerateInterface
112 { 123 {
113 my ($object, $dataNode, $defines) = @_; 124 my ($object, $dataNode, $defines) = @_;
114 125
115 # Add parent classes (for multiple-inheritance) fields as needed. 126 # Add parent classes (for multiple-inheritance) fields as needed.
116 @allParents = (); 127 @allParents = ();
117 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@allParents, 0); 128 $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode, \@allParents, 0);
118 # Prepare internal structures. 129 # Prepare internal structures.
119 $codeGenerator->LinkOverloadedFunctions($dataNode); 130 $codeGenerator->LinkOverloadedFunctions($dataNode);
120 131
132 if (exists $overrideConstructorParameters{$dataNode->name}) {
antonm 2012/01/18 15:12:23 this feels like a hack to me: if we change the ord
Nikolay 2012/01/19 13:27:34 Done.
133 $dataNode->extendedAttributes->{"ConstructorParameters"} = $overrideCons tructorParameters{$dataNode->name};
antonm 2012/01/18 15:12:23 nit: please, omit "" around ConstructorParameters
Nikolay 2012/01/19 13:27:34 Done.
134 }
135
121 # Start actual generation 136 # Start actual generation
122 if ($dataNode->extendedAttributes->{Callback}) { 137 if ($dataNode->extendedAttributes->{Callback}) {
123 $object->GenerateCallbackDartInterface($dataNode); 138 $object->GenerateCallbackDartInterface($dataNode);
124 $object->GenerateCallbackHeader($dataNode); 139 $object->GenerateCallbackHeader($dataNode);
125 $object->GenerateCallbackImplementation($dataNode); 140 $object->GenerateCallbackImplementation($dataNode);
126 } else { 141 } else {
127 $object->GenerateSource($dataNode); 142 $object->GenerateSource($dataNode);
128 $object->GenerateHeader($dataNode); 143 $object->GenerateHeader($dataNode);
129 } 144 }
130 145
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 # FIXME: useCapture was marked as optional upstream, however native 220 # FIXME: useCapture was marked as optional upstream, however native
206 # implementation still requires all three parameters. JavaScript bindings 221 # implementation still requires all three parameters. JavaScript bindings
207 # have custom generation for addEventListener and removeEventListener. 222 # have custom generation for addEventListener and removeEventListener.
208 return 0 if $function->signature->name eq "addEventListener" || $function->s ignature->name eq "removeEventListener"; 223 return 0 if $function->signature->name eq "addEventListener" || $function->s ignature->name eq "removeEventListener";
209 224
210 foreach my $parameter (@{$function->parameters}) { 225 foreach my $parameter (@{$function->parameters}) {
211 return 1 if IsParameterOptionalInWebKit($parameter); 226 return 1 if IsParameterOptionalInWebKit($parameter);
212 } 227 }
213 } 228 }
214 229
230 sub CanBeConstructed
231 {
232 my ($dataNode) = @_;
233
234 return
235 $dataNode->extendedAttributes->{"CanBeConstructed"} || HasCustomConstruc tor($dataNode);
antonm 2012/01/18 15:12:23 nit: omit "" (here and below)
Nikolay 2012/01/19 13:27:34 Done.
236 }
237
215 sub HasCustomConstructor 238 sub HasCustomConstructor
216 { 239 {
217 my ($dataNode) = @_; 240 my ($dataNode) = @_;
218 241
219 # FIXME: switch to using CanBeConstructed attribute. 242 return $dataNode->extendedAttributes->{"CustomConstructor"} && not ($dataNod e->name =~ "Event");
220 return 1 if $dataNode->name eq "FileReader";
221 return 1 if $dataNode->name eq "XMLHttpRequest";
222 return 1 if $dataNode->name eq "WebKitCSSMatrix";
223 return 1 if $dataNode->name eq "WebKitPoint";
224
225 return 0;
226 } 243 }
227 244
228 sub IsParameterOptionalInWebKit 245 sub IsParameterOptionalInWebKit
229 { 246 {
230 my ($parameter) = @_; 247 my ($parameter) = @_;
231 248
232 # Optional callbacks are not optional parameters in native implementations, they always have a default value (0). 249 # Optional callbacks are not optional parameters in native implementations, they always have a default value (0).
233 my $optional = $parameter->extendedAttributes->{Optional}; 250 my $optional = $parameter->extendedAttributes->{Optional};
234 return $optional && $optional ne "CallWithDefaultValue" && !$parameter->exte ndedAttributes->{Callback}; 251 return $optional && $optional ne "CallWithDefaultValue" && !$parameter->exte ndedAttributes->{Callback};
235 } 252 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 387
371 sub IDLTypeToW3C 388 sub IDLTypeToW3C
372 { 389 {
373 my ($idlType,) = @_; 390 my ($idlType,) = @_;
374 return $idlTypeToW3C{$idlType} if exists $idlTypeToW3C{$idlType}; 391 return $idlTypeToW3C{$idlType} if exists $idlTypeToW3C{$idlType};
375 return $idlType; 392 return $idlType;
376 } 393 }
377 394
378 my %idlTypeToDart = ( 395 my %idlTypeToDart = (
379 "any" => "Object", 396 "any" => "Object",
397 "any[]" => "List",
380 "boolean" => "bool", 398 "boolean" => "bool",
381 "custom" => "Object", 399 "custom" => "Object",
382 "object" => "Object", 400 "object" => "Object",
383 "Array" => "List", 401 "Array" => "List",
384 "DOMObject" => "Object", 402 "DOMObject" => "Object",
385 "DOMString" => "String", 403 "DOMString" => "String",
386 "DOMString[]" => "DOMStringList", 404 "DOMString[]" => "DOMStringList",
387 "DOMTimeStamp" => "int", 405 "DOMTimeStamp" => "int",
388 "ObjectArray" => "List", 406 "ObjectArray" => "List",
389 "SerializedScriptValue" => "Object", 407 "SerializedScriptValue" => "Object",
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 "SVGFitToViewBox" => 1, 1361 "SVGFitToViewBox" => 1,
1344 "SVGLangSpace" => 1, 1362 "SVGLangSpace" => 1,
1345 "SVGLocatable" => 1, 1363 "SVGLocatable" => 1,
1346 "SVGStylable" => 1, 1364 "SVGStylable" => 1,
1347 "SVGTests" => 1, 1365 "SVGTests" => 1,
1348 "SVGTransformable" => 1, 1366 "SVGTransformable" => 1,
1349 "SVGViewSpec" => 1, 1367 "SVGViewSpec" => 1,
1350 "SVGZoomAndPan" => 1, 1368 "SVGZoomAndPan" => 1,
1351 ); 1369 );
1352 1370
1353 sub ListLike 1371 sub ListLikeWithBase
1354 { 1372 {
1355 my ($elementType, $needsAuxiliaryAccessors) = @_; 1373 my ($elementType, $baseClass, $needsAuxiliaryAccessors) = @_;
1356 1374
1357 my @auxiliaryMethods = (); 1375 my @auxiliaryMethods = ();
1358 if ($needsAuxiliaryAccessors) { 1376 if ($needsAuxiliaryAccessors) {
1359 push(@auxiliaryMethods, ["$elementType operator [] (int index)", "numeri cIndexGetter", 2]); 1377 push(@auxiliaryMethods, ["$elementType operator [] (int index)", "numeri cIndexGetter", 2]);
1360 push(@auxiliaryMethods, ["void operator []= (int index, $elementType val ue)", "numericIndexSetter", 3]); 1378 push(@auxiliaryMethods, ["void operator []= (int index, $elementType val ue)", "numericIndexSetter", 3]);
1361 } 1379 }
1362 1380
1363 return IDLTypeInfoStruct->new( 1381 return IDLTypeInfoStruct->new(
1364 additionalInterfaces => ["List<$elementType>"], 1382 additionalInterfaces => ["List<$elementType>"],
1365 superClass => "ListBase<$elementType>", 1383 superClass => "$baseClass",
1366 auxilaryMethods => \@auxiliaryMethods 1384 auxilaryMethods => \@auxiliaryMethods
1367 ); 1385 );
1368 } 1386 }
1369 1387
1388 sub ListLike
1389 {
1390 my ($elementType, $needsAuxiliaryAccessors) = @_;
1391
1392 return ListLikeWithBase($elementType, "ListBase<$elementType>", $needsAuxili aryAccessors);
1393 }
1394
1395 sub ArrayBufferLike
1396 {
1397 my ($elementType, $needsAuxiliaryAccessors) = @_;
1398
1399 return ListLikeWithBase($elementType, "ArrayBufferViewImplementation", $need sAuxiliaryAccessors);
1400 }
1401
1370 sub MapLike 1402 sub MapLike
1371 { 1403 {
1372 # FIXME: most probably we need to deduce more types using hints like 1404 # FIXME: most probably we need to deduce more types using hints like
1373 # HasNameGetter, CustomDeleteProperty, CustomGetPropertyNames, DelegatingPut Function 1405 # HasNameGetter, CustomDeleteProperty, CustomGetPropertyNames, DelegatingPut Function
1374 # attributes. 1406 # attributes.
1375 # FIXME: technically at least DOMStringMap.setItem and DOMStringMap.item cou ld be automatically 1407 # FIXME: technically at least DOMStringMap.setItem and DOMStringMap.item cou ld be automatically
1376 # generated and then used from [] and []=. I don't do it for now not to mes s up with IDLs too 1408 # generated and then used from [] and []=. I don't do it for now not to mes s up with IDLs too
1377 # much. 1409 # much.
1378 # FIXME: support removal of elements if allowed (it is at least for DOMStrin gMap.) 1410 # FIXME: support removal of elements if allowed (it is at least for DOMStrin gMap.)
1379 my ($interfaceName, $keyType, $elementType) = @_; 1411 my ($interfaceName, $keyType, $elementType) = @_;
1380 return IDLTypeInfoStruct->new( 1412 return IDLTypeInfoStruct->new(
1381 additionalInterfaces => ["Map<$keyType, $elementType>"], 1413 additionalInterfaces => ["Map<$keyType, $elementType>"],
1382 superClass => "MapBase<$keyType, $elementType>", 1414 superClass => "MapBase<$keyType, $elementType>",
1383 auxilaryMethods => [ 1415 auxilaryMethods => [
1384 ["Collection<$keyType> getKeys()", "getKeys", 1], 1416 ["Collection<$keyType> getKeys()", "getKeys", 1],
1385 ["$elementType operator [] ($keyType k)", "item", 2], 1417 ["$elementType operator [] ($keyType k)", "item", 2],
1386 ["operator []= ($keyType k, $elementType v)", "setItem", 3], 1418 ["operator []= ($keyType k, $elementType v)", "setItem", 3],
1387 ["$elementType remove($keyType k)", "deleteItem", 2], 1419 ["$elementType remove($keyType k)", "deleteItem", 2],
1388 ], 1420 ],
1389 ); 1421 );
1390 } 1422 }
1391 1423
1392 my %idlTypeInfoOverrides = ( 1424 my %idlTypeInfoOverrides = (
1393 "CanvasPixelArray" => ListLike("int", 1), 1425 "CanvasPixelArray" => ListLike("int", 1),
1394 "DOMStringMap" => MapLike("DOMStringMap", "String", "String"), 1426 "DOMStringMap" => MapLike("DOMStringMap", "String", "String"),
1395 "HTMLCollection" => ListLike("Node"), 1427 "HTMLCollection" => ListLike("Node"),
1396 "NodeList" => ListLike("Node"), 1428 "NodeList" => ListLike("Node"),
1397 "StyleSheetList" => ListLike("StyleSheet"), 1429 "StyleSheetList" => ListLike("StyleSheet"),
1430 "ArrayBufferView" => ListLikeWithBase("num", "ListBase<num>"),
1431 "Float32Array" => ArrayBufferLike("double", 1),
1432 "Float64Array" => ArrayBufferLike("double", 1),
1433 "Int8Array" => ArrayBufferLike("int", 1),
1434 "Int16Array" => ArrayBufferLike("int", 1),
1435 "Int32Array" => ArrayBufferLike("int", 1),
1436 "Uint8Array" => ArrayBufferLike("int", 1),
1437 "Uint16Array" => ArrayBufferLike("int", 1),
1438 "Uint32Array" => ArrayBufferLike("int", 1),
1398 ); 1439 );
1399 1440
1400 # FIXME: turn into the single IDL type info registry. 1441 # FIXME: turn into the single IDL type info registry.
1401 sub IDLTypeInfo 1442 sub IDLTypeInfo
1402 { 1443 {
1403 my ($dataNode,) = @_; 1444 my ($dataNode,) = @_;
1404 my $override = $idlTypeInfoOverrides{$dataNode->name}; 1445 my $override = $idlTypeInfoOverrides{$dataNode->name};
1405 return $override if $override; 1446 return $override if $override;
1406 1447
1407 my $parentInterface = ParentInterface($dataNode); 1448 my $parentInterface = ParentInterface($dataNode);
(...skipping 21 matching lines...) Expand all
1429 1470
1430 push(@implementedInterfaces, @{IDLTypeInfo($dataNode)->additionalInterfaces} ); 1471 push(@implementedInterfaces, @{IDLTypeInfo($dataNode)->additionalInterfaces} );
1431 push(@implementedInterfaces, @allParents); 1472 push(@implementedInterfaces, @allParents);
1432 1473
1433 if (@implementedInterfaces) { 1474 if (@implementedInterfaces) {
1434 $extendsClause = " extends " . join(", ", @implementedInterfaces); 1475 $extendsClause = " extends " . join(", ", @implementedInterfaces);
1435 } 1476 }
1436 1477
1437 # Build default clause if any. 1478 # Build default clause if any.
1438 my $defaultClause = ""; 1479 my $defaultClause = "";
1439 if (HasCustomConstructor($dataNode)) { 1480 if (CanBeConstructed($dataNode)) {
1440 $defaultClause = " default ${w3cInterfaceName}Implementation"; 1481 $defaultClause = " default ${w3cInterfaceName}Implementation";
1441 push(@customCallbackDeclarations, GenerateCustomCallbackDeclaration("con structorCallback")); 1482 push(@customCallbackDeclarations, GenerateCustomCallbackDeclaration("con structorCallback"));
1442 } 1483 }
1443 1484
1444 push(@dartInterfaceContent, "\ninterface ${w3cInterfaceName}${extendsClause} ${defaultClause} {\n"); 1485 push(@dartInterfaceContent, "\ninterface ${w3cInterfaceName}${extendsClause} ${defaultClause} {\n");
1445 push(@dartInterfaceContent, "\n // Constants.\n"); 1486 push(@dartInterfaceContent, "\n // Constants.\n");
1446 foreach my $constant (@{$dataNode->constants}) { 1487 foreach my $constant (@{$dataNode->constants}) {
1447 my $name = $constant->name; 1488 my $name = $constant->name;
1448 my $value = $constant->value; 1489 my $value = $constant->value;
1449 1490
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 1728
1688 if (defined($DART_IMPL)) { 1729 if (defined($DART_IMPL)) {
1689 # Write content of Dart file. 1730 # Write content of Dart file.
1690 print $DART_IMPL @dartImplContent; 1731 print $DART_IMPL @dartImplContent;
1691 close($DART_IMPL); 1732 close($DART_IMPL);
1692 undef($DART_IMPL); 1733 undef($DART_IMPL);
1693 1734
1694 @dartImplContent = (); 1735 @dartImplContent = ();
1695 } 1736 }
1696 } 1737 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698