Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: Source/bindings/scripts/v8_union.py

Issue 953123003: IDL: Put generated union type containers in separate files (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/scripts/code_generator_v8.py ('k') | Source/bindings/templates/templates.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
8 UNION_H_INCLUDES = frozenset([ 9 UNION_H_INCLUDES = frozenset([
9 'bindings/core/v8/Dictionary.h', 10 'bindings/core/v8/Dictionary.h',
10 'bindings/core/v8/ExceptionState.h', 11 'bindings/core/v8/ExceptionState.h',
11 'bindings/core/v8/V8Binding.h', 12 'bindings/core/v8/V8Binding.h',
12 'platform/heap/Handle.h', 13 'platform/heap/Handle.h',
13 ]) 14 ])
14 15
15 UNION_CPP_INCLUDES_BLACKLIST = frozenset([ 16 UNION_HEADER_INCLUDES_BLACKLIST = frozenset([
16 # This header defines static functions needed to implement event handler 17 # This header defines static functions needed to implement event handler
17 # attributes in interfaces that implement GlobalEventHandlers. They are not 18 # attributes in interfaces that implement GlobalEventHandlers. They are not
18 # needed or used by UnionTypes*.cpp, so including the header causes 19 # needed or used by UnionTypes*.cpp, so including the header causes
19 # compilation errors. 20 # compilation errors.
20 # FIXME: We should solve this problem in a way that doesn't involve special- 21 # FIXME: We should solve this problem in a way that doesn't involve special-
21 # casing a header like this. 22 # casing a header like this.
22 'core/dom/GlobalEventHandlers.h', 23 'core/dom/GlobalEventHandlers.h',
23 ]) 24 ])
24 25
25 26
26 cpp_includes = set() 27 header_includes = set()
27 header_forward_decls = set()
28
29
30 def union_context(union_types, interfaces_info):
31 cpp_includes.clear()
32 header_forward_decls.clear()
33
34 # For container classes we strip nullable wrappers. For example,
35 # both (A or B)? and (A? or B) will become AOrB. This should be OK
36 # because container classes can handle null and it seems that
37 # distinguishing (A or B)? and (A? or B) doesn't make sense.
38 container_cpp_types = set()
39 union_types_for_containers = set()
40 nullable_cpp_types = set()
41 for union_type in union_types:
42 cpp_type = union_type.cpp_type
43 if cpp_type not in container_cpp_types:
44 union_types_for_containers.add(union_type)
45 container_cpp_types.add(cpp_type)
46 if union_type.includes_nullable_type:
47 nullable_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 nullable_cpp_types = sorted(nullable_cpp_types)
52
53 return {
54 'containers': [container_context(union_type, interfaces_info)
55 for union_type in union_types_for_containers],
56 'cpp_includes': sorted(cpp_includes - UNION_CPP_INCLUDES_BLACKLIST),
57 'header_forward_decls': sorted(header_forward_decls),
58 'header_includes': sorted(UNION_H_INCLUDES),
59 'nullable_cpp_types': nullable_cpp_types,
60 }
61 28
62 29
63 def container_context(union_type, interfaces_info): 30 def container_context(union_type, interfaces_info):
31 header_includes.clear()
32 header_includes.update(UNION_H_INCLUDES)
64 members = [] 33 members = []
65 34
66 # These variables refer to member contexts if the given union type has 35 # These variables refer to member contexts if the given union type has
67 # corresponding types. They are used for V8 -> impl conversion. 36 # corresponding types. They are used for V8 -> impl conversion.
68 array_buffer_type = None 37 array_buffer_type = None
69 array_buffer_view_type = None 38 array_buffer_view_type = None
70 array_or_sequence_type = None 39 array_or_sequence_type = None
71 boolean_type = None 40 boolean_type = None
72 dictionary_type = None 41 dictionary_type = None
73 interface_types = [] 42 interface_types = []
(...skipping 30 matching lines...) Expand all
104 else: 73 else:
105 raise Exception('%s is not supported as an union member.' % member.n ame) 74 raise Exception('%s is not supported as an union member.' % member.n ame)
106 75
107 # Nullable restriction checks 76 # Nullable restriction checks
108 nullable_members = union_type.number_of_nullable_member_types 77 nullable_members = union_type.number_of_nullable_member_types
109 if nullable_members > 1: 78 if nullable_members > 1:
110 raise Exception('%s contains more than one nullable members' % union_typ e.name) 79 raise Exception('%s contains more than one nullable members' % union_typ e.name)
111 if dictionary_type and nullable_members == 1: 80 if dictionary_type and nullable_members == 1:
112 raise Exception('%s has a dictionary and a nullable member' % union_type .name) 81 raise Exception('%s has a dictionary and a nullable member' % union_type .name)
113 82
83 cpp_class = union_type.cpp_type
114 return { 84 return {
115 'array_buffer_type': array_buffer_type, 85 'array_buffer_type': array_buffer_type,
116 'array_buffer_view_type': array_buffer_view_type, 86 'array_buffer_view_type': array_buffer_view_type,
117 'array_or_sequence_type': array_or_sequence_type, 87 'array_or_sequence_type': array_or_sequence_type,
118 'boolean_type': boolean_type, 88 'boolean_type': boolean_type,
119 'cpp_class': union_type.cpp_type, 89 'cpp_class': cpp_class,
120 'dictionary_type': dictionary_type, 90 'dictionary_type': dictionary_type,
91 'header_includes': sorted(header_includes - UNION_HEADER_INCLUDES_BLACKL IST),
121 'includes_nullable_type': union_type.includes_nullable_type, 92 'includes_nullable_type': union_type.includes_nullable_type,
122 'interface_types': interface_types, 93 'interface_types': interface_types,
123 'members': members, 94 'members': members,
124 'needs_trace': any(member['is_traceable'] for member in members), 95 'needs_trace': any(member['is_traceable'] for member in members),
125 'numeric_type': numeric_type, 96 'numeric_type': numeric_type,
126 'string_type': string_type, 97 'string_type': string_type,
127 'type_string': str(union_type), 98 'type_string': str(union_type),
99 'v8_class': v8_types.v8_type(cpp_class),
128 } 100 }
129 101
130 102
131 def member_context(member, interfaces_info): 103 def member_context(member, interfaces_info):
132 cpp_includes.update(member.includes_for_type) 104 header_includes.update(member.includes_for_type)
133 interface_info = interfaces_info.get(member.name, None) 105 interface_info = interfaces_info.get(member.name, None)
134 if interface_info: 106 if interface_info:
135 cpp_includes.update(interface_info.get('dependencies_include_paths', []) ) 107 header_includes.update(interface_info.get('dependencies_include_paths', []))
136 header_forward_decls.add(member.implemented_as)
137 if member.is_nullable: 108 if member.is_nullable:
138 member = member.inner_type 109 member = member.inner_type
139 return { 110 return {
140 'cpp_name': v8_utilities.uncapitalize(member.name), 111 'cpp_name': v8_utilities.uncapitalize(member.name),
141 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), 112 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
142 'cpp_local_type': member.cpp_type, 113 'cpp_local_type': member.cpp_type,
143 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( 114 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
144 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', 115 cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
145 creation_context='creationContext'), 116 creation_context='creationContext'),
146 'enum_validation_expression': member.enum_validation_expression, 117 'enum_validation_expression': member.enum_validation_expression,
147 'is_traceable': member.is_traceable, 118 'is_traceable': member.is_traceable,
148 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), 119 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
149 'specific_type_enum': 'SpecificType' + member.name, 120 'specific_type_enum': 'SpecificType' + member.name,
150 'type_name': member.name, 121 'type_name': member.name,
151 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( 122 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
152 {}, 'v8Value', 'cppValue', isolate='isolate', 123 {}, 'v8Value', 'cppValue', isolate='isolate',
153 needs_exception_state_for_string=True, restricted_float=True), 124 needs_exception_state_for_string=True, restricted_float=True),
154 } 125 }
OLDNEW
« no previous file with comments | « Source/bindings/scripts/code_generator_v8.py ('k') | Source/bindings/templates/templates.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698