Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: sdk/lib/html/scripts/systemhtml.py

Issue 11308075: Add custom annotations to some APIs for native tree shaking. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 499
500 # If the type has a conversion we need a getter or setter to contain the 500 # If the type has a conversion we need a getter or setter to contain the
501 # conversion code. 501 # conversion code.
502 if (self._OutputConversion(attribute.type.id, attribute.id) or 502 if (self._OutputConversion(attribute.type.id, attribute.id) or
503 self._InputConversion(attribute.type.id, attribute.id)): 503 self._InputConversion(attribute.type.id, attribute.id)):
504 self._AddAttributeUsingProperties(attribute, html_name, read_only) 504 self._AddAttributeUsingProperties(attribute, html_name, read_only)
505 return 505 return
506 506
507 output_type = self.SecureOutputType(attribute.type.id) 507 output_type = self.SecureOutputType(attribute.type.id)
508 input_type = self._NarrowInputType(attribute.type.id) 508 input_type = self._NarrowInputType(attribute.type.id)
509 annotations = self._Annotations(attribute.type.id, attribute.id)
509 self.EmitAttributeDocumentation(attribute) 510 self.EmitAttributeDocumentation(attribute)
510 if not read_only: 511 if not read_only:
511 self._members_emitter.Emit( 512 self._members_emitter.Emit(
512 '\n $TYPE $NAME;' 513 '\n $ANNOTATIONS$TYPE $NAME;'
513 '\n', 514 '\n',
515 ANNOTATIONS=annotations,
514 NAME=DartDomNameOfAttribute(attribute), 516 NAME=DartDomNameOfAttribute(attribute),
515 TYPE=output_type) 517 TYPE=output_type)
516 else: 518 else:
517 self._members_emitter.Emit( 519 self._members_emitter.Emit(
518 '\n final $TYPE $NAME;' 520 '\n $(ANNOTATIONS)final $TYPE $NAME;'
519 '\n', 521 '\n',
522 ANNOTATIONS=annotations,
520 NAME=DartDomNameOfAttribute(attribute), 523 NAME=DartDomNameOfAttribute(attribute),
521 TYPE=output_type) 524 TYPE=output_type)
522 525
523 def _AddAttributeUsingProperties(self, attribute, html_name, read_only): 526 def _AddAttributeUsingProperties(self, attribute, html_name, read_only):
524 self._AddRenamingGetter(attribute, html_name) 527 self._AddRenamingGetter(attribute, html_name)
525 if not read_only: 528 if not read_only:
526 self._AddRenamingSetter(attribute, html_name) 529 self._AddRenamingSetter(attribute, html_name)
527 530
528 def _AddInterfaceAttribute(self, attribute): 531 def _AddInterfaceAttribute(self, attribute):
529 self._members_emitter.Emit( 532 self._members_emitter.Emit(
530 '\n $TYPE $NAME;' 533 '\n $TYPE $NAME;'
531 '\n', 534 '\n',
532 NAME=DartDomNameOfAttribute(attribute), 535 NAME=DartDomNameOfAttribute(attribute),
533 TYPE=self.SecureOutputType(attribute.type.id)) 536 TYPE=self.SecureOutputType(attribute.type.id))
534 537
535 def _AddRenamingGetter(self, attr, html_name): 538 def _AddRenamingGetter(self, attr, html_name):
536 self.EmitAttributeDocumentation(attr) 539 self.EmitAttributeDocumentation(attr)
537 540
538 conversion = self._OutputConversion(attr.type.id, attr.id) 541 conversion = self._OutputConversion(attr.type.id, attr.id)
539 if conversion: 542 if conversion:
540 return self._AddConvertingGetter(attr, html_name, conversion) 543 return self._AddConvertingGetter(attr, html_name, conversion)
541 return_type = self.SecureOutputType(attr.type.id) 544 return_type = self.SecureOutputType(attr.type.id)
545 print '** ',attr.type.id, self._DartType(attr.type.id)
blois 2012/11/19 20:46:48 Debugging?
sra1 2012/11/19 23:15:07 Done.
542 self._members_emitter.Emit( 546 self._members_emitter.Emit(
543 # TODO(sra): Use metadata to provide native name. 547 # TODO(sra): Use metadata to provide native name.
544 '\n $TYPE get $HTML_NAME => JS("$TYPE", "#.$NAME", this);' 548 '\n $TYPE get $HTML_NAME => JS("$TYPE", "#.$NAME", this);'
545 '\n', 549 '\n',
546 HTML_NAME=html_name, 550 HTML_NAME=html_name,
547 NAME=attr.id, 551 NAME=attr.id,
548 TYPE=return_type) 552 TYPE=return_type)
549 553
550 def _AddRenamingSetter(self, attr, html_name): 554 def _AddRenamingSetter(self, attr, html_name):
551 self.EmitAttributeDocumentation(attr) 555 self.EmitAttributeDocumentation(attr)
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 # Any conversions needed? 615 # Any conversions needed?
612 self._AddOperationWithConversions(info, html_name) 616 self._AddOperationWithConversions(info, html_name)
613 else: 617 else:
614 self._AddDirectNativeOperation(info, html_name) 618 self._AddDirectNativeOperation(info, html_name)
615 619
616 def _AddDirectNativeOperation(self, info, html_name): 620 def _AddDirectNativeOperation(self, info, html_name):
617 # Do we need a native body? 621 # Do we need a native body?
618 if html_name != info.declared_name: 622 if html_name != info.declared_name:
619 return_type = self.SecureOutputType(info.type_name) 623 return_type = self.SecureOutputType(info.type_name)
620 624
621 operation_emitter = self._members_emitter.Emit('$!SCOPE', 625 operation_emitter = self._members_emitter.Emit(
626 '$!SCOPE',
622 MODIFIERS='static ' if info.IsStatic() else '', 627 MODIFIERS='static ' if info.IsStatic() else '',
628 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name),
623 TYPE=return_type, 629 TYPE=return_type,
624 HTML_NAME=html_name, 630 HTML_NAME=html_name,
625 NAME=info.declared_name, 631 NAME=info.declared_name,
626 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) 632 PARAMS=info.ParametersDeclaration(self._NarrowInputType))
627 633
628 operation_emitter.Emit( 634 operation_emitter.Emit(
629 '\n' 635 '\n'
630 #' // @native("$NAME")\n;' 636 ' $ANNOTATIONS'
631 ' $MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') 637 '$MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n')
632 else: 638 else:
633 self._members_emitter.Emit( 639 self._members_emitter.Emit(
634 '\n' 640 '\n'
635 ' $MODIFIERS$TYPE $NAME($PARAMS) native;\n', 641 ' $ANNOTATIONS$MODIFIERS$TYPE $NAME($PARAMS) native;\n',
636 MODIFIERS='static ' if info.IsStatic() else '', 642 MODIFIERS='static ' if info.IsStatic() else '',
643 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name),
637 TYPE=self.SecureOutputType(info.type_name), 644 TYPE=self.SecureOutputType(info.type_name),
638 NAME=info.name, 645 NAME=info.name,
639 PARAMS=info.ParametersDeclaration(self._NarrowInputType)) 646 PARAMS=info.ParametersDeclaration(self._NarrowInputType))
640 647
641 def _AddOperationWithConversions(self, info, html_name): 648 def _AddOperationWithConversions(self, info, html_name):
642 # Assert all operations have same return type. 649 # Assert all operations have same return type.
643 assert len(set([op.type.id for op in info.operations])) == 1 650 assert len(set([op.type.id for op in info.operations])) == 1
644 output_conversion = self._OutputConversion(info.type_name, 651 output_conversion = self._OutputConversion(info.type_name,
645 info.declared_name) 652 info.declared_name)
646 if output_conversion: 653 if output_conversion:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 if output_conversion: 735 if output_conversion:
729 call = '%s(%s)' % (output_conversion.function_name, call) 736 call = '%s(%s)' % (output_conversion.function_name, call)
730 737
731 if operation.type.id == 'void': 738 if operation.type.id == 'void':
732 call_emitter.Emit('$(INDENT)$CALL;\n$(INDENT)return;\n', 739 call_emitter.Emit('$(INDENT)$CALL;\n$(INDENT)return;\n',
733 CALL=call) 740 CALL=call)
734 else: 741 else:
735 call_emitter.Emit('$(INDENT)return $CALL;\n', CALL=call) 742 call_emitter.Emit('$(INDENT)return $CALL;\n', CALL=call)
736 743
737 self._members_emitter.Emit( 744 self._members_emitter.Emit(
738 ' $TYPE$TARGET($PARAMS) native "$NATIVE";\n', 745 ' $ANNOTATIONS$TYPE$TARGET($PARAMS) native "$NATIVE";\n',
746 ANNOTATIONS=self._Annotations(info.type_name, info.declared_name),
739 TYPE=TypeOrNothing(native_return_type), 747 TYPE=TypeOrNothing(native_return_type),
740 TARGET=target, 748 TARGET=target,
741 PARAMS=', '.join(target_parameters), 749 PARAMS=', '.join(target_parameters),
742 NATIVE=info.declared_name) 750 NATIVE=info.declared_name)
743 751
744 def GenerateChecksAndCall(operation, argument_count): 752 def GenerateChecksAndCall(operation, argument_count):
745 checks = [] 753 checks = []
746 for i in range(0, argument_count): 754 for i in range(0, argument_count):
747 argument = operation.arguments[i] 755 argument = operation.arguments[i]
748 parameter_name = parameter_names[i] 756 parameter_name = parameter_names[i]
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 return FindConversion(idl_type, 'get', self._interface.id, member) 820 return FindConversion(idl_type, 'get', self._interface.id, member)
813 821
814 def _InputConversion(self, idl_type, member): 822 def _InputConversion(self, idl_type, member):
815 return FindConversion(idl_type, 'set', self._interface.id, member) 823 return FindConversion(idl_type, 'set', self._interface.id, member)
816 824
817 def _HasCustomImplementation(self, member_name): 825 def _HasCustomImplementation(self, member_name):
818 member_name = '%s.%s' % (self._interface_type_info.interface_name(), 826 member_name = '%s.%s' % (self._interface_type_info.interface_name(),
819 member_name) 827 member_name)
820 return member_name in _js_custom_members 828 return member_name in _js_custom_members
821 829
830 def _Annotations(self, idl_type, member_name):
831 annotations = FindAnnotations(idl_type, self._interface.id, member_name)
832 if annotations:
833 return '%s\n ' % annotations
834 else:
835 return ''
836
822 def CustomJSMembers(self): 837 def CustomJSMembers(self):
823 return _js_custom_members 838 return _js_custom_members
824 839
825 def _NarrowToImplementationType(self, type_name): 840 def _NarrowToImplementationType(self, type_name):
826 return self._type_registry.TypeInfo(type_name).narrow_dart_type() 841 return self._type_registry.TypeInfo(type_name).narrow_dart_type()
827 842
828 def _NarrowInputType(self, type_name): 843 def _NarrowInputType(self, type_name):
829 return self._NarrowToImplementationType(type_name) 844 return self._NarrowToImplementationType(type_name)
830 845
831 def _FindShadowedAttribute(self, attr): 846 def _FindShadowedAttribute(self, attr):
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 'svg': DartLibrary('svg', template_loader, library_type, output_dir), 941 'svg': DartLibrary('svg', template_loader, library_type, output_dir),
927 'html': DartLibrary('html', template_loader, library_type, output_dir), 942 'html': DartLibrary('html', template_loader, library_type, output_dir),
928 } 943 }
929 944
930 def AddFile(self, basename, library_name, path): 945 def AddFile(self, basename, library_name, path):
931 self._libraries[library_name].AddFile(path) 946 self._libraries[library_name].AddFile(path)
932 947
933 def Emit(self, emitter, auxiliary_dir): 948 def Emit(self, emitter, auxiliary_dir):
934 for lib in self._libraries.values(): 949 for lib in self._libraries.values():
935 lib.Emit(emitter, auxiliary_dir) 950 lib.Emit(emitter, auxiliary_dir)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698