| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 IdlType.set_dictionaries(interfaces_info['dictionaries']) | 109 IdlType.set_dictionaries(interfaces_info['dictionaries']) |
| 110 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf
aces']) | 110 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf
aces']) |
| 111 IdlType.set_garbage_collected_types(interfaces_info['garbage_collected_inter
faces']) | 111 IdlType.set_garbage_collected_types(interfaces_info['garbage_collected_inter
faces']) |
| 112 IdlType.set_will_be_garbage_collected_types(interfaces_info['will_be_garbage
_collected_interfaces']) | 112 IdlType.set_will_be_garbage_collected_types(interfaces_info['will_be_garbage
_collected_interfaces']) |
| 113 v8_types.set_component_dirs(interfaces_info['component_dirs']) | 113 v8_types.set_component_dirs(interfaces_info['component_dirs']) |
| 114 | 114 |
| 115 | 115 |
| 116 class CodeGeneratorBase(object): | 116 class CodeGeneratorBase(object): |
| 117 """Base class for v8 bindings generator and IDL dictionary impl generator""" | 117 """Base class for v8 bindings generator and IDL dictionary impl generator""" |
| 118 | 118 |
| 119 def __init__(self, interfaces_info, cache_dir, output_dir): | 119 def __init__(self, interfaces_info, component_info, cache_dir, output_dir): |
| 120 interfaces_info = interfaces_info or {} | 120 interfaces_info = interfaces_info or {} |
| 121 self.interfaces_info = interfaces_info | 121 self.interfaces_info = interfaces_info |
| 122 self.component_info = component_info |
| 122 self.jinja_env = initialize_jinja_env(cache_dir) | 123 self.jinja_env = initialize_jinja_env(cache_dir) |
| 123 self.output_dir = output_dir | 124 self.output_dir = output_dir |
| 124 set_global_type_info(interfaces_info) | 125 set_global_type_info(interfaces_info) |
| 125 | 126 |
| 126 def generate_code(self, definitions, definition_name): | 127 def generate_code(self, definitions, definition_name): |
| 127 """Returns .h/.cpp code as ((path, content)...).""" | 128 """Returns .h/.cpp code as ((path, content)...).""" |
| 128 # Set local type info | 129 # Set local type info |
| 129 IdlType.set_callback_functions(definitions.callback_functions.keys()) | 130 IdlType.set_callback_functions(definitions.callback_functions.keys()) |
| 130 IdlType.set_enums((enum.name, enum.values) | 131 IdlType.set_enums((enum.name, enum.values) |
| 131 for enum in definitions.enumerations.values()) | 132 for enum in definitions.enumerations.values()) |
| 133 # Resolve typedefs |
| 134 definitions.resolve_typedefs(self.component_info['typedefs']) |
| 132 return self.generate_code_internal(definitions, definition_name) | 135 return self.generate_code_internal(definitions, definition_name) |
| 133 | 136 |
| 134 def generate_code_internal(self, definitions, definition_name): | 137 def generate_code_internal(self, definitions, definition_name): |
| 135 # This should be implemented in subclasses. | 138 # This should be implemented in subclasses. |
| 136 raise NotImplementedError() | 139 raise NotImplementedError() |
| 137 | 140 |
| 138 | 141 |
| 139 class CodeGeneratorV8(CodeGeneratorBase): | 142 class CodeGeneratorV8(CodeGeneratorBase): |
| 140 def __init__(self, interfaces_info, cache_dir, output_dir): | 143 def __init__(self, interfaces_info, component_info, cache_dir, output_dir): |
| 141 CodeGeneratorBase.__init__(self, interfaces_info, cache_dir, output_dir) | 144 CodeGeneratorBase.__init__(self, interfaces_info, component_info, cache_
dir, output_dir) |
| 142 | 145 |
| 143 def output_paths(self, definition_name): | 146 def output_paths(self, definition_name): |
| 144 header_path = posixpath.join(self.output_dir, | 147 header_path = posixpath.join(self.output_dir, |
| 145 'V8%s.h' % definition_name) | 148 'V8%s.h' % definition_name) |
| 146 cpp_path = posixpath.join(self.output_dir, 'V8%s.cpp' % definition_name) | 149 cpp_path = posixpath.join(self.output_dir, 'V8%s.cpp' % definition_name) |
| 147 return header_path, cpp_path | 150 return header_path, cpp_path |
| 148 | 151 |
| 149 def generate_code_internal(self, definitions, definition_name): | 152 def generate_code_internal(self, definitions, definition_name): |
| 150 if definition_name in definitions.interfaces: | 153 if definition_name in definitions.interfaces: |
| 151 return self.generate_interface_code( | 154 return self.generate_interface_code( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 header_text, cpp_text = render_template( | 216 header_text, cpp_text = render_template( |
| 214 include_paths, header_template, cpp_template, template_context) | 217 include_paths, header_template, cpp_template, template_context) |
| 215 header_path, cpp_path = self.output_paths(dictionary_name) | 218 header_path, cpp_path = self.output_paths(dictionary_name) |
| 216 return ( | 219 return ( |
| 217 (header_path, header_text), | 220 (header_path, header_text), |
| 218 (cpp_path, cpp_text), | 221 (cpp_path, cpp_text), |
| 219 ) | 222 ) |
| 220 | 223 |
| 221 | 224 |
| 222 class CodeGeneratorDictionaryImpl(CodeGeneratorBase): | 225 class CodeGeneratorDictionaryImpl(CodeGeneratorBase): |
| 223 def __init__(self, interfaces_info, cache_dir, output_dir): | 226 def __init__(self, interfaces_info, component_info, cache_dir, output_dir): |
| 224 CodeGeneratorBase.__init__(self, interfaces_info, cache_dir, output_dir) | 227 CodeGeneratorBase.__init__(self, interfaces_info, component_info, cache_
dir, output_dir) |
| 225 | 228 |
| 226 def output_paths(self, definition_name, interface_info): | 229 def output_paths(self, definition_name, interface_info): |
| 227 output_dir = posixpath.join(self.output_dir, | 230 output_dir = posixpath.join(self.output_dir, |
| 228 interface_info['relative_dir']) | 231 interface_info['relative_dir']) |
| 229 header_path = posixpath.join(output_dir, '%s.h' % definition_name) | 232 header_path = posixpath.join(output_dir, '%s.h' % definition_name) |
| 230 cpp_path = posixpath.join(output_dir, '%s.cpp' % definition_name) | 233 cpp_path = posixpath.join(output_dir, '%s.cpp' % definition_name) |
| 231 return header_path, cpp_path | 234 return header_path, cpp_path |
| 232 | 235 |
| 233 def generate_code_internal(self, definitions, definition_name): | 236 def generate_code_internal(self, definitions, definition_name): |
| 234 if not definition_name in definitions.dictionaries: | 237 if not definition_name in definitions.dictionaries: |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 369 |
| 367 # Create a dummy file as output for the build system, | 370 # Create a dummy file as output for the build system, |
| 368 # since filenames of individual cache files are unpredictable and opaque | 371 # since filenames of individual cache files are unpredictable and opaque |
| 369 # (they are hashes of the template path, which varies based on environment) | 372 # (they are hashes of the template path, which varies based on environment) |
| 370 with open(dummy_filename, 'w') as dummy_file: | 373 with open(dummy_filename, 'w') as dummy_file: |
| 371 pass # |open| creates or touches the file | 374 pass # |open| creates or touches the file |
| 372 | 375 |
| 373 | 376 |
| 374 if __name__ == '__main__': | 377 if __name__ == '__main__': |
| 375 sys.exit(main(sys.argv)) | 378 sys.exit(main(sys.argv)) |
| OLD | NEW |