OLD | NEW |
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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 type_name, constructor_info.declared_name) | 565 type_name, constructor_info.declared_name) |
566 if conversion: | 566 if conversion: |
567 return conversion.input_type | 567 return conversion.input_type |
568 else: | 568 else: |
569 return self._NarrowInputType(type_name) if type_name else 'dynamic' | 569 return self._NarrowInputType(type_name) if type_name else 'dynamic' |
570 | 570 |
571 if constructor_info.pure_dart_constructor: | 571 if constructor_info.pure_dart_constructor: |
572 # TODO(antonm): use common dispatcher generation for this case as well. | 572 # TODO(antonm): use common dispatcher generation for this case as well. |
573 has_optional = any(param_info.is_optional | 573 has_optional = any(param_info.is_optional |
574 for param_info in constructor_info.param_infos) | 574 for param_info in constructor_info.param_infos) |
575 | 575 factory_call = self.MakeFactoryCall( |
| 576 factory_name, factory_constructor_name, factory_parameters, |
| 577 constructor_info) |
576 if not has_optional: | 578 if not has_optional: |
577 self._members_emitter.Emit( | 579 self._members_emitter.Emit( |
578 '\n $(METADATA)' | 580 '\n $(METADATA)' |
579 'factory $CTOR($PARAMS) => ' | 581 'factory $CTOR($PARAMS) => ' |
580 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', | 582 '$FACTORY_CALL;\n', |
581 CTOR=constructor_info._ConstructorFullName(self._DartType), | 583 CTOR=constructor_info._ConstructorFullName(self._DartType), |
582 PARAMS=constructor_info.ParametersAsDeclaration(InputType), | 584 PARAMS=constructor_info.ParametersAsDeclaration(InputType), |
583 FACTORY=factory_name, | 585 FACTORY_CALL=factory_call, |
584 METADATA=metadata, | 586 METADATA=metadata) |
585 CTOR_FACTORY_NAME=factory_constructor_name, | |
586 FACTORY_PARAMS=factory_parameters) | |
587 else: | 587 else: |
588 inits = self._members_emitter.Emit( | 588 inits = self._members_emitter.Emit( |
589 '\n $(METADATA)' | 589 '\n $(METADATA)' |
590 'factory $CONSTRUCTOR($PARAMS) {\n' | 590 'factory $CONSTRUCTOR($PARAMS) {\n' |
591 ' $CONSTRUCTOR e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\
n' | 591 ' $CONSTRUCTOR e = $FACTORY_CALL;\n' |
592 '$!INITS' | 592 '$!INITS' |
593 ' return e;\n' | 593 ' return e;\n' |
594 ' }\n', | 594 ' }\n', |
595 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), | 595 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), |
596 METADATA=metadata, | 596 METADATA=metadata, |
597 FACTORY=factory_name, | 597 FACTORY_CALL=factory_call, |
598 CTOR_FACTORY_NAME=factory_constructor_name, | 598 PARAMS=constructor_info.ParametersAsDeclaration(InputType)) |
599 PARAMS=constructor_info.ParametersAsDeclaration(InputType), | |
600 FACTORY_PARAMS=factory_parameters) | |
601 | 599 |
602 for index, param_info in enumerate(constructor_info.param_infos): | 600 for index, param_info in enumerate(constructor_info.param_infos): |
603 if param_info.is_optional: | 601 if param_info.is_optional: |
604 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) | 602 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) |
605 else: | 603 else: |
606 custom_factory_ctr = self._interface.id in _custom_factories | 604 custom_factory_ctr = self._interface.id in _custom_factories |
607 constructor_full_name = constructor_info._ConstructorFullName( | 605 constructor_full_name = constructor_info._ConstructorFullName( |
608 self._DartType) | 606 self._DartType) |
609 | 607 |
610 def GenerateCall( | 608 def GenerateCall( |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 def _InputType(self, type_name, info): | 892 def _InputType(self, type_name, info): |
895 conversion = self._InputConversion(type_name, info.declared_name) | 893 conversion = self._InputConversion(type_name, info.declared_name) |
896 if conversion: | 894 if conversion: |
897 return conversion.input_type | 895 return conversion.input_type |
898 else: | 896 else: |
899 # If typedef it's a union return dynamic. | 897 # If typedef it's a union return dynamic. |
900 if self._database.HasTypeDef(type_name): | 898 if self._database.HasTypeDef(type_name): |
901 return 'dynamic' | 899 return 'dynamic' |
902 else: | 900 else: |
903 return self._NarrowInputType(type_name) if type_name else 'dynamic' | 901 return self._NarrowInputType(type_name) if type_name else 'dynamic' |
OLD | NEW |