| 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 shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 from systemfrog import * | 9 from systemfrog import * |
| 10 from systeminterface import * | 10 from systeminterface import * |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 self._shared = HtmlSystemShared(database) | 766 self._shared = HtmlSystemShared(database) |
| 767 | 767 |
| 768 class HtmlInterfacesSystem(HtmlSystem): | 768 class HtmlInterfacesSystem(HtmlSystem): |
| 769 | 769 |
| 770 def __init__(self, templates, database, emitters, output_dir): | 770 def __init__(self, templates, database, emitters, output_dir): |
| 771 super(HtmlInterfacesSystem, self).__init__( | 771 super(HtmlInterfacesSystem, self).__init__( |
| 772 templates, database, emitters, output_dir) | 772 templates, database, emitters, output_dir) |
| 773 self._dart_interface_file_paths = [] | 773 self._dart_interface_file_paths = [] |
| 774 self._factory_provider_emitters = {} | 774 self._factory_provider_emitters = {} |
| 775 | 775 |
| 776 def InterfaceGenerator(self, | 776 def ProcessInterface(self, interface): |
| 777 interface, | |
| 778 common_prefix, | |
| 779 super_interface_name, | |
| 780 source_filter): | |
| 781 """.""" | 777 """.""" |
| 782 if interface.id in _merged_html_interfaces: | 778 if interface.id in _merged_html_interfaces: |
| 783 return None | 779 return |
| 784 | 780 |
| 785 html_interface_name = self._shared._HTMLInterfaceName(interface.id) | 781 html_interface_name = self._shared._HTMLInterfaceName(interface.id) |
| 786 dart_interface_file_path = self._FilePathForDartInterface( | 782 dart_interface_file_path = self._FilePathForDartInterface( |
| 787 html_interface_name) | 783 html_interface_name) |
| 788 | 784 |
| 789 self._dart_interface_file_paths.append(dart_interface_file_path) | 785 self._dart_interface_file_paths.append(dart_interface_file_path) |
| 790 | 786 |
| 791 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) | 787 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| 792 | 788 |
| 793 template_file = 'interface_%s.darttemplate' % html_interface_name | 789 template_file = 'interface_%s.darttemplate' % html_interface_name |
| 794 template = self._templates.TryLoad(template_file) | 790 template = self._templates.TryLoad(template_file) |
| 795 if not template: | 791 if not template: |
| 796 template = self._templates.Load('interface.darttemplate') | 792 template = self._templates.Load('interface.darttemplate') |
| 797 | 793 |
| 798 return HtmlDartInterfaceGenerator( | 794 HtmlDartInterfaceGenerator( |
| 799 self, interface, dart_interface_code, | 795 self, interface, dart_interface_code, |
| 800 template, | 796 template, self._shared).Generate() |
| 801 common_prefix, super_interface_name, | |
| 802 source_filter, self._shared) | |
| 803 | 797 |
| 804 def ProcessCallback(self, interface, info): | 798 def ProcessCallback(self, interface, info): |
| 805 """Generates a typedef for the callback interface.""" | 799 """Generates a typedef for the callback interface.""" |
| 806 interface_name = interface.id | 800 interface_name = interface.id |
| 807 file_path = self._FilePathForDartInterface(interface_name) | 801 file_path = self._FilePathForDartInterface(interface_name) |
| 808 self._ProcessCallback(interface, info, file_path) | 802 self._ProcessCallback(interface, info, file_path) |
| 809 | 803 |
| 810 def GenerateLibraries(self): | 804 def GenerateLibraries(self): |
| 811 pass | 805 pass |
| 812 | 806 |
| 813 | 807 |
| 814 def _FilePathForDartInterface(self, interface_name): | 808 def _FilePathForDartInterface(self, interface_name): |
| 815 """Returns the file path of the Dart interface definition.""" | 809 """Returns the file path of the Dart interface definition.""" |
| 816 # TODO(jmesserly): is this the right path | 810 # TODO(jmesserly): is this the right path |
| 817 return os.path.join(self._output_dir, 'html', 'interface', | 811 return os.path.join(self._output_dir, 'html', 'interface', |
| 818 '%s.dart' % interface_name) | 812 '%s.dart' % interface_name) |
| 819 | 813 |
| 820 # ------------------------------------------------------------------------------ | 814 # ------------------------------------------------------------------------------ |
| 821 | 815 |
| 822 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 816 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| 823 # term, but it makes merging better for now. | 817 # term, but it makes merging better for now. |
| 824 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): | 818 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| 825 """Generates Dart Interface definition for one DOM IDL interface.""" | 819 """Generates Dart Interface definition for one DOM IDL interface.""" |
| 826 | 820 |
| 827 def __init__(self, system, interface, emitter, template, | 821 def __init__(self, system, interface, emitter, template, shared): |
| 828 common_prefix, super_interface, source_filter, shared): | |
| 829 super(HtmlDartInterfaceGenerator, self).__init__(system, interface, | 822 super(HtmlDartInterfaceGenerator, self).__init__(system, interface, |
| 830 emitter, template, common_prefix, super_interface, source_filter) | 823 emitter, template) |
| 831 self._shared = shared | 824 self._shared = shared |
| 832 self._html_interface_name = self._shared._HTMLInterfaceName( | 825 self._html_interface_name = self._shared._HTMLInterfaceName( |
| 833 self._interface.id) | 826 self._interface.id) |
| 834 | 827 |
| 835 def StartInterface(self): | 828 def StartInterface(self): |
| 836 typename = self._html_interface_name | 829 typename = self._html_interface_name |
| 837 | 830 |
| 838 extends = [] | 831 extends = [] |
| 839 suppressed_extends = [] | 832 suppressed_extends = [] |
| 840 | 833 |
| 841 for parent in self._interface.parents: | 834 for parent in self._interface.parents: |
| 842 # TODO(vsm): Remove source_filter. | 835 # TODO(vsm): Remove source_filter. |
| 843 if MatchSourceFilter(self._source_filter, parent): | 836 if MatchSourceFilter(parent): |
| 844 # Parent is a DOM type. | 837 # Parent is a DOM type. |
| 845 extends.append(self._shared.DartType(parent.type.id)) | 838 extends.append(self._shared.DartType(parent.type.id)) |
| 846 elif '<' in parent.type.id: | 839 elif '<' in parent.type.id: |
| 847 # Parent is a Dart collection type. | 840 # Parent is a Dart collection type. |
| 848 # TODO(vsm): Make this check more robust. | 841 # TODO(vsm): Make this check more robust. |
| 849 extends.append(self._shared.DartType(parent.type.id)) | 842 extends.append(self._shared.DartType(parent.type.id)) |
| 850 else: | 843 else: |
| 851 suppressed_extends.append('%s.%s' % | 844 suppressed_extends.append('%s.%s' % |
| 852 (self._common_prefix, self._shared.DartType(parent.type.id))) | 845 (self._common_prefix, self._shared.DartType(parent.type.id))) |
| 853 | 846 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 | 1009 |
| 1017 # ------------------------------------------------------------------------------ | 1010 # ------------------------------------------------------------------------------ |
| 1018 | 1011 |
| 1019 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 1012 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| 1020 # term, but it makes merging better for now. | 1013 # term, but it makes merging better for now. |
| 1021 class HtmlFrogClassGenerator(FrogInterfaceGenerator): | 1014 class HtmlFrogClassGenerator(FrogInterfaceGenerator): |
| 1022 """Generates a Frog class for the dart:html library from a DOM IDL | 1015 """Generates a Frog class for the dart:html library from a DOM IDL |
| 1023 interface. | 1016 interface. |
| 1024 """ | 1017 """ |
| 1025 | 1018 |
| 1026 def __init__(self, system, interface, template, super_interface, dart_code, | 1019 def __init__(self, system, interface, template, dart_code, |
| 1027 shared): | 1020 shared): |
| 1028 super(HtmlFrogClassGenerator, self).__init__( | 1021 super(HtmlFrogClassGenerator, self).__init__( |
| 1029 system, interface, template, super_interface, dart_code) | 1022 system, interface, template, dart_code) |
| 1030 self._shared = shared | 1023 self._shared = shared |
| 1031 self._html_interface_name = self._shared._HTMLInterfaceName( | 1024 self._html_interface_name = self._shared._HTMLInterfaceName( |
| 1032 self._interface.id) | 1025 self._interface.id) |
| 1033 | 1026 |
| 1034 def _ImplClassName(self, type_name): | 1027 def _ImplClassName(self, type_name): |
| 1035 return self._shared._ImplClassName(type_name) | 1028 return self._shared._ImplClassName(type_name) |
| 1036 | 1029 |
| 1037 def _NarrowToImplementationType(self, type_name): | 1030 def _NarrowToImplementationType(self, type_name): |
| 1038 if self._ShouldNarrowToImplementationType(type_name): | 1031 if self._ShouldNarrowToImplementationType(type_name): |
| 1039 return self._ImplClassName(self._shared.DartType(type_name)) | 1032 return self._ImplClassName(self._shared.DartType(type_name)) |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 # ------------------------------------------------------------------------------ | 1339 # ------------------------------------------------------------------------------ |
| 1347 | 1340 |
| 1348 class HtmlFrogSystem(HtmlSystem): | 1341 class HtmlFrogSystem(HtmlSystem): |
| 1349 | 1342 |
| 1350 def __init__(self, templates, database, emitters, output_dir): | 1343 def __init__(self, templates, database, emitters, output_dir): |
| 1351 super(HtmlFrogSystem, self).__init__( | 1344 super(HtmlFrogSystem, self).__init__( |
| 1352 templates, database, emitters, output_dir) | 1345 templates, database, emitters, output_dir) |
| 1353 self._dart_frog_file_paths = [] | 1346 self._dart_frog_file_paths = [] |
| 1354 self._factory_provider_emitters = {} | 1347 self._factory_provider_emitters = {} |
| 1355 | 1348 |
| 1356 def InterfaceGenerator(self, | 1349 def ProcessInterface(self, interface): |
| 1357 interface, | |
| 1358 common_prefix, | |
| 1359 super_interface_name, | |
| 1360 source_filter): | |
| 1361 """.""" | 1350 """.""" |
| 1362 if interface.id in _merged_html_interfaces: | 1351 if interface.id in _merged_html_interfaces: |
| 1363 return None | 1352 return None |
| 1364 | 1353 |
| 1365 if IsPureInterface(interface.id): | 1354 if IsPureInterface(interface.id): |
| 1366 return | 1355 return |
| 1367 | 1356 |
| 1368 html_interface_name = self._shared._HTMLInterfaceName(interface.id) | 1357 html_interface_name = self._shared._HTMLInterfaceName(interface.id) |
| 1369 template_file = 'impl_%s.darttemplate' % html_interface_name | 1358 template_file = 'impl_%s.darttemplate' % html_interface_name |
| 1370 template = self._templates.TryLoad(template_file) | 1359 template = self._templates.TryLoad(template_file) |
| 1371 if not template: | 1360 if not template: |
| 1372 template = self._templates.Load('frog_impl.darttemplate') | 1361 template = self._templates.Load('frog_impl.darttemplate') |
| 1373 | 1362 |
| 1374 dart_code = self._ImplFileEmitter(html_interface_name) | 1363 dart_code = self._ImplFileEmitter(html_interface_name) |
| 1375 return HtmlFrogClassGenerator(self, interface, template, | 1364 generator = HtmlFrogClassGenerator(self, interface, template, |
| 1376 super_interface_name, dart_code, self._shared) | 1365 dart_code, self._shared) |
| 1366 generator.Generate() |
| 1377 | 1367 |
| 1378 def GenerateLibraries(self): | 1368 def GenerateLibraries(self): |
| 1379 self._GenerateLibFile( | 1369 self._GenerateLibFile( |
| 1380 'html_frog.darttemplate', | 1370 'html_frog.darttemplate', |
| 1381 os.path.join(self._output_dir, 'html_frog.dart'), | 1371 os.path.join(self._output_dir, 'html_frog.dart'), |
| 1382 (self._interface_system._dart_interface_file_paths + | 1372 (self._interface_system._dart_interface_file_paths + |
| 1383 self._interface_system._dart_callback_file_paths + | 1373 self._interface_system._dart_callback_file_paths + |
| 1384 self._dart_frog_file_paths)) | 1374 self._dart_frog_file_paths)) |
| 1385 | 1375 |
| 1386 def Finish(self): | 1376 def Finish(self): |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1407 dom_implementation_classes, output_dir): | 1397 dom_implementation_classes, output_dir): |
| 1408 """Prepared for generating wrapping implementation. | 1398 """Prepared for generating wrapping implementation. |
| 1409 | 1399 |
| 1410 - Creates emitter for Dart code. | 1400 - Creates emitter for Dart code. |
| 1411 """ | 1401 """ |
| 1412 super(HtmlDartiumSystem, self).__init__( | 1402 super(HtmlDartiumSystem, self).__init__( |
| 1413 templates, database, emitters, output_dir) | 1403 templates, database, emitters, output_dir) |
| 1414 self._auxiliary_dir = auxiliary_dir | 1404 self._auxiliary_dir = auxiliary_dir |
| 1415 self._dom_implementation_classes = dom_implementation_classes | 1405 self._dom_implementation_classes = dom_implementation_classes |
| 1416 | 1406 |
| 1417 def InterfaceGenerator(self, | 1407 def ProcessInterface(self, interface): |
| 1418 interface, | |
| 1419 common_prefix, | |
| 1420 super_interface_name, | |
| 1421 source_filter): | |
| 1422 # Implementation classes are generated by NativeImplementationSystem. | 1408 # Implementation classes are generated by NativeImplementationSystem. |
| 1423 # FIXME: merge HtmlDartiumSystem into NativeImplementationSystem. | 1409 # FIXME: merge HtmlDartiumSystem into NativeImplementationSystem. |
| 1424 return None | 1410 pass |
| 1425 | 1411 |
| 1426 def ProcessCallback(self, interface, info): | 1412 def ProcessCallback(self, interface, info): |
| 1427 pass | 1413 pass |
| 1428 | 1414 |
| 1429 def GenerateLibraries(self): | 1415 def GenerateLibraries(self): |
| 1430 # Library generated for implementation. | 1416 # Library generated for implementation. |
| 1431 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) | 1417 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) |
| 1432 | 1418 |
| 1433 self._GenerateLibFile( | 1419 self._GenerateLibFile( |
| 1434 'html_dartium.darttemplate', | 1420 'html_dartium.darttemplate', |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1458 Collect(database.GetInterface(parent.type.id), | 1444 Collect(database.GetInterface(parent.type.id), |
| 1459 seen, collected) | 1445 seen, collected) |
| 1460 | 1446 |
| 1461 inheritance_closure = {} | 1447 inheritance_closure = {} |
| 1462 for interface in database.GetInterfaces(): | 1448 for interface in database.GetInterfaces(): |
| 1463 seen = set() | 1449 seen = set() |
| 1464 collected = [] | 1450 collected = [] |
| 1465 Collect(interface, seen, collected) | 1451 Collect(interface, seen, collected) |
| 1466 inheritance_closure[interface.id] = collected | 1452 inheritance_closure[interface.id] = collected |
| 1467 return inheritance_closure | 1453 return inheritance_closure |
| OLD | NEW |