Chromium Code Reviews| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 86 |
| 87 References through all interfaces will be renamed as well. | 87 References through all interfaces will be renamed as well. |
| 88 | 88 |
| 89 Args: | 89 Args: |
| 90 database: the database to apply the renames to. | 90 database: the database to apply the renames to. |
| 91 conversion_table: maps old names to new names. | 91 conversion_table: maps old names to new names. |
| 92 """ | 92 """ |
| 93 | 93 |
| 94 if conversion_table is None: | 94 if conversion_table is None: |
| 95 conversion_table = {} | 95 conversion_table = {} |
| 96 | 96 |
| 97 # Rename interfaces: | 97 # Rename interfaces: |
| 98 for old_name, new_name in conversion_table.items(): | 98 for old_name, new_name in conversion_table.items(): |
| 99 if database.HasInterface(old_name): | 99 if database.HasInterface(old_name): |
| 100 _logger.info('renaming interface %s to %s' % (old_name, new_name)) | 100 _logger.info('renaming interface %s to %s' % (old_name, new_name)) |
| 101 interface = database.GetInterface(old_name) | 101 interface = database.GetInterface(old_name) |
| 102 database.DeleteInterface(old_name) | 102 database.DeleteInterface(old_name) |
| 103 if not database.HasInterface(new_name): | 103 if not database.HasInterface(new_name): |
| 104 interface.id = new_name | 104 interface.id = new_name |
| 105 database.AddInterface(interface) | 105 database.AddInterface(interface) |
| 106 else: | 106 else: |
| 107 new_interface = database.GetInterface(new_name) | 107 new_interface = database.GetInterface(new_name) |
| 108 MergeNodes(new_interface, interface) | 108 MergeNodes(new_interface, interface) |
| 109 | 109 |
| 110 if rename_javascript_binding_names: | 110 if rename_javascript_binding_names: |
| 111 interface.javascript_binding_name = new_name | 111 interface.javascript_binding_name = new_name |
| 112 interface.doc_js_name = new_name | 112 interface.doc_js_name = new_name |
| 113 for member in (interface.operations + interface.constants | 113 for member in (interface.operations + interface.constants |
| 114 + interface.attributes): | 114 + interface.attributes): |
| 115 member.doc_js_interface_name = new_name | 115 member.doc_js_interface_name = new_name |
| 116 | 116 |
| 117 | 117 |
| 118 # Fix references: | 118 # Fix references: |
| 119 for interface in database.GetInterfaces(): | 119 for interface in database.GetInterfaces(): |
| 120 for idl_type in interface.all(idlnode.IDLType): | 120 for idl_type in interface.all(idlnode.IDLType): |
| 121 type_name = self._StripModules(idl_type.id) | 121 type_name = self._StripModules(idl_type.id) |
| 122 if type_name in conversion_table: | 122 if type_name in conversion_table: |
| 123 idl_type.id = conversion_table[type_name] | 123 idl_type.id = conversion_table[type_name] |
| 124 | 124 |
| 125 def FilterMembersWithUnidentifiedTypes(self, database): | 125 def FilterMembersWithUnidentifiedTypes(self, database): |
| 126 """Removes unidentified types. | 126 """Removes unidentified types. |
| 127 | 127 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 interface.operations = filter(HasAnnotations, interface.operations) | 201 interface.operations = filter(HasAnnotations, interface.operations) |
| 202 interface.parents = filter(HasAnnotations, interface.parents) | 202 interface.parents = filter(HasAnnotations, interface.parents) |
| 203 else: | 203 else: |
| 204 database.DeleteInterface(interface.id) | 204 database.DeleteInterface(interface.id) |
| 205 | 205 |
| 206 self.FilterMembersWithUnidentifiedTypes(database) | 206 self.FilterMembersWithUnidentifiedTypes(database) |
| 207 | 207 |
| 208 | 208 |
| 209 def Generate(self, database, output_dir, | 209 def Generate(self, database, output_dir, |
| 210 module_source_preference=[], source_filter=None, | 210 module_source_preference=[], source_filter=None, |
| 211 super_database=None, common_prefix=None, super_map={}, | 211 super_database=None, common_prefix=None, |
| 212 html_map={}, lib_dir=None, systems=[]): | 212 webkit_renames={}, |
| 213 html_renames={}, | |
| 214 lib_dir=None, | |
| 215 systems=[]): | |
| 213 """Generates Dart and JS files for the loaded interfaces. | 216 """Generates Dart and JS files for the loaded interfaces. |
| 214 | 217 |
| 215 Args: | 218 Args: |
| 216 database -- database containing interfaces to generate code for. | 219 database -- database containing interfaces to generate code for. |
| 217 output_dir -- directory to write generated files to. | 220 output_dir -- directory to write generated files to. |
| 218 module_source_preference -- priority order list of source annotations to | 221 module_source_preference -- priority order list of source annotations to |
| 219 use when choosing a module name, if none specified uses the module name | 222 use when choosing a module name, if none specified uses the module name |
| 220 from the database. | 223 from the database. |
| 221 source_filter -- if specified, only outputs interfaces that have one of | 224 source_filter -- if specified, only outputs interfaces that have one of |
| 222 these source annotation and rewrites the names of superclasses not | 225 these source annotation and rewrites the names of superclasses not |
| 223 marked with this source to use the common prefix. | 226 marked with this source to use the common prefix. |
| 224 super_database -- database containing super interfaces that the generated | 227 super_database -- database containing super interfaces that the generated |
| 225 interfaces should extend. | 228 interfaces should extend. |
| 226 common_prefix -- prefix for the common library, if any. | 229 common_prefix -- prefix for the common library, if any. |
| 227 lib_file_path -- filename for generated .lib file, None if not required. | 230 lib_file_path -- filename for generated .lib file, None if not required. |
| 228 lib_template -- template file in this directory for generated lib file. | 231 lib_template -- template file in this directory for generated lib file. |
| 229 """ | 232 """ |
| 230 | 233 |
| 231 self._emitters = multiemitter.MultiEmitter() | 234 self._emitters = multiemitter.MultiEmitter() |
| 232 self._database = database | 235 self._database = database |
| 233 self._output_dir = output_dir | 236 self._output_dir = output_dir |
| 234 | 237 |
| 235 self._FixEventTargets() | 238 self._FixEventTargets() |
| 236 self._ComputeInheritanceClosure() | 239 self._ComputeInheritanceClosure() |
| 237 | 240 |
| 238 self._systems = [] | 241 self._systems = [] |
| 239 | 242 |
| 240 # TODO(jmesserly): only create these if needed | 243 # TODO(jmesserly): only create these if needed |
| 241 if ('htmlfrog' in systems) or ('htmldartium' in systems): | 244 if ('htmlfrog' in systems) or ('htmldartium' in systems): |
| 242 html_interface_system = HtmlInterfacesSystem( | 245 html_interface_system = HtmlInterfacesSystem( |
| 243 TemplateLoader(self._template_dir, ['html/interface', 'html', '']), | 246 TemplateLoader(self._template_dir, ['html/interface', 'html', '']), |
| 244 self._database, self._emitters, self._output_dir, self) | 247 self._database, self._emitters, self._output_dir, self) |
| 245 self._systems.append(html_interface_system) | 248 self._systems.append(html_interface_system) |
| 246 else: | 249 else: |
| 247 interface_system = InterfacesSystem( | 250 interface_system = InterfacesSystem( |
| 248 TemplateLoader(self._template_dir, ['dom/interface', 'dom', '']), | 251 TemplateLoader(self._template_dir, ['dom/interface', 'dom', '']), |
| 249 self._database, self._emitters, self._output_dir) | 252 self._database, self._emitters, self._output_dir) |
| 250 self._systems.append(interface_system) | 253 self._systems.append(interface_system) |
| 251 | 254 |
| 252 if 'native' in systems: | 255 if 'native' in systems: |
| 253 native_system = NativeImplementationSystem( | 256 native_system = NativeImplementationSystem( |
| 254 TemplateLoader(self._template_dir, ['dom/native', 'dom', '']), | 257 TemplateLoader(self._template_dir, ['dom/native', 'dom', '']), |
| 255 self._database, self._emitters, self._auxiliary_dir, | 258 self._database, html_renames, self._emitters, self._auxiliary_dir, |
| 256 self._output_dir) | 259 self._output_dir) |
| 257 | 260 |
| 258 self._systems.append(native_system) | 261 self._systems.append(native_system) |
| 259 | 262 |
| 260 if 'dummy' in systems: | 263 if 'dummy' in systems: |
| 261 dummy_system = DummyImplementationSystem( | 264 dummy_system = DummyImplementationSystem( |
| 262 TemplateLoader(self._template_dir, ['dom/dummy', 'dom', '']), | 265 TemplateLoader(self._template_dir, ['dom/dummy', 'dom', '']), |
| 263 self._database, self._emitters, self._output_dir) | 266 self._database, self._emitters, self._output_dir) |
| 264 | 267 |
| 265 # Makes interface files available for listing in the library for the | 268 # Makes interface files available for listing in the library for the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 if not MatchSourceFilter(source_filter, interface): | 305 if not MatchSourceFilter(source_filter, interface): |
| 303 # Skip this interface since it's not present in the required source | 306 # Skip this interface since it's not present in the required source |
| 304 _logger.info('Omitting interface - %s' % interface.id) | 307 _logger.info('Omitting interface - %s' % interface.id) |
| 305 continue | 308 continue |
| 306 interfaces.append(interface) | 309 interfaces.append(interface) |
| 307 | 310 |
| 308 # TODO(sra): Use this list of exception names to generate information to | 311 # TODO(sra): Use this list of exception names to generate information to |
| 309 # tell Frog which exceptions can be passed from JS to Dart code. | 312 # tell Frog which exceptions can be passed from JS to Dart code. |
| 310 exceptions = self._CollectExceptions(interfaces) | 313 exceptions = self._CollectExceptions(interfaces) |
| 311 | 314 |
| 315 super_map = dict((v,k) for k, v in webkit_renames.iteritems()) | |
|
Anton Muhin
2012/05/15 14:54:57
nit: do not we need a space after comma? (v, k)?
podivilov
2012/05/16 12:32:24
Done.
| |
| 316 | |
| 312 # Render all interfaces into Dart and save them in files. | 317 # Render all interfaces into Dart and save them in files. |
| 313 for interface in self._PreOrderInterfaces(interfaces): | 318 for interface in self._PreOrderInterfaces(interfaces): |
| 314 | 319 |
| 315 super_interface = None | 320 super_interface = None |
| 316 super_name = interface.id | 321 super_name = interface.id |
| 317 | 322 |
| 318 if super_name in super_map: | 323 if super_name in super_map: |
| 319 super_name = super_map[super_name] | 324 super_name = super_map[super_name] |
| 320 | 325 |
| 321 if (super_database is not None and | 326 if (super_database is not None and |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 pass | 640 pass |
| 636 | 641 |
| 637 def AddOperation(self, info): | 642 def AddOperation(self, info): |
| 638 pass | 643 pass |
| 639 | 644 |
| 640 def AddStaticOperation(self, info): | 645 def AddStaticOperation(self, info): |
| 641 pass | 646 pass |
| 642 | 647 |
| 643 def AddEventAttributes(self, event_attrs): | 648 def AddEventAttributes(self, event_attrs): |
| 644 pass | 649 pass |
| OLD | NEW |