OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Code shared by the various language-specific code generators.""" | 5 """Code shared by the various language-specific code generators.""" |
6 | 6 |
7 from functools import partial | 7 from functools import partial |
8 import os.path | 8 import os.path |
9 import re | 9 import re |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 # Dump the data to disk. | 32 # Dump the data to disk. |
33 with open(full_path, "w+") as f: | 33 with open(full_path, "w+") as f: |
34 f.write(contents) | 34 f.write(contents) |
35 | 35 |
36 class Generator(object): | 36 class Generator(object): |
37 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all | 37 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all |
38 # files to stdout. | 38 # files to stdout. |
39 def __init__(self, module, output_dir=None, typemap=None, variant=None, | 39 def __init__(self, module, output_dir=None, typemap=None, variant=None, |
40 bytecode_path=None, for_blink=False, use_once_callback=False, | 40 bytecode_path=None, for_blink=False, use_once_callback=False, |
41 export_attribute=None, export_header=None, | 41 use_new_js_bindings=False, export_attribute=None, |
42 generate_non_variant_code=False): | 42 export_header=None, generate_non_variant_code=False): |
43 self.module = module | 43 self.module = module |
44 self.output_dir = output_dir | 44 self.output_dir = output_dir |
45 self.typemap = typemap or {} | 45 self.typemap = typemap or {} |
46 self.variant = variant | 46 self.variant = variant |
47 self.bytecode_path = bytecode_path | 47 self.bytecode_path = bytecode_path |
48 self.for_blink = for_blink | 48 self.for_blink = for_blink |
49 self.use_once_callback = use_once_callback | 49 self.use_once_callback = use_once_callback |
| 50 self.use_new_js_bindings = use_new_js_bindings |
50 self.export_attribute = export_attribute | 51 self.export_attribute = export_attribute |
51 self.export_header = export_header | 52 self.export_header = export_header |
52 self.generate_non_variant_code = generate_non_variant_code | 53 self.generate_non_variant_code = generate_non_variant_code |
53 | 54 |
54 def GetStructsFromMethods(self): | 55 def GetStructsFromMethods(self): |
55 result = [] | 56 result = [] |
56 for interface in self.module.interfaces: | 57 for interface in self.module.interfaces: |
57 for method in interface.methods: | 58 for method in interface.methods: |
58 result.append(self._GetStructFromMethod(method)) | 59 result.append(self._GetStructFromMethod(method)) |
59 if method.response_parameters != None: | 60 if method.response_parameters != None: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return self._AddStructComputedData(False, struct) | 144 return self._AddStructComputedData(False, struct) |
144 | 145 |
145 def _GetResponseStructFromMethod(self, method): | 146 def _GetResponseStructFromMethod(self, method): |
146 """Converts a method's response_parameters into the fields of a struct.""" | 147 """Converts a method's response_parameters into the fields of a struct.""" |
147 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) | 148 params_class = "%s_%s_ResponseParams" % (method.interface.name, method.name) |
148 struct = mojom.Struct(params_class, module=method.interface.module) | 149 struct = mojom.Struct(params_class, module=method.interface.module) |
149 for param in method.response_parameters: | 150 for param in method.response_parameters: |
150 struct.AddField(param.name, param.kind, param.ordinal, | 151 struct.AddField(param.name, param.kind, param.ordinal, |
151 attributes=param.attributes) | 152 attributes=param.attributes) |
152 return self._AddStructComputedData(False, struct) | 153 return self._AddStructComputedData(False, struct) |
OLD | NEW |