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

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

Issue 21006006: Add forEach() to CSSVariablesMap (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Python code generator changes 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 202
203 203
204 def cpp_class_name(interface): 204 def cpp_class_name(interface):
205 return interface.extended_attributes.get('ImplementedAs', interface.name) 205 return interface.extended_attributes.get('ImplementedAs', interface.name)
206 206
207 207
208 def v8_class_name(interface): 208 def v8_class_name(interface):
209 return v8_type(interface.name) 209 return v8_type(interface.name)
210 210
211 211
212 def values_for_extended_attributes(extended_attributes, key):
213 return extended_attributes.get(key, '').split('|')
Nils Barth (inactive) 2013/08/06 05:45:18 Extended attributes are internally a bit tricky; I
alancutter (OOO until 2018) 2013/08/07 00:40:24 Sounds good! Done.
214
215
212 class CodeGeneratorV8: 216 class CodeGeneratorV8:
213 def __init__(self, definitions, interface_name, output_directory, relative_d ir_posix, idl_directories, verbose=False): 217 def __init__(self, definitions, interface_name, output_directory, relative_d ir_posix, idl_directories, verbose=False):
214 self.idl_definitions = definitions 218 self.idl_definitions = definitions
215 self.interface_name = interface_name 219 self.interface_name = interface_name
216 self.idl_directories = idl_directories 220 self.idl_directories = idl_directories
217 self.output_directory = output_directory 221 self.output_directory = output_directory
218 self.relative_dir_posix = relative_dir_posix 222 self.relative_dir_posix = relative_dir_posix
219 self.verbose = verbose 223 self.verbose = verbose
220 self.interface = None 224 self.interface = None
221 self.header_includes = set() 225 self.header_includes = set()
(...skipping 25 matching lines...) Expand all
247 {cpp_basename} at every build. This file must not be tried to compile. 251 {cpp_basename} at every build. This file must not be tried to compile.
248 */ 252 */
249 """.format(**locals()) 253 """.format(**locals())
250 self.write_header_code(header_basename, contents) 254 self.write_header_code(header_basename, contents)
251 self.write_cpp_code(cpp_basename, contents) 255 self.write_cpp_code(cpp_basename, contents)
252 256
253 def write_header_and_cpp(self): 257 def write_header_and_cpp(self):
254 header_basename = v8_class_name(self.interface) + '.h' 258 header_basename = v8_class_name(self.interface) + '.h'
255 cpp_basename = v8_class_name(self.interface) + '.cpp' 259 cpp_basename = v8_class_name(self.interface) + '.cpp'
256 if self.interface.is_callback: 260 if self.interface.is_callback:
257 header_template = 'templates/callback_interface.h' 261 header_template = 'templates/callback_interface.h.tmpl'
258 cpp_template = 'templates/callback_interface.cpp' 262 cpp_template = 'templates/callback_interface.cpp.tmpl'
259 template_contents = self.generate_callback_interface() 263 template_contents = self.generate_callback_interface()
260 else: 264 else:
261 header_template = 'templates/interface.h' 265 header_template = 'templates/interface.h.tmpl'
262 cpp_template = 'templates/interface.cpp' 266 cpp_template = 'templates/interface.cpp.tmpl'
263 template_contents = self.generate_interface() 267 template_contents = self.generate_interface()
264 template_contents['conditional_string'] = generate_conditional_string(se lf.interface) 268 template_contents['conditional_string'] = generate_conditional_string(se lf.interface)
265 header_file_text = apply_template(header_template, template_contents) 269 header_file_text = apply_template(header_template, template_contents)
266 cpp_file_text = apply_template(cpp_template, template_contents) 270 cpp_file_text = apply_template(cpp_template, template_contents)
267 self.write_header_code(header_basename, header_file_text) 271 self.write_header_code(header_basename, header_file_text)
268 self.write_cpp_code(cpp_basename, cpp_file_text) 272 self.write_cpp_code(cpp_basename, cpp_file_text)
269 273
270 def write_header_code(self, header_basename, header_file_text): 274 def write_header_code(self, header_basename, header_file_text):
271 header_filename = os.path.join(self.output_directory, header_basename) 275 header_filename = os.path.join(self.output_directory, header_basename)
272 with open(header_filename, 'w') as header_file: 276 with open(header_filename, 'w') as header_file:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 cpp_to_js_conversion = self.generate_cpp_to_js_conversion(argument.d ata_type, argument.name, receiver, 'isolate', creation_context='v8::Handle<v8::O bject>()') 320 cpp_to_js_conversion = self.generate_cpp_to_js_conversion(argument.d ata_type, argument.name, receiver, 'isolate', creation_context='v8::Handle<v8::O bject>()')
317 return { 321 return {
318 'name': argument.name, 322 'name': argument.name,
319 'cpp_to_js_conversion': cpp_to_js_conversion, 323 'cpp_to_js_conversion': cpp_to_js_conversion,
320 } 324 }
321 325
322 def generate_method(operation): 326 def generate_method(operation):
323 def argument_declaration(argument): 327 def argument_declaration(argument):
324 return '%s %s' % (cpp_type(argument.data_type, 'raw'), argument. name) 328 return '%s %s' % (cpp_type(argument.data_type, 'raw'), argument. name)
325 329
330 call_with_this_handle = 'ThisValue' in values_for_extended_attribute s(operation.extended_attributes, 'CallWith')
Nils Barth (inactive) 2013/08/06 05:45:18 Using above functions, this can be rewritten as: c
alancutter (OOO until 2018) 2013/08/07 00:40:24 Done.
326 arguments = [] 331 arguments = []
327 custom = 'Custom' in operation.extended_attributes 332 custom = 'Custom' in operation.extended_attributes
328 if not custom: 333 if not custom:
329 self.cpp_includes |= includes_for_operation(operation) 334 self.cpp_includes |= includes_for_operation(operation)
330 if operation.data_type != 'boolean': 335 if operation.data_type != 'boolean':
331 raise Exception("We don't yet support callbacks that return non-boolean values.") 336 raise Exception("We don't yet support callbacks that return non-boolean values.")
332 arguments = [generate_argument(argument) for argument in operati on.arguments] 337 arguments = [generate_argument(argument) for argument in operati on.arguments]
333 method = { 338 method = {
339 'call_with_this_handle': call_with_this_handle,
334 'return_cpp_type': cpp_type(operation.data_type, 'RefPtr'), 340 'return_cpp_type': cpp_type(operation.data_type, 'RefPtr'),
335 'name': operation.name, 341 'name': operation.name,
336 'arguments': arguments, 342 'arguments': arguments,
337 'argument_declaration': ', '.join([argument_declaration(argument ) for argument in operation.arguments]), 343 'argument_declaration': ', '.join([argument_declaration(argument ) for argument in operation.arguments]),
338 'handles': ', '.join(['%sHandle' % argument.name for argument in operation.arguments]), 344 'handles': ', '.join(['%sHandle' % argument.name for argument in operation.arguments]),
339 'custom': custom, 345 'custom': custom,
340 } 346 }
341 return method 347 return method
342 348
343 methods = [generate_method(operation) for operation in self.interface.op erations] 349 methods = [generate_method(operation) for operation in self.interface.op erations]
344 template_contents = { 350 template_contents = {
345 'cpp_class_name': self.interface.name, 351 'cpp_class_name': self.interface.name,
346 'v8_class_name': v8_class_name(self.interface), 352 'v8_class_name': v8_class_name(self.interface),
347 'cpp_includes': sorted(list(self.cpp_includes)), 353 'cpp_includes': sorted(list(self.cpp_includes)),
348 'header_includes': sorted(list(self.header_includes)), 354 'header_includes': sorted(list(self.header_includes)),
349 'methods': methods, 355 'methods': methods,
350 } 356 }
351 return template_contents 357 return template_contents
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698