| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides base functionality for systems to generate | 6 """This module provides base functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 #import re | 10 #import re |
| 11 import generator | 11 import generator |
| 12 | 12 |
| 13 def MassagePath(path): |
| 14 # The most robust way to emit path separators is to use / always. |
| 15 return path.replace('\\', '/') |
| 16 |
| 13 class System(object): | 17 class System(object): |
| 14 """A System generates all the files for one implementation. | 18 """A System generates all the files for one implementation. |
| 15 | 19 |
| 16 This is a base class for all the specific systems. | 20 This is a base class for all the specific systems. |
| 17 The life-cycle of a System is: | 21 The life-cycle of a System is: |
| 18 - construction (__init__) | 22 - construction (__init__) |
| 19 - (InterfaceGenerator | ProcessCallback)* # for each IDL interface | 23 - (InterfaceGenerator | ProcessCallback)* # for each IDL interface |
| 20 - GenerateLibraries | 24 - GenerateLibraries |
| 21 - Finish | 25 - Finish |
| 22 """ | 26 """ |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 # Load template. | 78 # Load template. |
| 75 template = self._templates.Load(lib_template) | 79 template = self._templates.Load(lib_template) |
| 76 # Generate the .lib file. | 80 # Generate the .lib file. |
| 77 lib_file_contents = self._emitters.FileEmitter(lib_file_path) | 81 lib_file_contents = self._emitters.FileEmitter(lib_file_path) |
| 78 | 82 |
| 79 # Emit the list of #source directives. | 83 # Emit the list of #source directives. |
| 80 list_emitter = lib_file_contents.Emit(template, **template_args) | 84 list_emitter = lib_file_contents.Emit(template, **template_args) |
| 81 lib_file_dir = os.path.dirname(lib_file_path) | 85 lib_file_dir = os.path.dirname(lib_file_path) |
| 82 for path in sorted(file_paths): | 86 for path in sorted(file_paths): |
| 83 relpath = os.path.relpath(path, lib_file_dir) | 87 relpath = os.path.relpath(path, lib_file_dir) |
| 84 list_emitter.Emit("#source('$PATH');\n", PATH=relpath) | 88 list_emitter.Emit("#source('$PATH');\n", PATH=MassagePath(relpath)) |
| 85 | 89 |
| 86 | 90 |
| 87 def _BaseDefines(self, interface): | 91 def _BaseDefines(self, interface): |
| 88 """Returns a set of names (strings) for members defined in a base class. | 92 """Returns a set of names (strings) for members defined in a base class. |
| 89 """ | 93 """ |
| 90 def WalkParentChain(interface): | 94 def WalkParentChain(interface): |
| 91 if interface.parents: | 95 if interface.parents: |
| 92 # Only consider primary parent, secondary parents are not on the | 96 # Only consider primary parent, secondary parents are not on the |
| 93 # implementation class inheritance chain. | 97 # implementation class inheritance chain. |
| 94 parent = interface.parents[0] | 98 parent = interface.parents[0] |
| 95 if generator.IsDartCollectionType(parent.type.id): | 99 if generator.IsDartCollectionType(parent.type.id): |
| 96 return | 100 return |
| 97 if self._database.HasInterface(parent.type.id): | 101 if self._database.HasInterface(parent.type.id): |
| 98 parent_interface = self._database.GetInterface(parent.type.id) | 102 parent_interface = self._database.GetInterface(parent.type.id) |
| 99 for attr in parent_interface.attributes: | 103 for attr in parent_interface.attributes: |
| 100 result.add(attr.id) | 104 result.add(attr.id) |
| 101 for op in parent_interface.operations: | 105 for op in parent_interface.operations: |
| 102 result.add(op.id) | 106 result.add(op.id) |
| 103 WalkParentChain(parent_interface) | 107 WalkParentChain(parent_interface) |
| 104 | 108 |
| 105 result = set() | 109 result = set() |
| 106 WalkParentChain(interface) | 110 WalkParentChain(interface) |
| 107 return result; | 111 return result; |
| OLD | NEW |