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

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

Issue 11027033: Move Dart type narrowing to TypeRegistry. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
« lib/html/scripts/generator.py ('K') | « lib/html/scripts/generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 def CustomJSMembers(self): 1021 def CustomJSMembers(self):
1022 return _js_custom_members 1022 return _js_custom_members
1023 1023
1024 def _HasJavaScriptIndexingBehaviour(self): 1024 def _HasJavaScriptIndexingBehaviour(self):
1025 """Returns True if the native object has an indexer and length property.""" 1025 """Returns True if the native object has an indexer and length property."""
1026 (element_type, requires_indexer) = ListImplementationInfo( 1026 (element_type, requires_indexer) = ListImplementationInfo(
1027 self._interface, self._database) 1027 self._interface, self._database)
1028 if element_type and requires_indexer: return True 1028 if element_type and requires_indexer: return True
1029 return False 1029 return False
1030 1030
1031 def _ShouldNarrowToImplementationType(self, type_name):
1032 # TODO(sra): Move into the 'system' and cache the result.
1033 do_not_narrow = ['DOMStringList', 'DOMStringMap', 'EventListener',
1034 'IDBAny', 'IDBKey', 'MediaQueryListListener', 'List<Node>',
1035 'NodeList']
1036 if type_name in do_not_narrow:
1037 return False
1038 if self._database.HasInterface(type_name):
1039 interface = self._database.GetInterface(type_name)
1040 # Callbacks are typedef functions so don't have a class.
1041 return 'Callback' not in interface.ext_attrs
1042 return False
1043
1044 def _NarrowToImplementationType(self, type_name): 1031 def _NarrowToImplementationType(self, type_name):
1045 if type_name == 'Dynamic': 1032 if type_name == 'Dynamic':
1046 return type_name 1033 return type_name
1047 if self._ShouldNarrowToImplementationType(type_name): 1034 return self._type_registry.TypeInfo(type_name).narrow_dart_type()
1048 return self._ImplClassName(self._DartType(type_name))
1049 return self._DartType(type_name)
1050 1035
1051 def _NarrowInputType(self, type_name): 1036 def _NarrowInputType(self, type_name):
1052 return self._NarrowToImplementationType(type_name) 1037 return self._NarrowToImplementationType(type_name)
1053 1038
1054 def _NarrowOutputType(self, type_name): 1039 def _NarrowOutputType(self, type_name):
1055 return self._NarrowToImplementationType(type_name) 1040 return self._NarrowToImplementationType(type_name)
1056 1041
1057 def _FindShadowedAttribute(self, attr, merged_interfaces={}): 1042 def _FindShadowedAttribute(self, attr, merged_interfaces={}):
1058 """Returns (attribute, superinterface) or (None, None).""" 1043 """Returns (attribute, superinterface) or (None, None)."""
1059 def FindInParent(interface): 1044 def FindInParent(interface):
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1105
1121 library_emitter = self._multiemitter.FileEmitter(library_file_path) 1106 library_emitter = self._multiemitter.FileEmitter(library_file_path)
1122 library_file_dir = os.path.dirname(library_file_path) 1107 library_file_dir = os.path.dirname(library_file_path)
1123 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) 1108 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
1124 imports_emitter = library_emitter.Emit( 1109 imports_emitter = library_emitter.Emit(
1125 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) 1110 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir))
1126 for path in sorted(self._path_to_emitter.keys()): 1111 for path in sorted(self._path_to_emitter.keys()):
1127 relpath = os.path.relpath(path, library_file_dir) 1112 relpath = os.path.relpath(path, library_file_dir)
1128 imports_emitter.Emit( 1113 imports_emitter.Emit(
1129 "#source('$PATH');\n", PATH=massage_path(relpath)) 1114 "#source('$PATH');\n", PATH=massage_path(relpath))
OLDNEW
« lib/html/scripts/generator.py ('K') | « lib/html/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698