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

Side by Side Diff: tools/dom/scripts/htmldartgenerator.py

Issue 14367012: Move to new dart:typeddata types for dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert generated files for html lib Created 7 years, 8 months 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 from generator import AnalyzeOperation, ConstantOutputOrder, \ 10 from generator import AnalyzeOperation, ConstantOutputOrder, \
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 fromBufferAnnotations = FormatAnnotationsAndComments( 380 fromBufferAnnotations = FormatAnnotationsAndComments(
381 GetAnnotationsAndComments(self._library_name, self._interface.id, 381 GetAnnotationsAndComments(self._library_name, self._interface.id,
382 'fromBuffer'), ' ') 382 'fromBuffer'), ' ')
383 383
384 if typed_array_type: 384 if typed_array_type:
385 self._members_emitter.Emit( 385 self._members_emitter.Emit(
386 '\n $(ANNOTATIONS)factory $CTOR(int length) =>\n' 386 '\n $(ANNOTATIONS)factory $CTOR(int length) =>\n'
387 ' $FACTORY.create$(CTOR)(length);\n' 387 ' $FACTORY.create$(CTOR)(length);\n'
388 '\n $(LIST_ANNOTATIONS)factory $CTOR.fromList(List<$TYPE> list) =>\n' 388 '\n $(LIST_ANNOTATIONS)factory $CTOR.fromList(List<$TYPE> list) =>\n'
389 ' $FACTORY.create$(CTOR)_fromList(list);\n' 389 ' $FACTORY.create$(CTOR)_fromList(list);\n'
390 '\n $(BUFFER_ANNOTATIONS)factory $CTOR.fromBuffer(ArrayBuffer buffer, ' 390 '\n $(BUFFER_ANNOTATIONS)factory $CTOR.view(ByteBuffer buffer, '
391 '[int byteOffset, int length]) => \n' 391 '[int byteOffset, int length]) => \n'
392 ' $FACTORY.create$(CTOR)_fromBuffer(buffer, byteOffset, length);\n' , 392 ' $FACTORY.create$(CTOR)_fromBuffer(buffer, byteOffset, length);\n' ,
393 CTOR=self._interface.id, 393 CTOR=self._renamer.RenameInterface(interface),
394 ANNOTATIONS=annotations, 394 ANNOTATIONS=annotations,
395 LIST_ANNOTATIONS=fromListAnnotations, 395 LIST_ANNOTATIONS=fromListAnnotations,
396 BUFFER_ANNOTATIONS=fromBufferAnnotations, 396 BUFFER_ANNOTATIONS=fromBufferAnnotations,
397 TYPE=self._DartType(typed_array_type), 397 TYPE=self._DartType(typed_array_type),
398 FACTORY=factory_name) 398 FACTORY=factory_name)
399 399
400 def _AddConstructor(self, 400 def _AddConstructor(self,
401 constructor_info, factory_name, factory_constructor_name): 401 constructor_info, factory_name, factory_constructor_name):
402 if self.GenerateCustomFactory(constructor_info): 402 if self.GenerateCustomFactory(constructor_info):
403 return 403 return
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 PARAMS=operation.ParametersDeclaration(self._DartType)) 579 PARAMS=operation.ParametersDeclaration(self._DartType))
580 580
581 def EmitListMixin(self, element_name): 581 def EmitListMixin(self, element_name):
582 # TODO(sra): Use separate mixins for mutable implementations of List<T>. 582 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
583 # TODO(sra): Use separate mixins for typed array implementations of List<T>. 583 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
584 template_file = 'immutable_list_mixin.darttemplate' 584 template_file = 'immutable_list_mixin.darttemplate'
585 has_contains = any(op.id == 'contains' for op in self._interface.operations) 585 has_contains = any(op.id == 'contains' for op in self._interface.operations)
586 has_clear = any(op.id == 'clear' for op in self._interface.operations) 586 has_clear = any(op.id == 'clear' for op in self._interface.operations)
587 has_length = False 587 has_length = False
588 has_length_setter = False 588 has_length_setter = False
589 typed_array = self._interface_type_info.is_typed_array()
590
589 for attr in self._interface.attributes: 591 for attr in self._interface.attributes:
590 if attr.id == 'length': 592 if attr.id == 'length':
591 has_length = True 593 has_length = True
592 has_length_setter = not attr.is_read_only 594 has_length_setter = not attr.is_read_only
593 595
594 has_num_items = any(attr.id == 'numberOfItems' 596 has_num_items = any(attr.id == 'numberOfItems'
595 for attr in self._interface.attributes) 597 for attr in self._interface.attributes)
596 598
597 template = self._template_loader.Load( 599 template = self._template_loader.Load(
598 template_file, 600 template_file,
599 { 601 {
600 'DEFINE_CONTAINS': not has_contains, 602 'DEFINE_CONTAINS': not has_contains,
601 'DEFINE_CLEAR': not has_clear, 603 'DEFINE_CLEAR': not has_clear,
604 'DEFINE_IMMUTABLE': not typed_array,
602 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items, 605 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items,
603 'DEFINE_LENGTH_SETTER': not has_length_setter, 606 'DEFINE_LENGTH_SETTER': not has_length_setter,
604 }) 607 })
605 self._members_emitter.Emit(template, E=element_name) 608 self._members_emitter.Emit(template, E=element_name)
606 609
607 def SecureOutputType(self, type_name, is_dart_type=False): 610 def SecureOutputType(self, type_name, is_dart_type=False):
608 """ Converts the type name to the secure type name for return types. 611 """ Converts the type name to the secure type name for return types.
609 """ 612 """
610 if is_dart_type: 613 if is_dart_type:
611 dart_name = type_name 614 dart_name = type_name
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 walk(interface.parents) 653 walk(interface.parents)
651 else: 654 else:
652 walk(interface.parents[1:]) 655 walk(interface.parents[1:])
653 return result 656 return result
654 657
655 def _DartType(self, type_name): 658 def _DartType(self, type_name):
656 return self._type_registry.DartType(type_name) 659 return self._type_registry.DartType(type_name)
657 660
658 def _IsPrivate(self, name): 661 def _IsPrivate(self, name):
659 return name.startswith('_') 662 return name.startswith('_')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698