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_types |
6 import v8_utilities | 6 import v8_utilities |
7 | 7 |
8 | 8 |
9 UNION_CPP_INCLUDES = frozenset([ | 9 UNION_CPP_INCLUDES = frozenset([ |
10 'bindings/core/v8/ToV8.h', | 10 'bindings/core/v8/ToV8.h', |
11 ]) | 11 ]) |
12 | 12 |
13 UNION_H_INCLUDES = frozenset([ | 13 UNION_H_INCLUDES = frozenset([ |
14 'bindings/core/v8/Dictionary.h', | 14 'bindings/core/v8/Dictionary.h', |
15 'bindings/core/v8/ExceptionState.h', | 15 'bindings/core/v8/ExceptionState.h', |
| 16 'bindings/core/v8/NativeValueTraits.h', |
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 |
20 UNION_CPP_INCLUDES_BLACKLIST = frozenset([ | 21 UNION_CPP_INCLUDES_BLACKLIST = frozenset([ |
21 # This header defines static functions needed to implement event handler | 22 # This header defines static functions needed to implement event handler |
22 # attributes in interfaces that implement GlobalEventHandlers. They are not | 23 # attributes in interfaces that implement GlobalEventHandlers. They are not |
23 # needed or used by UnionTypes*.cpp, so including the header causes | 24 # needed or used by UnionTypes*.cpp, so including the header causes |
24 # compilation errors. | 25 # compilation errors. |
25 # FIXME: We should solve this problem in a way that doesn't involve special- | 26 # FIXME: We should solve this problem in a way that doesn't involve special- |
(...skipping 18 matching lines...) Expand all Loading... |
44 # These variables refer to member contexts if the given union type has | 45 # These variables refer to member contexts if the given union type has |
45 # corresponding types. They are used for V8 -> impl conversion. | 46 # corresponding types. They are used for V8 -> impl conversion. |
46 array_buffer_type = None | 47 array_buffer_type = None |
47 array_buffer_view_type = None | 48 array_buffer_view_type = None |
48 array_or_sequence_type = None | 49 array_or_sequence_type = None |
49 boolean_type = None | 50 boolean_type = None |
50 dictionary_type = None | 51 dictionary_type = None |
51 interface_types = [] | 52 interface_types = [] |
52 numeric_type = None | 53 numeric_type = None |
53 object_type = None | 54 object_type = None |
| 55 record_type = None |
54 string_type = None | 56 string_type = None |
55 for member in union_type.member_types: | 57 for member in union_type.member_types: |
56 context = member_context(member, interfaces_info) | 58 context = member_context(member, interfaces_info) |
57 members.append(context) | 59 members.append(context) |
58 if member.base_type == 'ArrayBuffer': | 60 if member.base_type == 'ArrayBuffer': |
59 if array_buffer_type: | 61 if array_buffer_type: |
60 raise Exception('%s is ambiguous.' % union_type.name) | 62 raise Exception('%s is ambiguous.' % union_type.name) |
61 array_buffer_type = context | 63 array_buffer_type = context |
62 elif member.base_type == 'ArrayBufferView': | 64 elif member.base_type == 'ArrayBufferView': |
63 if array_buffer_view_type: | 65 if array_buffer_view_type: |
64 raise Exception('%s is ambiguous.' % union_type.name) | 66 raise Exception('%s is ambiguous.' % union_type.name) |
65 array_buffer_view_type = context | 67 array_buffer_view_type = context |
66 elif member.is_dictionary: | 68 elif member.is_dictionary: |
67 if dictionary_type: | 69 if dictionary_type: |
68 raise Exception('%s is ambiguous.' % union_type.name) | 70 raise Exception('%s is ambiguous.' % union_type.name) |
69 dictionary_type = context | 71 dictionary_type = context |
70 elif member.is_array_or_sequence_type: | 72 elif member.is_array_or_sequence_type: |
71 if array_or_sequence_type: | 73 if array_or_sequence_type: |
72 raise Exception('%s is ambiguous.' % union_type.name) | 74 raise Exception('%s is ambiguous.' % union_type.name) |
73 array_or_sequence_type = context | 75 array_or_sequence_type = context |
74 # "Dictionary" is an object, rather than an IDL dictionary. | 76 # "Dictionary" is an object, rather than an IDL dictionary. |
75 elif member.base_type == 'Dictionary': | 77 elif member.base_type == 'Dictionary': |
76 if object_type: | 78 if object_type or record_type: |
77 raise Exception('%s is ambiguous.' % union_type.name) | 79 raise Exception('%s is ambiguous.' % union_type.name) |
78 object_type = context | 80 object_type = context |
| 81 elif member.is_record_type: |
| 82 if object_type or record_type: |
| 83 raise Exception('%s is ambiguous.' % union_type.name) |
| 84 record_type = context |
79 elif member.is_interface_type: | 85 elif member.is_interface_type: |
80 interface_types.append(context) | 86 interface_types.append(context) |
81 elif member is union_type.boolean_member_type: | 87 elif member is union_type.boolean_member_type: |
82 boolean_type = context | 88 boolean_type = context |
83 elif member is union_type.numeric_member_type: | 89 elif member is union_type.numeric_member_type: |
84 numeric_type = context | 90 numeric_type = context |
85 elif member is union_type.string_member_type: | 91 elif member is union_type.string_member_type: |
86 string_type = context | 92 string_type = context |
87 else: | 93 else: |
88 raise Exception('%s is not supported as an union member.' % member.n
ame) | 94 raise Exception('%s is not supported as an union member.' % member.n
ame) |
(...skipping 14 matching lines...) Expand all Loading... |
103 'cpp_class': cpp_class, | 109 'cpp_class': cpp_class, |
104 'cpp_includes': sorted(cpp_includes - UNION_CPP_INCLUDES_BLACKLIST), | 110 'cpp_includes': sorted(cpp_includes - UNION_CPP_INCLUDES_BLACKLIST), |
105 'dictionary_type': dictionary_type, | 111 'dictionary_type': dictionary_type, |
106 'header_includes': sorted(header_includes), | 112 'header_includes': sorted(header_includes), |
107 'header_forward_decls': sorted(header_forward_decls), | 113 'header_forward_decls': sorted(header_forward_decls), |
108 'includes_nullable_type': union_type.includes_nullable_type, | 114 'includes_nullable_type': union_type.includes_nullable_type, |
109 'interface_types': interface_types, | 115 'interface_types': interface_types, |
110 'members': members, | 116 'members': members, |
111 'numeric_type': numeric_type, | 117 'numeric_type': numeric_type, |
112 'object_type': object_type, | 118 'object_type': object_type, |
| 119 'record_type': record_type, |
113 'string_type': string_type, | 120 'string_type': string_type, |
114 'type_string': str(union_type), | 121 'type_string': str(union_type), |
115 'v8_class': v8_types.v8_type(cpp_class), | 122 'v8_class': v8_types.v8_type(cpp_class), |
116 } | 123 } |
117 | 124 |
118 | 125 |
119 def _update_includes_and_forward_decls(member, interface_info): | 126 def _update_includes_and_forward_decls(member, interface_info): |
120 if interface_info: | 127 if interface_info: |
121 cpp_includes.update(interface_info.get( | 128 cpp_includes.update(interface_info.get( |
122 'dependencies_include_paths', [])) | 129 'dependencies_include_paths', [])) |
123 # We need complete types for IDL dictionaries in union containers. | 130 # We need complete types for IDL dictionaries in union containers. |
124 if member.is_dictionary or member.is_typed_array: | 131 if member.is_dictionary or member.is_typed_array: |
125 header_includes.update(member.includes_for_type()) | 132 header_includes.update(member.includes_for_type()) |
126 else: | 133 else: |
127 cpp_includes.update(member.includes_for_type()) | 134 cpp_includes.update(member.includes_for_type()) |
128 header_forward_decls.add(member.implemented_as) | 135 header_forward_decls.add(member.implemented_as) |
129 else: | 136 else: |
130 cpp_includes.update(member.includes_for_type()) | 137 if member.is_record_type: |
| 138 # The headers for both T and U must be present when |
| 139 # Vector<std::pair<T, U>> is declared. |
| 140 header_includes.update(member.includes_for_type()) |
| 141 else: |
| 142 cpp_includes.update(member.includes_for_type()) |
131 | 143 |
132 | 144 |
133 def member_context(member, interfaces_info): | 145 def member_context(member, interfaces_info): |
134 interface_info = interfaces_info.get(member.name, None) | 146 interface_info = interfaces_info.get(member.name, None) |
135 _update_includes_and_forward_decls(member, interface_info) | 147 _update_includes_and_forward_decls(member, interface_info) |
136 if member.is_nullable: | 148 if member.is_nullable: |
137 member = member.inner_type | 149 member = member.inner_type |
138 return { | 150 return { |
139 'cpp_name': v8_utilities.uncapitalize(member.name), | 151 'cpp_name': v8_utilities.uncapitalize(member.name), |
140 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), | 152 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), |
141 'cpp_local_type': member.cpp_type, | 153 'cpp_local_type': member.cpp_type, |
142 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( | 154 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( |
143 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', | 155 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', |
144 creation_context='creationContext'), | 156 creation_context='creationContext'), |
145 'enum_values': member.enum_values, | 157 'enum_values': member.enum_values, |
146 'is_array_buffer_or_view_type': member.is_array_buffer_or_view, | 158 'is_array_buffer_or_view_type': member.is_array_buffer_or_view, |
147 'is_traceable': member.is_traceable, | 159 'is_traceable': member.is_traceable, |
148 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), | 160 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), |
149 'specific_type_enum': 'SpecificType' + member.name, | 161 'specific_type_enum': 'SpecificType' + member.name, |
150 'type_name': member.name, | 162 'type_name': member.name, |
151 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( | 163 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( |
152 {}, 'v8Value', 'cppValue', isolate='isolate', | 164 {}, 'v8Value', 'cppValue', isolate='isolate', |
153 use_exception_state=True) | 165 use_exception_state=True) |
154 } | 166 } |
OLD | NEW |