Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generate template contexts of dictionaries for both v8 bindings and | 5 """Generate template contexts of dictionaries for both v8 bindings and |
| 6 implementation classes that are used by blink's core/modules. | 6 implementation classes that are used by blink's core/modules. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import operator | 9 import operator |
| 10 from idl_types import IdlType | |
| 10 from v8_globals import includes | 11 from v8_globals import includes |
| 11 import v8_types | 12 import v8_types |
| 12 import v8_utilities | 13 import v8_utilities |
| 13 | 14 |
| 14 | 15 |
| 15 DICTIONARY_H_INCLUDES = frozenset([ | 16 DICTIONARY_H_INCLUDES = frozenset([ |
| 16 'bindings/core/v8/V8Binding.h', | 17 'bindings/core/v8/V8Binding.h', |
| 17 'platform/heap/Handle.h', | 18 'platform/heap/Handle.h', |
| 18 ]) | 19 ]) |
| 19 | 20 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 35 | 36 |
| 36 | 37 |
| 37 def unwrap_nullable_if_needed(idl_type): | 38 def unwrap_nullable_if_needed(idl_type): |
| 38 if idl_type.is_nullable: | 39 if idl_type.is_nullable: |
| 39 return idl_type.inner_type | 40 return idl_type.inner_type |
| 40 return idl_type | 41 return idl_type |
| 41 | 42 |
| 42 | 43 |
| 43 # Context for V8 bindings | 44 # Context for V8 bindings |
| 44 | 45 |
| 45 def dictionary_context(dictionary): | 46 def dictionary_context(dictionary, interfaces_info): |
| 46 includes.clear() | 47 includes.clear() |
| 47 includes.update(DICTIONARY_CPP_INCLUDES) | 48 includes.update(DICTIONARY_CPP_INCLUDES) |
| 48 return { | 49 cpp_class = v8_utilities.cpp_name(dictionary) |
| 49 'cpp_class': v8_utilities.cpp_name(dictionary), | 50 context = { |
| 51 'cpp_class': cpp_class, | |
| 50 'header_includes': set(DICTIONARY_H_INCLUDES), | 52 'header_includes': set(DICTIONARY_H_INCLUDES), |
| 51 'members': [member_context(member) | 53 'members': [member_context(member) |
| 52 for member in sorted(dictionary.members, | 54 for member in sorted(dictionary.members, |
| 53 key=operator.attrgetter('name'))], | 55 key=operator.attrgetter('name'))], |
| 54 'v8_class': v8_utilities.v8_class_name(dictionary), | 56 'v8_class': 'V8' + cpp_class, |
|
haraken
2014/11/19 09:11:26
v8_types.v8_type(cpp_class) ?
bashi
2014/11/19 11:04:42
Done.
| |
| 55 } | 57 } |
| 58 if dictionary.parent: | |
| 59 IdlType(dictionary.parent).add_includes_for_type() | |
| 60 parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( | |
| 61 dictionary.parent, interfaces_info) | |
| 62 context.update({ | |
| 63 'parent_cpp_class': parent_cpp_class, | |
| 64 'parent_v8_class': 'V8' + parent_cpp_class, | |
|
haraken
2014/11/19 09:11:26
v8_types.v8_type(parent_cpp_class) ?
bashi
2014/11/19 11:04:42
Done.
| |
| 65 }) | |
| 66 return context | |
| 56 | 67 |
| 57 | 68 |
| 58 def member_context(member): | 69 def member_context(member): |
| 59 idl_type = member.idl_type | 70 idl_type = member.idl_type |
| 60 idl_type.add_includes_for_type() | 71 idl_type.add_includes_for_type() |
| 61 idl_type = unwrap_nullable_if_needed(idl_type) | 72 idl_type = unwrap_nullable_if_needed(idl_type) |
| 62 | 73 |
| 63 def default_values(): | 74 def default_values(): |
| 64 if not member.default_value: | 75 if not member.default_value: |
| 65 return None, None | 76 return None, None |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 89 'setter_name': setter_name_for_dictionary_member(member), | 100 'setter_name': setter_name_for_dictionary_member(member), |
| 90 'v8_default_value': v8_default_value, | 101 'v8_default_value': v8_default_value, |
| 91 } | 102 } |
| 92 | 103 |
| 93 | 104 |
| 94 # Context for implementation classes | 105 # Context for implementation classes |
| 95 | 106 |
| 96 def dictionary_impl_context(dictionary, interfaces_info): | 107 def dictionary_impl_context(dictionary, interfaces_info): |
| 97 includes.clear() | 108 includes.clear() |
| 98 header_includes = set(['platform/heap/Handle.h']) | 109 header_includes = set(['platform/heap/Handle.h']) |
| 99 return { | 110 context = { |
| 100 'header_includes': header_includes, | 111 'header_includes': header_includes, |
| 101 'cpp_class': v8_utilities.cpp_name(dictionary), | 112 'cpp_class': v8_utilities.cpp_name(dictionary), |
| 102 'members': [member_impl_context(member, interfaces_info, | 113 'members': [member_impl_context(member, interfaces_info, |
| 103 header_includes) | 114 header_includes) |
| 104 for member in dictionary.members], | 115 for member in dictionary.members], |
| 105 } | 116 } |
| 117 if dictionary.parent: | |
| 118 context['parent_cpp_class'] = v8_utilities.cpp_name_from_interfaces_info ( | |
| 119 dictionary.parent, interfaces_info) | |
| 120 parent_interface_info = interfaces_info.get(dictionary.parent) | |
| 121 if parent_interface_info: | |
| 122 context['header_includes'].add( | |
| 123 parent_interface_info['include_path']) | |
| 124 return context | |
| 106 | 125 |
| 107 | 126 |
| 108 def member_impl_context(member, interfaces_info, header_includes): | 127 def member_impl_context(member, interfaces_info, header_includes): |
| 109 idl_type = unwrap_nullable_if_needed(member.idl_type) | 128 idl_type = unwrap_nullable_if_needed(member.idl_type) |
| 110 is_object = idl_type.name == 'Object' | 129 is_object = idl_type.name == 'Object' |
| 111 cpp_name = v8_utilities.cpp_name(member) | 130 cpp_name = v8_utilities.cpp_name(member) |
| 112 | 131 |
| 113 def getter_expression(): | 132 def getter_expression(): |
| 114 if idl_type.impl_should_use_nullable_container: | 133 if idl_type.impl_should_use_nullable_container: |
| 115 return 'm_%s.get()' % cpp_name | 134 return 'm_%s.get()' % cpp_name |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 139 'cpp_name': cpp_name, | 158 'cpp_name': cpp_name, |
| 140 'getter_expression': getter_expression(), | 159 'getter_expression': getter_expression(), |
| 141 'has_method_expression': has_method_expression(), | 160 'has_method_expression': has_method_expression(), |
| 142 'has_method_name': has_method_name_for_dictionary_member(member), | 161 'has_method_name': has_method_name_for_dictionary_member(member), |
| 143 'is_object': is_object, | 162 'is_object': is_object, |
| 144 'is_traceable': idl_type.is_traceable, | 163 'is_traceable': idl_type.is_traceable, |
| 145 'member_cpp_type': member_cpp_type(), | 164 'member_cpp_type': member_cpp_type(), |
| 146 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 165 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
| 147 'setter_name': setter_name_for_dictionary_member(member), | 166 'setter_name': setter_name_for_dictionary_member(member), |
| 148 } | 167 } |
| OLD | NEW |