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

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

Issue 10703194: Extract interfaces and members renaming logic to a new HtmlRenamer 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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 _svg_supplemental_includes = [ 808 _svg_supplemental_includes = [
809 '"SVGAnimatedPropertyTearOff.h"', 809 '"SVGAnimatedPropertyTearOff.h"',
810 '"SVGAnimatedListPropertyTearOff.h"', 810 '"SVGAnimatedListPropertyTearOff.h"',
811 '"SVGStaticListPropertyTearOff.h"', 811 '"SVGStaticListPropertyTearOff.h"',
812 '"SVGAnimatedListPropertyTearOff.h"', 812 '"SVGAnimatedListPropertyTearOff.h"',
813 '"SVGTransformListPropertyTearOff.h"', 813 '"SVGTransformListPropertyTearOff.h"',
814 '"SVGPathSegListPropertyTearOff.h"', 814 '"SVGPathSegListPropertyTearOff.h"',
815 ] 815 ]
816 816
817 class TypeRegistry(object): 817 class TypeRegistry(object):
818 def __init__(self, interface_renames): 818 def __init__(self, database, renamer=None):
819 self._interface_renames = interface_renames 819 self._database = database
820 self._renamer = renamer
820 self._cache = {} 821 self._cache = {}
821 822
822 def TypeInfo(self, type_name): 823 def TypeInfo(self, type_name):
823 if not type_name in self._cache: 824 if not type_name in self._cache:
824 self._cache[type_name] = self._TypeInfo(type_name) 825 self._cache[type_name] = self._TypeInfo(type_name)
825 return self._cache[type_name] 826 return self._cache[type_name]
826 827
827 def DartType(self, type_name): 828 def DartType(self, type_name):
828 dart_type = self.TypeInfo(type_name).dart_type() 829 dart_type = self.TypeInfo(type_name).dart_type()
829 return self._interface_renames.get(dart_type, dart_type) 830 if self._database.HasInterface(dart_type):
830 831 interface = self._database.GetInterface(dart_type)
831 def InterfaceName(self, type_name): 832 return self._renamer.RenameInterface(interface)
832 return self._interface_renames.get(type_name, type_name) 833 return dart_type
833 834
834 def _TypeInfo(self, type_name): 835 def _TypeInfo(self, type_name):
835 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name) 836 match = re.match(r'(?:sequence<(\w+)>|(\w+)\[\])$', type_name)
836 if match: 837 if match:
837 if type_name == 'DOMString[]': 838 if type_name == 'DOMString[]':
838 return DOMStringArrayTypeInfo(self.TypeInfo('DOMString')) 839 return DOMStringArrayTypeInfo(self.TypeInfo('DOMString'))
839 return SequenceIDLTypeInfo(type_name, self.TypeInfo(match.group(1) or matc h.group(2))) 840 return SequenceIDLTypeInfo(type_name, self.TypeInfo(match.group(1) or matc h.group(2)))
840 if not type_name in _idl_type_registry: 841 if not type_name in _idl_type_registry:
841 return InterfaceIDLTypeInfo(type_name, TypeData('Interface')) 842 return InterfaceIDLTypeInfo(type_name, TypeData('Interface'))
842 type_data = _idl_type_registry.get(type_name) 843 type_data = _idl_type_registry.get(type_name)
843 class_name = '%sIDLTypeInfo' % type_data.clazz 844 class_name = '%sIDLTypeInfo' % type_data.clazz
844 return globals()[class_name](type_name, type_data) 845 return globals()[class_name](type_name, type_data)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698