OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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): | |
bashi
2016/09/13 00:35:05
This class is similar to CodeGeneratorUnionType. I
lkawai
2016/09/16 05:05:49
Acknowledged.
| |
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): | |
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 template_context['header_includes'].add( | |
436 self.info_provider.include_path_for_export) | |
437 template_context['header_includes'] = normalize_and_sort_includes( | |
438 template_context['header_includes']) | |
439 template_context['code_generator'] = module_pyname | |
440 template_context['exported'] = self.info_provider.specifier_for_export | |
441 header_text = header_template.render(template_context) | |
442 cpp_text = cpp_template.render(template_context) | |
443 header_path = posixpath.join(self.output_dir, 'V8%s.h' % callback_functi on.name) | |
444 cpp_path = posixpath.join(self.output_dir, 'V8%s.cpp' % callback_functio n.name) | |
445 return ( | |
446 (header_path, header_text), | |
447 (cpp_path, cpp_text), | |
448 ) | |
449 | |
450 def generate_code(self): | |
451 callback_functions = self.info_provider.callback_functions | |
452 if not callback_functions: | |
453 return () | |
454 outputs = set() | |
455 for callback_function_dict in callback_functions.itervalues(): | |
456 callback_function = callback_function_dict['callback_function'] | |
457 outputs.update(self.generate_code_internal(callback_function)) | |
458 return outputs | |
459 | |
460 | |
419 def initialize_jinja_env(cache_dir): | 461 def initialize_jinja_env(cache_dir): |
420 jinja_env = jinja2.Environment( | 462 jinja_env = jinja2.Environment( |
421 loader=jinja2.FileSystemLoader(templates_dir), | 463 loader=jinja2.FileSystemLoader(templates_dir), |
422 # Bytecode cache is not concurrency-safe unless pre-cached: | 464 # Bytecode cache is not concurrency-safe unless pre-cached: |
423 # if pre-cached this is read-only, but writing creates a race condition. | 465 # if pre-cached this is read-only, but writing creates a race condition. |
424 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), | 466 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), |
425 keep_trailing_newline=True, # newline-terminate generated files | 467 keep_trailing_newline=True, # newline-terminate generated files |
426 lstrip_blocks=True, # so can indent control flow tags | 468 lstrip_blocks=True, # so can indent control flow tags |
427 trim_blocks=True) | 469 trim_blocks=True) |
428 jinja_env.filters.update({ | 470 jinja_env.filters.update({ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 | 532 |
491 # Create a dummy file as output for the build system, | 533 # Create a dummy file as output for the build system, |
492 # since filenames of individual cache files are unpredictable and opaque | 534 # since filenames of individual cache files are unpredictable and opaque |
493 # (they are hashes of the template path, which varies based on environment) | 535 # (they are hashes of the template path, which varies based on environment) |
494 with open(dummy_filename, 'w') as dummy_file: | 536 with open(dummy_filename, 'w') as dummy_file: |
495 pass # |open| creates or touches the file | 537 pass # |open| creates or touches the file |
496 | 538 |
497 | 539 |
498 if __name__ == '__main__': | 540 if __name__ == '__main__': |
499 sys.exit(main(sys.argv)) | 541 sys.exit(main(sys.argv)) |
OLD | NEW |