| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 ' DartIsolateScope scope(m_callback.isolate());\n' | 73 ' DartIsolateScope scope(m_callback.isolate());\n' |
| 74 ' DartApiScope apiScope;\n' | 74 ' DartApiScope apiScope;\n' |
| 75 ' $ARGUMENTS_DECLARATION;\n' | 75 ' $ARGUMENTS_DECLARATION;\n' |
| 76 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' | 76 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n' |
| 77 '}\n', | 77 '}\n', |
| 78 CLASS_NAME=class_name, | 78 CLASS_NAME=class_name, |
| 79 PARAMETERS=', '.join(parameters), | 79 PARAMETERS=', '.join(parameters), |
| 80 ARGUMENTS_DECLARATION=arguments_declaration, | 80 ARGUMENTS_DECLARATION=arguments_declaration, |
| 81 ARGUMENT_COUNT=len(arguments)) | 81 ARGUMENT_COUNT=len(arguments)) |
| 82 | 82 |
| 83 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(self._int
erface.id, True) | 83 cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter( |
| 84 self._interface.id, |
| 85 self._renamer.GetLibraryName(self._interface), |
| 86 True) |
| 84 cpp_header_emitter.Emit( | 87 cpp_header_emitter.Emit( |
| 85 self._template_loader.Load('cpp_callback_header.template'), | 88 self._template_loader.Load('cpp_callback_header.template'), |
| 86 INTERFACE=self._interface.id, | 89 INTERFACE=self._interface.id, |
| 87 HANDLERS=cpp_header_handlers_emitter.Fragments()) | 90 HANDLERS=cpp_header_handlers_emitter.Fragments()) |
| 88 | 91 |
| 89 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter
face.id) | 92 cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(self._inter
face.id) |
| 90 cpp_impl_emitter.Emit( | 93 cpp_impl_emitter.Emit( |
| 91 self._template_loader.Load('cpp_callback_implementation.template'), | 94 self._template_loader.Load('cpp_callback_implementation.template'), |
| 92 INCLUDES=self._GenerateCPPIncludes(cpp_impl_includes), | 95 INCLUDES=self._GenerateCPPIncludes(cpp_impl_includes), |
| 93 INTERFACE=self._interface.id, | 96 INTERFACE=self._interface.id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 105 | 108 |
| 106 def RootClassName(self): | 109 def RootClassName(self): |
| 107 return 'NativeFieldWrapperClass1' | 110 return 'NativeFieldWrapperClass1' |
| 108 | 111 |
| 109 def NativeSpec(self): | 112 def NativeSpec(self): |
| 110 return '' | 113 return '' |
| 111 | 114 |
| 112 def StartInterface(self, memebers_emitter): | 115 def StartInterface(self, memebers_emitter): |
| 113 # Create emitters for c++ implementation. | 116 # Create emitters for c++ implementation. |
| 114 if not IsPureInterface(self._interface.id): | 117 if not IsPureInterface(self._interface.id): |
| 115 self._cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter(s
elf._interface.id) | 118 self._cpp_header_emitter = self._cpp_library_emitter.CreateHeaderEmitter( |
| 119 self._interface.id, |
| 120 self._renamer.GetLibraryName(self._interface)) |
| 116 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel
f._interface.id) | 121 self._cpp_impl_emitter = self._cpp_library_emitter.CreateSourceEmitter(sel
f._interface.id) |
| 117 else: | 122 else: |
| 118 self._cpp_header_emitter = emitter.Emitter() | 123 self._cpp_header_emitter = emitter.Emitter() |
| 119 self._cpp_impl_emitter = emitter.Emitter() | 124 self._cpp_impl_emitter = emitter.Emitter() |
| 120 | 125 |
| 121 self._interface_type_info = self._TypeInfo(self._interface.id) | 126 self._interface_type_info = self._TypeInfo(self._interface.id) |
| 122 self._members_emitter = memebers_emitter | 127 self._members_emitter = memebers_emitter |
| 123 self._cpp_declarations_emitter = emitter.Emitter() | 128 self._cpp_declarations_emitter = emitter.Emitter() |
| 124 self._cpp_impl_includes = set() | 129 self._cpp_impl_includes = set() |
| 125 self._cpp_definitions_emitter = emitter.Emitter() | 130 self._cpp_definitions_emitter = emitter.Emitter() |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 return self._type_registry.TypeInfo(type_name) | 860 return self._type_registry.TypeInfo(type_name) |
| 856 | 861 |
| 857 def _DartType(self, type_name): | 862 def _DartType(self, type_name): |
| 858 return self._type_registry.DartType(type_name) | 863 return self._type_registry.DartType(type_name) |
| 859 | 864 |
| 860 | 865 |
| 861 class CPPLibraryEmitter(): | 866 class CPPLibraryEmitter(): |
| 862 def __init__(self, emitters, cpp_sources_dir): | 867 def __init__(self, emitters, cpp_sources_dir): |
| 863 self._emitters = emitters | 868 self._emitters = emitters |
| 864 self._cpp_sources_dir = cpp_sources_dir | 869 self._cpp_sources_dir = cpp_sources_dir |
| 865 self._headers_list = [] | 870 self._library_headers = {} |
| 866 self._sources_list = [] | 871 self._sources_list = [] |
| 867 | 872 |
| 868 def CreateHeaderEmitter(self, interface_name, is_callback=False): | 873 def CreateHeaderEmitter(self, interface_name, library_name, is_callback=False)
: |
| 869 path = os.path.join(self._cpp_sources_dir, 'Dart%s.h' % interface_name) | 874 path = os.path.join(self._cpp_sources_dir, 'Dart%s.h' % interface_name) |
| 870 if not is_callback: | 875 if not is_callback: |
| 871 self._headers_list.append(path) | 876 if not library_name in self._library_headers: |
| 877 self._library_headers[library_name] = [] |
| 878 self._library_headers[library_name].append(path) |
| 872 return self._emitters.FileEmitter(path) | 879 return self._emitters.FileEmitter(path) |
| 873 | 880 |
| 874 def CreateSourceEmitter(self, interface_name): | 881 def CreateSourceEmitter(self, interface_name): |
| 875 path = os.path.join(self._cpp_sources_dir, 'Dart%s.cpp' % interface_name) | 882 path = os.path.join(self._cpp_sources_dir, 'Dart%s.cpp' % interface_name) |
| 876 self._sources_list.append(path) | 883 self._sources_list.append(path) |
| 877 return self._emitters.FileEmitter(path) | 884 return self._emitters.FileEmitter(path) |
| 878 | 885 |
| 879 def EmitDerivedSources(self, template, output_dir): | 886 def EmitDerivedSources(self, template, output_dir): |
| 880 partitions = 20 # FIXME: this should be configurable. | 887 partitions = 20 # FIXME: this should be configurable. |
| 881 sources_count = len(self._sources_list) | 888 sources_count = len(self._sources_list) |
| 882 for i in range(0, partitions): | 889 for i in range(0, partitions): |
| 883 file_path = os.path.join(output_dir, 'DartDerivedSources%02i.cpp' % (i + 1
)) | 890 file_path = os.path.join(output_dir, 'DartDerivedSources%02i.cpp' % (i + 1
)) |
| 884 includes_emitter = self._emitters.FileEmitter(file_path).Emit(template) | 891 includes_emitter = self._emitters.FileEmitter(file_path).Emit(template) |
| 885 for source_file in self._sources_list[i::partitions]: | 892 for source_file in self._sources_list[i::partitions]: |
| 886 path = os.path.relpath(source_file, output_dir) | 893 path = os.path.relpath(source_file, output_dir) |
| 887 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 894 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 888 | 895 |
| 889 def EmitResolver(self, template, output_dir): | 896 def EmitResolver(self, template, output_dir): |
| 890 file_path = os.path.join(output_dir, 'DartResolver.cpp') | 897 for library_name in self._library_headers.keys(): |
| 891 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit(
template) | 898 file_path = os.path.join(output_dir, '%s_DartResolver.cpp' % library_name) |
| 892 for header_file in self._headers_list: | 899 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emi
t( |
| 893 path = os.path.relpath(header_file, output_dir) | 900 template, |
| 894 includes_emitter.Emit('#include "$PATH"\n', PATH=path) | 901 LIBRARY_NAME=library_name) |
| 895 body_emitter.Emit( | 902 |
| 896 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume
ntCount))\n' | 903 headers = self._library_headers[library_name] |
| 897 ' return func;\n', | 904 for header_file in headers: |
| 898 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) | 905 path = os.path.relpath(header_file, output_dir) |
| 906 includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
| 907 body_emitter.Emit( |
| 908 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argu
mentCount))\n' |
| 909 ' return func;\n', |
| 910 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
| OLD | NEW |