| 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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 760 |
| 761 class HtmlSystem(System): | 761 class HtmlSystem(System): |
| 762 | 762 |
| 763 def __init__(self, templates, database, emitters, output_dir): | 763 def __init__(self, templates, database, emitters, output_dir): |
| 764 super(HtmlSystem, self).__init__( | 764 super(HtmlSystem, self).__init__( |
| 765 templates, database, emitters, output_dir) | 765 templates, database, emitters, output_dir) |
| 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, backend): |
| 771 super(HtmlInterfacesSystem, self).__init__( | 771 super(HtmlInterfacesSystem, self).__init__( |
| 772 templates, database, emitters, output_dir) | 772 templates, database, emitters, output_dir) |
| 773 self._backend = backend |
| 773 self._dart_interface_file_paths = [] | 774 self._dart_interface_file_paths = [] |
| 774 self._factory_provider_emitters = {} | 775 self._factory_provider_emitters = {} |
| 775 | 776 |
| 776 def ProcessInterface(self, interface): | 777 def ProcessInterface(self, interface): |
| 777 """.""" | 778 """.""" |
| 779 |
| 780 self._backend.ProcessInterface(interface) |
| 781 |
| 778 if interface.id in _merged_html_interfaces: | 782 if interface.id in _merged_html_interfaces: |
| 779 return | 783 return |
| 780 | 784 |
| 781 html_interface_name = self._shared._HTMLInterfaceName(interface.id) | 785 html_interface_name = self._shared._HTMLInterfaceName(interface.id) |
| 782 dart_interface_file_path = self._FilePathForDartInterface( | 786 dart_interface_file_path = self._FilePathForDartInterface( |
| 783 html_interface_name) | 787 html_interface_name) |
| 784 | 788 |
| 785 self._dart_interface_file_paths.append(dart_interface_file_path) | 789 self._dart_interface_file_paths.append(dart_interface_file_path) |
| 786 | 790 |
| 787 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) | 791 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| 788 | 792 |
| 789 template_file = 'interface_%s.darttemplate' % html_interface_name | 793 template_file = 'interface_%s.darttemplate' % html_interface_name |
| 790 template = self._templates.TryLoad(template_file) | 794 template = self._templates.TryLoad(template_file) |
| 791 if not template: | 795 if not template: |
| 792 template = self._templates.Load('interface.darttemplate') | 796 template = self._templates.Load('interface.darttemplate') |
| 793 | 797 |
| 794 generator = HtmlDartInterfaceGenerator( | 798 generator = HtmlDartInterfaceGenerator( |
| 795 self, interface, dart_interface_code, | 799 self, interface, dart_interface_code, |
| 796 template, self._shared) | 800 template, self._shared) |
| 797 generator.Generate() | 801 generator.Generate() |
| 798 | 802 |
| 799 def ProcessCallback(self, interface, info): | 803 def ProcessCallback(self, interface, info): |
| 800 """Generates a typedef for the callback interface.""" | 804 """Generates a typedef for the callback interface.""" |
| 801 interface_name = interface.id | 805 interface_name = interface.id |
| 802 file_path = self._FilePathForDartInterface(interface_name) | 806 file_path = self._FilePathForDartInterface(interface_name) |
| 803 self._ProcessCallback(interface, info, file_path) | 807 self._ProcessCallback(interface, info, file_path) |
| 804 | 808 |
| 805 def GenerateLibraries(self): | 809 def GenerateLibraries(self): |
| 806 pass | 810 self._backend.GenerateLibraries(self._dart_interface_file_paths) |
| 807 | |
| 808 | 811 |
| 809 def _FilePathForDartInterface(self, interface_name): | 812 def _FilePathForDartInterface(self, interface_name): |
| 810 """Returns the file path of the Dart interface definition.""" | 813 """Returns the file path of the Dart interface definition.""" |
| 811 # TODO(jmesserly): is this the right path | 814 # TODO(jmesserly): is this the right path |
| 812 return os.path.join(self._output_dir, 'html', 'interface', | 815 return os.path.join(self._output_dir, 'html', 'interface', |
| 813 '%s.dart' % interface_name) | 816 '%s.dart' % interface_name) |
| 814 | 817 |
| 815 # ------------------------------------------------------------------------------ | 818 # ------------------------------------------------------------------------------ |
| 816 | 819 |
| 817 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 820 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 template_file = 'impl_%s.darttemplate' % html_interface_name | 1362 template_file = 'impl_%s.darttemplate' % html_interface_name |
| 1360 template = self._templates.TryLoad(template_file) | 1363 template = self._templates.TryLoad(template_file) |
| 1361 if not template: | 1364 if not template: |
| 1362 template = self._templates.Load('frog_impl.darttemplate') | 1365 template = self._templates.Load('frog_impl.darttemplate') |
| 1363 | 1366 |
| 1364 dart_code = self._ImplFileEmitter(html_interface_name) | 1367 dart_code = self._ImplFileEmitter(html_interface_name) |
| 1365 generator = HtmlFrogClassGenerator(self, interface, template, | 1368 generator = HtmlFrogClassGenerator(self, interface, template, |
| 1366 dart_code, self._shared) | 1369 dart_code, self._shared) |
| 1367 generator.Generate() | 1370 generator.Generate() |
| 1368 | 1371 |
| 1369 def GenerateLibraries(self): | 1372 def GenerateLibraries(self, interface_files): |
| 1370 self._GenerateLibFile( | 1373 self._GenerateLibFile( |
| 1371 'html_frog.darttemplate', | 1374 'html_frog.darttemplate', |
| 1372 os.path.join(self._output_dir, 'html_frog.dart'), | 1375 os.path.join(self._output_dir, 'html_frog.dart'), |
| 1373 (self._interface_system._dart_interface_file_paths + | 1376 interface_files + self._dart_frog_file_paths) |
| 1374 self._interface_system._dart_callback_file_paths + | |
| 1375 self._dart_frog_file_paths)) | |
| 1376 | 1377 |
| 1377 def Finish(self): | 1378 def Finish(self): |
| 1378 pass | 1379 pass |
| 1379 | 1380 |
| 1380 def _ImplFileEmitter(self, name): | 1381 def _ImplFileEmitter(self, name): |
| 1381 """Returns the file emitter of the Frog implementation file.""" | 1382 """Returns the file emitter of the Frog implementation file.""" |
| 1382 path = os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) | 1383 path = os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) |
| 1383 self._dart_frog_file_paths.append(path) | 1384 self._dart_frog_file_paths.append(path) |
| 1384 return self._emitters.FileEmitter(path) | 1385 return self._emitters.FileEmitter(path) |
| 1385 | 1386 |
| 1386 def _EmitterForFactoryProviderBody(self, name): | 1387 def _EmitterForFactoryProviderBody(self, name): |
| 1387 if name not in self._factory_provider_emitters: | 1388 if name not in self._factory_provider_emitters: |
| 1388 template = self._templates.Load('factoryprovider_%s.darttemplate' % name) | 1389 template = self._templates.Load('factoryprovider_%s.darttemplate' % name) |
| 1389 file_emitter = self._ImplFileEmitter(name) | 1390 file_emitter = self._ImplFileEmitter(name) |
| 1390 self._factory_provider_emitters[name] = file_emitter.Emit(template) | 1391 self._factory_provider_emitters[name] = file_emitter.Emit(template) |
| 1391 return self._factory_provider_emitters[name] | 1392 return self._factory_provider_emitters[name] |
| 1392 | 1393 |
| 1393 # ----------------------------------------------------------------------------- | 1394 # ----------------------------------------------------------------------------- |
| 1394 | 1395 |
| 1395 class HtmlDartiumSystem(HtmlSystem): | |
| 1396 | |
| 1397 def __init__(self, templates, database, emitters, auxiliary_dir, | |
| 1398 dom_implementation_classes, output_dir): | |
| 1399 """Prepared for generating wrapping implementation. | |
| 1400 | |
| 1401 - Creates emitter for Dart code. | |
| 1402 """ | |
| 1403 super(HtmlDartiumSystem, self).__init__( | |
| 1404 templates, database, emitters, output_dir) | |
| 1405 self._auxiliary_dir = auxiliary_dir | |
| 1406 self._dom_implementation_classes = dom_implementation_classes | |
| 1407 | |
| 1408 def ProcessInterface(self, interface): | |
| 1409 # Implementation classes are generated by NativeImplementationSystem. | |
| 1410 # FIXME: merge HtmlDartiumSystem into NativeImplementationSystem. | |
| 1411 pass | |
| 1412 | |
| 1413 def ProcessCallback(self, interface, info): | |
| 1414 pass | |
| 1415 | |
| 1416 def GenerateLibraries(self): | |
| 1417 # Library generated for implementation. | |
| 1418 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) | |
| 1419 | |
| 1420 self._GenerateLibFile( | |
| 1421 'html_dartium.darttemplate', | |
| 1422 os.path.join(self._output_dir, 'html_dartium.dart'), | |
| 1423 (self._interface_system._dart_interface_file_paths + | |
| 1424 self._interface_system._dart_callback_file_paths + | |
| 1425 self._dom_implementation_classes), | |
| 1426 AUXILIARY_DIR=MassagePath(auxiliary_dir)) | |
| 1427 | |
| 1428 def Finish(self): | |
| 1429 pass | |
| 1430 | |
| 1431 | |
| 1432 def _ComputeInheritanceClosure(database): | 1396 def _ComputeInheritanceClosure(database): |
| 1433 def Collect(interface, seen, collected): | 1397 def Collect(interface, seen, collected): |
| 1434 name = interface.id | 1398 name = interface.id |
| 1435 if '<' in name: | 1399 if '<' in name: |
| 1436 # TODO(sra): Handle parameterized types. | 1400 # TODO(sra): Handle parameterized types. |
| 1437 return | 1401 return |
| 1438 if not name in seen: | 1402 if not name in seen: |
| 1439 seen.add(name) | 1403 seen.add(name) |
| 1440 collected.append(name) | 1404 collected.append(name) |
| 1441 for parent in interface.parents: | 1405 for parent in interface.parents: |
| 1442 # TODO(sra): Handle parameterized types. | 1406 # TODO(sra): Handle parameterized types. |
| 1443 if not '<' in parent.type.id: | 1407 if not '<' in parent.type.id: |
| 1444 if database.HasInterface(parent.type.id): | 1408 if database.HasInterface(parent.type.id): |
| 1445 Collect(database.GetInterface(parent.type.id), | 1409 Collect(database.GetInterface(parent.type.id), |
| 1446 seen, collected) | 1410 seen, collected) |
| 1447 | 1411 |
| 1448 inheritance_closure = {} | 1412 inheritance_closure = {} |
| 1449 for interface in database.GetInterfaces(): | 1413 for interface in database.GetInterfaces(): |
| 1450 seen = set() | 1414 seen = set() |
| 1451 collected = [] | 1415 collected = [] |
| 1452 Collect(interface, seen, collected) | 1416 Collect(interface, seen, collected) |
| 1453 inheritance_closure[interface.id] = collected | 1417 inheritance_closure[interface.id] = collected |
| 1454 return inheritance_closure | 1418 return inheritance_closure |
| OLD | NEW |