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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 # Imported kinds can only be referred to in structs, constants, enums, | 363 # Imported kinds can only be referred to in structs, constants, enums, |
364 # unions and interfaces. | 364 # unions and interfaces. |
365 all_structs = list(self.module.structs) | 365 all_structs = list(self.module.structs) |
366 for i in self.module.interfaces: | 366 for i in self.module.interfaces: |
367 for method in i.methods: | 367 for method in i.methods: |
368 all_structs.append(self._GetStructFromMethod(method)) | 368 all_structs.append(self._GetStructFromMethod(method)) |
369 if method.response_parameters: | 369 if method.response_parameters: |
370 all_structs.append(self._GetResponseStructFromMethod(method)) | 370 all_structs.append(self._GetResponseStructFromMethod(method)) |
371 | 371 |
372 if (len(all_structs) > 0 or len(self.module.interfaces) > 0 | 372 if (len(all_structs) > 0 or len(self.module.interfaces) > 0 |
373 or len(self.module.unions) > 0): | 373 or len(self.module.unions) > 0 or len(self.module.enums) > 0): |
374 imports['fmt'] = 'fmt' | 374 imports['fmt'] = 'fmt' |
375 imports['mojo/public/go/bindings'] = 'bindings' | 375 imports['mojo/public/go/bindings'] = 'bindings' |
376 if len(self.module.interfaces) > 0: | 376 if len(self.module.interfaces) > 0: |
377 imports['mojo/public/go/system'] = 'system' | 377 imports['mojo/public/go/system'] = 'system' |
378 if len(all_structs) > 0: | 378 if len(all_structs) > 0: |
379 imports['sort'] = 'sort' | 379 imports['sort'] = 'sort' |
380 | 380 |
381 for union in self.module.unions: | 381 for union in self.module.unions: |
382 for field in union.fields: | 382 for field in union.fields: |
383 AddImport(imports, mojom_imports, self.module, field.kind) | 383 AddImport(imports, mojom_imports, self.module, field.kind) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 # modify the |name| property. Instead we add a |go_name| property. | 444 # modify the |name| property. Instead we add a |go_name| property. |
445 def _GetResponseStructFromMethod(self, method): | 445 def _GetResponseStructFromMethod(self, method): |
446 self._AddStructComputedData(False, method.response_param_struct) | 446 self._AddStructComputedData(False, method.response_param_struct) |
447 if not hasattr(method.response_param_struct, "go_name"): | 447 if not hasattr(method.response_param_struct, "go_name"): |
448 # Only generate the go_names if they have not already been generated. | 448 # Only generate the go_names if they have not already been generated. |
449 method.response_param_struct.go_name = "%s_%s_ResponseParams" % ( | 449 method.response_param_struct.go_name = "%s_%s_ResponseParams" % ( |
450 GetNameForElement(method.interface), GetNameForElement(method)) | 450 GetNameForElement(method.interface), GetNameForElement(method)) |
451 for field in method.response_param_struct.fields: | 451 for field in method.response_param_struct.fields: |
452 field.go_name = "out%s" % GetNameForElement(field) | 452 field.go_name = "out%s" % GetNameForElement(field) |
453 return method.response_param_struct | 453 return method.response_param_struct |
OLD | NEW |