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_utilities | |
5 | 6 |
6 def union_context(union_types): | 7 |
8 UNION_H_INCLUDES = frozenset([ | |
9 'bindings/core/v8/ExceptionState.h', | |
10 'bindings/core/v8/V8Binding.h', | |
11 'platform/heap/Handle.h', | |
12 ]) | |
13 | |
14 cpp_includes = set() | |
15 header_forward_decls = set() | |
16 | |
17 | |
18 def union_context(union_types, interfaces_info): | |
19 cpp_includes.clear() | |
20 header_forward_decls.clear() | |
haraken
2014/10/29 04:59:30
Nit: Do we need these clear()s?
bashi
2014/10/29 09:57:36
Removed.
| |
7 return { | 21 return { |
8 'containers': [container_context(union_type) | 22 'containers': [container_context(union_type, interfaces_info) |
9 for union_type in union_types], | 23 for union_type in union_types], |
24 'cpp_includes': sorted(cpp_includes), | |
25 'header_forward_decls': sorted(header_forward_decls), | |
26 'header_includes': sorted(UNION_H_INCLUDES), | |
10 } | 27 } |
11 | 28 |
12 | 29 |
13 def container_context(union_type): | 30 def container_context(union_type, interfaces_info): |
31 members = [] | |
32 | |
33 # These variables refer member contexts if the given union type has | |
34 # corresponding types. They are used for V8 -> impl conversion. | |
35 dictionary_type = None | |
36 boolean_type = None | |
37 numeric_type = None | |
38 interface_types = [] | |
39 string_type = None | |
40 for member in union_type.member_types: | |
41 context = member_context(member, interfaces_info) | |
42 members.append(context) | |
43 if member.is_interface_type: | |
44 interface_types.append(context) | |
45 elif member.is_dictionary: | |
46 if dictionary_type: | |
47 raise Exception('%s is ambiguous.' % union_type.name) | |
48 dictionary_type = context | |
49 elif member.base_type == 'boolean': | |
50 if boolean_type: | |
51 raise Exception('%s is ambiguous.' % union_type.name) | |
52 boolean_type = context | |
53 elif member.is_numeric_type: | |
54 if numeric_type: | |
55 raise Exception('%s is ambiguous.' % union_type.name) | |
56 numeric_type = context | |
57 elif member.is_string_type: | |
58 if string_type: | |
59 raise Exception('%s is ambiguous.' % union_type.name) | |
60 string_type = context | |
haraken
2014/10/29 04:59:30
Add:
else:
raise ...
bashi
2014/10/29 09:57:36
We should, but since this CL doesn't support seque
| |
61 | |
14 return { | 62 return { |
63 'boolean_type': boolean_type, | |
15 'cpp_class': union_type.name, | 64 'cpp_class': union_type.name, |
65 'dictionary_type': dictionary_type, | |
66 'interface_types': interface_types, | |
67 'members': members, | |
68 'numeric_type': numeric_type, | |
69 'string_type': string_type, | |
16 } | 70 } |
71 | |
72 | |
73 def member_context(member, interfaces_info): | |
74 cpp_includes.update(member.includes_for_type) | |
75 interface_info = interfaces_info.get(member.name, None) | |
76 if interface_info: | |
77 cpp_includes.update(interface_info.get('dependencies_include_paths', []) ) | |
78 header_forward_decls.add(member.name) | |
79 return { | |
80 'cpp_name': v8_utilities.uncapitalize(member.name), | |
81 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), | |
82 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( | |
83 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', | |
84 creation_context='creationContext'), | |
85 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), | |
86 'specific_type_enum': 'SpecificType' + member.name, | |
87 'type_name': member.name, | |
88 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( | |
89 {}, 'v8Value', 'cppValue'), | |
90 } | |
OLD | NEW |