| 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 emit_to_native(self, emitter, idl_node, accept_null, name, handle): | 469 def to_native_info(self, idl_node, accept_null, name, interface_name): |
| 470 cls = 'Dart%s' % self.idl_type() |
| 471 |
| 470 if 'Callback' in idl_node.ext_attrs: | 472 if 'Callback' in idl_node.ext_attrs: |
| 471 function_name = 'create' | 473 function_name = 'create' |
| 472 if accept_null: | 474 if accept_null: |
| 473 function_name += 'WithNullCheck' | 475 function_name += 'WithNullCheck' |
| 474 emitter.Emit( | 476 return name, 'RefPtr<%s>' % self.native_type(), cls, function_name |
| 475 '\n' | |
| 476 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::$FUNCTION_NAME($HANDLE, ex
ception);\n' | |
| 477 ' if (exception)\n' | |
| 478 ' goto fail;\n', | |
| 479 TYPE=self.native_type(), | |
| 480 NAME=name, | |
| 481 FUNCTION_NAME=function_name, | |
| 482 IDL_TYPE=self.idl_type(), | |
| 483 HANDLE=handle) | |
| 484 return | |
| 485 | 477 |
| 486 if self.custom_to_native(): | 478 if self.custom_to_native(): |
| 487 type = 'RefPtr<%s>' % self.native_type() | 479 type = 'RefPtr<%s>' % self.native_type() |
| 480 argument = '%s.get()' % name |
| 488 else: | 481 else: |
| 489 type = '%s*' % self.native_type() | 482 type = '%s*' % self.native_type() |
| 490 emitter.Emit( | 483 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith
('List'): |
| 491 '\n' | 484 argument = '%s->propertyReference()' % name |
| 492 ' $TYPE $NAME = Dart$IDL_TYPE::toNative($HANDLE, exception);\n' | 485 else: |
| 493 ' if (exception)\n' | 486 argument = name |
| 494 ' goto fail;\n', | 487 return argument, type, cls, 'toNative' |
| 495 TYPE=type, | |
| 496 NAME=name, | |
| 497 IDL_TYPE=self.idl_type(), | |
| 498 HANDLE=handle) | |
| 499 | |
| 500 def argument_expression(self, name, interface_name): | |
| 501 return '%s.get()' % name if self.custom_to_native() else name | |
| 502 | 488 |
| 503 def custom_to_native(self): | 489 def custom_to_native(self): |
| 504 return self._data.custom_to_native | 490 return self._data.custom_to_native |
| 505 | 491 |
| 506 def parameter_type(self): | 492 def parameter_type(self): |
| 507 return '%s*' % self.native_type() | 493 return '%s*' % self.native_type() |
| 508 | 494 |
| 509 def webcore_includes(self): | 495 def webcore_includes(self): |
| 510 WTF_INCLUDES = [ | 496 WTF_INCLUDES = [ |
| 511 'ArrayBuffer', | 497 'ArrayBuffer', |
| (...skipping 23 matching lines...) Expand all Loading... |
| 535 include = self._idl_type | 521 include = self._idl_type |
| 536 return ['"%s.h"' % include] + _svg_supplemental_includes | 522 return ['"%s.h"' % include] + _svg_supplemental_includes |
| 537 | 523 |
| 538 def receiver(self): | 524 def receiver(self): |
| 539 return 'receiver->' | 525 return 'receiver->' |
| 540 | 526 |
| 541 def conversion_includes(self): | 527 def conversion_includes(self): |
| 542 includes = [self._idl_type] + (self._data.conversion_includes or []) | 528 includes = [self._idl_type] + (self._data.conversion_includes or []) |
| 543 return ['"Dart%s.h"' % include for include in includes] | 529 return ['"Dart%s.h"' % include for include in includes] |
| 544 | 530 |
| 545 def to_native_includes(self): | |
| 546 return ['"Dart%s.h"' % self.idl_type()] | |
| 547 | |
| 548 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 531 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 549 return 'Dart%s::toDart(%s)' % (self._idl_type, value) | 532 return 'Dart%s::toDart(%s)' % (self._idl_type, value) |
| 550 | 533 |
| 551 def custom_to_dart(self): | 534 def custom_to_dart(self): |
| 552 return self._data.custom_to_dart | 535 return self._data.custom_to_dart |
| 553 | 536 |
| 554 | 537 |
| 555 class InterfaceIDLTypeInfo(IDLTypeInfo): | 538 class InterfaceIDLTypeInfo(IDLTypeInfo): |
| 556 def __init__(self, idl_type, data): | 539 def __init__(self, idl_type, data): |
| 557 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) | 540 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 569 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) | 552 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 570 | 553 |
| 571 def conversion_includes(self): | 554 def conversion_includes(self): |
| 572 return self._item_info.conversion_includes() | 555 return self._item_info.conversion_includes() |
| 573 | 556 |
| 574 | 557 |
| 575 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 558 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 576 def __init__(self, data, item_info): | 559 def __init__(self, data, item_info): |
| 577 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 560 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 578 | 561 |
| 579 def emit_to_native(self, emitter, idl_node, accept_null, name, handle): | 562 def to_native_info(self, idl_node, accept_null, name, interface_name): |
| 580 assert not accept_null | 563 assert not accept_null |
| 581 emitter.Emit( | 564 return name, 'RefPtr<DOMStringList>', 'DartDOMStringList', 'toNative' |
| 582 '\n' | |
| 583 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' | |
| 584 ' if (exception)\n' | |
| 585 ' goto fail;\n', | |
| 586 NAME=name, | |
| 587 HANDLE=handle) | |
| 588 | |
| 589 def to_native_includes(self): | |
| 590 return ['"DartDOMStringList.h"'] | |
| 591 | 565 |
| 592 | 566 |
| 593 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 567 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 594 def __init__(self, idl_type, data): | 568 def __init__(self, idl_type, data): |
| 595 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) | 569 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) |
| 596 | 570 |
| 597 def emit_to_native(self, emitter, idl_node, accept_null, name, handle): | 571 def to_native_info(self, idl_node, accept_null, name, interface_name): |
| 598 function_name = 'dartTo%s' % self._capitalized_native_type() | 572 function_name = 'dartTo%s' % self._capitalized_native_type() |
| 599 if accept_null: | 573 if accept_null: |
| 600 function_name += 'WithNullCheck' | 574 function_name += 'WithNullCheck' |
| 601 type = self.native_type() | 575 type = self.native_type() |
| 602 if type == 'SerializedScriptValue': | 576 if type == 'SerializedScriptValue': |
| 603 type = 'RefPtr<%s>' % type | 577 type = 'RefPtr<%s>' % type |
| 604 if type == 'String': | 578 if type == 'String': |
| 605 type = 'DartStringAdapter' | 579 type = 'DartStringAdapter' |
| 606 emitter.Emit( | 580 return name, type, 'DartUtilities', function_name |
| 607 '\n' | |
| 608 ' $TYPE $NAME = DartUtilities::$FUNCTION_NAME($HANDLE, exception)
;\n' | |
| 609 ' if (exception)\n' | |
| 610 ' goto fail;\n', | |
| 611 TYPE=type, | |
| 612 NAME=name, | |
| 613 FUNCTION_NAME=function_name, | |
| 614 HANDLE=handle) | |
| 615 | 581 |
| 616 def parameter_type(self): | 582 def parameter_type(self): |
| 617 if self.native_type() == 'String': | 583 if self.native_type() == 'String': |
| 618 return 'const String&' | 584 return 'const String&' |
| 619 return self.native_type() | 585 return self.native_type() |
| 620 | 586 |
| 621 def conversion_includes(self): | 587 def conversion_includes(self): |
| 622 return [] | 588 return [] |
| 623 | 589 |
| 624 def to_native_includes(sefl): | |
| 625 return [] | |
| 626 | |
| 627 def to_dart_conversion(self, value, interface_name=None, attributes=None): | 590 def to_dart_conversion(self, value, interface_name=None, attributes=None): |
| 628 function_name = self._capitalized_native_type() | 591 function_name = self._capitalized_native_type() |
| 629 function_name = function_name[0].lower() + function_name[1:] | 592 function_name = function_name[0].lower() + function_name[1:] |
| 630 function_name = 'DartUtilities::%sToDart' % function_name | 593 function_name = 'DartUtilities::%sToDart' % function_name |
| 631 if attributes and 'TreatReturnedNullStringAs' in attributes: | 594 if attributes and 'TreatReturnedNullStringAs' in attributes: |
| 632 function_name += 'WithNullCheck' | 595 function_name += 'WithNullCheck' |
| 633 return '%s(%s)' % (function_name, value) | 596 return '%s(%s)' % (function_name, value) |
| 634 | 597 |
| 635 def webcore_getter_name(self): | 598 def webcore_getter_name(self): |
| 636 return self._data.webcore_getter_name | 599 return self._data.webcore_getter_name |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 if match: | 779 if match: |
| 817 if type_name == 'DOMString[]': | 780 if type_name == 'DOMString[]': |
| 818 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 781 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 819 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 782 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 820 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 783 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 821 if not type_name in _idl_type_registry: | 784 if not type_name in _idl_type_registry: |
| 822 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 785 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 823 type_data = _idl_type_registry.get(type_name) | 786 type_data = _idl_type_registry.get(type_name) |
| 824 class_name = '%sIDLTypeInfo' % type_data.clazz | 787 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 825 return globals()[class_name](type_name, type_data) | 788 return globals()[class_name](type_name, type_data) |
| OLD | NEW |