| 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 the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 from systemfrog import * | 9 from systemfrog import * |
| 10 from systeminterface import * | 10 from systeminterface import * |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 self._dart_interface_file_paths.append(dart_interface_file_path) | 598 self._dart_interface_file_paths.append(dart_interface_file_path) |
| 599 | 599 |
| 600 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) | 600 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| 601 | 601 |
| 602 template_file = 'interface_%s.darttemplate' % interface_name | 602 template_file = 'interface_%s.darttemplate' % interface_name |
| 603 template = self._templates.TryLoad(template_file) | 603 template = self._templates.TryLoad(template_file) |
| 604 if not template: | 604 if not template: |
| 605 template = self._templates.Load('interface.darttemplate') | 605 template = self._templates.Load('interface.darttemplate') |
| 606 | 606 |
| 607 return HtmlDartInterfaceGenerator( | 607 return HtmlDartInterfaceGenerator( |
| 608 interface, dart_interface_code, | 608 self, interface, dart_interface_code, |
| 609 template, | 609 template, |
| 610 common_prefix, super_interface_name, | 610 common_prefix, super_interface_name, |
| 611 source_filter, self, self._shared) | 611 source_filter, self._shared) |
| 612 | 612 |
| 613 def ProcessCallback(self, interface, info): | 613 def ProcessCallback(self, interface, info): |
| 614 """Generates a typedef for the callback interface.""" | 614 """Generates a typedef for the callback interface.""" |
| 615 interface_name = interface.id | 615 interface_name = interface.id |
| 616 file_path = self._FilePathForDartInterface(interface_name) | 616 file_path = self._FilePathForDartInterface(interface_name) |
| 617 self._ProcessCallback(interface, info, file_path) | 617 self._ProcessCallback(interface, info, file_path) |
| 618 | 618 |
| 619 def GenerateLibraries(self, lib_dir): | 619 def GenerateLibraries(self, lib_dir): |
| 620 pass | 620 pass |
| 621 | 621 |
| 622 | 622 |
| 623 def _FilePathForDartInterface(self, interface_name): | 623 def _FilePathForDartInterface(self, interface_name): |
| 624 """Returns the file path of the Dart interface definition.""" | 624 """Returns the file path of the Dart interface definition.""" |
| 625 # TODO(jmesserly): is this the right path | 625 # TODO(jmesserly): is this the right path |
| 626 return os.path.join(self._output_dir, 'html', 'interface', | 626 return os.path.join(self._output_dir, 'html', 'interface', |
| 627 '%s.dart' % interface_name) | 627 '%s.dart' % interface_name) |
| 628 | 628 |
| 629 # ------------------------------------------------------------------------------ | 629 # ------------------------------------------------------------------------------ |
| 630 | 630 |
| 631 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 631 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| 632 # term, but it makes merging better for now. | 632 # term, but it makes merging better for now. |
| 633 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): | 633 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| 634 """Generates Dart Interface definition for one DOM IDL interface.""" | 634 """Generates Dart Interface definition for one DOM IDL interface.""" |
| 635 | 635 |
| 636 def __init__(self, interface, emitter, template, | 636 def __init__(self, system, interface, emitter, template, |
| 637 common_prefix, super_interface, source_filter, system, shared): | 637 common_prefix, super_interface, source_filter, shared): |
| 638 super(HtmlDartInterfaceGenerator, self).__init__(interface, | 638 super(HtmlDartInterfaceGenerator, self).__init__(system, interface, |
| 639 emitter, template, common_prefix, super_interface, source_filter) | 639 emitter, template, common_prefix, super_interface, source_filter) |
| 640 self._system = system | |
| 641 self._shared = shared | 640 self._shared = shared |
| 642 | 641 |
| 643 def StartInterface(self): | 642 def StartInterface(self): |
| 644 typename = self._interface.id | 643 typename = self._interface.id |
| 645 | 644 |
| 646 extends = [] | 645 extends = [] |
| 647 suppressed_extends = [] | 646 suppressed_extends = [] |
| 648 | 647 |
| 649 for parent in self._interface.parents: | 648 for parent in self._interface.parents: |
| 650 # TODO(vsm): Remove source_filter. | 649 # TODO(vsm): Remove source_filter. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 self._type_comment_emitter.Emit("/// @domName $DOMNAME", | 688 self._type_comment_emitter.Emit("/// @domName $DOMNAME", |
| 690 DOMNAME=self._interface.doc_js_name) | 689 DOMNAME=self._interface.doc_js_name) |
| 691 | 690 |
| 692 if constructor_info: | 691 if constructor_info: |
| 693 self._members_emitter.Emit( | 692 self._members_emitter.Emit( |
| 694 '\n' | 693 '\n' |
| 695 ' $CTOR($PARAMS);\n', | 694 ' $CTOR($PARAMS);\n', |
| 696 CTOR=typename, | 695 CTOR=typename, |
| 697 PARAMS=constructor_info.ParametersInterfaceDeclaration()); | 696 PARAMS=constructor_info.ParametersInterfaceDeclaration()); |
| 698 | 697 |
| 699 element_type = MaybeTypedArrayElementType(self._interface) | 698 element_type = MaybeTypedArrayElementTypeInHierarchy( |
| 699 self._interface, self._system._database) |
| 700 if element_type: | 700 if element_type: |
| 701 self._members_emitter.Emit( | 701 self._members_emitter.Emit( |
| 702 '\n' | 702 '\n' |
| 703 ' $CTOR(int length);\n' | 703 ' $CTOR(int length);\n' |
| 704 '\n' | 704 '\n' |
| 705 ' $CTOR.fromList(List<$TYPE> list);\n' | 705 ' $CTOR.fromList(List<$TYPE> list);\n' |
| 706 '\n' | 706 '\n' |
| 707 ' $CTOR.fromBuffer(ArrayBuffer buffer,' | 707 ' $CTOR.fromBuffer(ArrayBuffer buffer,' |
| 708 ' [int byteOffset, int length]);\n', | 708 ' [int byteOffset, int length]);\n', |
| 709 CTOR=self._interface.id, | 709 CTOR=self._interface.id, |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1520 # The list interface for this class is manually generated. | 1520 # The list interface for this class is manually generated. |
| 1521 if self._interface.id == 'NodeList': | 1521 if self._interface.id == 'NodeList': |
| 1522 return | 1522 return |
| 1523 | 1523 |
| 1524 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 1524 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
| 1525 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 1525 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
| 1526 template_file = 'immutable_list_mixin.darttemplate' | 1526 template_file = 'immutable_list_mixin.darttemplate' |
| 1527 template = self._system._templates.Load(template_file) | 1527 template = self._system._templates.Load(template_file) |
| 1528 self._members_emitter.Emit(template, E=DartType(element_type)) | 1528 self._members_emitter.Emit(template, E=DartType(element_type)) |
| 1529 | 1529 |
| 1530 def AmendIndexer(self, element_type): |
| 1531 pass |
| 1532 |
| 1530 def _HasNativeIndexGetter(self, interface): | 1533 def _HasNativeIndexGetter(self, interface): |
| 1531 return ('IndexedGetter' in interface.ext_attrs or | 1534 return ('IndexedGetter' in interface.ext_attrs or |
| 1532 'NumericIndexedGetter' in interface.ext_attrs) | 1535 'NumericIndexedGetter' in interface.ext_attrs) |
| 1533 | 1536 |
| 1534 def _EmitNativeIndexGetter(self, interface, element_type): | 1537 def _EmitNativeIndexGetter(self, interface, element_type): |
| 1535 method_name = '_index' | 1538 method_name = '_index' |
| 1536 self._members_emitter.Emit( | 1539 self._members_emitter.Emit( |
| 1537 '\n $TYPE operator[](int index) => _wrap($(THIS)[index]);\n', | 1540 '\n $TYPE operator[](int index) => _wrap($(THIS)[index]);\n', |
| 1538 TYPE=DartType(element_type), | 1541 TYPE=DartType(element_type), |
| 1539 THIS=self.DomObjectName(), | 1542 THIS=self.DomObjectName(), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 self._members_emitter.Emit( | 1578 self._members_emitter.Emit( |
| 1576 '\n' | 1579 '\n' |
| 1577 ' $TYPE $HTML_NAME($PARAMS) => $FUNCTION_CALL;\n', | 1580 ' $TYPE $HTML_NAME($PARAMS) => $FUNCTION_CALL;\n', |
| 1578 TYPE=info.type_name, | 1581 TYPE=info.type_name, |
| 1579 HTML_NAME=html_name, | 1582 HTML_NAME=html_name, |
| 1580 PARAMS=info.ParametersImplementationDeclaration(), | 1583 PARAMS=info.ParametersImplementationDeclaration(), |
| 1581 FUNCTION_CALL=function_call) | 1584 FUNCTION_CALL=function_call) |
| 1582 | 1585 |
| 1583 def AddStaticOperation(self, info): | 1586 def AddStaticOperation(self, info): |
| 1584 pass | 1587 pass |
| OLD | NEW |