| 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 class System(object): | 12 class System(object): |
| 13 """A System generates all the files for one implementation. | 13 """A System generates all the files for one implementation. |
| 14 | 14 |
| 15 This is a base class for all the specific systems. | 15 This is a base class for all the specific systems. |
| 16 The life-cycle of a System is: | 16 The life-cycle of a System is: |
| 17 - construction (__init__) | 17 - construction (__init__) |
| 18 - (InterfaceGenerator | ProcessCallback)* # for each IDL interface | 18 - (ProcessInterface)* # for each IDL interface |
| 19 """ | 19 """ |
| 20 | 20 |
| 21 def __init__(self, options): | 21 def __init__(self, options): |
| 22 self._templates = options.templates | 22 self._templates = options.templates |
| 23 self._database = options.database | 23 self._database = options.database |
| 24 self._type_registry = options.type_registry | 24 self._type_registry = options.type_registry |
| 25 self._renamer = options.renamer | 25 self._renamer = options.renamer |
| 26 | 26 |
| 27 def ProcessInterface(self, interface): | 27 def ProcessInterface(self, interface): |
| 28 """Processes an interface that is not a callback function.""" | 28 """Processes an interface that is not a callback function.""" |
| 29 pass | 29 pass |
| 30 | 30 |
| 31 def ProcessCallback(self, interface, info): | |
| 32 """Processes an interface that is a callback function.""" | |
| 33 pass | |
| 34 | |
| 35 | |
| 36 # Helper methods used by several systems. | 31 # Helper methods used by several systems. |
| 37 | 32 |
| 38 def _BaseDefines(self, interface): | 33 def _BaseDefines(self, interface): |
| 39 """Returns a set of names (strings) for members defined in a base class. | 34 """Returns a set of names (strings) for members defined in a base class. |
| 40 """ | 35 """ |
| 41 def WalkParentChain(interface): | 36 def WalkParentChain(interface): |
| 42 if interface.parents: | 37 if interface.parents: |
| 43 # Only consider primary parent, secondary parents are not on the | 38 # Only consider primary parent, secondary parents are not on the |
| 44 # implementation class inheritance chain. | 39 # implementation class inheritance chain. |
| 45 parent = interface.parents[0] | 40 parent = interface.parents[0] |
| 46 if IsDartCollectionType(parent.type.id): | 41 if IsDartCollectionType(parent.type.id): |
| 47 return | 42 return |
| 48 if self._database.HasInterface(parent.type.id): | 43 if self._database.HasInterface(parent.type.id): |
| 49 parent_interface = self._database.GetInterface(parent.type.id) | 44 parent_interface = self._database.GetInterface(parent.type.id) |
| 50 for attr in parent_interface.attributes: | 45 for attr in parent_interface.attributes: |
| 51 result.add(attr.id) | 46 result.add(attr.id) |
| 52 for op in parent_interface.operations: | 47 for op in parent_interface.operations: |
| 53 result.add(op.id) | 48 result.add(op.id) |
| 54 WalkParentChain(parent_interface) | 49 WalkParentChain(parent_interface) |
| 55 | 50 |
| 56 result = set() | 51 result = set() |
| 57 WalkParentChain(interface) | 52 WalkParentChain(interface) |
| 58 return result | 53 return result |
| 59 | 54 |
| 60 class BaseGenerator(object): | 55 class BaseGenerator(object): |
| 61 def __init__(self, database, interface): | 56 def __init__(self, database, type_registry, interface): |
| 62 self._database = database | 57 self._database = database |
| 58 self._type_registry = type_registry |
| 63 self._interface = interface | 59 self._interface = interface |
| 64 | 60 |
| 65 def Generate(self): | 61 def Generate(self): |
| 62 if 'Callback' in self._interface.ext_attrs: |
| 63 handlers = [operation for operation in self._interface.operations |
| 64 if operation.id == 'handleEvent'] |
| 65 info = AnalyzeOperation(self._interface, handlers) |
| 66 self.GenerateCallback(info) |
| 67 return |
| 68 |
| 66 self.StartInterface() | 69 self.StartInterface() |
| 67 self.AddMembers(self._interface) | 70 self.AddMembers(self._interface) |
| 68 self.AddSecondaryMembers(self._interface) | 71 self.AddSecondaryMembers(self._interface) |
| 69 self.FinishInterface() | 72 self.FinishInterface() |
| 70 | 73 |
| 74 def GenerateCallback(self, info): |
| 75 pass |
| 76 |
| 71 def AddMembers(self, interface): | 77 def AddMembers(self, interface): |
| 72 for const in sorted(interface.constants, ConstantOutputOrder): | 78 for const in sorted(interface.constants, ConstantOutputOrder): |
| 73 self.AddConstant(const) | 79 self.AddConstant(const) |
| 74 | 80 |
| 75 for attr in interface.attributes: | 81 for attr in interface.attributes: |
| 76 if attr.type.id != 'EventListener': | 82 if attr.type.id != 'EventListener': |
| 77 self.AddAttribute(attr) | 83 self.AddAttribute(attr) |
| 78 | 84 |
| 79 # The implementation should define an indexer if the interface directly | 85 # The implementation should define an indexer if the interface directly |
| 80 # extends List. | 86 # extends List. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 170 |
| 165 result = [] | 171 result = [] |
| 166 if interface.parents: | 172 if interface.parents: |
| 167 parent = interface.parents[0] | 173 parent = interface.parents[0] |
| 168 if IsPureInterface(parent.type.id): | 174 if IsPureInterface(parent.type.id): |
| 169 walk(interface.parents) | 175 walk(interface.parents) |
| 170 else: | 176 else: |
| 171 walk(interface.parents[1:]) | 177 walk(interface.parents[1:]) |
| 172 return result | 178 return result |
| 173 | 179 |
| 180 def _TypeInfo(self, type_name): |
| 181 return self._type_registry.TypeInfo(type_name) |
| 182 |
| 174 def _DartType(self, type_name): | 183 def _DartType(self, type_name): |
| 175 return self._system._type_registry.DartType(type_name) | 184 return self._type_registry.DartType(type_name) |
| 176 | 185 |
| 177 | 186 |
| 178 class GeneratorOptions(object): | 187 class GeneratorOptions(object): |
| 179 def __init__(self, templates, database, type_registry, renamer): | 188 def __init__(self, templates, database, type_registry, renamer): |
| 180 self.templates = templates | 189 self.templates = templates |
| 181 self.database = database | 190 self.database = database |
| 182 self.type_registry = type_registry | 191 self.type_registry = type_registry |
| 183 self.renamer = renamer | 192 self.renamer = renamer |
| 184 | 193 |
| 185 | 194 |
| 186 def IsReadOnly(attribute): | 195 def IsReadOnly(attribute): |
| 187 return attribute.is_read_only or 'Replaceable' in attribute.ext_attrs | 196 return attribute.is_read_only or 'Replaceable' in attribute.ext_attrs |
| OLD | NEW |