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

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

Issue 10700006: Make per-interface generators an implementation detail of a system. (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 | « lib/dom/scripts/systeminterface.py ('k') | no next file » | 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 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 import systembase 11 import systembase
12 from generator import * 12 from generator import *
13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared
14 from systemhtml import HtmlElementConstructorInfos 14 from systemhtml import HtmlElementConstructorInfos
15 from systemhtml import EmitHtmlElementFactoryConstructors 15 from systemhtml import EmitHtmlElementFactoryConstructors
16 16
17 class NativeImplementationSystem(systembase.System): 17 class NativeImplementationSystem(systembase.System):
18 18
19 def __init__(self, templates, database, emitters, output_dir): 19 def __init__(self, templates, database, emitters, output_dir):
20 super(NativeImplementationSystem, self).__init__( 20 super(NativeImplementationSystem, self).__init__(
21 templates, database, emitters, output_dir) 21 templates, database, emitters, output_dir)
22 22
23 self._dom_impl_files = [] 23 self._dom_impl_files = []
24 self._cpp_header_files = [] 24 self._cpp_header_files = []
25 self._cpp_impl_files = [] 25 self._cpp_impl_files = []
26 self._html_system = HtmlSystemShared(database) 26 self._html_system = HtmlSystemShared(database)
27 self._factory_provider_emitters = {} 27 self._factory_provider_emitters = {}
28 28
29 def InterfaceGenerator(self, 29 def ProcessInterface(self, interface):
30 interface,
31 common_prefix,
32 super_interface_name,
33 source_filter):
34 interface_name = interface.id 30 interface_name = interface.id
35 31
36 if IsPureInterface(interface_name): 32 if IsPureInterface(interface_name):
37 return None 33 return None
38 34
39 dart_impl_path = self._FilePathForDartImplementation(interface_name) 35 dart_impl_path = self._FilePathForDartImplementation(interface_name)
40 self._dom_impl_files.append(dart_impl_path) 36 self._dom_impl_files.append(dart_impl_path)
41 37
42 cpp_header_path = self._FilePathForCppHeader(interface_name) 38 cpp_header_path = self._FilePathForCppHeader(interface_name)
43 self._cpp_header_files.append(cpp_header_path) 39 self._cpp_header_files.append(cpp_header_path)
44 40
45 cpp_impl_path = self._FilePathForCppImplementation(interface_name) 41 cpp_impl_path = self._FilePathForCppImplementation(interface_name)
46 self._cpp_impl_files.append(cpp_impl_path) 42 self._cpp_impl_files.append(cpp_impl_path)
47 43
48 return NativeImplementationGenerator(self, interface, 44 NativeImplementationGenerator(self, interface,
49 self._emitters.FileEmitter(dart_impl_path), 45 self._emitters.FileEmitter(dart_impl_path),
50 self._emitters.FileEmitter(cpp_header_path), 46 self._emitters.FileEmitter(cpp_header_path),
51 self._emitters.FileEmitter(cpp_impl_path), 47 self._emitters.FileEmitter(cpp_impl_path),
52 self._BaseDefines(interface), 48 self._BaseDefines(interface),
53 self._templates) 49 self._templates).Generate()
54 50
55 def ProcessCallback(self, interface, info): 51 def ProcessCallback(self, interface, info):
56 self._interface = interface 52 self._interface = interface
57 53
58 if IsPureInterface(self._interface.id): 54 if IsPureInterface(self._interface.id):
59 return None 55 return None
60 56
61 cpp_impl_includes = set() 57 cpp_impl_includes = set()
62 cpp_header_handlers_emitter = emitter.Emitter() 58 cpp_header_handlers_emitter = emitter.Emitter()
63 cpp_impl_handlers_emitter = emitter.Emitter() 59 cpp_impl_handlers_emitter = emitter.Emitter()
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 been converted to Dart types (e.g. int, String), unless they are in 200 been converted to Dart types (e.g. int, String), unless they are in
205 the same package as the interface. 201 the same package as the interface.
206 dart_impl_emitter: an Emitter for the file containing the Dart 202 dart_impl_emitter: an Emitter for the file containing the Dart
207 implementation class. 203 implementation class.
208 cpp_header_emitter: an Emitter for the file containing the C++ header. 204 cpp_header_emitter: an Emitter for the file containing the C++ header.
209 cpp_impl_emitter: an Emitter for the file containing the C++ 205 cpp_impl_emitter: an Emitter for the file containing the C++
210 implementation. 206 implementation.
211 base_members: a set of names of members defined in a base class. This is 207 base_members: a set of names of members defined in a base class. This is
212 used to avoid static member 'overriding' in the generated Dart code. 208 used to avoid static member 'overriding' in the generated Dart code.
213 """ 209 """
214 super(NativeImplementationGenerator, self).__init__(system._database) 210 super(NativeImplementationGenerator, self).__init__(
211 system._database, interface)
215 self._system = system 212 self._system = system
216 self._interface = interface
217 self._dart_impl_emitter = dart_impl_emitter 213 self._dart_impl_emitter = dart_impl_emitter
218 self._cpp_header_emitter = cpp_header_emitter 214 self._cpp_header_emitter = cpp_header_emitter
219 self._cpp_impl_emitter = cpp_impl_emitter 215 self._cpp_impl_emitter = cpp_impl_emitter
220 self._base_members = base_members 216 self._base_members = base_members
221 self._templates = templates 217 self._templates = templates
222 self._current_secondary_parent = None 218 self._current_secondary_parent = None
223 self._html_system = self._system._html_system 219 self._html_system = self._system._html_system
224 self._html_renames = self._html_system._html_renames 220 self._html_renames = self._html_system._html_renames
225 221
226 def StartInterface(self): 222 def StartInterface(self):
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 for (i, argument) in enumerate(constructor_info.idl_args): 295 for (i, argument) in enumerate(constructor_info.idl_args):
300 argument_expression = self._GenerateToNative( 296 argument_expression = self._GenerateToNative(
301 parameter_definitions_emitter, argument, i) 297 parameter_definitions_emitter, argument, i)
302 arguments.append(argument_expression) 298 arguments.append(argument_expression)
303 299
304 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 300 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
305 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 301 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
306 self._interface.id, ext_attrs, raises_dom_exceptions) 302 self._interface.id, ext_attrs, raises_dom_exceptions)
307 303
308 runtime_check = None 304 runtime_check = None
309 database = self._system._database 305 database = self._database
310 assert (not ( 306 assert (not (
311 'synthesizedV8EnabledPerContext' in ext_attrs and 307 'synthesizedV8EnabledPerContext' in ext_attrs and
312 'synthesizedV8EnabledAtRuntime' in ext_attrs)) 308 'synthesizedV8EnabledAtRuntime' in ext_attrs))
313 if 'synthesizedV8EnabledPerContext' in ext_attrs: 309 if 'synthesizedV8EnabledPerContext' in ext_attrs:
314 raises_exceptions = True 310 raises_exceptions = True
315 self._cpp_impl_includes.add('"ContextFeatures.h"') 311 self._cpp_impl_includes.add('"ContextFeatures.h"')
316 runtime_check = emitter.Format( 312 runtime_check = emitter.Format(
317 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n' 313 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin dowForCurrentIsolate()->document())) {\n'
318 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n' 314 ' exception = Dart_NewString("Feature $FEATURE is not enabl ed");\n'
319 ' goto fail;\n' 315 ' goto fail;\n'
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 return 348 return
353 349
354 events_attributes = [attr for attr in self._interface.attributes 350 events_attributes = [attr for attr in self._interface.attributes
355 if attr.type.id == 'EventListener'] 351 if attr.type.id == 'EventListener']
356 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: 352 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
357 return 353 return
358 354
359 def IsEventTarget(interface): 355 def IsEventTarget(interface):
360 return ('EventTarget' in interface.ext_attrs and 356 return ('EventTarget' in interface.ext_attrs and
361 interface.id != 'EventTarget') 357 interface.id != 'EventTarget')
362 is_root = not _FindParent(self._interface, self._system._database, IsEventTa rget) 358 is_root = not _FindParent(self._interface, self._database, IsEventTarget)
363 if is_root: 359 if is_root:
364 self._members_emitter.Emit(' _EventsImpl _on;\n') 360 self._members_emitter.Emit(' _EventsImpl _on;\n')
365 361
366 if not events_attributes: 362 if not events_attributes:
367 if is_root: 363 if is_root:
368 self._EmitEventGetter('_EventsImpl') 364 self._EmitEventGetter('_EventsImpl')
369 return 365 return
370 366
371 events_class = '_%sEventsImpl' % self._interface.id 367 events_class = '_%sEventsImpl' % self._interface.id
372 self._EmitEventGetter(events_class) 368 self._EmitEventGetter(events_class)
373 369
374 def HasEventAttributes(interface): 370 def HasEventAttributes(interface):
375 return any([a.type.id == 'EventListener' for a in interface.attributes]) 371 return any([a.type.id == 'EventListener' for a in interface.attributes])
376 parent = _FindParent(self._interface, self._system._database, HasEventAttrib utes) 372 parent = _FindParent(self._interface, self._database, HasEventAttributes)
377 if parent: 373 if parent:
378 parent_events_class = '_%sEventsImpl' % parent.id 374 parent_events_class = '_%sEventsImpl' % parent.id
379 else: 375 else:
380 parent_events_class = '_EventsImpl' 376 parent_events_class = '_EventsImpl'
381 377
382 html_inteface = self._HTMLInterfaceName(self._interface.id) 378 html_inteface = self._HTMLInterfaceName(self._interface.id)
383 events_members = self._dart_impl_emitter.Emit( 379 events_members = self._dart_impl_emitter.Emit(
384 '\n' 380 '\n'
385 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n' 381 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n'
386 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n' 382 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n'
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 template, 461 template,
466 FACTORYPROVIDER='_%sFactoryProvider' % html_interface_name, 462 FACTORYPROVIDER='_%sFactoryProvider' % html_interface_name,
467 INTERFACE=html_interface_name, 463 INTERFACE=html_interface_name,
468 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType), 464 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da rtType),
469 ARGUMENTS=constructor_info.ParametersAsArgumentList(), 465 ARGUMENTS=constructor_info.ParametersAsArgumentList(),
470 NATIVE_NAME=native_implementation_function) 466 NATIVE_NAME=native_implementation_function)
471 467
472 def FinishInterface(self): 468 def FinishInterface(self):
473 html_interface_name = self._HTMLInterfaceName(self._interface.id) 469 html_interface_name = self._HTMLInterfaceName(self._interface.id)
474 template = None 470 template = None
475 if html_interface_name == self._interface.id or not self._system._database.H asInterface(html_interface_name): 471 if html_interface_name == self._interface.id or not self._database.HasInterf ace(html_interface_name):
476 template_file = 'impl_%s.darttemplate' % html_interface_name 472 template_file = 'impl_%s.darttemplate' % html_interface_name
477 template = self._templates.TryLoad(template_file) 473 template = self._templates.TryLoad(template_file)
478 if not template: 474 if not template:
479 template = self._templates.Load('dart_implementation.darttemplate') 475 template = self._templates.Load('dart_implementation.darttemplate')
480 476
481 class_name = self._ImplClassName(self._interface.id) 477 class_name = self._ImplClassName(self._interface.id)
482 members_emitter = self._dart_impl_emitter.Emit( 478 members_emitter = self._dart_impl_emitter.Emit(
483 template, 479 template,
484 CLASSNAME=class_name, 480 CLASSNAME=class_name,
485 EXTENDS=' extends ' + self._BaseClassName(), 481 EXTENDS=' extends ' + self._BaseClassName(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 ' static Dart_Handle toDart(NativeType* value);\n') 516 ' static Dart_Handle toDart(NativeType* value);\n')
521 else: 517 else:
522 to_dart_emitter.Emit( 518 to_dart_emitter.Emit(
523 ' static Dart_Handle toDart(NativeType* value)\n' 519 ' static Dart_Handle toDart(NativeType* value)\n'
524 ' {\n' 520 ' {\n'
525 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 521 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n'
526 ' }\n', 522 ' }\n',
527 INTERFACE=self._interface.id) 523 INTERFACE=self._interface.id)
528 524
529 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes()) 525 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes())
530 wrapper_type = _DOMWrapperType(self._system._database, self._interface) 526 wrapper_type = _DOMWrapperType(self._database, self._interface)
531 self._cpp_header_emitter.Emit( 527 self._cpp_header_emitter.Emit(
532 self._templates.Load('cpp_header.template'), 528 self._templates.Load('cpp_header.template'),
533 INTERFACE=self._interface.id, 529 INTERFACE=self._interface.id,
534 WEBCORE_INCLUDES=webcore_includes, 530 WEBCORE_INCLUDES=webcore_includes,
535 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 531 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
536 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), 532 DECLARATIONS=self._cpp_declarations_emitter.Fragments(),
537 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type, 533 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type,
538 TO_NATIVE=to_native_emitter.Fragments(), 534 TO_NATIVE=to_native_emitter.Fragments(),
539 TO_DART=to_dart_emitter.Fragments()) 535 TO_DART=to_dart_emitter.Fragments())
540 536
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1085
1090 def _IsArgumentOptionalInWebCore(argument): 1086 def _IsArgumentOptionalInWebCore(argument):
1091 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 1087 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
1092 1088
1093 def _ToWebKitName(name): 1089 def _ToWebKitName(name):
1094 name = name[0].lower() + name[1:] 1090 name = name[0].lower() + name[1:]
1095 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 1091 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
1096 name) 1092 name)
1097 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 1093 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
1098 name) 1094 name)
OLDNEW
« no previous file with comments | « lib/dom/scripts/systeminterface.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698