| OLD | NEW |
| 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 from systemfrog import * | 9 from systemfrog import * |
| 10 from systeminterface import * | 10 from systeminterface import * |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 | 429 |
| 430 | 430 |
| 431 | 431 |
| 432 # Information for generating element constructors. | 432 # Information for generating element constructors. |
| 433 # | 433 # |
| 434 # TODO(sra): maybe remove all the argument complexity and use cascades. | 434 # TODO(sra): maybe remove all the argument complexity and use cascades. |
| 435 # | 435 # |
| 436 # var c = new CanvasElement(width: 100, height: 70); | 436 # var c = new CanvasElement(width: 100, height: 70); |
| 437 # var c = new CanvasElement()..width = 100..height = 70; | 437 # var c = new CanvasElement()..width = 100..height = 70; |
| 438 # | 438 # |
| 439 class ElementCtorInfo(object): | 439 class ElementConstructorInfo(object): |
| 440 def __init__(self, tag=None, params=[], opt_params=[], | 440 def __init__(self, name=None, tag=None, |
| 441 params=[], opt_params=[], |
| 441 factory_provider_name='_Elements'): | 442 factory_provider_name='_Elements'): |
| 442 self.tag = tag | 443 self.name = name # The constructor name 'h1' in 'HeadingElement.h1' |
| 444 self.tag = tag or name # The HTML tag |
| 443 self.params = params | 445 self.params = params |
| 444 self.opt_params = opt_params | 446 self.opt_params = opt_params |
| 445 self.factory_provider_name = factory_provider_name | 447 self.factory_provider_name = factory_provider_name |
| 446 | 448 |
| 447 def ConstructorInfo(self, interface): | 449 def ConstructorInfo(self, interface_name): |
| 448 info = OperationInfo() | 450 info = OperationInfo() |
| 449 info.overloads = None | 451 info.overloads = None |
| 450 info.declared_name = interface.id | 452 info.declared_name = interface_name |
| 451 info.name = interface.id | 453 info.name = interface_name |
| 454 info.constructor_name = self.name |
| 452 info.js_name = None | 455 info.js_name = None |
| 453 info.type_name = interface.id | 456 info.type_name = interface_name |
| 454 info.param_infos = map(lambda tXn: ParamInfo(tXn[1], None, tXn[0], 'null'), | 457 info.param_infos = map(lambda tXn: ParamInfo(tXn[1], None, tXn[0], 'null'), |
| 455 self.opt_params) | 458 self.opt_params) |
| 456 return info | 459 return info |
| 457 | 460 |
| 458 _html_element_constructors = { | 461 _html_element_constructors = { |
| 459 'AnchorElement' : ElementCtorInfo(tag='a', opt_params=[('String', 'href')]), | 462 'AnchorElement' : |
| 463 ElementConstructorInfo(tag='a', opt_params=[('String', 'href')]), |
| 460 'AreaElement': 'area', | 464 'AreaElement': 'area', |
| 461 'ButtonElement': 'button', | 465 'ButtonElement': 'button', |
| 462 'BRElement': 'br', | 466 'BRElement': 'br', |
| 463 'BaseElement': 'base', | 467 'BaseElement': 'base', |
| 464 'BodyElement': 'body', | 468 'BodyElement': 'body', |
| 465 'ButtonElement': 'button', | 469 'ButtonElement': 'button', |
| 466 'CanvasElement': | 470 'CanvasElement': |
| 467 ElementCtorInfo(tag='canvas', | 471 ElementConstructorInfo(tag='canvas', |
| 468 opt_params=[('int', 'height'), ('int', 'width')]), | 472 opt_params=[('int', 'height'), ('int', 'width')]), |
| 469 'DListElement': 'dl', | 473 'DListElement': 'dl', |
| 470 'DetailsElement': 'details', | 474 'DetailsElement': 'details', |
| 471 'DivElement': 'div', | 475 'DivElement': 'div', |
| 472 'EmbedElement': 'embed', | 476 'EmbedElement': 'embed', |
| 473 'FieldSetElement': 'fieldset', | 477 'FieldSetElement': 'fieldset', |
| 474 'Form': 'form', | 478 'Form': 'form', |
| 475 'HRElement': 'hr', | 479 'HRElement': 'hr', |
| 476 'HeadElement': 'head', | 480 'HeadElement': 'head', |
| 481 'HeadingElement': [ElementConstructorInfo('h1'), |
| 482 ElementConstructorInfo('h2'), |
| 483 ElementConstructorInfo('h3'), |
| 484 ElementConstructorInfo('h4'), |
| 485 ElementConstructorInfo('h5'), |
| 486 ElementConstructorInfo('h6')], |
| 477 'HtmlElement': 'html', | 487 'HtmlElement': 'html', |
| 478 'IFrameElement': 'iframe', | 488 'IFrameElement': 'iframe', |
| 479 'ImageElement': | 489 'ImageElement': |
| 480 ElementCtorInfo(tag='img', | 490 ElementConstructorInfo(tag='img', |
| 481 opt_params=[('String', 'src'), | 491 opt_params=[('String', 'src'), |
| 482 ('int', 'height'), ('int', 'width')]), | 492 ('int', 'height'), ('int', 'width')]), |
| 483 'InputElement': | 493 'InputElement': |
| 484 ElementCtorInfo(tag='input', opt_params=[('String', 'type')]), | 494 ElementConstructorInfo(tag='input', opt_params=[('String', 'type')]), |
| 485 'KeygenElement': 'keygen', | 495 'KeygenElement': 'keygen', |
| 486 'LIElement': 'li', | 496 'LIElement': 'li', |
| 487 'LabelElement': 'label', | 497 'LabelElement': 'label', |
| 488 'LegendElement': 'legend', | 498 'LegendElement': 'legend', |
| 489 'LinkElement': 'link', | 499 'LinkElement': 'link', |
| 490 'MapElement': 'map', | 500 'MapElement': 'map', |
| 491 'MenuElement': 'menu', | 501 'MenuElement': 'menu', |
| 492 'MeterElement': 'meter', | 502 'MeterElement': 'meter', |
| 493 'OListElement': 'ol', | 503 'OListElement': 'ol', |
| 494 'ObjectElement': 'object', | 504 'ObjectElement': 'object', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 508 'TableElement': 'table', | 518 'TableElement': 'table', |
| 509 'TableRowElement': 'tr', | 519 'TableRowElement': 'tr', |
| 510 #'TableSectionElement' <thead> <tbody> <tfoot> | 520 #'TableSectionElement' <thead> <tbody> <tfoot> |
| 511 'TextAreaElement': 'textarea', | 521 'TextAreaElement': 'textarea', |
| 512 'TitleElement': 'title', | 522 'TitleElement': 'title', |
| 513 'TrackElement': 'track', | 523 'TrackElement': 'track', |
| 514 'UListElement': 'ul', | 524 'UListElement': 'ul', |
| 515 'VideoElement': 'video' | 525 'VideoElement': 'video' |
| 516 } | 526 } |
| 517 | 527 |
| 528 def HtmlElementConstructorInfos(typename): |
| 529 """Returns list of ElementConstructorInfos about the convenience constructors |
| 530 for an Element.""" |
| 531 # TODO(sra): Handle multiple and named constructors. |
| 532 if typename not in _html_element_constructors: |
| 533 return [] |
| 534 infos = _html_element_constructors[typename] |
| 535 if isinstance(infos, str): |
| 536 infos = ElementConstructorInfo(tag=infos) |
| 537 if not isinstance(infos, list): |
| 538 infos = [infos] |
| 539 return infos |
| 540 |
| 541 def EmitHtmlElementFactoryConstructors(emitter, infos, typename, class_name): |
| 542 for info in infos: |
| 543 constructor_info = info.ConstructorInfo(typename) |
| 544 inits = emitter.Emit( |
| 545 '\n' |
| 546 ' factory $CONSTRUCTOR($PARAMS) {\n' |
| 547 ' $CLASS _e = _document.$dom_createElement("$TAG");\n' |
| 548 '$!INITS' |
| 549 ' return _e;\n' |
| 550 ' }\n', |
| 551 CONSTRUCTOR=constructor_info.ConstructorFullName(), |
| 552 CLASS=class_name, |
| 553 TAG=info.tag, |
| 554 PARAMS=constructor_info.ParametersInterfaceDeclaration()) |
| 555 for param in constructor_info.param_infos: |
| 556 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) |
| 557 |
| 558 |
| 518 # These classes require an explicit declaration for the "on" method even though | 559 # These classes require an explicit declaration for the "on" method even though |
| 519 # they don't declare any unique events, because the concrete class hierarchy | 560 # they don't declare any unique events, because the concrete class hierarchy |
| 520 # doesn't match the interface hierarchy. | 561 # doesn't match the interface hierarchy. |
| 521 _html_explicit_event_classes = set(['DocumentFragment']) | 562 _html_explicit_event_classes = set(['DocumentFragment']) |
| 522 | 563 |
| 523 def _OnAttributeToEventName(on_method): | 564 def _OnAttributeToEventName(on_method): |
| 524 event_name = on_method.id[2:] | 565 event_name = on_method.id[2:] |
| 525 if event_name in _on_attribute_to_event_name_mapping: | 566 if event_name in _on_attribute_to_event_name_mapping: |
| 526 return _on_attribute_to_event_name_mapping[event_name] | 567 return _on_attribute_to_event_name_mapping[event_name] |
| 527 else: | 568 else: |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 def GenerateLibraries(self): | 731 def GenerateLibraries(self): |
| 691 pass | 732 pass |
| 692 | 733 |
| 693 | 734 |
| 694 def _FilePathForDartInterface(self, interface_name): | 735 def _FilePathForDartInterface(self, interface_name): |
| 695 """Returns the file path of the Dart interface definition.""" | 736 """Returns the file path of the Dart interface definition.""" |
| 696 # TODO(jmesserly): is this the right path | 737 # TODO(jmesserly): is this the right path |
| 697 return os.path.join(self._output_dir, 'html', 'interface', | 738 return os.path.join(self._output_dir, 'html', 'interface', |
| 698 '%s.dart' % interface_name) | 739 '%s.dart' % interface_name) |
| 699 | 740 |
| 700 def _EmitterForFactoryProviderBody(self, name): | |
| 701 if name not in self._factory_provider_emitters: | |
| 702 path = self._FilePathForDartInterface(name) | |
| 703 self._dart_interface_file_paths.append(path) | |
| 704 template = self._templates.Load('factoryprovider_%s.darttemplate' % name) | |
| 705 file_emitter = self._emitters.FileEmitter(path) | |
| 706 self._factory_provider_emitters[name] = file_emitter.Emit(template) | |
| 707 return self._factory_provider_emitters[name] | |
| 708 | |
| 709 # ------------------------------------------------------------------------------ | 741 # ------------------------------------------------------------------------------ |
| 710 | 742 |
| 711 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 743 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
| 712 # term, but it makes merging better for now. | 744 # term, but it makes merging better for now. |
| 713 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): | 745 class HtmlDartInterfaceGenerator(DartInterfaceGenerator): |
| 714 """Generates Dart Interface definition for one DOM IDL interface.""" | 746 """Generates Dart Interface definition for one DOM IDL interface.""" |
| 715 | 747 |
| 716 def __init__(self, system, interface, emitter, template, | 748 def __init__(self, system, interface, emitter, template, |
| 717 common_prefix, super_interface, source_filter, shared): | 749 common_prefix, super_interface, source_filter, shared): |
| 718 super(HtmlDartInterfaceGenerator, self).__init__(system, interface, | 750 super(HtmlDartInterfaceGenerator, self).__init__(system, interface, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 740 | 772 |
| 741 comment = ' extends' | 773 comment = ' extends' |
| 742 extends_str = '' | 774 extends_str = '' |
| 743 if extends: | 775 if extends: |
| 744 extends_str += ' extends ' + ', '.join(extends) | 776 extends_str += ' extends ' + ', '.join(extends) |
| 745 comment = ',' | 777 comment = ',' |
| 746 if suppressed_extends: | 778 if suppressed_extends: |
| 747 extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) | 779 extends_str += ' /*%s %s */' % (comment, ', '.join(suppressed_extends)) |
| 748 | 780 |
| 749 factory_provider = None | 781 factory_provider = None |
| 750 constructor_info = AnalyzeConstructor(self._interface) | |
| 751 if constructor_info: | |
| 752 factory_provider = '_' + typename + 'FactoryProvider'; | |
| 753 | |
| 754 if not constructor_info: | |
| 755 (constructor_info, factory_provider) = self._EmitElementFactory(typename) | |
| 756 | |
| 757 if typename in interface_factories: | 782 if typename in interface_factories: |
| 758 factory_provider = interface_factories[typename] | 783 factory_provider = interface_factories[typename] |
| 759 | 784 |
| 785 constructors = [] |
| 786 constructor_info = AnalyzeConstructor(self._interface) |
| 787 if constructor_info: |
| 788 constructors.append(constructor_info) |
| 789 factory_provider = '_' + typename + 'FactoryProvider'; |
| 790 |
| 791 infos = HtmlElementConstructorInfos(typename) |
| 792 for info in infos: |
| 793 constructors.append(info.ConstructorInfo(typename)) |
| 794 if factory_provider: |
| 795 assert factory_provider == info.factory_provider_name |
| 796 else: |
| 797 factory_provider = info.factory_provider_name |
| 798 |
| 760 if factory_provider: | 799 if factory_provider: |
| 761 extends_str += ' default ' + factory_provider | 800 extends_str += ' default ' + factory_provider |
| 762 | 801 |
| 763 # TODO(vsm): Add appropriate package / namespace syntax. | 802 # TODO(vsm): Add appropriate package / namespace syntax. |
| 764 (self._type_comment_emitter, | 803 (self._type_comment_emitter, |
| 765 self._members_emitter, | 804 self._members_emitter, |
| 766 self._top_level_emitter) = self._emitter.Emit( | 805 self._top_level_emitter) = self._emitter.Emit( |
| 767 self._template + '$!TOP_LEVEL', | 806 self._template + '$!TOP_LEVEL', |
| 768 ID=typename, | 807 ID=typename, |
| 769 EXTENDS=extends_str) | 808 EXTENDS=extends_str) |
| 770 | 809 |
| 771 self._type_comment_emitter.Emit("/// @domName $DOMNAME", | 810 self._type_comment_emitter.Emit("/// @domName $DOMNAME", |
| 772 DOMNAME=self._interface.doc_js_name) | 811 DOMNAME=self._interface.doc_js_name) |
| 773 | 812 |
| 774 if constructor_info: | 813 for constructor_info in constructors: |
| 775 self._members_emitter.Emit( | 814 self._members_emitter.Emit( |
| 776 '\n' | 815 '\n' |
| 777 ' $CTOR($PARAMS);\n', | 816 ' $CTOR($PARAMS);\n', |
| 778 CTOR=typename, | 817 CTOR=constructor_info.ConstructorFullName(), |
| 779 PARAMS=constructor_info.ParametersInterfaceDeclaration()); | 818 PARAMS=constructor_info.ParametersInterfaceDeclaration()); |
| 780 | 819 |
| 781 element_type = MaybeTypedArrayElementTypeInHierarchy( | 820 element_type = MaybeTypedArrayElementTypeInHierarchy( |
| 782 self._interface, self._system._database) | 821 self._interface, self._system._database) |
| 783 if element_type: | 822 if element_type: |
| 784 self._members_emitter.Emit( | 823 self._members_emitter.Emit( |
| 785 '\n' | 824 '\n' |
| 786 ' $CTOR(int length);\n' | 825 ' $CTOR(int length);\n' |
| 787 '\n' | 826 '\n' |
| 788 ' $CTOR.fromList(List<$TYPE> list);\n' | 827 ' $CTOR.fromList(List<$TYPE> list);\n' |
| 789 '\n' | 828 '\n' |
| 790 ' $CTOR.fromBuffer(ArrayBuffer buffer,' | 829 ' $CTOR.fromBuffer(ArrayBuffer buffer,' |
| 791 ' [int byteOffset, int length]);\n', | 830 ' [int byteOffset, int length]);\n', |
| 792 CTOR=self._interface.id, | 831 CTOR=self._interface.id, |
| 793 TYPE=DartType(element_type)) | 832 TYPE=DartType(element_type)) |
| 794 | 833 |
| 795 emit_events, events = self._shared.GetEventAttributes(self._interface) | 834 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 796 if not emit_events: | 835 if not emit_events: |
| 797 return | 836 return |
| 798 elif events: | 837 elif events: |
| 799 self.AddEventAttributes(events) | 838 self.AddEventAttributes(events) |
| 800 else: | 839 else: |
| 801 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) | 840 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) |
| 802 | 841 |
| 803 def _EmitElementFactory(self, typename): | |
| 804 """Returns pair (constructor_info, factory_provider_name).""" | |
| 805 if typename not in _html_element_constructors: | |
| 806 return (None, None) | |
| 807 info = _html_element_constructors[typename] | |
| 808 if isinstance(info, str): info = ElementCtorInfo(tag=info) | |
| 809 constructor_info = info.ConstructorInfo(self._interface) | |
| 810 em = self._system._EmitterForFactoryProviderBody(info.factory_provider_name) | |
| 811 inits = em.Emit( | |
| 812 '\n' | |
| 813 ' factory $INTERFACE($PARAMS) {\n' | |
| 814 ' $INTERFACE _e = _document.$dom_createElement("$TAG");\n' | |
| 815 '$!INITS' | |
| 816 ' return _e;\n' | |
| 817 ' }\n', | |
| 818 INTERFACE=typename, | |
| 819 TAG=info.tag, | |
| 820 PARAMS=constructor_info.ParametersInterfaceDeclaration()) | |
| 821 for param in constructor_info.param_infos: | |
| 822 inits.Emit(' if ($E != null) _e.$E = $E;\n', E=param.name) | |
| 823 | |
| 824 return (constructor_info, info.factory_provider_name) | |
| 825 | |
| 826 | 842 |
| 827 def AddAttribute(self, getter, setter): | 843 def AddAttribute(self, getter, setter): |
| 828 dom_name = DartDomNameOfAttribute(getter) | 844 dom_name = DartDomNameOfAttribute(getter) |
| 829 html_getter_name = self._shared.RenameInHtmlLibrary( | 845 html_getter_name = self._shared.RenameInHtmlLibrary( |
| 830 self._interface.id, dom_name, 'get:') | 846 self._interface.id, dom_name, 'get:') |
| 831 html_setter_name = self._shared.RenameInHtmlLibrary( | 847 html_setter_name = self._shared.RenameInHtmlLibrary( |
| 832 self._interface.id, dom_name, 'set:') | 848 self._interface.id, dom_name, 'set:') |
| 833 | 849 |
| 834 if not html_getter_name or self._shared.IsPrivate(html_getter_name): | 850 if not html_getter_name or self._shared.IsPrivate(html_getter_name): |
| 835 getter = None | 851 getter = None |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 NATIVESPEC=' native "' + native_spec + '"') | 982 NATIVESPEC=' native "' + native_spec + '"') |
| 967 if self._members_emitter == None: | 983 if self._members_emitter == None: |
| 968 raise Exception("Class %s doesn't use the $!MEMBERS variable" % | 984 raise Exception("Class %s doesn't use the $!MEMBERS variable" % |
| 969 self._class_name) | 985 self._class_name) |
| 970 | 986 |
| 971 # Emit a factory provider class for the constructor. | 987 # Emit a factory provider class for the constructor. |
| 972 constructor_info = AnalyzeConstructor(interface) | 988 constructor_info = AnalyzeConstructor(interface) |
| 973 if constructor_info: | 989 if constructor_info: |
| 974 self._EmitFactoryProvider(interface_name, constructor_info) | 990 self._EmitFactoryProvider(interface_name, constructor_info) |
| 975 | 991 |
| 992 infos = HtmlElementConstructorInfos(interface_name) |
| 993 if infos: |
| 994 self._EmitHtmlElementFactoryConstructors(infos) |
| 995 |
| 976 emit_events, events = self._shared.GetEventAttributes(self._interface) | 996 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 977 if not emit_events: | 997 if not emit_events: |
| 978 return | 998 return |
| 979 elif events: | 999 elif events: |
| 980 self.AddEventAttributes(events) | 1000 self.AddEventAttributes(events) |
| 981 else: | 1001 else: |
| 982 parent_events_class = self._shared.GetParentEventsClass(self._interface) | 1002 parent_events_class = self._shared.GetParentEventsClass(self._interface) |
| 983 self._EmitEventGetter('_' + parent_events_class + 'Impl') | 1003 self._EmitEventGetter('_' + parent_events_class + 'Impl') |
| 984 | 1004 |
| 985 def _EmitFactoryProvider(self, interface_name, constructor_info): | 1005 def _EmitFactoryProvider(self, interface_name, constructor_info): |
| 986 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 1006 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
| 987 template = self._system._templates.TryLoad(template_file) | 1007 template = self._system._templates.TryLoad(template_file) |
| 988 if not template: | 1008 if not template: |
| 989 template = self._system._templates.Load('factoryprovider.darttemplate') | 1009 template = self._system._templates.Load('factoryprovider.darttemplate') |
| 990 | 1010 |
| 991 factory_provider = '_' + interface_name + 'FactoryProvider' | 1011 factory_provider = '_' + interface_name + 'FactoryProvider' |
| 992 emitter = self._system._ImplFileEmitter(factory_provider) | 1012 emitter = self._system._ImplFileEmitter(factory_provider) |
| 993 emitter.Emit( | 1013 emitter.Emit( |
| 994 template, | 1014 template, |
| 995 FACTORYPROVIDER=factory_provider, | 1015 FACTORYPROVIDER=factory_provider, |
| 996 CONSTRUCTOR=interface_name, | 1016 CONSTRUCTOR=interface_name, |
| 997 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), | 1017 PARAMETERS=constructor_info.ParametersImplementationDeclaration(), |
| 998 NAMED_CONSTRUCTOR=constructor_info.name or interface_name, | 1018 NAMED_CONSTRUCTOR=constructor_info.name or interface_name, |
| 999 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 1019 ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
| 1000 | 1020 |
| 1021 def _EmitHtmlElementFactoryConstructors(self, infos): |
| 1022 EmitHtmlElementFactoryConstructors( |
| 1023 self._system._EmitterForFactoryProviderBody( |
| 1024 infos[0].factory_provider_name), |
| 1025 infos, |
| 1026 self._interface.id, self._class_name) |
| 1027 |
| 1001 def AddIndexer(self, element_type): | 1028 def AddIndexer(self, element_type): |
| 1002 """Adds all the methods required to complete implementation of List.""" | 1029 """Adds all the methods required to complete implementation of List.""" |
| 1003 # We would like to simply inherit the implementation of everything except | 1030 # We would like to simply inherit the implementation of everything except |
| 1004 # get length(), [], and maybe []=. It is possible to extend from a base | 1031 # get length(), [], and maybe []=. It is possible to extend from a base |
| 1005 # array implementation class only when there is no other implementation | 1032 # array implementation class only when there is no other implementation |
| 1006 # inheritance. There might be no implementation inheritance other than | 1033 # inheritance. There might be no implementation inheritance other than |
| 1007 # DOMBaseWrapper for many classes, but there might be some where the | 1034 # DOMBaseWrapper for many classes, but there might be some where the |
| 1008 # array-ness is introduced by a non-root interface: | 1035 # array-ness is introduced by a non-root interface: |
| 1009 # | 1036 # |
| 1010 # interface Y extends X, List<T> ... | 1037 # interface Y extends X, List<T> ... |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 TYPE=events_class) | 1243 TYPE=events_class) |
| 1217 | 1244 |
| 1218 # ------------------------------------------------------------------------------ | 1245 # ------------------------------------------------------------------------------ |
| 1219 | 1246 |
| 1220 class HtmlFrogSystem(HtmlSystem): | 1247 class HtmlFrogSystem(HtmlSystem): |
| 1221 | 1248 |
| 1222 def __init__(self, templates, database, emitters, output_dir): | 1249 def __init__(self, templates, database, emitters, output_dir): |
| 1223 super(HtmlFrogSystem, self).__init__( | 1250 super(HtmlFrogSystem, self).__init__( |
| 1224 templates, database, emitters, output_dir) | 1251 templates, database, emitters, output_dir) |
| 1225 self._dart_frog_file_paths = [] | 1252 self._dart_frog_file_paths = [] |
| 1226 | 1253 self._factory_provider_emitters = {} |
| 1227 | 1254 |
| 1228 def InterfaceGenerator(self, | 1255 def InterfaceGenerator(self, |
| 1229 interface, | 1256 interface, |
| 1230 common_prefix, | 1257 common_prefix, |
| 1231 super_interface_name, | 1258 super_interface_name, |
| 1232 source_filter): | 1259 source_filter): |
| 1233 """.""" | 1260 """.""" |
| 1234 template_file = 'impl_%s.darttemplate' % interface.id | 1261 template_file = 'impl_%s.darttemplate' % interface.id |
| 1235 template = self._templates.TryLoad(template_file) | 1262 template = self._templates.TryLoad(template_file) |
| 1236 if not template: | 1263 if not template: |
| 1237 template = self._templates.Load('frog_impl.darttemplate') | 1264 template = self._templates.Load('frog_impl.darttemplate') |
| 1238 | 1265 |
| 1239 dart_code = self._ImplFileEmitter(interface.id) | 1266 dart_code = self._ImplFileEmitter(interface.id) |
| 1240 return HtmlFrogClassGenerator(self, interface, template, | 1267 return HtmlFrogClassGenerator(self, interface, template, |
| 1241 super_interface_name, dart_code, self._shared) | 1268 super_interface_name, dart_code, self._shared) |
| 1242 | 1269 |
| 1243 def GenerateLibraries(self): | 1270 def GenerateLibraries(self): |
| 1244 self._GenerateLibFile( | 1271 self._GenerateLibFile( |
| 1245 'html_frog.darttemplate', | 1272 'html_frog.darttemplate', |
| 1246 os.path.join(self._output_dir, 'html_frog.dart'), | 1273 os.path.join(self._output_dir, 'html_frog.dart'), |
| 1247 (self._interface_system._dart_interface_file_paths + | 1274 (self._interface_system._dart_interface_file_paths + |
| 1248 self._interface_system._dart_callback_file_paths + | 1275 self._interface_system._dart_callback_file_paths + |
| 1249 self._dart_frog_file_paths)) | 1276 self._dart_frog_file_paths)) |
| 1250 | 1277 |
| 1251 def Finish(self): | 1278 def Finish(self): |
| 1252 pass | 1279 pass |
| 1253 | 1280 |
| 1254 def _ImplFileEmitter(self, name): | 1281 def _ImplFileEmitter(self, name): |
| 1255 """Returns the file emitter of the Frog implementation file.""" | 1282 """Returns the file emitter of the Frog implementation file.""" |
| 1256 # TODO(jmesserly): is this the right path | |
| 1257 path = os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) | 1283 path = os.path.join(self._output_dir, 'html', 'frog', '%s.dart' % name) |
| 1258 self._dart_frog_file_paths.append(path) | 1284 self._dart_frog_file_paths.append(path) |
| 1259 return self._emitters.FileEmitter(path) | 1285 return self._emitters.FileEmitter(path) |
| 1260 | 1286 |
| 1287 def _EmitterForFactoryProviderBody(self, name): |
| 1288 if name not in self._factory_provider_emitters: |
| 1289 template = self._templates.Load('factoryprovider_%s.darttemplate' % name) |
| 1290 file_emitter = self._ImplFileEmitter(name) |
| 1291 self._factory_provider_emitters[name] = file_emitter.Emit(template) |
| 1292 return self._factory_provider_emitters[name] |
| 1293 |
| 1261 # ----------------------------------------------------------------------------- | 1294 # ----------------------------------------------------------------------------- |
| 1262 | 1295 |
| 1263 class HtmlDartiumSystem(HtmlSystem): | 1296 class HtmlDartiumSystem(HtmlSystem): |
| 1264 | 1297 |
| 1265 def __init__(self, templates, database, emitters, auxiliary_dir, | 1298 def __init__(self, templates, database, emitters, auxiliary_dir, |
| 1266 dom_implementation_classes, output_dir): | 1299 dom_implementation_classes, output_dir): |
| 1267 """Prepared for generating wrapping implementation. | 1300 """Prepared for generating wrapping implementation. |
| 1268 | 1301 |
| 1269 - Creates emitter for Dart code. | 1302 - Creates emitter for Dart code. |
| 1270 """ | 1303 """ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 Collect(database.GetInterface(parent.type.id), | 1350 Collect(database.GetInterface(parent.type.id), |
| 1318 seen, collected) | 1351 seen, collected) |
| 1319 | 1352 |
| 1320 inheritance_closure = {} | 1353 inheritance_closure = {} |
| 1321 for interface in database.GetInterfaces(): | 1354 for interface in database.GetInterfaces(): |
| 1322 seen = set() | 1355 seen = set() |
| 1323 collected = [] | 1356 collected = [] |
| 1324 Collect(interface, seen, collected) | 1357 Collect(interface, seen, collected) |
| 1325 inheritance_closure[interface.id] = collected | 1358 inheritance_closure[interface.id] = collected |
| 1326 return inheritance_closure | 1359 return inheritance_closure |
| OLD | NEW |