| 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 dart2js binding from the IDL database.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 from generator import * | 10 from generator import * |
| 11 from systembase import * | 11 from systembase import * |
| 12 | 12 |
| 13 # Members (getters, setters, and methods) to suppress. These are | 13 # Members (getters, setters, and methods) to suppress. These are |
| 14 # either removed or custom implemented. | 14 # either removed or custom implemented. |
| 15 _dom_frog_omitted_members = set([ | 15 _dom_dart2js_omitted_members = set([ |
| 16 # Replace with custom. | 16 # Replace with custom. |
| 17 'DOMWindow.get:top', | 17 'DOMWindow.get:top', |
| 18 'HTMLIFrameElement.get:contentWindow', | 18 'HTMLIFrameElement.get:contentWindow', |
| 19 | 19 |
| 20 # Remove. | 20 # Remove. |
| 21 'DOMWindow.get:frameElement', | 21 'DOMWindow.get:frameElement', |
| 22 'HTMLIFrameElement.get:contentDocument', | 22 'HTMLIFrameElement.get:contentDocument', |
| 23 ]) | 23 ]) |
| 24 | 24 |
| 25 class FrogSystem(System): | 25 class Dart2JSSystem(System): |
| 26 | 26 |
| 27 def __init__(self, options): | 27 def __init__(self, options): |
| 28 super(FrogSystem, self).__init__(options) | 28 super(Dart2JSSystem, self).__init__(options) |
| 29 self._impl_file_paths = [] | 29 self._impl_file_paths = [] |
| 30 | 30 |
| 31 def ProcessInterface(self, interface): | 31 def ProcessInterface(self, interface): |
| 32 """.""" | 32 """.""" |
| 33 if IsPureInterface(interface.id): | 33 if IsPureInterface(interface.id): |
| 34 return | 34 return |
| 35 template_file = 'impl_%s.darttemplate' % interface.id | 35 template_file = 'impl_%s.darttemplate' % interface.id |
| 36 template = self._templates.TryLoad(template_file) | 36 template = self._templates.TryLoad(template_file) |
| 37 if not template: | 37 if not template: |
| 38 template = self._templates.Load('frog_impl.darttemplate') | 38 template = self._templates.Load('dart2js_impl.darttemplate') |
| 39 | 39 |
| 40 dart_code = self._ImplFileEmitter(interface.id) | 40 dart_code = self._ImplFileEmitter(interface.id) |
| 41 FrogInterfaceGenerator(self, interface, template, dart_code).Generate() | 41 Dart2JSInterfaceGenerator(self, interface, template, dart_code).Generate() |
| 42 | 42 |
| 43 def GenerateLibraries(self): | 43 def GenerateLibraries(self): |
| 44 self._GenerateLibFile( | 44 self._GenerateLibFile( |
| 45 'frog_dom.darttemplate', | 45 'dart2js_dom.darttemplate', |
| 46 os.path.join(self._output_dir, 'dom_frog.dart'), | 46 os.path.join(self._output_dir, 'dom_dart2js.dart'), |
| 47 (self._interface_system._dart_interface_file_paths + | 47 (self._interface_system._dart_interface_file_paths + |
| 48 self._impl_file_paths)) | 48 self._impl_file_paths)) |
| 49 | 49 |
| 50 def Finish(self): | 50 def Finish(self): |
| 51 pass | 51 pass |
| 52 | 52 |
| 53 def _ImplFileEmitter(self, name): | 53 def _ImplFileEmitter(self, name): |
| 54 """Returns the file emitter of the Frog implementation file.""" | 54 """Returns the file emitter of the Dart2JS implementation file.""" |
| 55 path = os.path.join(self._output_dir, 'src', 'frog', '%s.dart' % name) | 55 path = os.path.join(self._output_dir, 'src', 'dart2js', '%s.dart' % name) |
| 56 self._impl_file_paths.append(path) | 56 self._impl_file_paths.append(path) |
| 57 return self._emitters.FileEmitter(path) | 57 return self._emitters.FileEmitter(path) |
| 58 | 58 |
| 59 # ------------------------------------------------------------------------------ | 59 # ------------------------------------------------------------------------------ |
| 60 | 60 |
| 61 class FrogInterfaceGenerator(BaseGenerator): | 61 class Dart2JSInterfaceGenerator(BaseGenerator): |
| 62 """Generates a Frog class for a DOM IDL interface.""" | 62 """Generates a Dart2JS class for a DOM IDL interface.""" |
| 63 | 63 |
| 64 def __init__(self, system, interface, template, dart_code): | 64 def __init__(self, system, interface, template, dart_code): |
| 65 """Generates Dart code for the given interface. | 65 """Generates Dart code for the given interface. |
| 66 | 66 |
| 67 Args: | 67 Args: |
| 68 | 68 |
| 69 interface: an IDLInterface instance. It is assumed that all types have | 69 interface: an IDLInterface instance. It is assumed that all types have |
| 70 been converted to Dart types (e.g. int, String), unless they are in | 70 been converted to Dart types (e.g. int, String), unless they are in |
| 71 the same package as the interface. | 71 the same package as the interface. |
| 72 template: A string template. | 72 template: A string template. |
| 73 dart_code: an Emitter for the file containing the Dart implementation | 73 dart_code: an Emitter for the file containing the Dart implementation |
| 74 class. | 74 class. |
| 75 """ | 75 """ |
| 76 super(FrogInterfaceGenerator, self).__init__(system._database, interface) | 76 super(Dart2JSInterfaceGenerator, self).__init__(system._database, interface) |
| 77 self._system = system | 77 self._system = system |
| 78 self._interface = interface | 78 self._interface = interface |
| 79 self._template = template | 79 self._template = template |
| 80 self._dart_code = dart_code | 80 self._dart_code = dart_code |
| 81 self._current_secondary_parent = None | 81 self._current_secondary_parent = None |
| 82 | 82 |
| 83 | 83 |
| 84 def StartInterface(self): | 84 def StartInterface(self): |
| 85 interface = self._interface | 85 interface = self._interface |
| 86 interface_name = interface.id | 86 interface_name = interface.id |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 # generate the constants as part of the class. This will need to go away | 180 # generate the constants as part of the class. This will need to go away |
| 181 # if we revert back to generating interfaces. | 181 # if we revert back to generating interfaces. |
| 182 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', | 182 self._members_emitter.Emit('\n static final $TYPE $NAME = $VALUE;\n', |
| 183 NAME=constant.id, | 183 NAME=constant.id, |
| 184 TYPE=self._DartType(constant.type.id), | 184 TYPE=self._DartType(constant.type.id), |
| 185 VALUE=constant.value) | 185 VALUE=constant.value) |
| 186 | 186 |
| 187 pass | 187 pass |
| 188 | 188 |
| 189 def OverrideMember(self, member): | 189 def OverrideMember(self, member): |
| 190 return self._interface.id + '.' + member in _dom_frog_omitted_members | 190 return self._interface.id + '.' + member in _dom_dart2js_omitted_members |
| 191 | 191 |
| 192 def AddAttribute(self, attribute): | 192 def AddAttribute(self, attribute): |
| 193 getter = attribute | 193 getter = attribute |
| 194 setter = attribute if not IsReadOnly(attribute) else None | 194 setter = attribute if not IsReadOnly(attribute) else None |
| 195 if getter and self.OverrideMember('get:' + getter.id): | 195 if getter and self.OverrideMember('get:' + getter.id): |
| 196 getter = None | 196 getter = None |
| 197 if setter and self.OverrideMember('set:' + setter.id): | 197 if setter and self.OverrideMember('set:' + setter.id): |
| 198 setter = None | 198 setter = None |
| 199 if not getter and not setter: | 199 if not getter and not setter: |
| 200 return | 200 return |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 info: An OperationInfo object. | 370 info: An OperationInfo object. |
| 371 """ | 371 """ |
| 372 # TODO(vsm): Handle overloads. | 372 # TODO(vsm): Handle overloads. |
| 373 params = info.ParametersImplementationDeclaration( | 373 params = info.ParametersImplementationDeclaration( |
| 374 lambda type_name: self._NarrowInputType(type_name)) | 374 lambda type_name: self._NarrowInputType(type_name)) |
| 375 | 375 |
| 376 native_string = '' | 376 native_string = '' |
| 377 if info.declared_name != info.name: | 377 if info.declared_name != info.name: |
| 378 native_string = " '%s'" % info.declared_name | 378 native_string = " '%s'" % info.declared_name |
| 379 | 379 |
| 380 native_body = dom_frog_native_bodies.get( | 380 native_body = dom_dart2js_native_bodies.get( |
| 381 self._interface.id + '.' + info.name, '') | 381 self._interface.id + '.' + info.name, '') |
| 382 if native_body: | 382 if native_body: |
| 383 native_string = " '''" + native_body + "'''" | 383 native_string = " '''" + native_body + "'''" |
| 384 | 384 |
| 385 self._members_emitter.Emit( | 385 self._members_emitter.Emit( |
| 386 '\n' | 386 '\n' |
| 387 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', | 387 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', |
| 388 TYPE=self._NarrowOutputType(info.type_name), | 388 TYPE=self._NarrowOutputType(info.type_name), |
| 389 NAME=info.name, | 389 NAME=info.name, |
| 390 PARAMS=params, | 390 PARAMS=params, |
| 391 NATIVESTRING=native_string) | 391 NATIVESTRING=native_string) |
| OLD | NEW |