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

Unified Diff: sdk/lib/html/scripts/generator.py

Issue 11293292: Add constructors for SVG elements and remove static factory providers for html elements. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | « sdk/lib/html/dartium/html_dartium.dart ('k') | sdk/lib/html/scripts/htmldartgenerator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/scripts/generator.py
===================================================================
--- sdk/lib/html/scripts/generator.py (revision 14920)
+++ sdk/lib/html/scripts/generator.py (working copy)
@@ -305,7 +305,12 @@
is named, e.g. 'fromList' in Int8Array.fromList(list).
type_name: A string, the name of the return type of the operation.
param_infos: A list of ParamInfo.
+ factory_parameters: A list of parameters used for custom designed Factory
+ calls.
"""
+
+ def __init__(self):
+ self.factory_parameters = None
def ParametersDeclaration(self, rename_type, force_optional=False):
def FormatParam(param):
@@ -356,11 +361,18 @@
def ConstructorFactoryName(self, rename_type):
return 'create' + self._ConstructorFullName(rename_type).replace('.', '_')
- def GenerateFactoryInvocation(self, rename_type, emitter, factory_provider):
+ def GenerateFactoryInvocation(self, rename_type, emitter, factory_name,
+ factory_constructor_name=None, factory_parameters=None):
has_optional = any(param_info.is_optional
for param_info in self.param_infos)
- factory_name = self.ConstructorFactoryName(rename_type)
+ if not factory_constructor_name:
+ factory_constructor_name = self.ConstructorFactoryName(rename_type)
+ factory_parameters = self.ParametersAsArgumentList()
+ has_factory_provider = True
+ else:
+ factory_parameters = ', '.join(factory_parameters)
+ has_factory_provider = False
if not has_optional:
emitter.Emit(
'\n'
@@ -368,11 +380,19 @@
'$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n',
CTOR=self._ConstructorFullName(rename_type),
PARAMS=self.ParametersDeclaration(rename_type),
- FACTORY=factory_provider,
- CTOR_FACTORY_NAME=factory_name,
- FACTORY_PARAMS=self.ParametersAsArgumentList())
+ FACTORY=factory_name,
+ CTOR_FACTORY_NAME=factory_constructor_name,
+ FACTORY_PARAMS=factory_parameters)
return
+ if has_factory_provider:
+ self._GenerateFactoryOptParams(rename_type, emitter, factory_name)
+ else:
+ self._GenerateFactoryOptParamsWithoutFactoryProvider(rename_type, emitter,
+ factory_name, factory_constructor_name, factory_parameters)
+ def _GenerateFactoryOptParams(self, rename_type, emitter, factory_provider):
+ """Helper method for creating generic factory constructors with optional
+ parameters that use factory providers."""
dispatcher_emitter = emitter.Emit(
'\n'
' factory $CTOR($PARAMS) {\n'
@@ -382,7 +402,7 @@
CTOR=self._ConstructorFullName(rename_type),
PARAMS=self.ParametersDeclaration(rename_type),
FACTORY=factory_provider,
- CTOR_FACTORY_NAME=factory_name,
+ CTOR_FACTORY_NAME=self.ConstructorFactoryName(rename_type),
FACTORY_PARAMS=self.ParametersAsArgumentList())
# If we have optional parameters, check to see if they are set
@@ -394,12 +414,34 @@
' }\n',
OPT_PARAM_NAME=self.param_infos[index].name,
FACTORY=factory_provider,
- CTOR_FACTORY_NAME=factory_name,
+ CTOR_FACTORY_NAME=self.ConstructorFactoryName(rename_type),
FACTORY_PARAMS=self.ParametersAsArgumentList(index))
for index, param_info in enumerate(self.param_infos):
if param_info.is_optional:
EmitOptionalParameterInvocation(index)
+
+ def _GenerateFactoryOptParamsWithoutFactoryProvider(self, rename_type,
+ emitter, factory_name, factory_constructor_name, factory_parameters):
+ """Helper method for creating a factory constructor with optional
+ parameters that does not call a factory provider, it simply creates the
+ object itself. This is currently used for SVGElements and HTMLElements."""
+ inits = emitter.Emit(
+ '\n'
+ ' factory $CONSTRUCTOR($PARAMS) {\n'
+ ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n'
+ '$!INITS'
+ ' return e;\n'
+ ' }\n',
+ CONSTRUCTOR=self._ConstructorFullName(rename_type),
+ FACTORY=factory_name,
+ CTOR_FACTORY_NAME=factory_constructor_name,
+ PARAMS=self.ParametersDeclaration(rename_type, force_optional=True),
+ FACTORY_PARAMS=factory_parameters)
+ for index, param_info in enumerate(self.param_infos):
+ if param_info.is_optional:
+ inits.Emit(' if (!?$E) e.$E = $E;\n',
+ E=self.param_infos[index].name)
def ConstantOutputOrder(a, b):
"""Canonical output ordering for constants."""
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | sdk/lib/html/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698