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

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

Issue 735983002: IDL: Defer typedef resolution (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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 header_text, cpp_text = render_template( 217 header_text, cpp_text = render_template(
215 include_paths, header_template, cpp_template, template_context) 218 include_paths, header_template, cpp_template, template_context)
216 header_path, cpp_path = self.output_paths(dictionary_name) 219 header_path, cpp_path = self.output_paths(dictionary_name)
217 return ( 220 return (
218 (header_path, header_text), 221 (header_path, header_text),
219 (cpp_path, cpp_text), 222 (cpp_path, cpp_text),
220 ) 223 )
221 224
222 225
223 class CodeGeneratorDictionaryImpl(CodeGeneratorBase): 226 class CodeGeneratorDictionaryImpl(CodeGeneratorBase):
224 def __init__(self, interfaces_info, cache_dir, output_dir): 227 def __init__(self, interfaces_info, component_info, cache_dir, output_dir):
225 CodeGeneratorBase.__init__(self, interfaces_info, cache_dir, output_dir) 228 CodeGeneratorBase.__init__(self, interfaces_info, component_info, cache_ dir, output_dir)
226 229
227 def output_paths(self, definition_name, interface_info): 230 def output_paths(self, definition_name, interface_info):
228 output_dir = posixpath.join(self.output_dir, 231 output_dir = posixpath.join(self.output_dir,
229 interface_info['relative_dir']) 232 interface_info['relative_dir'])
230 header_path = posixpath.join(output_dir, '%s.h' % definition_name) 233 header_path = posixpath.join(output_dir, '%s.h' % definition_name)
231 cpp_path = posixpath.join(output_dir, '%s.cpp' % definition_name) 234 cpp_path = posixpath.join(output_dir, '%s.cpp' % definition_name)
232 return header_path, cpp_path 235 return header_path, cpp_path
233 236
234 def generate_code_internal(self, definitions, definition_name): 237 def generate_code_internal(self, definitions, definition_name):
235 if not definition_name in definitions.dictionaries: 238 if not definition_name in definitions.dictionaries:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 370
368 # Create a dummy file as output for the build system, 371 # Create a dummy file as output for the build system,
369 # since filenames of individual cache files are unpredictable and opaque 372 # since filenames of individual cache files are unpredictable and opaque
370 # (they are hashes of the template path, which varies based on environment) 373 # (they are hashes of the template path, which varies based on environment)
371 with open(dummy_filename, 'w') as dummy_file: 374 with open(dummy_filename, 'w') as dummy_file:
372 pass # |open| creates or touches the file 375 pass # |open| creates or touches the file
373 376
374 377
375 if __name__ == '__main__': 378 if __name__ == '__main__':
376 sys.exit(main(sys.argv)) 379 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « Source/bindings/modules/v8/generated.gyp ('k') | Source/bindings/scripts/compute_interfaces_info_individual.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698