| 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 | 10 |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 DOMNAME=self._interface.doc_js_name) | 880 DOMNAME=self._interface.doc_js_name) |
| 881 | 881 |
| 882 for constructor_info in constructors: | 882 for constructor_info in constructors: |
| 883 self._members_emitter.Emit( | 883 self._members_emitter.Emit( |
| 884 '\n' | 884 '\n' |
| 885 ' $CTOR($PARAMS);\n', | 885 ' $CTOR($PARAMS);\n', |
| 886 CTOR=self._shared.DartType(constructor_info.ConstructorFullName()), | 886 CTOR=self._shared.DartType(constructor_info.ConstructorFullName()), |
| 887 PARAMS=constructor_info.ParametersInterfaceDeclaration( | 887 PARAMS=constructor_info.ParametersInterfaceDeclaration( |
| 888 self._shared.DartType)); | 888 self._shared.DartType)); |
| 889 | 889 |
| 890 if infos: |
| 891 EmitHtmlElementFactoryConstructors( |
| 892 self._system._backend._EmitterForFactoryProviderBody( |
| 893 infos[0].factory_provider_name), |
| 894 infos, |
| 895 self._html_interface_name, |
| 896 self._backend.ImplementationClassName()) |
| 897 |
| 890 element_type = MaybeTypedArrayElementTypeInHierarchy( | 898 element_type = MaybeTypedArrayElementTypeInHierarchy( |
| 891 self._interface, self._system._database) | 899 self._interface, self._system._database) |
| 892 if element_type: | 900 if element_type: |
| 893 self._members_emitter.Emit( | 901 self._members_emitter.Emit( |
| 894 '\n' | 902 '\n' |
| 895 ' $CTOR(int length);\n' | 903 ' $CTOR(int length);\n' |
| 896 '\n' | 904 '\n' |
| 897 ' $CTOR.fromList(List<$TYPE> list);\n' | 905 ' $CTOR.fromList(List<$TYPE> list);\n' |
| 898 '\n' | 906 '\n' |
| 899 ' $CTOR.fromBuffer(ArrayBuffer buffer,' | 907 ' $CTOR.fromBuffer(ArrayBuffer buffer,' |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 super(HtmlFrogClassGenerator, self).__init__( | 1036 super(HtmlFrogClassGenerator, self).__init__( |
| 1029 system, interface, None, None) | 1037 system, interface, None, None) |
| 1030 self._shared = self._system._shared | 1038 self._shared = self._system._shared |
| 1031 self._html_interface_name = self._shared._HTMLInterfaceName( | 1039 self._html_interface_name = self._shared._HTMLInterfaceName( |
| 1032 self._interface.id) | 1040 self._interface.id) |
| 1033 | 1041 |
| 1034 def HasImplementation(self): | 1042 def HasImplementation(self): |
| 1035 return not (IsPureInterface(self._interface.id) or | 1043 return not (IsPureInterface(self._interface.id) or |
| 1036 self._interface.id in _merged_html_interfaces) | 1044 self._interface.id in _merged_html_interfaces) |
| 1037 | 1045 |
| 1046 def ImplementationClassName(self): |
| 1047 return self._ImplClassName(self._html_interface_name) |
| 1048 |
| 1038 def FilePathForDartImplementation(self): | 1049 def FilePathForDartImplementation(self): |
| 1039 return os.path.join(self._system._output_dir, 'html', 'frog', | 1050 return os.path.join(self._system._output_dir, 'html', 'frog', |
| 1040 '%s.dart' % self._html_interface_name) | 1051 '%s.dart' % self._html_interface_name) |
| 1041 | 1052 |
| 1042 def SetImplementationEmitter(self, implementation_emitter): | 1053 def SetImplementationEmitter(self, implementation_emitter): |
| 1043 self._dart_code = implementation_emitter | 1054 self._dart_code = implementation_emitter |
| 1044 | 1055 |
| 1045 def _ImplClassName(self, type_name): | 1056 def _ImplClassName(self, type_name): |
| 1046 return self._shared._ImplClassName(type_name) | 1057 return self._shared._ImplClassName(type_name) |
| 1047 | 1058 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 NATIVESPEC=' native "' + native_spec + '"') | 1103 NATIVESPEC=' native "' + native_spec + '"') |
| 1093 if self._members_emitter == None: | 1104 if self._members_emitter == None: |
| 1094 raise Exception("Class %s doesn't use the $!MEMBERS variable" % | 1105 raise Exception("Class %s doesn't use the $!MEMBERS variable" % |
| 1095 self._class_name) | 1106 self._class_name) |
| 1096 | 1107 |
| 1097 # Emit a factory provider class for the constructor. | 1108 # Emit a factory provider class for the constructor. |
| 1098 constructor_info = AnalyzeConstructor(interface) | 1109 constructor_info = AnalyzeConstructor(interface) |
| 1099 if constructor_info: | 1110 if constructor_info: |
| 1100 self._EmitFactoryProvider(constructor_info) | 1111 self._EmitFactoryProvider(constructor_info) |
| 1101 | 1112 |
| 1102 infos = HtmlElementConstructorInfos(self._html_interface_name) | |
| 1103 if infos: | |
| 1104 self._EmitHtmlElementFactoryConstructors(infos) | |
| 1105 | |
| 1106 emit_events, events = self._shared.GetEventAttributes(self._interface) | 1113 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 1107 if not emit_events: | 1114 if not emit_events: |
| 1108 return | 1115 return |
| 1109 elif events: | 1116 elif events: |
| 1110 self.AddEventAttributes(events) | 1117 self.AddEventAttributes(events) |
| 1111 else: | 1118 else: |
| 1112 parent_events_class = self._shared.GetParentEventsClass(self._interface) | 1119 parent_events_class = self._shared.GetParentEventsClass(self._interface) |
| 1113 self._EmitEventGetter('_' + parent_events_class + 'Impl') | 1120 self._EmitEventGetter('_' + parent_events_class + 'Impl') |
| 1114 | 1121 |
| 1115 for merged_interface in _merged_html_interfaces: | 1122 for merged_interface in _merged_html_interfaces: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1126 factory_provider = '_' + self._html_interface_name + 'FactoryProvider' | 1133 factory_provider = '_' + self._html_interface_name + 'FactoryProvider' |
| 1127 emitter = self._system._ImplFileEmitter(factory_provider) | 1134 emitter = self._system._ImplFileEmitter(factory_provider) |
| 1128 emitter.Emit( | 1135 emitter.Emit( |
| 1129 template, | 1136 template, |
| 1130 FACTORYPROVIDER=factory_provider, | 1137 FACTORYPROVIDER=factory_provider, |
| 1131 CONSTRUCTOR=self._html_interface_name, | 1138 CONSTRUCTOR=self._html_interface_name, |
| 1132 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), | 1139 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), |
| 1133 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, | 1140 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, |
| 1134 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 1141 ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
| 1135 | 1142 |
| 1136 def _EmitHtmlElementFactoryConstructors(self, infos): | |
| 1137 EmitHtmlElementFactoryConstructors( | |
| 1138 self._system._EmitterForFactoryProviderBody( | |
| 1139 infos[0].factory_provider_name), | |
| 1140 infos, | |
| 1141 self._html_interface_name, self._class_name) | |
| 1142 | |
| 1143 def AddIndexer(self, element_type): | 1143 def AddIndexer(self, element_type): |
| 1144 """Adds all the methods required to complete implementation of List.""" | 1144 """Adds all the methods required to complete implementation of List.""" |
| 1145 # We would like to simply inherit the implementation of everything except | 1145 # We would like to simply inherit the implementation of everything except |
| 1146 # get length(), [], and maybe []=. It is possible to extend from a base | 1146 # get length(), [], and maybe []=. It is possible to extend from a base |
| 1147 # array implementation class only when there is no other implementation | 1147 # array implementation class only when there is no other implementation |
| 1148 # inheritance. There might be no implementation inheritance other than | 1148 # inheritance. There might be no implementation inheritance other than |
| 1149 # DOMBaseWrapper for many classes, but there might be some where the | 1149 # DOMBaseWrapper for many classes, but there might be some where the |
| 1150 # array-ness is introduced by a non-root interface: | 1150 # array-ness is introduced by a non-root interface: |
| 1151 # | 1151 # |
| 1152 # interface Y extends X, List<T> ... | 1152 # interface Y extends X, List<T> ... |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 Collect(database.GetInterface(parent.type.id), | 1410 Collect(database.GetInterface(parent.type.id), |
| 1411 seen, collected) | 1411 seen, collected) |
| 1412 | 1412 |
| 1413 inheritance_closure = {} | 1413 inheritance_closure = {} |
| 1414 for interface in database.GetInterfaces(): | 1414 for interface in database.GetInterfaces(): |
| 1415 seen = set() | 1415 seen = set() |
| 1416 collected = [] | 1416 collected = [] |
| 1417 Collect(interface, seen, collected) | 1417 Collect(interface, seen, collected) |
| 1418 inheritance_closure[interface.id] = collected | 1418 inheritance_closure[interface.id] = collected |
| 1419 return inheritance_closure | 1419 return inheritance_closure |
| OLD | NEW |