Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 Python source files from a mojom.Module.""" | 5 """Generates Python source files from a mojom.Module.""" |
| 6 | 6 |
| 7 import re | 7 import re |
| 8 from itertools import ifilter | 8 from itertools import ifilter |
| 9 | 9 |
| 10 import mojom.generate.generator as generator | 10 import mojom.generate.generator as generator |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 def GenerateFiles(self, args): | 304 def GenerateFiles(self, args): |
| 305 import_path = MojomToPythonImport(self.module.name) | 305 import_path = MojomToPythonImport(self.module.name) |
| 306 self.Write(self.GeneratePythonModule(), | 306 self.Write(self.GeneratePythonModule(), |
| 307 self.MatchMojomFilePath('%s.py' % import_path)) | 307 self.MatchMojomFilePath('%s.py' % import_path)) |
| 308 | 308 |
| 309 def GetImports(self): | 309 def GetImports(self): |
| 310 for each in self.module.imports: | 310 for each in self.module.imports: |
| 311 each['python_module'] = MojomToPythonImport(each['module_name']) | 311 each['python_module'] = MojomToPythonImport(each['module_name']) |
| 312 return self.module.imports | 312 return self.module.imports |
| 313 | 313 |
| 314 def GetNormalizedName(self, kind): | |
| 315 """Returns a normalized name (C++-style fully qualified name) of the | |
| 316 provided object.""" | |
| 317 normalized = kind.name | |
| 318 if self.module.namespace: | |
| 319 normalized = '::'.join(self.module.namespace.split('.') + [kind.name]) | |
| 320 return normalized | |
| 321 | |
| 314 def GetQualifiedInterfaces(self): | 322 def GetQualifiedInterfaces(self): |
| 315 """ | 323 """ |
| 316 Returns the list of interfaces of the module. Each interface that has a | 324 Returns the list of interfaces of the module. Each interface that has a |
| 317 client will have a reference to the representation of the client interface | 325 client will have a reference to the representation of the client interface |
| 318 in the 'qualified_client' field. | 326 in the 'qualified_client' field. |
| 319 """ | 327 """ |
| 320 interfaces = self.module.interfaces | 328 interfaces = self.module.interfaces |
| 321 all_interfaces = [] + interfaces | 329 all_interfaces = [] + interfaces |
| 322 for each in self.GetImports(): | 330 for each in self.GetImports(): |
| 323 all_interfaces += [data.KindFromImport(x, each) for x in | 331 all_interfaces += [data.KindFromImport(x, each) for x in |
| 324 each['module'].interfaces]; | 332 each['module'].interfaces]; |
| 325 interfaces_by_name = dict((x.name, x) for x in all_interfaces) | 333 interfaces_by_name = dict((x.name, x) for x in all_interfaces) |
| 326 for interface in interfaces: | 334 for interface in interfaces: |
| 335 interface.normalized_name = self.GetNormalizedName(interface) | |
|
qsr
2015/01/14 18:08:41
Try to not modify the object if not needed. Either
etiennej
2015/01/15 00:03:07
Done.
| |
| 327 if interface.client: | 336 if interface.client: |
| 328 assert interface.client in interfaces_by_name, ( | 337 assert interface.client in interfaces_by_name, ( |
| 329 'Unable to find interface %s declared as client of %s.' % | 338 'Unable to find interface %s declared as client of %s.' % |
| 330 (interface.client, interface.name)) | 339 (interface.client, interface.name)) |
| 331 interface.qualified_client = interfaces_by_name[interface.client] | 340 interface.qualified_client = interfaces_by_name[interface.client] |
| 332 return sorted(interfaces, key=lambda i: (bool(i.client), i.name)) | 341 return sorted(interfaces, key=lambda i: (bool(i.client), i.name)) |
| 333 | 342 |
| 334 def GetJinjaParameters(self): | 343 def GetJinjaParameters(self): |
| 335 return { | 344 return { |
| 336 'lstrip_blocks': True, | 345 'lstrip_blocks': True, |
| 337 'trim_blocks': True, | 346 'trim_blocks': True, |
| 338 } | 347 } |
| OLD | NEW |