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

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

Issue 10451105: Revert "Rework Element constructors" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
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 systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
11 from generator import * 11 from generator import *
12 from systembase import * 12 from systembase import *
13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared
14 from systemhtml import HtmlElementConstructorInfos
15 from systemhtml import EmitHtmlElementFactoryConstructors
16 14
17 class NativeImplementationSystem(System): 15 class NativeImplementationSystem(System):
18 16
19 def __init__(self, templates, database, html_database, html_renames, 17 def __init__(self, templates, database, html_database, html_renames,
20 emitters, output_dir): 18 emitters, output_dir):
21 super(NativeImplementationSystem, self).__init__( 19 super(NativeImplementationSystem, self).__init__(
22 templates, database, emitters, output_dir) 20 templates, database, emitters, output_dir)
23 21
24 self._html_renames = html_renames 22 self._html_renames = html_renames
25 self._dom_impl_files = [] 23 self._dom_impl_files = []
26 self._cpp_header_files = [] 24 self._cpp_header_files = []
27 self._cpp_impl_files = [] 25 self._cpp_impl_files = []
28 self._html_system = HtmlSystemShared(html_database) 26 self._html_system = HtmlSystemShared(html_database)
29 self._factory_provider_emitters = {}
30 27
31 def InterfaceGenerator(self, 28 def InterfaceGenerator(self,
32 interface, 29 interface,
33 common_prefix, 30 common_prefix,
34 super_interface_name, 31 super_interface_name,
35 source_filter): 32 source_filter):
36 interface_name = interface.id 33 interface_name = interface.id
37 34
38 if IsPureInterface(interface_name): 35 if IsPureInterface(interface_name):
39 return None 36 return None
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 def _FilePathForDartFactoryProviderImplementation(self, interface_name): 169 def _FilePathForDartFactoryProviderImplementation(self, interface_name):
173 return os.path.join(self._output_dir, 'dart', 170 return os.path.join(self._output_dir, 'dart',
174 '%sFactoryProviderImplementation.dart' % interface_name) 171 '%sFactoryProviderImplementation.dart' % interface_name)
175 172
176 def _FilePathForCppHeader(self, interface_name): 173 def _FilePathForCppHeader(self, interface_name):
177 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name) 174 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name)
178 175
179 def _FilePathForCppImplementation(self, interface_name): 176 def _FilePathForCppImplementation(self, interface_name):
180 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name) 177 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name)
181 178
182 def _EmitterForFactoryProviderBody(self, name):
183 if name not in self._factory_provider_emitters:
184 file_name = self._FilePathForDartFactoryProviderImplementation(name)
185 self._dom_impl_files.append(file_name)
186 template = self._templates.Load('factoryprovider_%s.darttemplate' % name)
187 file_emitter = self._emitters.FileEmitter(file_name)
188 self._factory_provider_emitters[name] = file_emitter.Emit(template)
189 return self._factory_provider_emitters[name]
190
191 def DartImplementationFiles(self): 179 def DartImplementationFiles(self):
192 return self._dom_impl_files 180 return self._dom_impl_files
193 181
194 182
195 class NativeImplementationGenerator(object): 183 class NativeImplementationGenerator(object):
196 """Generates Dart implementation for one DOM IDL interface.""" 184 """Generates Dart implementation for one DOM IDL interface."""
197 185
198 def __init__(self, system, interface, 186 def __init__(self, system, interface,
199 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter, 187 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter,
200 base_members, templates): 188 base_members, templates):
(...skipping 27 matching lines...) Expand all
228 self._members_emitter = emitter.Emitter() 216 self._members_emitter = emitter.Emitter()
229 self._cpp_declarations_emitter = emitter.Emitter() 217 self._cpp_declarations_emitter = emitter.Emitter()
230 self._cpp_impl_includes = set() 218 self._cpp_impl_includes = set()
231 self._cpp_definitions_emitter = emitter.Emitter() 219 self._cpp_definitions_emitter = emitter.Emitter()
232 self._cpp_resolver_emitter = emitter.Emitter() 220 self._cpp_resolver_emitter = emitter.Emitter()
233 221
234 self._GenerateConstructors() 222 self._GenerateConstructors()
235 self._GenerateEvents() 223 self._GenerateEvents()
236 224
237 def _GenerateConstructors(self): 225 def _GenerateConstructors(self):
238 html_interface_name = self._HTMLInterfaceName(self._interface.id)
239 infos = HtmlElementConstructorInfos(html_interface_name)
240 if infos:
241 self._EmitHtmlElementFactoryConstructors(infos, html_interface_name)
242
243 if not self._IsConstructable(): 226 if not self._IsConstructable():
244 return 227 return
245 228
246 # TODO(antonm): currently we don't have information about number of argument s expected by 229 # TODO(antonm): currently we don't have information about number of argument s expected by
247 # the constructor, so name only dispatch. 230 # the constructor, so name only dispatch.
248 self._cpp_resolver_emitter.Emit( 231 self._cpp_resolver_emitter.Emit(
249 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' 232 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
250 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', 233 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
251 INTERFACE_NAME=self._interface.id) 234 INTERFACE_NAME=self._interface.id)
252 235
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 arguments.append(argument_expression) 283 arguments.append(argument_expression)
301 284
302 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 285 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
303 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 286 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
304 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 287 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
305 self._GenerateNativeCallback(callback_name='constructorCallback', 288 self._GenerateNativeCallback(callback_name='constructorCallback',
306 parameter_definitions=parameter_definitions_emitter.Fragments(), 289 parameter_definitions=parameter_definitions_emitter.Fragments(),
307 needs_receiver=False, invocation=invocation, 290 needs_receiver=False, invocation=invocation,
308 raises_exceptions=raises_exceptions) 291 raises_exceptions=raises_exceptions)
309 292
310 def _EmitHtmlElementFactoryConstructors(self, infos, html_interface_name):
311 EmitHtmlElementFactoryConstructors(
312 self._system._EmitterForFactoryProviderBody(
313 infos[0].factory_provider_name),
314 infos,
315 html_interface_name,
316 html_interface_name)
317
318 def _GenerateEvents(self): 293 def _GenerateEvents(self):
319 if self._interface.id == 'DocumentFragment': 294 if self._interface.id == 'DocumentFragment':
320 # Interface DocumentFragment extends Element in dart:html but this fact 295 # Interface DocumentFragment extends Element in dart:html but this fact
321 # is not reflected in idls. 296 # is not reflected in idls.
322 self._EmitEventGetter('_ElementEventsImpl') 297 self._EmitEventGetter('_ElementEventsImpl')
323 return 298 return
324 299
325 events_attributes = [attr for attr in self._interface.attributes 300 events_attributes = [attr for attr in self._interface.attributes
326 if attr.type.id == 'EventListener'] 301 if attr.type.id == 'EventListener']
327 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: 302 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 for parent in interface.parents: 1169 for parent in interface.parents:
1195 parent_name = parent.type.id 1170 parent_name = parent.type.id
1196 if not database.HasInterface(parent.type.id): 1171 if not database.HasInterface(parent.type.id):
1197 continue 1172 continue
1198 parent_interface = database.GetInterface(parent.type.id) 1173 parent_interface = database.GetInterface(parent.type.id)
1199 if callback(parent_interface): 1174 if callback(parent_interface):
1200 return parent_interface 1175 return parent_interface
1201 parent_interface = _FindParent(parent_interface, database, callback) 1176 parent_interface = _FindParent(parent_interface, database, callback)
1202 if parent_interface: 1177 if parent_interface:
1203 return parent_interface 1178 return parent_interface
OLDNEW
« no previous file with comments | « lib/dom/scripts/systemhtml.py ('k') | lib/dom/templates/html/dartium/factoryprovider__Elements.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698