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

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: . 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') | 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 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 441
442 def idl_type(self): 442 def idl_type(self):
443 return self._idl_type 443 return self._idl_type
444 444
445 def dart_type(self): 445 def dart_type(self):
446 return self._dart_type or self._idl_type 446 return self._dart_type or self._idl_type
447 447
448 def native_type(self): 448 def native_type(self):
449 return self._native_type or self._idl_type 449 return self._native_type or self._idl_type
450 450
451 def parameter_adapter_info(self): 451 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
452 adapter_type = 'ParameterAdapter<Dart%s>' % self._idl_type 452 if 'Callback' in idl_node.ext_attrs:
453 include = '"Dart%s.h"' % self._idl_type 453 if 'RequiredCppParameter' in idl_node.ext_attrs:
454 return (adapter_type, include) 454 flag = 'DartUtilities::ConvertNullToDefaultValue'
455 else:
456 flag = 'DartUtilities::ConvertNone'
457 emitter.Emit(
458 '\n'
459 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc eption);\n'
460 ' if (exception)\n'
461 ' goto fail;\n',
462 TYPE=self.native_type(),
463 NAME=name,
464 IDL_TYPE=self.idl_type(),
465 HANDLE=handle,
466 FLAG=flag)
467 return name
468
469 argument = name
470 if self.custom_to_native():
471 type = 'RefPtr<%s>' % self.native_type()
472 argument = '%s.get()' % name
473 else:
474 type = '%s*' % self.native_type()
475 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'):
476 argument = '%s->propertyReference()' % name
477 emitter.Emit(
478 '\n'
479 ' $TYPE $NAME = Dart$IDL_TYPE::toNative($HANDLE, exception);\n'
480 ' if (exception)\n'
481 ' goto fail;\n',
482 TYPE=type,
483 NAME=name,
484 IDL_TYPE=self.idl_type(),
485 HANDLE=handle)
486 return argument
455 487
456 def custom_to_native(self): 488 def custom_to_native(self):
457 return self._custom_to_native 489 return self._custom_to_native
458 490
459 def parameter_type(self): 491 def parameter_type(self):
460 return '%s*' % self.native_type() 492 return '%s*' % self.native_type()
461 493
462 def webcore_includes(self): 494 def webcore_includes(self):
463 WTF_INCLUDES = [ 495 WTF_INCLUDES = [
464 'ArrayBuffer', 496 'ArrayBuffer',
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 550
519 class PrimitiveIDLTypeInfo(IDLTypeInfo): 551 class PrimitiveIDLTypeInfo(IDLTypeInfo):
520 def __init__(self, idl_type, dart_type, native_type=None, 552 def __init__(self, idl_type, dart_type, native_type=None,
521 webcore_getter_name='getAttribute', 553 webcore_getter_name='getAttribute',
522 webcore_setter_name='setAttribute'): 554 webcore_setter_name='setAttribute'):
523 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, 555 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type,
524 native_type=native_type) 556 native_type=native_type)
525 self._webcore_getter_name = webcore_getter_name 557 self._webcore_getter_name = webcore_getter_name
526 self._webcore_setter_name = webcore_setter_name 558 self._webcore_setter_name = webcore_setter_name
527 559
528 def parameter_adapter_info(self): 560 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
529 adapter_type = 'ParameterAdapter<%s>' % self.native_type() 561 arguments = [handle]
530 return (adapter_type, None) 562 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or 'RequiredC ppParameter' in idl_node.ext_attrs:
563 arguments.append('DartUtilities::ConvertNullToDefaultValue')
564 emitter.Emit(
565 '\n'
566 ' const ParameterAdapter<$TYPE> $NAME($ARGUMENTS);\n'
567 ' if (!$NAME.conversionSuccessful()) {\n'
568 ' exception = $NAME.exception();\n'
569 ' goto fail;\n'
570 ' }\n',
571 TYPE=self.native_type(),
572 NAME=name,
573 ARGUMENTS=', '.join(arguments))
574 return name
531 575
532 def parameter_type(self): 576 def parameter_type(self):
533 if self.native_type() == 'String': 577 if self.native_type() == 'String':
534 return 'const String&' 578 return 'const String&'
535 return self.native_type() 579 return self.native_type()
536 580
537 def conversion_includes(self): 581 def conversion_includes(self):
538 return [] 582 return []
539 583
540 def to_dart_conversion(self, value, interface_name=None, attributes=None): 584 def to_dart_conversion(self, value, interface_name=None, attributes=None):
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'), 683 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'),
640 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust om_to_native=True), 684 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust om_to_native=True),
641 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') , 685 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') ,
642 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), 686 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True),
643 'Element': IDLTypeInfo('Element', custom_to_dart=True), 687 'Element': IDLTypeInfo('Element', custom_to_dart=True),
644 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), 688 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True),
645 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), 689 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True),
646 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), 690 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True),
647 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), 691 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True),
648 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), 692 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True),
649 'MediaQueryListListener': IDLTypeInfo('MediaQueryListListener', custom_to_na tive=True),
650 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]), 693 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]),
651 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True), 694 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True),
652 695
653 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), 696 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'),
654 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), 697 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'),
655 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList'), 698 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList'),
656 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), 699 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'),
657 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'), 700 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'),
658 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList'), 701 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList'),
659 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa thSegListPropertyTearOff'), 702 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa thSegListPropertyTearOff'),
(...skipping 13 matching lines...) Expand all
673 '"SVGAnimatedListPropertyTearOff.h"', 716 '"SVGAnimatedListPropertyTearOff.h"',
674 '"SVGTransformListPropertyTearOff.h"', 717 '"SVGTransformListPropertyTearOff.h"',
675 '"SVGPathSegListPropertyTearOff.h"', 718 '"SVGPathSegListPropertyTearOff.h"',
676 ] 719 ]
677 720
678 def GetIDLTypeInfo(idl_type_name): 721 def GetIDLTypeInfo(idl_type_name):
679 match = re.match(r'sequence<(\w+)>$', idl_type_name) 722 match = re.match(r'sequence<(\w+)>$', idl_type_name)
680 if match: 723 if match:
681 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 724 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1)))
682 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) 725 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698