| 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 native binding from the IDL database.""" | 7 native binding from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 dart_impl_path = self._FilePathForDartImplementation(interface_name) | 40 dart_impl_path = self._FilePathForDartImplementation(interface_name) |
| 41 self._dom_impl_files.append(dart_impl_path) | 41 self._dom_impl_files.append(dart_impl_path) |
| 42 | 42 |
| 43 cpp_header_path = self._FilePathForCppHeader(interface_name) | 43 cpp_header_path = self._FilePathForCppHeader(interface_name) |
| 44 self._cpp_header_files.append(cpp_header_path) | 44 self._cpp_header_files.append(cpp_header_path) |
| 45 | 45 |
| 46 cpp_impl_path = self._FilePathForCppImplementation(interface_name) | 46 cpp_impl_path = self._FilePathForCppImplementation(interface_name) |
| 47 self._cpp_impl_files.append(cpp_impl_path) | 47 self._cpp_impl_files.append(cpp_impl_path) |
| 48 | 48 |
| 49 return NativeImplementationGenerator(self, interface, super_interface_name, | 49 return NativeImplementationGenerator(self, interface, |
| 50 self._emitters.FileEmitter(dart_impl_path), | 50 self._emitters.FileEmitter(dart_impl_path), |
| 51 self._emitters.FileEmitter(cpp_header_path), | 51 self._emitters.FileEmitter(cpp_header_path), |
| 52 self._emitters.FileEmitter(cpp_impl_path), | 52 self._emitters.FileEmitter(cpp_impl_path), |
| 53 self._BaseDefines(interface), | 53 self._BaseDefines(interface), |
| 54 self._templates) | 54 self._templates) |
| 55 | 55 |
| 56 def ProcessCallback(self, interface, info): | 56 def ProcessCallback(self, interface, info): |
| 57 self._interface = interface | 57 self._interface = interface |
| 58 | 58 |
| 59 dart_interface_path = self._FilePathForDartInterface(self._interface.id) | 59 dart_interface_path = self._FilePathForDartInterface(self._interface.id) |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 def _FilePathForCppHeader(self, interface_name): | 188 def _FilePathForCppHeader(self, interface_name): |
| 189 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name) | 189 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name) |
| 190 | 190 |
| 191 def _FilePathForCppImplementation(self, interface_name): | 191 def _FilePathForCppImplementation(self, interface_name): |
| 192 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name) | 192 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name) |
| 193 | 193 |
| 194 | 194 |
| 195 class NativeImplementationGenerator(systemwrapping.WrappingInterfaceGenerator): | 195 class NativeImplementationGenerator(systemwrapping.WrappingInterfaceGenerator): |
| 196 """Generates Dart implementation for one DOM IDL interface.""" | 196 """Generates Dart implementation for one DOM IDL interface.""" |
| 197 | 197 |
| 198 def __init__(self, system, interface, super_interface, | 198 def __init__(self, system, interface, |
| 199 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter, | 199 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter, |
| 200 base_members, templates): | 200 base_members, templates): |
| 201 """Generates Dart and C++ code for the given interface. | 201 """Generates Dart and C++ code for the given interface. |
| 202 | 202 |
| 203 Args: | 203 Args: |
| 204 system: The NativeImplementationSystem. | 204 system: The NativeImplementationSystem. |
| 205 interface: an IDLInterface instance. It is assumed that all types have | 205 interface: an IDLInterface instance. It is assumed that all types have |
| 206 been converted to Dart types (e.g. int, String), unless they are in | 206 been converted to Dart types (e.g. int, String), unless they are in |
| 207 the same package as the interface. | 207 the same package as the interface. |
| 208 super_interface: A string or None, the name of the common interface that | |
| 209 this interface implements, if any. | |
| 210 dart_impl_emitter: an Emitter for the file containing the Dart | 208 dart_impl_emitter: an Emitter for the file containing the Dart |
| 211 implementation class. | 209 implementation class. |
| 212 cpp_header_emitter: an Emitter for the file containing the C++ header. | 210 cpp_header_emitter: an Emitter for the file containing the C++ header. |
| 213 cpp_impl_emitter: an Emitter for the file containing the C++ | 211 cpp_impl_emitter: an Emitter for the file containing the C++ |
| 214 implementation. | 212 implementation. |
| 215 base_members: a set of names of members defined in a base class. This is | 213 base_members: a set of names of members defined in a base class. This is |
| 216 used to avoid static member 'overriding' in the generated Dart code. | 214 used to avoid static member 'overriding' in the generated Dart code. |
| 217 """ | 215 """ |
| 218 self._system = system | 216 self._system = system |
| 219 self._interface = interface | 217 self._interface = interface |
| 220 self._super_interface = super_interface | |
| 221 self._dart_impl_emitter = dart_impl_emitter | 218 self._dart_impl_emitter = dart_impl_emitter |
| 222 self._cpp_header_emitter = cpp_header_emitter | 219 self._cpp_header_emitter = cpp_header_emitter |
| 223 self._cpp_impl_emitter = cpp_impl_emitter | 220 self._cpp_impl_emitter = cpp_impl_emitter |
| 224 self._base_members = base_members | 221 self._base_members = base_members |
| 225 self._templates = templates | 222 self._templates = templates |
| 226 self._current_secondary_parent = None | 223 self._current_secondary_parent = None |
| 227 | 224 |
| 228 def StartInterface(self): | 225 def StartInterface(self): |
| 229 self._class_name = self._ImplClassName(self._interface.id) | 226 self._class_name = self._ImplClassName(self._interface.id) |
| 230 self._interface_type_info = GetIDLTypeInfo(self._interface.id) | 227 self._interface_type_info = GetIDLTypeInfo(self._interface.id) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' | 380 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' |
| 384 '{\n' | 381 '{\n' |
| 385 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' | 382 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' |
| 386 '}\n') | 383 '}\n') |
| 387 to_dart_value_emitter = emitter.Emitter() | 384 to_dart_value_emitter = emitter.Emitter() |
| 388 to_dart_value_emitter.Emit( | 385 to_dart_value_emitter.Emit( |
| 389 to_dart_value_template, | 386 to_dart_value_template, |
| 390 INTERFACE=self._interface.id, | 387 INTERFACE=self._interface.id, |
| 391 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) | 388 WEBCORE_CLASS_NAME=self._interface_type_info.native_type()) |
| 392 | 389 |
| 390 |
| 391 wrapper_type = _DOMWrapperType(self._system._database, self._interface) |
| 393 self._cpp_header_emitter.Emit( | 392 self._cpp_header_emitter.Emit( |
| 394 self._templates.Load('cpp_header.template'), | 393 self._templates.Load('cpp_header.template'), |
| 395 INTERFACE=self._interface.id, | 394 INTERFACE=self._interface.id, |
| 396 WEBCORE_INCLUDES=webcore_includes, | 395 WEBCORE_INCLUDES=webcore_includes, |
| 397 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 396 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 398 TO_DART_VALUE=to_dart_value_emitter.Fragments(), | 397 TO_DART_VALUE=to_dart_value_emitter.Fragments(), |
| 399 DECLARATIONS=self._cpp_declarations_emitter.Fragments()) | 398 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), |
| 399 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type) |
| 400 | 400 |
| 401 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum
ents): | 401 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum
ents): |
| 402 if 'CallWith' not in node.ext_attrs: | 402 if 'CallWith' not in node.ext_attrs: |
| 403 return False | 403 return False |
| 404 | 404 |
| 405 call_with = node.ext_attrs['CallWith'] | 405 call_with = node.ext_attrs['CallWith'] |
| 406 if call_with == 'ScriptExecutionContext': | 406 if call_with == 'ScriptExecutionContext': |
| 407 parameter_definitions_emitter.Emit( | 407 parameter_definitions_emitter.Emit( |
| 408 '\n' | 408 '\n' |
| 409 ' ScriptExecutionContext* context = DartUtilities::scriptExecut
ionContext();\n' | 409 ' ScriptExecutionContext* context = DartUtilities::scriptExecut
ionContext();\n' |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 831 |
| 832 if 'ImplementedBy' in attributes: | 832 if 'ImplementedBy' in attributes: |
| 833 arguments.insert(0, 'receiver') | 833 arguments.insert(0, 'receiver') |
| 834 self._cpp_impl_includes.add('"%s.h"' % attributes['ImplementedBy']) | 834 self._cpp_impl_includes.add('"%s.h"' % attributes['ImplementedBy']) |
| 835 | 835 |
| 836 return emitter.Format(invocation_template, | 836 return emitter.Format(invocation_template, |
| 837 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) | 837 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) |
| 838 | 838 |
| 839 def _GenerateCPPIncludes(includes): | 839 def _GenerateCPPIncludes(includes): |
| 840 return ''.join(['#include %s\n' % include for include in includes]) | 840 return ''.join(['#include %s\n' % include for include in includes]) |
| 841 |
| 842 def _DOMWrapperType(database, interface): |
| 843 if _InstanceOfNode(database, interface): |
| 844 return 'DOMNode' |
| 845 return 'DOMObject' |
| 846 |
| 847 def _InstanceOfNode(database, interface): |
| 848 if interface.id == 'Node': |
| 849 return True |
| 850 for parent in interface.parents: |
| 851 if not database.HasInterface(parent.type.id): |
| 852 continue |
| 853 parent_interface = database.GetInterface(parent.type.id) |
| 854 if _InstanceOfNode(database, parent_interface): |
| 855 return True |
| 856 return False |
| OLD | NEW |