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

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

Issue 10829037: Unify null treatment. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 copy 9 import copy
10 import re 10 import re
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 return self._data.dart_type or self._idl_type 478 return self._data.dart_type or self._idl_type
479 479
480 def native_type(self): 480 def native_type(self):
481 return self._data.native_type or self._idl_type 481 return self._data.native_type or self._idl_type
482 482
483 def requires_v8_scope(self): 483 def requires_v8_scope(self):
484 return self._data.requires_v8_scope 484 return self._data.requires_v8_scope
485 485
486 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa ce_name): 486 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa ce_name):
487 if 'Callback' in idl_node.ext_attrs: 487 if 'Callback' in idl_node.ext_attrs:
488 function_name = 'create'
488 if accept_null: 489 if accept_null:
489 flag = 'DartUtilities::ConvertNullToDefaultValue' 490 function_name += 'WithNullCheck'
490 else:
491 flag = 'DartUtilities::ConvertNone'
492 emitter.Emit( 491 emitter.Emit(
493 '\n' 492 '\n'
494 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc eption);\n' 493 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::$FUNCTION_NAME($HANDLE, ex ception);\n'
495 ' if (exception)\n' 494 ' if (exception)\n'
496 ' goto fail;\n', 495 ' goto fail;\n',
497 TYPE=self.native_type(), 496 TYPE=self.native_type(),
498 NAME=name, 497 NAME=name,
498 FUNCTION_NAME=function_name,
499 IDL_TYPE=self.idl_type(), 499 IDL_TYPE=self.idl_type(),
500 HANDLE=handle, 500 HANDLE=handle)
501 FLAG=flag)
502 return name 501 return name
503 502
504 argument = name 503 argument = name
505 if self.custom_to_native(): 504 if self.custom_to_native():
506 type = 'RefPtr<%s>' % self.native_type() 505 type = 'RefPtr<%s>' % self.native_type()
507 argument = '%s.get()' % name 506 argument = '%s.get()' % name
508 else: 507 else:
509 type = '%s*' % self.native_type() 508 type = '%s*' % self.native_type()
510 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'): 509 if isinstance(self, SVGTearOffIDLTypeInfo) and not interface_name.endswith ('List'):
511 argument = '%s->propertyReference()' % name 510 argument = '%s->propertyReference()' % name
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 return 'const String&' 639 return 'const String&'
641 return self.native_type() 640 return self.native_type()
642 641
643 def conversion_includes(self): 642 def conversion_includes(self):
644 return [] 643 return []
645 644
646 def to_native_includes(sefl): 645 def to_native_includes(sefl):
647 return [] 646 return []
648 647
649 def to_dart_conversion(self, value, interface_name=None, attributes=None): 648 def to_dart_conversion(self, value, interface_name=None, attributes=None):
650 conversion_arguments = [value]
651 if attributes and 'TreatReturnedNullStringAs' in attributes:
652 conversion_arguments.append('DartUtilities::ConvertNullToDefaultValue')
653 function_name = self._capitalized_native_type() 649 function_name = self._capitalized_native_type()
654 function_name = function_name[0].lower() + function_name[1:] 650 function_name = function_name[0].lower() + function_name[1:]
655 function_name = 'DartUtilities::%sToDart' % function_name 651 function_name = 'DartUtilities::%sToDart' % function_name
656 return '%s(%s)' % (function_name, ', '.join(conversion_arguments)) 652 if attributes and 'TreatReturnedNullStringAs' in attributes:
653 function_name += 'WithNullCheck'
654 return '%s(%s)' % (function_name, value)
657 655
658 def webcore_getter_name(self): 656 def webcore_getter_name(self):
659 return self._data.webcore_getter_name 657 return self._data.webcore_getter_name
660 658
661 def webcore_setter_name(self): 659 def webcore_setter_name(self):
662 return self._data.webcore_setter_name 660 return self._data.webcore_setter_name
663 661
664 def _capitalized_native_type(self): 662 def _capitalized_native_type(self):
665 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e()) 663 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e())
666 664
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 if match: 834 if match:
837 if type_name == 'DOMString[]': 835 if type_name == 'DOMString[]':
838 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring')) 836 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt ring'))
839 item_info = self.TypeInfo(match.group(1) or match.group(2)) 837 item_info = self.TypeInfo(match.group(1) or match.group(2))
840 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) 838 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info)
841 if not type_name in _idl_type_registry: 839 if not type_name in _idl_type_registry:
842 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 840 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
843 type_data = _idl_type_registry.get(type_name) 841 type_data = _idl_type_registry.get(type_name)
844 class_name = '%sIDLTypeInfo' % type_data.clazz 842 class_name = '%sIDLTypeInfo' % type_data.clazz
845 return globals()[class_name](type_name, type_data) 843 return globals()[class_name](type_name, type_data)
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