| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 factory_provider = '_' + interface_name + 'FactoryProvider' | 155 factory_provider = '_' + interface_name + 'FactoryProvider' |
| 156 emitter = self._system._ImplFileEmitter(factory_provider) | 156 emitter = self._system._ImplFileEmitter(factory_provider) |
| 157 emitter.Emit( | 157 emitter.Emit( |
| 158 template, | 158 template, |
| 159 FACTORYPROVIDER=factory_provider, | 159 FACTORYPROVIDER=factory_provider, |
| 160 CONSTRUCTOR=interface_name, | 160 CONSTRUCTOR=interface_name, |
| 161 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), | 161 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), |
| 162 NAMEDCONSTRUCTOR=constructor_info.name or interface_name, | 162 NAMEDCONSTRUCTOR=constructor_info.name or interface_name, |
| 163 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 163 ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
| 164 | 164 |
| 165 def _NarrowToImplementationType(self, type_name): | 165 def _ShouldNarrowToImplementationType(self, type_name): |
| 166 # TODO(sra): Move into the 'system' and cache the result. | 166 # TODO(sra): Move into the 'system' and cache the result. |
| 167 if type_name == 'EventListener': | 167 if type_name == 'EventListener': |
| 168 # Callbacks are typedef functions so don't have a class. | 168 # Callbacks are typedef functions so don't have a class. |
| 169 return type_name | 169 return False |
| 170 if self._system._database.HasInterface(type_name): | 170 if self._system._database.HasInterface(type_name): |
| 171 interface = self._system._database.GetInterface(type_name) | 171 interface = self._system._database.GetInterface(type_name) |
| 172 if RecognizeCallback(interface): | 172 if RecognizeCallback(interface): |
| 173 # Callbacks are typedef functions so don't have a class. | 173 # Callbacks are typedef functions so don't have a class. |
| 174 return type_name | 174 return False |
| 175 elif type_name == 'MediaQueryListListener': | 175 elif type_name == 'MediaQueryListListener': |
| 176 # Somewhat like a callback. See Issue 3338. | 176 # Somewhat like a callback. See Issue 3338. |
| 177 return type_name | 177 return False |
| 178 else: | 178 else: |
| 179 return self._ImplClassName(type_name) | 179 return True |
| 180 return False |
| 181 |
| 182 def _NarrowToImplementationType(self, type_name): |
| 183 if self._ShouldNarrowToImplementationType(type_name): |
| 184 return self._ImplClassName(type_name) |
| 180 return type_name | 185 return type_name |
| 181 | 186 |
| 182 def _NarrowInputType(self, type_name): | 187 def _NarrowInputType(self, type_name): |
| 183 return self._NarrowToImplementationType(DartType(type_name)) | 188 return self._NarrowToImplementationType(DartType(type_name)) |
| 184 | 189 |
| 185 def _NarrowOutputType(self, type_name): | 190 def _NarrowOutputType(self, type_name): |
| 186 return self._NarrowToImplementationType(DartType(type_name)) | 191 return self._NarrowToImplementationType(DartType(type_name)) |
| 187 | 192 |
| 188 def AddConstant(self, constant): | 193 def AddConstant(self, constant): |
| 189 # Since we are currently generating native classes without interfaces, | 194 # Since we are currently generating native classes without interfaces, |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 if native_body: | 395 if native_body: |
| 391 native_string = " '''" + native_body + "'''" | 396 native_string = " '''" + native_body + "'''" |
| 392 | 397 |
| 393 self._members_emitter.Emit( | 398 self._members_emitter.Emit( |
| 394 '\n' | 399 '\n' |
| 395 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', | 400 ' $TYPE $NAME($PARAMS) native$NATIVESTRING;\n', |
| 396 TYPE=self._NarrowOutputType(info.type_name), | 401 TYPE=self._NarrowOutputType(info.type_name), |
| 397 NAME=info.name, | 402 NAME=info.name, |
| 398 PARAMS=params, | 403 PARAMS=params, |
| 399 NATIVESTRING=native_string) | 404 NATIVESTRING=native_string) |
| OLD | NEW |