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

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

Issue 10119009: Move custom to dart conversion logic to IDLTypeInfo implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | lib/dom/scripts/systemnative.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/dom/scripts/generator.py
diff --git a/lib/dom/scripts/generator.py b/lib/dom/scripts/generator.py
index 9033ffe0a3ecb9edebe9498940e27ac78449a5a4..b6234b046ff34b52fb3fd3ceb8fb0b1916ccf360 100644
--- a/lib/dom/scripts/generator.py
+++ b/lib/dom/scripts/generator.py
@@ -426,14 +426,13 @@ def TypeName(type_ids, interface):
class IDLTypeInfo(object):
def __init__(self, idl_type, dart_type=None,
native_type=None, ref_counted=True,
- custom_parameter_adapter=False, conversion_template=None,
+ custom_parameter_adapter=False,
custom_to_dart=False, to_dart_includes=[]):
self._idl_type = idl_type
self._dart_type = dart_type
self._native_type = native_type
self._ref_counted = ref_counted
self._custom_parameter_adapter = custom_parameter_adapter
- self._conversion_template = conversion_template
self._custom_to_dart = custom_to_dart
self._to_dart_includes = to_dart_includes
@@ -500,10 +499,8 @@ class IDLTypeInfo(object):
for include in
[self.idl_type()] + self._to_dart_includes]
- def conversion_cast(self, expression):
- if self._conversion_template:
- return self._conversion_template % expression
- return expression
+ def to_dart_conversion(self, value, interface_name, attributes):
+ return 'toDartValue(%s)' % value
def custom_to_dart(self):
return self._custom_to_dart
@@ -526,12 +523,12 @@ class CompositeIDLTypeInfo(IDLTypeInfo):
class PrimitiveIDLTypeInfo(IDLTypeInfo):
def __init__(self, idl_type, dart_type, native_type=None, ref_counted=False,
- conversion_template=None,
+ needs_static_cast=False,
webcore_getter_name='getAttribute',
webcore_setter_name='setAttribute'):
super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type,
- native_type=native_type, ref_counted=ref_counted,
- conversion_template=conversion_template)
+ native_type=native_type, ref_counted=ref_counted)
+ self._needs_static_cast = needs_static_cast
self._webcore_getter_name = webcore_getter_name
self._webcore_setter_name = webcore_setter_name
@@ -549,6 +546,14 @@ class PrimitiveIDLTypeInfo(IDLTypeInfo):
def to_dart_includes(self):
return []
+ def to_dart_conversion(self, value, interface_name, attributes):
+ if self._needs_static_cast:
+ value = 'static_cast<%s>(%s)' % (self.native_type(), value)
+ conversion_arguments = [value]
+ if 'TreatReturnedNullStringAs' in attributes:
+ conversion_arguments.append('ConvertDefaultToNull')
+ return 'toDartValue(%s)' % ', '.join(conversion_arguments)
+
def webcore_getter_name(self):
return self._webcore_getter_name
@@ -574,19 +579,35 @@ class SVGTearOffIDLTypeInfo(IDLTypeInfo):
return 'receiver->'
return 'receiver->propertyReference().'
+ def to_dart_conversion(self, value, interface_name, attributes):
+ svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix',
+ 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform']
+ conversion_cast = '%s::create(%s)'
+ if interface_name.startswith('SVGAnimated'):
+ conversion_cast = 'static_cast<%s*>(%s)'
+ elif self.idl_type() == 'SVGStringList':
+ conversion_cast = '%s::create(receiver, %s)'
+ elif interface_name.endswith('List'):
+ conversion_cast = 'static_cast<%s*>(%s.get())'
+ elif self.idl_type() in svg_primitive_types:
+ conversion_cast = '%s::create(%s)'
+ else:
+ conversion_cast = 'static_cast<%s*>(%s)'
+ conversion_cast = conversion_cast % (self.native_type(), value)
+ return 'toDartValue(%s)' % conversion_cast
_idl_type_registry = {
# There is GC3Dboolean which is not a bool, but unsigned char for OpenGL compatibility.
'boolean': PrimitiveIDLTypeInfo('boolean', dart_type='bool', native_type='bool',
- conversion_template='static_cast<bool>(%s)',
+ needs_static_cast=True,
webcore_getter_name='hasAttribute',
webcore_setter_name='setBooleanAttribute'),
# Some IDL's unsigned shorts/shorts are mapped to WebCore C++ enums, so we
# use a static_cast<int> here not to provide overloads for all enums.
'short': PrimitiveIDLTypeInfo('short', dart_type='int', native_type='int',
- conversion_template='static_cast<int>(%s)'),
+ needs_static_cast=True),
'unsigned short': PrimitiveIDLTypeInfo('unsigned short', dart_type='int',
- native_type='int', conversion_template='static_cast<int>(%s)'),
+ native_type='int', needs_static_cast=True,),
'int': PrimitiveIDLTypeInfo('int', dart_type='int'),
'unsigned int': PrimitiveIDLTypeInfo('unsigned int', dart_type='int',
native_type='unsigned'),
« no previous file with comments | « no previous file | lib/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698