OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 '''Generates Go source files from a mojom.Module.''' | 5 '''Generates Go source files from a mojom.Module.''' |
6 | 6 |
7 from itertools import chain | 7 from itertools import chain |
8 import os | 8 import os |
9 import re | 9 import re |
10 | 10 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 # Imports can only be used in structs, constants, enums, interfaces. | 246 # Imports can only be used in structs, constants, enums, interfaces. |
247 all_structs = list(module.structs) | 247 all_structs = list(module.structs) |
248 for i in module.interfaces: | 248 for i in module.interfaces: |
249 AddImport(module, i) | 249 AddImport(module, i) |
250 for method in i.methods: | 250 for method in i.methods: |
251 all_structs.append(GetStructFromMethod(method)) | 251 all_structs.append(GetStructFromMethod(method)) |
252 if method.response_parameters: | 252 if method.response_parameters: |
253 all_structs.append(GetResponseStructFromMethod(method)) | 253 all_structs.append(GetResponseStructFromMethod(method)) |
254 | 254 |
255 if len(all_structs) > 0 or len(module.interfaces) > 0: | 255 if len(all_structs) > 0 or len(module.interfaces) > 0: |
| 256 _imports['fmt'] = 'fmt' |
256 _imports['mojo/public/go/bindings'] = 'bindings' | 257 _imports['mojo/public/go/bindings'] = 'bindings' |
| 258 if len(all_structs) > 0: |
| 259 _imports['sort'] = 'sort' |
| 260 |
257 for struct in all_structs: | 261 for struct in all_structs: |
258 for field in struct.fields: | 262 for field in struct.fields: |
259 AddImport(module, field.kind) | 263 AddImport(module, field.kind) |
260 # TODO(rogulenko): add these after generating constants and struct defaults. | 264 # TODO(rogulenko): add these after generating constants and struct defaults. |
261 # if field.default: | 265 # if field.default: |
262 # AddImport(module, field.default) | 266 # AddImport(module, field.default) |
263 | 267 |
264 for enum in GetAllEnums(module): | 268 for enum in GetAllEnums(module): |
265 for field in enum.fields: | 269 for field in enum.fields: |
266 if field.value: | 270 if field.value: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return { | 325 return { |
322 'lstrip_blocks': True, | 326 'lstrip_blocks': True, |
323 'trim_blocks': True, | 327 'trim_blocks': True, |
324 } | 328 } |
325 | 329 |
326 def GetGlobals(self): | 330 def GetGlobals(self): |
327 return { | 331 return { |
328 'namespace': self.module.namespace, | 332 'namespace': self.module.namespace, |
329 'module': self.module, | 333 'module': self.module, |
330 } | 334 } |
OLD | NEW |