| 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 systems to generate | 6 """This module provides shared functionality for the systems to generate |
| 7 frog binding from the IDL database.""" | 7 frog binding from the IDL database.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 from generator import * | 10 from generator import * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 'HTMLIFrameElement.get:contentDocument', | 22 'HTMLIFrameElement.get:contentDocument', |
| 23 ]) | 23 ]) |
| 24 | 24 |
| 25 class FrogSystem(System): | 25 class FrogSystem(System): |
| 26 | 26 |
| 27 def __init__(self, templates, database, emitters, output_dir): | 27 def __init__(self, templates, database, emitters, output_dir): |
| 28 super(FrogSystem, self).__init__( | 28 super(FrogSystem, self).__init__( |
| 29 templates, database, emitters, output_dir) | 29 templates, database, emitters, output_dir) |
| 30 self._impl_file_paths = [] | 30 self._impl_file_paths = [] |
| 31 | 31 |
| 32 def InterfaceGenerator(self, | 32 def ProcessInterface(self, interface): |
| 33 interface, | |
| 34 common_prefix, | |
| 35 super_interface_name, | |
| 36 source_filter): | |
| 37 """.""" | 33 """.""" |
| 38 if IsPureInterface(interface.id): | 34 if IsPureInterface(interface.id): |
| 39 return | 35 return |
| 40 template_file = 'impl_%s.darttemplate' % interface.id | 36 template_file = 'impl_%s.darttemplate' % interface.id |
| 41 template = self._templates.TryLoad(template_file) | 37 template = self._templates.TryLoad(template_file) |
| 42 if not template: | 38 if not template: |
| 43 template = self._templates.Load('frog_impl.darttemplate') | 39 template = self._templates.Load('frog_impl.darttemplate') |
| 44 | 40 |
| 45 dart_code = self._ImplFileEmitter(interface.id) | 41 dart_code = self._ImplFileEmitter(interface.id) |
| 46 return FrogInterfaceGenerator(self, interface, template, | 42 FrogInterfaceGenerator(self, interface, template, dart_code).Generate() |
| 47 super_interface_name, dart_code) | |
| 48 | 43 |
| 49 def GenerateLibraries(self): | 44 def GenerateLibraries(self): |
| 50 self._GenerateLibFile( | 45 self._GenerateLibFile( |
| 51 'frog_dom.darttemplate', | 46 'frog_dom.darttemplate', |
| 52 os.path.join(self._output_dir, 'dom_frog.dart'), | 47 os.path.join(self._output_dir, 'dom_frog.dart'), |
| 53 (self._interface_system._dart_interface_file_paths + | 48 (self._interface_system._dart_interface_file_paths + |
| 54 self._interface_system._dart_callback_file_paths + | 49 self._interface_system._dart_callback_file_paths + |
| 55 self._impl_file_paths)) | 50 self._impl_file_paths)) |
| 56 | 51 |
| 57 def Finish(self): | 52 def Finish(self): |
| 58 pass | 53 pass |
| 59 | 54 |
| 60 def _ImplFileEmitter(self, name): | 55 def _ImplFileEmitter(self, name): |
| 61 """Returns the file emitter of the Frog implementation file.""" | 56 """Returns the file emitter of the Frog implementation file.""" |
| 62 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name) | 57 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name) |
| 63 self._impl_file_paths.append(path) | 58 self._impl_file_paths.append(path) |
| 64 return self._emitters.FileEmitter(path) | 59 return self._emitters.FileEmitter(path) |
| 65 | 60 |
| 66 # ------------------------------------------------------------------------------ | 61 # ------------------------------------------------------------------------------ |
| 67 | 62 |
| 68 class FrogInterfaceGenerator(BaseGenerator): | 63 class FrogInterfaceGenerator(BaseGenerator): |
| 69 """Generates a Frog class for a DOM IDL interface.""" | 64 """Generates a Frog class for a DOM IDL interface.""" |
| 70 | 65 |
| 71 def __init__(self, system, interface, template, super_interface, dart_code): | 66 def __init__(self, system, interface, template, dart_code): |
| 72 """Generates Dart code for the given interface. | 67 """Generates Dart code for the given interface. |
| 73 | 68 |
| 74 Args: | 69 Args: |
| 75 | 70 |
| 76 interface: an IDLInterface instance. It is assumed that all types have | 71 interface: an IDLInterface instance. It is assumed that all types have |
| 77 been converted to Dart types (e.g. int, String), unless they are in | 72 been converted to Dart types (e.g. int, String), unless they are in |
| 78 the same package as the interface. | 73 the same package as the interface. |
| 79 template: A string template. | 74 template: A string template. |
| 80 super_interface: A string or None, the name of the common interface that | |
| 81 this interface implements, if any. | |
| 82 dart_code: an Emitter for the file containing the Dart implementation | 75 dart_code: an Emitter for the file containing the Dart implementation |
| 83 class. | 76 class. |
| 84 """ | 77 """ |
| 85 super(FrogInterfaceGenerator, self).__init__(system._database) | 78 super(FrogInterfaceGenerator, self).__init__(system._database, interface) |
| 86 self._system = system | 79 self._system = system |
| 87 self._interface = interface | 80 self._interface = interface |
| 88 self._template = template | 81 self._template = template |
| 89 self._super_interface = super_interface | |
| 90 self._dart_code = dart_code | 82 self._dart_code = dart_code |
| 91 self._current_secondary_parent = None | 83 self._current_secondary_parent = None |
| 92 | 84 |
| 93 | 85 |
| 94 def StartInterface(self): | 86 def StartInterface(self): |
| 95 interface = self._interface | 87 interface = self._interface |
| 96 interface_name = interface.id | 88 interface_name = interface.id |
| 97 self._class_name = self._ImplClassName(interface_name) | 89 self._class_name = self._ImplClassName(interface_name) |
| 98 | 90 |
| 99 base = None | 91 base = None |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 if native_body: | 387 if native_body: |
| 396 native_string = " '''" + native_body + "'''" | 388 native_string = " '''" + native_body + "'''" |
| 397 | 389 |
| 398 self._members_emitter.Emit( | 390 self._members_emitter.Emit( |
| 399 '\n' | 391 '\n' |
| 400 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', | 392 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', |
| 401 TYPE=self._NarrowOutputType(info.type_name), | 393 TYPE=self._NarrowOutputType(info.type_name), |
| 402 NAME=info.name, | 394 NAME=info.name, |
| 403 PARAMS=params, | 395 PARAMS=params, |
| 404 NATIVESTRING=native_string) | 396 NATIVESTRING=native_string) |
| OLD | NEW |