Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: Source/bindings/scripts/code_generator_v8.py

Issue 680193003: IDL: Generate union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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):
107 idl_types.set_ancestors(interfaces_info['ancestors'])
108 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces'])
109 IdlType.set_dictionaries(interfaces_info['dictionaries'])
110 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_interf aces'])
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'])
113 v8_types.set_component_dirs(interfaces_info['component_dirs'])
114
115
106 class CodeGeneratorBase(object): 116 class CodeGeneratorBase(object):
107 """Base class for v8 bindings generator and IDL dictionary impl generator""" 117 """Base class for v8 bindings generator and IDL dictionary impl generator"""
108 118
109 def __init__(self, interfaces_info, cache_dir, output_dir): 119 def __init__(self, interfaces_info, cache_dir, output_dir):
110 interfaces_info = interfaces_info or {} 120 interfaces_info = interfaces_info or {}
111 self.interfaces_info = interfaces_info 121 self.interfaces_info = interfaces_info
112 self.jinja_env = initialize_jinja_env(cache_dir) 122 self.jinja_env = initialize_jinja_env(cache_dir)
113 self.output_dir = output_dir 123 self.output_dir = output_dir
114 124 set_global_type_info(interfaces_info)
115 # Set global type info
116 idl_types.set_ancestors(interfaces_info['ancestors'])
117 IdlType.set_callback_interfaces(interfaces_info['callback_interfaces'])
118 IdlType.set_dictionaries(interfaces_info['dictionaries'])
119 IdlType.set_implemented_as_interfaces(interfaces_info['implemented_as_in terfaces'])
120 IdlType.set_garbage_collected_types(interfaces_info['garbage_collected_i nterfaces'])
121 IdlType.set_will_be_garbage_collected_types(interfaces_info['will_be_gar bage_collected_interfaces'])
122 v8_types.set_component_dirs(interfaces_info['component_dirs'])
123 125
124 def generate_code(self, definitions, definition_name): 126 def generate_code(self, definitions, definition_name):
125 """Returns .h/.cpp code as ((path, content)...).""" 127 """Returns .h/.cpp code as ((path, content)...)."""
126 # Set local type info 128 # Set local type info
127 IdlType.set_callback_functions(definitions.callback_functions.keys()) 129 IdlType.set_callback_functions(definitions.callback_functions.keys())
128 IdlType.set_enums((enum.name, enum.values) 130 IdlType.set_enums((enum.name, enum.values)
129 for enum in definitions.enumerations.values()) 131 for enum in definitions.enumerations.values())
130 return self.generate_code_internal(definitions, definition_name) 132 return self.generate_code_internal(definitions, definition_name)
131 133
132 def generate_code_internal(self, definitions, definition_name): 134 def generate_code_internal(self, definitions, definition_name):
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 header_text, cpp_text = render_template( 243 header_text, cpp_text = render_template(
242 include_paths, header_template, cpp_template, template_context) 244 include_paths, header_template, cpp_template, template_context)
243 header_path, cpp_path = self.output_paths( 245 header_path, cpp_path = self.output_paths(
244 definition_name, interface_info) 246 definition_name, interface_info)
245 return ( 247 return (
246 (header_path, header_text), 248 (header_path, header_text),
247 (cpp_path, cpp_text), 249 (cpp_path, cpp_text),
248 ) 250 )
249 251
250 252
251 class CodeGeneratorUnionTypeContainers(object): 253 class CodeGeneratorUnionType(object):
252 """Generates union type container classes. 254 """Generates union type container classes.
253 This generator is different from CodeGeneratorV8 and 255 This generator is different from CodeGeneratorV8 and
254 CodeGeneratorDictionaryImpl. It assumes that all union types are already 256 CodeGeneratorDictionaryImpl. It assumes that all union types are already
255 collected. It doesn't process idl files directly. 257 collected. It doesn't process idl files directly.
256 """ 258 """
257 def __init__(self, interfaces_info, cache_dir, output_dir, target_component) : 259 def __init__(self, interfaces_info, cache_dir, output_dir, target_component) :
258 self.interfaces_info = interfaces_info 260 self.interfaces_info = interfaces_info
259 self.jinja_env = initialize_jinja_env(cache_dir) 261 self.jinja_env = initialize_jinja_env(cache_dir)
260 self.output_dir = output_dir 262 self.output_dir = output_dir
261 self.target_component = target_component 263 self.target_component = target_component
264 set_global_type_info(interfaces_info)
262 265
263 def generate_code(self, union_types): 266 def generate_code(self, union_types):
264 if not union_types: 267 if not union_types:
265 return () 268 return ()
266 header_template = self.jinja_env.get_template('union.h') 269 header_template = self.jinja_env.get_template('union.h')
267 cpp_template = self.jinja_env.get_template('union.cpp') 270 cpp_template = self.jinja_env.get_template('union.cpp')
268 template_context = v8_union.union_context( 271 template_context = v8_union.union_context(
269 sorted(union_types, key=lambda union_type: union_type.name)) 272 sorted(union_types, key=lambda union_type: union_type.name),
273 self.interfaces_info)
270 template_context['code_generator'] = module_pyname 274 template_context['code_generator'] = module_pyname
271 capitalized_component = self.target_component.capitalize() 275 capitalized_component = self.target_component.capitalize()
276 template_context['header_filename'] = 'bindings/%s/v8/UnionTypes%s.h' % (
277 self.target_component, capitalized_component)
272 template_context['macro_guard'] = 'UnionType%s_h' % capitalized_componen t 278 template_context['macro_guard'] = 'UnionType%s_h' % capitalized_componen t
273 header_text = header_template.render(template_context) 279 header_text = header_template.render(template_context)
274 cpp_text = cpp_template.render(template_context) 280 cpp_text = cpp_template.render(template_context)
275 header_path = posixpath.join(self.output_dir, 281 header_path = posixpath.join(self.output_dir,
276 'UnionTypes%s.h' % capitalized_component) 282 'UnionTypes%s.h' % capitalized_component)
277 cpp_path = posixpath.join(self.output_dir, 283 cpp_path = posixpath.join(self.output_dir,
278 'UnionTypes%s.cpp' % capitalized_component) 284 'UnionTypes%s.cpp' % capitalized_component)
279 return ( 285 return (
280 (header_path, header_text), 286 (header_path, header_text),
281 (cpp_path, cpp_text), 287 (cpp_path, cpp_text),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 367
362 # Create a dummy file as output for the build system, 368 # Create a dummy file as output for the build system,
363 # since filenames of individual cache files are unpredictable and opaque 369 # since filenames of individual cache files are unpredictable and opaque
364 # (they are hashes of the template path, which varies based on environment) 370 # (they are hashes of the template path, which varies based on environment)
365 with open(dummy_filename, 'w') as dummy_file: 371 with open(dummy_filename, 'w') as dummy_file:
366 pass # |open| creates or touches the file 372 pass # |open| creates or touches the file
367 373
368 374
369 if __name__ == '__main__': 375 if __name__ == '__main__':
370 sys.exit(main(sys.argv)) 376 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698