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

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

Issue 1738913003: Needed to handling calling static attributes/operations in blink (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: rebased Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | 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 # 2 #
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.""" 7 """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file."""
8 8
9 import os 9 import os
10 10
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 # getter, setter, deleter and propertyQuery code 152 # getter, setter, deleter and propertyQuery code
153 OPERATION_1 = ' $%s_Callback_1_(mthis, __arg_0) => Blink_JsNative_DomException. callMethod(mthis, "%s", [__arg_0]);\n\n' 153 OPERATION_1 = ' $%s_Callback_1_(mthis, __arg_0) => Blink_JsNative_DomException. callMethod(mthis, "%s", [__arg_0]);\n\n'
154 OPERATION_2 = ' $%s_Callback_2_(mthis, __arg_0, __arg_1) => Blink_JsNative_DomE xception.callMethod(mthis, "%s", [__arg_0, __arg_1]);\n\n' 154 OPERATION_2 = ' $%s_Callback_2_(mthis, __arg_0, __arg_1) => Blink_JsNative_DomE xception.callMethod(mthis, "%s", [__arg_0, __arg_1]);\n\n'
155 OPERATION_PQ = ' $%s_Callback_1_(mthis, __arg_0) => mthis[__arg_0];\n\n' 155 OPERATION_PQ = ' $%s_Callback_1_(mthis, __arg_0) => mthis[__arg_0];\n\n'
156 156
157 #(operation_name, argument_count, arguments, operation_name, arguments) 157 #(operation_name, argument_count, arguments, operation_name, arguments)
158 ARGUMENT_NUM = "__arg_%s" 158 ARGUMENT_NUM = "__arg_%s"
159 OPERATION_ARGS = ' %s_Callback_%s_(mthis, %s) => Blink_JsNative_DomException.ca llMethod(mthis, "%s", [%s]);\n\n' 159 OPERATION_ARGS = ' %s_Callback_%s_(mthis, %s) => Blink_JsNative_DomException.ca llMethod(mthis, "%s", [%s]);\n\n'
160 160
161 # get class property to make static call.
162 CLASS_STATIC = 'Blink_JsNative_DomException.getProperty(js.context, "%s")'
163
164 # name, classname_getproperty, name
165 STATIC_ATTRIBUTE_GETTER = ' %s_Getter_() => Blink_JsNative_DomException.getProp erty(%s, "%s");\n\n'
166
167 # name, classname_getproperty, name
168 STATIC_OPERATION_0 = ' %s_Callback_0_() => Blink_JsNative_DomException.callMeth od(%s, "%s", []);\n\n'
169
170 # name, argsCount, args, classname_getproperty, name, args
171 STATIC_OPERATION_ARGS = ' %s_Callback_%s_(%s) => Blink_JsNative_DomException.ca llMethod(%s, "%s", [%s]);\n\n'
172
161 CLASS_DEFINITION_END = """} 173 CLASS_DEFINITION_END = """}
162 174
163 """ 175 """
164 176
165 def ConstantOutputOrder(a, b): 177 def ConstantOutputOrder(a, b):
166 """Canonical output ordering for constants.""" 178 """Canonical output ordering for constants."""
167 return cmp(a.id, b.id) 179 return cmp(a.id, b.id)
168 180
169 def generate_parameter_entries(param_infos): 181 def generate_parameter_entries(param_infos):
170 optional_default_args = 0; 182 optional_default_args = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 class_def = CLASS_DEFINITION % (name, name) 220 class_def = CLASS_DEFINITION % (name, name)
209 blink_file.write(class_def); 221 blink_file.write(class_def);
210 222
211 analyzed_constructors = AnalyzeConstructor(interface) 223 analyzed_constructors = AnalyzeConstructor(interface)
212 if analyzed_constructors: 224 if analyzed_constructors:
213 _Emit_Blink_Constructors(blink_file, analyzed_constructors) 225 _Emit_Blink_Constructors(blink_file, analyzed_constructors)
214 elif 'Constructor' in interface.ext_attrs: 226 elif 'Constructor' in interface.ext_attrs:
215 # Zero parameter constructor. 227 # Zero parameter constructor.
216 blink_file.write(CONSTRUCTOR_0 % rename_constructor(name)) 228 blink_file.write(CONSTRUCTOR_0 % rename_constructor(name))
217 229
218 _Process_Attributes(blink_file, interface.attributes) 230 _Process_Attributes(blink_file, interface, interface.attributes)
219 _Process_Operations(blink_file, interface, interface.operations) 231 _Process_Operations(blink_file, interface, interface.operations)
220 232
221 secondary_parents = database.TransitiveSecondaryParents(interface, False) 233 secondary_parents = database.TransitiveSecondaryParents(interface, False)
222 for secondary in secondary_parents: 234 for secondary in secondary_parents:
223 _Process_Attributes(blink_file, secondary.attributes) 235 _Process_Attributes(blink_file, secondary, secondary.attributes)
224 _Process_Operations(blink_file, secondary, secondary.operations) 236 _Process_Operations(blink_file, secondary, secondary.operations)
225 237
226 blink_file.write(CLASS_DEFINITION_END); 238 blink_file.write(CLASS_DEFINITION_END);
227 239
228 blink_file.write(BLINK_UTILS) 240 blink_file.write(BLINK_UTILS)
229 241
230 blink_file.close() 242 blink_file.close()
231 243
232 def _Emit_Blink_Constructors(blink_file, analyzed_constructors): 244 def _Emit_Blink_Constructors(blink_file, analyzed_constructors):
233 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed_construct ors.param_infos) 245 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed_construct ors.param_infos)
234 name = analyzed_constructors.js_name 246 name = analyzed_constructors.js_name
235 if not(name): 247 if not(name):
236 name = analyzed_constructors.type_name 248 name = analyzed_constructors.type_name
237 249
238 for callback_index in range(arg_min_count, arg_max_count): 250 for callback_index in range(arg_min_count, arg_max_count):
239 if callback_index == 0: 251 if callback_index == 0:
240 blink_file.write(CONSTRUCTOR_0 % (rename_constructor(name))) 252 blink_file.write(CONSTRUCTOR_0 % (rename_constructor(name)))
241 else: 253 else:
242 arguments = [] 254 arguments = []
243 for i in range(0, callback_index): 255 for i in range(0, callback_index):
244 arguments.append(ARGUMENT_NUM % i) 256 arguments.append(ARGUMENT_NUM % i)
245 argument_list = ', '.join(arguments) 257 argument_list = ', '.join(arguments)
246 blink_file.write(CONSTRUCTOR_ARGS % (callback_index, argument_list, rename _constructor(name), argument_list)) 258 blink_file.write(CONSTRUCTOR_ARGS % (callback_index, argument_list, rename _constructor(name), argument_list))
247 259
248 def _Process_Attributes(blink_file, attributes): 260 def _Process_Attributes(blink_file, interface, attributes):
249 # Emit an interface's attributes and operations. 261 # Emit an interface's attributes and operations.
250 for attribute in sorted(attributes, ConstantOutputOrder): 262 for attribute in sorted(attributes, ConstantOutputOrder):
251 name = attribute.id 263 name = attribute.id
252 if attribute.is_read_only: 264 if attribute.is_read_only:
253 blink_file.write(ATTRIBUTE_GETTER % (name, name)) 265 if attribute.is_static:
266 class_property = CLASS_STATIC % interface.id
267 blink_file.write(STATIC_ATTRIBUTE_GETTER % (name, class_property, name))
268 else:
269 blink_file.write(ATTRIBUTE_GETTER % (name, name))
254 else: 270 else:
255 blink_file.write(ATTRIBUTE_GETTER % (name, name)) 271 blink_file.write(ATTRIBUTE_GETTER % (name, name))
256 blink_file.write(ATTRIBUTE_SETTER % (name, name)) 272 blink_file.write(ATTRIBUTE_SETTER % (name, name))
257 273
258 def _Process_Operations(blink_file, interface, operations): 274 def _Process_Operations(blink_file, interface, operations):
259 analyzeOperations = [] 275 analyzeOperations = []
260 276
261 for operation in sorted(operations, ConstantOutputOrder): 277 for operation in sorted(operations, ConstantOutputOrder):
262 if len(analyzeOperations) == 0: 278 if len(analyzeOperations) == 0:
263 analyzeOperations.append(operation) 279 analyzeOperations.append(operation)
(...skipping 26 matching lines...) Expand all
290 elif arg_max_count == 3: 306 elif arg_max_count == 3:
291 blink_file.write(OPERATION_2 % (name, name)) 307 blink_file.write(OPERATION_2 % (name, name))
292 else: 308 else:
293 print "FATAL ERROR: _blink emitter operator %s.%s" % (interface.id, name ) 309 print "FATAL ERROR: _blink emitter operator %s.%s" % (interface.id, name )
294 exit 310 exit
295 311
296 return 312 return
297 313
298 for callback_index in range(arg_min_count, arg_max_count): 314 for callback_index in range(arg_min_count, arg_max_count):
299 if callback_index == 0: 315 if callback_index == 0:
300 blink_file.write(OPERATION_0 % (name, name)) 316 if operation.is_static:
317 class_property = CLASS_STATIC % interface.id
318 blink_file.write(STATIC_OPERATION_0 % (name, class_property, name))
319 else:
320 blink_file.write(OPERATION_0 % (name, name))
301 else: 321 else:
302 arguments = [] 322 arguments = []
303 for i in range(0, callback_index): 323 for i in range(0, callback_index):
304 arguments.append(ARGUMENT_NUM % i) 324 arguments.append(ARGUMENT_NUM % i)
305 argument_list = ', '.join(arguments) 325 argument_list = ', '.join(arguments)
306 blink_file.write(OPERATION_ARGS % (name, callback_index, argument_list, na me, argument_list)) 326 if operation.is_static:
327 class_property = CLASS_STATIC % interface.id
328 blink_file.write(STATIC_OPERATION_ARGS % (name, callback_index, argument _list, class_property, name, argument_list))
329 else:
330 blink_file.write(OPERATION_ARGS % (name, callback_index, argument_list, name, argument_list))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698