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