| 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 dart source files from a mojom.Module.""" | 5 """Generates dart source files from a mojom.Module.""" |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import shutil | 9 import shutil |
| 10 import sys | 10 import sys |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 353 |
| 354 def IsPointerArrayKind(kind): | 354 def IsPointerArrayKind(kind): |
| 355 if not mojom.IsArrayKind(kind): | 355 if not mojom.IsArrayKind(kind): |
| 356 return False | 356 return False |
| 357 sub_kind = kind.kind | 357 sub_kind = kind.kind |
| 358 return mojom.IsObjectKind(sub_kind) | 358 return mojom.IsObjectKind(sub_kind) |
| 359 | 359 |
| 360 def GetImportUri(module): | 360 def GetImportUri(module): |
| 361 elements = module.namespace.split('.') | 361 elements = module.namespace.split('.') |
| 362 elements.append("%s" % module.name) | 362 elements.append("%s" % module.name) |
| 363 return os.path.join(*elements) | 363 return os.path.join("mojom", *elements) |
| 364 | 364 |
| 365 class Generator(generator.Generator): | 365 class Generator(generator.Generator): |
| 366 | 366 |
| 367 dart_filters = { | 367 dart_filters = { |
| 368 'array_expected_length': GetArrayExpectedLength, | 368 'array_expected_length': GetArrayExpectedLength, |
| 369 'array': GetArrayKind, | 369 'array': GetArrayKind, |
| 370 'decode_method': DecodeMethod, | 370 'decode_method': DecodeMethod, |
| 371 'default_value': DartDefaultValue, | 371 'default_value': DartDefaultValue, |
| 372 'encode_method': EncodeMethod, | 372 'encode_method': EncodeMethod, |
| 373 'expression_to_text': ExpressionToText, | 373 'expression_to_text': ExpressionToText, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 395 "imported_from": self.ImportedFrom(), | 395 "imported_from": self.ImportedFrom(), |
| 396 } | 396 } |
| 397 | 397 |
| 398 @UseJinja("dart_templates/module.lib.tmpl", filters=dart_filters) | 398 @UseJinja("dart_templates/module.lib.tmpl", filters=dart_filters) |
| 399 def GenerateLibModule(self, args): | 399 def GenerateLibModule(self, args): |
| 400 return self.GetParameters(args) | 400 return self.GetParameters(args) |
| 401 | 401 |
| 402 def GenerateFiles(self, args): | 402 def GenerateFiles(self, args): |
| 403 elements = self.module.namespace.split('.') | 403 elements = self.module.namespace.split('.') |
| 404 elements.append("%s.dart" % self.module.name) | 404 elements.append("%s.dart" % self.module.name) |
| 405 path = os.path.join("dart-gen", *elements) | 405 path = os.path.join("dart-gen", "mojom", *elements) |
| 406 self.Write(self.GenerateLibModule(args), path) | 406 self.Write(self.GenerateLibModule(args), path) |
| 407 link = self.MatchMojomFilePath("%s.dart" % self.module.name) | 407 link = self.MatchMojomFilePath("%s.dart" % self.module.name) |
| 408 if os.path.exists(os.path.join(self.output_dir, link)): | 408 if os.path.exists(os.path.join(self.output_dir, link)): |
| 409 os.unlink(os.path.join(self.output_dir, link)) | 409 os.unlink(os.path.join(self.output_dir, link)) |
| 410 try: | 410 try: |
| 411 if sys.platform == "win32": | 411 if sys.platform == "win32": |
| 412 shutil.copy(os.path.join(self.output_dir, path), | 412 shutil.copy(os.path.join(self.output_dir, path), |
| 413 os.path.join(self.output_dir, link)) | 413 os.path.join(self.output_dir, link)) |
| 414 else: | 414 else: |
| 415 os.symlink(os.path.join(self.output_dir, path), | 415 os.symlink(os.path.join(self.output_dir, path), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 interface_to_import[name] = each_import["unique_name"] + "." + name | 449 interface_to_import[name] = each_import["unique_name"] + "." + name |
| 450 return interface_to_import | 450 return interface_to_import |
| 451 | 451 |
| 452 def ImportedFrom(self): | 452 def ImportedFrom(self): |
| 453 interface_to_import = {} | 453 interface_to_import = {} |
| 454 for each_import in self.module.imports: | 454 for each_import in self.module.imports: |
| 455 for each_interface in each_import["module"].interfaces: | 455 for each_interface in each_import["module"].interfaces: |
| 456 name = each_interface.name | 456 name = each_interface.name |
| 457 interface_to_import[name] = each_import["unique_name"] + "." | 457 interface_to_import[name] = each_import["unique_name"] + "." |
| 458 return interface_to_import | 458 return interface_to_import |
| OLD | NEW |