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: tools/dom/scripts/systemhtml.py

Issue 12052076: Support overloaded constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 provides shared functionality for the system to generate 6 """This module provides shared functionality for the system to generate
7 Dart:html APIs from the IDL database.""" 7 Dart:html APIs from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 507
508 def FinishInterface(self): 508 def FinishInterface(self):
509 pass 509 pass
510 510
511 def HasSupportCheck(self): 511 def HasSupportCheck(self):
512 return self._interface.doc_js_name in js_support_checks 512 return self._interface.doc_js_name in js_support_checks
513 513
514 def GetSupportCheck(self): 514 def GetSupportCheck(self):
515 return js_support_checks.get(self._interface.doc_js_name) 515 return js_support_checks.get(self._interface.doc_js_name)
516 516
517 def EmitStaticFactory(self, constructor_info): 517 def HasCustomFactory(self):
518 WITH_CUSTOM_STATIC_FACTORY = [ 518 return self._interface.doc_js_name in [
519 'AudioContext', 519 'AudioContext',
520 'Blob', 520 'Blob',
521 'MutationObserver', 521 'MutationObserver',
522 'SpeechRecognition', 522 'SpeechRecognition',
523 ] 523 ]
524 524
525 if self._interface.doc_js_name in WITH_CUSTOM_STATIC_FACTORY: 525 def IsConstructorArgumentOptional(self, argument):
526 return 526 return 'Optional' in argument.ext_attrs
527 527
528 has_optional = any(param_info.is_optional 528 def EmitStaticFactoryOverload(self, constructor_info, name, arguments):
529 for param_info in constructor_info.param_infos) 529 index = len(arguments)
530 530 arguments = constructor_info.ParametersAsArgumentList(index)
531 def FormatJS(index): 531 if arguments:
532 arguments = constructor_info.ParametersAsArgumentList(index) 532 arguments = ', ' + arguments
533 if arguments: 533 self._members_emitter.Emit(
534 arguments = ', ' + arguments 534 " static $INTERFACE_NAME $NAME($PARAMETERS) => "
535 return "JS('%s', 'new %s(%s)'%s)" % ( 535 "JS('$INTERFACE_NAME', 'new $CTOR_NAME($PLACEHOLDERS)'$ARGUMENTS);\n",
536 self._interface_type_info.interface_name(), 536 INTERFACE_NAME=self._interface_type_info.interface_name(),
537 constructor_info.name or self._interface.doc_js_name, 537 NAME=name,
538 ','.join(['#'] * index), 538 # TODO: add types to parameters.
Emily Fortuna 2013/01/28 23:01:28 nit: add username to TODO
Anton Muhin 2013/01/29 12:09:28 Done.
539 arguments) 539 PARAMETERS=constructor_info.ParametersAsArgumentList(index),
540 540 CTOR_NAME=constructor_info.name or self._interface.doc_js_name,
541 if not has_optional: 541 PLACEHOLDERS=','.join(['#'] * index),
542 self._members_emitter.Emit( 542 ARGUMENTS=arguments)
543 " static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) => $JS;\n",
544 INTERFACE_NAME=self._interface_type_info.interface_name(),
545 PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration(
546 self._DartType),
547 JS=FormatJS(len(constructor_info.param_infos)))
548 else:
549 dispatcher_emitter = self._members_emitter.Emit(
550 " static $INTERFACE_NAME _create($PARAMETERS_DECLARATION) {\n"
551 "$!DISPATCHER"
552 " return $JS;\n"
553 " }\n",
554 INTERFACE_NAME=self._interface_type_info.interface_name(),
555 PARAMETERS_DECLARATION=constructor_info.ParametersDeclaration(
556 self._DartType),
557 JS=FormatJS(len(constructor_info.param_infos)))
558
559 for index, param_info in enumerate(constructor_info.param_infos):
560 if param_info.is_optional:
561 dispatcher_emitter.Emit(
562 " if (!?$OPT_PARAM_NAME) {\n"
563 " return $JS;\n"
564 " }\n",
565 OPT_PARAM_NAME=constructor_info.param_infos[index].name,
566 JS=FormatJS(index))
567 543
568 def SecondaryContext(self, interface): 544 def SecondaryContext(self, interface):
569 if interface is not self._current_secondary_parent: 545 if interface is not self._current_secondary_parent:
570 self._current_secondary_parent = interface 546 self._current_secondary_parent = interface
571 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) 547 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id)
572 548
573 def AddIndexer(self, element_type): 549 def AddIndexer(self, element_type):
574 """Adds all the methods required to complete implementation of List.""" 550 """Adds all the methods required to complete implementation of List."""
575 # We would like to simply inherit the implementation of everything except 551 # We would like to simply inherit the implementation of everything except
576 # length, [], and maybe []=. It is possible to extend from a base 552 # length, [], and maybe []=. It is possible to extend from a base
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 for library_name in libraries: 1010 for library_name in libraries:
1035 self._libraries[library_name] = DartLibrary( 1011 self._libraries[library_name] = DartLibrary(
1036 library_name, template_loader, library_type, output_dir) 1012 library_name, template_loader, library_type, output_dir)
1037 1013
1038 def AddFile(self, basename, library_name, path): 1014 def AddFile(self, basename, library_name, path):
1039 self._libraries[library_name].AddFile(path) 1015 self._libraries[library_name].AddFile(path)
1040 1016
1041 def Emit(self, emitter, auxiliary_dir): 1017 def Emit(self, emitter, auxiliary_dir):
1042 for lib in self._libraries.values(): 1018 for lib in self._libraries.values():
1043 lib.Emit(emitter, auxiliary_dir) 1019 lib.Emit(emitter, auxiliary_dir)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698