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

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_emitter = emitter.Emitter()
384 if self._interface_type_info.custom_to_native():
385 to_native_emitter.Emit(
386 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception);\n')
387 else:
388 to_native_emitter.Emit(
389 ' static PassRefPtr<NativeType> toNative(Dart_Handle handle, Dart_H andle& exception)\n'
390 ' {\n'
391 ' return DartDOMWrapper::unwrapDartWrapper<Dart$INTERFACE>(hand le, exception);\n'
392 ' }\n',
393 INTERFACE=self._interface.id)
384 394
395 to_dart_emitter = emitter.Emitter()
385 if ('CustomToJS' in self._interface.ext_attrs or 396 if ('CustomToJS' in self._interface.ext_attrs or
386 'CustomToJSObject' in self._interface.ext_attrs or 397 'CustomToJSObject' in self._interface.ext_attrs or
387 'PureInterface' in self._interface.ext_attrs or 398 'PureInterface' in self._interface.ext_attrs or
388 'CPPPureInterface' in self._interface.ext_attrs or 399 'CPPPureInterface' in self._interface.ext_attrs or
389 self._interface_type_info.custom_to_dart()): 400 self._interface_type_info.custom_to_dart()):
390 to_dart_value_template = ( 401 to_dart_emitter.Emit(
391 'Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value);\n') 402 'Dart_Handle toDartValue(Dart$(INTERFACE)::NativeType* value);\n',
403 INTERFACE=self._interface.id)
392 else: 404 else:
393 to_dart_value_template = ( 405 to_dart_emitter.Emit(
394 'inline Dart_Handle toDartValue($(WEBCORE_CLASS_NAME)* value)\n' 406 'inline Dart_Handle toDartValue(Dart$(INTERFACE)::NativeType* value)\n '
395 '{\n' 407 '{\n'
396 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' 408 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n'
397 '}\n') 409 '}\n',
398 to_dart_value_emitter = emitter.Emitter() 410 INTERFACE=self._interface.id)
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 411
404 412 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in cludes())
405 wrapper_type = _DOMWrapperType(self._system._database, self._interface) 413 wrapper_type = _DOMWrapperType(self._system._database, self._interface)
406 self._cpp_header_emitter.Emit( 414 self._cpp_header_emitter.Emit(
407 self._templates.Load('cpp_header.template'), 415 self._templates.Load('cpp_header.template'),
408 INTERFACE=self._interface.id, 416 INTERFACE=self._interface.id,
409 WEBCORE_INCLUDES=webcore_includes, 417 WEBCORE_INCLUDES=webcore_includes,
410 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 418 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(), 419 DECLARATIONS=self._cpp_declarations_emitter.Fragments(),
413 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type) 420 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type,
421 TO_NATIVE=to_native_emitter.Fragments(),
422 TO_DART=to_dart_emitter.Fragments())
414 423
415 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum ents): 424 def _GenerateCallWithHandling(self, node, parameter_definitions_emitter, argum ents):
416 if 'CallWith' not in node.ext_attrs: 425 if 'CallWith' not in node.ext_attrs:
417 return False 426 return False
418 427
419 call_with = node.ext_attrs['CallWith'] 428 call_with = node.ext_attrs['CallWith']
420 if call_with == 'ScriptExecutionContext': 429 if call_with == 'ScriptExecutionContext':
421 parameter_definitions_emitter.Emit( 430 parameter_definitions_emitter.Emit(
422 '\n' 431 '\n'
423 ' ScriptExecutionContext* context = DartUtilities::scriptExecut ionContext();\n' 432 ' ScriptExecutionContext* context = DartUtilities::scriptExecut ionContext();\n'
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 def _InstanceOfNode(database, interface): 847 def _InstanceOfNode(database, interface):
839 if interface.id == 'Node': 848 if interface.id == 'Node':
840 return True 849 return True
841 for parent in interface.parents: 850 for parent in interface.parents:
842 if not database.HasInterface(parent.type.id): 851 if not database.HasInterface(parent.type.id):
843 continue 852 continue
844 parent_interface = database.GetInterface(parent.type.id) 853 parent_interface = database.GetInterface(parent.type.id)
845 if _InstanceOfNode(database, parent_interface): 854 if _InstanceOfNode(database, parent_interface):
846 return True 855 return True
847 return False 856 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