| 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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
| 7 | 7 |
| 8 import emitter | 8 import emitter |
| 9 import idlnode | 9 import idlnode |
| 10 import logging | 10 import logging |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 # Collect interfaces | 159 # Collect interfaces |
| 160 interfaces = [] | 160 interfaces = [] |
| 161 for interface in database.GetInterfaces(): | 161 for interface in database.GetInterfaces(): |
| 162 if not MatchSourceFilter(interface): | 162 if not MatchSourceFilter(interface): |
| 163 # Skip this interface since it's not present in the required source | 163 # Skip this interface since it's not present in the required source |
| 164 _logger.info('Omitting interface - %s' % interface.id) | 164 _logger.info('Omitting interface - %s' % interface.id) |
| 165 continue | 165 continue |
| 166 interfaces.append(interface) | 166 interfaces.append(interface) |
| 167 | 167 |
| 168 # TODO(sra): Use this list of exception names to generate information to | |
| 169 # tell dart2js which exceptions can be passed from JS to Dart code. | |
| 170 exceptions = self._CollectExceptions(interfaces) | |
| 171 | |
| 172 # Render all interfaces into Dart and save them in files. | 168 # Render all interfaces into Dart and save them in files. |
| 173 for interface in self._PreOrderInterfaces(interfaces): | 169 for interface in self._PreOrderInterfaces(interfaces): |
| 174 interface_name = interface.id | 170 interface_name = interface.id |
| 175 auxiliary_file = self._auxiliary_files.get(interface_name) | 171 auxiliary_file = self._auxiliary_files.get(interface_name) |
| 176 if auxiliary_file is not None: | 172 if auxiliary_file is not None: |
| 177 _logger.info('Skipping %s because %s exists' % ( | 173 _logger.info('Skipping %s because %s exists' % ( |
| 178 interface_name, auxiliary_file)) | 174 interface_name, auxiliary_file)) |
| 179 continue | 175 continue |
| 180 | 176 |
| 181 _logger.info('Generating %s' % interface.id) | 177 _logger.info('Generating %s' % interface.id) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 194 continue | 190 continue |
| 195 if self._database.HasInterface(parent.type.id): | 191 if self._database.HasInterface(parent.type.id): |
| 196 parent_interface = self._database.GetInterface(parent.type.id) | 192 parent_interface = self._database.GetInterface(parent.type.id) |
| 197 visit(parent_interface) | 193 visit(parent_interface) |
| 198 ordered.append(interface) | 194 ordered.append(interface) |
| 199 | 195 |
| 200 for interface in interfaces: | 196 for interface in interfaces: |
| 201 visit(interface) | 197 visit(interface) |
| 202 return ordered | 198 return ordered |
| 203 | 199 |
| 204 def _CollectExceptions(self, interfaces): | |
| 205 """Returns the names of all exception classes raised.""" | |
| 206 exceptions = set() | |
| 207 for interface in interfaces: | |
| 208 for attribute in interface.attributes: | |
| 209 if attribute.get_raises: | |
| 210 exceptions.add(attribute.get_raises.id) | |
| 211 if attribute.set_raises: | |
| 212 exceptions.add(attribute.set_raises.id) | |
| 213 for operation in interface.operations: | |
| 214 if operation.raises: | |
| 215 exceptions.add(operation.raises.id) | |
| 216 return exceptions | |
| 217 | |
| 218 | |
| 219 def FixEventTargets(self, database): | 200 def FixEventTargets(self, database): |
| 220 for interface in database.GetInterfaces(): | 201 for interface in database.GetInterfaces(): |
| 221 # Create fake EventTarget parent interface for interfaces that have | 202 # Create fake EventTarget parent interface for interfaces that have |
| 222 # 'EventTarget' extended attribute. | 203 # 'EventTarget' extended attribute. |
| 223 if 'EventTarget' in interface.ext_attrs and interface.id != 'EventTarget': | 204 if 'EventTarget' in interface.ext_attrs and interface.id != 'EventTarget': |
| 224 ast = [('Annotation', [('Id', 'WebKit')]), | 205 ast = [('Annotation', [('Id', 'WebKit')]), |
| 225 ('InterfaceType', ('ScopedName', 'EventTarget'))] | 206 ('InterfaceType', ('ScopedName', 'EventTarget'))] |
| 226 interface.parents.append(idlnode.IDLParentInterface(ast)) | 207 interface.parents.append(idlnode.IDLParentInterface(ast)) |
| 227 | 208 |
| 228 def AddMissingArguments(self, database): | 209 def AddMissingArguments(self, database): |
| 229 ARG = idlnode.IDLArgument([('Type', ('ScopedName', 'object')), ('Id', 'arg')
]) | 210 ARG = idlnode.IDLArgument([('Type', ('ScopedName', 'object')), ('Id', 'arg')
]) |
| 230 for interface in database.GetInterfaces(): | 211 for interface in database.GetInterfaces(): |
| 231 for operation in interface.operations: | 212 for operation in interface.operations: |
| 232 if operation.ext_attrs.get('CallWith') == 'ScriptArguments|ScriptState': | 213 if operation.ext_attrs.get('CallWith') == 'ScriptArguments|ScriptState': |
| 233 operation.arguments.append(ARG) | 214 operation.arguments.append(ARG) |
| OLD | NEW |