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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 _AddUnionComputedData(union) | 148 _AddUnionComputedData(union) |
149 for interface in module.interfaces: | 149 for interface in module.interfaces: |
150 _AddInterfaceComputedData(interface) | 150 _AddInterfaceComputedData(interface) |
151 | 151 |
152 | 152 |
153 class Generator(object): | 153 class Generator(object): |
154 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all | 154 # Pass |output_dir| to emit files to disk. Omit |output_dir| to echo all |
155 # files to stdout. | 155 # files to stdout. |
156 def __init__(self, module, output_dir=None, typemap=None, variant=None, | 156 def __init__(self, module, output_dir=None, typemap=None, variant=None, |
157 bytecode_path=None, for_blink=False, use_once_callback=False, | 157 bytecode_path=None, for_blink=False, use_once_callback=False, |
158 use_new_js_bindings=False, export_attribute=None, | 158 js_bindings_mode="new", export_attribute=None, |
159 export_header=None, generate_non_variant_code=False): | 159 export_header=None, generate_non_variant_code=False): |
160 self.module = module | 160 self.module = module |
161 self.output_dir = output_dir | 161 self.output_dir = output_dir |
162 self.typemap = typemap or {} | 162 self.typemap = typemap or {} |
163 self.variant = variant | 163 self.variant = variant |
164 self.bytecode_path = bytecode_path | 164 self.bytecode_path = bytecode_path |
165 self.for_blink = for_blink | 165 self.for_blink = for_blink |
166 self.use_once_callback = use_once_callback | 166 self.use_once_callback = use_once_callback |
167 self.use_new_js_bindings = use_new_js_bindings | 167 self.js_bindings_mode = js_bindings_mode |
168 self.export_attribute = export_attribute | 168 self.export_attribute = export_attribute |
169 self.export_header = export_header | 169 self.export_header = export_header |
170 self.generate_non_variant_code = generate_non_variant_code | 170 self.generate_non_variant_code = generate_non_variant_code |
171 | 171 |
172 def Write(self, contents, filename): | 172 def Write(self, contents, filename): |
173 if self.output_dir is None: | 173 if self.output_dir is None: |
174 print contents | 174 print contents |
175 return | 175 return |
176 full_path = os.path.join(self.output_dir, filename) | 176 full_path = os.path.join(self.output_dir, filename) |
177 WriteFile(contents, full_path) | 177 WriteFile(contents, full_path) |
178 | 178 |
179 def GenerateFiles(self, args): | 179 def GenerateFiles(self, args): |
180 raise NotImplementedError("Subclasses must override/implement this method") | 180 raise NotImplementedError("Subclasses must override/implement this method") |
181 | 181 |
182 def GetJinjaParameters(self): | 182 def GetJinjaParameters(self): |
183 """Returns default constructor parameters for the jinja environment.""" | 183 """Returns default constructor parameters for the jinja environment.""" |
184 return {} | 184 return {} |
185 | 185 |
186 def GetGlobals(self): | 186 def GetGlobals(self): |
187 """Returns global mappings for the template generation.""" | 187 """Returns global mappings for the template generation.""" |
188 return {} | 188 return {} |
189 | 189 |
OLD | NEW |