Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 | 459 |
| 460 def dart_type(self): | 460 def dart_type(self): |
| 461 return self._data.dart_type or self._idl_type | 461 return self._data.dart_type or self._idl_type |
| 462 | 462 |
| 463 def native_type(self): | 463 def native_type(self): |
| 464 return self._data.native_type or self._idl_type | 464 return self._data.native_type or self._idl_type |
| 465 | 465 |
| 466 def requires_v8_scope(self): | 466 def requires_v8_scope(self): |
| 467 return self._data.requires_v8_scope | 467 return self._data.requires_v8_scope |
| 468 | 468 |
| 469 def to_native_info(self, idl_node, accept_null, name, interface_name): | 469 def to_native_info(self, idl_node, interface_name): |
| 470 cls = 'Dart%s' % self.idl_type() | 470 cls = 'Dart%s' % self.idl_type() |
| 471 | 471 |
| 472 if 'Callback' in idl_node.ext_attrs: | 472 if 'Callback' in idl_node.ext_attrs: |
| 473 function_name = 'create' | 473 return '%s', 'RefPtr<%s>' % self.native_type(), cls, 'create' |
| 474 if accept_null: | |
| 475 function_name += 'WithNullCheck' | |
| 476 return name, 'RefPtr<%s>' % self.native_type(), cls, function_name | |
| 477 | 474 |
| 478 if self.custom_to_native(): | 475 if self.custom_to_native(): |
| 479 type = 'RefPtr<%s>' % self.native_type() | 476 type = 'RefPtr<%s>' % self.native_type() |
| 480 argument = '%s.get()' % name | 477 argument_template = '%s.get()' |
|
podivilov
2012/08/23 08:18:04
argument_expression_template?
Anton Muhin
2012/08/23 15:04:12
Done.
| |
| 481 else: | 478 else: |
| 482 type = '%s*' % self.native_type() | 479 type = '%s*' % self.native_type() |
| 483 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'): | 480 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'): |
| 484 argument = '%s->propertyReference()' % name | 481 argument_template = '%s->propertyReference()' |
| 485 else: | 482 else: |
| 486 argument = name | 483 argument_template = '%s' |
| 487 return argument, type, cls, 'toNative' | 484 return argument_template, type, cls, 'toNative' |
| 488 | 485 |
| 489 def custom_to_native(self): | 486 def custom_to_native(self): |
| 490 return self._data.custom_to_native | 487 return self._data.custom_to_native |
| 491 | 488 |
| 492 def parameter_type(self): | 489 def parameter_type(self): |
| 493 return '%s*' % self.native_type() | 490 return '%s*' % self.native_type() |
| 494 | 491 |
| 495 def webcore_includes(self): | 492 def webcore_includes(self): |
| 496 WTF_INCLUDES = [ | 493 WTF_INCLUDES = [ |
| 497 'ArrayBuffer', | 494 'ArrayBuffer', |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value) | 549 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value) |
| 553 | 550 |
| 554 def conversion_includes(self): | 551 def conversion_includes(self): |
| 555 return self._item_info.conversion_includes() | 552 return self._item_info.conversion_includes() |
| 556 | 553 |
| 557 | 554 |
| 558 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 555 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 559 def __init__(self, data, item_info): | 556 def __init__(self, data, item_info): |
| 560 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 557 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 561 | 558 |
| 562 def to_native_info(self, idl_node, accept_null, name, interface_name): | 559 def to_native_info(self, idl_node, interface_name): |
| 563 assert not accept_null | 560 return '%s', 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' |
| 564 return name, 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' | |
| 565 | 561 |
| 566 | 562 |
| 567 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 563 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 568 def __init__(self, idl_type, data): | 564 def __init__(self, idl_type, data): |
| 569 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) | 565 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) |
| 570 | 566 |
| 571 def to_native_info(self, idl_node, accept_null, name, interface_name): | 567 def to_native_info(self, idl_node, interface_name): |
| 572 function_name = 'dartTo%s' % self._capitalized_native_type() | |
| 573 if accept_null: | |
| 574 function_name += 'WithNullCheck' | |
| 575 type = self.native_type() | 568 type = self.native_type() |
| 576 if type == 'SerializedScriptValue': | 569 if type == 'SerializedScriptValue': |
| 577 type = 'RefPtr<%s>' % type | 570 type = 'RefPtr<%s>' % type |
| 578 if type == 'String': | 571 if type == 'String': |
| 579 type = 'DartStringAdapter' | 572 type = 'DartStringAdapter' |
| 580 return name, type, 'DartUtilities', function_name | 573 return '%s', type, 'DartUtilities', 'dartTo%s' % self._capitalized_native_ty pe() |
| 581 | 574 |
| 582 def parameter_type(self): | 575 def parameter_type(self): |
| 583 if self.native_type() == 'String': | 576 if self.native_type() == 'String': |
| 584 return 'const String&' | 577 return 'const String&' |
| 585 return self.native_type() | 578 return self.native_type() |
| 586 | 579 |
| 587 def conversion_includes(self): | 580 def conversion_includes(self): |
| 588 return [] | 581 return [] |
| 589 | 582 |
| 590 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 583 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 780 if match: | 773 if match: |
| 781 if type_name == 'DOMString[]': | 774 if type_name == 'DOMString[]': |
| 782 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) | 775 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) |
| 783 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 776 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 784 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 777 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 785 if not type_name in _idl_type_registry: | 778 if not type_name in _idl_type_registry: |
| 786 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 779 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 787 type_data = _idl_type_registry.get(type_name) | 780 type_data = _idl_type_registry.get(type_name) |
| 788 class_name = '%sIDLTypeInfo' % type_data.clazz | 781 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 789 return globals()[class_name](type_name, type_data) | 782 return globals()[class_name](type_name, type_data) |
| OLD | NEW |