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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 self._systems.append(html_system) | 432 self._systems.append(html_system) |
433 | 433 |
434 if 'htmldartium' in systems: | 434 if 'htmldartium' in systems: |
435 html_system = HtmlDartiumSystem( | 435 html_system = HtmlDartiumSystem( |
436 TemplateLoader(self._template_dir, ['html/dartium', 'html', '']), | 436 TemplateLoader(self._template_dir, ['html/dartium', 'html', '']), |
437 self._database, self._emitters, self._output_dir) | 437 self._database, self._emitters, self._output_dir) |
438 | 438 |
439 html_system._interface_system = html_interface_system | 439 html_system._interface_system = html_interface_system |
440 self._systems.append(html_system) | 440 self._systems.append(html_system) |
441 | 441 |
| 442 |
| 443 # Collect interfaces |
| 444 interfaces = [] |
| 445 for interface in database.GetInterfaces(): |
| 446 if not _MatchSourceFilter(source_filter, interface): |
| 447 # Skip this interface since it's not present in the required source |
| 448 _logger.info('Omitting interface - %s' % interface.id) |
| 449 continue |
| 450 interfaces.append(interface) |
| 451 |
442 # Render all interfaces into Dart and save them in files. | 452 # Render all interfaces into Dart and save them in files. |
443 for interface in database.GetInterfaces(): | 453 for interface in self._PreOrderInterfaces(interfaces): |
444 | 454 |
445 super_interface = None | 455 super_interface = None |
446 super_name = interface.id | 456 super_name = interface.id |
447 | 457 |
448 if not _MatchSourceFilter(source_filter, interface): | |
449 # Skip this interface since it's not present in the required source | |
450 _logger.info('Omitting interface - %s' % interface.id) | |
451 continue | |
452 | |
453 if super_name in super_map: | 458 if super_name in super_map: |
454 super_name = super_map[super_name] | 459 super_name = super_map[super_name] |
455 | 460 |
456 if (super_database is not None and | 461 if (super_database is not None and |
457 super_database.HasInterface(super_name)): | 462 super_database.HasInterface(super_name)): |
458 super_interface = super_name | 463 super_interface = super_name |
459 | 464 |
460 interface_name = interface.id | 465 interface_name = interface.id |
461 auxiliary_file = self._auxiliary_files.get(interface_name) | 466 auxiliary_file = self._auxiliary_files.get(interface_name) |
462 if auxiliary_file is not None: | 467 if auxiliary_file is not None: |
(...skipping 14 matching lines...) Expand all Loading... |
477 | 482 |
478 # Libraries | 483 # Libraries |
479 if lib_dir: | 484 if lib_dir: |
480 for system in self._systems: | 485 for system in self._systems: |
481 system.GenerateLibraries(lib_dir) | 486 system.GenerateLibraries(lib_dir) |
482 | 487 |
483 for system in self._systems: | 488 for system in self._systems: |
484 system.Finish() | 489 system.Finish() |
485 | 490 |
486 | 491 |
| 492 def _PreOrderInterfaces(self, interfaces): |
| 493 """Returns the interfaces in pre-order, i.e. parents first.""" |
| 494 seen = set() |
| 495 ordered = [] |
| 496 def visit(interface): |
| 497 if interface.id in seen: |
| 498 return |
| 499 seen.add(interface.id) |
| 500 for parent in interface.parents: |
| 501 if _IsDartCollectionType(parent.type.id): |
| 502 continue |
| 503 if self._database.HasInterface(parent.type.id): |
| 504 parent_interface = self._database.GetInterface(parent.type.id) |
| 505 visit(parent_interface) |
| 506 ordered.append(interface) |
| 507 |
| 508 for interface in interfaces: |
| 509 visit(interface) |
| 510 return ordered |
| 511 |
| 512 |
487 def _ProcessInterface(self, interface, super_interface_name, | 513 def _ProcessInterface(self, interface, super_interface_name, |
488 source_filter, | 514 source_filter, |
489 common_prefix): | 515 common_prefix): |
490 """.""" | 516 """.""" |
491 _logger.info('Generating %s' % interface.id) | 517 _logger.info('Generating %s' % interface.id) |
492 | 518 |
493 generators = [system.InterfaceGenerator(interface, | 519 generators = [system.InterfaceGenerator(interface, |
494 common_prefix, | 520 common_prefix, |
495 super_interface_name, | 521 super_interface_name, |
496 source_filter) | 522 source_filter) |
(...skipping 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2399 INDENT=indent, | 2425 INDENT=indent, |
2400 NATIVENAME=native_name, | 2426 NATIVENAME=native_name, |
2401 ARGS=argument_expressions) | 2427 ARGS=argument_expressions) |
2402 | 2428 |
2403 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' | 2429 self._members_emitter.Emit(' $TYPE $NATIVE_NAME($PARAMS) native ' |
2404 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', | 2430 '"$(INTERFACE)$(NATIVE_NAME)_Callback";\n', |
2405 NATIVE_NAME=native_name, | 2431 NATIVE_NAME=native_name, |
2406 TYPE=info.type_name, | 2432 TYPE=info.type_name, |
2407 PARAMS=', '.join(arg_names), | 2433 PARAMS=', '.join(arg_names), |
2408 INTERFACE=self._interface.id) | 2434 INTERFACE=self._interface.id) |
OLD | NEW |