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 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 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 def FinishInterface(self): | 638 def FinishInterface(self): |
| 639 pass | 639 pass |
| 640 | 640 |
| 641 def EmitFactoryProvider(self, constructor_info, factory_provider, emitter): | 641 def EmitFactoryProvider(self, constructor_info, factory_provider, emitter): |
| 642 template_file = ('factoryprovider_%s.darttemplate' % | 642 template_file = ('factoryprovider_%s.darttemplate' % |
| 643 self._html_interface_name) | 643 self._html_interface_name) |
| 644 template = self._template_loader.TryLoad(template_file) | 644 template = self._template_loader.TryLoad(template_file) |
| 645 if not template: | 645 if not template: |
| 646 template = self._template_loader.Load('factoryprovider.darttemplate') | 646 template = self._template_loader.Load('factoryprovider.darttemplate') |
| 647 | 647 |
| 648 arguments = constructor_info.ParametersAsArgumentList() | |
| 649 comma = ',' if arguments else '' | |
| 648 emitter.Emit( | 650 emitter.Emit( |
| 649 template, | 651 template, |
| 650 FACTORYPROVIDER=factory_provider, | 652 FACTORYPROVIDER=factory_provider, |
| 651 CONSTRUCTOR=self._html_interface_name, | 653 CONSTRUCTOR=self._html_interface_name, |
| 652 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType), | 654 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType), |
| 653 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, | 655 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, |
| 654 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 656 ARGUMENTS=arguments, |
| 657 PRE_ARGUMENTS_COMMA=comma, | |
| 658 ARGUMENTS_PATTERN=','.join(['#'] * len(constructor_info.param_infos))) | |
| 655 | 659 |
| 656 def SecondaryContext(self, interface): | 660 def SecondaryContext(self, interface): |
| 657 if interface is not self._current_secondary_parent: | 661 if interface is not self._current_secondary_parent: |
| 658 self._current_secondary_parent = interface | 662 self._current_secondary_parent = interface |
| 659 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 663 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
| 660 | 664 |
| 661 def AddIndexer(self, element_type): | 665 def AddIndexer(self, element_type): |
| 662 """Adds all the methods required to complete implementation of List.""" | 666 """Adds all the methods required to complete implementation of List.""" |
| 663 # We would like to simply inherit the implementation of everything except | 667 # We would like to simply inherit the implementation of everything except |
| 664 # length, [], and maybe []=. It is possible to extend from a base | 668 # length, [], and maybe []=. It is possible to extend from a base |
| 665 # array implementation class only when there is no other implementation | 669 # array implementation class only when there is no other implementation |
| 666 # inheritance. There might be no implementation inheritance other than | 670 # inheritance. There might be no implementation inheritance other than |
| 667 # DOMBaseWrapper for many classes, but there might be some where the | 671 # DOMBaseWrapper for many classes, but there might be some where the |
| 668 # array-ness is introduced by a non-root interface: | 672 # array-ness is introduced by a non-root interface: |
| 669 # | 673 # |
| 670 # interface Y extends X, List<T> ... | 674 # interface Y extends X, List<T> ... |
| 671 # | 675 # |
| 672 # In the non-root case we have to choose between: | 676 # In the non-root case we have to choose between: |
| 673 # | 677 # |
| 674 # class YImpl extends XImpl { add List<T> methods; } | 678 # class YImpl extends XImpl { add List<T> methods; } |
| 675 # | 679 # |
| 676 # and | 680 # and |
| 677 # | 681 # |
| 678 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 682 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
| 679 # | 683 # |
| 680 self._members_emitter.Emit( | 684 self._members_emitter.Emit( |
| 681 '\n' | 685 '\n' |
| 682 ' $TYPE operator[](int index) native "return this[index];";\n', | 686 ' $TYPE operator[](int index) => JS("$TYPE", "#[#]", this, index);\n', |
| 683 TYPE=self._NarrowOutputType(element_type)) | 687 TYPE=self._NarrowOutputType(element_type)) |
| 684 | 688 |
| 685 if 'CustomIndexedSetter' in self._interface.ext_attrs: | 689 if 'CustomIndexedSetter' in self._interface.ext_attrs: |
| 686 self._members_emitter.Emit( | 690 self._members_emitter.Emit( |
| 687 '\n' | 691 '\n' |
| 688 ' void operator[]=(int index, $TYPE value) native "this[index] = valu e";\n', | 692 ' void operator[]=(int index, $TYPE value) =>' |
| 693 ' JS("void", "#[#] = #", this, index, value);\n', | |
| 689 TYPE=self._NarrowInputType(element_type)) | 694 TYPE=self._NarrowInputType(element_type)) |
| 690 else: | 695 else: |
| 691 # The HTML library implementation of NodeList has a custom indexed setter | 696 # The HTML library implementation of NodeList has a custom indexed setter |
| 692 # implementation that uses the parent node the NodeList is associated | 697 # implementation that uses the parent node the NodeList is associated |
| 693 # with if one is available. | 698 # with if one is available. |
| 694 if self._interface.id != 'NodeList': | 699 if self._interface.id != 'NodeList': |
| 695 self._members_emitter.Emit( | 700 self._members_emitter.Emit( |
| 696 '\n' | 701 '\n' |
| 697 ' void operator[]=(int index, $TYPE value) {\n' | 702 ' void operator[]=(int index, $TYPE value) {\n' |
| 698 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' | 703 ' throw new UnsupportedOperationException("Cannot assign element of immutable List.");\n' |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 self._AddRenamingGetter(attribute, html_name) | 768 self._AddRenamingGetter(attribute, html_name) |
| 764 if not read_only: | 769 if not read_only: |
| 765 self._AddRenamingSetter(attribute, html_name) | 770 self._AddRenamingSetter(attribute, html_name) |
| 766 | 771 |
| 767 def _AddRenamingGetter(self, attr, html_name): | 772 def _AddRenamingGetter(self, attr, html_name): |
| 768 conversion = self._OutputConversion(attr.type.id, attr.id) | 773 conversion = self._OutputConversion(attr.type.id, attr.id) |
| 769 if conversion: | 774 if conversion: |
| 770 return self._AddConvertingGetter(attr, html_name, conversion) | 775 return self._AddConvertingGetter(attr, html_name, conversion) |
| 771 return_type = self._NarrowOutputType(attr.type.id) | 776 return_type = self._NarrowOutputType(attr.type.id) |
| 772 self._members_emitter.Emit( | 777 self._members_emitter.Emit( |
| 773 '\n $TYPE get $HTML_NAME() native "return this.$NAME;";\n', | 778 # TODO(sra): Use metadata to provide native name. |
| 779 '\n $TYPE get $HTML_NAME() => JS("$TYPE", "#.$NAME", this);\n', | |
| 774 HTML_NAME=html_name, | 780 HTML_NAME=html_name, |
| 775 NAME=attr.id, | 781 NAME=attr.id, |
| 776 TYPE=return_type) | 782 TYPE=return_type) |
| 777 | 783 |
| 778 def _AddRenamingSetter(self, attr, html_name): | 784 def _AddRenamingSetter(self, attr, html_name): |
| 779 conversion = self._InputConversion(attr.type.id, attr.id) | 785 conversion = self._InputConversion(attr.type.id, attr.id) |
| 780 if conversion: | 786 if conversion: |
| 781 return self._AddConvertingSetter(attr, html_name, conversion) | 787 return self._AddConvertingSetter(attr, html_name, conversion) |
| 782 self._members_emitter.Emit( | 788 self._members_emitter.Emit( |
| 783 '\n void set $HTML_NAME($TYPE value)' | 789 # TODO(sra): Use metadata to provide native name. |
| 784 ' native "this.$NAME = value;";\n', | 790 '\n void set $HTML_NAME($TYPE value) {' |
| 791 ' JS("void", "#.$NAME = #", this, value); }\n', | |
|
blois
2012/10/12 16:55:19
Nit- should this be expanded to multiple lines? No
sra1
2012/10/12 21:39:47
Done.
| |
| 785 HTML_NAME=html_name, | 792 HTML_NAME=html_name, |
| 786 NAME=attr.id, | 793 NAME=attr.id, |
| 787 TYPE=self._NarrowInputType(attr.type.id)) | 794 TYPE=self._NarrowInputType(attr.type.id)) |
| 788 | 795 |
| 789 def _AddConvertingGetter(self, attr, html_name, conversion): | 796 def _AddConvertingGetter(self, attr, html_name, conversion): |
| 790 self._members_emitter.Emit( | 797 self._members_emitter.Emit( |
| 798 # TODO(sra): Use metadata to provide native name. | |
| 791 '\n $RETURN_TYPE get $HTML_NAME => $CONVERT(this._$(HTML_NAME));' | 799 '\n $RETURN_TYPE get $HTML_NAME => $CONVERT(this._$(HTML_NAME));' |
| 792 '\n $NATIVE_TYPE get _$HTML_NAME() native "return this.$NAME;";' | 800 '\n $NATIVE_TYPE get _$HTML_NAME() =>' |
| 801 ' JS("$NATIVE_TYPE", "#.$NAME", this);\n' | |
| 793 '\n', | 802 '\n', |
| 794 CONVERT=conversion.function_name, | 803 CONVERT=conversion.function_name, |
| 795 HTML_NAME=html_name, | 804 HTML_NAME=html_name, |
| 796 NAME=attr.id, | 805 NAME=attr.id, |
| 797 RETURN_TYPE=conversion.output_type, | 806 RETURN_TYPE=conversion.output_type, |
| 798 NATIVE_TYPE=conversion.input_type) | 807 NATIVE_TYPE=conversion.input_type) |
| 799 | 808 |
| 800 def _AddConvertingSetter(self, attr, html_name, conversion): | 809 def _AddConvertingSetter(self, attr, html_name, conversion): |
| 801 self._members_emitter.Emit( | 810 self._members_emitter.Emit( |
| 811 # TODO(sra): Use metadata to provide native name. | |
| 802 '\n void set $HTML_NAME($INPUT_TYPE value) {' | 812 '\n void set $HTML_NAME($INPUT_TYPE value) {' |
| 803 ' this._$HTML_NAME = $CONVERT(value); }' | 813 ' this._$HTML_NAME = $CONVERT(value); }' |
| 804 '\n void set _$HTML_NAME(/*$NATIVE_TYPE*/ value)' | 814 '\n void set _$HTML_NAME(/*$NATIVE_TYPE*/ value) {' |
| 805 ' native "this.$NAME = value;";' | 815 ' JS("void", "#.$NAME = #", this, value); }\n' |
| 806 '\n', | 816 '\n', |
| 807 CONVERT=conversion.function_name, | 817 CONVERT=conversion.function_name, |
| 808 HTML_NAME=html_name, | 818 HTML_NAME=html_name, |
| 809 NAME=attr.id, | 819 NAME=attr.id, |
| 810 INPUT_TYPE=conversion.input_type, | 820 INPUT_TYPE=conversion.input_type, |
| 811 NATIVE_TYPE=conversion.output_type) | 821 NATIVE_TYPE=conversion.output_type) |
| 812 | 822 |
| 813 def AmendIndexer(self, element_type): | 823 def AmendIndexer(self, element_type): |
| 814 pass | 824 pass |
| 815 | 825 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 836 MODIFIERS='static ' if info.IsStatic() else '', | 846 MODIFIERS='static ' if info.IsStatic() else '', |
| 837 TYPE=return_type, | 847 TYPE=return_type, |
| 838 HTML_NAME=html_name, | 848 HTML_NAME=html_name, |
| 839 NAME=info.declared_name, | 849 NAME=info.declared_name, |
| 840 PARAMS=info.ParametersImplementationDeclaration( | 850 PARAMS=info.ParametersImplementationDeclaration( |
| 841 lambda type_name: self._NarrowInputType(type_name))) | 851 lambda type_name: self._NarrowInputType(type_name))) |
| 842 | 852 |
| 843 operation_emitter.Emit( | 853 operation_emitter.Emit( |
| 844 '\n' | 854 '\n' |
| 845 #' // @native("$NAME")\n;' | 855 #' // @native("$NAME")\n;' |
| 846 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') | 856 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
|
Anton Muhin
2012/10/12 11:40:38
just for my education, any reasons why it still us
sra1
2012/10/12 21:39:47
Some form where there is a simple renaming will co
Anton Muhin
2012/10/15 10:27:34
I see, thanks, Stephen. May main concern is this
| |
| 847 else: | 857 else: |
| 848 self._members_emitter.Emit( | 858 self._members_emitter.Emit( |
| 849 '\n' | 859 '\n' |
| 850 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', | 860 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
| 851 MODIFIERS='static ' if info.IsStatic() else '', | 861 MODIFIERS='static ' if info.IsStatic() else '', |
| 852 TYPE=self._NarrowOutputType(info.type_name), | 862 TYPE=self._NarrowOutputType(info.type_name), |
| 853 NAME=info.name, | 863 NAME=info.name, |
| 854 PARAMS=info.ParametersImplementationDeclaration( | 864 PARAMS=info.ParametersImplementationDeclaration( |
| 855 lambda type_name: self._NarrowInputType(type_name))) | 865 lambda type_name: self._NarrowInputType(type_name))) |
| 856 | 866 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 | 1117 |
| 1108 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1118 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1109 library_file_dir = os.path.dirname(library_file_path) | 1119 library_file_dir = os.path.dirname(library_file_path) |
| 1110 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1120 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1111 imports_emitter = library_emitter.Emit( | 1121 imports_emitter = library_emitter.Emit( |
| 1112 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1122 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1113 for path in sorted(self._path_to_emitter.keys()): | 1123 for path in sorted(self._path_to_emitter.keys()): |
| 1114 relpath = os.path.relpath(path, library_file_dir) | 1124 relpath = os.path.relpath(path, library_file_dir) |
| 1115 imports_emitter.Emit( | 1125 imports_emitter.Emit( |
| 1116 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1126 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |