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

Side by Side Diff: sdk/lib/html/scripts/generator.py

Issue 11316113: Creating a common library for all DOM types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merging with latest from tree. Created 8 years 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
« no previous file with comments | « sdk/lib/html/html_common/html_common_dartium.dart ('k') | sdk/lib/html/src/_Collections.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 re 10 import re
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 Attributes: 301 Attributes:
302 overloads: A list of IDL operation overloads with the same name. 302 overloads: A list of IDL operation overloads with the same name.
303 name: A string, the simple name of the operation. 303 name: A string, the simple name of the operation.
304 constructor_name: A string, the name of the constructor iff the constructor 304 constructor_name: A string, the name of the constructor iff the constructor
305 is named, e.g. 'fromList' in Int8Array.fromList(list). 305 is named, e.g. 'fromList' in Int8Array.fromList(list).
306 type_name: A string, the name of the return type of the operation. 306 type_name: A string, the name of the return type of the operation.
307 param_infos: A list of ParamInfo. 307 param_infos: A list of ParamInfo.
308 factory_parameters: A list of parameters used for custom designed Factory 308 factory_parameters: A list of parameters used for custom designed Factory
309 calls. 309 calls.
310 """ 310 """
311 311
312 def __init__(self): 312 def __init__(self):
313 self.factory_parameters = None 313 self.factory_parameters = None
314 314
315 def ParametersDeclaration(self, rename_type, force_optional=False): 315 def ParametersDeclaration(self, rename_type, force_optional=False):
316 def FormatParam(param): 316 def FormatParam(param):
317 dart_type = rename_type(param.type_id) if param.type_id else 'dynamic' 317 dart_type = rename_type(param.type_id) if param.type_id else 'dynamic'
318 return '%s%s' % (TypeOrNothing(dart_type, param.type_id), param.name) 318 return '%s%s' % (TypeOrNothing(dart_type, param.type_id), param.name)
319 319
320 required = [] 320 required = []
321 optional = [] 321 optional = []
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' 413 ' return $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n'
414 ' }\n', 414 ' }\n',
415 OPT_PARAM_NAME=self.param_infos[index].name, 415 OPT_PARAM_NAME=self.param_infos[index].name,
416 FACTORY=factory_provider, 416 FACTORY=factory_provider,
417 CTOR_FACTORY_NAME=self.ConstructorFactoryName(rename_type), 417 CTOR_FACTORY_NAME=self.ConstructorFactoryName(rename_type),
418 FACTORY_PARAMS=self.ParametersAsArgumentList(index)) 418 FACTORY_PARAMS=self.ParametersAsArgumentList(index))
419 419
420 for index, param_info in enumerate(self.param_infos): 420 for index, param_info in enumerate(self.param_infos):
421 if param_info.is_optional: 421 if param_info.is_optional:
422 EmitOptionalParameterInvocation(index) 422 EmitOptionalParameterInvocation(index)
423 423
424 def _GenerateFactoryOptParamsWithoutFactoryProvider(self, rename_type, 424 def _GenerateFactoryOptParamsWithoutFactoryProvider(self, rename_type,
425 emitter, factory_name, factory_constructor_name, factory_parameters): 425 emitter, factory_name, factory_constructor_name, factory_parameters):
426 """Helper method for creating a factory constructor with optional 426 """Helper method for creating a factory constructor with optional
427 parameters that does not call a factory provider, it simply creates the 427 parameters that does not call a factory provider, it simply creates the
428 object itself. This is currently used for SVGElements and HTMLElements.""" 428 object itself. This is currently used for SVGElements and HTMLElements."""
429 inits = emitter.Emit( 429 inits = emitter.Emit(
430 '\n' 430 '\n'
431 ' factory $CONSTRUCTOR($PARAMS) {\n'» 431 ' factory $CONSTRUCTOR($PARAMS) {\n'
432 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' 432 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n'
433 '$!INITS' 433 '$!INITS'
434 ' return e;\n' 434 ' return e;\n'
435 ' }\n', 435 ' }\n',
436 CONSTRUCTOR=self._ConstructorFullName(rename_type), 436 CONSTRUCTOR=self._ConstructorFullName(rename_type),
437 FACTORY=factory_name, 437 FACTORY=factory_name,
438 CTOR_FACTORY_NAME=factory_constructor_name, 438 CTOR_FACTORY_NAME=factory_constructor_name,
439 PARAMS=self.ParametersDeclaration(rename_type), 439 PARAMS=self.ParametersDeclaration(rename_type),
440 FACTORY_PARAMS=factory_parameters) 440 FACTORY_PARAMS=factory_parameters)
441 for index, param_info in enumerate(self.param_infos): 441 for index, param_info in enumerate(self.param_infos):
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 # Specific member of interface 493 # Specific member of interface
494 # "TYPE DIRECTION INTERFACE.*" -> conversion 494 # "TYPE DIRECTION INTERFACE.*" -> conversion
495 # All members of interface getting (setting) with type. 495 # All members of interface getting (setting) with type.
496 # "TYPE DIRECTION" -> conversion 496 # "TYPE DIRECTION" -> conversion
497 # All getters (setters) of type. 497 # All getters (setters) of type.
498 # 498 #
499 # where DIRECTION is 'get' for getters and operation return values, 'set' for 499 # where DIRECTION is 'get' for getters and operation return values, 'set' for
500 # setters and operation arguments. INTERFACE and MEMBER are the idl names. 500 # setters and operation arguments. INTERFACE and MEMBER are the idl names.
501 # 501 #
502 502
503 _serialize_SSV = Conversion('_convertDartToNative_SerializedScriptValue', 503 _serialize_SSV = Conversion('convertDartToNative_SerializedScriptValue',
504 'dynamic', 'dynamic') 504 'dynamic', 'dynamic')
505 505
506 dart2js_conversions = { 506 dart2js_conversions = {
507 # Wrap non-local Windows. We need to check EventTarget (the base type) 507 # Wrap non-local Windows. We need to check EventTarget (the base type)
508 # as well. Note, there are no functions that take a non-local Window 508 # as well. Note, there are no functions that take a non-local Window
509 # as a parameter / setter. 509 # as a parameter / setter.
510 'DOMWindow get': 510 'DOMWindow get':
511 Conversion('_convertNativeToDart_Window', 'dynamic', 'Window'), 511 Conversion('_convertNativeToDart_Window', 'dynamic', 'Window'),
512 'EventTarget get': 512 'EventTarget get':
513 Conversion('_convertNativeToDart_EventTarget', 'dynamic', 513 Conversion('_convertNativeToDart_EventTarget', 'dynamic',
514 'EventTarget'), 514 'EventTarget'),
515 'EventTarget set': 515 'EventTarget set':
516 Conversion('_convertDartToNative_EventTarget', 'EventTarget', 516 Conversion('_convertDartToNative_EventTarget', 'EventTarget',
517 'dynamic'), 517 'dynamic'),
518 518
519 'IDBKey get': 519 'IDBKey get':
520 Conversion('_convertNativeToDart_IDBKey', 'dynamic', 'dynamic'), 520 Conversion('_convertNativeToDart_IDBKey', 'dynamic', 'dynamic'),
521 'IDBKey set': 521 'IDBKey set':
522 Conversion('_convertDartToNative_IDBKey', 'dynamic', 'dynamic'), 522 Conversion('_convertDartToNative_IDBKey', 'dynamic', 'dynamic'),
523 523
524 'ImageData get': 524 'ImageData get':
525 Conversion('_convertNativeToDart_ImageData', 'dynamic', 'ImageData'), 525 Conversion('_convertNativeToDart_ImageData', 'dynamic', 'ImageData'),
526 'ImageData set': 526 'ImageData set':
527 Conversion('_convertDartToNative_ImageData', 'ImageData', 'dynamic'), 527 Conversion('_convertDartToNative_ImageData', 'ImageData', 'dynamic'),
528 528
529 'Dictionary get': 529 'Dictionary get':
530 Conversion('_convertNativeToDart_Dictionary', 'dynamic', 'Map'), 530 Conversion('convertNativeToDart_Dictionary', 'dynamic', 'Map'),
531 'Dictionary set': 531 'Dictionary set':
532 Conversion('_convertDartToNative_Dictionary', 'Map', 'dynamic'), 532 Conversion('convertDartToNative_Dictionary', 'Map', 'dynamic'),
533 533
534 'DOMString[] set': 534 'DOMString[] set':
535 Conversion('_convertDartToNative_StringArray', 'List<String>', 'List'), 535 Conversion('convertDartToNative_StringArray', 'List<String>', 'List'),
536 536
537 'any set IDBObjectStore.add': _serialize_SSV, 537 'any set IDBObjectStore.add': _serialize_SSV,
538 'any set IDBObjectStore.put': _serialize_SSV, 538 'any set IDBObjectStore.put': _serialize_SSV,
539 'any set IDBCursor.update': _serialize_SSV, 539 'any set IDBCursor.update': _serialize_SSV,
540 540
541 # postMessage 541 # postMessage
542 'any set DedicatedWorkerContext.postMessage': _serialize_SSV, 542 'any set DedicatedWorkerContext.postMessage': _serialize_SSV,
543 'any set MessagePort.postMessage': _serialize_SSV, 543 'any set MessagePort.postMessage': _serialize_SSV,
544 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV, 544 'SerializedScriptValue set DOMWindow.postMessage': _serialize_SSV,
545 'SerializedScriptValue set Worker.postMessage': _serialize_SSV, 545 'SerializedScriptValue set Worker.postMessage': _serialize_SSV,
546 546
547 # receiving message via MessageEvent 547 # receiving message via MessageEvent
548 'DOMObject get MessageEvent.data': 548 'DOMObject get MessageEvent.data':
549 Conversion('_convertNativeToDart_SerializedScriptValue', 549 Conversion('convertNativeToDart_SerializedScriptValue',
550 'dynamic', 'dynamic'), 550 'dynamic', 'dynamic'),
551 551
552 'DOMObject get PopStateEvent.state': 552 'DOMObject get PopStateEvent.state':
553 Conversion('_convertNativeToDart_SerializedScriptValue', 553 Conversion('convertNativeToDart_SerializedScriptValue',
554 'dynamic', 'dynamic'), 554 'dynamic', 'dynamic'),
555 555
556 # IDBAny is problematic. Some uses are just a union of other IDB types, 556 # IDBAny is problematic. Some uses are just a union of other IDB types,
557 # which need no conversion.. Others include data values which require 557 # which need no conversion.. Others include data values which require
558 # serialized script value processing. 558 # serialized script value processing.
559 'IDBAny get IDBCursorWithValue.value': 559 'IDBAny get IDBCursorWithValue.value':
560 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'), 560 Conversion('_convertNativeToDart_IDBAny', 'dynamic', 'dynamic'),
561 561
562 # This is problematic. The result property of IDBRequest is used for 562 # This is problematic. The result property of IDBRequest is used for
563 # all requests. Read requests like IDBDataStore.getObject need 563 # all requests. Read requests like IDBDataStore.getObject need
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 'IDBRequest.result': "@Creates('Null')", 613 'IDBRequest.result': "@Creates('Null')",
614 614
615 # The source is usually a participant in the operation that generated the 615 # The source is usually a participant in the operation that generated the
616 # IDBRequest. 616 # IDBRequest.
617 'IDBRequest.source': "@Creates('Null')", 617 'IDBRequest.source': "@Creates('Null')",
618 618
619 'IDBFactory.open': "@Creates('IDBDatabase')", 619 'IDBFactory.open': "@Creates('IDBDatabase')",
620 620
621 'IDBObjectStore.put': "@_annotation_Creates_IDBKey", 621 'IDBObjectStore.put': "@_annotation_Creates_IDBKey",
622 'IDBObjectStore.add': "@_annotation_Creates_IDBKey", 622 'IDBObjectStore.add': "@_annotation_Creates_IDBKey",
623 'IDBObjectStore.get': "@_annotation_Creates_SerializedScriptValue", 623 'IDBObjectStore.get': "@annotation_Creates_SerializedScriptValue",
624 'IDBObjectStore.openCursor': "@Creates('IDBCursor')", 624 'IDBObjectStore.openCursor': "@Creates('IDBCursor')",
625 625
626 'IDBIndex.get': "@_annotation_Creates_SerializedScriptValue", 626 'IDBIndex.get': "@annotation_Creates_SerializedScriptValue",
627 'IDBIndex.getKey': 627 'IDBIndex.getKey':
628 "@_annotation_Creates_SerializedScriptValue " 628 "@annotation_Creates_SerializedScriptValue "
629 # The source is the object store behind the index. 629 # The source is the object store behind the index.
630 "@Creates('IDBObjectStore')", 630 "@Creates('IDBObjectStore')",
631 'IDBIndex.openCursor': "@Creates('IDBCursor')", 631 'IDBIndex.openCursor': "@Creates('IDBCursor')",
632 'IDBIndex.openKeyCursor': "@Creates('IDBCursor')", 632 'IDBIndex.openKeyCursor': "@Creates('IDBCursor')",
633 633
634 'IDBCursorWithValue.value': 634 'IDBCursorWithValue.value':
635 '@_annotation_Creates_SerializedScriptValue ' 635 '@annotation_Creates_SerializedScriptValue '
636 '@_annotation_Returns_SerializedScriptValue', 636 '@annotation_Returns_SerializedScriptValue',
637 637
638 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", 638 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey",
639 639
640 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", 640 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')",
641 641
642 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", 642 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')",
643 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", 643 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')",
644 644
645 645
646 'MessageEvent.ports': "@Creates('=List')", 646 'MessageEvent.ports': "@Creates('=List')",
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 'CSSValueList': TypeData(clazz='Interface', 1079 'CSSValueList': TypeData(clazz='Interface',
1080 item_type='CSSValue', suppress_interface=True), 1080 item_type='CSSValue', suppress_interface=True),
1081 'DOMMimeTypeArray': TypeData(clazz='Interface', item_type='DOMMimeType'), 1081 'DOMMimeTypeArray': TypeData(clazz='Interface', item_type='DOMMimeType'),
1082 'DOMPluginArray': TypeData(clazz='Interface', item_type='DOMPlugin'), 1082 'DOMPluginArray': TypeData(clazz='Interface', item_type='DOMPlugin'),
1083 'DOMStringList': TypeData(clazz='Interface', item_type='DOMString', 1083 'DOMStringList': TypeData(clazz='Interface', item_type='DOMString',
1084 suppress_interface=True, custom_to_native=True), 1084 suppress_interface=True, custom_to_native=True),
1085 'EntryArray': TypeData(clazz='Interface', item_type='Entry', 1085 'EntryArray': TypeData(clazz='Interface', item_type='Entry',
1086 suppress_interface=True), 1086 suppress_interface=True),
1087 'EntryArraySync': TypeData(clazz='Interface', item_type='EntrySync', 1087 'EntryArraySync': TypeData(clazz='Interface', item_type='EntrySync',
1088 suppress_interface=True), 1088 suppress_interface=True),
1089 'FileList': TypeData(clazz='Interface', item_type='File', 1089 'FileList': TypeData(clazz='Interface', item_type='File'),
1090 suppress_interface=True),
1091 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad', 1090 'GamepadList': TypeData(clazz='Interface', item_type='Gamepad',
1092 suppress_interface=True), 1091 suppress_interface=True),
1093 'HTMLAllCollection': TypeData(clazz='Interface', item_type='Node'), 1092 'HTMLAllCollection': TypeData(clazz='Interface', item_type='Node'),
1094 'HTMLCollection': TypeData(clazz='Interface', item_type='Node'), 1093 'HTMLCollection': TypeData(clazz='Interface', item_type='Node'),
1095 'MediaStreamList': TypeData(clazz='Interface', 1094 'MediaStreamList': TypeData(clazz='Interface',
1096 item_type='MediaStream', suppress_interface=True), 1095 item_type='MediaStream', suppress_interface=True),
1097 'NamedNodeMap': TypeData(clazz='Interface', item_type='Node'), 1096 'NamedNodeMap': TypeData(clazz='Interface', item_type='Node'),
1098 'NodeList': TypeData(clazz='Interface', item_type='Node', 1097 'NodeList': TypeData(clazz='Interface', item_type='Node',
1099 suppress_interface=True), 1098 suppress_interface=True),
1100 'SVGAnimatedLengthList': TypeData(clazz='Interface', 1099 'SVGAnimatedLengthList': TypeData(clazz='Interface',
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 self) 1200 self)
1202 1201
1203 if type_data.clazz == 'SVGTearOff': 1202 if type_data.clazz == 'SVGTearOff':
1204 dart_interface_name = self._renamer.RenameInterface( 1203 dart_interface_name = self._renamer.RenameInterface(
1205 self._database.GetInterface(type_name)) 1204 self._database.GetInterface(type_name))
1206 return SVGTearOffIDLTypeInfo( 1205 return SVGTearOffIDLTypeInfo(
1207 type_name, type_data, dart_interface_name, self) 1206 type_name, type_data, dart_interface_name, self)
1208 1207
1209 class_name = '%sIDLTypeInfo' % type_data.clazz 1208 class_name = '%sIDLTypeInfo' % type_data.clazz
1210 return globals()[class_name](type_name, type_data) 1209 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « sdk/lib/html/html_common/html_common_dartium.dart ('k') | sdk/lib/html/src/_Collections.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698