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

Side by Side Diff: lib/dom/scripts/systemnative.py

Issue 10155027: Support custom to native conversions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/dom/scripts/generator.py ('k') | lib/dom/templates/dom/native/cpp_header.template » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 self._GenerateCppHeader() 373 self._GenerateCppHeader()
374 374
375 self._cpp_impl_emitter.Emit( 375 self._cpp_impl_emitter.Emit(
376 self._templates.Load('cpp_implementation.template'), 376 self._templates.Load('cpp_implementation.template'),
377 INTERFACE=self._interface.id, 377 INTERFACE=self._interface.id,
378 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes), 378 INCLUDES=_GenerateCPPIncludes(self._cpp_impl_includes),
379 CALLBACKS=self._cpp_definitions_emitter.Fragments(), 379 CALLBACKS=self._cpp_definitions_emitter.Fragments(),
380 RESOLVER=self._cpp_resolver_emitter.Fragments()) 380 RESOLVER=self._cpp_resolver_emitter.Fragments())
381 381
382 def _GenerateCppHeader(self): 382 def _GenerateCppHeader(self):
383 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes()) 383 to_native_template = ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_Handle& exception)'
384 if self._interface_type_info.custom_to_native():
385 to_native_template += ';\n'
386 else:
387 to_native_template += (
388 '\n'
389 ' {\n'
390 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand le, exception);\n'
391 ' }\n')
384 392
385 if ('CustomToJS' in self._interface.ext_attrs or 393 if ('CustomToJS' in self._interface.ext_attrs or
386 'CustomToJSObject' in self._interface.ext_attrs or 394 'CustomToJSObject' in self._interface.ext_attrs or
387 'PureInterface' in self._interface.ext_attrs or 395 'PureInterface' in self._interface.ext_attrs or
388 'CPPPureInterface' in self._interface.ext_attrs or 396 'CPPPureInterface' in self._interface.ext_attrs or
389 self._interface_type_info.custom_to_dart()): 397 self._interface_type_info.custom_to_dart()):
390 to_dart_value_template = ( 398 to_dart_template = (
391 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n') 399 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n')
392 else: 400 else:
393 to_dart_value_template = ( 401 to_dart_template = (
394 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' 402 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n'
395 '{\n' 403 '{\n'
396 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 404 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n'
397 '}\n') 405 '}\n')
398 to_dart_value_emitter = emitter.Emitter()
399 to_dart_value_emitter.Emit(
400 to_dart_value_template,
401 INTERFACE=self._interface.id,
402 WEBCORE_CLASS_NAME=self._interface_type_info.native_type())
403 406
407 intermediate_emitter = emitter.Emitter()
Anton Muhin 2012/04/24 14:05:51 this two level emitting might be too much. Maybe
podivilov 2012/04/24 14:30:33 Done.
408 intermediate_emitter.Emit(
409 self._templates.Load('cpp_header.template'),
410 TO_NATIVE=to_native_template,
411 TO_DART=to_dart_template)
404 412
413 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes())
405 wrapper_type = _DOMWrapperType(self._system._database, self._interface) 414 wrapper_type = _DOMWrapperType(self._system._database, self._interface)
406 self._cpp_header_emitter.Emit( 415 self._cpp_header_emitter.Emit(
407 self._templates.Load('cpp_header.template'), 416 ''.join(intermediate_emitter.Fragments()),
408 INTERFACE=self._interface.id, 417 INTERFACE=self._interface.id,
409 WEBCORE_INCLUDES=webcore_includes, 418 WEBCORE_INCLUDES=webcore_includes,
410 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 419 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
411 TO_DART_VALUE=to_dart_value_emitter.Fragments(),
412 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), 420 DECLARATIONS=self._cpp_declarations_emitter.Fragments(),
413 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type) 421 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type)
414 422
415 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum ents): 423 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum ents):
416 if 'CallWith' not in node.ext_attrs: 424 if 'CallWith' not in node.ext_attrs:
417 return False 425 return False
418 426
419 call_with = node.ext_attrs['CallWith'] 427 call_with = node.ext_attrs['CallWith']
420 if call_with == 'ScriptExecutionContext': 428 if call_with == 'ScriptExecutionContext':
421 parameter_definitions_emitter.Emit( 429 parameter_definitions_emitter.Emit(
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 def _InstanceOfNode(database, interface): 846 def _InstanceOfNode(database, interface):
839 if interface.id == 'Node': 847 if interface.id == 'Node':
840 return True 848 return True
841 for parent in interface.parents: 849 for parent in interface.parents:
842 if not database.HasInterface(parent.type.id): 850 if not database.HasInterface(parent.type.id):
843 continue 851 continue
844 parent_interface = database.GetInterface(parent.type.id) 852 parent_interface = database.GetInterface(parent.type.id)
845 if _InstanceOfNode(database, parent_interface): 853 if _InstanceOfNode(database, parent_interface):
846 return True 854 return True
847 return False 855 return False
OLDNEW
« no previous file with comments | « lib/dom/scripts/generator.py ('k') | lib/dom/templates/dom/native/cpp_header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698