Index: client/dom/scripts/dartgenerator.py |
diff --git a/client/dom/scripts/dartgenerator.py b/client/dom/scripts/dartgenerator.py |
index d0cd539e694c058a4a24ec2b0d78025c0d2929e9..ab35be1ea1f1861a7cbafd2635b51c6a53e9ffbe 100755 |
--- a/client/dom/scripts/dartgenerator.py |
+++ b/client/dom/scripts/dartgenerator.py |
@@ -2106,6 +2106,8 @@ class NativeImplementationSystem(System): |
self._auxiliary_dir = auxiliary_dir |
self._dom_public_files = [] |
self._dom_impl_files = [] |
+ self._cpp_header_files = [] |
+ self._cpp_impl_files = [] |
def InterfaceGenerator(self, |
interface, |
@@ -2120,8 +2122,16 @@ class NativeImplementationSystem(System): |
dart_impl_path = self._FilePathForDartImplementation(interface_name) |
self._dom_impl_files.append(dart_impl_path) |
+ cpp_header_path = self._FilePathForCppHeader(interface_name) |
+ self._cpp_header_files.append(cpp_header_path) |
+ |
+ cpp_impl_path = self._FilePathForCppImplementation(interface_name) |
+ self._cpp_impl_files.append(cpp_impl_path) |
+ |
return NativeImplementationGenerator(interface, super_interface_name, |
self._emitters.FileEmitter(dart_impl_path), |
+ self._emitters.FileEmitter(cpp_header_path), |
+ self._emitters.FileEmitter(cpp_impl_path), |
self._BaseDefines(interface), |
self._templates) |
@@ -2148,8 +2158,8 @@ class NativeImplementationSystem(System): |
dom_impl_path = os.path.join(self._output_dir, 'dom_impl.dart') |
dom_impl_imports_emitter = emitter.Emitter() |
- for file in self._dom_impl_files: |
- path = os.path.relpath(file, os.path.dirname(dom_impl_path)) |
+ for f in self._dom_impl_files: |
+ path = os.path.relpath(f, os.path.dirname(dom_impl_path)) |
dom_impl_imports_emitter.Emit('#source("$PATH");\n', PATH=path) |
dom_impl_emitter = self._emitters.FileEmitter(dom_impl_path) |
@@ -2157,6 +2167,39 @@ class NativeImplementationSystem(System): |
AUXILIARY_DIR=auxiliary_dir, |
SOURCES=dom_impl_imports_emitter.Fragments()) |
+ # Generate DartDerivedSourcesAll.cpp. |
+ cpp_all_in_one_path = os.path.join(self._output_dir, |
+ 'DartDerivedSourcesAll.cpp') |
+ |
+ includes_emitter = emitter.Emitter() |
+ for f in self._cpp_impl_files: |
+ path = os.path.relpath(f, os.path.dirname(cpp_all_in_one_path)) |
+ includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
+ |
+ cpp_all_in_one_emitter = self._emitters.FileEmitter(cpp_all_in_one_path) |
+ cpp_all_in_one_emitter.Emit( |
+ self._templates.Load('cpp_all_in_one.template'), |
+ INCLUDES=includes_emitter.Fragments()) |
+ |
+ # Generate DartResolver.cpp. |
+ cpp_resolver_path = os.path.join(self._output_dir, 'DartResolver.cpp') |
+ |
+ includes_emitter = emitter.Emitter() |
+ resolver_body_emitter = emitter.Emitter() |
+ for f in self._cpp_header_files: |
+ path = os.path.relpath(f, os.path.dirname(cpp_resolver_path)) |
+ includes_emitter.Emit('#include "$PATH"\n', PATH=path) |
+ resolver_body_emitter.Emit( |
+ ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argumentCount))\n' |
+ ' return func;\n', |
+ CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) |
antonm
2012/02/06 13:45:51
up to you, but I find those basename/splitext game
podivilov
2012/02/10 15:59:37
not really...
|
+ |
+ cpp_resolver_emitter = self._emitters.FileEmitter(cpp_resolver_path) |
+ cpp_resolver_emitter.Emit( |
+ self._templates.Load('cpp_resolver.template'), |
+ INCLUDES=includes_emitter.Fragments(), |
+ RESOLVER_BODY=resolver_body_emitter.Fragments()) |
+ |
def Finish(self): |
pass |
@@ -2168,13 +2211,20 @@ class NativeImplementationSystem(System): |
return os.path.join(self._output_dir, 'dart', |
'%sImplementation.dart' % interface_name) |
+ def _FilePathForCppHeader(self, interface_name): |
+ return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name) |
+ |
+ def _FilePathForCppImplementation(self, interface_name): |
+ return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name) |
+ |
class NativeImplementationGenerator(WrappingInterfaceGenerator): |
"""Generates Dart implementation for one DOM IDL interface.""" |
- def __init__(self, interface, super_interface, dart_impl_emitter, |
+ def __init__(self, interface, super_interface, |
+ dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter, |
base_members, templates): |
- """Generates Dart code for the given interface. |
+ """Generates Dart and c++ code for the given interface. |
antonm
2012/02/06 13:45:51
nit: C++
podivilov
2012/02/10 15:59:37
Done.
|
Args: |
@@ -2185,12 +2235,17 @@ class NativeImplementationGenerator(WrappingInterfaceGenerator): |
this interface implements, if any. |
dart_impl_emitter: an Emitter for the file containing the Dart |
implementation class. |
+ cpp_header_emitter: an Emitter for the file containing the c++ header. |
antonm
2012/02/06 13:45:51
again (here and below), C++ imho is preferred.
podivilov
2012/02/10 15:59:37
Done.
|
+ cpp_impl_emitter: an Emitter for the file containing the c++ |
+ implementation. |
base_members: a set of names of members defined in a base class. This is |
used to avoid static member 'overriding' in the generated Dart code. |
""" |
self._interface = interface |
self._super_interface = super_interface |
self._dart_impl_emitter = dart_impl_emitter |
+ self._cpp_header_emitter = cpp_header_emitter |
+ self._cpp_impl_emitter = cpp_impl_emitter |
self._base_members = base_members |
self._templates = templates |
self._current_secondary_parent = None |
@@ -2199,19 +2254,24 @@ class NativeImplementationGenerator(WrappingInterfaceGenerator): |
self._class_name = self._ImplClassName(self._interface.id) |
self._members_emitter = emitter.Emitter() |
- def _ImplClassName(self, type_name): |
- return type_name + 'Implementation' |
+ def _ImplClassName(self, interface_name): |
+ return interface_name + 'Implementation' |
def FinishInterface(self): |
- interface = self._interface |
- interface_name = interface.id |
- |
- base = self._BaseClassName(interface) |
+ base = self._BaseClassName(self._interface) |
self._dart_impl_emitter.Emit( |
self._templates.Load('dart_implementation.darttemplate'), |
- CLASS=self._class_name, BASE=base, INTERFACE=interface_name, |
+ CLASS=self._class_name, BASE=base, INTERFACE=self._interface.id, |
MEMBERS=self._members_emitter.Fragments()) |
+ self._cpp_header_emitter.Emit( |
+ self._templates.Load('cpp_header.template'), |
+ INTERFACE=self._interface.id) |
+ |
+ self._cpp_impl_emitter.Emit( |
+ self._templates.Load('cpp_implementation.template'), |
+ INTERFACE=self._interface.id) |
+ |
def AddAttribute(self, getter, setter): |
if getter: |
self._AddGetter(getter) |