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 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): | |
| 7 return { | 19 return { |
| 8 'containers': [container_context(union_type) | 20 'containers': [container_context(union_type, interfaces_info) |
| 9 for union_type in union_types], | 21 for union_type in union_types], |
| 22 'cpp_includes': sorted(cpp_includes), | |
| 23 'header_forward_decls': sorted(header_forward_decls), | |
| 24 'header_includes': sorted(UNION_H_INCLUDES), | |
| 10 } | 25 } |
| 11 | 26 |
| 12 | 27 |
| 13 def container_context(union_type): | 28 def container_context(union_type, interfaces_info): |
| 29 members = [] | |
| 30 | |
| 31 # These variables refer member contexts if the given union type has | |
|
haraken
2014/10/30 13:01:30
refer => refer to
bashi
2014/10/30 23:19:18
Done.
| |
| 32 # corresponding types. They are used for V8 -> impl conversion. | |
| 33 boolean_type = None | |
| 34 dictionary_type = None | |
| 35 interface_types = [] | |
| 36 numeric_type = None | |
| 37 string_type = None | |
| 38 for member in union_type.member_types: | |
| 39 context = member_context(member, interfaces_info) | |
| 40 members.append(context) | |
| 41 if member.is_interface_type: | |
| 42 interface_types.append(context) | |
| 43 elif member.is_dictionary: | |
| 44 if dictionary_type: | |
| 45 raise Exception('%s is ambiguous.' % union_type.name) | |
| 46 dictionary_type = context | |
| 47 elif member.base_type == 'boolean': | |
| 48 if boolean_type: | |
| 49 raise Exception('%s is ambiguous.' % union_type.name) | |
| 50 boolean_type = context | |
| 51 elif member.is_numeric_type: | |
| 52 if numeric_type: | |
| 53 raise Exception('%s is ambiguous.' % union_type.name) | |
| 54 numeric_type = context | |
| 55 elif member.is_string_type: | |
| 56 if string_type: | |
| 57 raise Exception('%s is ambiguous.' % union_type.name) | |
| 58 string_type = context | |
| 59 else: | |
| 60 raise Exception('%s is not supported as an union member.' % member.n ame) | |
| 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_local_type': member.cpp_type, | |
| 83 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( | |
| 84 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', | |
| 85 creation_context='creationContext'), | |
| 86 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), | |
| 87 'specific_type_enum': 'SpecificType' + member.name, | |
| 88 'type_name': member.name, | |
| 89 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( | |
| 90 {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True), | |
| 91 } | |
| OLD | NEW |