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

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

Issue 854113002: IDL: Enumeration support in union types (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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
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_utilities 5 import v8_utilities
6 6
7 7
8 UNION_H_INCLUDES = frozenset([ 8 UNION_H_INCLUDES = frozenset([
9 'bindings/core/v8/Dictionary.h', 9 'bindings/core/v8/Dictionary.h',
10 'bindings/core/v8/ExceptionState.h', 10 'bindings/core/v8/ExceptionState.h',
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 def container_context(union_type, interfaces_info): 63 def container_context(union_type, interfaces_info):
64 members = [] 64 members = []
65 65
66 # These variables refer to member contexts if the given union type has 66 # These variables refer to member contexts if the given union type has
67 # corresponding types. They are used for V8 -> impl conversion. 67 # corresponding types. They are used for V8 -> impl conversion.
68 array_buffer_type = None 68 array_buffer_type = None
69 array_buffer_view_type = None 69 array_buffer_view_type = None
70 array_or_sequence_type = None 70 array_or_sequence_type = None
71 boolean_type = None 71 boolean_type = None
72 dictionary_type = None 72 dictionary_type = None
73 enum_type = None
73 interface_types = [] 74 interface_types = []
74 numeric_type = None 75 numeric_type = None
75 string_type = None 76 string_type = None
76 for member in union_type.member_types: 77 for member in union_type.member_types:
77 context = member_context(member, interfaces_info) 78 context = member_context(member, interfaces_info)
78 members.append(context) 79 members.append(context)
79 if member.base_type == 'ArrayBuffer': 80 if member.base_type == 'ArrayBuffer':
80 if array_buffer_type: 81 if array_buffer_type:
81 raise Exception('%s is ambiguous.' % union_type.name) 82 raise Exception('%s is ambiguous.' % union_type.name)
82 array_buffer_type = context 83 array_buffer_type = context
83 elif member.base_type == 'ArrayBufferView': 84 elif member.base_type == 'ArrayBufferView':
84 if array_buffer_view_type: 85 if array_buffer_view_type:
85 raise Exception('%s is ambiguous.' % union_type.name) 86 raise Exception('%s is ambiguous.' % union_type.name)
86 array_buffer_view_type = context 87 array_buffer_view_type = context
87 # FIXME: Remove generic Dictionary special casing. 88 # FIXME: Remove generic Dictionary special casing.
88 elif member.is_dictionary or member.base_type == 'Dictionary': 89 elif member.is_dictionary or member.base_type == 'Dictionary':
89 if dictionary_type: 90 if dictionary_type:
90 raise Exception('%s is ambiguous.' % union_type.name) 91 raise Exception('%s is ambiguous.' % union_type.name)
91 dictionary_type = context 92 dictionary_type = context
92 elif member.is_array_or_sequence_type: 93 elif member.is_array_or_sequence_type:
93 if array_or_sequence_type: 94 if array_or_sequence_type:
94 raise Exception('%s is ambiguous.' % union_type.name) 95 raise Exception('%s is ambiguous.' % union_type.name)
95 array_or_sequence_type = context 96 array_or_sequence_type = context
96 elif member.is_interface_type: 97 elif member.is_interface_type:
97 interface_types.append(context) 98 interface_types.append(context)
99 elif member.is_enum:
Jens Widell 2015/01/16 09:53:51 If there's an enum type in the union, it will be u
bashi 2015/01/16 10:11:58 My understanding is that enums and strings are not
100 if string_type:
101 raise Exception('%s is ambiguous.' % union_type.name)
102 enum_type = context
98 elif member is union_type.boolean_member_type: 103 elif member is union_type.boolean_member_type:
99 boolean_type = context 104 boolean_type = context
100 elif member is union_type.numeric_member_type: 105 elif member is union_type.numeric_member_type:
101 numeric_type = context 106 numeric_type = context
102 elif member is union_type.string_member_type: 107 elif member is union_type.string_member_type:
108 if enum_type:
109 raise Exception('%s is ambiguious.' % union_type.name)
103 string_type = context 110 string_type = context
104 else: 111 else:
105 raise Exception('%s is not supported as an union member.' % member.n ame) 112 raise Exception('%s is not supported as an union member.' % member.n ame)
106 113
107 # Nullable restriction checks 114 # Nullable restriction checks
108 nullable_members = union_type.number_of_nullable_member_types 115 nullable_members = union_type.number_of_nullable_member_types
109 if nullable_members > 1: 116 if nullable_members > 1:
110 raise Exception('%s contains more than one nullable members' % union_typ e.name) 117 raise Exception('%s contains more than one nullable members' % union_typ e.name)
111 if dictionary_type and nullable_members == 1: 118 if dictionary_type and nullable_members == 1:
112 raise Exception('%s has a dictionary and a nullable member' % union_type .name) 119 raise Exception('%s has a dictionary and a nullable member' % union_type .name)
113 120
114 return { 121 return {
115 'array_buffer_type': array_buffer_type, 122 'array_buffer_type': array_buffer_type,
116 'array_buffer_view_type': array_buffer_view_type, 123 'array_buffer_view_type': array_buffer_view_type,
117 'array_or_sequence_type': array_or_sequence_type, 124 'array_or_sequence_type': array_or_sequence_type,
118 'boolean_type': boolean_type, 125 'boolean_type': boolean_type,
119 'cpp_class': union_type.cpp_type, 126 'cpp_class': union_type.cpp_type,
120 'dictionary_type': dictionary_type, 127 'dictionary_type': dictionary_type,
121 'type_string': str(union_type), 128 'enum_type': enum_type,
122 'includes_nullable_type': union_type.includes_nullable_type, 129 'includes_nullable_type': union_type.includes_nullable_type,
123 'interface_types': interface_types, 130 'interface_types': interface_types,
124 'members': members, 131 'members': members,
125 'needs_trace': any(member['is_traceable'] for member in members), 132 'needs_trace': any(member['is_traceable'] for member in members),
126 'numeric_type': numeric_type, 133 'numeric_type': numeric_type,
127 'string_type': string_type, 134 'string_type': string_type,
135 'type_string': str(union_type),
128 } 136 }
129 137
130 138
131 def member_context(member, interfaces_info): 139 def member_context(member, interfaces_info):
132 cpp_includes.update(member.includes_for_type) 140 cpp_includes.update(member.includes_for_type)
133 interface_info = interfaces_info.get(member.name, None) 141 interface_info = interfaces_info.get(member.name, None)
134 if interface_info: 142 if interface_info:
135 cpp_includes.update(interface_info.get('dependencies_include_paths', []) ) 143 cpp_includes.update(interface_info.get('dependencies_include_paths', []) )
136 header_forward_decls.add(member.implemented_as) 144 header_forward_decls.add(member.implemented_as)
137 if member.is_nullable: 145 if member.is_nullable:
138 member = member.inner_type 146 member = member.inner_type
139 return { 147 return {
140 'cpp_name': v8_utilities.uncapitalize(member.name), 148 'cpp_name': v8_utilities.uncapitalize(member.name),
141 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True), 149 'cpp_type': member.cpp_type_args(used_in_cpp_sequence=True),
142 'cpp_local_type': member.cpp_type, 150 'cpp_local_type': member.cpp_type,
143 'cpp_value_to_v8_value': member.cpp_value_to_v8_value( 151 'cpp_value_to_v8_value': member.cpp_value_to_v8_value(
144 cpp_value='impl.getAs%s()' % member.name, isolate='isolate', 152 cpp_value='impl.getAs%s()' % member.name, isolate='isolate',
145 creation_context='creationContext'), 153 creation_context='creationContext'),
154 'enum_validation_expression': member.enum_validation_expression,
146 'is_traceable': member.is_traceable, 155 'is_traceable': member.is_traceable,
147 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True), 156 'rvalue_cpp_type': member.cpp_type_args(used_as_rvalue_type=True),
148 'specific_type_enum': 'SpecificType' + member.name, 157 'specific_type_enum': 'SpecificType' + member.name,
149 'type_name': member.name, 158 'type_name': member.name,
150 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value( 159 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
151 {}, 'v8Value', 'cppValue', isolate='isolate', 160 {}, 'v8Value', 'cppValue', isolate='isolate',
152 needs_exception_state_for_string=True), 161 needs_exception_state_for_string=True),
153 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698