| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 return '.' in type_name | 60 return '.' in type_name |
| 61 | 61 |
| 62 def LoadAuxiliary(self, auxiliary_dir): | 62 def LoadAuxiliary(self, auxiliary_dir): |
| 63 def Visitor(_, dirname, names): | 63 def Visitor(_, dirname, names): |
| 64 for name in names: | 64 for name in names: |
| 65 if name.endswith('.dart'): | 65 if name.endswith('.dart'): |
| 66 name = name[0:-5] # strip off ".dart" | 66 name = name[0:-5] # strip off ".dart" |
| 67 self._auxiliary_files[name] = os.path.join(dirname, name) | 67 self._auxiliary_files[name] = os.path.join(dirname, name) |
| 68 os.path.walk(auxiliary_dir, Visitor, None) | 68 os.path.walk(auxiliary_dir, Visitor, None) |
| 69 | 69 |
| 70 def RenameTypes(self, database, conversion_table, rename_javascript_binding_na
mes): | |
| 71 """Renames interfaces using the given conversion table. | |
| 72 | |
| 73 References through all interfaces will be renamed as well. | |
| 74 | |
| 75 Args: | |
| 76 database: the database to apply the renames to. | |
| 77 conversion_table: maps old names to new names. | |
| 78 """ | |
| 79 | |
| 80 if conversion_table is None: | |
| 81 conversion_table = {} | |
| 82 | |
| 83 # Rename interfaces: | |
| 84 for old_name, new_name in conversion_table.items(): | |
| 85 if database.HasInterface(old_name): | |
| 86 _logger.info('renaming interface %s to %s' % (old_name, new_name)) | |
| 87 interface = database.GetInterface(old_name) | |
| 88 if not database.HasInterface(new_name): | |
| 89 interface.id = new_name | |
| 90 database.DeleteInterface(old_name) | |
| 91 database.AddInterface(interface) | |
| 92 | |
| 93 if rename_javascript_binding_names: | |
| 94 interface.javascript_binding_name = new_name | |
| 95 interface.doc_js_name = new_name | |
| 96 for member in (interface.operations + interface.constants | |
| 97 + interface.attributes): | |
| 98 member.doc_js_interface_name = new_name | |
| 99 | |
| 100 | |
| 101 # Fix references: | |
| 102 for interface in database.GetInterfaces(): | |
| 103 for idl_type in interface.all(idlnode.IDLType): | |
| 104 type_name = self._StripModules(idl_type.id) | |
| 105 if type_name in conversion_table: | |
| 106 idl_type.id = conversion_table[type_name] | |
| 107 | |
| 108 def FilterMembersWithUnidentifiedTypes(self, database): | 70 def FilterMembersWithUnidentifiedTypes(self, database): |
| 109 """Removes unidentified types. | 71 """Removes unidentified types. |
| 110 | 72 |
| 111 Removes constants, attributes, operations and parents with unidentified | 73 Removes constants, attributes, operations and parents with unidentified |
| 112 types. | 74 types. |
| 113 """ | 75 """ |
| 114 | 76 |
| 115 for interface in database.GetInterfaces(): | 77 for interface in database.GetInterfaces(): |
| 116 def IsIdentified(idl_node): | 78 def IsIdentified(idl_node): |
| 117 node_name = idl_node.id if idl_node.id else 'parent' | 79 node_name = idl_node.id if idl_node.id else 'parent' |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if HasAnnotations(interface): | 143 if HasAnnotations(interface): |
| 182 interface.constants = filter(HasAnnotations, interface.constants) | 144 interface.constants = filter(HasAnnotations, interface.constants) |
| 183 interface.attributes = filter(HasAnnotations, interface.attributes) | 145 interface.attributes = filter(HasAnnotations, interface.attributes) |
| 184 interface.operations = filter(HasAnnotations, interface.operations) | 146 interface.operations = filter(HasAnnotations, interface.operations) |
| 185 interface.parents = filter(HasAnnotations, interface.parents) | 147 interface.parents = filter(HasAnnotations, interface.parents) |
| 186 else: | 148 else: |
| 187 database.DeleteInterface(interface.id) | 149 database.DeleteInterface(interface.id) |
| 188 | 150 |
| 189 self.FilterMembersWithUnidentifiedTypes(database) | 151 self.FilterMembersWithUnidentifiedTypes(database) |
| 190 | 152 |
| 191 def Generate(self, database, super_database, webkit_renames, | 153 def Generate(self, database, super_database, generate_interface): |
| 192 generate_interface): | |
| 193 self._database = database | 154 self._database = database |
| 194 | 155 |
| 195 # Collect interfaces | 156 # Collect interfaces |
| 196 interfaces = [] | 157 interfaces = [] |
| 197 for interface in database.GetInterfaces(): | 158 for interface in database.GetInterfaces(): |
| 198 if not MatchSourceFilter(interface): | 159 if not MatchSourceFilter(interface): |
| 199 # Skip this interface since it's not present in the required source | 160 # Skip this interface since it's not present in the required source |
| 200 _logger.info('Omitting interface - %s' % interface.id) | 161 _logger.info('Omitting interface - %s' % interface.id) |
| 201 continue | 162 continue |
| 202 interfaces.append(interface) | 163 interfaces.append(interface) |
| 203 | 164 |
| 204 # TODO(sra): Use this list of exception names to generate information to | 165 # TODO(sra): Use this list of exception names to generate information to |
| 205 # tell dart2js which exceptions can be passed from JS to Dart code. | 166 # tell dart2js which exceptions can be passed from JS to Dart code. |
| 206 exceptions = self._CollectExceptions(interfaces) | 167 exceptions = self._CollectExceptions(interfaces) |
| 207 | 168 |
| 208 super_map = dict((v, k) for k, v in webkit_renames.iteritems()) | |
| 209 | |
| 210 # Render all interfaces into Dart and save them in files. | 169 # Render all interfaces into Dart and save them in files. |
| 211 for interface in self._PreOrderInterfaces(interfaces): | 170 for interface in self._PreOrderInterfaces(interfaces): |
| 212 | |
| 213 super_name = interface.id | |
| 214 | |
| 215 if super_name in super_map: | |
| 216 super_name = super_map[super_name] | |
| 217 | |
| 218 if (super_database is not None and | |
| 219 super_database.HasInterface(super_name)): | |
| 220 interface.ext_attrs['synthesizedSuperInterfaceName'] = super_name | |
| 221 | |
| 222 interface_name = interface.id | 171 interface_name = interface.id |
| 223 auxiliary_file = self._auxiliary_files.get(interface_name) | 172 auxiliary_file = self._auxiliary_files.get(interface_name) |
| 224 if auxiliary_file is not None: | 173 if auxiliary_file is not None: |
| 225 _logger.info('Skipping %s because %s exists' % ( | 174 _logger.info('Skipping %s because %s exists' % ( |
| 226 interface_name, auxiliary_file)) | 175 interface_name, auxiliary_file)) |
| 227 continue | 176 continue |
| 228 | 177 |
| 229 _logger.info('Generating %s' % interface.id) | 178 _logger.info('Generating %s' % interface.id) |
| 230 generate_interface(interface) | 179 generate_interface(interface) |
| 231 | 180 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 ast = [('Annotation', [('Id', 'WebKit')]), | 221 ast = [('Annotation', [('Id', 'WebKit')]), |
| 273 ('InterfaceType', ('ScopedName', 'EventTarget'))] | 222 ('InterfaceType', ('ScopedName', 'EventTarget'))] |
| 274 interface.parents.append(idlnode.IDLParentInterface(ast)) | 223 interface.parents.append(idlnode.IDLParentInterface(ast)) |
| 275 | 224 |
| 276 def AddMissingArguments(self, database): | 225 def AddMissingArguments(self, database): |
| 277 ARG = idlnode.IDLArgument([('Type', ('ScopedName', 'object')), ('Id', 'arg')
]) | 226 ARG = idlnode.IDLArgument([('Type', ('ScopedName', 'object')), ('Id', 'arg')
]) |
| 278 for interface in database.GetInterfaces(): | 227 for interface in database.GetInterfaces(): |
| 279 for operation in interface.operations: | 228 for operation in interface.operations: |
| 280 if operation.ext_attrs.get('CallWith') == 'ScriptArguments|CallStack': | 229 if operation.ext_attrs.get('CallWith') == 'ScriptArguments|CallStack': |
| 281 operation.arguments.append(ARG) | 230 operation.arguments.append(ARG) |
| OLD | NEW |