| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 def GetImports(module): | 252 def GetImports(module): |
| 253 # Imports can only be used in structs, constants, enums, interfaces. | 253 # Imports can only be used in structs, constants, enums, interfaces. |
| 254 all_structs = list(module.structs) | 254 all_structs = list(module.structs) |
| 255 for i in module.interfaces: | 255 for i in module.interfaces: |
| 256 for method in i.methods: | 256 for method in i.methods: |
| 257 all_structs.append(GetStructFromMethod(method)) | 257 all_structs.append(GetStructFromMethod(method)) |
| 258 if method.response_parameters: | 258 if method.response_parameters: |
| 259 all_structs.append(GetResponseStructFromMethod(method)) | 259 all_structs.append(GetResponseStructFromMethod(method)) |
| 260 | 260 |
| 261 if len(all_structs) > 0 or len(module.interfaces) > 0: | 261 if len(all_structs) > 0 or len(module.interfaces) > 0: |
| 262 _imports['fmt'] = 'fmt' |
| 262 _imports['mojo/public/go/bindings'] = 'bindings' | 263 _imports['mojo/public/go/bindings'] = 'bindings' |
| 264 if len(all_structs) > 0: |
| 265 _imports['sort'] = 'sort' |
| 266 |
| 263 for struct in all_structs: | 267 for struct in all_structs: |
| 264 for field in struct.fields: | 268 for field in struct.fields: |
| 265 AddImport(module, field.kind) | 269 AddImport(module, field.kind) |
| 266 # TODO(rogulenko): add these after generating constants and struct defaults. | 270 # TODO(rogulenko): add these after generating constants and struct defaults. |
| 267 # if field.default: | 271 # if field.default: |
| 268 # AddImport(module, field.default) | 272 # AddImport(module, field.default) |
| 269 | 273 |
| 270 for enum in GetAllEnums(module): | 274 for enum in GetAllEnums(module): |
| 271 for field in enum.fields: | 275 for field in enum.fields: |
| 272 if field.value: | 276 if field.value: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return { | 333 return { |
| 330 'lstrip_blocks': True, | 334 'lstrip_blocks': True, |
| 331 'trim_blocks': True, | 335 'trim_blocks': True, |
| 332 } | 336 } |
| 333 | 337 |
| 334 def GetGlobals(self): | 338 def GetGlobals(self): |
| 335 return { | 339 return { |
| 336 'namespace': self.module.namespace, | 340 'namespace': self.module.namespace, |
| 337 'module': self.module, | 341 'module': self.module, |
| 338 } | 342 } |
| OLD | NEW |