Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: lib/dom/scripts/systemhtml.py

Issue 10700006: Make per-interface generators an implementation detail of a system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 generator = HtmlDartInterfaceGenerator(
Anton Muhin 2012/06/27 18:13:55 ditto, overall, should be henerators a classes, or
podivilov 2012/06/27 18:48:07 There should be a class to keep per-interface stat
799 self, interface, dart_interface_code, 795 self, interface, dart_interface_code,
800 template, 796 template, self._shared)
801 common_prefix, super_interface_name, 797 generator.Generate()
802 source_filter, self._shared)
803 798
804 def ProcessCallback(self, interface, info): 799 def ProcessCallback(self, interface, info):
805 """Generates a typedef for the callback interface.""" 800 """Generates a typedef for the callback interface."""
806 interface_name = interface.id 801 interface_name = interface.id
807 file_path = self._FilePathForDartInterface(interface_name) 802 file_path = self._FilePathForDartInterface(interface_name)
808 self._ProcessCallback(interface, info, file_path) 803 self._ProcessCallback(interface, info, file_path)
809 804
810 def GenerateLibraries(self): 805 def GenerateLibraries(self):
811 pass 806 pass
812 807
813 808
814 def _FilePathForDartInterface(self, interface_name): 809 def _FilePathForDartInterface(self, interface_name):
815 """Returns the file path of the Dart interface definition.""" 810 """Returns the file path of the Dart interface definition."""
816 # TODO(jmesserly): is this the right path 811 # TODO(jmesserly): is this the right path
817 return os.path.join(self._output_dir, 'html', 'interface', 812 return os.path.join(self._output_dir, 'html', 'interface',
818 '%s.dart' % interface_name) 813 '%s.dart' % interface_name)
819 814
820 # ------------------------------------------------------------------------------ 815 # ------------------------------------------------------------------------------
821 816
822 # TODO(jmesserly): inheritance is probably not the right way to factor this long 817 # TODO(jmesserly): inheritance is probably not the right way to factor this long
823 # term, but it makes merging better for now. 818 # term, but it makes merging better for now.
824 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): 819 class HtmlDartInterfaceGenerator(DartInterfaceGenerator):
825 """Generates Dart Interface definition for one DOM IDL interface.""" 820 """Generates Dart Interface definition for one DOM IDL interface."""
826 821
827 def __init__(self, system, interface, emitter, template, 822 def __init__(self, system, interface, emitter, template, shared):
828 common_prefix, super_interface, source_filter, shared):
829 super(HtmlDartInterfaceGenerator, self).__init__(system, interface, 823 super(HtmlDartInterfaceGenerator, self).__init__(system, interface,
830 emitter, template, common_prefix, super_interface, source_filter) 824 emitter, template)
831 self._shared = shared 825 self._shared = shared
832 self._html_interface_name = self._shared._HTMLInterfaceName( 826 self._html_interface_name = self._shared._HTMLInterfaceName(
833 self._interface.id) 827 self._interface.id)
834 828
835 def StartInterface(self): 829 def StartInterface(self):
836 typename = self._html_interface_name 830 typename = self._html_interface_name
837 831
838 extends = [] 832 extends = []
839 suppressed_extends = [] 833 suppressed_extends = []
840 834
841 for parent in self._interface.parents: 835 for parent in self._interface.parents:
842 # TODO(vsm): Remove source_filter. 836 # TODO(vsm): Remove source_filter.
843 if MatchSourceFilter(self._source_filter, parent): 837 if MatchSourceFilter(parent):
844 # Parent is a DOM type. 838 # Parent is a DOM type.
845 extends.append(self._shared.DartType(parent.type.id)) 839 extends.append(self._shared.DartType(parent.type.id))
846 elif '<' in parent.type.id: 840 elif '<' in parent.type.id:
847 # Parent is a Dart collection type. 841 # Parent is a Dart collection type.
848 # TODO(vsm): Make this check more robust. 842 # TODO(vsm): Make this check more robust.
849 extends.append(self._shared.DartType(parent.type.id)) 843 extends.append(self._shared.DartType(parent.type.id))
850 else: 844 else:
851 suppressed_extends.append('%s.%s' % 845 suppressed_extends.append('%s.%s' %
852 (self._common_prefix, self._shared.DartType(parent.type.id))) 846 (self._common_prefix, self._shared.DartType(parent.type.id)))
853 847
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 1010
1017 # ------------------------------------------------------------------------------ 1011 # ------------------------------------------------------------------------------
1018 1012
1019 # TODO(jmesserly): inheritance is probably not the right way to factor this long 1013 # TODO(jmesserly): inheritance is probably not the right way to factor this long
1020 # term, but it makes merging better for now. 1014 # term, but it makes merging better for now.
1021 class HtmlFrogClassGenerator(FrogInterfaceGenerator): 1015 class HtmlFrogClassGenerator(FrogInterfaceGenerator):
1022 """Generates a Frog class for the dart:html library from a DOM IDL 1016 """Generates a Frog class for the dart:html library from a DOM IDL
1023 interface. 1017 interface.
1024 """ 1018 """
1025 1019
1026 def __init__(self, system, interface, template, super_interface, dart_code, 1020 def __init__(self, system, interface, template, dart_code,
1027 shared): 1021 shared):
1028 super(HtmlFrogClassGenerator, self).__init__( 1022 super(HtmlFrogClassGenerator, self).__init__(
1029 system, interface, template, super_interface, dart_code) 1023 system, interface, template, dart_code)
1030 self._shared = shared 1024 self._shared = shared
1031 self._html_interface_name = self._shared._HTMLInterfaceName( 1025 self._html_interface_name = self._shared._HTMLInterfaceName(
1032 self._interface.id) 1026 self._interface.id)
1033 1027
1034 def _ImplClassName(self, type_name): 1028 def _ImplClassName(self, type_name):
1035 return self._shared._ImplClassName(type_name) 1029 return self._shared._ImplClassName(type_name)
1036 1030
1037 def _NarrowToImplementationType(self, type_name): 1031 def _NarrowToImplementationType(self, type_name):
1038 if self._ShouldNarrowToImplementationType(type_name): 1032 if self._ShouldNarrowToImplementationType(type_name):
1039 return self._ImplClassName(self._shared.DartType(type_name)) 1033 return self._ImplClassName(self._shared.DartType(type_name))
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 # ------------------------------------------------------------------------------ 1340 # ------------------------------------------------------------------------------
1347 1341
1348 class HtmlFrogSystem(HtmlSystem): 1342 class HtmlFrogSystem(HtmlSystem):
1349 1343
1350 def __init__(self, templates, database, emitters, output_dir): 1344 def __init__(self, templates, database, emitters, output_dir):
1351 super(HtmlFrogSystem, self).__init__( 1345 super(HtmlFrogSystem, self).__init__(
1352 templates, database, emitters, output_dir) 1346 templates, database, emitters, output_dir)
1353 self._dart_frog_file_paths = [] 1347 self._dart_frog_file_paths = []
1354 self._factory_provider_emitters = {} 1348 self._factory_provider_emitters = {}
1355 1349
1356 def InterfaceGenerator(self, 1350 def ProcessInterface(self, interface):
1357 interface,
1358 common_prefix,
1359 super_interface_name,
1360 source_filter):
1361 """.""" 1351 """."""
1362 if interface.id in _merged_html_interfaces: 1352 if interface.id in _merged_html_interfaces:
1363 return None 1353 return None
1364 1354
1365 if IsPureInterface(interface.id): 1355 if IsPureInterface(interface.id):
1366 return 1356 return
1367 1357
1368 html_interface_name = self._shared._HTMLInterfaceName(interface.id) 1358 html_interface_name = self._shared._HTMLInterfaceName(interface.id)
1369 template_file = 'impl_%s.darttemplate' % html_interface_name 1359 template_file = 'impl_%s.darttemplate' % html_interface_name
1370 template = self._templates.TryLoad(template_file) 1360 template = self._templates.TryLoad(template_file)
1371 if not template: 1361 if not template:
1372 template = self._templates.Load('frog_impl.darttemplate') 1362 template = self._templates.Load('frog_impl.darttemplate')
1373 1363
1374 dart_code = self._ImplFileEmitter(html_interface_name) 1364 dart_code = self._ImplFileEmitter(html_interface_name)
1375 return HtmlFrogClassGenerator(self, interface, template, 1365 generator = HtmlFrogClassGenerator(self, interface, template,
1376 super_interface_name, dart_code, self._shared) 1366 dart_code, self._shared)
1367 generator.Generate()
1377 1368
1378 def GenerateLibraries(self): 1369 def GenerateLibraries(self):
1379 self._GenerateLibFile( 1370 self._GenerateLibFile(
1380 'html_frog.darttemplate', 1371 'html_frog.darttemplate',
1381 os.path.join(self._output_dir, 'html_frog.dart'), 1372 os.path.join(self._output_dir, 'html_frog.dart'),
1382 (self._interface_system._dart_interface_file_paths + 1373 (self._interface_system._dart_interface_file_paths +
1383 self._interface_system._dart_callback_file_paths + 1374 self._interface_system._dart_callback_file_paths +
1384 self._dart_frog_file_paths)) 1375 self._dart_frog_file_paths))
1385 1376
1386 def Finish(self): 1377 def Finish(self):
(...skipping 20 matching lines...) Expand all
1407 dom_implementation_classes, output_dir): 1398 dom_implementation_classes, output_dir):
1408 """Prepared for generating wrapping implementation. 1399 """Prepared for generating wrapping implementation.
1409 1400
1410 - Creates emitter for Dart code. 1401 - Creates emitter for Dart code.
1411 """ 1402 """
1412 super(HtmlDartiumSystem, self).__init__( 1403 super(HtmlDartiumSystem, self).__init__(
1413 templates, database, emitters, output_dir) 1404 templates, database, emitters, output_dir)
1414 self._auxiliary_dir = auxiliary_dir 1405 self._auxiliary_dir = auxiliary_dir
1415 self._dom_implementation_classes = dom_implementation_classes 1406 self._dom_implementation_classes = dom_implementation_classes
1416 1407
1417 def InterfaceGenerator(self, 1408 def ProcessInterface(self, interface):
1418 interface,
1419 common_prefix,
1420 super_interface_name,
1421 source_filter):
1422 # Implementation classes are generated by NativeImplementationSystem. 1409 # Implementation classes are generated by NativeImplementationSystem.
1423 # FIXME: merge HtmlDartiumSystem into NativeImplementationSystem. 1410 # FIXME: merge HtmlDartiumSystem into NativeImplementationSystem.
1424 return None 1411 pass
1425 1412
1426 def ProcessCallback(self, interface, info): 1413 def ProcessCallback(self, interface, info):
1427 pass 1414 pass
1428 1415
1429 def GenerateLibraries(self): 1416 def GenerateLibraries(self):
1430 # Library generated for implementation. 1417 # Library generated for implementation.
1431 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) 1418 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir)
1432 1419
1433 self._GenerateLibFile( 1420 self._GenerateLibFile(
1434 'html_dartium.darttemplate', 1421 'html_dartium.darttemplate',
(...skipping 23 matching lines...) Expand all
1458 Collect(database.GetInterface(parent.type.id), 1445 Collect(database.GetInterface(parent.type.id),
1459 seen, collected) 1446 seen, collected)
1460 1447
1461 inheritance_closure = {} 1448 inheritance_closure = {}
1462 for interface in database.GetInterfaces(): 1449 for interface in database.GetInterfaces():
1463 seen = set() 1450 seen = set()
1464 collected = [] 1451 collected = []
1465 Collect(interface, seen, collected) 1452 Collect(interface, seen, collected)
1466 inheritance_closure[interface.id] = collected 1453 inheritance_closure[interface.id] = collected
1467 return inheritance_closure 1454 return inheritance_closure
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698