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

Side by Side Diff: sdk/lib/html/scripts/systemnative.py

Issue 11363130: Cleaning up dart:html generation after interface/implementation merge. Removing most of the interfa… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporating review feedback, cleaning up comments Created 8 years, 1 month 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 provides shared functionality for the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
11 from generator import * 11 from generator import *
12 from systemhtml import SecureOutputType
13 from htmldartgenerator import * 12 from htmldartgenerator import *
14 13
15 class DartiumBackend(HtmlDartGenerator): 14 class DartiumBackend(HtmlDartGenerator):
16 """Generates Dart implementation for one DOM IDL interface.""" 15 """Generates Dart implementation for one DOM IDL interface."""
17 16
18 def __init__(self, interface, cpp_library_emitter, options): 17 def __init__(self, interface, cpp_library_emitter, options):
19 super(DartiumBackend, self).__init__(interface, options) 18 super(DartiumBackend, self).__init__(interface, options)
20 19
21 self._interface = interface 20 self._interface = interface
22 self._cpp_library_emitter = cpp_library_emitter 21 self._cpp_library_emitter = cpp_library_emitter
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 INTERFACE=self._interface.id, 279 INTERFACE=self._interface.id,
281 WEBCORE_INCLUDES=webcore_includes, 280 WEBCORE_INCLUDES=webcore_includes,
282 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), 281 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(),
283 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), 282 DECLARATIONS=self._cpp_declarations_emitter.Fragments(),
284 IS_NODE=TypeCheckHelper(is_node_test), 283 IS_NODE=TypeCheckHelper(is_node_test),
285 IS_ACTIVE=TypeCheckHelper(is_active_test), 284 IS_ACTIVE=TypeCheckHelper(is_active_test),
286 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test), 285 IS_EVENT_TARGET=TypeCheckHelper(is_event_target_test),
287 TO_NATIVE=to_native_emitter.Fragments(), 286 TO_NATIVE=to_native_emitter.Fragments(),
288 TO_DART=to_dart_emitter.Fragments()) 287 TO_DART=to_dart_emitter.Fragments())
289 288
290 def AddAttribute(self, attribute, html_name, read_only): 289 def EmitAttribute(self, attribute, html_name, read_only):
291 self._AddGetter(attribute, html_name) 290 self._AddGetter(attribute, html_name)
292 if not read_only: 291 if not read_only:
293 self._AddSetter(attribute, html_name) 292 self._AddSetter(attribute, html_name)
294 293
295 def _AddGetter(self, attr, html_name): 294 def _AddGetter(self, attr, html_name):
296 type_info = self._TypeInfo(attr.type.id) 295 type_info = self._TypeInfo(attr.type.id)
297 dart_declaration = '%s get %s' % (SecureOutputType(self, attr.type.id), html _name) 296 dart_declaration = '%s get %s' % (
297 self.SecureOutputType(attr.type.id), html_name)
298 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs 298 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs
299 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 299 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
300 dart_declaration, 'Getter', is_custom) 300 dart_declaration, 'Getter', is_custom)
301 if is_custom: 301 if is_custom:
302 return 302 return
303 303
304 if 'Reflect' in attr.ext_attrs: 304 if 'Reflect' in attr.ext_attrs:
305 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name() 305 webcore_function_name = self._TypeInfo(attr.type.id).webcore_getter_name()
306 if 'URL' in attr.ext_attrs: 306 if 'URL' in attr.ext_attrs:
307 if 'NonEmpty' in attr.ext_attrs: 307 if 'NonEmpty' in attr.ext_attrs:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 # 378 #
379 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } 379 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; }
380 # 380 #
381 dart_element_type = self._DartType(element_type) 381 dart_element_type = self._DartType(element_type)
382 if self._HasNativeIndexGetter(): 382 if self._HasNativeIndexGetter():
383 self._EmitNativeIndexGetter(dart_element_type) 383 self._EmitNativeIndexGetter(dart_element_type)
384 else: 384 else:
385 self._members_emitter.Emit( 385 self._members_emitter.Emit(
386 '\n' 386 '\n'
387 ' $TYPE operator[](int index) native "$(INTERFACE)_item_Callback";\n' , 387 ' $TYPE operator[](int index) native "$(INTERFACE)_item_Callback";\n' ,
388 TYPE=SecureOutputType(self, element_type), INTERFACE=self._interface.i d) 388 TYPE=self.SecureOutputType(element_type),
389 INTERFACE=self._interface.id)
389 390
390 if self._HasNativeIndexSetter(): 391 if self._HasNativeIndexSetter():
391 self._EmitNativeIndexSetter(dart_element_type) 392 self._EmitNativeIndexSetter(dart_element_type)
392 else: 393 else:
393 # The HTML library implementation of NodeList has a custom indexed setter 394 # The HTML library implementation of NodeList has a custom indexed setter
394 # implementation that uses the parent node the NodeList is associated 395 # implementation that uses the parent node the NodeList is associated
395 # with if one is available. 396 # with if one is available.
396 if self._interface.id != 'NodeList': 397 if self._interface.id != 'NodeList':
397 self._members_emitter.Emit( 398 self._members_emitter.Emit(
398 '\n' 399 '\n'
(...skipping 29 matching lines...) Expand all
428 self._EmitNativeIndexGetter(dart_element_type) 429 self._EmitNativeIndexGetter(dart_element_type)
429 if self._HasNativeIndexSetter(): 430 if self._HasNativeIndexSetter():
430 self._EmitNativeIndexSetter(dart_element_type) 431 self._EmitNativeIndexSetter(dart_element_type)
431 432
432 def _HasNativeIndexGetter(self): 433 def _HasNativeIndexGetter(self):
433 ext_attrs = self._interface.ext_attrs 434 ext_attrs = self._interface.ext_attrs
434 return ('CustomIndexedGetter' in ext_attrs or 435 return ('CustomIndexedGetter' in ext_attrs or
435 'NumericIndexedGetter' in ext_attrs) 436 'NumericIndexedGetter' in ext_attrs)
436 437
437 def _EmitNativeIndexGetter(self, element_type): 438 def _EmitNativeIndexGetter(self, element_type):
438 dart_declaration = '%s operator[](int index)' % SecureOutputType(self, eleme nt_type, True) 439 dart_declaration = '%s operator[](int index)' % \
440 self.SecureOutputType(element_type, True)
439 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration, 441 self._GenerateNativeBinding('numericIndexGetter', 2, dart_declaration,
440 'Callback', True) 442 'Callback', True)
441 443
442 def _HasNativeIndexSetter(self): 444 def _HasNativeIndexSetter(self):
443 return 'CustomIndexedSetter' in self._interface.ext_attrs 445 return 'CustomIndexedSetter' in self._interface.ext_attrs
444 446
445 def _EmitNativeIndexSetter(self, element_type): 447 def _EmitNativeIndexSetter(self, element_type):
446 dart_declaration = 'void operator[]=(int index, %s value)' % element_type 448 dart_declaration = 'void operator[]=(int index, %s value)' % element_type
447 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration, 449 self._GenerateNativeBinding('numericIndexSetter', 3, dart_declaration,
448 'Callback', True) 450 'Callback', True)
449 451
450 def AddOperation(self, info, html_name): 452 def EmitOperation(self, info, html_name):
451 """ 453 """
452 Arguments: 454 Arguments:
453 info: An OperationInfo object. 455 info: An OperationInfo object.
454 """ 456 """
455 457
456 operation = info.operations[0] 458 operation = info.operations[0]
457 459
458 is_custom = 'Custom' in operation.ext_attrs 460 is_custom = 'Custom' in operation.ext_attrs
459 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments) 461 has_optional_arguments = any(self._IsArgumentOptionalInWebCore(operation, ar gument) for argument in operation.arguments)
460 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments) 462 needs_dispatcher = not is_custom and (len(info.operations) > 1 or has_option al_arguments)
461 463
462 dart_declaration = '%s%s %s(%s)' % ( 464 dart_declaration = '%s%s %s(%s)' % (
463 'static ' if info.IsStatic() else '', 465 'static ' if info.IsStatic() else '',
464 SecureOutputType(self, info.type_name), 466 self.SecureOutputType(info.type_name),
465 html_name, 467 html_name,
466 info.ParametersDeclaration( 468 info.ParametersDeclaration(
467 (lambda x: 'dynamic') if needs_dispatcher else self._DartType)) 469 (lambda x: 'dynamic') if needs_dispatcher else self._DartType))
468 470
469 if not needs_dispatcher: 471 if not needs_dispatcher:
470 # Bind directly to native implementation 472 # Bind directly to native implementation
471 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos) 473 argument_count = (0 if info.IsStatic() else 1) + len(info.param_infos)
472 cpp_callback_name = self._GenerateNativeBinding( 474 cpp_callback_name = self._GenerateNativeBinding(
473 info.name, argument_count, dart_declaration, 'Callback', is_custom) 475 info.name, argument_count, dart_declaration, 'Callback', is_custom)
474 if not is_custom: 476 if not is_custom:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 template = ' $CALL;\n' 508 template = ' $CALL;\n'
507 509
508 overload_name = '%s_%s' % (operation.id, version[0]) 510 overload_name = '%s_%s' % (operation.id, version[0])
509 version[0] += 1 511 version[0] += 1
510 argument_list = ', '.join(argument_names[:argument_count]) 512 argument_list = ', '.join(argument_names[:argument_count])
511 call = '_%s(%s)' % (overload_name, argument_list) 513 call = '_%s(%s)' % (overload_name, argument_list)
512 body.Emit(template, CHECKS=' && '.join(checks), CALL=call) 514 body.Emit(template, CHECKS=' && '.join(checks), CALL=call)
513 515
514 dart_declaration = '%s%s _%s(%s)' % ( 516 dart_declaration = '%s%s _%s(%s)' % (
515 'static ' if operation.is_static else '', 517 'static ' if operation.is_static else '',
516 SecureOutputType(self, operation.type.id), overload_name, argument_lis t) 518 self.SecureOutputType(operation.type.id),
519 overload_name, argument_list)
517 cpp_callback_name = self._GenerateNativeBinding( 520 cpp_callback_name = self._GenerateNativeBinding(
518 overload_name, (0 if operation.is_static else 1) + argument_count, 521 overload_name, (0 if operation.is_static else 1) + argument_count,
519 dart_declaration, 'Callback', False) 522 dart_declaration, 'Callback', False)
520 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name) 523 self._GenerateOperationNativeCallback(operation, operation.arguments[:argu ment_count], cpp_callback_name)
521 524
522 def GenerateChecksAndCall(operation, argument_count): 525 def GenerateChecksAndCall(operation, argument_count):
523 checks = [] 526 checks = []
524 for i in range(0, argument_count): 527 for i in range(0, argument_count):
525 argument = operation.arguments[i] 528 argument = operation.arguments[i]
526 argument_name = argument_names[i] 529 argument_name = argument_names[i]
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 def EmitResolver(self, template, output_dir): 888 def EmitResolver(self, template, output_dir):
886 file_path = os.path.join(output_dir, 'DartResolver.cpp') 889 file_path = os.path.join(output_dir, 'DartResolver.cpp')
887 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template) 890 includes_emitter, body_emitter = self._emitters.FileEmitter(file_path).Emit( template)
888 for header_file in self._headers_list: 891 for header_file in self._headers_list:
889 path = os.path.relpath(header_file, output_dir) 892 path = os.path.relpath(header_file, output_dir)
890 includes_emitter.Emit('#include "$PATH"\n', PATH=path) 893 includes_emitter.Emit('#include "$PATH"\n', PATH=path)
891 body_emitter.Emit( 894 body_emitter.Emit(
892 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n' 895 ' if (Dart_NativeFunction func = $CLASS_NAME::resolver(name, argume ntCount))\n'
893 ' return func;\n', 896 ' return func;\n',
894 CLASS_NAME=os.path.splitext(os.path.basename(path))[0]) 897 CLASS_NAME=os.path.splitext(os.path.basename(path))[0])
OLDNEW
« no previous file with comments | « sdk/lib/html/scripts/systemhtml.py ('k') | sdk/lib/html/templates/html/interface/interface.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698