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

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

Issue 12463028: "Reverting 19586" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/htmlrenamer.py » ('j') | 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 from generator import AnalyzeOperation, ConstantOutputOrder, \ 10 from generator import AnalyzeOperation, ConstantOutputOrder, \
11 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ 11 DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \
12 IsPureInterface, TypeOrNothing, GetAnnotationsAndComments, \ 12 IsPureInterface, TypeOrNothing, GetAnnotationsAndComments, \
13 FormatAnnotationsAndComments, ConvertToFuture, GetCallbackInfo 13 FormatAnnotationsAndComments
14 from htmlrenamer import convert_to_future_members
15 14
16 # Types that are accessible cross-frame in a limited fashion. 15 # Types that are accessible cross-frame in a limited fashion.
17 # In these cases, the base type (e.g., WindowBase) provides restricted access 16 # In these cases, the base type (e.g., WindowBase) provides restricted access
18 # while the subtype (e.g., Window) provides full access to the 17 # while the subtype (e.g., Window) provides full access to the
19 # corresponding objects if there are from the same frame. 18 # corresponding objects if there are from the same frame.
20 _secure_base_types = { 19 _secure_base_types = {
21 'Window': 'WindowBase', 20 'Window': 'WindowBase',
22 'Location': 'LocationBase', 21 'Location': 'LocationBase',
23 'History': 'HistoryBase', 22 'History': 'HistoryBase',
24 } 23 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 for operation in interface.operations: 82 for operation in interface.operations:
84 if operation.id not in operationsById: 83 if operation.id not in operationsById:
85 operationsById[operation.id] = [] 84 operationsById[operation.id] = []
86 operationsById[operation.id].append(operation) 85 operationsById[operation.id].append(operation)
87 86
88 # Generate operations. 87 # Generate operations.
89 for id in sorted(operationsById.keys()): 88 for id in sorted(operationsById.keys()):
90 operations = operationsById[id] 89 operations = operationsById[id]
91 info = AnalyzeOperation(interface, operations) 90 info = AnalyzeOperation(interface, operations)
92 self.AddOperation(info, declare_only) 91 self.AddOperation(info, declare_only)
93 if ('%s.%s' % (interface.id, info.declared_name) in
94 convert_to_future_members):
95 self.AddOperation(ConvertToFuture(info), declare_only)
96 92
97 def AddSecondaryMembers(self, interface): 93 def AddSecondaryMembers(self, interface):
98 # With multiple inheritance, attributes and operations of non-first 94 # With multiple inheritance, attributes and operations of non-first
99 # interfaces need to be added. Sometimes the attribute or operation is 95 # interfaces need to be added. Sometimes the attribute or operation is
100 # defined in the current interface as well as a parent. In that case we 96 # defined in the current interface as well as a parent. In that case we
101 # avoid making a duplicate definition and pray that the signatures match. 97 # avoid making a duplicate definition and pray that the signatures match.
102 secondary_parents = self._TransitiveSecondaryParents(interface) 98 secondary_parents = self._TransitiveSecondaryParents(interface)
103 for parent_interface in sorted(secondary_parents): 99 for parent_interface in sorted(secondary_parents):
104 if isinstance(parent_interface, str): 100 if isinstance(parent_interface, str):
105 continue 101 continue
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 constructor_info.idl_args, 447 constructor_info.idl_args,
452 False, 448 False,
453 [info.name for info in constructor_info.param_infos], 449 [info.name for info in constructor_info.param_infos],
454 emitter.Format('$(ANNOTATIONS)factory $CTOR($PARAMS)', 450 emitter.Format('$(ANNOTATIONS)factory $CTOR($PARAMS)',
455 CTOR=constructor_info._ConstructorFullName(self._DartType), 451 CTOR=constructor_info._ConstructorFullName(self._DartType),
456 ANNOTATIONS=annotations, 452 ANNOTATIONS=annotations,
457 PARAMS=constructor_info.ParametersDeclaration(self._DartType)), 453 PARAMS=constructor_info.ParametersDeclaration(self._DartType)),
458 GenerateCall, 454 GenerateCall,
459 IsOptional) 455 IsOptional)
460 456
461 def _AddFutureifiedOperation(self, info, html_name):
462 """Given a API function that uses callbacks, convert it to using Futures.
463
464 This conversion assumes the success callback is always provided before the
465 error callback (and so far in the DOM API, this is the case)."""
466 callback_info = GetCallbackInfo(
467 self._database.GetInterface(info.callback_args[0].type_id))
468
469 param_list = info.ParametersAsArgumentList()
470 annotations = ''
471 if '_RenamingAnnotation' in dir(self):
472 annotations = (self._RenamingAnnotation(info.declared_name, html_name) +
473 self._Annotations(info.type_name, info.declared_name))
474 self._members_emitter.Emit(
475 '\n'
476 ' $ANNOTATIONS$MODIFIERS$TYPE$FUTURE_GENERIC $NAME($PARAMS) {\n'
477 ' var completer = new Completer$(FUTURE_GENERIC)();\n'
478 ' $ORIGINAL_FUNCTION($PARAMS_LIST\n'
479 ' $NAMED_PARAM($VARIABLE_NAME) { '
480 'completer.complete($VARIABLE_NAME); }'
481 '$ERROR_CALLBACK);\n'
482 ' return completer.future;\n'
483 ' }\n',
484 ANNOTATIONS=annotations,
485 MODIFIERS='static ' if info.IsStatic() else '',
486 TYPE=self.SecureOutputType(info.type_name),
487 NAME=html_name[1:],
488 PARAMS=info.ParametersDeclaration(self._NarrowInputType
489 if '_NarrowInputType' in dir(self) else self._DartType),
490 PARAMS_LIST='' if param_list == '' else param_list + ',',
491 NAMED_PARAM=('%s : ' % info.callback_args[0].name
492 if info.requires_named_arguments and
493 info.callback_args[0].is_optional else ''),
494 VARIABLE_NAME= '' if len(callback_info.param_infos) == 0 else 'value',
495 ERROR_CALLBACK=('' if len(info.callback_args) == 1 else
496 (',\n %s(error) { completer.completeError(error); }' %
497 ('%s : ' % info.callback_args[1].name
498 if info.requires_named_arguments and
499 info.callback_args[1].is_optional else ''))),
500 FUTURE_GENERIC = ('' if len(callback_info.param_infos) == 0 or
501 not callback_info.param_infos[0].type_id else
502 '<%s>' % self._DartType(callback_info.param_infos[0].type_id)),
503 ORIGINAL_FUNCTION = html_name)
504
505 def EmitHelpers(self, base_class): 457 def EmitHelpers(self, base_class):
506 pass 458 pass
507 459
508 def DeclareAttribute(self, attribute, type_name, attr_name, read_only): 460 def DeclareAttribute(self, attribute, type_name, attr_name, read_only):
509 """ Declares an attribute but does not include the code to invoke it. 461 """ Declares an attribute but does not include the code to invoke it.
510 """ 462 """
511 if read_only: 463 if read_only:
512 template = '\n $TYPE get $NAME;\n' 464 template = '\n $TYPE get $NAME;\n'
513 else: 465 else:
514 template = '\n $TYPE $NAME;\n' 466 template = '\n $TYPE $NAME;\n'
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 walk(interface.parents) 555 walk(interface.parents)
604 else: 556 else:
605 walk(interface.parents[1:]) 557 walk(interface.parents[1:])
606 return result 558 return result
607 559
608 def _DartType(self, type_name): 560 def _DartType(self, type_name):
609 return self._type_registry.DartType(type_name) 561 return self._type_registry.DartType(type_name)
610 562
611 def _IsPrivate(self, name): 563 def _IsPrivate(self, name):
612 return name.startswith('_') 564 return name.startswith('_')
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/htmlrenamer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698