| OLD | NEW |
| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 'Promise': 'ScriptPromise', | 113 'Promise': 'ScriptPromise', |
| 114 'ScriptValue': 'ScriptValue', | 114 'ScriptValue': 'ScriptValue', |
| 115 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 | 115 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345
529 |
| 116 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', | 116 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', |
| 117 'boolean': 'bool', | 117 'boolean': 'bool', |
| 118 'unrestricted double': 'double', | 118 'unrestricted double': 'double', |
| 119 'unrestricted float': 'float', | 119 'unrestricted float': 'float', |
| 120 } | 120 } |
| 121 | 121 |
| 122 | 122 |
| 123 def cpp_type(idl_type, extended_attributes=None, raw_type=False, used_as_argumen
t=False, used_as_variadic_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_as_variadic_argument=False, used_in_cpp_sequence=False): |
| 124 """Returns C++ type corresponding to IDL type. | 124 """Returns C++ type corresponding to IDL type. |
| 125 | 125 |
| 126 |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 |
| 127 | 127 |
| 128 Args: | 128 Args: |
| 129 idl_type: | 129 idl_type: |
| 130 IdlType | 130 IdlType |
| 131 raw_type: | 131 raw_type: |
| 132 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. |
| 133 used_as_argument: | 133 used_as_rvalue_type: |
| 134 bool, True if the C++ type is used as an argument of a method. | 134 bool, True if the C++ type is used as an argument or the return |
| 135 type of a method. |
| 135 used_as_variadic_argument: | 136 used_as_variadic_argument: |
| 136 bool, True if the C++ type is used as a variadic argument of a metho
d. | 137 bool, True if the C++ type is used as a variadic argument of a metho
d. |
| 137 used_in_cpp_sequence: | 138 used_in_cpp_sequence: |
| 138 bool, True if the C++ type is used as an element of an array or sequ
ence. | 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. |
| 139 """ | 141 """ |
| 140 def string_mode(): | 142 def string_mode(): |
| 141 if extended_attributes.get('TreatNullAs') == 'EmptyString': | 143 if extended_attributes.get('TreatNullAs') == 'EmptyString': |
| 142 return 'TreatNullAsEmptyString' | 144 return 'TreatNullAsEmptyString' |
| 143 if idl_type.is_nullable or extended_attributes.get('TreatNullAs') == 'Nu
llString': | 145 if idl_type.is_nullable or extended_attributes.get('TreatNullAs') == 'Nu
llString': |
| 144 if extended_attributes.get('TreatUndefinedAs') == 'NullString': | 146 if extended_attributes.get('TreatUndefinedAs') == 'NullString': |
| 145 return 'TreatNullAndUndefinedAsNullString' | 147 return 'TreatNullAndUndefinedAsNullString' |
| 146 return 'TreatNullAsNullString' | 148 return 'TreatNullAsNullString' |
| 147 return '' | 149 return '' |
| 148 | 150 |
| 149 extended_attributes = extended_attributes or {} | 151 extended_attributes = extended_attributes or {} |
| 150 idl_type = idl_type.preprocessed_type | 152 idl_type = idl_type.preprocessed_type |
| 151 | 153 |
| 152 # Composite types | 154 # Composite types |
| 153 if used_as_variadic_argument: | 155 if used_as_variadic_argument: |
| 154 native_array_element_type = idl_type | 156 native_array_element_type = idl_type |
| 155 else: | 157 else: |
| 156 native_array_element_type = idl_type.native_array_element_type | 158 native_array_element_type = idl_type.native_array_element_type |
| 157 if native_array_element_type: | 159 if native_array_element_type: |
| 158 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_
type.gc_type) | 160 vector_type = cpp_ptr_type('Vector', 'HeapVector', native_array_element_
type.gc_type) |
| 159 return cpp_template_type(vector_type, native_array_element_type.cpp_type
_args(used_in_cpp_sequence=True)) | 161 vector_template_type = cpp_template_type(vector_type, native_array_eleme
nt_type.cpp_type_args(used_in_cpp_sequence=True)) |
| 162 return vector_template_type |
| 160 | 163 |
| 161 # Simple types | 164 # Simple types |
| 162 base_idl_type = idl_type.base_type | 165 base_idl_type = idl_type.base_type |
| 163 | 166 |
| 164 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: | 167 if base_idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: |
| 165 return base_idl_type | 168 return base_idl_type |
| 166 if base_idl_type in CPP_INT_TYPES: | 169 if base_idl_type in CPP_INT_TYPES: |
| 167 return 'int' | 170 return 'int' |
| 168 if base_idl_type in CPP_UNSIGNED_TYPES: | 171 if base_idl_type in CPP_UNSIGNED_TYPES: |
| 169 return 'unsigned' | 172 return 'unsigned' |
| 170 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: | 173 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: |
| 171 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] | 174 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] |
| 172 | 175 |
| 173 if base_idl_type in NON_WRAPPER_TYPES: | 176 if base_idl_type in NON_WRAPPER_TYPES: |
| 174 return ('PassRefPtr<%s>' if used_as_argument else 'RefPtr<%s>') % base_i
dl_type | 177 return ('PassRefPtr<%s>' if used_as_rvalue_type else 'RefPtr<%s>') % bas
e_idl_type |
| 175 if idl_type.is_string_type: | 178 if idl_type.is_string_type: |
| 176 if not raw_type: | 179 if not raw_type: |
| 177 return 'String' | 180 return 'String' |
| 178 return 'V8StringResource<%s>' % string_mode() | 181 return 'V8StringResource<%s>' % string_mode() |
| 179 | 182 |
| 180 if idl_type.is_typed_array_element_type and raw_type: | 183 if idl_type.is_typed_array_element_type and raw_type: |
| 181 return base_idl_type + '*' | 184 return base_idl_type + '*' |
| 182 if idl_type.is_interface_type: | 185 if idl_type.is_interface_type: |
| 183 implemented_as_class = idl_type.implemented_as | 186 implemented_as_class = idl_type.implemented_as |
| 184 if raw_type: | 187 if raw_type: |
| 185 return implemented_as_class + '*' | 188 return implemented_as_class + '*' |
| 186 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' | 189 new_type = 'Member' if used_in_cpp_sequence else 'RawPtr' |
| 187 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_argument else 'RefPtr')
, new_type, idl_type.gc_type) | 190 ptr_type = cpp_ptr_type(('PassRefPtr' if used_as_rvalue_type else 'RefPt
r'), new_type, idl_type.gc_type) |
| 188 return cpp_template_type(ptr_type, implemented_as_class) | 191 return cpp_template_type(ptr_type, implemented_as_class) |
| 189 # Default, assume native type is a pointer with same type name as idl type | 192 # Default, assume native type is a pointer with same type name as idl type |
| 190 return base_idl_type + '*' | 193 return base_idl_type + '*' |
| 191 | 194 |
| 192 | 195 |
| 193 def cpp_type_initializer(idl_type): | 196 def cpp_type_initializer(idl_type): |
| 194 """Returns a string containing a C++ initialization statement for the | 197 """Returns a string containing a C++ initialization statement for the |
| 195 corresponding type. | 198 corresponding type. |
| 196 | 199 |
| 197 |idl_type| argument is of type IdlType. | 200 |idl_type| argument is of type IdlType. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 IdlUnionType.add_includes_for_type = add_includes_for_type | 383 IdlUnionType.add_includes_for_type = add_includes_for_type |
| 381 | 384 |
| 382 | 385 |
| 383 def includes_for_interface(interface_name): | 386 def includes_for_interface(interface_name): |
| 384 return IdlType(interface_name).includes_for_type | 387 return IdlType(interface_name).includes_for_type |
| 385 | 388 |
| 386 | 389 |
| 387 def add_includes_for_interface(interface_name): | 390 def add_includes_for_interface(interface_name): |
| 388 includes.update(includes_for_interface(interface_name)) | 391 includes.update(includes_for_interface(interface_name)) |
| 389 | 392 |
| 393 |
| 394 def impl_should_use_nullable_container(idl_type): |
| 395 return idl_type.native_array_element_type or idl_type.is_primitive_type |
| 396 |
| 397 IdlType.impl_should_use_nullable_container = property( |
| 398 impl_should_use_nullable_container) |
| 399 |
| 400 |
| 401 def impl_includes_for_type(idl_type, interfaces_info): |
| 402 includes_for_type = set() |
| 403 if idl_type.impl_should_use_nullable_container: |
| 404 includes_for_type.add('bindings/core/v8/Nullable.h') |
| 405 |
| 406 idl_type = idl_type.preprocessed_type |
| 407 native_array_element_type = idl_type.native_array_element_type |
| 408 if native_array_element_type: |
| 409 includes_for_type.update(impl_includes_for_type( |
| 410 native_array_element_type, interfaces_info)) |
| 411 includes_for_type.add('wtf/Vector.h') |
| 412 |
| 413 if idl_type.is_string_type: |
| 414 includes_for_type.add('wtf/text/WTFString.h') |
| 415 if idl_type.name in interfaces_info: |
| 416 interface_info = interfaces_info[idl_type.name] |
| 417 includes_for_type.add(interface_info['include_path']) |
| 418 return includes_for_type |
| 419 |
| 420 IdlType.impl_includes_for_type = impl_includes_for_type |
| 421 |
| 422 |
| 390 component_dir = {} | 423 component_dir = {} |
| 391 | 424 |
| 392 | 425 |
| 393 def set_component_dirs(new_component_dirs): | 426 def set_component_dirs(new_component_dirs): |
| 394 component_dir.update(new_component_dirs) | 427 component_dir.update(new_component_dirs) |
| 395 | 428 |
| 396 | 429 |
| 397 ################################################################################ | 430 ################################################################################ |
| 398 # V8 -> C++ | 431 # V8 -> C++ |
| 399 ################################################################################ | 432 ################################################################################ |
| 400 | 433 |
| 401 V8_VALUE_TO_CPP_VALUE = { | 434 V8_VALUE_TO_CPP_VALUE = { |
| 402 # Basic | 435 # Basic |
| 403 'Date': 'toCoreDate({v8_value})', | 436 'Date': 'toCoreDate({v8_value})', |
| 404 'DOMString': '{v8_value}', | 437 'DOMString': '{v8_value}', |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 796 |
| 764 def is_explicit_nullable(idl_type): | 797 def is_explicit_nullable(idl_type): |
| 765 # Nullable type that isn't implicit nullable (see above.) For such types, | 798 # Nullable type that isn't implicit nullable (see above.) For such types, |
| 766 # we use Nullable<T> or similar explicit ways to represent a null value. | 799 # we use Nullable<T> or similar explicit ways to represent a null value. |
| 767 return idl_type.is_nullable and not idl_type.is_implicit_nullable | 800 return idl_type.is_nullable and not idl_type.is_implicit_nullable |
| 768 | 801 |
| 769 IdlType.is_implicit_nullable = property(is_implicit_nullable) | 802 IdlType.is_implicit_nullable = property(is_implicit_nullable) |
| 770 IdlType.is_explicit_nullable = property(is_explicit_nullable) | 803 IdlType.is_explicit_nullable = property(is_explicit_nullable) |
| 771 IdlUnionType.is_implicit_nullable = False | 804 IdlUnionType.is_implicit_nullable = False |
| 772 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) | 805 IdlUnionType.is_explicit_nullable = property(is_explicit_nullable) |
| OLD | NEW |