| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_function |
| 55 import v8_callback_interface | 55 import v8_callback_interface |
| 56 import v8_dictionary | 56 import v8_dictionary |
| 57 from v8_globals import includes, interfaces | 57 from v8_globals import includes |
| 58 import v8_interface | 58 import v8_interface |
| 59 import v8_types | 59 import v8_types |
| 60 import v8_union | 60 import v8_union |
| 61 from v8_utilities import cpp_name | 61 from v8_utilities import cpp_name |
| 62 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 |
| 63 | 63 |
| 64 | 64 |
| 65 # 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 |
| 66 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' | 66 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' |
| 67 | 67 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return self.generate_interface_code( | 163 return self.generate_interface_code( |
| 164 definitions, definition_name, | 164 definitions, definition_name, |
| 165 definitions.interfaces[definition_name]) | 165 definitions.interfaces[definition_name]) |
| 166 if definition_name in definitions.dictionaries: | 166 if definition_name in definitions.dictionaries: |
| 167 return self.generate_dictionary_code( | 167 return self.generate_dictionary_code( |
| 168 definitions, definition_name, | 168 definitions, definition_name, |
| 169 definitions.dictionaries[definition_name]) | 169 definitions.dictionaries[definition_name]) |
| 170 raise ValueError('%s is not in IDL definitions' % definition_name) | 170 raise ValueError('%s is not in IDL definitions' % definition_name) |
| 171 | 171 |
| 172 def generate_interface_code(self, definitions, interface_name, interface): | 172 def generate_interface_code(self, definitions, interface_name, interface): |
| 173 # Store other interfaces for introspection | |
| 174 interfaces.update(definitions.interfaces) | |
| 175 | |
| 176 interface_info = self.info_provider.interfaces_info[interface_name] | 173 interface_info = self.info_provider.interfaces_info[interface_name] |
| 177 full_path = interface_info.get('full_path') | 174 full_path = interface_info.get('full_path') |
| 178 component = idl_filename_to_component(full_path) | 175 component = idl_filename_to_component(full_path) |
| 179 include_paths = interface_info.get('dependencies_include_paths') | 176 include_paths = interface_info.get('dependencies_include_paths') |
| 180 | 177 |
| 181 # Select appropriate Jinja template and contents function | 178 # Select appropriate Jinja template and contents function |
| 182 if interface.is_callback: | 179 if interface.is_callback: |
| 183 header_template_filename = 'callback_interface.h.tmpl' | 180 header_template_filename = 'callback_interface.h.tmpl' |
| 184 cpp_template_filename = 'callback_interface.cpp.tmpl' | 181 cpp_template_filename = 'callback_interface.cpp.tmpl' |
| 185 interface_context = v8_callback_interface.callback_interface_context | 182 interface_context = v8_callback_interface.callback_interface_context |
| 186 elif interface.is_partial: | 183 elif interface.is_partial: |
| 187 interface_context = v8_interface.interface_context | 184 interface_context = v8_interface.interface_context |
| 188 header_template_filename = 'partial_interface.h.tmpl' | 185 header_template_filename = 'partial_interface.h.tmpl' |
| 189 cpp_template_filename = 'partial_interface.cpp.tmpl' | 186 cpp_template_filename = 'partial_interface.cpp.tmpl' |
| 190 interface_name += 'Partial' | 187 interface_name += 'Partial' |
| 191 assert component == 'core' | 188 assert component == 'core' |
| 192 component = 'modules' | 189 component = 'modules' |
| 193 include_paths = interface_info.get('dependencies_other_component_inc
lude_paths') | 190 include_paths = interface_info.get('dependencies_other_component_inc
lude_paths') |
| 194 else: | 191 else: |
| 195 header_template_filename = 'interface.h.tmpl' | 192 header_template_filename = 'interface.h.tmpl' |
| 196 cpp_template_filename = 'interface.cpp.tmpl' | 193 cpp_template_filename = 'interface.cpp.tmpl' |
| 197 interface_context = v8_interface.interface_context | 194 interface_context = v8_interface.interface_context |
| 198 | 195 |
| 199 template_context = interface_context(interface) | 196 template_context = interface_context(interface, definitions.interfaces) |
| 200 includes.update(interface_info.get('cpp_includes', {}).get(component, se
t())) | 197 includes.update(interface_info.get('cpp_includes', {}).get(component, se
t())) |
| 201 if not interface.is_partial and not is_testing_target(full_path): | 198 if not interface.is_partial and not is_testing_target(full_path): |
| 202 template_context['header_includes'].add(self.info_provider.include_p
ath_for_export) | 199 template_context['header_includes'].add(self.info_provider.include_p
ath_for_export) |
| 203 template_context['exported'] = self.info_provider.specifier_for_expo
rt | 200 template_context['exported'] = self.info_provider.specifier_for_expo
rt |
| 204 # Add the include for interface itself | 201 # Add the include for interface itself |
| 205 if IdlType(interface_name).is_typed_array: | 202 if IdlType(interface_name).is_typed_array: |
| 206 template_context['header_includes'].add('core/dom/DOMTypedArray.h') | 203 template_context['header_includes'].add('core/dom/DOMTypedArray.h') |
| 207 elif interface_info['include_path']: | 204 elif interface_info['include_path']: |
| 208 template_context['header_includes'].add(interface_info['include_path
']) | 205 template_context['header_includes'].add(interface_info['include_path
']) |
| 209 template_context['header_includes'].update( | 206 template_context['header_includes'].update( |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 def generate_code(self): | 367 def generate_code(self): |
| 371 callback_functions = self.info_provider.callback_functions | 368 callback_functions = self.info_provider.callback_functions |
| 372 if not callback_functions: | 369 if not callback_functions: |
| 373 return () | 370 return () |
| 374 outputs = set() | 371 outputs = set() |
| 375 for callback_function_dict in callback_functions.itervalues(): | 372 for callback_function_dict in callback_functions.itervalues(): |
| 376 callback_function = callback_function_dict['callback_function'] | 373 callback_function = callback_function_dict['callback_function'] |
| 377 path = callback_function_dict['full_path'] | 374 path = callback_function_dict['full_path'] |
| 378 outputs.update(self.generate_code_internal(callback_function, path)) | 375 outputs.update(self.generate_code_internal(callback_function, path)) |
| 379 return outputs | 376 return outputs |
| OLD | NEW |