Index: client/dom/scripts/systemhtml.py |
diff --git a/client/dom/scripts/systemhtml.py b/client/dom/scripts/systemhtml.py |
index 64748f425d9e1ea2ddcfd0e1cda4b8009d174bc8..81629091995957d66559735a9e39bc829b3a24f6 100644 |
--- a/client/dom/scripts/systemhtml.py |
+++ b/client/dom/scripts/systemhtml.py |
@@ -591,8 +591,16 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
if suppressed_extends: |
extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) |
+ factory_provider = None |
+ constructor_info = AnalyzeConstructor(self._interface) |
+ if constructor_info: |
+ factory_provider = '_' + typename + 'FactoryProvider'; |
+ |
if typename in interface_factories: |
- extends_str += ' default ' + interface_factories[typename] |
+ factory_provider = interface_factories[typename] |
+ |
+ if factory_provider: |
+ extends_str += ' default ' + factory_provider |
# TODO(vsm): Add appropriate package / namespace syntax. |
(self._members_emitter, |
@@ -601,6 +609,13 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
ID=typename, |
EXTENDS=extends_str) |
+ if constructor_info: |
+ self._members_emitter.Emit( |
+ '\n' |
+ ' $CTOR($PARAMS);\n', |
+ CTOR=typename, |
+ PARAMS=constructor_info.ParametersInterfaceDeclaration()); |
+ |
element_type = MaybeTypedArrayElementType(self._interface) |
if element_type: |
self._members_emitter.Emit( |
@@ -738,6 +753,27 @@ class HtmlFrogClassGenerator(FrogInterfaceGenerator): |
if element_type: |
self.AddTypedArrayConstructors(element_type) |
+ # Emit a factory provider class for the constructor. |
+ constructor_info = AnalyzeConstructor(interface) |
+ if constructor_info: |
+ self._EmitFactoryProvider(interface_name, constructor_info) |
+ |
+ def _EmitFactoryProvider(self, interface_name, constructor_info): |
+ template_file = 'factoryprovider_%s.darttemplate' % interface_name |
+ template = self._system._templates.TryLoad(template_file) |
+ if not template: |
+ template = self._system._templates.Load('factoryprovider.darttemplate') |
+ |
+ factory_provider = '_' + interface_name + 'FactoryProvider' |
+ emitter = self._system._ImplFileEmitter(factory_provider) |
+ emitter.Emit( |
+ template, |
+ FACTORYPROVIDER=factory_provider, |
+ CONSTRUCTOR=interface_name, |
+ PARAMETERS=constructor_info.ParametersImplementationDeclaration(), |
+ NAMED_CONSTRUCTOR=constructor_info.name or interface_name, |
+ ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
+ |
def AddIndexer(self, element_type): |
"""Adds all the methods required to complete implementation of List.""" |
# We would like to simply inherit the implementation of everything except |
@@ -1000,15 +1036,12 @@ class HtmlFrogSystem(HtmlSystem): |
super_interface_name, |
source_filter): |
""".""" |
- dart_frog_file_path = self._FilePathForFrogImpl(interface.id) |
- self._dart_frog_file_paths.append(dart_frog_file_path) |
- |
template_file = 'impl_%s.darttemplate' % interface.id |
template = self._templates.TryLoad(template_file) |
if not template: |
template = self._templates.Load('frog_impl.darttemplate') |
- dart_code = self._emitters.FileEmitter(dart_frog_file_path) |
+ dart_code = self._ImplFileEmitter(interface.id) |
return HtmlFrogClassGenerator(self, interface, template, |
super_interface_name, dart_code, self._shared) |
@@ -1023,11 +1056,12 @@ class HtmlFrogSystem(HtmlSystem): |
def Finish(self): |
pass |
- def _FilePathForFrogImpl(self, interface_name): |
- """Returns the file path of the Frog implementation.""" |
+ def _ImplFileEmitter(self, name): |
+ """Returns the file emitter of the Frog implementation file.""" |
# TODO(jmesserly): is this the right path |
- return os.path.join(self._output_dir, 'html', 'frog', |
- '%s.dart' % interface_name) |
+ path = os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) |
+ self._dart_frog_file_paths.append(path) |
+ return self._emitters.FileEmitter(path) |
# ----------------------------------------------------------------------------- |
@@ -1050,25 +1084,22 @@ class HtmlDartiumSystem(HtmlSystem): |
super_interface_name, |
source_filter): |
""".""" |
- dart_dartium_file_path = self._FilePathForImpl(interface.id) |
- self._dart_dartium_file_paths.append(dart_dartium_file_path) |
- |
template_file = 'impl_%s.darttemplate' % interface.id |
template = self._templates.TryLoad(template_file) |
# TODO(jacobr): change this name as it is confusing. |
if not template: |
template = self._templates.Load('frog_impl.darttemplate') |
- dart_code = self._emitters.FileEmitter(dart_dartium_file_path) |
+ dart_code = self._ImplFileEmitter(interface.id) |
return HtmlDartiumInterfaceGenerator(self, interface, template, |
super_interface_name, dart_code, self._BaseDefines(interface), |
self._shared) |
- def _FilePathForImpl(self, interface_name): |
- """Returns the file path of the Frog implementation.""" |
- # TODO(jmesserly): is this the right path |
- return os.path.join(self._output_dir, 'html', 'dartium', |
- '%s.dart' % interface_name) |
+ def _ImplFileEmitter(self, name): |
+ """Returns the file emitter of the Dartium implementation file.""" |
+ path = os.path.join(self._output_dir, 'html', 'dartium', '%s.dart' % name) |
+ self._dart_dartium_file_paths.append(path) |
+ return self._emitters.FileEmitter(path); |
def ProcessCallback(self, interface, info): |
pass |
@@ -1080,7 +1111,6 @@ class HtmlDartiumSystem(HtmlSystem): |
os.path.join(lib_dir, 'html_dartium.dart'), |
(self._interface_system._dart_interface_file_paths + |
self._interface_system._dart_callback_file_paths + |
- # FIXME: Move the implementation to a separate library. |
self._dart_dartium_file_paths |
), |
WRAPCASES='\n'.join(self._wrap_cases)) |
@@ -1202,6 +1232,27 @@ class HtmlDartiumInterfaceGenerator(object): |
' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', |
CLASSNAME=self._class_name) |
+ # Emit a factory provider class for the constructor. |
+ constructor_info = AnalyzeConstructor(interface) |
+ if constructor_info: |
+ self._EmitFactoryProvider(interface_name, constructor_info) |
+ |
+ def _EmitFactoryProvider(self, interface_name, constructor_info): |
+ template_file = 'factoryprovider_%s.darttemplate' % interface_name |
+ template = self._system._templates.TryLoad(template_file) |
+ if not template: |
+ template = self._system._templates.Load('factoryprovider.darttemplate') |
+ |
+ factory_provider = '_' + interface_name + 'FactoryProvider' |
+ emitter = self._system._ImplFileEmitter(factory_provider) |
+ emitter.Emit( |
+ template, |
+ FACTORYPROVIDER=factory_provider, |
+ CONSTRUCTOR=interface_name, |
+ PARAMETERS=constructor_info.ParametersImplementationDeclaration(), |
+ NAMED_CONSTRUCTOR=constructor_info.name or interface_name, |
+ ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
+ |
def _BaseClassName(self, interface): |
if not interface.parents: |
return '_DOMTypeBase' |