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

Unified Diff: client/dom/scripts/systemhtml.py

Issue 9464002: Implement automatically generated constructors for frog and dartium dart:html (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rerun script Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | client/dom/templates/html/frog/factoryprovider.darttemplate » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/dom/scripts/systemhtml.py
diff --git a/client/dom/scripts/systemhtml.py b/client/dom/scripts/systemhtml.py
index e18099e093f5c202ea2c2358b2449c925e915544..07aeb91500df50b99beab70dbb5e73c8a5c8b56e 100644
--- a/client/dom/scripts/systemhtml.py
+++ b/client/dom/scripts/systemhtml.py
@@ -442,6 +442,7 @@ class HtmlSystem(System):
names.append(interface.id + 'Events')
return names
+
class HtmlInterfacesSystem(HtmlSystem):
def __init__(self, templates, database, emitters, output_dir, generator):
@@ -529,8 +530,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,
@@ -539,6 +548,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(
@@ -677,13 +693,33 @@ 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(),
+ NAMEDCONSTRUCTOR=constructor_info.name or interface_name,
+ ARGUMENTS=constructor_info.ParametersAsArgumentList())
+
+
def AddAttribute(self, getter, setter):
if self._system._PrivateInHtmlLibrary(self._interface, getter.id):
- if getter:
- self._AddGetter(getter, True)
- if setter:
Jacob 2012/02/25 03:50:03 can you revert this part?
- self._AddSetter(setter, True)
+ self._AddAttributeUsingProperties(getter, setter, True)
return
if getter and not self._system._AllowInHtmlLibrary(self._interface,
'get:' + getter.id):
@@ -712,10 +748,7 @@ class HtmlFrogClassGenerator(FrogInterfaceGenerator):
return
self._members_emitter.Emit('\n // Shadowing definition.')
- if getter:
- self._AddGetter(getter, False)
- if setter:
- self._AddSetter(setter, False)
+ self._AddAttributeUsingProperties(getter, setter, False)
return
if self._interface.id != 'Document':
@@ -848,15 +881,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)
@@ -871,11 +901,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)
# ------------------------------------------------------------------------------
« no previous file with comments | « no previous file | client/dom/templates/html/frog/factoryprovider.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698