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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 45 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
46 """ | 46 """ |
47 | 47 |
48 import os | 48 import os |
49 import posixpath | 49 import posixpath |
50 | 50 |
51 from code_generator import CodeGeneratorBase, normalize_and_sort_includes | 51 from code_generator import CodeGeneratorBase, normalize_and_sort_includes |
52 from idl_definitions import Visitor | 52 from idl_definitions import Visitor |
53 from idl_types import IdlType | 53 from idl_types import IdlType |
| 54 import v8_callback_function |
54 import v8_callback_interface | 55 import v8_callback_interface |
55 import v8_dictionary | 56 import v8_dictionary |
56 from v8_globals import includes, interfaces | 57 from v8_globals import includes, interfaces |
57 import v8_interface | 58 import v8_interface |
58 import v8_types | 59 import v8_types |
59 import v8_union | 60 import v8_union |
60 from v8_utilities import cpp_name | 61 from v8_utilities import cpp_name |
61 from utilities import idl_filename_to_component, is_testing_target, shorten_unio
n_name | 62 from utilities import idl_filename_to_component, is_testing_target, shorten_unio
n_name |
62 | 63 |
| 64 |
63 # Make sure extension is .py, not .pyc or .pyo, so doesn't depend on caching | 65 # Make sure extension is .py, not .pyc or .pyo, so doesn't depend on caching |
64 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' | 66 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' |
65 | 67 |
66 def depending_union_type(idl_type): | 68 def depending_union_type(idl_type): |
67 """Returns the union type name if the given idl_type depends on a | 69 """Returns the union type name if the given idl_type depends on a |
68 union type. | 70 union type. |
69 """ | 71 """ |
70 def find_base_type(current_type): | 72 def find_base_type(current_type): |
71 if current_type.is_array_or_sequence_type: | 73 if current_type.is_array_or_sequence_type: |
72 return find_base_type(current_type.element_type) | 74 return find_base_type(current_type.element_type) |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 return union_types_for_containers | 331 return union_types_for_containers |
330 | 332 |
331 def generate_code(self): | 333 def generate_code(self): |
332 union_types = self._get_union_types_for_containers() | 334 union_types = self._get_union_types_for_containers() |
333 if not union_types: | 335 if not union_types: |
334 return () | 336 return () |
335 outputs = set() | 337 outputs = set() |
336 for union_type in union_types: | 338 for union_type in union_types: |
337 outputs.update(self._generate_container_code(union_type)) | 339 outputs.update(self._generate_container_code(union_type)) |
338 return outputs | 340 return outputs |
| 341 |
| 342 |
| 343 class CodeGeneratorCallbackFunction(CodeGeneratorBase): |
| 344 def __init__(self, info_provider, cache_dir, output_dir, target_component): |
| 345 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir
, output_dir) |
| 346 self.target_component = target_component |
| 347 |
| 348 def generate_code_internal(self, callback_function, path): |
| 349 header_template = self.jinja_env.get_template('callback_function.h') |
| 350 cpp_template = self.jinja_env.get_template('callback_function.cpp') |
| 351 template_context = v8_callback_function.callback_function_context( |
| 352 callback_function) |
| 353 if not is_testing_target(path): |
| 354 template_context['exported'] = self.info_provider.specifier_for_expo
rt |
| 355 template_context['header_includes'].append( |
| 356 self.info_provider.include_path_for_export) |
| 357 template_context['header_includes'] = normalize_and_sort_includes( |
| 358 template_context['header_includes']) |
| 359 template_context['code_generator'] = MODULE_PYNAME |
| 360 header_text = header_template.render(template_context) |
| 361 cpp_text = cpp_template.render(template_context) |
| 362 header_path = posixpath.join(self.output_dir, 'V8%s.h' % callback_functi
on.name) |
| 363 cpp_path = posixpath.join(self.output_dir, 'V8%s.cpp' % callback_functio
n.name) |
| 364 return ( |
| 365 (header_path, header_text), |
| 366 (cpp_path, cpp_text), |
| 367 ) |
| 368 |
| 369 # pylint: disable=W0221 |
| 370 def generate_code(self): |
| 371 callback_functions = self.info_provider.callback_functions |
| 372 if not callback_functions: |
| 373 return () |
| 374 outputs = set() |
| 375 for callback_function_dict in callback_functions.itervalues(): |
| 376 callback_function = callback_function_dict['callback_function'] |
| 377 path = callback_function_dict['full_path'] |
| 378 outputs.update(self.generate_code_internal(callback_function, path)) |
| 379 return outputs |
OLD | NEW |