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

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

Issue 10696035: Extract common logic for element factory constructors generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 | « no previous file | lib/dom/scripts/systemnative.py » ('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 10
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 DOMNAME=self._interface.doc_js_name) 903 DOMNAME=self._interface.doc_js_name)
904 904
905 for constructor_info in constructors: 905 for constructor_info in constructors:
906 self._members_emitter.Emit( 906 self._members_emitter.Emit(
907 '\n' 907 '\n'
908 ' $CTOR($PARAMS);\n', 908 ' $CTOR($PARAMS);\n',
909 CTOR=self._shared.DartType(constructor_info.ConstructorFullName()), 909 CTOR=self._shared.DartType(constructor_info.ConstructorFullName()),
910 PARAMS=constructor_info.ParametersInterfaceDeclaration( 910 PARAMS=constructor_info.ParametersInterfaceDeclaration(
911 self._shared.DartType)); 911 self._shared.DartType));
912 912
913 if infos:
914 EmitHtmlElementFactoryConstructors(
915 self._system._backend._EmitterForFactoryProviderBody(
916 infos[0].factory_provider_name),
917 infos,
918 self._html_interface_name,
919 self._backend.FactoryConstructorElementClassName())
920
913 element_type = MaybeTypedArrayElementTypeInHierarchy( 921 element_type = MaybeTypedArrayElementTypeInHierarchy(
914 self._interface, self._system._database) 922 self._interface, self._system._database)
915 if element_type: 923 if element_type:
916 self._members_emitter.Emit( 924 self._members_emitter.Emit(
917 '\n' 925 '\n'
918 ' $CTOR(int length);\n' 926 ' $CTOR(int length);\n'
919 '\n' 927 '\n'
920 ' $CTOR.fromList(List<$TYPE> list);\n' 928 ' $CTOR.fromList(List<$TYPE> list);\n'
921 '\n' 929 '\n'
922 ' $CTOR.fromBuffer(ArrayBuffer buffer,' 930 ' $CTOR.fromBuffer(ArrayBuffer buffer,'
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 """ 1048 """
1041 1049
1042 def __init__(self, system, interface, template, dart_code, 1050 def __init__(self, system, interface, template, dart_code,
1043 shared): 1051 shared):
1044 super(HtmlFrogClassGenerator, self).__init__( 1052 super(HtmlFrogClassGenerator, self).__init__(
1045 system, interface, template, dart_code) 1053 system, interface, template, dart_code)
1046 self._shared = shared 1054 self._shared = shared
1047 self._html_interface_name = self._shared._HTMLInterfaceName( 1055 self._html_interface_name = self._shared._HTMLInterfaceName(
1048 self._interface.id) 1056 self._interface.id)
1049 1057
1058 def FactoryConstructorElementClassName(self):
Anton Muhin 2012/06/28 13:24:23 too long chain of nouns and I cannot decipher it,
podivilov 2012/06/29 13:53:39 Previously it was interface name in Dartium and im
1059 return self._ImplClassName(self._html_interface_name)
1060
1050 def _ImplClassName(self, type_name): 1061 def _ImplClassName(self, type_name):
1051 return self._shared._ImplClassName(type_name) 1062 return self._shared._ImplClassName(type_name)
1052 1063
1053 def _NarrowToImplementationType(self, type_name): 1064 def _NarrowToImplementationType(self, type_name):
1054 if self._ShouldNarrowToImplementationType(type_name): 1065 if self._ShouldNarrowToImplementationType(type_name):
1055 return self._ImplClassName(self._shared.DartType(type_name)) 1066 return self._ImplClassName(self._shared.DartType(type_name))
1056 return self._shared.DartType(type_name) 1067 return self._shared.DartType(type_name)
1057 1068
1058 def StartInterface(self): 1069 def StartInterface(self):
1059 interface = self._interface 1070 interface = self._interface
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 NATIVESPEC=' native "' + native_spec + '"') 1105 NATIVESPEC=' native "' + native_spec + '"')
1095 if self._members_emitter == None: 1106 if self._members_emitter == None:
1096 raise Exception("Class %s doesn't use the $!MEMBERS variable" % 1107 raise Exception("Class %s doesn't use the $!MEMBERS variable" %
1097 self._class_name) 1108 self._class_name)
1098 1109
1099 # Emit a factory provider class for the constructor. 1110 # Emit a factory provider class for the constructor.
1100 constructor_info = AnalyzeConstructor(interface) 1111 constructor_info = AnalyzeConstructor(interface)
1101 if constructor_info: 1112 if constructor_info:
1102 self._EmitFactoryProvider(constructor_info) 1113 self._EmitFactoryProvider(constructor_info)
1103 1114
1104 infos = HtmlElementConstructorInfos(self._html_interface_name)
1105 if infos:
1106 self._EmitHtmlElementFactoryConstructors(infos)
1107
1108 emit_events, events = self._shared.GetEventAttributes(self._interface) 1115 emit_events, events = self._shared.GetEventAttributes(self._interface)
1109 if not emit_events: 1116 if not emit_events:
1110 return 1117 return
1111 elif events: 1118 elif events:
1112 self.AddEventAttributes(events) 1119 self.AddEventAttributes(events)
1113 else: 1120 else:
1114 parent_events_class = self._shared.GetParentEventsClass(self._interface) 1121 parent_events_class = self._shared.GetParentEventsClass(self._interface)
1115 self._EmitEventGetter('_' + parent_events_class + 'Impl') 1122 self._EmitEventGetter('_' + parent_events_class + 'Impl')
1116 1123
1117 for merged_interface in _merged_html_interfaces: 1124 for merged_interface in _merged_html_interfaces:
(...skipping 10 matching lines...) Expand all
1128 factory_provider = '_' + self._html_interface_name + 'FactoryProvider' 1135 factory_provider = '_' + self._html_interface_name + 'FactoryProvider'
1129 emitter = self._system._ImplFileEmitter(factory_provider) 1136 emitter = self._system._ImplFileEmitter(factory_provider)
1130 emitter.Emit( 1137 emitter.Emit(
1131 template, 1138 template,
1132 FACTORYPROVIDER=factory_provider, 1139 FACTORYPROVIDER=factory_provider,
1133 CONSTRUCTOR=self._html_interface_name, 1140 CONSTRUCTOR=self._html_interface_name,
1134 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), 1141 PARAMETERS=constructor_info.ParametersImplementationDeclaration(),
1135 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, 1142 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name,
1136 ARGUMENTS=constructor_info.ParametersAsArgumentList()) 1143 ARGUMENTS=constructor_info.ParametersAsArgumentList())
1137 1144
1138 def _EmitHtmlElementFactoryConstructors(self, infos):
1139 EmitHtmlElementFactoryConstructors(
1140 self._system._EmitterForFactoryProviderBody(
1141 infos[0].factory_provider_name),
1142 infos,
1143 self._html_interface_name, self._class_name)
1144
1145 def AddIndexer(self, element_type): 1145 def AddIndexer(self, element_type):
1146 """Adds all the methods required to complete implementation of List.""" 1146 """Adds all the methods required to complete implementation of List."""
1147 # We would like to simply inherit the implementation of everything except 1147 # We would like to simply inherit the implementation of everything except
1148 # get length(), [], and maybe []=. It is possible to extend from a base 1148 # get length(), [], and maybe []=. It is possible to extend from a base
1149 # array implementation class only when there is no other implementation 1149 # array implementation class only when there is no other implementation
1150 # inheritance. There might be no implementation inheritance other than 1150 # inheritance. There might be no implementation inheritance other than
1151 # DOMBaseWrapper for many classes, but there might be some where the 1151 # DOMBaseWrapper for many classes, but there might be some where the
1152 # array-ness is introduced by a non-root interface: 1152 # array-ness is introduced by a non-root interface:
1153 # 1153 #
1154 # interface Y extends X, List<T> ... 1154 # interface Y extends X, List<T> ...
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 Collect(database.GetInterface(parent.type.id), 1421 Collect(database.GetInterface(parent.type.id),
1422 seen, collected) 1422 seen, collected)
1423 1423
1424 inheritance_closure = {} 1424 inheritance_closure = {}
1425 for interface in database.GetInterfaces(): 1425 for interface in database.GetInterfaces():
1426 seen = set() 1426 seen = set()
1427 collected = [] 1427 collected = []
1428 Collect(interface, seen, collected) 1428 Collect(interface, seen, collected)
1429 inheritance_closure[interface.id] = collected 1429 inheritance_closure[interface.id] = collected
1430 return inheritance_closure 1430 return inheritance_closure
OLDNEW
« no previous file with comments | « no previous file | lib/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698