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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 assert is_valid_component_dependency(component, dependency) | 96 assert is_valid_component_dependency(component, dependency) |
97 includes.add(include_path) | 97 includes.add(include_path) |
98 | 98 |
99 template_context['cpp_includes'] = sorted(includes) | 99 template_context['cpp_includes'] = sorted(includes) |
100 | 100 |
101 header_text = header_template.render(template_context) | 101 header_text = header_template.render(template_context) |
102 cpp_text = cpp_template.render(template_context) | 102 cpp_text = cpp_template.render(template_context) |
103 return header_text, cpp_text | 103 return header_text, cpp_text |
104 | 104 |
105 | 105 |
106 def set_global_type_info(interfaces_info): | 106 def set_global_type_info(info_provider): |
| 107 interfaces_info = info_provider.interfaces_info |
107 idl_types.set_ancestors(interfaces_info['ancestors']) | 108 idl_types.set_ancestors(interfaces_info['ancestors']) |
108 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces']) | 109 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces']) |
109 IdlType.set_dictionaries(interfaces_info['dictionaries']) | 110 IdlType.set_dictionaries(interfaces_info['dictionaries']) |
| 111 IdlType.set_enums(info_provider.enumerations) |
110 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf
aces']) | 112 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf
aces']) |
111 IdlType.set_garbage_collected_types(interfaces_info['garbage_collected_inter
faces']) | 113 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']) | 114 IdlType.set_will_be_garbage_collected_types(interfaces_info['will_be_garbage
_collected_interfaces']) |
113 v8_types.set_component_dirs(interfaces_info['component_dirs']) | 115 v8_types.set_component_dirs(interfaces_info['component_dirs']) |
114 | 116 |
115 | 117 |
116 class CodeGeneratorBase(object): | 118 class CodeGeneratorBase(object): |
117 """Base class for v8 bindings generator and IDL dictionary impl generator""" | 119 """Base class for v8 bindings generator and IDL dictionary impl generator""" |
118 | 120 |
119 def __init__(self, info_provider, cache_dir, output_dir): | 121 def __init__(self, info_provider, cache_dir, output_dir): |
120 self.info_provider = info_provider | 122 self.info_provider = info_provider |
121 self.jinja_env = initialize_jinja_env(cache_dir) | 123 self.jinja_env = initialize_jinja_env(cache_dir) |
122 self.output_dir = output_dir | 124 self.output_dir = output_dir |
123 set_global_type_info(info_provider.interfaces_info) | 125 set_global_type_info(info_provider) |
124 | 126 |
125 def generate_code(self, definitions, definition_name): | 127 def generate_code(self, definitions, definition_name): |
126 """Returns .h/.cpp code as ((path, content)...).""" | 128 """Returns .h/.cpp code as ((path, content)...).""" |
127 # Set local type info | 129 # Set local type info |
128 IdlType.set_callback_functions(definitions.callback_functions.keys()) | 130 IdlType.set_callback_functions(definitions.callback_functions.keys()) |
129 IdlType.set_enums((enum.name, enum.values) | |
130 for enum in definitions.enumerations.values()) | |
131 # Resolve typedefs | 131 # Resolve typedefs |
132 definitions.resolve_typedefs(self.info_provider.component_info['typedefs
']) | 132 definitions.resolve_typedefs(self.info_provider.component_info['typedefs
']) |
133 return self.generate_code_internal(definitions, definition_name) | 133 return self.generate_code_internal(definitions, definition_name) |
134 | 134 |
135 def generate_code_internal(self, definitions, definition_name): | 135 def generate_code_internal(self, definitions, definition_name): |
136 # This should be implemented in subclasses. | 136 # This should be implemented in subclasses. |
137 raise NotImplementedError() | 137 raise NotImplementedError() |
138 | 138 |
139 | 139 |
140 class CodeGeneratorV8(CodeGeneratorBase): | 140 class CodeGeneratorV8(CodeGeneratorBase): |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 """Generates union type container classes. | 266 """Generates union type container classes. |
267 This generator is different from CodeGeneratorV8 and | 267 This generator is different from CodeGeneratorV8 and |
268 CodeGeneratorDictionaryImpl. It assumes that all union types are already | 268 CodeGeneratorDictionaryImpl. It assumes that all union types are already |
269 collected. It doesn't process idl files directly. | 269 collected. It doesn't process idl files directly. |
270 """ | 270 """ |
271 def __init__(self, info_provider, cache_dir, output_dir, target_component): | 271 def __init__(self, info_provider, cache_dir, output_dir, target_component): |
272 self.info_provider = info_provider | 272 self.info_provider = info_provider |
273 self.jinja_env = initialize_jinja_env(cache_dir) | 273 self.jinja_env = initialize_jinja_env(cache_dir) |
274 self.output_dir = output_dir | 274 self.output_dir = output_dir |
275 self.target_component = target_component | 275 self.target_component = target_component |
276 set_global_type_info(info_provider.interfaces_info) | 276 set_global_type_info(info_provider) |
277 | 277 |
278 def generate_code(self): | 278 def generate_code(self): |
279 union_types = self.info_provider.union_types | 279 union_types = self.info_provider.union_types |
280 if not union_types: | 280 if not union_types: |
281 return () | 281 return () |
282 header_template = self.jinja_env.get_template('union.h') | 282 header_template = self.jinja_env.get_template('union.h') |
283 cpp_template = self.jinja_env.get_template('union.cpp') | 283 cpp_template = self.jinja_env.get_template('union.cpp') |
284 template_context = v8_union.union_context( | 284 template_context = v8_union.union_context( |
285 union_types, self.info_provider.interfaces_info) | 285 union_types, self.info_provider.interfaces_info) |
286 template_context['code_generator'] = module_pyname | 286 template_context['code_generator'] = module_pyname |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 | 390 |
391 # Create a dummy file as output for the build system, | 391 # Create a dummy file as output for the build system, |
392 # since filenames of individual cache files are unpredictable and opaque | 392 # since filenames of individual cache files are unpredictable and opaque |
393 # (they are hashes of the template path, which varies based on environment) | 393 # (they are hashes of the template path, which varies based on environment) |
394 with open(dummy_filename, 'w') as dummy_file: | 394 with open(dummy_filename, 'w') as dummy_file: |
395 pass # |open| creates or touches the file | 395 pass # |open| creates or touches the file |
396 | 396 |
397 | 397 |
398 if __name__ == '__main__': | 398 if __name__ == '__main__': |
399 sys.exit(main(sys.argv)) | 399 sys.exit(main(sys.argv)) |
OLD | NEW |