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

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

Issue 420763002: IDL: DOM impl class code generation for IDL dictionaries (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 months 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 template_context['header_includes']) 89 template_context['header_includes'])
90 includes.update(interface_info.get('dependencies_include_paths', [])) 90 includes.update(interface_info.get('dependencies_include_paths', []))
91 template_context['cpp_includes'] = sorted(includes) 91 template_context['cpp_includes'] = sorted(includes)
92 92
93 header_text = header_template.render(template_context) 93 header_text = header_template.render(template_context)
94 cpp_text = cpp_template.render(template_context) 94 cpp_text = cpp_template.render(template_context)
95 return header_text, cpp_text 95 return header_text, cpp_text
96 96
97 97
98 class CodeGeneratorV8(object): 98 class CodeGeneratorV8(object):
99 def __init__(self, interfaces_info, cache_dir): 99 def __init__(self, interfaces_info, cache_dir, output_dir):
100 interfaces_info = interfaces_info or {} 100 interfaces_info = interfaces_info or {}
101 self.interfaces_info = interfaces_info 101 self.interfaces_info = interfaces_info
102 self.jinja_env = initialize_jinja_env(cache_dir) 102 self.jinja_env = initialize_jinja_env(cache_dir)
103 self.output_dir = output_dir
103 104
104 # Set global type info 105 # Set global type info
105 idl_types.set_ancestors(dict( 106 idl_types.set_ancestors(dict(
106 (interface_name, interface_info['ancestors']) 107 (interface_name, interface_info['ancestors'])
107 for interface_name, interface_info in interfaces_info.iteritems() 108 for interface_name, interface_info in interfaces_info.iteritems()
108 if interface_info['ancestors'])) 109 if interface_info['ancestors']))
109 IdlType.set_callback_interfaces(set( 110 IdlType.set_callback_interfaces(set(
110 interface_name 111 interface_name
111 for interface_name, interface_info in interfaces_info.iteritems() 112 for interface_name, interface_info in interfaces_info.iteritems()
112 if interface_info['is_callback_interface'])) 113 if interface_info['is_callback_interface']))
(...skipping 10 matching lines...) Expand all
123 for interface_name, interface_info in interfaces_info.iteritems() 124 for interface_name, interface_info in interfaces_info.iteritems()
124 if 'GarbageCollected' in interface_info['inherited_extended_attribut es'])) 125 if 'GarbageCollected' in interface_info['inherited_extended_attribut es']))
125 IdlType.set_will_be_garbage_collected_types(set( 126 IdlType.set_will_be_garbage_collected_types(set(
126 interface_name 127 interface_name
127 for interface_name, interface_info in interfaces_info.iteritems() 128 for interface_name, interface_info in interfaces_info.iteritems()
128 if 'WillBeGarbageCollected' in interface_info['inherited_extended_at tributes'])) 129 if 'WillBeGarbageCollected' in interface_info['inherited_extended_at tributes']))
129 v8_types.set_component_dirs(dict( 130 v8_types.set_component_dirs(dict(
130 (interface_name, interface_info['component_dir']) 131 (interface_name, interface_info['component_dir'])
131 for interface_name, interface_info in interfaces_info.iteritems())) 132 for interface_name, interface_info in interfaces_info.iteritems()))
132 133
134 def output_paths_for_bindings(self, definition_name):
135 header_path = posixpath.join(self.output_dir,
136 'V8%s.h' % definition_name)
137 cpp_path = posixpath.join(self.output_dir, 'V8%s.cpp' % definition_name)
138 return header_path, cpp_path
139
140 def output_paths_for_impl(self, definition_name):
141 header_path = posixpath.join(self.output_dir, '%s.h' % definition_name)
142 cpp_path = posixpath.join(self.output_dir, '%s.cpp' % definition_name)
143 return header_path, cpp_path
144
133 def generate_code(self, definitions, definition_name): 145 def generate_code(self, definitions, definition_name):
134 """Returns .h/.cpp code as (header_text, cpp_text).""" 146 """Returns .h/.cpp code as (header_text, cpp_text)."""
135 # Set local type info 147 # Set local type info
136 IdlType.set_callback_functions(definitions.callback_functions.keys()) 148 IdlType.set_callback_functions(definitions.callback_functions.keys())
137 IdlType.set_enums((enum.name, enum.values) 149 IdlType.set_enums((enum.name, enum.values)
138 for enum in definitions.enumerations.values()) 150 for enum in definitions.enumerations.values())
139 151
140 if definition_name in definitions.interfaces: 152 if definition_name in definitions.interfaces:
141 return self.generate_interface_code( 153 return self.generate_interface_code(
142 definitions, definition_name, 154 definitions, definition_name,
(...skipping 20 matching lines...) Expand all
163 header_template = self.jinja_env.get_template(header_template_filename) 175 header_template = self.jinja_env.get_template(header_template_filename)
164 cpp_template = self.jinja_env.get_template(cpp_template_filename) 176 cpp_template = self.jinja_env.get_template(cpp_template_filename)
165 177
166 interface_info = self.interfaces_info[interface_name] 178 interface_info = self.interfaces_info[interface_name]
167 179
168 template_context = interface_context(interface) 180 template_context = interface_context(interface)
169 # Add the include for interface itself 181 # Add the include for interface itself
170 template_context['header_includes'].add(interface_info['include_path']) 182 template_context['header_includes'].add(interface_info['include_path'])
171 header_text, cpp_text = render_template( 183 header_text, cpp_text = render_template(
172 interface_info, header_template, cpp_template, template_context) 184 interface_info, header_template, cpp_template, template_context)
173 return header_text, cpp_text 185 header_path, cpp_path = self.output_paths_for_bindings(interface_name)
186 return (
187 (header_path, header_text),
188 (cpp_path, cpp_text),
189 )
174 190
175 def generate_dictionary_code(self, definitions, dictionary_name, 191 def generate_dictionary_code(self, definitions, dictionary_name,
176 dictionary): 192 dictionary):
177 interface_info = self.interfaces_info[dictionary_name] 193 interface_info = self.interfaces_info[dictionary_name]
178 # FIXME: Generate impl class 194 bindings_results = self.generate_dictionary_bindings(
179 return self.generate_dictionary_bindings(
180 dictionary_name, interface_info, dictionary) 195 dictionary_name, interface_info, dictionary)
196 impl_results = self.generate_dictionary_impl(
197 dictionary_name, interface_info, dictionary)
198 return bindings_results + impl_results
181 199
182 def generate_dictionary_bindings(self, dictionary_name, 200 def generate_dictionary_bindings(self, dictionary_name,
183 interface_info, dictionary): 201 interface_info, dictionary):
184 header_template = self.jinja_env.get_template('dictionary_v8.h') 202 header_template = self.jinja_env.get_template('dictionary_v8.h')
185 cpp_template = self.jinja_env.get_template('dictionary_v8.cpp') 203 cpp_template = self.jinja_env.get_template('dictionary_v8.cpp')
186 template_context = v8_dictionary.dictionary_context(dictionary) 204 template_context = v8_dictionary.dictionary_context(dictionary)
187 # Add the include for interface itself 205 # Add the include for interface itself
188 template_context['header_includes'].add(interface_info['include_path']) 206 template_context['header_includes'].add(interface_info['include_path'])
189 header_text, cpp_text = render_template( 207 header_text, cpp_text = render_template(
190 interface_info, header_template, cpp_template, template_context) 208 interface_info, header_template, cpp_template, template_context)
191 return header_text, cpp_text 209 header_path, cpp_path = self.output_paths_for_bindings(dictionary_name)
210 return (
211 (header_path, header_text),
212 (cpp_path, cpp_text),
213 )
214
215 def generate_dictionary_impl(self, dictionary_name,
216 interface_info, dictionary):
217 header_template = self.jinja_env.get_template('dictionary_impl.h')
218 cpp_template = self.jinja_env.get_template('dictionary_impl.cpp')
219 template_context = v8_dictionary.dictionary_impl_context(
220 dictionary, self.interfaces_info)
221 header_text, cpp_text = render_template(
222 interface_info, header_template, cpp_template, template_context)
223 header_path, cpp_path = self.output_paths_for_impl(dictionary_name)
224 return (
225 (header_path, header_text),
226 (cpp_path, cpp_text),
227 )
192 228
193 229
194 def initialize_jinja_env(cache_dir): 230 def initialize_jinja_env(cache_dir):
195 jinja_env = jinja2.Environment( 231 jinja_env = jinja2.Environment(
196 loader=jinja2.FileSystemLoader(templates_dir), 232 loader=jinja2.FileSystemLoader(templates_dir),
197 # Bytecode cache is not concurrency-safe unless pre-cached: 233 # Bytecode cache is not concurrency-safe unless pre-cached:
198 # if pre-cached this is read-only, but writing creates a race condition. 234 # if pre-cached this is read-only, but writing creates a race condition.
199 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 235 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
200 keep_trailing_newline=True, # newline-terminate generated files 236 keep_trailing_newline=True, # newline-terminate generated files
201 lstrip_blocks=True, # so can indent control flow tags 237 lstrip_blocks=True, # so can indent control flow tags
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 286
251 # Create a dummy file as output for the build system, 287 # Create a dummy file as output for the build system,
252 # since filenames of individual cache files are unpredictable and opaque 288 # since filenames of individual cache files are unpredictable and opaque
253 # (they are hashes of the template path, which varies based on environment) 289 # (they are hashes of the template path, which varies based on environment)
254 with open(dummy_filename, 'w') as dummy_file: 290 with open(dummy_filename, 'w') as dummy_file:
255 pass # |open| creates or touches the file 291 pass # |open| creates or touches the file
256 292
257 293
258 if __name__ == '__main__': 294 if __name__ == '__main__':
259 sys.exit(main(sys.argv)) 295 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_compiler.py » ('j') | Source/bindings/scripts/v8_dictionary.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698