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

Side by Side Diff: client/dom/scripts/dartgenerator.py

Issue 9264057: Refresh dart:dom libraries from WebKit (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Don't re-implement List<>, causes code that dartc rejects due to static 'override' Created 8 years, 10 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
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 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 26 matching lines...) Expand all
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(vsm): We need to support other types. We could weaken to
46 # Object, or inject SSV into the appropriate types. 46 # Object, or inject SSV into the appropriate types.
47 'SerializedScriptValue': 'String', 47 'SerializedScriptValue': 'Dynamic/*SerializedScriptValue*/',
vsm 2012/01/31 02:41:40 Not sure it's useful to put this in the comment if
48 # TODO(vsm): Automatically recognize types defined in src. 48 # TODO(vsm): Automatically recognize types defined in src.
49 'TimeoutHandler': 'TimeoutHandler', 49 'TimeoutHandler': 'TimeoutHandler',
50 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback', 50 'RequestAnimationFrameCallback': 'RequestAnimationFrameCallback',
51 51
52 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 52 # 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 53 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
54 'WebKitFlags': 'Object', 54 'WebKitFlags': 'Object',
55 } 55 }
56 56
57 _dart_to_idl_type_conversions = dict((v,k) for k, v in 57 _dart_to_idl_type_conversions = dict((v,k) for k, v in
(...skipping 30 matching lines...) Expand all
88 # 88 #
89 _interface_factories = { 89 _interface_factories = {
90 'Float32Array': '_TypedArrayFactoryProvider', 90 'Float32Array': '_TypedArrayFactoryProvider',
91 'Float64Array': '_TypedArrayFactoryProvider', 91 'Float64Array': '_TypedArrayFactoryProvider',
92 'Int8Array': '_TypedArrayFactoryProvider', 92 'Int8Array': '_TypedArrayFactoryProvider',
93 'Int16Array': '_TypedArrayFactoryProvider', 93 'Int16Array': '_TypedArrayFactoryProvider',
94 'Int32Array': '_TypedArrayFactoryProvider', 94 'Int32Array': '_TypedArrayFactoryProvider',
95 'Uint8Array': '_TypedArrayFactoryProvider', 95 'Uint8Array': '_TypedArrayFactoryProvider',
96 'Uint16Array': '_TypedArrayFactoryProvider', 96 'Uint16Array': '_TypedArrayFactoryProvider',
97 'Uint32Array': '_TypedArrayFactoryProvider', 97 'Uint32Array': '_TypedArrayFactoryProvider',
98 'Uint8ClampedArray': '_TypedArrayFactoryProvider',
98 } 99 }
99 100
100 # 101 #
101 # Custom methods that must be implemented by hand. 102 # Custom methods that must be implemented by hand.
102 # 103 #
103 _custom_methods = set([ 104 _custom_methods = set([
104 ('DOMWindow', 'setInterval'), 105 ('DOMWindow', 'setInterval'),
105 ('DOMWindow', 'setTimeout'), 106 ('DOMWindow', 'setTimeout'),
106 ('WorkerContext', 'setInterval'), 107 ('WorkerContext', 'setInterval'),
107 ('WorkerContext', 'setTimeout'), 108 ('WorkerContext', 'setTimeout'),
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 return None 744 return None
744 745
745 def MaybeTypedArrayElementType(interface): 746 def MaybeTypedArrayElementType(interface):
746 """Returns the typed array element type, or None in interface is not a 747 """Returns the typed array element type, or None in interface is not a
747 TypedArray. 748 TypedArray.
748 """ 749 """
749 # Typed arrays implement ArrayBufferView and List<T>. 750 # Typed arrays implement ArrayBufferView and List<T>.
750 for parent in interface.parents: 751 for parent in interface.parents:
751 if parent.type.id == 'ArrayBufferView': 752 if parent.type.id == 'ArrayBufferView':
752 return MaybeListElementType(interface) 753 return MaybeListElementType(interface)
754 if parent.type.id == 'Uint8Array':
755 return 'int'
756 #return MaybeListElementType(interface)
vsm 2012/01/31 02:41:40 Delete comment.
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
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)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698