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

Side by Side Diff: tools/dom/scripts/systemhtml.py

Issue 1987073002: Strip unused functionality from dart:html and fix strong mode errors. Switch from blacklisting pure… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
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 logging 10 import logging
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 if factory_provider and factory_provider != info.factory_provider_name: 547 if factory_provider and factory_provider != info.factory_provider_name:
548 _logger.warn('Conflicting factory provider names: %s != %s' % 548 _logger.warn('Conflicting factory provider names: %s != %s' %
549 (factory_provider, info.factory_provider_name)) 549 (factory_provider, info.factory_provider_name))
550 factory_provider = info.factory_provider_name 550 factory_provider = info.factory_provider_name
551 551
552 implementation_emitter = self._ImplementationEmitter() 552 implementation_emitter = self._ImplementationEmitter()
553 553
554 base_type_info = None 554 base_type_info = None
555 if self._interface.parents: 555 if self._interface.parents:
556 supertype = self._interface.parents[0].type.id 556 supertype = self._interface.parents[0].type.id
557 if not IsDartCollectionType(supertype) and not IsPureInterface(supertype): 557 if not IsDartCollectionType(supertype) and not IsPureInterface(supertype, self._database):
558 base_type_info = self._type_registry.TypeInfo(supertype) 558 base_type_info = self._type_registry.TypeInfo(supertype)
559 559
560 if base_type_info: 560 if base_type_info:
561 base_class = base_type_info.implementation_name() 561 base_class = base_type_info.implementation_name()
562 else: 562 else:
563 base_class = self._backend.RootClassName() 563 base_class = self._backend.RootClassName()
564 564
565 implements = self._backend.AdditionalImplementedInterfaces() 565 implements = self._backend.AdditionalImplementedInterfaces()
566 for parent in self._interface.parents: 566 for parent in self._interface.parents:
567 parent_type_info = self._type_registry.TypeInfo(parent.type.id) 567 parent_type_info = self._type_registry.TypeInfo(parent.type.id)
(...skipping 19 matching lines...) Expand all
587 elif (base_class == 'NativeFieldWrapperClass2' and 587 elif (base_class == 'NativeFieldWrapperClass2' and
588 self._options.dart_js_interop and 588 self._options.dart_js_interop and
589 not(isinstance(self._backend, Dart2JSBackend))): 589 not(isinstance(self._backend, Dart2JSBackend))):
590 base_class = 'DartHtmlDomObject' 590 base_class = 'DartHtmlDomObject'
591 591
592 annotations = self._metadata.GetFormattedMetadata( 592 annotations = self._metadata.GetFormattedMetadata(
593 self._library_name, self._interface, None, '') 593 self._library_name, self._interface, None, '')
594 594
595 class_modifiers = '' 595 class_modifiers = ''
596 if (self._renamer.ShouldSuppressInterface(self._interface) or 596 if (self._renamer.ShouldSuppressInterface(self._interface) or
597 IsPureInterface(self._interface.id)): 597 IsPureInterface(self._interface.id, self._database)):
598 # XMLHttpRequestProgressEvent can't be abstract we need to instantiate 598 # XMLHttpRequestProgressEvent can't be abstract we need to instantiate
599 # for JsInterop. 599 # for JsInterop.
600 if (not(isinstance(self._backend, Dart2JSBackend)) and 600 if (not(isinstance(self._backend, Dart2JSBackend)) and
601 (self._interface.id == 'XMLHttpRequestProgressEvent' or 601 (self._interface.id == 'XMLHttpRequestProgressEvent' or
602 self._interface.id == 'DOMStringMap')): 602 self._interface.id == 'DOMStringMap')):
603 # Suppress abstract for XMLHttpRequestProgressEvent and DOMStringMap 603 # Suppress abstract for XMLHttpRequestProgressEvent and DOMStringMap
604 # for Dartium. Need to be able to instantiate the class; can't be abstr act. 604 # for Dartium. Need to be able to instantiate the class; can't be abstr act.
605 class_modifiers = '' 605 class_modifiers = ''
606 else: 606 else:
607 # For Dartium w/ JsInterop these suppressed interfaces are needed to 607 # For Dartium w/ JsInterop these suppressed interfaces are needed to
608 # instanciate the internal classes. 608 # instanciate the internal classes.
609 if (self._renamer.ShouldSuppressInterface(self._interface) and 609 if (self._renamer.ShouldSuppressInterface(self._interface) and
610 not(isinstance(self._backend, Dart2JSBackend)) and 610 not(isinstance(self._backend, Dart2JSBackend)) and
611 self._options.dart_js_interop): 611 self._options.dart_js_interop):
612 class_modifiers = '' 612 class_modifiers = ''
613 else: 613 else:
614 class_modifiers = 'abstract ' 614 class_modifiers = 'abstract '
615 615
616 native_spec = '' 616 native_spec = ''
617 if not IsPureInterface(self._interface.id): 617 if not IsPureInterface(self._interface.id, self._database):
618 native_spec = self._backend.NativeSpec() 618 native_spec = self._backend.NativeSpec()
619 619
620 class_name = self._interface_type_info.implementation_name() 620 class_name = self._interface_type_info.implementation_name()
621 621
622 js_interop_wrapper = ''' 622 js_interop_wrapper = '''
623 623
624 @Deprecated("Internal Use Only") 624 @Deprecated("Internal Use Only")
625 external static Type get instanceRuntimeType; 625 external static Type get instanceRuntimeType;
626 626
627 @Deprecated("Internal Use Only") 627 @Deprecated("Internal Use Only")
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 682
683 isElement = False 683 isElement = False
684 for parent in self._database.Hierarchy(self._interface): 684 for parent in self._database.Hierarchy(self._interface):
685 if parent.id == 'Element': 685 if parent.id == 'Element':
686 isElement = True 686 isElement = True
687 687
688 # Write out the JsInterop code. 688 # Write out the JsInterop code.
689 if (implementation_members_emitter and 689 if (implementation_members_emitter and
690 self._options.templates._conditions['DARTIUM'] and 690 self._options.templates._conditions['DARTIUM'] and
691 self._options.dart_js_interop and 691 self._options.dart_js_interop and
692 not IsPureInterface(self._interface.id)): 692 not IsPureInterface(self._interface.id, self._database)):
693 implementation_members_emitter.Emit(js_interop_wrapper) 693 implementation_members_emitter.Emit(js_interop_wrapper)
694 694
695 if isElement and self._interface.id != 'Element': 695 if isElement and self._interface.id != 'Element':
696 implementation_members_emitter.Emit( 696 implementation_members_emitter.Emit(
697 ' /**\n' 697 ' /**\n'
698 ' * Constructor instantiated by the DOM when a custom element has be en created.\n' 698 ' * Constructor instantiated by the DOM when a custom element has be en created.\n'
699 ' *\n' 699 ' *\n'
700 ' * This can only be called by subclasses from their created constru ctor.\n' 700 ' * This can only be called by subclasses from their created constru ctor.\n'
701 ' */\n' 701 ' */\n'
702 ' $CLASSNAME.created() : super.created();\n', 702 ' $CLASSNAME.created() : super.created();\n',
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 753
754 def ImplementsMergedMembers(self): 754 def ImplementsMergedMembers(self):
755 return True 755 return True
756 756
757 def GenerateCallback(self, info): 757 def GenerateCallback(self, info):
758 pass 758 pass
759 759
760 def AdditionalImplementedInterfaces(self): 760 def AdditionalImplementedInterfaces(self):
761 implements = super(Dart2JSBackend, self).AdditionalImplementedInterfaces() 761 implements = super(Dart2JSBackend, self).AdditionalImplementedInterfaces()
762 if self._interface_type_info.list_item_type() and self.HasIndexedGetter(): 762 if self._interface_type_info.list_item_type() and self.HasIndexedGetter():
763 implements.append('JavaScriptIndexingBehavior') 763 item_type = self._type_registry.TypeInfo(
764 self._interface_type_info.list_item_type()).dart_type()
765 implements.append('JavaScriptIndexingBehavior<%s>' % item_type)
764 return implements 766 return implements
765 767
766 def NativeSpec(self): 768 def NativeSpec(self):
767 native_spec = MakeNativeSpec(self._interface.javascript_binding_name) 769 native_spec = MakeNativeSpec(self._interface.javascript_binding_name)
768 return '@Native("%s")\n' % native_spec 770 return '@Native("%s")\n' % native_spec
769 771
770 def ImplementationTemplate(self): 772 def ImplementationTemplate(self):
771 template_file = ('impl_%s.darttemplate' % 773 template_file = ('impl_%s.darttemplate' %
772 self._interface.doc_js_name) 774 self._interface.doc_js_name)
773 return (self._template_loader.TryLoad(template_file) or 775 return (self._template_loader.TryLoad(template_file) or
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 ' throw new UnsupportedError("Cannot assign element of immutable Li st.");\n' 893 ' throw new UnsupportedError("Cannot assign element of immutable Li st.");\n'
892 ' }\n', 894 ' }\n',
893 TYPE=self._NarrowInputType(element_type)) 895 TYPE=self._NarrowInputType(element_type))
894 896
895 self.EmitListMixin(self._DartType(element_type)) 897 self.EmitListMixin(self._DartType(element_type))
896 898
897 def EmitAttribute(self, attribute, html_name, read_only): 899 def EmitAttribute(self, attribute, html_name, read_only):
898 if self._HasCustomImplementation(attribute.id): 900 if self._HasCustomImplementation(attribute.id):
899 return 901 return
900 902
901 if IsPureInterface(self._interface.id): 903 if IsPureInterface(self._interface.id, self._database):
902 self._AddInterfaceAttribute(attribute, html_name, read_only) 904 self._AddInterfaceAttribute(attribute, html_name, read_only)
903 return 905 return
904 906
905 # If the attribute is shadowing, we can't generate a shadowing 907 # If the attribute is shadowing, we can't generate a shadowing
906 # field (Issue 1633). 908 # field (Issue 1633).
907 # TODO(sra): _FindShadowedAttribute does not take into account the html 909 # TODO(sra): _FindShadowedAttribute does not take into account the html
908 # renaming. we should be looking for another attribute that has the same 910 # renaming. we should be looking for another attribute that has the same
909 # html_name. Two attributes with the same IDL name might not match if one 911 # html_name. Two attributes with the same IDL name might not match if one
910 # is renamed. 912 # is renamed.
911 (super_attribute, super_attribute_interface) = self._FindShadowedAttribute( 913 (super_attribute, super_attribute_interface) = self._FindShadowedAttribute(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 return True 1063 return True
1062 1064
1063 def EmitOperation(self, info, html_name, dart_js_interop=False): 1065 def EmitOperation(self, info, html_name, dart_js_interop=False):
1064 """ 1066 """
1065 Arguments: 1067 Arguments:
1066 info: An OperationInfo object. 1068 info: An OperationInfo object.
1067 """ 1069 """
1068 if self._HasCustomImplementation(info.name): 1070 if self._HasCustomImplementation(info.name):
1069 return 1071 return
1070 1072
1071 if IsPureInterface(self._interface.id): 1073 if IsPureInterface(self._interface.id, self._database):
1072 self._AddInterfaceOperation(info, html_name) 1074 self._AddInterfaceOperation(info, html_name)
1073 elif info.callback_args: 1075 elif info.callback_args:
1074 self._AddFutureifiedOperation(info, html_name) 1076 self._AddFutureifiedOperation(info, html_name)
1075 elif any(self._OperationRequiresConversions(op) for op in info.overloads): 1077 elif any(self._OperationRequiresConversions(op) for op in info.overloads):
1076 # Any conversions needed? 1078 # Any conversions needed?
1077 self._AddOperationWithConversions(info, html_name) 1079 self._AddOperationWithConversions(info, html_name)
1078 else: 1080 else:
1079 self._AddDirectNativeOperation(info, html_name) 1081 self._AddDirectNativeOperation(info, html_name)
1080 1082
1081 def _AddDirectNativeOperation(self, info, html_name): 1083 def _AddDirectNativeOperation(self, info, html_name):
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 return '' 1197 return ''
1196 1198
1197 def _Metadata(self, idl_type, idl_member_name, dart_type, indent=' '): 1199 def _Metadata(self, idl_type, idl_member_name, dart_type, indent=' '):
1198 anns = self._metadata.GetDart2JSMetadata( 1200 anns = self._metadata.GetDart2JSMetadata(
1199 idl_type, self._library_name, self._interface, idl_member_name) 1201 idl_type, self._library_name, self._interface, idl_member_name)
1200 1202
1201 if not self._metadata.AnyConversionAnnotations( 1203 if not self._metadata.AnyConversionAnnotations(
1202 idl_type, self._interface.id, idl_member_name): 1204 idl_type, self._interface.id, idl_member_name):
1203 return_type = self.SecureOutputType(idl_type) 1205 return_type = self.SecureOutputType(idl_type)
1204 native_type = self._NarrowToImplementationType(idl_type) 1206 native_type = self._NarrowToImplementationType(idl_type)
1207
1205 if native_type != return_type: 1208 if native_type != return_type:
1206 anns = anns + [ 1209 anns = anns + [
1207 "@Returns('%s')" % native_type, 1210 "@Returns('%s')" % native_type,
1208 "@Creates('%s')" % native_type, 1211 "@Creates('%s')" % native_type,
1209 ] 1212 ]
1210 if dart_type == 'dynamic' or dart_type == 'Object': 1213 if dart_type == 'dynamic' or dart_type == 'Object':
1211 def js_type_annotation(ann): 1214 def js_type_annotation(ann):
1212 return re.search('^@.*Returns', ann) or re.search('^@.*Creates', ann) 1215 return re.search('^@.*Returns', ann) or re.search('^@.*Creates', ann)
1213 if not filter(js_type_annotation, anns): 1216 if not filter(js_type_annotation, anns):
1214 _logger.warn('Member with wildcard native type: %s.%s' % 1217 _logger.warn('Member with wildcard native type: %s.%s' %
1215 (self._interface.id, idl_member_name)) 1218 (self._interface.id, idl_member_name))
1216 1219
1217 return self._metadata.FormatMetadata(anns, indent); 1220 return self._metadata.FormatMetadata(anns, indent);
1218 1221
1219 def CustomJSMembers(self): 1222 def CustomJSMembers(self):
1220 return _js_custom_members 1223 return _js_custom_members
1221 1224
1222 def _FindShadowedAttribute(self, attr): 1225 def _FindShadowedAttribute(self, attr):
1223 """Returns (attribute, superinterface) or (None, None).""" 1226 """Returns (attribute, superinterface) or (None, None)."""
1224 def FindInParent(interface): 1227 def FindInParent(interface):
1225 """Returns matching attribute in parent, or None.""" 1228 """Returns matching attribute in parent, or None."""
1226 if interface.parents: 1229 if interface.parents:
1227 parent = interface.parents[0] 1230 parent = interface.parents[0]
1228 if IsDartCollectionType(parent.type.id): 1231 if IsDartCollectionType(parent.type.id):
1229 return (None, None) 1232 return (None, None)
1230 if IsPureInterface(parent.type.id): 1233 if IsPureInterface(parent.type.id, self._database):
1231 return (None, None) 1234 return (None, None)
1232 if self._database.HasInterface(parent.type.id): 1235 if self._database.HasInterface(parent.type.id):
1233 interfaces_to_search_in = [] 1236 interfaces_to_search_in = []
1234 parent_interface_name = parent.type.id 1237 parent_interface_name = parent.type.id
1235 interfaces_to_search_in.append(parent_interface_name) 1238 interfaces_to_search_in.append(parent_interface_name)
1236 parent_type_info = self._type_registry.TypeInfo(parent_interface_name) 1239 parent_type_info = self._type_registry.TypeInfo(parent_interface_name)
1237 if parent_type_info.merged_into(): 1240 if parent_type_info.merged_into():
1238 # IDL parent was merged into another interface, which became a 1241 # IDL parent was merged into another interface, which became a
1239 # parent interface in Dart. 1242 # parent interface in Dart.
1240 parent_interface_name = parent_type_info.merged_into() 1243 parent_interface_name = parent_type_info.merged_into()
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1344
1342 def AddFile(self, basename, library_name, path): 1345 def AddFile(self, basename, library_name, path):
1343 self._libraries[library_name].AddFile(path) 1346 self._libraries[library_name].AddFile(path)
1344 1347
1345 def AddTypeEntry(self, library_name, idl_name, dart_name): 1348 def AddTypeEntry(self, library_name, idl_name, dart_name):
1346 self._libraries[library_name].AddTypeEntry(idl_name, dart_name) 1349 self._libraries[library_name].AddTypeEntry(idl_name, dart_name)
1347 1350
1348 def Emit(self, emitter, auxiliary_dir): 1351 def Emit(self, emitter, auxiliary_dir):
1349 for lib in self._libraries.values(): 1352 for lib in self._libraries.values():
1350 lib.Emit(emitter, auxiliary_dir) 1353 lib.Emit(emitter, auxiliary_dir)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698