| 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 import v8_types | |
| 6 import v8_utilities | 5 import v8_utilities |
| 7 | 6 |
| 8 | 7 |
| 9 UNION_CPP_INCLUDES = frozenset([ | |
| 10 'bindings/core/v8/ToV8.h', | |
| 11 ]) | |
| 12 | |
| 13 UNION_H_INCLUDES = frozenset([ | 8 UNION_H_INCLUDES = frozenset([ |
| 14 'bindings/core/v8/Dictionary.h', | 9 'bindings/core/v8/Dictionary.h', |
| 15 'bindings/core/v8/ExceptionState.h', | 10 'bindings/core/v8/ExceptionState.h', |
| 16 'bindings/core/v8/V8Binding.h', | 11 'bindings/core/v8/V8Binding.h', |
| 17 'platform/heap/Handle.h', | 12 'platform/heap/Handle.h', |
| 18 ]) | 13 ]) |
| 19 | 14 |
| 20 UNION_CPP_INCLUDES_BLACKLIST = frozenset([ | 15 UNION_CPP_INCLUDES_BLACKLIST = frozenset([ |
| 21 # This header defines static functions needed to implement event handler | 16 # This header defines static functions needed to implement event handler |
| 22 # attributes in interfaces that implement GlobalEventHandlers. They are not | 17 # attributes in interfaces that implement GlobalEventHandlers. They are not |
| 23 # needed or used by UnionTypes*.cpp, so including the header causes | 18 # needed or used by UnionTypes*.cpp, so including the header causes |
| 24 # compilation errors. | 19 # compilation errors. |
| 25 # FIXME: We should solve this problem in a way that doesn't involve special- | 20 # FIXME: We should solve this problem in a way that doesn't involve special- |
| 26 # casing a header like this. | 21 # casing a header like this. |
| 27 'core/dom/GlobalEventHandlers.h', | 22 'core/dom/GlobalEventHandlers.h', |
| 28 ]) | 23 ]) |
| 29 | 24 |
| 30 | 25 |
| 31 cpp_includes = set() | 26 cpp_includes = set() |
| 32 header_forward_decls = set() | 27 header_forward_decls = set() |
| 33 header_includes = set() | 28 header_includes = set() |
| 34 | 29 |
| 35 | 30 |
| 36 def container_context(union_type, interfaces_info): | 31 def union_context(union_types, interfaces_info): |
| 37 cpp_includes.clear() | 32 cpp_includes.clear() |
| 38 header_forward_decls.clear() | 33 header_forward_decls.clear() |
| 39 header_includes.clear() | 34 header_includes.clear() |
| 40 cpp_includes.update(UNION_CPP_INCLUDES) | |
| 41 header_includes.update(UNION_H_INCLUDES) | 35 header_includes.update(UNION_H_INCLUDES) |
| 36 |
| 37 # For container classes we strip nullable wrappers. For example, |
| 38 # both (A or B)? and (A? or B) will become AOrB. This should be OK |
| 39 # because container classes can handle null and it seems that |
| 40 # distinguishing (A or B)? and (A? or B) doesn't make sense. |
| 41 container_cpp_types = set() |
| 42 union_types_for_containers = set() |
| 43 for union_type in union_types: |
| 44 cpp_type = union_type.cpp_type |
| 45 if cpp_type not in container_cpp_types: |
| 46 union_types_for_containers.add(union_type) |
| 47 container_cpp_types.add(cpp_type) |
| 48 |
| 49 union_types_for_containers = sorted(union_types_for_containers, |
| 50 key=lambda union_type: union_type.cpp_ty
pe) |
| 51 |
| 52 return { |
| 53 'containers': [container_context(union_type, interfaces_info) |
| 54 for union_type in union_types_for_containers], |
| 55 'cpp_includes': sorted(cpp_includes - UNION_CPP_INCLUDES_BLACKLIST), |
| 56 'header_forward_decls': sorted(header_forward_decls), |
| 57 'header_includes': sorted(header_includes), |
| 58 } |
| 59 |
| 60 |
| 61 def container_context(union_type, interfaces_info): |
| 42 members = [] | 62 members = [] |
| 43 | 63 |
| 44 # These variables refer to member contexts if the given union type has | 64 # These variables refer to member contexts if the given union type has |
| 45 # corresponding types. They are used for V8 -> impl conversion. | 65 # corresponding types. They are used for V8 -> impl conversion. |
| 46 array_buffer_type = None | 66 array_buffer_type = None |
| 47 array_buffer_view_type = None | 67 array_buffer_view_type = None |
| 48 array_or_sequence_type = None | 68 array_or_sequence_type = None |
| 49 boolean_type = None | 69 boolean_type = None |
| 50 dictionary_type = None | 70 dictionary_type = None |
| 51 interface_types = [] | 71 interface_types = [] |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 else: | 107 else: |
| 88 raise Exception('%s is not supported as an union member.' % member.n
ame) | 108 raise Exception('%s is not supported as an union member.' % member.n
ame) |
| 89 | 109 |
| 90 # Nullable restriction checks | 110 # Nullable restriction checks |
| 91 nullable_members = union_type.number_of_nullable_member_types | 111 nullable_members = union_type.number_of_nullable_member_types |
| 92 if nullable_members > 1: | 112 if nullable_members > 1: |
| 93 raise Exception('%s contains more than one nullable members' % union_typ
e.name) | 113 raise Exception('%s contains more than one nullable members' % union_typ
e.name) |
| 94 if dictionary_type and nullable_members == 1: | 114 if dictionary_type and nullable_members == 1: |
| 95 raise Exception('%s has a dictionary and a nullable member' % union_type
.name) | 115 raise Exception('%s has a dictionary and a nullable member' % union_type
.name) |
| 96 | 116 |
| 97 cpp_class = union_type.cpp_type | |
| 98 return { | 117 return { |
| 99 'array_buffer_type': array_buffer_type, | 118 'array_buffer_type': array_buffer_type, |
| 100 'array_buffer_view_type': array_buffer_view_type, | 119 'array_buffer_view_type': array_buffer_view_type, |
| 101 'array_or_sequence_type': array_or_sequence_type, | 120 'array_or_sequence_type': array_or_sequence_type, |
| 102 'boolean_type': boolean_type, | 121 'boolean_type': boolean_type, |
| 103 'cpp_class': cpp_class, | 122 'cpp_class': union_type.cpp_type, |
| 104 'cpp_includes': sorted(cpp_includes - UNION_CPP_INCLUDES_BLACKLIST), | |
| 105 'dictionary_type': dictionary_type, | 123 'dictionary_type': dictionary_type, |
| 106 'header_includes': sorted(header_includes), | |
| 107 'header_forward_decls': sorted(header_forward_decls), | |
| 108 'includes_nullable_type': union_type.includes_nullable_type, | 124 'includes_nullable_type': union_type.includes_nullable_type, |
| 109 'interface_types': interface_types, | 125 'interface_types': interface_types, |
| 110 'members': members, | 126 'members': members, |
| 111 'numeric_type': numeric_type, | 127 'numeric_type': numeric_type, |
| 112 'object_type': object_type, | 128 'object_type': object_type, |
| 113 'string_type': string_type, | 129 'string_type': string_type, |
| 114 'type_string': str(union_type), | 130 'type_string': str(union_type), |
| 115 'v8_class': v8_types.v8_type(cpp_class), | |
| 116 } | 131 } |
| 117 | 132 |
| 118 | 133 |
| 119 def _update_includes_and_forward_decls(member, interface_info): | 134 def _update_includes_and_forward_decls(member, interface_info): |
| 120 if interface_info: | 135 if interface_info: |
| 121 cpp_includes.update(interface_info.get( | 136 cpp_includes.update(interface_info.get( |
| 122 'dependencies_include_paths', [])) | 137 'dependencies_include_paths', [])) |
| 123 # We need complete types for IDL dictionaries in union containers. | 138 # TODO(bashi): Workaround for http://crbug.com/524424 |
| 139 # Avoid using forward declaration for IDL dictionaries so that they |
| 140 # aren't imcomplete types in UnionTypes.h. This enables an IDL |
| 141 # dictionary to have a union type which has an IDL dictionary. e.g. |
| 142 # dictionary DictA { (boolean or DictB) member; } |
| 143 # Note that this doesn't cover all cases. We still can't use an IDL |
| 144 # dictionary in a union type when the dictionary contains a union type. |
| 145 # e.g. |
| 146 # void foo((DOMString or DictA) arg); // won't compile |
| 124 if member.is_dictionary: | 147 if member.is_dictionary: |
| 125 header_includes.update(member.includes_for_type()) | 148 header_includes.update(member.includes_for_type()) |
| 126 else: | 149 else: |
| 127 cpp_includes.update(member.includes_for_type()) | 150 cpp_includes.update(member.includes_for_type()) |
| 128 header_forward_decls.add(member.implemented_as) | 151 header_forward_decls.add(member.implemented_as) |
| 129 else: | 152 else: |
| 130 cpp_includes.update(member.includes_for_type()) | 153 cpp_includes.update(member.includes_for_type()) |
| 131 | 154 |
| 132 | 155 |
| 133 def member_context(member, interfaces_info): | 156 def member_context(member, interfaces_info): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 144 creation_context='creationContext'), | 167 creation_context='creationContext'), |
| 145 'enum_values': member.enum_values, | 168 'enum_values': member.enum_values, |
| 146 'is_traceable': member.is_traceable, | 169 'is_traceable': member.is_traceable, |
| 147 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), | 170 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), |
| 148 'specific_type_enum': 'SpecificType' + member.name, | 171 'specific_type_enum': 'SpecificType' + member.name, |
| 149 'type_name': member.name, | 172 'type_name': member.name, |
| 150 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( | 173 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( |
| 151 {}, 'v8Value', 'cppValue', isolate='isolate', | 174 {}, 'v8Value', 'cppValue', isolate='isolate', |
| 152 use_exception_state=True, restricted_float=True), | 175 use_exception_state=True, restricted_float=True), |
| 153 } | 176 } |
| OLD | NEW |