| 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 def dart_type(self): | 477 def dart_type(self): |
| 478 return self._data.dart_type or self._idl_type | 478 return self._data.dart_type or self._idl_type |
| 479 | 479 |
| 480 def native_type(self): | 480 def native_type(self): |
| 481 return self._data.native_type or self._idl_type | 481 return self._data.native_type or self._idl_type |
| 482 | 482 |
| 483 def requires_v8_scope(self): | 483 def requires_v8_scope(self): |
| 484 return self._data.requires_v8_scope | 484 return self._data.requires_v8_scope |
| 485 | 485 |
| 486 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa
ce_name): | 486 def emit_to_native(self, emitter, idl_node, accept_null, name, handle): |
| 487 if 'Callback' in idl_node.ext_attrs: | 487 if 'Callback' in idl_node.ext_attrs: |
| 488 function_name = 'create' | 488 function_name = 'create' |
| 489 if accept_null: | 489 if accept_null: |
| 490 function_name += 'WithNullCheck' | 490 function_name += 'WithNullCheck' |
| 491 emitter.Emit( | 491 emitter.Emit( |
| 492 '\n' | 492 '\n' |
| 493 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::$FUNCTION_NAME($HANDLE, ex
ception);\n' | 493 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::$FUNCTION_NAME($HANDLE, ex
ception);\n' |
| 494 ' if (exception)\n' | 494 ' if (exception)\n' |
| 495 ' goto fail;\n', | 495 ' goto fail;\n', |
| 496 TYPE=self.native_type(), | 496 TYPE=self.native_type(), |
| 497 NAME=name, | 497 NAME=name, |
| 498 FUNCTION_NAME=function_name, | 498 FUNCTION_NAME=function_name, |
| 499 IDL_TYPE=self.idl_type(), | 499 IDL_TYPE=self.idl_type(), |
| 500 HANDLE=handle) | 500 HANDLE=handle) |
| 501 return name | 501 return |
| 502 | 502 |
| 503 argument = name | |
| 504 if self.custom_to_native(): | 503 if self.custom_to_native(): |
| 505 type = 'RefPtr<%s>' % self.native_type() | 504 type = 'RefPtr<%s>' % self.native_type() |
| 506 argument = '%s.get()' % name | |
| 507 else: | 505 else: |
| 508 type = '%s*' % self.native_type() | 506 type = '%s*' % self.native_type() |
| 509 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith
('List'): | |
| 510 argument = '%s->propertyReference()' % name | |
| 511 emitter.Emit( | 507 emitter.Emit( |
| 512 '\n' | 508 '\n' |
| 513 ' $TYPE $NAME = Dart$IDL_TYPE::toNative($HANDLE, exception);\n' | 509 ' $TYPE $NAME = Dart$IDL_TYPE::toNative($HANDLE, exception);\n' |
| 514 ' if (exception)\n' | 510 ' if (exception)\n' |
| 515 ' goto fail;\n', | 511 ' goto fail;\n', |
| 516 TYPE=type, | 512 TYPE=type, |
| 517 NAME=name, | 513 NAME=name, |
| 518 IDL_TYPE=self.idl_type(), | 514 IDL_TYPE=self.idl_type(), |
| 519 HANDLE=handle) | 515 HANDLE=handle) |
| 520 return argument | 516 |
| 517 def argument_expression(self, name, interface_name): |
| 518 return '%s.get()' % name if self.custom_to_native() else name |
| 521 | 519 |
| 522 def custom_to_native(self): | 520 def custom_to_native(self): |
| 523 return self._data.custom_to_native | 521 return self._data.custom_to_native |
| 524 | 522 |
| 525 def parameter_type(self): | 523 def parameter_type(self): |
| 526 return '%s*' % self.native_type() | 524 return '%s*' % self.native_type() |
| 527 | 525 |
| 528 def webcore_includes(self): | 526 def webcore_includes(self): |
| 529 WTF_INCLUDES = [ | 527 WTF_INCLUDES = [ |
| 530 'ArrayBuffer', | 528 'ArrayBuffer', |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) | 586 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 589 | 587 |
| 590 def conversion_includes(self): | 588 def conversion_includes(self): |
| 591 return self._item_info.conversion_includes() | 589 return self._item_info.conversion_includes() |
| 592 | 590 |
| 593 | 591 |
| 594 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 592 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 595 def __init__(self, data, item_info): | 593 def __init__(self, data, item_info): |
| 596 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 594 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 597 | 595 |
| 598 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa
ce_name): | 596 def emit_to_native(self, emitter, idl_node, accept_null, name, handle): |
| 599 assert not accept_null | 597 assert not accept_null |
| 600 emitter.Emit( | 598 emitter.Emit( |
| 601 '\n' | 599 '\n' |
| 602 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' | 600 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' |
| 603 ' if (exception)\n' | 601 ' if (exception)\n' |
| 604 ' goto fail;\n', | 602 ' goto fail;\n', |
| 605 NAME=name, | 603 NAME=name, |
| 606 HANDLE=handle) | 604 HANDLE=handle) |
| 607 return name | |
| 608 | 605 |
| 609 def to_native_includes(self): | 606 def to_native_includes(self): |
| 610 return ['"DartDOMStringList.h"'] | 607 return ['"DartDOMStringList.h"'] |
| 611 | 608 |
| 612 | 609 |
| 613 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 610 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 614 def __init__(self, idl_type, data): | 611 def __init__(self, idl_type, data): |
| 615 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) | 612 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) |
| 616 | 613 |
| 617 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa
ce_name): | 614 def emit_to_native(self, emitter, idl_node, accept_null, name, handle): |
| 618 function_name = 'dartTo%s' % self._capitalized_native_type() | 615 function_name = 'dartTo%s' % self._capitalized_native_type() |
| 619 if accept_null: | 616 if accept_null: |
| 620 function_name += 'WithNullCheck' | 617 function_name += 'WithNullCheck' |
| 621 type = self.native_type() | 618 type = self.native_type() |
| 622 if type == 'SerializedScriptValue': | 619 if type == 'SerializedScriptValue': |
| 623 type = 'RefPtr<%s>' % type | 620 type = 'RefPtr<%s>' % type |
| 624 if type == 'String': | 621 if type == 'String': |
| 625 type = 'DartStringAdapter' | 622 type = 'DartStringAdapter' |
| 626 emitter.Emit( | 623 emitter.Emit( |
| 627 '\n' | 624 '\n' |
| 628 ' $TYPE $NAME = DartUtilities::$FUNCTION_NAME($HANDLE, exception)
;\n' | 625 ' $TYPE $NAME = DartUtilities::$FUNCTION_NAME($HANDLE, exception)
;\n' |
| 629 ' if (exception)\n' | 626 ' if (exception)\n' |
| 630 ' goto fail;\n', | 627 ' goto fail;\n', |
| 631 TYPE=type, | 628 TYPE=type, |
| 632 NAME=name, | 629 NAME=name, |
| 633 FUNCTION_NAME=function_name, | 630 FUNCTION_NAME=function_name, |
| 634 HANDLE=handle) | 631 HANDLE=handle) |
| 635 return name | |
| 636 | 632 |
| 637 def parameter_type(self): | 633 def parameter_type(self): |
| 638 if self.native_type() == 'String': | 634 if self.native_type() == 'String': |
| 639 return 'const String&' | 635 return 'const String&' |
| 640 return self.native_type() | 636 return self.native_type() |
| 641 | 637 |
| 642 def conversion_includes(self): | 638 def conversion_includes(self): |
| 643 return [] | 639 return [] |
| 644 | 640 |
| 645 def to_native_includes(sefl): | 641 def to_native_includes(sefl): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 conversion_cast = '%s::create(receiver, %s)' | 686 conversion_cast = '%s::create(receiver, %s)' |
| 691 elif interface_name.endswith('List'): | 687 elif interface_name.endswith('List'): |
| 692 conversion_cast = 'static_cast<%s*>(%s.get())' | 688 conversion_cast = 'static_cast<%s*>(%s.get())' |
| 693 elif self.idl_type() in svg_primitive_types: | 689 elif self.idl_type() in svg_primitive_types: |
| 694 conversion_cast = '%s::create(%s)' | 690 conversion_cast = '%s::create(%s)' |
| 695 else: | 691 else: |
| 696 conversion_cast = 'static_cast<%s*>(%s)' | 692 conversion_cast = 'static_cast<%s*>(%s)' |
| 697 conversion_cast = conversion_cast % (self.native_type(), value) | 693 conversion_cast = conversion_cast % (self.native_type(), value) |
| 698 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) | 694 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) |
| 699 | 695 |
| 696 def argument_expression(self, name, interface_name): |
| 697 return name if interface_name.endswith('List') else '%s->propertyReference()
' % name |
| 698 |
| 700 | 699 |
| 701 class TypeData(object): | 700 class TypeData(object): |
| 702 def __init__(self, clazz, dart_type=None, native_type=None, | 701 def __init__(self, clazz, dart_type=None, native_type=None, |
| 703 custom_to_dart=None, custom_to_native=None, | 702 custom_to_dart=None, custom_to_native=None, |
| 704 conversion_includes=None, | 703 conversion_includes=None, |
| 705 webcore_getter_name='getAttribute', | 704 webcore_getter_name='getAttribute', |
| 706 webcore_setter_name='setAttribute', | 705 webcore_setter_name='setAttribute', |
| 707 requires_v8_scope=False): | 706 requires_v8_scope=False): |
| 708 self.clazz = clazz | 707 self.clazz = clazz |
| 709 self.dart_type = dart_type | 708 self.dart_type = dart_type |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 if match: | 833 if match: |
| 835 if type_name == 'DOMString[]': | 834 if type_name == 'DOMString[]': |
| 836 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 835 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 837 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 836 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 838 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 837 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 839 if not type_name in _idl_type_registry: | 838 if not type_name in _idl_type_registry: |
| 840 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 839 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 841 type_data = _idl_type_registry.get(type_name) | 840 type_data = _idl_type_registry.get(type_name) |
| 842 class_name = '%sIDLTypeInfo' % type_data.clazz | 841 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 843 return globals()[class_name](type_name, type_data) | 842 return globals()[class_name](type_name, type_data) |
| OLD | NEW |