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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 | 202 |
203 | 203 |
204 def cpp_class_name(interface): | 204 def cpp_class_name(interface): |
205 return interface.extended_attributes.get('ImplementedAs', interface.name) | 205 return interface.extended_attributes.get('ImplementedAs', interface.name) |
206 | 206 |
207 | 207 |
208 def v8_class_name(interface): | 208 def v8_class_name(interface): |
209 return v8_type(interface.name) | 209 return v8_type(interface.name) |
210 | 210 |
211 | 211 |
212 def has_extended_attribute_value(extended_attributes, key, value): | |
213 return key in extended_attributes and value in extended_attribute_values(ext ended_attributes, key) | |
214 | |
215 | |
216 def extended_attribute_values(extended_attributes, key): | |
haraken
2013/08/07 00:55:54
Nit: Do you need this helper? You might be able to
alancutter (OOO until 2018)
2013/08/07 01:12:48
I think the motivation for making it a separate fu
Nils Barth (inactive)
2013/08/07 01:50:34
For reference, I suggested these functions;
as Ala
| |
217 if key not in extended_attributes: | |
218 return None | |
219 values_string = extended_attributes[key] | |
220 if not values_string: | |
221 return [] | |
222 return re.split('[|&]', values_string) | |
223 | |
224 | |
212 class CodeGeneratorV8: | 225 class CodeGeneratorV8: |
213 def __init__(self, definitions, interface_name, output_directory, relative_d ir_posix, idl_directories, verbose=False): | 226 def __init__(self, definitions, interface_name, output_directory, relative_d ir_posix, idl_directories, verbose=False): |
214 self.idl_definitions = definitions | 227 self.idl_definitions = definitions |
215 self.interface_name = interface_name | 228 self.interface_name = interface_name |
216 self.idl_directories = idl_directories | 229 self.idl_directories = idl_directories |
217 self.output_directory = output_directory | 230 self.output_directory = output_directory |
218 self.relative_dir_posix = relative_dir_posix | 231 self.relative_dir_posix = relative_dir_posix |
219 self.verbose = verbose | 232 self.verbose = verbose |
220 self.interface = None | 233 self.interface = None |
221 self.header_includes = set() | 234 self.header_includes = set() |
(...skipping 25 matching lines...) Expand all Loading... | |
247 {cpp_basename} at every build. This file must not be tried to compile. | 260 {cpp_basename} at every build. This file must not be tried to compile. |
248 */ | 261 */ |
249 """.format(**locals()) | 262 """.format(**locals()) |
250 self.write_header_code(header_basename, contents) | 263 self.write_header_code(header_basename, contents) |
251 self.write_cpp_code(cpp_basename, contents) | 264 self.write_cpp_code(cpp_basename, contents) |
252 | 265 |
253 def write_header_and_cpp(self): | 266 def write_header_and_cpp(self): |
254 header_basename = v8_class_name(self.interface) + '.h' | 267 header_basename = v8_class_name(self.interface) + '.h' |
255 cpp_basename = v8_class_name(self.interface) + '.cpp' | 268 cpp_basename = v8_class_name(self.interface) + '.cpp' |
256 if self.interface.is_callback: | 269 if self.interface.is_callback: |
257 header_template = 'templates/callback_interface.h' | 270 header_template = 'templates/callback_interface.h.tmpl' |
258 cpp_template = 'templates/callback_interface.cpp' | 271 cpp_template = 'templates/callback_interface.cpp.tmpl' |
259 template_contents = self.generate_callback_interface() | 272 template_contents = self.generate_callback_interface() |
260 else: | 273 else: |
261 header_template = 'templates/interface.h' | 274 header_template = 'templates/interface.h.tmpl' |
262 cpp_template = 'templates/interface.cpp' | 275 cpp_template = 'templates/interface.cpp.tmpl' |
263 template_contents = self.generate_interface() | 276 template_contents = self.generate_interface() |
264 template_contents['conditional_string'] = generate_conditional_string(se lf.interface) | 277 template_contents['conditional_string'] = generate_conditional_string(se lf.interface) |
265 header_file_text = apply_template(header_template, template_contents) | 278 header_file_text = apply_template(header_template, template_contents) |
266 cpp_file_text = apply_template(cpp_template, template_contents) | 279 cpp_file_text = apply_template(cpp_template, template_contents) |
267 self.write_header_code(header_basename, header_file_text) | 280 self.write_header_code(header_basename, header_file_text) |
268 self.write_cpp_code(cpp_basename, cpp_file_text) | 281 self.write_cpp_code(cpp_basename, cpp_file_text) |
269 | 282 |
270 def write_header_code(self, header_basename, header_file_text): | 283 def write_header_code(self, header_basename, header_file_text): |
271 header_filename = os.path.join(self.output_directory, header_basename) | 284 header_filename = os.path.join(self.output_directory, header_basename) |
272 with open(header_filename, 'w') as header_file: | 285 with open(header_filename, 'w') as header_file: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 cpp_to_js_conversion = self.generate_cpp_to_js_conversion(argument.d ata_type, argument.name, receiver, 'isolate', creation_context='v8::Handle<v8::O bject>()') | 329 cpp_to_js_conversion = self.generate_cpp_to_js_conversion(argument.d ata_type, argument.name, receiver, 'isolate', creation_context='v8::Handle<v8::O bject>()') |
317 return { | 330 return { |
318 'name': argument.name, | 331 'name': argument.name, |
319 'cpp_to_js_conversion': cpp_to_js_conversion, | 332 'cpp_to_js_conversion': cpp_to_js_conversion, |
320 } | 333 } |
321 | 334 |
322 def generate_method(operation): | 335 def generate_method(operation): |
323 def argument_declaration(argument): | 336 def argument_declaration(argument): |
324 return '%s %s' % (cpp_type(argument.data_type, 'raw'), argument. name) | 337 return '%s %s' % (cpp_type(argument.data_type, 'raw'), argument. name) |
325 | 338 |
339 call_with_this_handle = has_extended_attribute_value(operation.exten ded_attributes, 'CallWith', 'ThisValue') | |
326 arguments = [] | 340 arguments = [] |
327 custom = 'Custom' in operation.extended_attributes | 341 custom = 'Custom' in operation.extended_attributes |
328 if not custom: | 342 if not custom: |
329 self.cpp_includes |= includes_for_operation(operation) | 343 self.cpp_includes |= includes_for_operation(operation) |
330 if operation.data_type != 'boolean': | 344 if operation.data_type != 'boolean': |
331 raise Exception("We don't yet support callbacks that return non-boolean values.") | 345 raise Exception("We don't yet support callbacks that return non-boolean values.") |
332 arguments = [generate_argument(argument) for argument in operati on.arguments] | 346 arguments = [generate_argument(argument) for argument in operati on.arguments] |
347 argument_declaration = ', '.join([argument_declaration(argument) for argument in operation.arguments]) | |
348 if call_with_this_handle: | |
349 argument_declaration = 'ScriptValue thisValue, ' + argument_decl aration | |
333 method = { | 350 method = { |
351 'call_with_this_handle': call_with_this_handle, | |
334 'return_cpp_type': cpp_type(operation.data_type, 'RefPtr'), | 352 'return_cpp_type': cpp_type(operation.data_type, 'RefPtr'), |
335 'name': operation.name, | 353 'name': operation.name, |
336 'arguments': arguments, | 354 'arguments': arguments, |
337 'argument_declaration': ', '.join([argument_declaration(argument ) for argument in operation.arguments]), | 355 'argument_declaration': argument_declaration, |
338 'handles': ', '.join(['%sHandle' % argument.name for argument in operation.arguments]), | 356 'handles': ', '.join(['%sHandle' % argument.name for argument in operation.arguments]), |
339 'custom': custom, | 357 'custom': custom, |
340 } | 358 } |
341 return method | 359 return method |
342 | 360 |
343 methods = [generate_method(operation) for operation in self.interface.op erations] | 361 methods = [generate_method(operation) for operation in self.interface.op erations] |
344 template_contents = { | 362 template_contents = { |
345 'cpp_class_name': self.interface.name, | 363 'cpp_class_name': self.interface.name, |
346 'v8_class_name': v8_class_name(self.interface), | 364 'v8_class_name': v8_class_name(self.interface), |
347 'cpp_includes': sorted(list(self.cpp_includes)), | 365 'cpp_includes': sorted(list(self.cpp_includes)), |
348 'header_includes': sorted(list(self.header_includes)), | 366 'header_includes': sorted(list(self.header_includes)), |
349 'methods': methods, | 367 'methods': methods, |
350 } | 368 } |
351 return template_contents | 369 return template_contents |
OLD | NEW |