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

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

Issue 11227024: Cleanup list-like interfaces generation. (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/idl/dart/dart.idl ('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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 not self._interface_type_info.merged_into()): 233 not self._interface_type_info.merged_into()):
234 interface_emitter = self._library_emitter.FileEmitter(interface_name) 234 interface_emitter = self._library_emitter.FileEmitter(interface_name)
235 else: 235 else:
236 interface_emitter = emitter.Emitter() 236 interface_emitter = emitter.Emitter()
237 237
238 template_file = 'interface_%s.darttemplate' % interface_name 238 template_file = 'interface_%s.darttemplate' % interface_name
239 interface_template = (self._template_loader.TryLoad(template_file) or 239 interface_template = (self._template_loader.TryLoad(template_file) or
240 self._template_loader.Load('interface.darttemplate')) 240 self._template_loader.Load('interface.darttemplate'))
241 241
242 implements = [] 242 implements = []
243 suppressed_implements = []
244
245 for parent in self._interface.parents: 243 for parent in self._interface.parents:
246 parent_type_info = self._type_registry.TypeInfo(parent.type.id) 244 parent_type_info = self._type_registry.TypeInfo(parent.type.id)
247 parent_interface_name = parent_type_info.interface_name() 245 implements.append(parent_type_info.interface_name())
248 # TODO(vsm): Remove source_filter. 246
249 if MatchSourceFilter(parent): 247 if self._interface_type_info.list_item_type():
250 # Parent is a DOM type. 248 item_type_info = self._type_registry.TypeInfo(
251 implements.append(parent_interface_name) 249 self._interface_type_info.list_item_type())
252 elif '<' in parent.type.id: 250 implements.append('List<%s>' % item_type_info.dart_type())
253 # Parent is a Dart collection type.
254 # TODO(vsm): Make this check more robust.
255 implements.append(parent_interface_name)
256 else:
257 suppressed_implements.append('%s.%s' %
258 (self._common_prefix, parent_interface_name))
259 251
260 if interface_name in _secure_base_types: 252 if interface_name in _secure_base_types:
261 implements.append(_secure_base_types[interface_name]) 253 implements.append(_secure_base_types[interface_name])
262 254
263 comment = ' extends' 255 comment = ' extends'
264 implements_str = '' 256 implements_str = ''
265 if implements: 257 if implements:
266 implements_str += ' implements ' + ', '.join(implements) 258 implements_str += ' implements ' + ', '.join(implements)
267 comment = ',' 259 comment = ','
268 if suppressed_implements:
269 implements_str += ' /*%s %s */' % (comment,
270 ', '.join(suppressed_implements))
271 260
272 factory_provider = None 261 factory_provider = None
273 if interface_name in interface_factories: 262 if interface_name in interface_factories:
274 factory_provider = interface_factories[interface_name] 263 factory_provider = interface_factories[interface_name]
275 264
276 constructors = [] 265 constructors = []
277 constructor_info = AnalyzeConstructor(self._interface) 266 constructor_info = AnalyzeConstructor(self._interface)
278 if constructor_info: 267 if constructor_info:
279 constructors.append(constructor_info) 268 constructors.append(constructor_info)
280 factory_provider = '_' + interface_name + 'FactoryProvider' 269 factory_provider = '_' + interface_name + 'FactoryProvider'
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 CLASSNAME=self._interface_type_info.implementation_name(), 319 CLASSNAME=self._interface_type_info.implementation_name(),
331 EXTENDS=' extends %s' % base_class if base_class else '', 320 EXTENDS=' extends %s' % base_class if base_class else '',
332 IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces), 321 IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces),
333 NATIVESPEC=self._backend.NativeSpec()) 322 NATIVESPEC=self._backend.NativeSpec())
334 self._backend.StartInterface(self._implementation_members_emitter) 323 self._backend.StartInterface(self._implementation_members_emitter)
335 324
336 for constructor_info in constructors: 325 for constructor_info in constructors:
337 constructor_info.GenerateFactoryInvocation( 326 constructor_info.GenerateFactoryInvocation(
338 self._DartType, self._members_emitter, factory_provider) 327 self._DartType, self._members_emitter, factory_provider)
339 328
340 element_type = MaybeTypedArrayElementTypeInHierarchy( 329 element_type = None
341 self._interface, self._database) 330 for interface in self._database.Hierarchy(self._interface):
331 type_info = self._type_registry.TypeInfo(interface.id)
332 if type_info.is_typed_array():
333 element_type = type_info.list_item_type()
334 break
342 if element_type: 335 if element_type:
343 self._members_emitter.Emit( 336 self._members_emitter.Emit(
344 '\n' 337 '\n'
345 ' factory $CTOR(int length) =>\n' 338 ' factory $CTOR(int length) =>\n'
346 ' $FACTORY.create$(CTOR)(length);\n' 339 ' $FACTORY.create$(CTOR)(length);\n'
347 '\n' 340 '\n'
348 ' factory $CTOR.fromList(List<$TYPE> list) =>\n' 341 ' factory $CTOR.fromList(List<$TYPE> list) =>\n'
349 ' $FACTORY.create$(CTOR)_fromList(list);\n' 342 ' $FACTORY.create$(CTOR)_fromList(list);\n'
350 '\n' 343 '\n'
351 ' factory $CTOR.fromBuffer(ArrayBuffer buffer, [int byteOffset, int l ength]) => \n' 344 ' factory $CTOR.fromBuffer(ArrayBuffer buffer, [int byteOffset, int l ength]) => \n'
(...skipping 24 matching lines...) Expand all
376 def AddMembers(self, interface): 369 def AddMembers(self, interface):
377 for const in sorted(interface.constants, ConstantOutputOrder): 370 for const in sorted(interface.constants, ConstantOutputOrder):
378 self.AddConstant(const) 371 self.AddConstant(const)
379 372
380 for attr in sorted(interface.attributes, ConstantOutputOrder): 373 for attr in sorted(interface.attributes, ConstantOutputOrder):
381 if attr.type.id != 'EventListener': 374 if attr.type.id != 'EventListener':
382 self.AddAttribute(attr) 375 self.AddAttribute(attr)
383 376
384 # The implementation should define an indexer if the interface directly 377 # The implementation should define an indexer if the interface directly
385 # extends List. 378 # extends List.
386 (element_type, requires_indexer) = ListImplementationInfo( 379 element_type = None
387 interface, self._database) 380 requires_indexer = False
388 if element_type: 381 if self._interface_type_info.list_item_type():
389 if requires_indexer: 382 self.AddIndexer(self._interface_type_info.list_item_type())
390 self.AddIndexer(element_type) 383 else:
391 else: 384 for parent in self._database.Hierarchy(self._interface):
392 self.AmendIndexer(element_type) 385 if parent == self._interface:
386 continue
387 parent_type_info = self._type_registry.TypeInfo(parent.id)
388 if parent_type_info.list_item_type():
389 self.AmendIndexer(parent_type_info.list_item_type())
390 break
391
393 # Group overloaded operations by id 392 # Group overloaded operations by id
394 operationsById = {} 393 operationsById = {}
395 for operation in interface.operations: 394 for operation in interface.operations:
396 if operation.id not in operationsById: 395 if operation.id not in operationsById:
397 operationsById[operation.id] = [] 396 operationsById[operation.id] = []
398 operationsById[operation.id].append(operation) 397 operationsById[operation.id].append(operation)
399 398
400 # Generate operations 399 # Generate operations
401 for id in sorted(operationsById.keys()): 400 for id in sorted(operationsById.keys()):
402 operations = operationsById[id] 401 operations = operationsById[id]
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 604
606 def GenerateCallback(self, info): 605 def GenerateCallback(self, info):
607 pass 606 pass
608 607
609 def RootClassName(self): 608 def RootClassName(self):
610 return None 609 return None
611 610
612 def AdditionalImplementedInterfaces(self): 611 def AdditionalImplementedInterfaces(self):
613 # TODO: Include all implemented interfaces, including other Lists. 612 # TODO: Include all implemented interfaces, including other Lists.
614 implements = [] 613 implements = []
615 element_type = MaybeTypedArrayElementType(self._interface) 614 if self._interface_type_info.is_typed_array():
616 if element_type: 615 element_type = self._interface_type_info.list_item_type()
617 implements.append('List<%s>' % self._DartType(element_type)) 616 implements.append('List<%s>' % self._DartType(element_type))
618 if self._HasJavaScriptIndexingBehaviour(): 617 if self._interface_type_info.list_item_type():
619 implements.append('JavaScriptIndexingBehavior') 618 implements.append('JavaScriptIndexingBehavior')
620 return implements 619 return implements
621 620
622 def NativeSpec(self): 621 def NativeSpec(self):
623 native_spec = MakeNativeSpec(self._interface.javascript_binding_name) 622 native_spec = MakeNativeSpec(self._interface.javascript_binding_name)
624 return ' native "%s"' % native_spec 623 return ' native "%s"' % native_spec
625 624
626 def ImplementationTemplate(self): 625 def ImplementationTemplate(self):
627 template_file = ('impl_%s.darttemplate' % 626 template_file = ('impl_%s.darttemplate' %
628 self._interface_type_info.interface_name()) 627 self._interface_type_info.interface_name())
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 return FindConversion(idl_type, 'set', self._interface.id, member) 1033 return FindConversion(idl_type, 'set', self._interface.id, member)
1035 1034
1036 def _HasCustomImplementation(self, member_name): 1035 def _HasCustomImplementation(self, member_name):
1037 member_name = '%s.%s' % (self._interface_type_info.interface_name(), 1036 member_name = '%s.%s' % (self._interface_type_info.interface_name(),
1038 member_name) 1037 member_name)
1039 return member_name in _js_custom_members 1038 return member_name in _js_custom_members
1040 1039
1041 def CustomJSMembers(self): 1040 def CustomJSMembers(self):
1042 return _js_custom_members 1041 return _js_custom_members
1043 1042
1044 def _HasJavaScriptIndexingBehaviour(self):
1045 """Returns True if the native object has an indexer and length property."""
1046 (element_type, requires_indexer) = ListImplementationInfo(
1047 self._interface, self._database)
1048 if element_type and requires_indexer: return True
1049 return False
1050
1051 def _NarrowToImplementationType(self, type_name): 1043 def _NarrowToImplementationType(self, type_name):
1052 return self._type_registry.TypeInfo(type_name).narrow_dart_type() 1044 return self._type_registry.TypeInfo(type_name).narrow_dart_type()
1053 1045
1054 def _NarrowInputType(self, type_name): 1046 def _NarrowInputType(self, type_name):
1055 return self._NarrowToImplementationType(type_name) 1047 return self._NarrowToImplementationType(type_name)
1056 1048
1057 def _NarrowOutputType(self, type_name): 1049 def _NarrowOutputType(self, type_name):
1058 secure_name = SecureOutputType(self, type_name, True) 1050 secure_name = SecureOutputType(self, type_name, True)
1059 return self._NarrowToImplementationType(secure_name) 1051 return self._NarrowToImplementationType(secure_name)
1060 1052
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 1114
1123 library_emitter = self._multiemitter.FileEmitter(library_file_path) 1115 library_emitter = self._multiemitter.FileEmitter(library_file_path)
1124 library_file_dir = os.path.dirname(library_file_path) 1116 library_file_dir = os.path.dirname(library_file_path)
1125 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) 1117 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir)
1126 imports_emitter = library_emitter.Emit( 1118 imports_emitter = library_emitter.Emit(
1127 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) 1119 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir))
1128 for path in sorted(self._path_to_emitter.keys()): 1120 for path in sorted(self._path_to_emitter.keys()):
1129 relpath = os.path.relpath(path, library_file_dir) 1121 relpath = os.path.relpath(path, library_file_dir)
1130 imports_emitter.Emit( 1122 imports_emitter.Emit(
1131 "#source('$PATH');\n", PATH=massage_path(relpath)) 1123 "#source('$PATH');\n", PATH=massage_path(relpath))
OLDNEW
« lib/html/idl/dart/dart.idl ('K') | « lib/html/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698