| OLD | NEW |
| 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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 476 |
| 477 def dart_type(self): | 477 def dart_type(self): |
| 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, name, handle, interface_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 if set(['Optional', 'Callback']).issubset(idl_node.ext_attrs.keys()): | 488 if accept_null: |
| 489 flag = 'DartUtilities::ConvertNullToDefaultValue' | 489 flag = 'DartUtilities::ConvertNullToDefaultValue' |
| 490 else: | 490 else: |
| 491 flag = 'DartUtilities::ConvertNone' | 491 flag = 'DartUtilities::ConvertNone' |
| 492 emitter.Emit( | 492 emitter.Emit( |
| 493 '\n' | 493 '\n' |
| 494 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc
eption);\n' | 494 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc
eption);\n' |
| 495 ' if (exception)\n' | 495 ' if (exception)\n' |
| 496 ' goto fail;\n', | 496 ' goto fail;\n', |
| 497 TYPE=self.native_type(), | 497 TYPE=self.native_type(), |
| 498 NAME=name, | 498 NAME=name, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) | 589 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_
type(), value) |
| 590 | 590 |
| 591 def conversion_includes(self): | 591 def conversion_includes(self): |
| 592 return self._item_info.conversion_includes() | 592 return self._item_info.conversion_includes() |
| 593 | 593 |
| 594 | 594 |
| 595 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): | 595 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): |
| 596 def __init__(self, data, item_info): | 596 def __init__(self, data, item_info): |
| 597 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) | 597 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', data, item_info) |
| 598 | 598 |
| 599 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): | 599 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa
ce_name): |
| 600 assert not accept_null |
| 600 emitter.Emit( | 601 emitter.Emit( |
| 601 '\n' | 602 '\n' |
| 602 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' | 603 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND
LE, exception);\n' |
| 603 ' if (exception)\n' | 604 ' if (exception)\n' |
| 604 ' goto fail;\n', | 605 ' goto fail;\n', |
| 605 NAME=name, | 606 NAME=name, |
| 606 HANDLE=handle) | 607 HANDLE=handle) |
| 607 return name | 608 return name |
| 608 | 609 |
| 609 def to_native_includes(self): | 610 def to_native_includes(self): |
| 610 return ['"DartDOMStringList.h"'] | 611 return ['"DartDOMStringList.h"'] |
| 611 | 612 |
| 612 | 613 |
| 613 class PrimitiveIDLTypeInfo(IDLTypeInfo): | 614 class PrimitiveIDLTypeInfo(IDLTypeInfo): |
| 614 def __init__(self, idl_type, data): | 615 def __init__(self, idl_type, data): |
| 615 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) | 616 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data) |
| 616 | 617 |
| 617 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): | 618 def emit_to_native(self, emitter, idl_node, accept_null, name, handle, interfa
ce_name): |
| 618 function_name = 'dartTo%s' % self._capitalized_native_type() | 619 function_name = 'dartTo%s' % self._capitalized_native_type() |
| 619 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString': | 620 if accept_null: |
| 620 function_name += 'WithNullCheck' | 621 function_name += 'WithNullCheck' |
| 621 type = self.native_type() | 622 type = self.native_type() |
| 622 if type == 'SerializedScriptValue': | 623 if type == 'SerializedScriptValue': |
| 623 type = 'RefPtr<%s>' % type | 624 type = 'RefPtr<%s>' % type |
| 624 if type == 'String': | 625 if type == 'String': |
| 625 type = 'DartStringAdapter' | 626 type = 'DartStringAdapter' |
| 626 emitter.Emit( | 627 emitter.Emit( |
| 627 '\n' | 628 '\n' |
| 628 ' $TYPE $NAME = DartUtilities::$FUNCTION_NAME($HANDLE, exception)
;\n' | 629 ' $TYPE $NAME = DartUtilities::$FUNCTION_NAME($HANDLE, exception)
;\n' |
| 629 ' if (exception)\n' | 630 ' if (exception)\n' |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 if match: | 836 if match: |
| 836 if type_name == 'DOMString[]': | 837 if type_name == 'DOMString[]': |
| 837 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) | 838 return DOMStringArrayTypeInfo(TypeData('Sequence'), self.TypeInfo('DOMSt
ring')) |
| 838 item_info = self.TypeInfo(match.group(1) or match.group(2)) | 839 item_info = self.TypeInfo(match.group(1) or match.group(2)) |
| 839 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) | 840 return SequenceIDLTypeInfo(type_name, TypeData('Sequence'), item_info) |
| 840 if not type_name in _idl_type_registry: | 841 if not type_name in _idl_type_registry: |
| 841 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) | 842 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) |
| 842 type_data = _idl_type_registry.get(type_name) | 843 type_data = _idl_type_registry.get(type_name) |
| 843 class_name = '%sIDLTypeInfo' % type_data.clazz | 844 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 844 return globals()[class_name](type_name, type_data) | 845 return globals()[class_name](type_name, type_data) |
| OLD | NEW |