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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 Input: An object of class IdlDefinitions, containing an IDL interface X | 42 Input: An object of class IdlDefinitions, containing an IDL interface X |
43 Output: V8X.h and V8X.cpp | 43 Output: V8X.h and V8X.cpp |
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, render_template, normalize_and_sor
t_includes | 51 from code_generator import IDLCodeGeneratorBase, render_template, 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 | 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 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 self.additional_header_includes.add( | 124 self.additional_header_includes.add( |
125 self.info_provider.include_path_for_union_types(union_type)) | 125 self.info_provider.include_path_for_union_types(union_type)) |
126 # Need to re-assign the attribute, not just mutate idl_type, since | 126 # Need to re-assign the attribute, not just mutate idl_type, since |
127 # type(idl_type) may change. | 127 # type(idl_type) may change. |
128 setattr(typed_object, attribute_name, resolved_idl_type) | 128 setattr(typed_object, attribute_name, resolved_idl_type) |
129 | 129 |
130 def visit_typed_object(self, typed_object): | 130 def visit_typed_object(self, typed_object): |
131 self._resolve_typedefs(typed_object) | 131 self._resolve_typedefs(typed_object) |
132 | 132 |
133 | 133 |
134 class CodeGeneratorV8Base(CodeGeneratorBase): | 134 class CodeGeneratorV8Base(IDLCodeGeneratorBase): |
135 """Base class for v8 bindings generator and IDL dictionary impl generator""" | 135 """Base class for v8 bindings generator and IDL dictionary impl generator""" |
136 | 136 |
137 def __init__(self, info_provider, cache_dir, output_dir): | 137 def __init__(self, info_provider, cache_dir, output_dir): |
138 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir
, output_dir) | 138 IDLCodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_
dir, output_dir) |
139 self.typedef_resolver = TypedefResolver(info_provider) | 139 self.typedef_resolver = TypedefResolver(info_provider) |
140 | 140 |
141 def generate_code(self, definitions, definition_name): | 141 def generate_code(self, definitions, definition_name): |
142 """Returns .h/.cpp code as ((path, content)...).""" | 142 """Returns .h/.cpp code as ((path, content)...).""" |
143 # Set local type info | 143 # Set local type info |
144 if not self.should_generate_code(definitions): | 144 if not self.should_generate_code(definitions): |
145 return set() | 145 return set() |
146 | 146 |
147 # Resolve typedefs | 147 # Resolve typedefs |
148 self.typedef_resolver.resolve(definitions, definition_name) | 148 self.typedef_resolver.resolve(definitions, definition_name) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 header_text, cpp_text = self.render_template( | 282 header_text, cpp_text = self.render_template( |
283 include_paths, header_template, cpp_template, template_context) | 283 include_paths, header_template, cpp_template, template_context) |
284 header_path, cpp_path = self.output_paths( | 284 header_path, cpp_path = self.output_paths( |
285 cpp_name(dictionary), interface_info) | 285 cpp_name(dictionary), interface_info) |
286 return ( | 286 return ( |
287 (header_path, header_text), | 287 (header_path, header_text), |
288 (cpp_path, cpp_text), | 288 (cpp_path, cpp_text), |
289 ) | 289 ) |
290 | 290 |
291 | 291 |
292 class CodeGeneratorUnionType(CodeGeneratorBase): | 292 class CodeGeneratorUnionType(IDLCodeGeneratorBase): |
293 """Generates union type container classes. | 293 """Generates union type container classes. |
294 This generator is different from CodeGeneratorV8 and | 294 This generator is different from CodeGeneratorV8 and |
295 CodeGeneratorDictionaryImpl. It assumes that all union types are already | 295 CodeGeneratorDictionaryImpl. It assumes that all union types are already |
296 collected. It doesn't process idl files directly. | 296 collected. It doesn't process idl files directly. |
297 """ | 297 """ |
298 def __init__(self, info_provider, cache_dir, output_dir, target_component): | 298 def __init__(self, info_provider, cache_dir, output_dir, target_component): |
299 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir
, output_dir) | 299 IDLCodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_
dir, output_dir) |
300 self.target_component = target_component | 300 self.target_component = target_component |
301 # The code below duplicates parts of TypedefResolver. We do not use it | 301 # The code below duplicates parts of TypedefResolver. We do not use it |
302 # directly because IdlUnionType is not a type defined in | 302 # directly because IdlUnionType is not a type defined in |
303 # idl_definitions.py. What we do instead is to resolve typedefs in | 303 # idl_definitions.py. What we do instead is to resolve typedefs in |
304 # _generate_container_code() whenever a new union file is generated. | 304 # _generate_container_code() whenever a new union file is generated. |
305 self.typedefs = {} | 305 self.typedefs = {} |
306 for name, typedef in self.info_provider.typedefs.iteritems(): | 306 for name, typedef in self.info_provider.typedefs.iteritems(): |
307 self.typedefs[name] = typedef.idl_type | 307 self.typedefs[name] = typedef.idl_type |
308 | 308 |
309 def _generate_container_code(self, union_type): | 309 def _generate_container_code(self, union_type): |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 def generate_code(self): | 349 def generate_code(self): |
350 union_types = self._get_union_types_for_containers() | 350 union_types = self._get_union_types_for_containers() |
351 if not union_types: | 351 if not union_types: |
352 return () | 352 return () |
353 outputs = set() | 353 outputs = set() |
354 for union_type in union_types: | 354 for union_type in union_types: |
355 outputs.update(self._generate_container_code(union_type)) | 355 outputs.update(self._generate_container_code(union_type)) |
356 return outputs | 356 return outputs |
357 | 357 |
358 | 358 |
359 class CodeGeneratorCallbackFunction(CodeGeneratorBase): | 359 class CodeGeneratorCallbackFunction(IDLCodeGeneratorBase): |
360 def __init__(self, info_provider, cache_dir, output_dir, target_component): | 360 def __init__(self, info_provider, cache_dir, output_dir, target_component): |
361 CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_dir
, output_dir) | 361 IDLCodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, cache_
dir, output_dir) |
362 self.target_component = target_component | 362 self.target_component = target_component |
363 self.typedef_resolver = TypedefResolver(info_provider) | 363 self.typedef_resolver = TypedefResolver(info_provider) |
364 | 364 |
365 def generate_code_internal(self, callback_function, path): | 365 def generate_code_internal(self, callback_function, path): |
366 self.typedef_resolver.resolve(callback_function, callback_function.name) | 366 self.typedef_resolver.resolve(callback_function, callback_function.name) |
367 header_template = self.jinja_env.get_template('callback_function.h.tmpl'
) | 367 header_template = self.jinja_env.get_template('callback_function.h.tmpl'
) |
368 cpp_template = self.jinja_env.get_template('callback_function.cpp.tmpl') | 368 cpp_template = self.jinja_env.get_template('callback_function.cpp.tmpl') |
369 template_context = v8_callback_function.callback_function_context( | 369 template_context = v8_callback_function.callback_function_context( |
370 callback_function) | 370 callback_function) |
371 if not is_testing_target(path): | 371 if not is_testing_target(path): |
(...skipping 20 matching lines...) Expand all Loading... |
392 outputs = set() | 392 outputs = set() |
393 for callback_function_dict in callback_functions.itervalues(): | 393 for callback_function_dict in callback_functions.itervalues(): |
394 if callback_function_dict['component_dir'] != self.target_component: | 394 if callback_function_dict['component_dir'] != self.target_component: |
395 continue | 395 continue |
396 callback_function = callback_function_dict['callback_function'] | 396 callback_function = callback_function_dict['callback_function'] |
397 if 'Custom' in callback_function.extended_attributes: | 397 if 'Custom' in callback_function.extended_attributes: |
398 continue | 398 continue |
399 path = callback_function_dict['full_path'] | 399 path = callback_function_dict['full_path'] |
400 outputs.update(self.generate_code_internal(callback_function, path)) | 400 outputs.update(self.generate_code_internal(callback_function, path)) |
401 return outputs | 401 return outputs |
OLD | NEW |