Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: lib/html/scripts/systemhtml.py

Issue 11094082: Convert legacy 'native code' to JS-forms in dart:html (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/html/dart2js/html_dart2js.dart ('k') | lib/html/src/dart2js_FactoryProviders.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 # conversion code. 748 # conversion code.
744 if (self._OutputConversion(attribute.type.id, attribute.id) or 749 if (self._OutputConversion(attribute.type.id, attribute.id) or
745 self._InputConversion(attribute.type.id, attribute.id)): 750 self._InputConversion(attribute.type.id, attribute.id)):
746 self._AddAttributeUsingProperties(attribute, html_name, read_only) 751 self._AddAttributeUsingProperties(attribute, html_name, read_only)
747 return 752 return
748 753
749 output_type = self._NarrowOutputType(attribute.type.id) 754 output_type = self._NarrowOutputType(attribute.type.id)
750 input_type = self._NarrowInputType(attribute.type.id) 755 input_type = self._NarrowInputType(attribute.type.id)
751 if not read_only: 756 if not read_only:
752 self._members_emitter.Emit( 757 self._members_emitter.Emit(
753 '\n $TYPE $NAME;\n', 758 '\n $TYPE $NAME;'
759 '\n',
754 NAME=DartDomNameOfAttribute(attribute), 760 NAME=DartDomNameOfAttribute(attribute),
755 TYPE=output_type) 761 TYPE=output_type)
756 else: 762 else:
757 self._members_emitter.Emit( 763 self._members_emitter.Emit(
758 '\n final $TYPE $NAME;\n', 764 '\n final $TYPE $NAME;'
765 '\n',
759 NAME=DartDomNameOfAttribute(attribute), 766 NAME=DartDomNameOfAttribute(attribute),
760 TYPE=output_type) 767 TYPE=output_type)
761 768
762 def _AddAttributeUsingProperties(self, attribute, html_name, read_only): 769 def _AddAttributeUsingProperties(self, attribute, html_name, read_only):
763 self._AddRenamingGetter(attribute, html_name) 770 self._AddRenamingGetter(attribute, html_name)
764 if not read_only: 771 if not read_only:
765 self._AddRenamingSetter(attribute, html_name) 772 self._AddRenamingSetter(attribute, html_name)
766 773
767 def _AddRenamingGetter(self, attr, html_name): 774 def _AddRenamingGetter(self, attr, html_name):
768 conversion = self._OutputConversion(attr.type.id, attr.id) 775 conversion = self._OutputConversion(attr.type.id, attr.id)
769 if conversion: 776 if conversion:
770 return self._AddConvertingGetter(attr, html_name, conversion) 777 return self._AddConvertingGetter(attr, html_name, conversion)
771 return_type = self._NarrowOutputType(attr.type.id) 778 return_type = self._NarrowOutputType(attr.type.id)
772 self._members_emitter.Emit( 779 self._members_emitter.Emit(
773 '\n $TYPE get $HTML_NAME() native "return this.$NAME;";\n', 780 # TODO(sra): Use metadata to provide native name.
781 '\n $TYPE get $HTML_NAME() => JS("$TYPE", "#.$NAME", this);'
782 '\n',
774 HTML_NAME=html_name, 783 HTML_NAME=html_name,
775 NAME=attr.id, 784 NAME=attr.id,
776 TYPE=return_type) 785 TYPE=return_type)
777 786
778 def _AddRenamingSetter(self, attr, html_name): 787 def _AddRenamingSetter(self, attr, html_name):
779 conversion = self._InputConversion(attr.type.id, attr.id) 788 conversion = self._InputConversion(attr.type.id, attr.id)
780 if conversion: 789 if conversion:
781 return self._AddConvertingSetter(attr, html_name, conversion) 790 return self._AddConvertingSetter(attr, html_name, conversion)
782 self._members_emitter.Emit( 791 self._members_emitter.Emit(
783 '\n void set $HTML_NAME($TYPE value)' 792 # TODO(sra): Use metadata to provide native name.
784 ' native "this.$NAME = value;";\n', 793 '\n void set $HTML_NAME($TYPE value) {'
794 '\n JS("void", "#.$NAME = #", this, value);'
795 '\n }'
796 '\n',
785 HTML_NAME=html_name, 797 HTML_NAME=html_name,
786 NAME=attr.id, 798 NAME=attr.id,
787 TYPE=self._NarrowInputType(attr.type.id)) 799 TYPE=self._NarrowInputType(attr.type.id))
788 800
789 def _AddConvertingGetter(self, attr, html_name, conversion): 801 def _AddConvertingGetter(self, attr, html_name, conversion):
790 self._members_emitter.Emit( 802 self._members_emitter.Emit(
803 # TODO(sra): Use metadata to provide native name.
791 '\n $RETURN_TYPE get $HTML_NAME => $CONVERT(this._$(HTML_NAME));' 804 '\n $RETURN_TYPE get $HTML_NAME => $CONVERT(this._$(HTML_NAME));'
792 '\n $NATIVE_TYPE get _$HTML_NAME() native "return this.$NAME;";' 805 '\n $NATIVE_TYPE get _$HTML_NAME() =>'
806 ' JS("$NATIVE_TYPE", "#.$NAME", this);'
793 '\n', 807 '\n',
794 CONVERT=conversion.function_name, 808 CONVERT=conversion.function_name,
795 HTML_NAME=html_name, 809 HTML_NAME=html_name,
796 NAME=attr.id, 810 NAME=attr.id,
797 RETURN_TYPE=conversion.output_type, 811 RETURN_TYPE=conversion.output_type,
798 NATIVE_TYPE=conversion.input_type) 812 NATIVE_TYPE=conversion.input_type)
799 813
800 def _AddConvertingSetter(self, attr, html_name, conversion): 814 def _AddConvertingSetter(self, attr, html_name, conversion):
801 self._members_emitter.Emit( 815 self._members_emitter.Emit(
816 # TODO(sra): Use metadata to provide native name.
802 '\n void set $HTML_NAME($INPUT_TYPE value) {' 817 '\n void set $HTML_NAME($INPUT_TYPE value) {'
803 ' this._$HTML_NAME = $CONVERT(value); }' 818 '\n this._$HTML_NAME = $CONVERT(value);'
804 '\n void set _$HTML_NAME(/*$NATIVE_TYPE*/ value)' 819 '\n }'
805 ' native "this.$NAME = value;";' 820 '\n void set _$HTML_NAME(/*$NATIVE_TYPE*/ value) {'
821 '\n JS("void", "#.$NAME = #", this, value);'
822 '\n }'
806 '\n', 823 '\n',
807 CONVERT=conversion.function_name, 824 CONVERT=conversion.function_name,
808 HTML_NAME=html_name, 825 HTML_NAME=html_name,
809 NAME=attr.id, 826 NAME=attr.id,
810 INPUT_TYPE=conversion.input_type, 827 INPUT_TYPE=conversion.input_type,
811 NATIVE_TYPE=conversion.output_type) 828 NATIVE_TYPE=conversion.output_type)
812 829
813 def AmendIndexer(self, element_type): 830 def AmendIndexer(self, element_type):
814 pass 831 pass
815 832
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1124
1108 library_emitter = self._multiemitter.FileEmitter(library_file_path) 1125 library_emitter = self._multiemitter.FileEmitter(library_file_path)
1109 library_file_dir = os.path.dirname(library_file_path) 1126 library_file_dir = os.path.dirname(library_file_path)
1110 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) 1127 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
1111 imports_emitter = library_emitter.Emit( 1128 imports_emitter = library_emitter.Emit(
1112 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) 1129 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir))
1113 for path in sorted(self._path_to_emitter.keys()): 1130 for path in sorted(self._path_to_emitter.keys()):
1114 relpath = os.path.relpath(path, library_file_dir) 1131 relpath = os.path.relpath(path, library_file_dir)
1115 imports_emitter.Emit( 1132 imports_emitter.Emit(
1116 "#source('$PATH');\n", PATH=massage_path(relpath)) 1133 "#source('$PATH');\n", PATH=massage_path(relpath))
OLDNEW
« no previous file with comments | « lib/html/dart2js/html_dart2js.dart ('k') | lib/html/src/dart2js_FactoryProviders.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698