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

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

Issue 14036014: Updating DOM code to use list mixins (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 implements = [] 322 implements = []
323 if self._interface_type_info.is_typed_array(): 323 if self._interface_type_info.is_typed_array():
324 element_type = self._interface_type_info.list_item_type() 324 element_type = self._interface_type_info.list_item_type()
325 implements.append('List<%s>' % element_type) 325 implements.append('List<%s>' % element_type)
326 elif self._interface_type_info.list_item_type(): 326 elif self._interface_type_info.list_item_type():
327 item_type_info = self._type_registry.TypeInfo( 327 item_type_info = self._type_registry.TypeInfo(
328 self._interface_type_info.list_item_type()) 328 self._interface_type_info.list_item_type())
329 implements.append('List<%s>' % item_type_info.dart_type()) 329 implements.append('List<%s>' % item_type_info.dart_type())
330 return implements 330 return implements
331 331
332 def Mixins(self):
333 mixins = []
334 item_type = None
335 if self._interface_type_info.is_typed_array():
336 item_type = self._interface_type_info.list_item_type()
337 elif self._interface_type_info.list_item_type():
338 item_type = self._type_registry.TypeInfo(
339 self._interface_type_info.list_item_type()).dart_type()
340 if item_type:
341 mixins.append('ListMixin<%s>' % item_type)
342 mixins.append('ImmutableListMixin<%s>' % item_type)
343
344 return mixins
345
346
332 def AddConstructors(self, 347 def AddConstructors(self,
333 constructors, factory_name, factory_constructor_name): 348 constructors, factory_name, factory_constructor_name):
334 """ Adds all of the constructors. 349 """ Adds all of the constructors.
335 Arguments: 350 Arguments:
336 constructors - List of the constructors to be added. 351 constructors - List of the constructors to be added.
337 factory_name - Name of the factory for this class. 352 factory_name - Name of the factory for this class.
338 factory_constructor_name - The name of the constructor on the 353 factory_constructor_name - The name of the constructor on the
339 factory_name to call (calls an autogenerated FactoryProvider 354 factory_name to call (calls an autogenerated FactoryProvider
340 if unspecified) 355 if unspecified)
341 """ 356 """
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 '\n' 571 '\n'
557 ' $TYPE $NAME($PARAMS);\n', 572 ' $TYPE $NAME($PARAMS);\n',
558 TYPE=return_type_name, 573 TYPE=return_type_name,
559 NAME=method_name, 574 NAME=method_name,
560 PARAMS=operation.ParametersDeclaration(self._DartType)) 575 PARAMS=operation.ParametersDeclaration(self._DartType))
561 576
562 def EmitListMixin(self, element_name): 577 def EmitListMixin(self, element_name):
563 # TODO(sra): Use separate mixins for mutable implementations of List<T>. 578 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
564 # TODO(sra): Use separate mixins for typed array implementations of List<T>. 579 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
565 template_file = 'immutable_list_mixin.darttemplate' 580 template_file = 'immutable_list_mixin.darttemplate'
566 has_contains = any(op.id == 'contains' for op in self._interface.operations)
567 has_clear = any(op.id == 'clear' for op in self._interface.operations)
568 has_length = False 581 has_length = False
569 has_length_setter = False 582 has_length_setter = False
570 typed_array = self._interface_type_info.is_typed_array() 583 typed_array = self._interface_type_info.is_typed_array()
571 584
572 for attr in self._interface.attributes: 585 for attr in self._interface.attributes:
573 if attr.id == 'length': 586 if attr.id == 'length':
574 has_length = True 587 has_length = True
575 has_length_setter = not attr.is_read_only 588 has_length_setter = not attr.is_read_only
576 589
577 has_num_items = any(attr.id == 'numberOfItems' 590 has_num_items = any(attr.id == 'numberOfItems'
578 for attr in self._interface.attributes) 591 for attr in self._interface.attributes)
579 592
580 template = self._template_loader.Load( 593 template = self._template_loader.Load(
581 template_file, 594 template_file,
582 { 595 {
583 'DEFINE_CONTAINS': not has_contains,
584 'DEFINE_CLEAR': not has_clear,
585 'DEFINE_IMMUTABLE': not typed_array, 596 'DEFINE_IMMUTABLE': not typed_array,
586 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items, 597 'DEFINE_LENGTH_AS_NUM_ITEMS': not has_length and has_num_items,
587 'DEFINE_LENGTH_SETTER': not has_length_setter, 598 'DEFINE_LENGTH_SETTER': not has_length_setter,
588 }) 599 })
589 self._members_emitter.Emit(template, E=element_name) 600 self._members_emitter.Emit(template, E=element_name)
590 601
591 def SecureOutputType(self, type_name, is_dart_type=False): 602 def SecureOutputType(self, type_name, is_dart_type=False):
592 """ Converts the type name to the secure type name for return types. 603 """ Converts the type name to the secure type name for return types.
593 """ 604 """
594 if is_dart_type: 605 if is_dart_type:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 walk(interface.parents) 645 walk(interface.parents)
635 else: 646 else:
636 walk(interface.parents[1:]) 647 walk(interface.parents[1:])
637 return result 648 return result
638 649
639 def _DartType(self, type_name): 650 def _DartType(self, type_name):
640 return self._type_registry.DartType(type_name) 651 return self._type_registry.DartType(type_name)
641 652
642 def _IsPrivate(self, name): 653 def _IsPrivate(self, name):
643 return name.startswith('_') 654 return name.startswith('_')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698