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

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

Issue 2312093003: Generated bindings for IDL callback functions (Closed)
Patch Set: Addressed win failure Created 4 years, 3 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 (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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 # jinja2 is in chromium's third_party directory. 69 # jinja2 is in chromium's third_party directory.
70 # Insert at 1 so at front to override system libraries, and 70 # Insert at 1 so at front to override system libraries, and
71 # after path[0] == invoking script dir 71 # after path[0] == invoking script dir
72 sys.path.insert(1, third_party_dir) 72 sys.path.insert(1, third_party_dir)
73 import jinja2 73 import jinja2
74 74
75 from idl_definitions import Visitor 75 from idl_definitions import Visitor
76 import idl_types 76 import idl_types
77 from idl_types import IdlType 77 from idl_types import IdlType
78 from v8_attributes import attribute_filters 78 from v8_attributes import attribute_filters
79 import v8_callback_function
79 import v8_callback_interface 80 import v8_callback_interface
80 import v8_dictionary 81 import v8_dictionary
81 from v8_globals import includes, interfaces 82 from v8_globals import includes, interfaces
82 import v8_interface 83 import v8_interface
83 from v8_methods import method_filters 84 from v8_methods import method_filters
84 import v8_types 85 import v8_types
85 import v8_union 86 import v8_union
86 from v8_utilities import capitalize, cpp_name, for_origin_trial_feature, unique_ by 87 from v8_utilities import capitalize, cpp_name, for_origin_trial_feature, unique_ by
87 from utilities import ( 88 from utilities import (
88 idl_filename_to_component, is_valid_component_dependency, is_testing_target, 89 idl_filename_to_component, is_valid_component_dependency, is_testing_target,
(...skipping 28 matching lines...) Expand all
117 118
118 header_text = header_template.render(template_context) 119 header_text = header_template.render(template_context)
119 cpp_text = cpp_template.render(template_context) 120 cpp_text = cpp_template.render(template_context)
120 return header_text, cpp_text 121 return header_text, cpp_text
121 122
122 123
123 def set_global_type_info(info_provider): 124 def set_global_type_info(info_provider):
124 interfaces_info = info_provider.interfaces_info 125 interfaces_info = info_provider.interfaces_info
125 idl_types.set_ancestors(interfaces_info['ancestors']) 126 idl_types.set_ancestors(interfaces_info['ancestors'])
126 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces']) 127 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces'])
128 IdlType.set_experimental_callback_functions(
129 info_provider.callback_functions)
127 IdlType.set_dictionaries(interfaces_info['dictionaries']) 130 IdlType.set_dictionaries(interfaces_info['dictionaries'])
128 IdlType.set_enums(info_provider.enumerations) 131 IdlType.set_enums(info_provider.enumerations)
129 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf aces']) 132 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf aces'])
130 IdlType.set_garbage_collected_types(interfaces_info['garbage_collected_inter faces']) 133 IdlType.set_garbage_collected_types(interfaces_info['garbage_collected_inter faces'])
131 v8_types.set_component_dirs(interfaces_info['component_dirs']) 134 v8_types.set_component_dirs(interfaces_info['component_dirs'])
132 135
133 136
134 def should_generate_code(definitions): 137 def should_generate_code(definitions):
135 return definitions.interfaces or definitions.dictionaries 138 return definitions.interfaces or definitions.dictionaries
136 139
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 def generate_code(self): 412 def generate_code(self):
410 union_types = self._get_union_types_for_containers() 413 union_types = self._get_union_types_for_containers()
411 if not union_types: 414 if not union_types:
412 return () 415 return ()
413 outputs = set() 416 outputs = set()
414 for union_type in union_types: 417 for union_type in union_types:
415 outputs.update(self._generate_container_code(union_type)) 418 outputs.update(self._generate_container_code(union_type))
416 return outputs 419 return outputs
417 420
418 421
422 class CodeGeneratorCallbackFunction(object):
423 def __init__(self, info_provider, cache_dir, output_dir, target_component):
424 self.info_provider = info_provider
425 self.jinja_env = initialize_jinja_env(cache_dir)
426 self.output_dir = output_dir
427 self.target_component = target_component
428 set_global_type_info(info_provider)
429
430 def generate_code_internal(self, callback_function, path):
431 header_template = self.jinja_env.get_template('callback_function.h')
432 cpp_template = self.jinja_env.get_template('callback_function.cpp')
433 template_context = v8_callback_function.callback_function_context(
434 callback_function)
435 if not is_testing_target(path):
436 template_context['exported'] = self.info_provider.specifier_for_expo rt
437 template_context['header_includes'].append(
438 self.info_provider.include_path_for_export)
439 template_context['header_includes'] = normalize_and_sort_includes(
440 template_context['header_includes'])
441 template_context['code_generator'] = module_pyname
442 header_text = header_template.render(template_context)
443 cpp_text = cpp_template.render(template_context)
444 header_path = posixpath.join(self.output_dir, 'V8%s.h' % callback_functi on.name)
445 cpp_path = posixpath.join(self.output_dir, 'V8%s.cpp' % callback_functio n.name)
446 return (
447 (header_path, header_text),
448 (cpp_path, cpp_text),
449 )
450
451 def generate_code(self):
452 callback_functions = self.info_provider.callback_functions
453 if not callback_functions:
454 return ()
455 outputs = set()
456 for callback_function_dict in callback_functions.itervalues():
457 callback_function = callback_function_dict['callback_function']
458 path = callback_function_dict['full_path']
459 outputs.update(self.generate_code_internal(callback_function, path))
460 return outputs
461
462
419 def initialize_jinja_env(cache_dir): 463 def initialize_jinja_env(cache_dir):
420 jinja_env = jinja2.Environment( 464 jinja_env = jinja2.Environment(
421 loader=jinja2.FileSystemLoader(templates_dir), 465 loader=jinja2.FileSystemLoader(templates_dir),
422 # Bytecode cache is not concurrency-safe unless pre-cached: 466 # Bytecode cache is not concurrency-safe unless pre-cached:
423 # if pre-cached this is read-only, but writing creates a race condition. 467 # if pre-cached this is read-only, but writing creates a race condition.
424 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 468 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
425 keep_trailing_newline=True, # newline-terminate generated files 469 keep_trailing_newline=True, # newline-terminate generated files
426 lstrip_blocks=True, # so can indent control flow tags 470 lstrip_blocks=True, # so can indent control flow tags
427 trim_blocks=True) 471 trim_blocks=True)
428 jinja_env.filters.update({ 472 jinja_env.filters.update({
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 535
492 # Create a dummy file as output for the build system, 536 # Create a dummy file as output for the build system,
493 # since filenames of individual cache files are unpredictable and opaque 537 # since filenames of individual cache files are unpredictable and opaque
494 # (they are hashes of the template path, which varies based on environment) 538 # (they are hashes of the template path, which varies based on environment)
495 with open(dummy_filename, 'w') as dummy_file: 539 with open(dummy_filename, 'w') as dummy_file:
496 pass # |open| creates or touches the file 540 pass # |open| creates or touches the file
497 541
498 542
499 if __name__ == '__main__': 543 if __name__ == '__main__':
500 sys.exit(main(sys.argv)) 544 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698