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 os | 9 import os |
10 from generator import * | 10 from generator import * |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 def StartInterface(self): | 505 def StartInterface(self): |
506 typename = self._interface.id | 506 typename = self._interface.id |
507 | 507 |
508 extends = [] | 508 extends = [] |
509 suppressed_extends = [] | 509 suppressed_extends = [] |
510 | 510 |
511 for parent in self._interface.parents: | 511 for parent in self._interface.parents: |
512 # TODO(vsm): Remove source_filter. | 512 # TODO(vsm): Remove source_filter. |
513 if MatchSourceFilter(self._source_filter, parent): | 513 if MatchSourceFilter(self._source_filter, parent): |
514 # Parent is a DOM type. | 514 # Parent is a DOM type. |
515 extends.append(parent.type.id) | 515 extends.append(DartType(parent.type.id)) |
516 elif '<' in parent.type.id: | 516 elif '<' in parent.type.id: |
517 # Parent is a Dart collection type. | 517 # Parent is a Dart collection type. |
518 # TODO(vsm): Make this check more robust. | 518 # TODO(vsm): Make this check more robust. |
519 extends.append(parent.type.id) | 519 extends.append(parent.type.id) |
520 else: | 520 else: |
521 suppressed_extends.append('%s.%s' % | 521 suppressed_extends.append('%s.%s' % |
522 (self._common_prefix, parent.type.id)) | 522 (self._common_prefix, parent.type.id)) |
523 | 523 |
524 comment = ' extends' | 524 comment = ' extends' |
525 extends_str = '' | 525 extends_str = '' |
(...skipping 16 matching lines...) Expand all Loading... |
542 element_type = MaybeTypedArrayElementType(self._interface) | 542 element_type = MaybeTypedArrayElementType(self._interface) |
543 if element_type: | 543 if element_type: |
544 self._members_emitter.Emit( | 544 self._members_emitter.Emit( |
545 '\n' | 545 '\n' |
546 ' $CTOR(int length);\n' | 546 ' $CTOR(int length);\n' |
547 '\n' | 547 '\n' |
548 ' $CTOR.fromList(List<$TYPE> list);\n' | 548 ' $CTOR.fromList(List<$TYPE> list);\n' |
549 '\n' | 549 '\n' |
550 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | 550 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', |
551 CTOR=self._interface.id, | 551 CTOR=self._interface.id, |
552 TYPE=element_type) | 552 TYPE=DartType(element_type)) |
553 | 553 |
554 def AddAttribute(self, getter, setter): | 554 def AddAttribute(self, getter, setter): |
555 if getter and not self._system._AllowInHtmlLibrary(self._interface, | 555 if getter and not self._system._AllowInHtmlLibrary(self._interface, |
556 'get:' + getter.id): | 556 'get:' + getter.id): |
557 getter = None | 557 getter = None |
558 if setter and not self._system._AllowInHtmlLibrary(self._interface, | 558 if setter and not self._system._AllowInHtmlLibrary(self._interface, |
559 'set:' + setter.id): | 559 'set:' + setter.id): |
560 setter = None | 560 setter = None |
561 if not getter and not setter: | 561 if not getter and not setter: |
562 return | 562 return |
563 if getter and setter and getter.type.id == setter.type.id: | 563 if getter and setter and DartType(getter.type.id) == DartType(setter.type.id
): |
564 self._members_emitter.Emit('\n $TYPE $NAME;\n', | 564 self._members_emitter.Emit('\n $TYPE $NAME;\n', |
565 NAME=getter.id, TYPE=getter.type.id); | 565 NAME=getter.id, TYPE=DartType(getter.type.id)); |
566 return | 566 return |
567 if getter and not setter: | 567 if getter and not setter: |
568 self._members_emitter.Emit('\n final $TYPE $NAME;\n', | 568 self._members_emitter.Emit('\n final $TYPE $NAME;\n', |
569 NAME=getter.id, TYPE=getter.type.id); | 569 NAME=getter.id, TYPE=DartType(getter.type.id)); |
570 return | 570 return |
571 raise Exception('Unexpected getter/setter combination %s %s' % | 571 raise Exception('Unexpected getter/setter combination %s %s' % |
572 (getter, setter)) | 572 (getter, setter)) |
573 | 573 |
574 def AddOperation(self, info): | 574 def AddOperation(self, info): |
575 """ | 575 """ |
576 Arguments: | 576 Arguments: |
577 operations - contains the overloads, one or more operations with the same | 577 operations - contains the overloads, one or more operations with the same |
578 name. | 578 name. |
579 """ | 579 """ |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 base = self._ImplClassName(supertype) | 654 base = self._ImplClassName(supertype) |
655 | 655 |
656 native_spec = MakeNativeSpec(interface.javascript_binding_name) | 656 native_spec = MakeNativeSpec(interface.javascript_binding_name) |
657 | 657 |
658 extends = ' extends ' + base if base else '' | 658 extends = ' extends ' + base if base else '' |
659 | 659 |
660 # TODO: Include all implemented interfaces, including other Lists. | 660 # TODO: Include all implemented interfaces, including other Lists. |
661 implements = [interface_name] | 661 implements = [interface_name] |
662 element_type = MaybeTypedArrayElementType(self._interface) | 662 element_type = MaybeTypedArrayElementType(self._interface) |
663 if element_type: | 663 if element_type: |
664 implements.append('List<' + element_type + '>') | 664 implements.append('List<%s>' % DartType(element_type)) |
665 | 665 |
666 self._members_emitter = self._dart_code.Emit( | 666 self._members_emitter = self._dart_code.Emit( |
667 self._template, | 667 self._template, |
668 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 668 #class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
669 #$!MEMBERS | 669 #$!MEMBERS |
670 #} | 670 #} |
671 CLASSNAME=self._class_name, | 671 CLASSNAME=self._class_name, |
672 EXTENDS=extends, | 672 EXTENDS=extends, |
673 IMPLEMENTS=' implements ' + ', '.join(implements), | 673 IMPLEMENTS=' implements ' + ', '.join(implements), |
674 NATIVESPEC=' native "' + native_spec + '"') | 674 NATIVESPEC=' native "' + native_spec + '"') |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } | 1033 # class YImpl extends ListBase<T> { copies of transitive XImpl methods; } |
1034 # | 1034 # |
1035 if self._HasNativeIndexGetter(self._interface): | 1035 if self._HasNativeIndexGetter(self._interface): |
1036 self._EmitNativeIndexGetter(self._interface, element_type) | 1036 self._EmitNativeIndexGetter(self._interface, element_type) |
1037 else: | 1037 else: |
1038 self._members_emitter.Emit( | 1038 self._members_emitter.Emit( |
1039 '\n' | 1039 '\n' |
1040 ' $TYPE operator[](int index) {\n' | 1040 ' $TYPE operator[](int index) {\n' |
1041 ' return item(index);\n' | 1041 ' return item(index);\n' |
1042 ' }\n', | 1042 ' }\n', |
1043 TYPE=element_type) | 1043 TYPE=DartType(element_type)) |
1044 | 1044 |
1045 if self._HasNativeIndexSetter(self._interface): | 1045 if self._HasNativeIndexSetter(self._interface): |
1046 self._EmitNativeIndexSetter(self._interface, element_type) | 1046 self._EmitNativeIndexSetter(self._interface, element_type) |
1047 else: | 1047 else: |
1048 self._members_emitter.Emit( | 1048 self._members_emitter.Emit( |
1049 '\n' | 1049 '\n' |
1050 ' void operator[]=(int index, $TYPE value) {\n' | 1050 ' void operator[]=(int index, $TYPE value) {\n' |
1051 ' throw new UnsupportedOperationException("Cannot assign element of
immutable List.");\n' | 1051 ' throw new UnsupportedOperationException("Cannot assign element of
immutable List.");\n' |
1052 ' }\n', | 1052 ' }\n', |
1053 TYPE=element_type) | 1053 TYPE=element_type) |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee | 1326 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee |
1327 # that Y = Z-X, so we need to check for Y. | 1327 # that Y = Z-X, so we need to check for Y. |
1328 true_code = emitter.Emit( | 1328 true_code = emitter.Emit( |
1329 '$(INDENT)if ($COND) {\n' | 1329 '$(INDENT)if ($COND) {\n' |
1330 '$!TRUE' | 1330 '$!TRUE' |
1331 '$(INDENT)}\n', | 1331 '$(INDENT)}\n', |
1332 COND=test, INDENT=indent) | 1332 COND=test, INDENT=indent) |
1333 self.GenerateDispatch( | 1333 self.GenerateDispatch( |
1334 true_code, info, indent + ' ', position + 1, positive) | 1334 true_code, info, indent + ' ', position + 1, positive) |
1335 return True | 1335 return True |
OLD | NEW |