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

Unified Diff: lib/dom/scripts/generator.py

Issue 10698108: Stop passing HtmlSystemShared around and move html renaming to IDLTypeInfo. (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 side-by-side diff with in-line comments
Download patch
Index: lib/dom/scripts/generator.py
diff --git a/lib/dom/scripts/generator.py b/lib/dom/scripts/generator.py
index 65b87e08714d45edf337e1a52eee606965a44d9b..5f4254a9448ed98239b2d129a1b441762c28532f 100644
--- a/lib/dom/scripts/generator.py
+++ b/lib/dom/scripts/generator.py
@@ -168,6 +168,8 @@ def MatchSourceFilter(thing):
def DartType(idl_type_name):
return GetIDLTypeInfo(idl_type_name).dart_type()
+def DartInterfaceName(interface):
+ return IDLTypeInfo.interface_renames.get(interface.id, interface.id)
class ParamInfo(object):
"""Holder for various information about a parameter of a Dart operation.
@@ -202,9 +204,9 @@ def _DartArg(args, interface, constructor=False):
dart_types = sorted(set(DartType(arg.type.id) for arg in args))
if len(dart_types) == 1:
if len(type_ids) == 1:
- return (type_ids[0], dart_types[0])
+ return (type_ids[0], type_ids[0])
else:
- return (None, dart_types[0])
+ return (None, type_ids[0])
else:
return (None, TypeName(type_ids, interface))
@@ -258,7 +260,7 @@ def AnalyzeOperation(interface, operations):
info.name = operations[0].ext_attrs.get('DartName', info.declared_name)
info.constructor_name = None
info.js_name = info.declared_name
- info.type_name = DartType(operations[0].type.id) # TODO: widen.
+ info.type_name = operations[0].type.id # TODO: widen.
info.param_infos = args
return info
@@ -380,14 +382,14 @@ class OperationInfo(object):
param_infos: A list of ParamInfo.
"""
- def ParametersInterfaceDeclaration(self, rename_type=lambda x: x):
+ def ParametersInterfaceDeclaration(self, rename_type=DartType):
"""Returns a formatted string declaring the parameters for the interface."""
return self._FormatParams(
self.param_infos, None,
lambda param: TypeOrNothing(rename_type(param.dart_type), param.type_id))
def ParametersImplementationDeclaration(
- self, rename_type=None, default_value='null'):
+ self, rename_type=DartType, default_value='null'):
"""Returns a formatted string declaring the parameters for the
implementation.
@@ -395,23 +397,9 @@ class OperationInfo(object):
rename_type: A function that allows the types to be renamed.
The function is applied to the parameter's dart_type.
"""
- if rename_type:
- def renamer(param_info):
- return TypeOrNothing(rename_type(param_info.dart_type))
- return self._FormatParams(self.param_infos, default_value, renamer)
- else:
- def type_fn(param_info):
- if param_info.dart_type == 'Dynamic':
- if param_info.type_id:
- # It is more informative to use a comment IDL type.
- return '/*%s*/' % param_info.type_id
- else:
- return 'var'
- else:
- return param_info.dart_type
- return self._FormatParams(
- self.param_infos, default_value,
- lambda param: TypeOrNothing(param.dart_type, param.type_id))
+ return self._FormatParams(
+ self.param_infos, default_value,
+ lambda param: TypeOrNothing(rename_type(param.dart_type)))
def ParametersAsArgumentList(self):
"""Returns a string of the parameter names suitable for passing the
@@ -505,7 +493,8 @@ class IDLTypeInfo(object):
return self._idl_type
def dart_type(self):
- return self._dart_type or self._idl_type
+ dart_type = self._dart_type or self._idl_type
+ return self.interface_renames.get(dart_type, dart_type)
def native_type(self):
return self._native_type or self._idl_type
@@ -597,6 +586,8 @@ class IDLTypeInfo(object):
def custom_to_dart(self):
return self._custom_to_dart
+ interface_renames = {}
+
class SequenceIDLTypeInfo(IDLTypeInfo):
def __init__(self, idl_type, item_info):

Powered by Google App Engine
This is Rietveld 408576698