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

Side by Side Diff: bindings/dart/scripts/dart_types.py

Issue 581453002: Dartium Roll 38 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Sync'd w/ r 182210 Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bindings/dart/scripts/dart_methods.py ('k') | bindings/dart/scripts/dart_utilities.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 20 matching lines...) Expand all
31 Extends IdlType and IdlUnionType with C++-specific properties, methods, and 31 Extends IdlType and IdlUnionType with C++-specific properties, methods, and
32 class methods. 32 class methods.
33 33
34 Spec: 34 Spec:
35 http://www.w3.org/TR/WebIDL/#es-type-mapping 35 http://www.w3.org/TR/WebIDL/#es-type-mapping
36 36
37 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 37 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
38 """ 38 """
39 39
40 import posixpath 40 import posixpath
41 from idl_types import IdlType, IdlUnionType, TYPE_NAMES 41 from idl_types import IdlTypeBase, IdlType, IdlUnionType, TYPE_NAMES, IdlArrayOr SequenceType
42
42 import dart_attributes # for IdlType.constructor_type_name 43 import dart_attributes # for IdlType.constructor_type_name
43 from dart_utilities import DartUtilities 44 from dart_utilities import DartUtilities
44 from v8_globals import includes 45 from v8_globals import includes
45 46
46 47
47 ################################################################################ 48 ################################################################################
48 # CPP -specific handling of IDL types for Dart:Blink 49 # CPP -specific handling of IDL types for Dart:Blink
49 ################################################################################ 50 ################################################################################
50 51
51 NON_WRAPPER_TYPES = frozenset([ 52 NON_WRAPPER_TYPES = frozenset([
(...skipping 13 matching lines...) Expand all
65 'Float64Array': ('double', 'Float64List'), 66 'Float64Array': ('double', 'Float64List'),
66 'Int8Array': ('signed char', 'Int8List'), 67 'Int8Array': ('signed char', 'Int8List'),
67 'Int16Array': ('short', 'Int16List'), 68 'Int16Array': ('short', 'Int16List'),
68 'Int32Array': ('int', 'Int32List'), 69 'Int32Array': ('int', 'Int32List'),
69 'Uint8Array': ('unsigned char', 'Uint8List'), 70 'Uint8Array': ('unsigned char', 'Uint8List'),
70 'Uint8ClampedArray': ('unsigned char', 'Uint8ClampedList'), 71 'Uint8ClampedArray': ('unsigned char', 'Uint8ClampedList'),
71 'Uint16Array': ('unsigned short', 'Uint16List'), 72 'Uint16Array': ('unsigned short', 'Uint16List'),
72 'Uint32Array': ('unsigned int', 'Uint32List'), 73 'Uint32Array': ('unsigned int', 'Uint32List'),
73 } 74 }
74 75
75 IdlType.is_typed_array_type = property( 76
77 IdlTypeBase.is_typed_array_type = property(
76 lambda self: self.base_type in TYPED_ARRAYS) 78 lambda self: self.base_type in TYPED_ARRAYS)
77 79
78 80
79 IdlType.is_wrapper_type = property( 81 IdlType.is_wrapper_type = property(
80 lambda self: (self.is_interface_type and 82 lambda self: (self.is_interface_type and
81 self.base_type not in NON_WRAPPER_TYPES)) 83 self.base_type not in NON_WRAPPER_TYPES))
82 84
83 85
84 ################################################################################ 86 ################################################################################
85 # C++ types 87 # C++ types
(...skipping 25 matching lines...) Expand all
111 'Promise': 'ScriptPromise', 113 'Promise': 'ScriptPromise',
112 'ScriptValue': 'ScriptValue', 114 'ScriptValue': 'ScriptValue',
113 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529 115 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529
114 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', 116 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>',
115 'boolean': 'bool', 117 'boolean': 'bool',
116 'unrestricted double': 'double', 118 'unrestricted double': 'double',
117 'unrestricted float': 'float', 119 'unrestricted float': 'float',
118 } 120 }
119 121
120 122
121 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_in _cpp_sequence=False): 123 def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_rvalue_ type=False, used_in_cpp_sequence=False):
122 """Returns C++ type corresponding to IDL type. 124 """Returns C++ type corresponding to IDL type.
123 125
124 |idl_type| argument is of type IdlType, while return value is a string 126 |idl_type| argument is of type IdlType, while return value is a string
125 127
126 Args: 128 Args:
127 idl_type: 129 idl_type:
128 IdlType 130 IdlType
129 used_as_argument: 131 raw_type:
130 bool, True if idl_type's raw/primitive C++ type should be returned. 132 bool, True if idl_type's raw/primitive C++ type should be returned.
131 will_be_in_heap_object: 133 used_as_rvalue_type:
132 bool, True if idl_type will be part of a possibly heap allocated 134 bool, True if the C++ type is used as an argument or the return
133 object (e.g., appears as an element of a C++ heap vector type.) 135 type of a method.
134 The C++ type of an interface type changes, if so. 136 used_as_variadic_argument:
137 bool, True if the C++ type is used as a variadic argument of a metho d.
138 used_in_cpp_sequence:
139 bool, True if the C++ type is used as an element of a container.
140 Containers can be an array, a sequence or a dictionary.
135 """ 141 """
136 extended_attributes = extended_attributes or {} 142 extended_attributes = extended_attributes or {}
137 idl_type = idl_type.preprocessed_type 143 idl_type = idl_type.preprocessed_type
138 144
139 # Composite types 145 # Composite types
140 array_or_sequence_type = idl_type.array_or_sequence_type 146 native_array_element_type = idl_type.native_array_element_type
141 if array_or_sequence_type: 147 if native_array_element_type:
142 vector_type = cpp_ptr_type('Vector', 'HeapVector', array_or_sequence_typ e.gc_type) 148 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_ type.gc_type)
143 return cpp_template_type(vector_type, array_or_sequence_type.cpp_type_ar gs(used_in_cpp_sequence=True)) 149 return cpp_template_type(vector_type, native_array_element_type.cpp_type _args(used_in_cpp_sequence=True))
144 150
145 # Simple types 151 # Simple types
146 base_idl_type = idl_type.base_type 152 base_idl_type = idl_type.base_type
147 153
148 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: 154 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE:
149 return base_idl_type 155 return base_idl_type
150 if base_idl_type in CPP_INT_TYPES: 156 if base_idl_type in CPP_INT_TYPES:
151 return 'int' 157 return 'int'
152 if base_idl_type in CPP_UNSIGNED_TYPES: 158 if base_idl_type in CPP_UNSIGNED_TYPES:
153 return 'unsigned' 159 return 'unsigned'
154 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: 160 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES:
155 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] 161 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type]
156 162
157 if base_idl_type in NON_WRAPPER_TYPES: 163 if base_idl_type in NON_WRAPPER_TYPES:
158 return 'RefPtr<%s>' % base_idl_type 164 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas e_idl_type
159 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'): 165 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'):
160 if not used_as_argument: 166 if not raw_type:
161 return 'String' 167 return 'String'
162 return 'DartStringAdapter' 168 return 'DartStringAdapter'
163 169
164 if idl_type.is_typed_array_type and used_as_argument: 170 if idl_type.is_typed_array_type and raw_type:
165 return 'RefPtr<%s>' % base_idl_type 171 return 'RefPtr<%s>' % base_idl_type
166 if idl_type.is_callback_interface: 172 if idl_type.is_callback_interface:
167 return 'OwnPtr<%s>' % base_idl_type 173 return 'OwnPtr<%s>' % base_idl_type
168 if idl_type.is_interface_type: 174 if idl_type.is_interface_type:
169 implemented_as_class = idl_type.implemented_as 175 implemented_as_class = idl_type.implemented_as
170 if used_as_argument: 176 if raw_type:
171 return implemented_as_class + '*' 177 return implemented_as_class + '*'
172 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' 178 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr'
173 ptr_type = cpp_ptr_type('RefPtr', new_type, idl_type.gc_type) 179 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt r'), new_type, idl_type.gc_type)
174 return cpp_template_type(ptr_type, implemented_as_class) 180 return cpp_template_type(ptr_type, implemented_as_class)
175 181
176 # Default, assume native type is a pointer with same type name as idl type 182 # Default, assume native type is a pointer with same type name as idl type
177 return base_idl_type + '*' 183 return base_idl_type + '*'
178 184
179 185
180 def cpp_type_union(idl_type, extended_attributes=None, used_as_argument=False, w ill_be_in_heap_object=False): 186 def cpp_type_union(idl_type, extended_attributes=None, used_as_rvalue_type=False , will_be_in_heap_object=False):
181 return (member_type.cpp_type for member_type in idl_type.member_types) 187 return (member_type.cpp_type for member_type in idl_type.member_types)
182 188
189
183 # Allow access as idl_type.cpp_type if no arguments 190 # Allow access as idl_type.cpp_type if no arguments
184 IdlType.cpp_type = property(cpp_type) 191 IdlTypeBase.cpp_type = property(cpp_type)
192 IdlTypeBase.cpp_type_args = cpp_type
185 IdlUnionType.cpp_type = property(cpp_type_union) 193 IdlUnionType.cpp_type = property(cpp_type_union)
186 IdlType.cpp_type_args = cpp_type
187 IdlUnionType.cpp_type_args = cpp_type_union 194 IdlUnionType.cpp_type_args = cpp_type_union
188 195
189 196
197 IdlTypeBase.native_array_element_type = None
198 IdlArrayOrSequenceType.native_array_element_type = property(
199 lambda self: self.element_type)
200
201
190 def cpp_template_type(template, inner_type): 202 def cpp_template_type(template, inner_type):
191 """Returns C++ template specialized to type, with space added if needed.""" 203 """Returns C++ template specialized to type, with space added if needed."""
192 if inner_type.endswith('>'): 204 if inner_type.endswith('>'):
193 format_string = '{template}<{inner_type} >' 205 format_string = '{template}<{inner_type} >'
194 else: 206 else:
195 format_string = '{template}<{inner_type}>' 207 format_string = '{template}<{inner_type}>'
196 return format_string.format(template=template, inner_type=inner_type) 208 return format_string.format(template=template, inner_type=inner_type)
197 209
198 210
199 def cpp_ptr_type(old_type, new_type, gc_type): 211 def cpp_ptr_type(old_type, new_type, gc_type):
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return IdlType.implemented_as_interfaces[base_idl_type] 243 return IdlType.implemented_as_interfaces[base_idl_type]
232 return base_idl_type 244 return base_idl_type
233 245
234 246
235 IdlType.implemented_as = property(implemented_as) 247 IdlType.implemented_as = property(implemented_as)
236 248
237 IdlType.set_implemented_as_interfaces = classmethod( 249 IdlType.set_implemented_as_interfaces = classmethod(
238 lambda cls, new_implemented_as_interfaces: 250 lambda cls, new_implemented_as_interfaces:
239 cls.implemented_as_interfaces.update(new_implemented_as_interfaces)) 251 cls.implemented_as_interfaces.update(new_implemented_as_interfaces))
240 252
253
241 # [GarbageCollected] 254 # [GarbageCollected]
242 IdlType.garbage_collected_types = set() 255 IdlType.garbage_collected_types = set()
243 256
257 IdlTypeBase.is_garbage_collected = False
244 IdlType.is_garbage_collected = property( 258 IdlType.is_garbage_collected = property(
245 lambda self: self.base_type in IdlType.garbage_collected_types) 259 lambda self: self.base_type in IdlType.garbage_collected_types)
246 260
247 IdlType.set_garbage_collected_types = classmethod( 261 IdlType.set_garbage_collected_types = classmethod(
248 lambda cls, new_garbage_collected_types: 262 lambda cls, new_garbage_collected_types:
249 cls.garbage_collected_types.update(new_garbage_collected_types)) 263 cls.garbage_collected_types.update(new_garbage_collected_types))
250 264
251 265
252 # [WillBeGarbageCollected] 266 # [WillBeGarbageCollected]
253 IdlType.will_be_garbage_collected_types = set() 267 IdlType.will_be_garbage_collected_types = set()
254 268
269 IdlTypeBase.is_will_be_garbage_collected = False
255 IdlType.is_will_be_garbage_collected = property( 270 IdlType.is_will_be_garbage_collected = property(
256 lambda self: self.base_type in IdlType.will_be_garbage_collected_types) 271 lambda self: self.base_type in IdlType.will_be_garbage_collected_types)
257 272
258 IdlType.set_will_be_garbage_collected_types = classmethod( 273 IdlType.set_will_be_garbage_collected_types = classmethod(
259 lambda cls, new_will_be_garbage_collected_types: 274 lambda cls, new_will_be_garbage_collected_types:
260 cls.will_be_garbage_collected_types.update(new_will_be_garbage_collected _types)) 275 cls.will_be_garbage_collected_types.update(new_will_be_garbage_collected _types))
261 276
262 277
263 def gc_type(idl_type): 278 def gc_type(idl_type):
264 if idl_type.is_garbage_collected: 279 if idl_type.is_garbage_collected:
265 return 'GarbageCollectedObject' 280 return 'GarbageCollectedObject'
266 if idl_type.is_will_be_garbage_collected: 281 if idl_type.is_will_be_garbage_collected:
267 return 'WillBeGarbageCollectedObject' 282 return 'WillBeGarbageCollectedObject'
268 return 'RefCountedObject' 283 return 'RefCountedObject'
269 284
270 IdlType.gc_type = property(gc_type) 285 IdlTypeBase.gc_type = property(gc_type)
271 286
272 287
273 ################################################################################ 288 ################################################################################
274 # Includes 289 # Includes
275 ################################################################################ 290 ################################################################################
276 291
277 def includes_for_cpp_class(class_name, relative_dir_posix): 292 def includes_for_cpp_class(class_name, relative_dir_posix):
278 return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h' )]) 293 return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h' )])
279 294
280 # TODO(terry): Will we need this group header for dart:blink? 295 # TODO(terry): Will we need this group header for dart:blink?
281 INCLUDES_FOR_TYPE = { 296 INCLUDES_FOR_TYPE = {
282 'object': set(), 297 'object': set(),
283 'CompareHow': set(), 298 'CompareHow': set(),
284 'Dictionary': set(['bindings/common/Dictionary.h']), 299 'Dictionary': set(['bindings/core/v8/Dictionary.h']),
285 'EventHandler': set(), 300 'EventHandler': set(),
286 'EventListener': set(), 301 'EventListener': set(),
287 'HTMLCollection': set(['bindings/core/dart/DartHTMLCollection.h', 302 'HTMLCollection': set(['bindings/core/dart/DartHTMLCollection.h',
288 'core/dom/ClassCollection.h', 303 'core/dom/ClassCollection.h',
289 'core/dom/TagCollection.h', 304 'core/dom/TagCollection.h',
290 'core/html/HTMLCollection.h', 305 'core/html/HTMLCollection.h',
291 'core/html/HTMLFormControlsCollection.h', 306 'core/html/HTMLFormControlsCollection.h',
292 'core/html/HTMLTableRowsCollection.h']), 307 'core/html/HTMLTableRowsCollection.h']),
293 'MediaQueryListListener': set(['core/css/MediaQueryListListener.h']), 308 'MediaQueryListListener': set(['core/css/MediaQueryListListener.h']),
294 'NodeList': set(['bindings/core/dart/DartNodeList.h', 309 'NodeList': set(['bindings/core/dart/DartNodeList.h',
295 'core/dom/NameNodeList.h', 310 'core/dom/NameNodeList.h',
296 'core/dom/NodeList.h', 311 'core/dom/NodeList.h',
297 'core/dom/StaticNodeList.h', 312 'core/dom/StaticNodeList.h',
298 'core/html/LabelsNodeList.h']), 313 'core/html/LabelsNodeList.h']),
299 'Promise': set(), 314 'Promise': set(),
300 'SerializedScriptValue': set(), 315 'SerializedScriptValue': set(),
301 'ScriptValue': set(['bindings/dart/DartScriptValue.h']), 316 'ScriptValue': set(['bindings/core/dart/DartScriptValue.h']),
302 } 317 }
303 318
304 319
305 def includes_for_type(idl_type): 320 def includes_for_type(idl_type):
306 idl_type = idl_type.preprocessed_type 321 idl_type = idl_type.preprocessed_type
307 322
308 # Composite types 323 # Composite types
309 array_or_sequence_type = idl_type.array_or_sequence_type 324 if idl_type.native_array_element_type:
310 if array_or_sequence_type: 325 return includes_for_type(idl_type)
311 return includes_for_type(array_or_sequence_type)
312 326
313 # Simple types 327 # Simple types
314 base_idl_type = idl_type.base_type 328 base_idl_type = idl_type.base_type
315 if base_idl_type in INCLUDES_FOR_TYPE: 329 if base_idl_type in INCLUDES_FOR_TYPE:
316 return INCLUDES_FOR_TYPE[base_idl_type] 330 return INCLUDES_FOR_TYPE[base_idl_type]
317 if idl_type.is_basic_type: 331 if idl_type.is_basic_type:
318 return set() 332 return set()
319 if idl_type.is_typed_array_type: 333 if idl_type.is_typed_array_type:
320 # Typed array factory methods are already provided by DartUtilities.h. 334 # Typed array factory methods are already provided by DartUtilities.h.
321 return set([]) 335 return set([])
322 if base_idl_type.endswith('ConstructorConstructor'): 336 if base_idl_type.endswith('ConstructorConstructor'):
323 # FIXME: rename to NamedConstructor 337 # FIXME: rename to NamedConstructor
324 # FIXME: replace with a [NamedConstructorAttribute] extended attribute 338 # FIXME: replace with a [NamedConstructorAttribute] extended attribute
325 # Ending with 'ConstructorConstructor' indicates a named constructor, 339 # Ending with 'ConstructorConstructor' indicates a named constructor,
326 # and these do not have header files, as they are part of the generated 340 # and these do not have header files, as they are part of the generated
327 # bindings for the interface 341 # bindings for the interface
328 return set() 342 return set()
329 if base_idl_type.endswith('Constructor'): 343 if base_idl_type.endswith('Constructor'):
330 # FIXME: replace with a [ConstructorAttribute] extended attribute 344 # FIXME: replace with a [ConstructorAttribute] extended attribute
331 base_idl_type = idl_type.constructor_type_name 345 base_idl_type = idl_type.constructor_type_name
332 return set(['Dart%s.h' % base_idl_type]) 346 if base_idl_type not in component_dir:
347 return set()
348 return set(['bindings/%s/dart/Dart%s.h' % (component_dir[base_idl_type],
349 base_idl_type)])
333 350
334 IdlType.includes_for_type = property(includes_for_type) 351 IdlType.includes_for_type = property(includes_for_type)
335 IdlUnionType.includes_for_type = property( 352 IdlUnionType.includes_for_type = property(
336 lambda self: set.union(*[includes_for_type(member_type) 353 lambda self: set.union(*[includes_for_type(member_type)
337 for member_type in self.member_types])) 354 for member_type in self.member_types]))
338 355
339 356
340 def add_includes_for_type(idl_type): 357 def add_includes_for_type(idl_type):
341 includes.update(idl_type.includes_for_type) 358 includes.update(idl_type.includes_for_type)
342 359
343 IdlType.add_includes_for_type = add_includes_for_type 360 IdlTypeBase.add_includes_for_type = add_includes_for_type
344 IdlUnionType.add_includes_for_type = add_includes_for_type 361 IdlUnionType.add_includes_for_type = add_includes_for_type
345 362
346 363
347 def includes_for_interface(interface_name): 364 def includes_for_interface(interface_name):
348 return IdlType(interface_name).includes_for_type 365 return IdlType(interface_name).includes_for_type
349 366
350 367
351 def add_includes_for_interface(interface_name): 368 def add_includes_for_interface(interface_name):
352 includes.update(includes_for_interface(interface_name)) 369 includes.update(includes_for_interface(interface_name))
353 370
354 371
372 component_dir = {}
373
374
375 def set_component_dirs(new_component_dirs):
376 component_dir.update(new_component_dirs)
377
378
355 ################################################################################ 379 ################################################################################
356 # Dart -> C++ 380 # Dart -> C++
357 ################################################################################ 381 ################################################################################
358 382
359 # TODO(terry): Need to fix to handle getter/setters for onEvent. 383 # TODO(terry): Need to fix to handle getter/setters for onEvent.
360 DART_FIX_ME = 'DART_UNIMPLEMENTED(/* Conversion unimplemented*/);' 384 DART_FIX_ME = 'DART_UNIMPLEMENTED(/* Conversion unimplemented*/);'
361 385
362 # For a given IDL type, the DartHandle to C++ conversion. 386 # For a given IDL type, the DartHandle to C++ conversion.
363 DART_TO_CPP_VALUE = { 387 DART_TO_CPP_VALUE = {
364 # Basic 388 # Basic
(...skipping 30 matching lines...) Expand all
395 'XPathNSResolver': 'nullptr /* FIXME, DART_TO_CPP_VALUE[XPathNSResolver] */' , 419 'XPathNSResolver': 'nullptr /* FIXME, DART_TO_CPP_VALUE[XPathNSResolver] */' ,
396 # FIXME(vsm): This is an enum type (defined in StorageQuota.idl). 420 # FIXME(vsm): This is an enum type (defined in StorageQuota.idl).
397 # We should handle it automatically, but map to a String for now. 421 # We should handle it automatically, but map to a String for now.
398 'StorageType': 'DartUtilities::dartToString(args, {index}, exception, {auto_ scope})', 422 'StorageType': 'DartUtilities::dartToString(args, {index}, exception, {auto_ scope})',
399 } 423 }
400 424
401 425
402 def dart_value_to_cpp_value(idl_type, interface_extended_attributes, extended_at tributes, variable_name, 426 def dart_value_to_cpp_value(idl_type, interface_extended_attributes, extended_at tributes, variable_name,
403 null_check, index, auto_scope=True): 427 null_check, index, auto_scope=True):
404 # Composite types 428 # Composite types
405 array_or_sequence_type = idl_type.array_or_sequence_type 429 native_array_element_type = idl_type.native_array_element_type
406 if array_or_sequence_type: 430 if native_array_element_type:
407 return dart_value_to_cpp_value_array_or_sequence(array_or_sequence_type, variable_name, index) 431 return dart_value_to_cpp_value_array_or_sequence(native_array_element_ty pe, variable_name, index)
408 432
409 # Simple types 433 # Simple types
410 idl_type = idl_type.preprocessed_type 434 idl_type = idl_type.preprocessed_type
411 add_includes_for_type(idl_type) 435 add_includes_for_type(idl_type)
412 base_idl_type = idl_type.base_type 436 base_idl_type = idl_type.base_type
413 437
414 if 'EnforceRange' in extended_attributes: 438 if 'EnforceRange' in extended_attributes:
415 arguments = ', '.join([variable_name, 'EnforceRange', 'exceptionState']) 439 arguments = ', '.join([variable_name, 'EnforceRange', 'exceptionState'])
416 elif idl_type.is_integer_type: # NormalConversion 440 elif idl_type.is_integer_type: # NormalConversion
417 arguments = ', '.join([variable_name, 'es']) 441 arguments = ', '.join([variable_name, 'es'])
(...skipping 19 matching lines...) Expand all
437 # of this differently, and we may wish to reconsider this approach 461 # of this differently, and we may wish to reconsider this approach
438 null_check = 'WithNullCheck' \ 462 null_check = 'WithNullCheck' \
439 if null_check or allow_null(idl_type, interface_extended_attributes, ext ended_attributes) else '' 463 if null_check or allow_null(idl_type, interface_extended_attributes, ext ended_attributes) else ''
440 return cpp_expression_format.format(null_check=null_check, 464 return cpp_expression_format.format(null_check=null_check,
441 arguments=arguments, 465 arguments=arguments,
442 index=index, 466 index=index,
443 idl_type=base_idl_type, 467 idl_type=base_idl_type,
444 auto_scope=DartUtilities.bool_to_cpp(aut o_scope)) 468 auto_scope=DartUtilities.bool_to_cpp(aut o_scope))
445 469
446 470
447 def dart_value_to_cpp_value_array_or_sequence(array_or_sequence_type, variable_n ame, index): 471 def dart_value_to_cpp_value_array_or_sequence(native_array_element_type, variabl e_name, index):
448 # Index is None for setters, index (starting at 0) for method arguments, 472 # Index is None for setters, index (starting at 0) for method arguments,
449 # and is used to provide a human-readable exception message 473 # and is used to provide a human-readable exception message
450
451 if index is None: 474 if index is None:
452 index = 0 # special case, meaning "setter" 475 index = 0 # special case, meaning "setter"
453 # else: 476 # else:
454 # index += 1 # human-readable index 477 # index += 1 # human-readable index
455 if (array_or_sequence_type.is_interface_type and 478 if (native_array_element_type.is_interface_type and
456 array_or_sequence_type.name != 'Dictionary'): 479 native_array_element_type.name != 'Dictionary'):
457 this_cpp_type = array_or_sequence_type.cpp_type 480 this_cpp_type = None
458 ref_ptr_type = 'Member' if array_or_sequence_type.is_will_be_garbage_col lected else 'RefPtr' 481 ref_ptr_type = cpp_ptr_type('RefPtr', 'Member', native_array_element_typ e.gc_type)
459 # FIXME(vsm): We're not using ref_ptr_type.... 482 # FIXME(vsm): We're not using ref_ptr_type....
460 expression_format = 'DartUtilities::toNativeVector<{cpp_type} >(args, {i ndex}, {variable_name}, exception)' 483 expression_format = 'DartUtilities::toNativeVector<{cpp_type} >(args, {i ndex}, {variable_name}, exception)'
461 add_includes_for_type(array_or_sequence_type) 484 add_includes_for_type(native_array_element_type)
462 else: 485 else:
463 ref_ptr_type = None 486 ref_ptr_type = None
464 this_cpp_type = array_or_sequence_type.cpp_type 487 this_cpp_type = native_array_element_type.cpp_type
465 expression_format = 'DartUtilities::toNativeVector<{cpp_type}>(args, {in dex}, {variable_name}, exception)' 488 expression_format = 'DartUtilities::toNativeVector<{cpp_type}>(args, {in dex}, {variable_name}, exception)'
466 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name, 489
490 expression = expression_format.format(native_array_element_type=native_array _element_type.name,
467 cpp_type=this_cpp_type, index=index, r ef_ptr_type=ref_ptr_type, 491 cpp_type=this_cpp_type, index=index, r ef_ptr_type=ref_ptr_type,
468 variable_name=variable_name) 492 variable_name=variable_name)
469 return expression 493 return expression
470 494
471
472 def dart_value_to_local_cpp_value(idl_type, interface_extended_attributes, exten ded_attributes, 495 def dart_value_to_local_cpp_value(idl_type, interface_extended_attributes, exten ded_attributes,
473 variable_name, null_check, index=None, auto_sc ope=True): 496 variable_name, null_check, index=None, auto_sc ope=True):
474 """Returns an expression that converts a Dart value to a C++ value as a loca l value.""" 497 """Returns an expression that converts a Dart value to a C++ value as a loca l value."""
475 idl_type = idl_type.preprocessed_type 498 idl_type = idl_type.preprocessed_type
476 499
477 cpp_value = dart_value_to_cpp_value( 500 cpp_value = dart_value_to_cpp_value(
478 idl_type, interface_extended_attributes, extended_attributes, 501 idl_type, interface_extended_attributes, extended_attributes,
479 variable_name, null_check, index, auto_scope) 502 variable_name, null_check, index, auto_scope)
480 503
481 return cpp_value 504 return cpp_value
482 505
483 IdlType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value 506 IdlTypeBase.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value
484 IdlUnionType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value 507 #IdlUnionType.dart_value_to_local_cpp_value = dart_value_to_local_cpp_value
485 508
486 509
487 # Insure that we don't use C++ reserved names. Today on default is a problem. 510 # Insure that we don't use C++ reserved names. Today on default is a problem.
488 def check_reserved_name(name): 511 def check_reserved_name(name):
489 return 'default_value' if (name == 'default') else name 512 return 'default_value' if (name == 'default') else name
490 513
491 514
492 ################################################################################ 515 ################################################################################
493 # C++ -> V8 516 # C++ -> V8
494 ################################################################################ 517 ################################################################################
495 518
496 def preprocess_idl_type(idl_type): 519 def preprocess_idl_type(idl_type):
497 if idl_type.is_enum: 520 if idl_type.is_enum:
498 # Enumerations are internally DOMStrings 521 # Enumerations are internally DOMStrings
499 return IdlType('DOMString') 522 return IdlType('DOMString')
500 if (idl_type.name == 'Any' or idl_type.is_callback_function): 523 if (idl_type.name == 'Any' or idl_type.is_callback_function):
501 return IdlType('ScriptValue') 524 return IdlType('ScriptValue')
502 return idl_type 525 return idl_type
503 526
504 IdlType.preprocessed_type = property(preprocess_idl_type) 527 IdlTypeBase.preprocessed_type = property(preprocess_idl_type)
505 IdlUnionType.preprocessed_type = property(preprocess_idl_type) 528 IdlUnionType.preprocessed_type = property(preprocess_idl_type)
506 529
507 530
508 def preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes): 531 def preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes):
509 """Returns IDL type and value, with preliminary type conversions applied.""" 532 """Returns IDL type and value, with preliminary type conversions applied."""
510 idl_type = idl_type.preprocessed_type 533 idl_type = idl_type.preprocessed_type
511 if idl_type.name == 'Promise': 534 if idl_type.name == 'Promise':
512 idl_type = IdlType('ScriptValue') 535 idl_type = IdlType('ScriptValue')
513 # FIXME(vsm): V8 maps 'long long' and 'unsigned long long' to double 536 # FIXME(vsm): V8 maps 'long long' and 'unsigned long long' to double
514 # as they are not representable in ECMAScript. Should we do the same? 537 # as they are not representable in ECMAScript. Should we do the same?
(...skipping 13 matching lines...) Expand all
528 def dart_conversion_type(idl_type, extended_attributes): 551 def dart_conversion_type(idl_type, extended_attributes):
529 """Returns Dart conversion type, adding any additional includes. 552 """Returns Dart conversion type, adding any additional includes.
530 553
531 The Dart conversion type is used to select the C++ -> Dart conversion functi on 554 The Dart conversion type is used to select the C++ -> Dart conversion functi on
532 or setDart*ReturnValue function; it can be an idl_type, a cpp_type, or a 555 or setDart*ReturnValue function; it can be an idl_type, a cpp_type, or a
533 separate name for the type of conversion (e.g., 'DOMWrapper'). 556 separate name for the type of conversion (e.g., 'DOMWrapper').
534 """ 557 """
535 extended_attributes = extended_attributes or {} 558 extended_attributes = extended_attributes or {}
536 559
537 # Composite types 560 # Composite types
538 array_or_sequence_type = idl_type.array_or_sequence_type 561 native_array_element_type = idl_type.native_array_element_type
539 if array_or_sequence_type: 562 if native_array_element_type:
540 if array_or_sequence_type.is_interface_type: 563 if native_array_element_type.is_interface_type:
541 add_includes_for_type(array_or_sequence_type) 564 add_includes_for_type(native_array_element_type)
542 return 'array' 565 return 'array'
543 566
544 # Simple types 567 # Simple types
545 base_idl_type = idl_type.base_type 568 base_idl_type = idl_type.base_type
546 # Basic types, without additional includes 569 # Basic types, without additional includes
547 if base_idl_type in CPP_INT_TYPES or base_idl_type == 'long long': 570 if base_idl_type in CPP_INT_TYPES or base_idl_type == 'long long':
548 return 'int' 571 return 'int'
549 if base_idl_type in CPP_UNSIGNED_TYPES or base_idl_type == 'unsigned long lo ng': 572 if base_idl_type in CPP_UNSIGNED_TYPES or base_idl_type == 'unsigned long lo ng':
550 return 'unsigned' 573 return 'unsigned'
551 if base_idl_type == 'DOMString': 574 if base_idl_type == 'DOMString':
(...skipping 16 matching lines...) Expand all
568 # Typed arrays don't have special Dart* classes for Dart. 591 # Typed arrays don't have special Dart* classes for Dart.
569 if idl_type.is_typed_array_type: 592 if idl_type.is_typed_array_type:
570 if base_idl_type == 'ArrayBuffer': 593 if base_idl_type == 'ArrayBuffer':
571 return 'ArrayBuffer' 594 return 'ArrayBuffer'
572 else: 595 else:
573 return 'TypedList' 596 return 'TypedList'
574 597
575 # Pointer type 598 # Pointer type
576 return 'DOMWrapper' 599 return 'DOMWrapper'
577 600
578 IdlType.dart_conversion_type = dart_conversion_type 601 IdlTypeBase.dart_conversion_type = dart_conversion_type
579 602
580 603
581 DART_SET_RETURN_VALUE = { 604 DART_SET_RETURN_VALUE = {
582 'boolean': 'Dart_SetBooleanReturnValue(args, {cpp_value})', 605 'boolean': 'Dart_SetBooleanReturnValue(args, {cpp_value})',
583 'int': 'DartUtilities::setDartIntegerReturnValue(args, {cpp_value})', 606 'int': 'DartUtilities::setDartIntegerReturnValue(args, {cpp_value})',
584 'unsigned': 'DartUtilities::setDartUnsignedLongLongReturnValue(args, {cpp_va lue})', 607 'unsigned': 'DartUtilities::setDartUnsignedLongLongReturnValue(args, {cpp_va lue})',
585 'DOMString': 'DartUtilities::setDartStringReturnValue(args, {cpp_value}, {au to_scope})', 608 'DOMString': 'DartUtilities::setDartStringReturnValue(args, {cpp_value}, {au to_scope})',
586 # FIXME(terry): Need to handle checking to byte values > 255 throwing except ion. 609 # FIXME(terry): Need to handle checking to byte values > 255 throwing except ion.
587 'ByteString': 'DartUtilities::setDartByteStringReturnValue(args, {cpp_value} , {auto_scope})', 610 'ByteString': 'DartUtilities::setDartByteStringReturnValue(args, {cpp_value} , {auto_scope})',
588 # FIXME(terry): Need to make valid unicode; match UTF-16 to U+FFFD REPLACEM ENT CHARACTER. 611 # FIXME(terry): Need to make valid unicode; match UTF-16 to U+FFFD REPLACEM ENT CHARACTER.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 this_dart_conversion_type = idl_type.dart_conversion_type(extended_attribute s) 658 this_dart_conversion_type = idl_type.dart_conversion_type(extended_attribute s)
636 # SetReturn-specific overrides 659 # SetReturn-specific overrides
637 if this_dart_conversion_type in ['Date', 'EventHandler', 'ScriptValue', 'Ser ializedScriptValue', 'array']: 660 if this_dart_conversion_type in ['Date', 'EventHandler', 'ScriptValue', 'Ser ializedScriptValue', 'array']:
638 # Convert value to Dart and then use general Dart_SetReturnValue 661 # Convert value to Dart and then use general Dart_SetReturnValue
639 # FIXME(vsm): Why do we differ from V8 here? It doesn't have a 662 # FIXME(vsm): Why do we differ from V8 here? It doesn't have a
640 # creation_context. 663 # creation_context.
641 creation_context = '' 664 creation_context = ''
642 if this_dart_conversion_type == 'array': 665 if this_dart_conversion_type == 'array':
643 # FIXME: This is not right if the base type is a primitive, DOMStrin g, etc. 666 # FIXME: This is not right if the base type is a primitive, DOMStrin g, etc.
644 # What is the right check for base type? 667 # What is the right check for base type?
645 if idl_type.base_type not in DART_TO_CPP_VALUE: 668 base_type = str(idl_type.element_type)
646 creation_context = '<Dart%s>' % idl_type.base_type 669 if base_type not in DART_TO_CPP_VALUE:
670 if base_type == 'None':
671 raise Exception('Unknown base type for ' + str(idl_type))
672 creation_context = '<Dart%s>' % base_type
673 if idl_type.is_nullable:
674 creation_context = 'Nullable' + creation_context
647 675
648 cpp_value = idl_type.cpp_value_to_dart_value(cpp_value, creation_context =creation_context, 676 cpp_value = idl_type.cpp_value_to_dart_value(cpp_value, creation_context =creation_context,
649 extended_attributes=extende d_attributes) 677 extended_attributes=extende d_attributes)
650 if this_dart_conversion_type == 'DOMWrapper': 678 if this_dart_conversion_type == 'DOMWrapper':
651 this_dart_conversion_type = dom_wrapper_conversion_type() 679 this_dart_conversion_type = dom_wrapper_conversion_type()
652 680
653 format_string = DART_SET_RETURN_VALUE[this_dart_conversion_type] 681 format_string = DART_SET_RETURN_VALUE[this_dart_conversion_type]
654 682
655 if release: 683 if release:
656 cpp_value = '%s.release()' % cpp_value 684 cpp_value = '%s.release()' % cpp_value
(...skipping 16 matching lines...) Expand all
673 # FIXME(vsm): Why do we use 'result' instead of cpp_value as V8? 701 # FIXME(vsm): Why do we use 'result' instead of cpp_value as V8?
674 member_type.dart_set_return_value('result' + str(i), 702 member_type.dart_set_return_value('result' + str(i),
675 extended_attributes, 703 extended_attributes,
676 script_wrappable, 704 script_wrappable,
677 release and release[i], 705 release and release[i],
678 for_main_world, 706 for_main_world,
679 auto_scope) 707 auto_scope)
680 for i, member_type in 708 for i, member_type in
681 enumerate(idl_type.member_types)] 709 enumerate(idl_type.member_types)]
682 710
683 IdlType.dart_set_return_value = dart_set_return_value 711 IdlTypeBase.dart_set_return_value = dart_set_return_value
684 IdlUnionType.dart_set_return_value = dart_set_return_value_union 712 IdlUnionType.dart_set_return_value = dart_set_return_value_union
685 713
686 IdlType.release = property(lambda self: self.is_interface_type) 714 IdlType.release = property(lambda self: self.is_interface_type)
687 IdlUnionType.release = property( 715 IdlUnionType.release = property(
688 lambda self: [member_type.is_interface_type 716 lambda self: [member_type.is_interface_type
689 for member_type in self.member_types]) 717 for member_type in self.member_types])
690 718
691 719
692 CPP_VALUE_TO_DART_VALUE = { 720 CPP_VALUE_TO_DART_VALUE = {
693 # Built-in types 721 # Built-in types
(...skipping 24 matching lines...) Expand all
718 """Returns an expression that converts a C++ value to a Dart value.""" 746 """Returns an expression that converts a C++ value to a Dart value."""
719 # the isolate parameter is needed for callback interfaces 747 # the isolate parameter is needed for callback interfaces
720 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 748 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
721 this_dart_conversion_type = idl_type.dart_conversion_type(extended_attribute s) 749 this_dart_conversion_type = idl_type.dart_conversion_type(extended_attribute s)
722 format_string = CPP_VALUE_TO_DART_VALUE[this_dart_conversion_type] 750 format_string = CPP_VALUE_TO_DART_VALUE[this_dart_conversion_type]
723 statement = format_string.format( 751 statement = format_string.format(
724 cpp_value=cpp_value, creation_context=creation_context, 752 cpp_value=cpp_value, creation_context=creation_context,
725 idl_type=idl_type.base_type) 753 idl_type=idl_type.base_type)
726 return statement 754 return statement
727 755
728 IdlType.cpp_value_to_dart_value = cpp_value_to_dart_value 756 IdlTypeBase.cpp_value_to_dart_value = cpp_value_to_dart_value
729 757
730 758
731 # Override idl_type.name to not suffix orNull to the name, in Dart we always 759 # Override idl_type.name to not suffix orNull to the name, in Dart we always
732 # test for null e.g., 760 # test for null e.g.,
733 # 761 #
734 # bool isNull = false; 762 # bool isNull = false;
735 # TYPE* result = receiver->GETTER(isNull); 763 # TYPE* result = receiver->GETTER(isNull);
736 # if (isNull) 764 # if (isNull)
737 # return; 765 # return;
738 # 766 #
739 def dart_name(idl_type): 767 def dart_name(idl_type):
740 """Return type name. 768 """Return type name.
741 769
742 http://heycam.github.io/webidl/#dfn-type-name 770 http://heycam.github.io/webidl/#dfn-type-name
743 """ 771 """
744 base_type = idl_type.base_type 772 base_type = idl_type.base_type
745 base_type_name = TYPE_NAMES.get(base_type, base_type) 773 base_type_name = TYPE_NAMES.get(base_type, base_type)
746 if idl_type.is_array: 774 if idl_type.native_array_element_type:
747 return base_type_name + 'Array' 775 return idl_type.inner_name()
748 if idl_type.is_sequence:
749 return base_type_name + 'Sequence'
750 return base_type_name 776 return base_type_name
751 777
752 IdlType.name = property(dart_name) 778 IdlType.name = property(dart_name)
753 IdlUnionType.name = property(dart_name) 779 IdlUnionType.name = property(dart_name)
754 780
755 781
756 def typechecked_interface(extended_attributes): 782 def typechecked_interface(extended_attributes):
757 return ('TypeChecking' in extended_attributes and\ 783 return ('TypeChecking' in extended_attributes and\
758 DartUtilities.extended_attribute_value_contains(extended_attributes[ 'TypeChecking'], 'Interface')) 784 DartUtilities.extended_attribute_value_contains(extended_attributes[ 'TypeChecking'], 'Interface'))
759 785
(...skipping 26 matching lines...) Expand all
786 else: 812 else:
787 # This logic is implemented in the methods.cpp template in V8 813 # This logic is implemented in the methods.cpp template in V8
788 if (idl_type.is_nullable or 814 if (idl_type.is_nullable or
789 (not typechecked_argument(idl_type, interface_extended_attributes, ex tended_attributes))): 815 (not typechecked_argument(idl_type, interface_extended_attributes, ex tended_attributes))):
790 return True 816 return True
791 817
792 if extended_attributes.get('Default') == 'Undefined': 818 if extended_attributes.get('Default') == 'Undefined':
793 return True 819 return True
794 820
795 return False 821 return False
OLDNEW
« no previous file with comments | « bindings/dart/scripts/dart_methods.py ('k') | bindings/dart/scripts/dart_utilities.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698