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

Side by Side Diff: lib/dom/scripts/generator.py

Issue 10702202: Introduce TypeRegistry class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import copy 9 import copy
10 import re 10 import re
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 # Some JavaScript processors, especially tools like yuicompress and 78 # Some JavaScript processors, especially tools like yuicompress and
79 # JSCompiler, choke on 'this.continue' 79 # JSCompiler, choke on 'this.continue'
80 'IDBCursor.continueFunction': 80 'IDBCursor.continueFunction':
81 """ 81 """
82 if (key == null) return this['continue'](); 82 if (key == null) return this['continue']();
83 return this['continue'](key); 83 return this['continue'](key);
84 """, 84 """,
85 } 85 }
86 86
87 def IsPrimitiveType(type_name): 87 def IsPrimitiveType(type_name):
88 return isinstance(GetIDLTypeInfo(type_name), PrimitiveIDLTypeInfo) 88 if not type_name in _idl_type_registry:
89 return False
90 return _idl_type_registry[type_name]['type'] == 'Primitive'
89 91
90 def ListImplementationInfo(interface, database): 92 def ListImplementationInfo(interface, database):
91 """Returns a tuple (elment_type, requires_indexer). 93 """Returns a tuple (elment_type, requires_indexer).
92 If interface do not have to implement List, element_type is None. 94 If interface do not have to implement List, element_type is None.
93 Otherwise element_type is list element type and requires_indexer 95 Otherwise element_type is list element type and requires_indexer
94 is true iff this interface implementation must have indexer and 96 is true iff this interface implementation must have indexer and
95 false otherwise. False means that interface implementation 97 false otherwise. False means that interface implementation
96 inherits indexer and may just reuse it.""" 98 inherits indexer and may just reuse it."""
97 element_type = MaybeListElementType(interface) 99 element_type = MaybeListElementType(interface)
98 if element_type: 100 if element_type:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 # is useful not only for browser compat, but to allow code that links 161 # is useful not only for browser compat, but to allow code that links
160 # against dart:dom_deprecated to load in a worker isolate. 162 # against dart:dom_deprecated to load in a worker isolate.
161 return '*' + javascript_binding_name 163 return '*' + javascript_binding_name
162 164
163 165
164 def MatchSourceFilter(thing): 166 def MatchSourceFilter(thing):
165 return 'WebKit' in thing.annotations or 'Dart' in thing.annotations 167 return 'WebKit' in thing.annotations or 'Dart' in thing.annotations
166 168
167 169
168 def DartType(idl_type_name): 170 def DartType(idl_type_name):
169 return GetIDLTypeInfo(idl_type_name).dart_type() 171 return TypeRegistry().TypeInfo(idl_type_name).dart_type()
170 172
171 173
172 class ParamInfo(object): 174 class ParamInfo(object):
173 """Holder for various information about a parameter of a Dart operation. 175 """Holder for various information about a parameter of a Dart operation.
174 176
175 Attributes: 177 Attributes:
176 name: Name of parameter. 178 name: Name of parameter.
177 type_id: Original type id. None for merged types. 179 type_id: Original type id. None for merged types.
178 dart_type: DartType of parameter. 180 dart_type: DartType of parameter.
179 is_optional: Parameter optionality. 181 is_optional: Parameter optionality.
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 485
484 # Given a sorted sequence of type identifiers, return an appropriate type 486 # Given a sorted sequence of type identifiers, return an appropriate type
485 # name 487 # name
486 def TypeName(type_ids, interface): 488 def TypeName(type_ids, interface):
487 # Dynamically type this field for now. 489 # Dynamically type this field for now.
488 return 'Dynamic' 490 return 'Dynamic'
489 491
490 # ------------------------------------------------------------------------------ 492 # ------------------------------------------------------------------------------
491 493
492 class IDLTypeInfo(object): 494 class IDLTypeInfo(object):
493 def __init__(self, idl_type, dart_type=None, 495 def __init__(self, idl_type, data):
494 native_type=None,
495 custom_to_native=False,
496 custom_to_dart=False, conversion_includes=[]):
497 self._idl_type = idl_type 496 self._idl_type = idl_type
498 self._dart_type = dart_type 497 for p in _idl_type_registry_properties:
499 self._native_type = native_type 498 self.__dict__['_' + p] = data.get(p, None)
Anton Muhin 2012/07/13 15:18:55 I wonder if it's semantically ok: when _-mangling
podivilov 2012/07/13 16:05:21 Done.
500 self._custom_to_native = custom_to_native
501 self._custom_to_dart = custom_to_dart
502 self._conversion_includes = conversion_includes + [idl_type]
503 499
504 def idl_type(self): 500 def idl_type(self):
505 return self._idl_type 501 return self._idl_type
506 502
507 def dart_type(self): 503 def dart_type(self):
508 return self._dart_type or self._idl_type 504 return self._dart_type or self._idl_type
509 505
510 def native_type(self): 506 def native_type(self):
511 return self._native_type or self._idl_type 507 return self._native_type or self._idl_type
512 508
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 if self._idl_type.startswith('SVGPathSeg'): 575 if self._idl_type.startswith('SVGPathSeg'):
580 include = self._idl_type.replace('Abs', '').replace('Rel', '') 576 include = self._idl_type.replace('Abs', '').replace('Rel', '')
581 else: 577 else:
582 include = self._idl_type 578 include = self._idl_type
583 return ['"%s.h"' % include] + _svg_supplemental_includes 579 return ['"%s.h"' % include] + _svg_supplemental_includes
584 580
585 def receiver(self): 581 def receiver(self):
586 return 'receiver->' 582 return 'receiver->'
587 583
588 def conversion_includes(self): 584 def conversion_includes(self):
589 return ['"Dart%s.h"' % include for include in self._conversion_includes] 585 includes = [self._idl_type] + (self._conversion_includes or [])
586 return ['"Dart%s.h"' % include for include in includes]
590 587
591 def to_native_includes(self): 588 def to_native_includes(self):
592 return ['"Dart%s.h"' % self.idl_type()] 589 return ['"Dart%s.h"' % self.idl_type()]
593 590
594 def to_dart_conversion(self, value, interface_name=None, attributes=None): 591 def to_dart_conversion(self, value, interface_name=None, attributes=None):
595 return 'Dart%s::toDart(%s)' % (self._idl_type, value) 592 return 'Dart%s::toDart(%s)' % (self._idl_type, value)
596 593
597 def custom_to_dart(self): 594 def custom_to_dart(self):
598 return self._custom_to_dart 595 return self._custom_to_dart
599 596
600 597
598 class InterfaceIDLTypeInfo(IDLTypeInfo):
599 def __init__(self, idl_type, data):
600 super(InterfaceIDLTypeInfo, self).__init__(idl_type, data)
601
602
601 class SequenceIDLTypeInfo(IDLTypeInfo): 603 class SequenceIDLTypeInfo(IDLTypeInfo):
602 def __init__(self, idl_type, item_info): 604 def __init__(self, idl_type, item_info):
603 super(SequenceIDLTypeInfo, self).__init__(idl_type) 605 super(SequenceIDLTypeInfo, self).__init__(idl_type, {})
604 self._item_info = item_info 606 self._item_info = item_info
605 607
606 def dart_type(self): 608 def dart_type(self):
607 return 'List<%s>' % self._item_info.dart_type() 609 return 'List<%s>' % self._item_info.dart_type()
608 610
609 def to_dart_conversion(self, value, interface_name=None, attributes=None): 611 def to_dart_conversion(self, value, interface_name=None, attributes=None):
610 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value) 612 return 'DartDOMWrapper::vectorToDart<Dart%s>(%s)' % (self._item_info.native_ type(), value)
611 613
612 def conversion_includes(self): 614 def conversion_includes(self):
613 return self._item_info.conversion_includes() 615 return self._item_info.conversion_includes()
614 616
615 617
616 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo): 618 class DOMStringArrayTypeInfo(SequenceIDLTypeInfo):
617 def __init__(self): 619 def __init__(self, item_info):
618 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', _dom_string_type _info) 620 super(DOMStringArrayTypeInfo, self).__init__('DOMString[]', item_info)
619 621
620 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): 622 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
621 emitter.Emit( 623 emitter.Emit(
622 '\n' 624 '\n'
623 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND LE, exception);\n' 625 ' RefPtr<DOMStringList> $NAME = DartDOMStringList::toNative($HAND LE, exception);\n'
624 ' if (exception)\n' 626 ' if (exception)\n'
625 ' goto fail;\n', 627 ' goto fail;\n',
626 NAME=name, 628 NAME=name,
627 HANDLE=handle) 629 HANDLE=handle)
628 return name 630 return name
629 631
630 def to_native_includes(self): 632 def to_native_includes(self):
631 return ['"DartDOMStringList.h"'] 633 return ['"DartDOMStringList.h"']
632 634
633 635
634 class PrimitiveIDLTypeInfo(IDLTypeInfo): 636 class PrimitiveIDLTypeInfo(IDLTypeInfo):
635 def __init__(self, idl_type, dart_type, native_type=None, 637 def __init__(self, idl_type, data):
636 webcore_getter_name='getAttribute', 638 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, data)
637 webcore_setter_name='setAttribute'): 639 self._webcore_getter_name = data.get('webcore_getter_name', 'getAttribute')
638 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, 640 self._webcore_setter_name = data.get('webcore_setter_name', 'setAttribute')
639 native_type=native_type)
640 self._webcore_getter_name = webcore_getter_name
641 self._webcore_setter_name = webcore_setter_name
642 641
643 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): 642 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
644 function_name = 'dartTo%s' % self._capitalized_native_type() 643 function_name = 'dartTo%s' % self._capitalized_native_type()
645 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString': 644 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString':
646 function_name += 'WithNullCheck' 645 function_name += 'WithNullCheck'
647 type = self.native_type() 646 type = self.native_type()
648 if type == 'SerializedScriptValue': 647 if type == 'SerializedScriptValue':
649 type = 'RefPtr<%s>' % type 648 type = 'RefPtr<%s>' % type
650 if type == 'String': 649 if type == 'String':
651 type = 'DartStringAdapter' 650 type = 'DartStringAdapter'
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 return self._webcore_getter_name 683 return self._webcore_getter_name
685 684
686 def webcore_setter_name(self): 685 def webcore_setter_name(self):
687 return self._webcore_setter_name 686 return self._webcore_setter_name
688 687
689 def _capitalized_native_type(self): 688 def _capitalized_native_type(self):
690 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e()) 689 return re.sub(r'(^| )([a-z])', lambda x: x.group(2).upper(), self.native_typ e())
691 690
692 691
693 class SVGTearOffIDLTypeInfo(IDLTypeInfo): 692 class SVGTearOffIDLTypeInfo(IDLTypeInfo):
694 def __init__(self, idl_type, native_type=''): 693 def __init__(self, idl_type, data):
695 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, 694 super(SVGTearOffIDLTypeInfo, self).__init__(idl_type, data)
696 native_type=native_type)
697 695
698 def native_type(self): 696 def native_type(self):
699 if self._native_type: 697 if self._native_type:
700 return self._native_type 698 return self._native_type
701 tear_off_type = 'SVGPropertyTearOff' 699 tear_off_type = 'SVGPropertyTearOff'
702 if self._idl_type.endswith('List'): 700 if self._idl_type.endswith('List'):
703 tear_off_type = 'SVGListPropertyTearOff' 701 tear_off_type = 'SVGListPropertyTearOff'
704 return '%s<%s>' % (tear_off_type, self._idl_type) 702 return '%s<%s>' % (tear_off_type, self._idl_type)
705 703
706 def receiver(self): 704 def receiver(self):
(...skipping 11 matching lines...) Expand all
718 conversion_cast = '%s::create(receiver, %s)' 716 conversion_cast = '%s::create(receiver, %s)'
719 elif interface_name.endswith('List'): 717 elif interface_name.endswith('List'):
720 conversion_cast = 'static_cast<%s*>(%s.get())' 718 conversion_cast = 'static_cast<%s*>(%s.get())'
721 elif self.idl_type() in svg_primitive_types: 719 elif self.idl_type() in svg_primitive_types:
722 conversion_cast = '%s::create(%s)' 720 conversion_cast = '%s::create(%s)'
723 else: 721 else:
724 conversion_cast = 'static_cast<%s*>(%s)' 722 conversion_cast = 'static_cast<%s*>(%s)'
725 conversion_cast = conversion_cast % (self.native_type(), value) 723 conversion_cast = conversion_cast % (self.native_type(), value)
726 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast) 724 return 'Dart%s::toDart(%s)' % (self._idl_type, conversion_cast)
727 725
728 _dom_string_type_info = PrimitiveIDLTypeInfo( 726
729 'DOMString', dart_type='String', native_type='String') 727 _idl_type_registry_properties = [
Anton Muhin 2012/07/13 15:18:55 as another option. class TypeData(object): def
podivilov 2012/07/13 16:05:21 Done.
728 'dart_type',
729 'native_type',
730 'custom_to_native',
731 'custom_to_dart',
732 'conversion_includes'
733 ]
730 734
731 _idl_type_registry = { 735 _idl_type_registry = {
732 'boolean': PrimitiveIDLTypeInfo('boolean', dart_type='bool', native_type='bo ol', 736 'boolean': { 'type': 'Primitive', 'dart_type': 'bool', 'native_type': 'bool' ,
733 webcore_getter_name='hasAttribute', 737 'webcore_getter_name': 'hasAttribute',
734 webcore_setter_name='setBooleanAttribute'), 738 'webcore_setter_name': 'setBooleanAttribute' },
735 'byte': PrimitiveIDLTypeInfo('byte', dart_type='int', native_type='int'), 739 'byte': { 'type': 'Primitive', 'dart_type': 'int', 'native_type': 'int' },
736 'octet': PrimitiveIDLTypeInfo('octet', dart_type='int', native_type='int'), 740 'octet': { 'type': 'Primitive', 'dart_type': 'int', 'native_type': 'int' },
737 'short': PrimitiveIDLTypeInfo('short', dart_type='int', native_type='int'), 741 'short': { 'type': 'Primitive', 'dart_type': 'int', 'native_type': 'int' },
738 'unsigned short': PrimitiveIDLTypeInfo('unsigned short', dart_type='int', 742 'unsigned short': { 'type': 'Primitive', 'dart_type': 'int',
739 native_type='int'), 743 'native_type': 'int' },
740 'int': PrimitiveIDLTypeInfo('int', dart_type='int'), 744 'int': { 'type': 'Primitive', 'dart_type': 'int' },
741 'unsigned int': PrimitiveIDLTypeInfo('unsigned int', dart_type='int', 745 'unsigned int': { 'type': 'Primitive', 'dart_type': 'int', 'native_type': 'u nsigned' },
742 native_type='unsigned'), 746 'long': { 'type': 'Primitive', 'dart_type': 'int', 'native_type': 'int',
743 'long': PrimitiveIDLTypeInfo('long', dart_type='int', native_type='int', 747 'webcore_getter_name': 'getIntegralAttribute',
744 webcore_getter_name='getIntegralAttribute', 748 'webcore_setter_name': 'setIntegralAttribute' },
745 webcore_setter_name='setIntegralAttribute'), 749 'unsigned long': { 'type': 'Primitive', 'dart_type': 'int',
746 'unsigned long': PrimitiveIDLTypeInfo('unsigned long', dart_type='int', 750 'native_type': 'unsigned',
747 native_type='unsigned', 751 'webcore_getter_name': 'getUnsignedIntegralAttribute',
748 webcore_getter_name='getUnsignedIntegralAttribute', 752 'webcore_setter_name': 'setUnsignedIntegralAttribute'},
749 webcore_setter_name='setUnsignedIntegralAttribute'), 753 'long long': { 'type': 'Primitive', 'dart_type': 'int' },
750 'long long': PrimitiveIDLTypeInfo('long long', dart_type='int'), 754 'unsigned long long': { 'type': 'Primitive', 'dart_type': 'int' },
751 'unsigned long long': PrimitiveIDLTypeInfo('unsigned long long', dart_type=' int'), 755 'float': { 'type': 'Primitive', 'dart_type': 'num', 'native_type': 'double' },
752 'float': PrimitiveIDLTypeInfo('float', dart_type='num', native_type='double' ), 756 'double': { 'type': 'Primitive', 'dart_type': 'num' },
753 'double': PrimitiveIDLTypeInfo('double', dart_type='num'),
754 757
755 'any': PrimitiveIDLTypeInfo('any', dart_type='Object'), 758 'any': { 'type': 'Primitive', 'dart_type': 'Object' },
756 'Array': PrimitiveIDLTypeInfo('Array', dart_type='List'), 759 'Array': { 'type': 'Primitive', 'dart_type': 'List' },
757 'custom': PrimitiveIDLTypeInfo('custom', dart_type='Dynamic'), 760 'custom': { 'type': 'Primitive', 'dart_type': 'Dynamic' },
758 'Date': PrimitiveIDLTypeInfo('Date', dart_type='Date', native_type='double') , 761 'Date': { 'type': 'Primitive', 'dart_type': 'Date', 'native_type': 'double' },
759 'DOMObject': PrimitiveIDLTypeInfo('DOMObject', dart_type='Object', native_ty pe='ScriptValue'), 762 'DOMObject': { 'type': 'Primitive', 'dart_type': 'Object', 'native_type': 'S criptValue' },
760 'DOMString': _dom_string_type_info, 763 'DOMString': { 'type': 'Primitive', 'dart_type': 'String', 'native_type': 'S tring' },
761 # TODO(vsm): This won't actually work until we convert the Map to 764 # TODO(vsm): This won't actually work until we convert the Map to
762 # a native JS Map for JS DOM. 765 # a native JS Map for JS DOM.
763 'Dictionary': PrimitiveIDLTypeInfo('Dictionary', dart_type='Map'), 766 'Dictionary': { 'type': 'Primitive', 'dart_type': 'Map' },
764 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 767 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
765 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 768 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
766 'Flags': PrimitiveIDLTypeInfo('Flags', dart_type='Object'), 769 'Flags': { 'type': 'Primitive', 'dart_type': 'Object' },
767 'DOMTimeStamp': PrimitiveIDLTypeInfo('DOMTimeStamp', dart_type='int', native _type='unsigned long long'), 770 'DOMTimeStamp': { 'type': 'Primitive', 'dart_type': 'int', 'native_type': 'u nsigned long long' },
768 'object': PrimitiveIDLTypeInfo('object', dart_type='Object', native_type='Sc riptValue'), 771 'object': { 'type': 'Primitive', 'dart_type': 'Object', 'native_type': 'Scri ptValue' },
769 'PositionOptions': PrimitiveIDLTypeInfo('PositionOptions', dart_type='Object '), 772 'PositionOptions': { 'type': 'Primitive', 'dart_type': 'Object' },
770 # TODO(sra): Come up with some meaningful name so that where this appears in 773 # TODO(sra): Come up with some meaningful name so that where this appears in
771 # the documentation, the user is made aware that only a limited subset of 774 # the documentation, the user is made aware that only a limited subset of
772 # serializable types are actually permitted. 775 # serializable types are actually permitted.
773 'SerializedScriptValue': PrimitiveIDLTypeInfo('SerializedScriptValue', dart_ type='Dynamic'), 776 'SerializedScriptValue': { 'type': 'Primitive', 'dart_type': 'Dynamic' },
774 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool} 777 # TODO(sra): Flags is really a dictionary: {create:bool, exclusive:bool}
775 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce 778 # http://dev.w3.org/2009/dap/file-system/file-dir-sys.html#the-flags-interfa ce
776 'WebKitFlags': PrimitiveIDLTypeInfo('WebKitFlags', dart_type='Object'), 779 'WebKitFlags': { 'type': 'Primitive', 'dart_type': 'Object' },
777 780
778 'sequence': PrimitiveIDLTypeInfo('sequence', dart_type='List'), 781 'sequence': { 'type': 'Primitive', 'dart_type': 'List' },
779 'void': PrimitiveIDLTypeInfo('void', dart_type='void'), 782 'void': { 'type': 'Primitive', 'dart_type': 'void' },
780 783
781 'CSSRule': IDLTypeInfo('CSSRule', conversion_includes=['CSSImportRule']), 784 'CSSRule': { 'type': 'Interface', 'conversion_includes': ['CSSImportRule'] } ,
782 'DOMException': IDLTypeInfo('DOMException', native_type='DOMCoreException'), 785 'DOMException': { 'type': 'Interface', 'native_type': 'DOMCoreException' },
783 'DOMString[]': DOMStringArrayTypeInfo(), 786 'DOMStringList': { 'type': 'Interface', 'dart_type': 'List<String>', 'custom _to_native': True },
784 'DOMStringList': IDLTypeInfo('DOMStringList', dart_type='List<String>', cust om_to_native=True), 787 'DOMStringMap': { 'type': 'Interface', 'dart_type': 'Map<String, String>' },
785 'DOMStringMap': IDLTypeInfo('DOMStringMap', dart_type='Map<String, String>') , 788 'DOMWindow': { 'type': 'Interface', 'custom_to_dart': True },
786 'DOMWindow': IDLTypeInfo('DOMWindow', custom_to_dart=True), 789 'Element': { 'type': 'Interface', 'custom_to_dart': True },
787 'Element': IDLTypeInfo('Element', custom_to_dart=True), 790 'EventListener': { 'type': 'Interface', 'custom_to_native': True },
788 'EventListener': IDLTypeInfo('EventListener', custom_to_native=True), 791 'EventTarget': { 'type': 'Interface', 'custom_to_native': True },
789 'EventTarget': IDLTypeInfo('EventTarget', custom_to_native=True), 792 'HTMLElement': { 'type': 'Interface', 'custom_to_dart': True },
790 'HTMLElement': IDLTypeInfo('HTMLElement', custom_to_dart=True), 793 'IDBAny': { 'type': 'Interface', 'dart_type': 'Dynamic', 'custom_to_native': True },
791 'IDBAny': IDLTypeInfo('IDBAny', dart_type='Dynamic', custom_to_native=True), 794 'IDBKey': { 'type': 'Interface', 'dart_type': 'Dynamic', 'custom_to_native': True },
792 'IDBKey': IDLTypeInfo('IDBKey', dart_type='Dynamic', custom_to_native=True), 795 'StyleSheet': { 'type': 'Interface', 'conversion_includes': ['CSSStyleSheet' ] },
793 'StyleSheet': IDLTypeInfo('StyleSheet', conversion_includes=['CSSStyleSheet' ]), 796 'SVGElement': { 'type': 'Interface', 'custom_to_dart': True },
794 'SVGElement': IDLTypeInfo('SVGElement', custom_to_dart=True),
795 797
796 'SVGAngle': SVGTearOffIDLTypeInfo('SVGAngle'), 798 'SVGAngle': { 'type': 'SVGTearOff' },
797 'SVGLength': SVGTearOffIDLTypeInfo('SVGLength'), 799 'SVGLength': { 'type': 'SVGTearOff' },
798 'SVGLengthList': SVGTearOffIDLTypeInfo('SVGLengthList'), 800 'SVGLengthList': { 'type': 'SVGTearOff' },
799 'SVGMatrix': SVGTearOffIDLTypeInfo('SVGMatrix'), 801 'SVGMatrix': { 'type': 'SVGTearOff' },
800 'SVGNumber': SVGTearOffIDLTypeInfo('SVGNumber', native_type='SVGPropertyTear Off<float>'), 802 'SVGNumber': { 'type': 'SVGTearOff', 'native_type': 'SVGPropertyTearOff<floa t>' },
801 'SVGNumberList': SVGTearOffIDLTypeInfo('SVGNumberList'), 803 'SVGNumberList': { 'type': 'SVGTearOff' },
802 'SVGPathSegList': SVGTearOffIDLTypeInfo('SVGPathSegList', native_type='SVGPa thSegListPropertyTearOff'), 804 'SVGPathSegList': { 'type': 'SVGTearOff', 'native_type': 'SVGPathSegListProp ertyTearOff' },
803 'SVGPoint': SVGTearOffIDLTypeInfo('SVGPoint', native_type='SVGPropertyTearOf f<FloatPoint>'), 805 'SVGPoint': { 'type': 'SVGTearOff', 'native_type': 'SVGPropertyTearOff<Float Point>' },
804 'SVGPointList': SVGTearOffIDLTypeInfo('SVGPointList'), 806 'SVGPointList': { 'type': 'SVGTearOff' },
805 'SVGPreserveAspectRatio': SVGTearOffIDLTypeInfo('SVGPreserveAspectRatio'), 807 'SVGPreserveAspectRatio': { 'type': 'SVGTearOff' },
806 'SVGRect': SVGTearOffIDLTypeInfo('SVGRect', native_type='SVGPropertyTearOff< FloatRect>'), 808 'SVGRect': { 'type': 'SVGTearOff', 'native_type': 'SVGPropertyTearOff<FloatR ect>' },
807 'SVGStringList': SVGTearOffIDLTypeInfo('SVGStringList', native_type='SVGStat icListPropertyTearOff<SVGStringList>'), 809 'SVGStringList': { 'type': 'SVGTearOff', 'native_type': 'SVGStaticListProper tyTearOff<SVGStringList>' },
808 'SVGTransform': SVGTearOffIDLTypeInfo('SVGTransform'), 810 'SVGTransform': { 'type': 'SVGTearOff' },
809 'SVGTransformList': SVGTearOffIDLTypeInfo('SVGTransformList', native_type='S VGTransformListPropertyTearOff') 811 'SVGTransformList': { 'type': 'SVGTearOff', 'native_type': 'SVGTransformList PropertyTearOff' }
810 } 812 }
811 813
812 _svg_supplemental_includes = [ 814 _svg_supplemental_includes = [
813 '"SVGAnimatedPropertyTearOff.h"', 815 '"SVGAnimatedPropertyTearOff.h"',
814 '"SVGAnimatedListPropertyTearOff.h"', 816 '"SVGAnimatedListPropertyTearOff.h"',
815 '"SVGStaticListPropertyTearOff.h"', 817 '"SVGStaticListPropertyTearOff.h"',
816 '"SVGAnimatedListPropertyTearOff.h"', 818 '"SVGAnimatedListPropertyTearOff.h"',
817 '"SVGTransformListPropertyTearOff.h"', 819 '"SVGTransformListPropertyTearOff.h"',
818 '"SVGPathSegListPropertyTearOff.h"', 820 '"SVGPathSegListPropertyTearOff.h"',
819 ] 821 ]
820 822
821 def GetIDLTypeInfo(idl_type_name): 823 class TypeRegistry(object):
822 type_info = _idl_type_registry.get(idl_type_name) 824 def __init__(self):
823 if type_info is not None: 825 self._cache = {}
824 return type_info
825 826
826 match = re.match(r'sequence<(\w+)>$', idl_type_name) 827 def TypeInfo(self, type_name):
827 if match: 828 if not type_name in self._cache:
828 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 829 self._cache[type_name] = self._TypeInfo(type_name)
830 return self._cache[type_name]
829 831
830 match = re.match(r'(\w+)\[\]$', idl_type_name) 832 def _TypeInfo(self, type_name):
831 if match: 833 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name)
832 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 834 if match:
833 835 if type_name == 'DOMString[]':
834 return IDLTypeInfo(idl_type_name) 836 return DOMStringArrayTypeInfo(self.TypeInfo('DOMString'))
837 return SequenceIDLTypeInfo(type_name, self.TypeInfo(match.group(1) or matc h.group(2)))
838 if not type_name in _idl_type_registry:
839 return InterfaceIDLTypeInfo(type_name, {})
840 type_data = _idl_type_registry.get(type_name)
841 class_name = '%sIDLTypeInfo' % type_data['type']
842 return globals()[class_name](type_name, type_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698