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 import emitter | 9 import emitter |
10 | 10 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 'webkitSpeechChange': 'speechChange', | 210 'webkitSpeechChange': 'speechChange', |
211 'webkitsourceclose': 'sourceClose', | 211 'webkitsourceclose': 'sourceClose', |
212 'webkitsourceended': 'sourceEnded', | 212 'webkitsourceended': 'sourceEnded', |
213 'webkitsourceopen': 'sourceOpen', | 213 'webkitsourceopen': 'sourceOpen', |
214 'webkitTransitionEnd': 'transitionEnd', | 214 'webkitTransitionEnd': 'transitionEnd', |
215 'write': 'write', | 215 'write': 'write', |
216 'writeend': 'writeEnd', | 216 'writeend': 'writeEnd', |
217 'writestart': 'writeStart' | 217 'writestart': 'writeStart' |
218 } | 218 } |
219 | 219 |
220 | |
221 | |
222 # Information for generating element constructors. | 220 # Information for generating element constructors. |
223 # | 221 # |
224 # TODO(sra): maybe remove all the argument complexity and use cascades. | 222 # TODO(sra): maybe remove all the argument complexity and use cascades. |
225 # | 223 # |
226 # var c = new CanvasElement(width: 100, height: 70); | 224 # var c = new CanvasElement(width: 100, height: 70); |
227 # var c = new CanvasElement()..width = 100..height = 70; | 225 # var c = new CanvasElement()..width = 100..height = 70; |
228 # | 226 # |
229 class ElementConstructorInfo(object): | 227 class ElementConstructorInfo(object): |
230 def __init__(self, name=None, tag=None, | 228 def __init__(self, name=None, tag=None, |
231 params=[], opt_params=[], | 229 params=[], opt_params=[], |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 code.Emit('typedef $TYPE $NAME($PARAMS);\n', | 451 code.Emit('typedef $TYPE $NAME($PARAMS);\n', |
454 NAME=interface.id, | 452 NAME=interface.id, |
455 TYPE=DartType(info.type_name), | 453 TYPE=DartType(info.type_name), |
456 PARAMS=info.ParametersImplementationDeclaration(DartType)) | 454 PARAMS=info.ParametersImplementationDeclaration(DartType)) |
457 self._backend.ProcessCallback(interface, info) | 455 self._backend.ProcessCallback(interface, info) |
458 | 456 |
459 def GenerateLibraries(self): | 457 def GenerateLibraries(self): |
460 self._backend.GenerateLibraries(self._dart_file_paths) | 458 self._backend.GenerateLibraries(self._dart_file_paths) |
461 | 459 |
462 def _CreateEmitter(self, filename): | 460 def _CreateEmitter(self, filename): |
463 path = os.path.join(self._output_dir, 'dart', filename) | 461 is_native_class = filename[:-len('.dart')] in nativified_classes.values() |
vsm
2012/09/21 22:43:12
This feels brittle. If we change the file naming
Emily Fortuna
2012/09/22 00:13:52
Unfortunately not. The backend _Impl files are ver
| |
464 self._dart_file_paths.append(path) | 462 if is_native_class: |
465 return self._emitters.FileEmitter(path) | 463 return emitter.Emitter() |
464 else: | |
465 path = os.path.join(self._output_dir, 'dart', filename) | |
466 self._dart_file_paths.append(path) | |
467 return self._emitters.FileEmitter(path) | |
466 | 468 |
467 # ------------------------------------------------------------------------------ | 469 # ------------------------------------------------------------------------------ |
468 | 470 |
469 class HtmlDartInterfaceGenerator(BaseGenerator): | 471 class HtmlDartInterfaceGenerator(BaseGenerator): |
470 """Generates dart interface and implementation for the DOM IDL interface.""" | 472 """Generates dart interface and implementation for the DOM IDL interface.""" |
471 | 473 |
472 def __init__(self, system, interface): | 474 def __init__(self, system, interface): |
473 super(HtmlDartInterfaceGenerator, self).__init__( | 475 super(HtmlDartInterfaceGenerator, self).__init__( |
474 system._database, interface) | 476 system._database, interface) |
475 self._system = system | 477 self._system = system |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 self._top_level_emitter) = self._interface_emitter.Emit( | 557 self._top_level_emitter) = self._interface_emitter.Emit( |
556 interface_template + '$!TOP_LEVEL', | 558 interface_template + '$!TOP_LEVEL', |
557 ID=typename, | 559 ID=typename, |
558 EXTENDS=implements_str) | 560 EXTENDS=implements_str) |
559 | 561 |
560 self._type_comment_emitter.Emit("/// @domName $DOMNAME", | 562 self._type_comment_emitter.Emit("/// @domName $DOMNAME", |
561 DOMNAME=self._interface.doc_js_name) | 563 DOMNAME=self._interface.doc_js_name) |
562 | 564 |
563 if self._backend.HasImplementation(): | 565 if self._backend.HasImplementation(): |
564 if not self._interface.id in _merged_html_interfaces: | 566 if not self._interface.id in _merged_html_interfaces: |
565 filename = '%sImpl.dart' % self._html_interface_name | 567 name = self._html_interface_name |
568 if self._html_interface_name in nativified_classes: | |
569 name = nativified_classes[self._html_interface_name] | |
570 filename = '%sImpl.dart' % name | |
566 else: | 571 else: |
567 filename = '%sImpl_Merged.dart' % self._html_interface_name | 572 filename = '%sImpl_Merged.dart' % self._html_interface_name |
568 self._implementation_emitter = self._system._CreateEmitter(filename) | 573 self._implementation_emitter = self._system._CreateEmitter(filename) |
569 else: | 574 else: |
570 self._implementation_emitter = emitter.Emitter() | 575 self._implementation_emitter = emitter.Emitter() |
571 self._backend.SetImplementationEmitter(self._implementation_emitter) | 576 self._backend.SetImplementationEmitter(self._implementation_emitter) |
572 self._implementation_members_emitter = self._backend.StartInterface() | 577 self._implementation_members_emitter = self._backend.StartInterface() |
573 | 578 |
574 for constructor_info in constructors: | 579 for constructor_info in constructors: |
575 constructor_info.GenerateFactoryInvocation( | 580 constructor_info.GenerateFactoryInvocation( |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 def ImplementationClassName(self): | 780 def ImplementationClassName(self): |
776 return self._ImplClassName(self._html_interface_name) | 781 return self._ImplClassName(self._html_interface_name) |
777 | 782 |
778 def SetImplementationEmitter(self, implementation_emitter): | 783 def SetImplementationEmitter(self, implementation_emitter): |
779 self._dart_code = implementation_emitter | 784 self._dart_code = implementation_emitter |
780 | 785 |
781 def ImplementsMergedMembers(self): | 786 def ImplementsMergedMembers(self): |
782 return True | 787 return True |
783 | 788 |
784 def _ImplClassName(self, type_name): | 789 def _ImplClassName(self, type_name): |
785 return '_%sImpl' % type_name | 790 name = type_name |
791 if type_name in nativified_classes: | |
792 name = nativified_classes[type_name] | |
793 return '_%sImpl' % name | |
786 | 794 |
787 def StartInterface(self): | 795 def StartInterface(self): |
788 interface = self._interface | 796 interface = self._interface |
789 interface_name = interface.id | 797 interface_name = interface.id |
790 | 798 |
791 self._class_name = self._ImplClassName(self._html_interface_name) | 799 self._class_name = self._ImplClassName(self._html_interface_name) |
792 | 800 |
793 base = None | 801 base = None |
794 if interface.parents: | 802 if interface.parents: |
795 supertype = interface.parents[0].type.id | 803 supertype = interface.parents[0].type.id |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1229 def GenerateLibraries(self, dart_files): | 1237 def GenerateLibraries(self, dart_files): |
1230 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) | 1238 auxiliary_dir = os.path.relpath(self._auxiliary_dir, self._output_dir) |
1231 self._GenerateLibFile( | 1239 self._GenerateLibFile( |
1232 'html_dart2js.darttemplate', | 1240 'html_dart2js.darttemplate', |
1233 os.path.join(self._output_dir, 'html_dart2js.dart'), | 1241 os.path.join(self._output_dir, 'html_dart2js.dart'), |
1234 dart_files, | 1242 dart_files, |
1235 AUXILIARY_DIR=systembase.MassagePath(auxiliary_dir)) | 1243 AUXILIARY_DIR=systembase.MassagePath(auxiliary_dir)) |
1236 | 1244 |
1237 def Finish(self): | 1245 def Finish(self): |
1238 pass | 1246 pass |
OLD | NEW |