Chromium Code Reviews| Index: lib/dom/scripts/systemhtml.py |
| diff --git a/lib/dom/scripts/systemhtml.py b/lib/dom/scripts/systemhtml.py |
| index 3b3b418885a120c26a454006f90c8ef7ac0d4bcd..1585eed512e9f9922f2f4bdd69caea17d5073773 100644 |
| --- a/lib/dom/scripts/systemhtml.py |
| +++ b/lib/dom/scripts/systemhtml.py |
| @@ -6,6 +6,8 @@ |
| """This module provides shared functionality for the system to generate |
| Dart:html APIs from the IDL database.""" |
| +import emitter |
| + |
| from systemfrog import * |
| from systeminterface import * |
| @@ -775,30 +777,8 @@ class HtmlInterfacesSystem(HtmlSystem): |
| self._factory_provider_emitters = {} |
| def ProcessInterface(self, interface): |
| - """.""" |
| - |
| - self._backend.ProcessInterface(interface) |
| - |
| - if interface.id in _merged_html_interfaces: |
| - return |
| - |
| - html_interface_name = self._shared._HTMLInterfaceName(interface.id) |
| - dart_interface_file_path = self._FilePathForDartInterface( |
| - html_interface_name) |
| - |
| - self._dart_interface_file_paths.append(dart_interface_file_path) |
| - |
| - dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| - |
| - template_file = 'interface_%s.darttemplate' % html_interface_name |
| - template = self._templates.TryLoad(template_file) |
| - if not template: |
| - template = self._templates.Load('interface.darttemplate') |
| - |
| - generator = HtmlDartInterfaceGenerator( |
| - self, interface, dart_interface_code, |
| - template, self._shared) |
| - generator.Generate() |
| + """Generates dart interface and implementation for the DOM IDL interface.""" |
| + HtmlDartInterfaceGenerator(self, interface).Generate() |
| def ProcessCallback(self, interface, info): |
| """Generates a typedef for the callback interface.""" |
| @@ -818,19 +798,46 @@ class HtmlInterfacesSystem(HtmlSystem): |
| # ------------------------------------------------------------------------------ |
| -# TODO(jmesserly): inheritance is probably not the right way to factor this long |
| -# term, but it makes merging better for now. |
| -class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| - """Generates Dart Interface definition for one DOM IDL interface.""" |
| - |
| - def __init__(self, system, interface, emitter, template, shared): |
| - super(HtmlDartInterfaceGenerator, self).__init__(system, interface, |
| - emitter, template) |
| - self._shared = shared |
| +class HtmlDartInterfaceGenerator(BaseGenerator): |
| + """Generates dart interface and implementation for the DOM IDL interface.""" |
| + |
| + def __init__(self, system, interface): |
| + super(HtmlDartInterfaceGenerator, self).__init__( |
| + system._database, interface) |
| + self._system = system |
|
Anton Muhin
2012/06/28 13:20:19
do you need to store system here too (it's passed
podivilov
2012/06/29 12:59:28
No, it's not passed.
Anton Muhin
2012/06/29 13:34:57
Maybe you should pass it, but I am not insisting o
|
| + self._backend = system._backend |
| + self._emitters = system._emitters |
| + self._shared = system._shared |
| + self._templates = system._templates |
|
Anton Muhin
2012/06/28 13:20:19
why are you caching _backend, _emitters, _shared a
podivilov
2012/06/29 12:59:28
Done.
|
| self._html_interface_name = self._shared._HTMLInterfaceName( |
| self._interface.id) |
| + interface_path = self._system._FilePathForDartInterface( |
|
Anton Muhin
2012/06/28 13:20:19
it looks like interface_path is only used in then
podivilov
2012/06/29 12:59:28
Done.
|
| + self._html_interface_name) |
| + if not interface.id in _merged_html_interfaces: |
| + self._system._dart_interface_file_paths.append(interface_path) |
|
Anton Muhin
2012/06/28 13:20:19
again, why you need _system here, or are you going
podivilov
2012/06/29 12:59:28
_dart_interface_file_paths is per-library state, l
|
| + self._interface_emitter = self._emitters.FileEmitter(interface_path) |
| + else: |
| + self._interface_emitter = emitter.Emitter() |
| + |
| + template_file = 'interface_%s.darttemplate' % self._html_interface_name |
| + self._interface_template = (self._templates.TryLoad(template_file) or |
| + self._templates.Load('interface.darttemplate')) |
| + |
| + implementation_path = self._backend.FilePathForDartImplementation( |
|
Anton Muhin
2012/06/28 13:20:19
ditto for implementation_path and if below.
podivilov
2012/06/29 12:59:28
Done.
|
| + self._interface.id) |
| + if self._backend.HasImplementation(self._interface.id): |
| + self._system._dart_interface_file_paths.append(implementation_path) |
|
Anton Muhin
2012/06/28 13:20:19
that looks slightly odd that you add implementatio
podivilov
2012/06/29 12:59:28
This is slightly complicated to refactor right now
|
| + self._implementation_emitter = self._emitters.FileEmitter( |
| + implementation_path) |
| + else: |
| + self._implementation_emitter = emitter.Emitter() |
| + |
| def StartInterface(self): |
| + if not IsPureInterface(self._interface.id): |
|
Anton Muhin
2012/06/28 13:20:19
that might be stupid, but it feels more natural to
Anton Muhin
2012/06/28 13:20:19
should you call into backend if it's not pure or i
podivilov
2012/06/29 12:59:28
Done.
podivilov
2012/06/29 12:59:28
Done.
|
| + self._backend.ProcessInterface( |
| + self._interface, self._implementation_emitter) |
| + |
| typename = self._html_interface_name |
| extends = [] |
| @@ -881,8 +888,8 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| # TODO(vsm): Add appropriate package / namespace syntax. |
| (self._type_comment_emitter, |
| self._members_emitter, |
| - self._top_level_emitter) = self._emitter.Emit( |
| - self._template + '$!TOP_LEVEL', |
| + self._top_level_emitter) = self._interface_emitter.Emit( |
| + self._interface_template + '$!TOP_LEVEL', |
| ID=typename, |
| EXTENDS=extends_str) |
| @@ -982,7 +989,11 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| pass |
| def AddConstant(self, constant): |
| - self._EmitConstant(self._members_emitter, constant) |
| + type = TypeOrNothing(DartType(constant.type.id), constant.type.id) |
| + self._members_emitter.Emit('\n static final $TYPE$NAME = $VALUE;\n', |
| + NAME=constant.id, |
| + TYPE=type, |
| + VALUE=constant.value) |
| def AddEventAttributes(self, event_attrs): |
| event_attrs = DomToHtmlEvents(self._html_interface_name, event_attrs) |
| @@ -990,7 +1001,7 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| events_interface = self._html_interface_name + 'Events' |
| self._EmitEventGetter(events_interface) |
| - events_members = self._emitter.Emit( |
| + events_members = self._interface_emitter.Emit( |
| '\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n', |
| INTERFACE=events_interface, |
| PARENTS=', '.join( |
| @@ -1351,23 +1362,16 @@ class HtmlFrogSystem(HtmlSystem): |
| self._dart_frog_file_paths = [] |
| self._factory_provider_emitters = {} |
| - def ProcessInterface(self, interface): |
| + def ProcessInterface(self, interface, implementation_emitter): |
| """.""" |
| - if interface.id in _merged_html_interfaces: |
| - return None |
| - |
| - if IsPureInterface(interface.id): |
| - return |
| - |
| html_interface_name = self._shared._HTMLInterfaceName(interface.id) |
| template_file = 'impl_%s.darttemplate' % html_interface_name |
| template = self._templates.TryLoad(template_file) |
| if not template: |
| template = self._templates.Load('frog_impl.darttemplate') |
| - dart_code = self._ImplFileEmitter(html_interface_name) |
| generator = HtmlFrogClassGenerator(self, interface, template, |
| - dart_code, self._shared) |
| + implementation_emitter, self._shared) |
| generator.Generate() |
| def GenerateLibraries(self, interface_files): |
| @@ -1379,9 +1383,13 @@ class HtmlFrogSystem(HtmlSystem): |
| def Finish(self): |
| pass |
| + def HasImplementation(self, interface): |
| + return not (IsPureInterface(interface) or |
| + interface in _merged_html_interfaces) |
| + |
| def _ImplFileEmitter(self, name): |
| """Returns the file emitter of the Frog implementation file.""" |
| - path = os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) |
| + path = self.FilePathForDartImplementation(name) |
| self._dart_frog_file_paths.append(path) |
| return self._emitters.FileEmitter(path) |
| @@ -1392,6 +1400,10 @@ class HtmlFrogSystem(HtmlSystem): |
| self._factory_provider_emitters[name] = file_emitter.Emit(template) |
| return self._factory_provider_emitters[name] |
| + def FilePathForDartImplementation(self, name): |
| + name = self._shared._HTMLInterfaceName(name) |
| + return os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) |
| + |
| # ----------------------------------------------------------------------------- |
| def _ComputeInheritanceClosure(database): |