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

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

Issue 904663005: Revert "Annotate dart:html constructor expressions with precise non-nullable types." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « tests/html/element_types_test.dart ('k') | tools/dom/scripts/systemhtml.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, \
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 factory_constructor_name = '_create' 540 factory_constructor_name = '_create'
541 factory_parameters = constructor_info.ParametersAsArgumentList() 541 factory_parameters = constructor_info.ParametersAsArgumentList()
542 else: 542 else:
543 factory_parameters = ', '.join(constructor_info.factory_parameters) 543 factory_parameters = ', '.join(constructor_info.factory_parameters)
544 544
545 if constructor_info.pure_dart_constructor: 545 if constructor_info.pure_dart_constructor:
546 # TODO(antonm): use common dispatcher generation for this case as well. 546 # TODO(antonm): use common dispatcher generation for this case as well.
547 has_optional = any(param_info.is_optional 547 has_optional = any(param_info.is_optional
548 for param_info in constructor_info.param_infos) 548 for param_info in constructor_info.param_infos)
549 549
550 factory_expression = self.FactoryConstructorExpression(constructor_info,
551 factory_name, factory_constructor_name, factory_parameters)
552
553 if not has_optional: 550 if not has_optional:
554 self._members_emitter.Emit( 551 self._members_emitter.Emit(
555 '\n $(METADATA)' 552 '\n $(METADATA)'
556 'factory $CTOR($PARAMS) => $FACTORY_EXPRESSION;\n', 553 'factory $CTOR($PARAMS) => '
554 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n',
557 CTOR=constructor_info._ConstructorFullName(self._DartType), 555 CTOR=constructor_info._ConstructorFullName(self._DartType),
558 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType), 556 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
559 FACTORY_EXPRESSION=factory_expression, 557 FACTORY=factory_name,
560 METADATA=metadata) 558 METADATA=metadata,
559 CTOR_FACTORY_NAME=factory_constructor_name,
560 FACTORY_PARAMS=factory_parameters)
561 else: 561 else:
562 inits = self._members_emitter.Emit( 562 inits = self._members_emitter.Emit(
563 '\n $(METADATA)' 563 '\n $(METADATA)'
564 'factory $CONSTRUCTOR($PARAMS) {\n' 564 'factory $CONSTRUCTOR($PARAMS) {\n'
565 ' var e = $FACTORY_EXPRESSION;\n' 565 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n'
566 '$!INITS' 566 '$!INITS'
567 ' return e;\n' 567 ' return e;\n'
568 ' }\n', 568 ' }\n',
569 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), 569 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType),
570 METADATA=metadata, 570 METADATA=metadata,
571 FACTORY_EXPRESSION=factory_expression, 571 FACTORY=factory_name,
572 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType)) 572 CTOR_FACTORY_NAME=factory_constructor_name,
573 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
574 FACTORY_PARAMS=factory_parameters)
573 575
574 for index, param_info in enumerate(constructor_info.param_infos): 576 for index, param_info in enumerate(constructor_info.param_infos):
575 if param_info.is_optional: 577 if param_info.is_optional:
576 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) 578 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name)
577 else: 579 else:
578 custom_factory_ctr = self._interface.id in _custom_factories 580 custom_factory_ctr = self._interface.id in _custom_factories
579 constructor_full_name = constructor_info._ConstructorFullName( 581 constructor_full_name = constructor_info._ConstructorFullName(
580 self._DartType) 582 self._DartType)
581 583
582 def GenerateCall( 584 def GenerateCall(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 621
620 self._GenerateOverloadDispatcher( 622 self._GenerateOverloadDispatcher(
621 constructor_info, 623 constructor_info,
622 constructor_info.idl_args, 624 constructor_info.idl_args,
623 False, 625 False,
624 overload_declaration, 626 overload_declaration,
625 GenerateCall, 627 GenerateCall,
626 IsOptional, 628 IsOptional,
627 overload_emitter) 629 overload_emitter)
628 630
629 def FactoryConstructorExpression(self, constructor_info,
630 factory_name, factory_constructor_name, factory_parameters):
631 return emitter.Format(
632 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS)',
633 FACTORY=factory_name,
634 CTOR_FACTORY_NAME=factory_constructor_name,
635 FACTORY_PARAMS=factory_parameters);
636
637 def _AddFutureifiedOperation(self, info, html_name): 631 def _AddFutureifiedOperation(self, info, html_name):
638 """Given a API function that uses callbacks, convert it to using Futures. 632 """Given a API function that uses callbacks, convert it to using Futures.
639 633
640 This conversion assumes the success callback is always provided before the 634 This conversion assumes the success callback is always provided before the
641 error callback (and so far in the DOM API, this is the case).""" 635 error callback (and so far in the DOM API, this is the case)."""
642 callback_info = GetCallbackInfo( 636 callback_info = GetCallbackInfo(
643 self._database.GetInterface(info.callback_args[0].type_id)) 637 self._database.GetInterface(info.callback_args[0].type_id))
644 638
645 param_list = info.ParametersAsArgumentList() 639 param_list = info.ParametersAsArgumentList()
646 metadata = '' 640 metadata = ''
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 return self._type_registry.TypeInfo(type_name).narrow_dart_type() 778 return self._type_registry.TypeInfo(type_name).narrow_dart_type()
785 779
786 def _NarrowInputType(self, type_name): 780 def _NarrowInputType(self, type_name):
787 return self._NarrowToImplementationType(type_name) 781 return self._NarrowToImplementationType(type_name)
788 782
789 def _DartType(self, type_name): 783 def _DartType(self, type_name):
790 return self._type_registry.DartType(type_name) 784 return self._type_registry.DartType(type_name)
791 785
792 def _TypeInfo(self, type_name): 786 def _TypeInfo(self, type_name):
793 return self._type_registry.TypeInfo(type_name) 787 return self._type_registry.TypeInfo(type_name)
OLDNEW
« no previous file with comments | « tests/html/element_types_test.dart ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698