Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: client/dom/scripts/dartgenerator.py

Issue 9316096: Draft implementation of c++ bindings generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/dom/scripts/dartgenerator.py
diff --git a/client/dom/scripts/dartgenerator.py b/client/dom/scripts/dartgenerator.py
index 2ee96e18de573cb33dfca8b746274d5c00143dea..69165434b7f0c26bc5cae2f98c5ca914f409c2c5 100755
--- a/client/dom/scripts/dartgenerator.py
+++ b/client/dom/scripts/dartgenerator.py
@@ -2077,6 +2077,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,
@@ -2091,8 +2093,18 @@ class NativeImplementationSystem(System):
dart_impl_path = self._FilePathForDartImplementation(interface_name)
self._dom_impl_files.append(dart_impl_path)
+ cpp_header_path = os.path.join(self._output_dir, 'cpp',
+ 'Dart%s.h' % interface_name)
+ self._cpp_header_files.append(cpp_header_path)
+
+ cpp_impl_path = os.path.join(self._output_dir, 'cpp',
antonm 2012/02/03 14:03:06 nit: maybe introduce a helper a la _FilePathForDar
podivilov 2012/02/06 13:24:36 Done.
+ 'Dart%s.cpp' % 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)
@@ -2128,6 +2140,39 @@ class NativeImplementationSystem(System):
AUXILIARY_DIR=auxiliary_dir,
SOURCES=dom_impl_imports_emitter.Fragments())
+ # Generate DartDerivedSourcesAll.cpp
antonm 2012/02/03 14:03:06 nit: missing trailing dot.
podivilov 2012/02/06 13:24:36 Done.
+ cpp_all_in_one_path = os.path.join(self._output_dir,
+ 'DartDerivedSourcesAll.cpp')
+
+ includes_emitter = emitter.Emitter()
+ for file in self._cpp_impl_files:
+ path = os.path.relpath(file, os.path.dirname(cpp_all_in_one_path))
antonm 2012/02/03 14:03:06 nit: two-space indent for control flow.
podivilov 2012/02/06 13:24:36 Done.
+ includes_emitter.Emit('#include "$PATH"\n', PATH=path)
antonm 2012/02/03 14:03:06 what about ENABLE_ features? Do you have filters
podivilov 2012/02/06 13:24:36 Disabled interfaces and operations are removed by
+
+ 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'),
sra1 2012/02/03 21:30:49 Instead of using Fragments to build and substitute
podivilov 2012/02/06 13:24:36 Not using template holes was a conscious decision
+ INCLUDES=includes_emitter.Fragments())
antonm 2012/02/03 14:03:06 just curious, I don't know if the templating syste
sra1 2012/02/03 21:30:49 Lets spend a few minutes talking about the templat
+
+ # Generate DartResolver.cpp
+ cpp_resolver_path = os.path.join(self._output_dir, 'DartResolver.cpp')
+
+ includes_emitter = emitter.Emitter()
+ resolver_body_emitter = emitter.Emitter()
+ for file in self._cpp_header_files:
antonm 2012/02/03 14:03:06 file is a synonym for open in Python and it's usua
podivilov 2012/02/06 13:24:36 Done.
+ path = os.path.relpath(file, 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'
antonm 2012/02/03 14:03:06 multiline literal?
podivilov 2012/02/06 13:24:36 Multiline literals break indentation rules and mak
+ ' return func;\n',
+ CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
antonm 2012/02/03 14:03:06 hrr, do not we have it stored somewhere already?
+
+ 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())
sra1 2012/02/03 21:30:49 See above comment about using 'holes'. Start reso
+
def Finish(self):
pass
@@ -2143,9 +2188,10 @@ class NativeImplementationSystem(System):
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.
Args:
@@ -2156,12 +2202,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.
+ 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
@@ -2170,19 +2221,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 AddGetter(self, attr):
self._members_emitter.Emit(
'\n'

Powered by Google App Engine
This is Rietveld 408576698