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

Side by Side Diff: tools/dom/scripts/generator.py

Issue 14367012: Move to new dart:typeddata types for dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert generated files for html lib Created 7 years, 8 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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import json 10 import json
11 import monitored 11 import monitored
12 import os 12 import os
13 import re 13 import re
14 from htmlrenamer import html_interface_renames, renamed_html_members 14 from htmlrenamer import html_interface_renames, renamed_html_members, \
15 typed_array_renames
15 16
16 # Set up json file for retrieving comments. 17 # Set up json file for retrieving comments.
17 _current_dir = os.path.dirname(__file__) 18 _current_dir = os.path.dirname(__file__)
18 _json_path = os.path.join(_current_dir, '..', 'docs', 'docs.json') 19 _json_path = os.path.join(_current_dir, '..', 'docs', 'docs.json')
19 _dom_json = json.load(open(_json_path)) 20 _dom_json = json.load(open(_json_path))
20 21
21 _pure_interfaces = monitored.Set('generator._pure_interfaces', [ 22 _pure_interfaces = monitored.Set('generator._pure_interfaces', [
22 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. 23 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>.
23 'DOMStringMap', 24 'DOMStringMap',
24 'ElementTimeControl', 25 'ElementTimeControl',
25 'ElementTraversal', 26 'ElementTraversal',
26 'EventListener', 27 'EventListener',
27 'MediaQueryListListener', 28 'MediaQueryListListener',
28 'MutationCallback', 29 'MutationCallback',
29 'SVGExternalResourcesRequired', 30 'SVGExternalResourcesRequired',
30 'SVGFilterPrimitiveStandardAttributes', 31 'SVGFilterPrimitiveStandardAttributes',
31 'SVGFitToViewBox', 32 'SVGFitToViewBox',
32 'SVGLangSpace', 33 'SVGLangSpace',
33 'SVGLocatable', 34 'SVGLocatable',
34 'SVGTests', 35 'SVGTests',
35 'SVGTransformable', 36 'SVGTransformable',
36 'SVGURIReference', 37 'SVGURIReference',
37 'SVGZoomAndPan', 38 'SVGZoomAndPan',
38 'TimeoutHandler']) 39 'TimeoutHandler',
40 ])
39 41
40 def IsPureInterface(interface_name): 42 def IsPureInterface(interface_name):
41 return interface_name in _pure_interfaces 43 return interface_name in _pure_interfaces
42 44
45 _custom_types = monitored.Set('generator._custom_types',
46 typed_array_renames.keys())
47
48 def IsCustomType(interface_name):
49 return interface_name in _custom_types
43 50
44 _methods_with_named_formals = monitored.Set( 51 _methods_with_named_formals = monitored.Set(
45 'generator._methods_with_named_formals', [ 52 'generator._methods_with_named_formals', [
46 'DataView.getFloat32',
47 'DataView.getFloat64',
48 'DataView.getInt16',
49 'DataView.getInt32',
50 'DataView.getInt8',
51 'DataView.getUint16',
52 'DataView.getUint32',
53 'DataView.getUint8',
54 'DataView.setFloat32',
55 'DataView.setFloat64',
56 'DataView.setInt16',
57 'DataView.setInt32',
58 'DataView.setInt8',
59 'DataView.setUint16',
60 'DataView.setUint32',
61 'DataView.setUint8',
62 'DirectoryEntry.getDirectory', 53 'DirectoryEntry.getDirectory',
63 'DirectoryEntry.getFile', 54 'DirectoryEntry.getFile',
64 'Entry.copyTo', 55 'Entry.copyTo',
65 'Entry.moveTo', 56 'Entry.moveTo',
66 'HTMLInputElement.setRangeText', 57 'HTMLInputElement.setRangeText',
67 'XMLHttpRequest.open', 58 'XMLHttpRequest.open',
68 ]) 59 ])
69 60
70 # 61 #
71 # Renames for attributes that have names that are not legal Dart names. 62 # Renames for attributes that have names that are not legal Dart names.
72 # 63 #
73 _dart_attribute_renames = monitored.Dict('generator._dart_attribute_renames', { 64 _dart_attribute_renames = monitored.Dict('generator._dart_attribute_renames', {
74 'default': 'defaultValue', 65 'default': 'defaultValue',
75 }) 66 })
76 67
77 # 68 #
78 # Interface version of the DOM needs to delegate typed array constructors to a 69 # Interface version of the DOM needs to delegate typed array constructors to a
79 # factory provider. 70 # factory provider.
80 # 71 #
81 interface_factories = monitored.Dict('generator.interface_factories', { 72 interface_factories = monitored.Dict('generator.interface_factories', {
82 'Float32Array': '_TypedArrayFactoryProvider',
83 'Float64Array': '_TypedArrayFactoryProvider',
84 'Int8Array': '_TypedArrayFactoryProvider',
85 'Int16Array': '_TypedArrayFactoryProvider',
86 'Int32Array': '_TypedArrayFactoryProvider',
87 'Uint8Array': '_TypedArrayFactoryProvider',
88 'Uint8ClampedArray': '_TypedArrayFactoryProvider',
89 'Uint16Array': '_TypedArrayFactoryProvider',
90 'Uint32Array': '_TypedArrayFactoryProvider',
91 }) 73 })
92 74
93 # 75 #
94 # Custom native specs for the dart2js dom. 76 # Custom native specs for the dart2js dom.
95 # 77 #
96 _dart2js_dom_custom_native_specs = monitored.Dict( 78 _dart2js_dom_custom_native_specs = monitored.Dict(
97 'generator._dart2js_dom_custom_native_specs', { 79 'generator._dart2js_dom_custom_native_specs', {
98 # Decorate the singleton Console object, if present (workers do not have a 80 # Decorate the singleton Console object, if present (workers do not have a
99 # console). 81 # console).
100 'Console': "=(typeof console == 'undefined' ? {} : console)", 82 'Console': "=(typeof console == 'undefined' ? {} : console)",
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 def _ConstructorFullName(self, rename_type): 372 def _ConstructorFullName(self, rename_type):
391 if self.constructor_name: 373 if self.constructor_name:
392 return rename_type(self.type_name) + '.' + self.constructor_name 374 return rename_type(self.type_name) + '.' + self.constructor_name
393 else: 375 else:
394 # TODO(antonm): temporary ugly hack. 376 # TODO(antonm): temporary ugly hack.
395 # While in transition phase we allow both DOM's ArrayBuffer 377 # While in transition phase we allow both DOM's ArrayBuffer
396 # and dart:typeddata's ByteBuffer for IDLs' ArrayBuffers, 378 # and dart:typeddata's ByteBuffer for IDLs' ArrayBuffers,
397 # hence ArrayBuffer is mapped to dynamic in arguments and return 379 # hence ArrayBuffer is mapped to dynamic in arguments and return
398 # values. To compensate for that when generating ArrayBuffer itself, 380 # values. To compensate for that when generating ArrayBuffer itself,
399 # we need to lie a bit: 381 # we need to lie a bit:
400 if self.type_name == 'ArrayBuffer': return 'ArrayBuffer' 382 if self.type_name == 'ArrayBuffer': return 'ByteBuffer'
401 return rename_type(self.type_name) 383 return rename_type(self.type_name)
402 384
403 def ConstantOutputOrder(a, b): 385 def ConstantOutputOrder(a, b):
404 """Canonical output ordering for constants.""" 386 """Canonical output ordering for constants."""
405 return cmp(a.id, b.id) 387 return cmp(a.id, b.id)
406 388
407 389
408 def _FormatNameList(names): 390 def _FormatNameList(names):
409 """Returns JavaScript array literal expression with one name per line.""" 391 """Returns JavaScript array literal expression with one name per line."""
410 #names = sorted(names) 392 #names = sorted(names)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 # used to assemble the annotations: 527 # used to assemble the annotations:
546 # 528 #
547 # INTERFACE.MEMBER: annotations for member. 529 # INTERFACE.MEMBER: annotations for member.
548 # +TYPE: add annotations only if there are member annotations. 530 # +TYPE: add annotations only if there are member annotations.
549 # -TYPE: add annotations only if there are no member annotations. 531 # -TYPE: add annotations only if there are no member annotations.
550 # TYPE: add regardless of member annotations. 532 # TYPE: add regardless of member annotations.
551 533
552 dart2js_annotations = monitored.Dict('generator.dart2js_annotations', { 534 dart2js_annotations = monitored.Dict('generator.dart2js_annotations', {
553 535
554 'ArrayBuffer': [ 536 'ArrayBuffer': [
555 "@Creates('ArrayBuffer')", 537 "@Creates('ByteBuffer')",
556 "@Returns('ArrayBuffer|Null')", 538 "@Returns('ByteBuffer|Null')",
557 ], 539 ],
558 540
559 'ArrayBufferView': [ 541 'ArrayBufferView': [
560 "@Creates('ArrayBufferView')", 542 "@Creates('TypedData')",
561 "@Returns('ArrayBufferView|Null')", 543 "@Returns('TypedData|Null')",
562 ], 544 ],
563 545
564 'CanvasRenderingContext2D.createImageData': [ 546 'CanvasRenderingContext2D.createImageData': [
565 "@Creates('ImageData|=Object')", 547 "@Creates('ImageData|=Object')",
566 ], 548 ],
567 549
568 'CanvasRenderingContext2D.getImageData': [ 550 'CanvasRenderingContext2D.getImageData': [
569 "@Creates('ImageData|=Object')", 551 "@Creates('ImageData|=Object')",
570 ], 552 ],
571 553
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 "@Creates('Node')", 593 "@Creates('Node')",
612 "@Returns('EventTarget|=Object')", 594 "@Returns('EventTarget|=Object')",
613 ], 595 ],
614 596
615 # Touch targets are Elements in a Document, or the Document. 597 # Touch targets are Elements in a Document, or the Document.
616 'Touch.target': [ 598 'Touch.target': [
617 "@Creates('Element|Document')", 599 "@Creates('Element|Document')",
618 "@Returns('Element|Document')", 600 "@Returns('Element|Document')",
619 ], 601 ],
620 602
621 'FileReader.result': ["@Creates('String|ArrayBuffer|Null')"], 603 'FileReader.result': ["@Creates('String|ByteBuffer|Null')"],
622 604
623 # Rather than have the result of an IDBRequest as a union over all possible 605 # Rather than have the result of an IDBRequest as a union over all possible
624 # results, we mark the result as instantiating any classes, and mark 606 # results, we mark the result as instantiating any classes, and mark
625 # each operation with the classes that it could cause to be asynchronously 607 # each operation with the classes that it could cause to be asynchronously
626 # instantiated. 608 # instantiated.
627 'IDBRequest.result': ["@Creates('Null')"], 609 'IDBRequest.result': ["@Creates('Null')"],
628 610
629 # The source is usually a participant in the operation that generated the 611 # The source is usually a participant in the operation that generated the
630 # IDBRequest. 612 # IDBRequest.
631 'IDBRequest.source': ["@Creates('Null')"], 613 'IDBRequest.source': ["@Creates('Null')"],
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 'SerializedScriptValue': [ 662 'SerializedScriptValue': [
681 "@annotation_Creates_SerializedScriptValue", 663 "@annotation_Creates_SerializedScriptValue",
682 "@annotation_Returns_SerializedScriptValue", 664 "@annotation_Returns_SerializedScriptValue",
683 ], 665 ],
684 666
685 'SQLResultSetRowList.item': ["@Creates('=Object')"], 667 'SQLResultSetRowList.item': ["@Creates('=Object')"],
686 668
687 'WebGLRenderingContext.getParameter': [ 669 'WebGLRenderingContext.getParameter': [
688 # Taken from http://www.khronos.org/registry/webgl/specs/latest/ 670 # Taken from http://www.khronos.org/registry/webgl/specs/latest/
689 # Section 5.14.3 Setting and getting state 671 # Section 5.14.3 Setting and getting state
690 "@Creates('Null|num|String|bool|=List|Float32Array|Int32Array|Uint32Array" 672 "@Creates('Null|num|String|bool|=List|Float32List|Int32List|Uint32List"
691 "|Framebuffer|Renderbuffer|Texture')", 673 "|Framebuffer|Renderbuffer|Texture')",
692 "@Returns('Null|num|String|bool|=List|Float32Array|Int32Array|Uint32Array" 674 "@Returns('Null|num|String|bool|=List|Float32List|Int32List|Uint32List"
693 "|Framebuffer|Renderbuffer|Texture')", 675 "|Framebuffer|Renderbuffer|Texture')",
694 ], 676 ],
695 677
696 'XMLHttpRequest.response': [ 678 'XMLHttpRequest.response': [
697 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", 679 "@Creates('ByteBuffer|Blob|Document|=Object|=List|String|num')",
698 ], 680 ],
699 }, dart2jsOnly=True) 681 }, dart2jsOnly=True)
700 682
701 _indexed_db_annotations = [ 683 _indexed_db_annotations = [
702 "@SupportedBrowser(SupportedBrowser.CHROME)", 684 "@SupportedBrowser(SupportedBrowser.CHROME)",
703 "@SupportedBrowser(SupportedBrowser.FIREFOX, '15')", 685 "@SupportedBrowser(SupportedBrowser.FIREFOX, '15')",
704 "@SupportedBrowser(SupportedBrowser.IE, '10')", 686 "@SupportedBrowser(SupportedBrowser.IE, '10')",
705 "@Experimental", 687 "@Experimental",
706 ] 688 ]
707 689
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 1446
1465 'Float32Array': TypedArrayTypeData('double'), 1447 'Float32Array': TypedArrayTypeData('double'),
1466 'Float64Array': TypedArrayTypeData('double'), 1448 'Float64Array': TypedArrayTypeData('double'),
1467 'Int8Array': TypedArrayTypeData('int'), 1449 'Int8Array': TypedArrayTypeData('int'),
1468 'Int16Array': TypedArrayTypeData('int'), 1450 'Int16Array': TypedArrayTypeData('int'),
1469 'Int32Array': TypedArrayTypeData('int'), 1451 'Int32Array': TypedArrayTypeData('int'),
1470 'Uint8Array': TypedArrayTypeData('int'), 1452 'Uint8Array': TypedArrayTypeData('int'),
1471 'Uint8ClampedArray': TypedArrayTypeData('int'), 1453 'Uint8ClampedArray': TypedArrayTypeData('int'),
1472 'Uint16Array': TypedArrayTypeData('int'), 1454 'Uint16Array': TypedArrayTypeData('int'),
1473 'Uint32Array': TypedArrayTypeData('int'), 1455 'Uint32Array': TypedArrayTypeData('int'),
1474 # TODO(antonm): temporary ugly hack. 1456 'ArrayBufferView': TypeData(clazz='Interface',
1475 # While in transition phase we allow both DOM's ArrayBuffer
1476 # and dart:typeddata's ByteBuffer for IDLs' ArrayBuffers,
1477 # hence ArrayBuffer is mapped to dynamic in arguments and return
1478 # values.
1479 'ArrayBufferView': TypeData(clazz='Interface', dart_type='dynamic',
1480 custom_to_native=True, custom_to_dart=True), 1457 custom_to_native=True, custom_to_dart=True),
1481 'ArrayBuffer': TypeData(clazz='Interface', dart_type='dynamic', 1458 'ArrayBuffer': TypeData(clazz='Interface',
1482 custom_to_native=True, custom_to_dart=True), 1459 custom_to_native=True, custom_to_dart=True),
1483 1460
1484 'SVGAngle': TypeData(clazz='SVGTearOff'), 1461 'SVGAngle': TypeData(clazz='SVGTearOff'),
1485 'SVGLength': TypeData(clazz='SVGTearOff'), 1462 'SVGLength': TypeData(clazz='SVGTearOff'),
1486 'SVGLengthList': TypeData(clazz='SVGTearOff', item_type='SVGLength'), 1463 'SVGLengthList': TypeData(clazz='SVGTearOff', item_type='SVGLength'),
1487 'SVGMatrix': TypeData(clazz='SVGTearOff'), 1464 'SVGMatrix': TypeData(clazz='SVGTearOff'),
1488 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'), 1465 'SVGNumber': TypeData(clazz='SVGTearOff', native_type='SVGPropertyTearOff<fl oat>'),
1489 'SVGNumberList': TypeData(clazz='SVGTearOff', item_type='SVGNumber'), 1466 'SVGNumberList': TypeData(clazz='SVGTearOff', item_type='SVGNumber'),
1490 'SVGPathSegList': TypeData(clazz='SVGTearOff', item_type='SVGPathSeg', 1467 'SVGPathSegList': TypeData(clazz='SVGTearOff', item_type='SVGPathSeg',
1491 native_type='SVGPathSegListPropertyTearOff'), 1468 native_type='SVGPathSegListPropertyTearOff'),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 self) 1536 self)
1560 1537
1561 if type_data.clazz == 'SVGTearOff': 1538 if type_data.clazz == 'SVGTearOff':
1562 dart_interface_name = self._renamer.RenameInterface( 1539 dart_interface_name = self._renamer.RenameInterface(
1563 self._database.GetInterface(type_name)) 1540 self._database.GetInterface(type_name))
1564 return SVGTearOffIDLTypeInfo( 1541 return SVGTearOffIDLTypeInfo(
1565 type_name, type_data, dart_interface_name, self) 1542 type_name, type_data, dart_interface_name, self)
1566 1543
1567 class_name = '%sIDLTypeInfo' % type_data.clazz 1544 class_name = '%sIDLTypeInfo' % type_data.clazz
1568 return globals()[class_name](type_name, type_data) 1545 return globals()[class_name](type_name, type_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698