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 generates Dart APIs from the IDL database.""" | 6 """This module generates Dart APIs from the IDL database.""" |
7 | 7 |
8 import emitter | 8 import emitter |
9 import idlnode | 9 import idlnode |
10 import logging | 10 import logging |
(...skipping 24 matching lines...) Expand all Loading... |
35 # Map to extra precision - int is a bignum in Dart. | 35 # Map to extra precision - int is a bignum in Dart. |
36 'long': 'int', | 36 'long': 'int', |
37 'long long': 'int', | 37 'long long': 'int', |
38 'object': 'Object', | 38 'object': 'Object', |
39 # Map to extra precision - int is a bignum in Dart. | 39 # Map to extra precision - int is a bignum in Dart. |
40 'short': 'int', | 40 'short': 'int', |
41 'string': 'String', | 41 'string': 'String', |
42 'void': 'void', | 42 'void': 'void', |
43 'Array': 'List', | 43 'Array': 'List', |
44 'sequence': 'List', | 44 'sequence': 'List', |
45 # TODO(vsm): We need to support other types. We could weaken to | 45 # TODO(sra): Come up with some meaningful name so that where this appears in |
46 # Object, or inject SSV into the appropriate types. | 46 # the documentation, the user is made aware that only a limited subset of |
47 'SerializedScriptValue': 'String', | 47 # serializable types are actually permitted. |
| 48 'SerializedScriptValue': 'Dynamic', |
48 # TODO(vsm): Automatically recognize types defined in src. | 49 # TODO(vsm): Automatically recognize types defined in src. |
49 'TimeoutHandler': 'TimeoutHandler', | 50 'TimeoutHandler': 'TimeoutHandler', |
50 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', | 51 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', |
51 | 52 |
52 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} | 53 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} |
53 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce | 54 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa
ce |
54 'WebKitFlags': 'Object', | 55 'WebKitFlags': 'Object', |
55 } | 56 } |
56 | 57 |
57 _dart_to_idl_type_conversions = dict((v,k) for k, v in | 58 _dart_to_idl_type_conversions = dict((v,k) for k, v in |
(...skipping 30 matching lines...) Expand all Loading... |
88 # | 89 # |
89 _interface_factories = { | 90 _interface_factories = { |
90 'Float32Array': '_TypedArrayFactoryProvider', | 91 'Float32Array': '_TypedArrayFactoryProvider', |
91 'Float64Array': '_TypedArrayFactoryProvider', | 92 'Float64Array': '_TypedArrayFactoryProvider', |
92 'Int8Array': '_TypedArrayFactoryProvider', | 93 'Int8Array': '_TypedArrayFactoryProvider', |
93 'Int16Array': '_TypedArrayFactoryProvider', | 94 'Int16Array': '_TypedArrayFactoryProvider', |
94 'Int32Array': '_TypedArrayFactoryProvider', | 95 'Int32Array': '_TypedArrayFactoryProvider', |
95 'Uint8Array': '_TypedArrayFactoryProvider', | 96 'Uint8Array': '_TypedArrayFactoryProvider', |
96 'Uint16Array': '_TypedArrayFactoryProvider', | 97 'Uint16Array': '_TypedArrayFactoryProvider', |
97 'Uint32Array': '_TypedArrayFactoryProvider', | 98 'Uint32Array': '_TypedArrayFactoryProvider', |
| 99 'Uint8ClampedArray': '_TypedArrayFactoryProvider', |
98 } | 100 } |
99 | 101 |
100 # | 102 # |
101 # Custom methods that must be implemented by hand. | 103 # Custom methods that must be implemented by hand. |
102 # | 104 # |
103 _custom_methods = set([ | 105 _custom_methods = set([ |
104 ('DOMWindow', 'setInterval'), | 106 ('DOMWindow', 'setInterval'), |
105 ('DOMWindow', 'setTimeout'), | 107 ('DOMWindow', 'setTimeout'), |
106 ('WorkerContext', 'setInterval'), | 108 ('WorkerContext', 'setInterval'), |
107 ('WorkerContext', 'setTimeout'), | 109 ('WorkerContext', 'setTimeout'), |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 return None | 745 return None |
744 | 746 |
745 def MaybeTypedArrayElementType(interface): | 747 def MaybeTypedArrayElementType(interface): |
746 """Returns the typed array element type, or None in interface is not a | 748 """Returns the typed array element type, or None in interface is not a |
747 TypedArray. | 749 TypedArray. |
748 """ | 750 """ |
749 # Typed arrays implement ArrayBufferView and List<T>. | 751 # Typed arrays implement ArrayBufferView and List<T>. |
750 for parent in interface.parents: | 752 for parent in interface.parents: |
751 if parent.type.id == 'ArrayBufferView': | 753 if parent.type.id == 'ArrayBufferView': |
752 return MaybeListElementType(interface) | 754 return MaybeListElementType(interface) |
| 755 if parent.type.id == 'Uint8Array': |
| 756 return 'int' |
753 return None | 757 return None |
754 | 758 |
755 | 759 |
756 def AttributeOutputOrder(a, b): | 760 def AttributeOutputOrder(a, b): |
757 """Canonical output ordering for attributes.""" | 761 """Canonical output ordering for attributes.""" |
758 # Getters before setters: | 762 # Getters before setters: |
759 if a.id < b.id: return -1 | 763 if a.id < b.id: return -1 |
760 if a.id > b.id: return 1 | 764 if a.id > b.id: return 1 |
761 if a.is_fc_setter < b.is_fc_setter: return -1 | 765 if a.is_fc_setter < b.is_fc_setter: return -1 |
762 if a.is_fc_setter > b.is_fc_setter: return 1 | 766 if a.is_fc_setter > b.is_fc_setter: return 1 |
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 # TODO(sra): Use separate mixins for mutable implementations of List<T>. | 2007 # TODO(sra): Use separate mixins for mutable implementations of List<T>. |
2004 # TODO(sra): Use separate mixins for typed array implementations of List<T>. | 2008 # TODO(sra): Use separate mixins for typed array implementations of List<T>. |
2005 template_file = 'immutable_list_mixin.darttemplate' | 2009 template_file = 'immutable_list_mixin.darttemplate' |
2006 template = self._system._templates.Load(template_file) | 2010 template = self._system._templates.Load(template_file) |
2007 self._members_emitter.Emit(template, E=element_type) | 2011 self._members_emitter.Emit(template, E=element_type) |
2008 | 2012 |
2009 | 2013 |
2010 def AddTypedArrayConstructors(self, element_type): | 2014 def AddTypedArrayConstructors(self, element_type): |
2011 self._members_emitter.Emit( | 2015 self._members_emitter.Emit( |
2012 '\n' | 2016 '\n' |
2013 ' factory $CTOR(int length) => _construct(length);\n' | 2017 ' factory $CTOR(int length) => _construct_$CTOR(length);\n' |
2014 '\n' | 2018 '\n' |
2015 ' factory $CTOR.fromList(List<$TYPE> list) => _construct(list);\n' | 2019 ' factory $CTOR.fromList(List<$TYPE> list) => _construct_$CTOR(list);\n
' |
2016 '\n' | 2020 '\n' |
2017 ' factory $CTOR.fromBuffer(ArrayBuffer buffer) => _construct(buffer);\n
' | 2021 ' factory $CTOR.fromBuffer(ArrayBuffer buffer) => _construct_$CTOR(buff
er);\n' |
2018 '\n' | 2022 '\n' |
2019 ' static _construct(arg) native \'return new $CTOR(arg);\';\n', | 2023 ' static _construct_$CTOR(arg) native \'return new $CTOR(arg);\';\n', |
2020 CTOR=self._interface.id, | 2024 CTOR=self._interface.id, |
2021 TYPE=element_type) | 2025 TYPE=element_type) |
2022 | 2026 |
2023 | 2027 |
2024 def AddOperation(self, info): | 2028 def AddOperation(self, info): |
2025 """ | 2029 """ |
2026 Arguments: | 2030 Arguments: |
2027 info: An OperationInfo object. | 2031 info: An OperationInfo object. |
2028 """ | 2032 """ |
2029 # TODO(vsm): Handle overloads. | 2033 # TODO(vsm): Handle overloads. |
2030 self._members_emitter.Emit( | 2034 self._members_emitter.Emit( |
2031 '\n' | 2035 '\n' |
2032 ' $TYPE $NAME($PARAMS) native;\n', | 2036 ' $TYPE $NAME($PARAMS) native;\n', |
2033 TYPE=self._NarrowOutputType(info.type_name), | 2037 TYPE=self._NarrowOutputType(info.type_name), |
2034 NAME=info.name, | 2038 NAME=info.name, |
2035 PARAMS=info.ParametersImplementationDeclaration( | 2039 PARAMS=info.ParametersImplementationDeclaration( |
2036 lambda type_name: self._NarrowInputType(type_name))) | 2040 lambda type_name: self._NarrowInputType(type_name))) |
OLD | NEW |