| 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 17 matching lines...) Expand all Loading... |
| 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 InterfaceGenerator(self, |
| 33 interface, | 33 interface, |
| 34 common_prefix, | 34 common_prefix, |
| 35 super_interface_name, | 35 super_interface_name, |
| 36 source_filter): | 36 source_filter): |
| 37 """.""" | 37 """.""" |
| 38 if IsPureInterface(interface.id): |
| 39 return |
| 38 template_file = 'impl_%s.darttemplate' % interface.id | 40 template_file = 'impl_%s.darttemplate' % interface.id |
| 39 template = self._templates.TryLoad(template_file) | 41 template = self._templates.TryLoad(template_file) |
| 40 if not template: | 42 if not template: |
| 41 template = self._templates.Load('frog_impl.darttemplate') | 43 template = self._templates.Load('frog_impl.darttemplate') |
| 42 | 44 |
| 43 dart_code = self._ImplFileEmitter(interface.id) | 45 dart_code = self._ImplFileEmitter(interface.id) |
| 44 return FrogInterfaceGenerator(self, interface, template, | 46 return FrogInterfaceGenerator(self, interface, template, |
| 45 super_interface_name, dart_code) | 47 super_interface_name, dart_code) |
| 46 | 48 |
| 47 def GenerateLibraries(self): | 49 def GenerateLibraries(self): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 interface = self._interface | 94 interface = self._interface |
| 93 interface_name = interface.id | 95 interface_name = interface.id |
| 94 self._class_name = self._ImplClassName(interface_name) | 96 self._class_name = self._ImplClassName(interface_name) |
| 95 | 97 |
| 96 base = None | 98 base = None |
| 97 if interface.parents: | 99 if interface.parents: |
| 98 supertype = interface.parents[0].type.id | 100 supertype = interface.parents[0].type.id |
| 99 if IsDartCollectionType(supertype): | 101 if IsDartCollectionType(supertype): |
| 100 # List methods are injected in AddIndexer. | 102 # List methods are injected in AddIndexer. |
| 101 pass | 103 pass |
| 104 elif IsPureInterface(supertype): |
| 105 pass |
| 102 else: | 106 else: |
| 103 base = self._ImplClassName(supertype) | 107 base = self._ImplClassName(supertype) |
| 104 | 108 |
| 105 native_spec = MakeNativeSpec(interface.javascript_binding_name) | 109 native_spec = MakeNativeSpec(interface.javascript_binding_name) |
| 106 | 110 |
| 107 if base: | 111 if base: |
| 108 extends = ' extends ' + base | 112 extends = ' extends ' + base |
| 109 elif native_spec[0] == '=': | 113 elif native_spec[0] == '=': |
| 110 # The implementation is a singleton with no prototype. | 114 # The implementation is a singleton with no prototype. |
| 111 extends = '' | 115 extends = '' |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 def _NarrowToImplementationType(self, type_name): | 164 def _NarrowToImplementationType(self, type_name): |
| 161 # TODO(sra): Move into the 'system' and cache the result. | 165 # TODO(sra): Move into the 'system' and cache the result. |
| 162 if type_name == 'EventListener': | 166 if type_name == 'EventListener': |
| 163 # Callbacks are typedef functions so don't have a class. | 167 # Callbacks are typedef functions so don't have a class. |
| 164 return type_name | 168 return type_name |
| 165 if self._system._database.HasInterface(type_name): | 169 if self._system._database.HasInterface(type_name): |
| 166 interface = self._system._database.GetInterface(type_name) | 170 interface = self._system._database.GetInterface(type_name) |
| 167 if RecognizeCallback(interface): | 171 if RecognizeCallback(interface): |
| 168 # Callbacks are typedef functions so don't have a class. | 172 # Callbacks are typedef functions so don't have a class. |
| 169 return type_name | 173 return type_name |
| 174 elif type_name == 'MediaQueryListListener': |
| 175 # Somewhat like a callback. See Issue 3338. |
| 176 return type_name |
| 170 else: | 177 else: |
| 171 return self._ImplClassName(type_name) | 178 return self._ImplClassName(type_name) |
| 172 return type_name | 179 return type_name |
| 173 | 180 |
| 174 def _NarrowInputType(self, type_name): | 181 def _NarrowInputType(self, type_name): |
| 175 return self._NarrowToImplementationType(DartType(type_name)) | 182 return self._NarrowToImplementationType(DartType(type_name)) |
| 176 | 183 |
| 177 def _NarrowOutputType(self, type_name): | 184 def _NarrowOutputType(self, type_name): |
| 178 return self._NarrowToImplementationType(DartType(type_name)) | 185 return self._NarrowToImplementationType(DartType(type_name)) |
| 179 | 186 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 OPT_TYPE=TypeOrNothing(self._NarrowInputType(attr.type.id))) | 277 OPT_TYPE=TypeOrNothing(self._NarrowInputType(attr.type.id))) |
| 271 | 278 |
| 272 def _FindShadowedAttribute(self, attr): | 279 def _FindShadowedAttribute(self, attr): |
| 273 """Returns (attribute, superinterface) or (None, None).""" | 280 """Returns (attribute, superinterface) or (None, None).""" |
| 274 def FindInParent(interface): | 281 def FindInParent(interface): |
| 275 """Returns matching attribute in parent, or None.""" | 282 """Returns matching attribute in parent, or None.""" |
| 276 if interface.parents: | 283 if interface.parents: |
| 277 parent = interface.parents[0] | 284 parent = interface.parents[0] |
| 278 if IsDartCollectionType(parent.type.id): | 285 if IsDartCollectionType(parent.type.id): |
| 279 return (None, None) | 286 return (None, None) |
| 287 if IsPureInterface(parent.type.id): |
| 288 return (None, None) |
| 280 if self._system._database.HasInterface(parent.type.id): | 289 if self._system._database.HasInterface(parent.type.id): |
| 281 parent_interface = self._system._database.GetInterface(parent.type.id) | 290 parent_interface = self._system._database.GetInterface(parent.type.id) |
| 282 attr2 = FindMatchingAttribute(parent_interface, attr) | 291 attr2 = FindMatchingAttribute(parent_interface, attr) |
| 283 if attr2: | 292 if attr2: |
| 284 return (attr2, parent_interface) | 293 return (attr2, parent_interface) |
| 285 return FindInParent(parent_interface) | 294 return FindInParent(parent_interface) |
| 286 return (None, None) | 295 return (None, None) |
| 287 | 296 |
| 288 return FindInParent(self._interface) if attr else (None, None) | 297 return FindInParent(self._interface) if attr else (None, None) |
| 289 | 298 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 self._members_emitter.Emit( | 377 self._members_emitter.Emit( |
| 369 '\n' | 378 '\n' |
| 370 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', | 379 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', |
| 371 TYPE=self._NarrowOutputType(info.type_name), | 380 TYPE=self._NarrowOutputType(info.type_name), |
| 372 NAME=info.name, | 381 NAME=info.name, |
| 373 PARAMS=params, | 382 PARAMS=params, |
| 374 NATIVESTRING=native_string) | 383 NATIVESTRING=native_string) |
| 375 | 384 |
| 376 def AddStaticOperation(self, info): | 385 def AddStaticOperation(self, info): |
| 377 pass | 386 pass |
| OLD | NEW |