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

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

Issue 14211014: Chrome roll. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | « tools/dom/scripts/fremontcutbuilder.py ('k') | tools/dom/scripts/htmldartgenerator.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 json 10 import json
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 """For the given interface, find operations that take callbacks (for use in 136 """For the given interface, find operations that take callbacks (for use in
137 auto-transforming callbacks into futures).""" 137 auto-transforming callbacks into futures)."""
138 callback_handlers = [operation for operation in interface.operations 138 callback_handlers = [operation for operation in interface.operations
139 if operation.id == 'handleEvent'] 139 if operation.id == 'handleEvent']
140 return AnalyzeOperation(interface, callback_handlers) 140 return AnalyzeOperation(interface, callback_handlers)
141 141
142 # Given a list of overloaded arguments, render dart arguments. 142 # Given a list of overloaded arguments, render dart arguments.
143 def _BuildArguments(args, interface, constructor=False): 143 def _BuildArguments(args, interface, constructor=False):
144 def IsOptional(argument): 144 def IsOptional(argument):
145 if 'Callback' in argument.ext_attrs: 145 if 'Callback' in argument.ext_attrs:
146 # Callbacks with 'Optional=XXX' are treated as optional arguments. 146 # Optional callbacks arguments are treated as optional arguments.
147 return 'Optional' in argument.ext_attrs 147 return argument.optional
148 if constructor: 148 if constructor:
149 # FIXME: Constructors with 'Optional=XXX' shouldn't be treated as 149 # FIXME: Optional constructors arguments should not be treated as
150 # optional arguments. 150 # optional arguments.
151 return 'Optional' in argument.ext_attrs 151 return argument.optional
152 return False 152 return False
153 153
154 # Given a list of overloaded arguments, choose a suitable name. 154 # Given a list of overloaded arguments, choose a suitable name.
155 def OverloadedName(args): 155 def OverloadedName(args):
156 return '_OR_'.join(sorted(set(arg.id for arg in args))) 156 return '_OR_'.join(sorted(set(arg.id for arg in args)))
157 157
158 def DartType(idl_type_name): 158 def DartType(idl_type_name):
159 if idl_type_name in _idl_type_registry: 159 if idl_type_name in _idl_type_registry:
160 return _idl_type_registry[idl_type_name].dart_type or idl_type_name 160 return _idl_type_registry[idl_type_name].dart_type or idl_type_name
161 return idl_type_name 161 return idl_type_name
(...skipping 13 matching lines...) Expand all
175 is_optional = is_optional or any(arg is None or IsOptional(arg) for arg in a rg_tuple) 175 is_optional = is_optional or any(arg is None or IsOptional(arg) for arg in a rg_tuple)
176 176
177 filtered = filter(None, arg_tuple) 177 filtered = filter(None, arg_tuple)
178 type_id = OverloadedType(filtered) 178 type_id = OverloadedType(filtered)
179 name = OverloadedName(filtered) 179 name = OverloadedName(filtered)
180 result.append(ParamInfo(name, type_id, is_optional)) 180 result.append(ParamInfo(name, type_id, is_optional))
181 181
182 return result 182 return result
183 183
184 def IsOptional(argument): 184 def IsOptional(argument):
185 return ('Optional' in argument.ext_attrs and 185 return argument.optional and ('Default' not in argument.ext_attrs)
186 argument.ext_attrs['Optional'] == None)
187 186
188 def AnalyzeOperation(interface, operations): 187 def AnalyzeOperation(interface, operations):
189 """Makes operation calling convention decision for a set of overloads. 188 """Makes operation calling convention decision for a set of overloads.
190 189
191 Returns: An OperationInfo object. 190 Returns: An OperationInfo object.
192 """ 191 """
193 192
194 # split operations with optional args into multiple operations 193 # split operations with optional args into multiple operations
195 split_operations = [] 194 split_operations = []
196 for operation in operations: 195 for operation in operations:
(...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 type_name, type_data, dart_interface_name, self) 1586 type_name, type_data, dart_interface_name, self)
1588 1587
1589 if type_data.clazz == 'BasicTypedList': 1588 if type_data.clazz == 'BasicTypedList':
1590 dart_interface_name = self._renamer.RenameInterface( 1589 dart_interface_name = self._renamer.RenameInterface(
1591 self._database.GetInterface(type_name)) 1590 self._database.GetInterface(type_name))
1592 return BasicTypedListIDLTypeInfo( 1591 return BasicTypedListIDLTypeInfo(
1593 type_name, type_data, dart_interface_name, self) 1592 type_name, type_data, dart_interface_name, self)
1594 1593
1595 class_name = '%sIDLTypeInfo' % type_data.clazz 1594 class_name = '%sIDLTypeInfo' % type_data.clazz
1596 return globals()[class_name](type_name, type_data) 1595 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « tools/dom/scripts/fremontcutbuilder.py ('k') | tools/dom/scripts/htmldartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698