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

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

Issue 22436002: Replace EntryArray type by an Entry[] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 4 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
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return 'v8Boolean(%s, %s)' % (cpp_value, isolate) 119 return 'v8Boolean(%s, %s)' % (cpp_value, isolate)
120 if data_type in ['long long', 'unsigned long long', 'DOMTimeStamp']: 120 if data_type in ['long long', 'unsigned long long', 'DOMTimeStamp']:
121 # long long and unsigned long long are not representable in ECMAScript. 121 # long long and unsigned long long are not representable in ECMAScript.
122 return 'v8::Number::New(static_cast<double>(%s))' % cpp_value 122 return 'v8::Number::New(static_cast<double>(%s))' % cpp_value
123 if primitive_type(data_type): 123 if primitive_type(data_type):
124 if data_type not in ['float', 'double']: 124 if data_type not in ['float', 'double']:
125 raise Exception('unexpected data_type %s' % data_type) 125 raise Exception('unexpected data_type %s' % data_type)
126 return 'v8::Number::New(%s)' % cpp_value 126 return 'v8::Number::New(%s)' % cpp_value
127 if data_type == 'DOMString': 127 if data_type == 'DOMString':
128 return 'v8String(%s, %s)' % (cpp_value, isolate) 128 return 'v8String(%s, %s)' % (cpp_value, isolate)
129 if sequence_type(data_type): 129 if array_or_sequence_type(data_type):
130 return 'v8Array(%s, %s)' % (cpp_value, isolate) 130 return 'v8Array(%s, %s)' % (cpp_value, isolate)
131 return 'toV8(%s, %s, %s)' % (cpp_value, creation_context, isolate) 131 return 'toV8(%s, %s, %s)' % (cpp_value, creation_context, isolate)
132 132
133 133
134 def generate_conditional_string(interface_or_attribute_or_operation): 134 def generate_conditional_string(interface_or_attribute_or_operation):
135 if 'Conditional' not in interface_or_attribute_or_operation.extended_attribu tes: 135 if 'Conditional' not in interface_or_attribute_or_operation.extended_attribu tes:
136 return '' 136 return ''
137 conditional = interface_or_attribute_or_operation.extended_attributes['Condi tional'] 137 conditional = interface_or_attribute_or_operation.extended_attributes['Condi tional']
138 for operator in ['&', '|']: 138 for operator in ['&', '|']:
139 if operator in conditional: 139 if operator in conditional:
140 conditions = set(conditional.split(operator)) 140 conditions = set(conditional.split(operator))
141 operator_separator = ' %s%s ' % (operator, operator) 141 operator_separator = ' %s%s ' % (operator, operator)
142 return operator_separator.join(['ENABLE(%s)' % expression for expres sion in sorted(conditions)]) 142 return operator_separator.join(['ENABLE(%s)' % expression for expres sion in sorted(conditions)])
143 return 'ENABLE(%s)' % conditional 143 return 'ENABLE(%s)' % conditional
144 144
145 145
146 def includes_for_type(data_type): 146 def includes_for_type(data_type):
147 if primitive_type(data_type) or data_type == 'DOMString': 147 if primitive_type(data_type) or data_type == 'DOMString':
148 return set() 148 return set()
149 if sequence_type(data_type): 149 if array_or_sequence_type(data_type):
150 return includes_for_type(sequence_type(data_type)) 150 return includes_for_type(array_or_sequence_type(data_type))
151 return set(['V8%s.h' % data_type]) 151 return set(['V8%s.h' % data_type])
152 152
153 153
154 def includes_for_cpp_class(class_name, relative_dir_posix): 154 def includes_for_cpp_class(class_name, relative_dir_posix):
155 return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h' )]) 155 return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h' )])
156 156
157 157
158 def includes_for_operation(operation): 158 def includes_for_operation(operation):
159 includes = includes_for_type(operation.data_type) 159 includes = includes_for_type(operation.data_type)
160 for parameter in operation.arguments: 160 for parameter in operation.arguments:
161 includes |= includes_for_type(parameter.data_type) 161 includes |= includes_for_type(parameter.data_type)
162 return includes 162 return includes
163 163
164 164
165 def primitive_type(data_type): 165 def primitive_type(data_type):
166 return data_type in PRIMITIVE_TYPES 166 return data_type in PRIMITIVE_TYPES
167 167
168 168
169 def sequence_type(data_type): 169 def sequence_type(data_type):
170 matched = re.match(r'sequence<([\w\d_\s]+)>', data_type) 170 matched = re.match(r'sequence<([\w\d_\s]+)>', data_type)
171 if not matched: 171 if not matched:
172 return None 172 return None
173 return matched.group(1) 173 return matched.group(1)
174 174
175 175
176 def array_type(data_type):
177 matched = re.match(r'([\w\d_\s]+)\[\]', data_type)
178 if not matched:
179 return None
180 return matched.group(1)
181
182
183 def array_or_sequence_type(data_type):
184 return array_type(data_type) or sequence_type(data_type)
185
176 def cpp_type(data_type, pointer_type): 186 def cpp_type(data_type, pointer_type):
177 """Returns the C++ type corresponding to the IDL type. 187 """Returns the C++ type corresponding to the IDL type.
178 188
179 Args: 189 Args:
180 pointer_type: 190 pointer_type:
181 'raw': return raw pointer form (e.g. Foo*) 191 'raw': return raw pointer form (e.g. Foo*)
182 'RefPtr': return RefPtr form (e.g. RefPtr<Foo>) 192 'RefPtr': return RefPtr form (e.g. RefPtr<Foo>)
183 'PassRefPtr': return PassRefPtr form (e.g. RefPtr<Foo>) 193 'PassRefPtr': return PassRefPtr form (e.g. RefPtr<Foo>)
184 """ 194 """
185 if data_type in CPP_TYPE_SPECIAL_CONVERSION_RULES: 195 if data_type in CPP_TYPE_SPECIAL_CONVERSION_RULES:
186 return CPP_TYPE_SPECIAL_CONVERSION_RULES[data_type] 196 return CPP_TYPE_SPECIAL_CONVERSION_RULES[data_type]
187 if sequence_type(data_type): 197 if array_or_sequence_type(data_type):
188 return 'Vector<%s >' % cpp_type(sequence_type(data_type), 'RefPtr') 198 return 'const Vector<%s >&' % cpp_type(array_or_sequence_type(data_type) , 'RefPtr')
189 if pointer_type == 'raw': 199 if pointer_type == 'raw':
190 return data_type + '*' 200 return data_type + '*'
191 if pointer_type in ['RefPtr', 'PassRefPtr']: 201 if pointer_type in ['RefPtr', 'PassRefPtr']:
192 return '%s<%s>' % (pointer_type, data_type) 202 return '%s<%s>' % (pointer_type, data_type)
193 raise Exception('Unrecognized pointer type: "%s"' % pointer_type) 203 raise Exception('Unrecognized pointer type: "%s"' % pointer_type)
194 204
195 205
196 def v8_type(data_type): 206 def v8_type(data_type):
197 return 'V8' + data_type 207 return 'V8' + data_type
198 208
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 352
343 methods = [generate_method(operation) for operation in self.interface.op erations] 353 methods = [generate_method(operation) for operation in self.interface.op erations]
344 template_contents = { 354 template_contents = {
345 'cpp_class_name': self.interface.name, 355 'cpp_class_name': self.interface.name,
346 'v8_class_name': v8_class_name(self.interface), 356 'v8_class_name': v8_class_name(self.interface),
347 'cpp_includes': sorted(list(self.cpp_includes)), 357 'cpp_includes': sorted(list(self.cpp_includes)),
348 'header_includes': sorted(list(self.header_includes)), 358 'header_includes': sorted(list(self.header_includes)),
349 'methods': methods, 359 'methods': methods,
350 } 360 }
351 return template_contents 361 return template_contents
OLDNEW
« no previous file with comments | « LayoutTests/fast/filesystem/script-tests/read-directory.js ('k') | Source/core/inspector/InspectorFileSystemAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698