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): | |
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 | 326 |
314 def generate_argument(argument): | 327 def generate_argument(argument): |
315 receiver = 'v8::Handle<v8::Value> %sHandle = %%s;' % argument.name | 328 receiver = 'v8::Handle<v8::Value> %sHandle = %%s;' % argument.name |
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 generate_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([generate_argument_declaration(argu ment) for argument in operation.arguments]) | |
arv (Not doing code reviews)
2013/08/08 14:24:51
I was referring to the []. join takes an iterable
alancutter (OOO until 2018)
2013/08/09 05:33:26
I see now, that is better.
Done.
| |
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 |