| 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 from generator import * | 10 from generator import * |
| 11 | 11 |
| 12 def MassagePath(path): | |
| 13 # The most robust way to emit path separators is to use / always. | |
| 14 return path.replace('\\', '/') | |
| 15 | |
| 16 class System(object): | 12 class System(object): |
| 17 """A System generates all the files for one implementation. | 13 """A System generates all the files for one implementation. |
| 18 | 14 |
| 19 This is a base class for all the specific systems. | 15 This is a base class for all the specific systems. |
| 20 The life-cycle of a System is: | 16 The life-cycle of a System is: |
| 21 - construction (__init__) | 17 - construction (__init__) |
| 22 - (InterfaceGenerator | ProcessCallback)* # for each IDL interface | 18 - (InterfaceGenerator | ProcessCallback)* # for each IDL interface |
| 23 - GenerateLibraries | |
| 24 - Finish | |
| 25 """ | 19 """ |
| 26 | 20 |
| 27 def __init__(self, options): | 21 def __init__(self, options): |
| 28 self._templates = options.templates | 22 self._templates = options.templates |
| 29 self._database = options.database | 23 self._database = options.database |
| 30 self._emitters = options.emitters | |
| 31 self._type_registry = options.type_registry | 24 self._type_registry = options.type_registry |
| 32 self._renamer = options.renamer | 25 self._renamer = options.renamer |
| 33 self._output_dir = options.output_dir | |
| 34 self._auxiliary_dir = options.auxiliary_dir | |
| 35 | 26 |
| 36 def ProcessInterface(self, interface): | 27 def ProcessInterface(self, interface): |
| 37 """Processes an interface that is not a callback function.""" | 28 """Processes an interface that is not a callback function.""" |
| 38 pass | 29 pass |
| 39 | 30 |
| 40 def ProcessCallback(self, interface, info): | 31 def ProcessCallback(self, interface, info): |
| 41 """Processes an interface that is a callback function.""" | 32 """Processes an interface that is a callback function.""" |
| 42 pass | 33 pass |
| 43 | 34 |
| 44 def GenerateLibraries(self, lib_dir): | |
| 45 pass | |
| 46 | |
| 47 def Finish(self): | |
| 48 pass | |
| 49 | |
| 50 | 35 |
| 51 # Helper methods used by several systems. | 36 # Helper methods used by several systems. |
| 52 | 37 |
| 53 def _GenerateLibFile(self, lib_template, lib_file_path, file_paths, | |
| 54 **template_args): | |
| 55 """Generates a lib file from a template and a list of files. | |
| 56 | |
| 57 Additional keyword arguments are passed to the template. | |
| 58 Typically called from self.GenerateLibraries. | |
| 59 """ | |
| 60 # Load template. | |
| 61 template = self._templates.Load(lib_template) | |
| 62 # Generate the .lib file. | |
| 63 lib_file_contents = self._emitters.FileEmitter(lib_file_path) | |
| 64 | |
| 65 # Emit the list of #source directives. | |
| 66 list_emitter = lib_file_contents.Emit(template, **template_args) | |
| 67 lib_file_dir = os.path.dirname(lib_file_path) | |
| 68 for path in sorted(file_paths): | |
| 69 relpath = os.path.relpath(path, lib_file_dir) | |
| 70 list_emitter.Emit("#source('$PATH');\n", PATH=MassagePath(relpath)) | |
| 71 | |
| 72 | |
| 73 def _BaseDefines(self, interface): | 38 def _BaseDefines(self, interface): |
| 74 """Returns a set of names (strings) for members defined in a base class. | 39 """Returns a set of names (strings) for members defined in a base class. |
| 75 """ | 40 """ |
| 76 def WalkParentChain(interface): | 41 def WalkParentChain(interface): |
| 77 if interface.parents: | 42 if interface.parents: |
| 78 # Only consider primary parent, secondary parents are not on the | 43 # Only consider primary parent, secondary parents are not on the |
| 79 # implementation class inheritance chain. | 44 # implementation class inheritance chain. |
| 80 parent = interface.parents[0] | 45 parent = interface.parents[0] |
| 81 if IsDartCollectionType(parent.type.id): | 46 if IsDartCollectionType(parent.type.id): |
| 82 return | 47 return |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 walk(interface.parents) | 175 walk(interface.parents) |
| 211 else: | 176 else: |
| 212 walk(interface.parents[1:]) | 177 walk(interface.parents[1:]) |
| 213 return result | 178 return result |
| 214 | 179 |
| 215 def _DartType(self, type_name): | 180 def _DartType(self, type_name): |
| 216 return self._system._type_registry.DartType(type_name) | 181 return self._system._type_registry.DartType(type_name) |
| 217 | 182 |
| 218 | 183 |
| 219 class GeneratorOptions(object): | 184 class GeneratorOptions(object): |
| 220 def __init__(self, templates, database, emitters, type_registry, renamer, | 185 def __init__(self, templates, database, type_registry, renamer): |
| 221 output_dir, auxiliary_dir): | |
| 222 self.templates = templates | 186 self.templates = templates |
| 223 self.database = database | 187 self.database = database |
| 224 self.emitters = emitters | |
| 225 self.type_registry = type_registry | 188 self.type_registry = type_registry |
| 226 self.renamer = renamer | 189 self.renamer = renamer |
| 227 self.output_dir = output_dir | |
| 228 self.auxiliary_dir = auxiliary_dir | |
| 229 | 190 |
| 230 | 191 |
| 231 def IsReadOnly(attribute): | 192 def IsReadOnly(attribute): |
| 232 return attribute.is_read_only or 'Replaceable' in attribute.ext_attrs | 193 return attribute.is_read_only or 'Replaceable' in attribute.ext_attrs |
| OLD | NEW |