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

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

Issue 10331015: Remove ParameterAdapters for bindings classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Emit to native conversion in virtual method. Created 8 years, 7 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 | « no previous file | lib/dom/scripts/systemnative.py » ('j') | lib/dom/scripts/systemnative.py » ('J')
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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import re 9 import re
10 10
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 436
437 def idl_type(self): 437 def idl_type(self):
438 return self._idl_type 438 return self._idl_type
439 439
440 def dart_type(self): 440 def dart_type(self):
441 return self._dart_type or self._idl_type 441 return self._dart_type or self._idl_type
442 442
443 def native_type(self): 443 def native_type(self):
444 return self._native_type or self._idl_type 444 return self._native_type or self._idl_type
445 445
446 def parameter_adapter_info(self): 446 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
447 adapter_type = 'ParameterAdapter<Dart%s>' % self._idl_type 447 if 'Callback' in idl_node.ext_attrs:
448 include = '"Dart%s.h"' % self._idl_type 448 if 'RequiredCppParameter' in idl_node.ext_attrs:
449 return (adapter_type, include) 449 flag = 'DartUtilities::ConvertNullToDefaultValue'
450 else:
451 flag = 'DartUtilities::ConvertNone'
452 emitter.Emit(
453 '\n'
454 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc eption);\n'
455 ' if (exception)\n'
456 ' goto fail;\n',
457 TYPE=self.native_type(),
458 NAME=name,
459 IDL_TYPE=self.idl_type(),
460 HANDLE=handle,
461 FLAG=flag)
462 return name
463
464 argument = name
465 if self.custom_to_native():
466 type = 'RefPtr<%s>' % self.native_type()
467 argument = '%s.get()' % name
468 else:
469 type = '%s*' % self.native_type()
470 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'):
471 argument = '%s->propertyReference()' % name
472 emitter.Emit(
473 '\n'
474 ' $TYPE $NAME = Dart$IDL_TYPE::toNative($HANDLE, exception);\n'
475 ' if (exception)\n'
476 ' goto fail;\n',
477 TYPE=type,
478 NAME=name,
479 IDL_TYPE=self.idl_type(),
480 HANDLE=handle)
481 return argument
450 482
451 def custom_to_native(self): 483 def custom_to_native(self):
452 return self._custom_to_native 484 return self._custom_to_native
453 485
454 def parameter_type(self): 486 def parameter_type(self):
455 return '%s*' % self.native_type() 487 return '%s*' % self.native_type()
456 488
457 def webcore_includes(self): 489 def webcore_includes(self):
458 WTF_INCLUDES = [ 490 WTF_INCLUDES = [
459 'ArrayBuffer', 491 'ArrayBuffer',
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 545
514 class PrimitiveIDLTypeInfo(IDLTypeInfo): 546 class PrimitiveIDLTypeInfo(IDLTypeInfo):
515 def __init__(self, idl_type, dart_type, native_type=None, 547 def __init__(self, idl_type, dart_type, native_type=None,
516 webcore_getter_name='getAttribute', 548 webcore_getter_name='getAttribute',
517 webcore_setter_name='setAttribute'): 549 webcore_setter_name='setAttribute'):
518 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, 550 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type,
519 native_type=native_type) 551 native_type=native_type)
520 self._webcore_getter_name = webcore_getter_name 552 self._webcore_getter_name = webcore_getter_name
521 self._webcore_setter_name = webcore_setter_name 553 self._webcore_setter_name = webcore_setter_name
522 554
523 def parameter_adapter_info(self): 555 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
524 adapter_type = 'ParameterAdapter<%s>' % self.native_type() 556 arguments = [handle]
525 return (adapter_type, None) 557 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or 'RequiredC ppParameter' in idl_node.ext_attrs:
558 arguments.append('DartUtilities::ConvertNullToDefaultValue')
559 emitter.Emit(
560 '\n'
561 ' const ParameterAdapter<$TYPE> $NAME($ARGUMENTS);\n'
562 ' if (!$NAME.conversionSuccessful()) {\n'
563 ' exception = $NAME.exception();\n'
564 ' goto fail;\n'
565 ' }\n',
566 TYPE=self.native_type(),
567 NAME=name,
568 ARGUMENTS=', '.join(arguments))
569 return name
526 570
527 def parameter_type(self): 571 def parameter_type(self):
528 if self.native_type() == 'String': 572 if self.native_type() == 'String':
529 return 'const String&' 573 return 'const String&'
530 return self.native_type() 574 return self.native_type()
531 575
532 def conversion_includes(self): 576 def conversion_includes(self):
533 return [] 577 return []
534 578
535 def to_dart_conversion(self, value, interface_name=None, attributes=None): 579 def to_dart_conversion(self, value, interface_name=None, attributes=None):
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'), 678 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'),
635 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust om_to_native=True), 679 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust om_to_native=True),
636 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') , 680 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') ,
637 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), 681 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True),
638 'Element': IDLTypeInfo('Element', custom_to_dart=True), 682 'Element': IDLTypeInfo('Element', custom_to_dart=True),
639 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), 683 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True),
640 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), 684 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True),
641 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), 685 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True),
642 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), 686 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True),
643 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), 687 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True),
644 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', custom_to_na tive=True),
645 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]), 688 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]),
646 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), 689 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True),
647 690
648 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), 691 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'),
649 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), 692 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'),
650 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList'), 693 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList'),
651 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), 694 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'),
652 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'), 695 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'),
653 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList'), 696 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList'),
654 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa thSegListPropertyTearOff'), 697 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa thSegListPropertyTearOff'),
(...skipping 13 matching lines...) Expand all
668 '"SVGAnimatedListPropertyTearOff.h"', 711 '"SVGAnimatedListPropertyTearOff.h"',
669 '"SVGTransformListPropertyTearOff.h"', 712 '"SVGTransformListPropertyTearOff.h"',
670 '"SVGPathSegListPropertyTearOff.h"', 713 '"SVGPathSegListPropertyTearOff.h"',
671 ] 714 ]
672 715
673 def GetIDLTypeInfo(idl_type_name): 716 def GetIDLTypeInfo(idl_type_name):
674 match = re.match(r'sequence<(\w+)>$', idl_type_name) 717 match = re.match(r'sequence<(\w+)>$', idl_type_name)
675 if match: 718 if match:
676 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 719 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1)))
677 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) 720 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name))
OLDNEW
« no previous file with comments | « no previous file | lib/dom/scripts/systemnative.py » ('j') | lib/dom/scripts/systemnative.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698