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