| 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 def GenerateCall( | 431 def GenerateCall( |
| 432 stmts_emitter, call_emitter, version, signature_index, argument_count): | 432 stmts_emitter, call_emitter, version, signature_index, argument_count): |
| 433 generate_call( | 433 generate_call( |
| 434 stmts_emitter, call_emitter, | 434 stmts_emitter, call_emitter, |
| 435 version, operations[signature_index], argument_count) | 435 version, operations[signature_index], argument_count) |
| 436 | 436 |
| 437 def IsOptional(signature_index, argument): | 437 def IsOptional(signature_index, argument): |
| 438 return is_optional(operations[signature_index], argument) | 438 return is_optional(operations[signature_index], argument) |
| 439 | 439 |
| 440 emitter = \ | 440 emitter = \ |
| 441 self._native_library_emitter if self._dart_use_blink \ | 441 self._native_class_emitter if self._dart_use_blink \ |
| 442 else self._members_emitter | 442 else self._members_emitter |
| 443 | 443 |
| 444 self._GenerateOverloadDispatcher( | 444 self._GenerateOverloadDispatcher( |
| 445 info, | 445 info, |
| 446 [operation.arguments for operation in operations], | 446 [operation.arguments for operation in operations], |
| 447 operations[0].type.id == 'void', | 447 operations[0].type.id == 'void', |
| 448 declaration, | 448 declaration, |
| 449 GenerateCall, | 449 GenerateCall, |
| 450 IsOptional, | 450 IsOptional, |
| 451 emitter, | 451 emitter, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 else: | 541 else: |
| 542 custom_factory_ctr = self._interface.id in _custom_factories | 542 custom_factory_ctr = self._interface.id in _custom_factories |
| 543 constructor_full_name = constructor_info._ConstructorFullName( | 543 constructor_full_name = constructor_info._ConstructorFullName( |
| 544 self._DartType) | 544 self._DartType) |
| 545 | 545 |
| 546 def GenerateCall( | 546 def GenerateCall( |
| 547 stmts_emitter, call_emitter, | 547 stmts_emitter, call_emitter, |
| 548 version, signature_index, argument_count): | 548 version, signature_index, argument_count): |
| 549 name = emitter.Format('_create_$VERSION', VERSION=version) | 549 name = emitter.Format('_create_$VERSION', VERSION=version) |
| 550 if self._dart_use_blink: | 550 if self._dart_use_blink: |
| 551 qualified_name = \ | 551 qualified_name = self.DeriveNativeName(name + 'constructorCallback') |
| 552 "_".join(["Native",self._interface.id, | |
| 553 name + 'constructorCallback']) | |
| 554 else: | 552 else: |
| 555 qualified_name = emitter.Format( | 553 qualified_name = emitter.Format( |
| 556 '$FACTORY.$NAME', | 554 '$FACTORY.$NAME', |
| 557 FACTORY=factory_name, | 555 FACTORY=factory_name, |
| 558 NAME=name) | 556 NAME=name) |
| 559 call_emitter.Emit('$FACTORY_NAME($FACTORY_PARAMS)', | 557 call_emitter.Emit('$FACTORY_NAME($FACTORY_PARAMS)', |
| 560 FACTORY_NAME=qualified_name, | 558 FACTORY_NAME=qualified_name, |
| 561 FACTORY_PARAMS= \ | 559 FACTORY_PARAMS= \ |
| 562 constructor_info.ParametersAsArgumentList(argument_count)) | 560 constructor_info.ParametersAsArgumentList(argument_count)) |
| 563 self.EmitStaticFactoryOverload( | 561 self.EmitStaticFactoryOverload( |
| 564 constructor_info, name, | 562 constructor_info, name, |
| 565 constructor_info.idl_args[signature_index][:argument_count]) | 563 constructor_info.idl_args[signature_index][:argument_count]) |
| 566 | 564 |
| 567 def IsOptional(signature_index, argument): | 565 def IsOptional(signature_index, argument): |
| 568 return self.IsConstructorArgumentOptional(argument) | 566 return self.IsConstructorArgumentOptional(argument) |
| 569 | 567 |
| 570 entry_declaration = emitter.Format( | 568 entry_declaration = emitter.Format( |
| 571 '$(METADATA)$FACTORY_KEYWORD $CTOR($PARAMS)', | 569 '$(METADATA)$FACTORY_KEYWORD $CTOR($PARAMS)', |
| 572 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else | 570 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else |
| 573 'static %s' % constructor_full_name), | 571 'static %s' % constructor_full_name), |
| 574 CTOR=(('' if not custom_factory_ctr else '_factory') | 572 CTOR=(('' if not custom_factory_ctr else '_factory') |
| 575 + constructor_full_name), | 573 + constructor_full_name), |
| 576 METADATA=metadata, | 574 METADATA=metadata, |
| 577 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType)) | 575 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType)) |
| 578 | 576 |
| 579 if self._dart_use_blink: | 577 if self._dart_use_blink: |
| 580 overload_emitter = self._native_library_emitter | 578 overload_emitter = self._native_class_emitter |
| 581 mname = constructor_full_name.replace(".", "_") | 579 mname = constructor_full_name.replace(".", "_") |
| 582 blink_name = \ | 580 blink_name = "$mk" + mname |
| 583 "_".join(["Native",self._interface.id, mname]) | 581 qual_name = self.DeriveQualifiedBlinkName( |
| 584 qual_name = self._native_library_name + "." + blink_name | 582 self._interface.id, blink_name) |
| 585 actuals_s = constructor_info.ParametersAsStringOfVariables() | 583 actuals_s = constructor_info.ParametersAsStringOfVariables() |
| 586 self._members_emitter.Emit( | 584 self._members_emitter.Emit( |
| 587 '\n' | 585 '\n' |
| 588 ' $DECLARATION => $NATIVE_NAME($ACTUALS);\n', | 586 ' $DECLARATION => $NATIVE_NAME($ACTUALS);\n', |
| 589 DECLARATION=entry_declaration, | 587 DECLARATION=entry_declaration, |
| 590 NATIVE_NAME=qual_name, | 588 NATIVE_NAME=qual_name, |
| 591 ACTUALS=actuals_s) | 589 ACTUALS=actuals_s) |
| 592 overload_declaration = emitter.Format( | 590 overload_declaration = emitter.Format( |
| 593 '// Generated overload resolver\n' | 591 '// Generated overload resolver\n' |
| 594 '$CTOR($PARAMS)', | 592 ' static $CTOR($PARAMS)', |
| 595 CTOR=blink_name, | 593 CTOR=blink_name, |
| 596 PARAMS=actuals_s) | 594 PARAMS=actuals_s) |
| 597 | 595 |
| 598 | 596 |
| 599 else: | 597 else: |
| 600 overload_emitter = self._members_emitter | 598 overload_emitter = self._members_emitter |
| 601 overload_declaration = entry_declaration | 599 overload_declaration = entry_declaration |
| 602 | 600 |
| 603 self._GenerateOverloadDispatcher( | 601 self._GenerateOverloadDispatcher( |
| 604 constructor_info, | 602 constructor_info, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 751 |
| 754 def SecureBaseName(self, type_name): | 752 def SecureBaseName(self, type_name): |
| 755 if type_name in _secure_base_types: | 753 if type_name in _secure_base_types: |
| 756 return _secure_base_types[type_name] | 754 return _secure_base_types[type_name] |
| 757 | 755 |
| 758 def _DartType(self, type_name): | 756 def _DartType(self, type_name): |
| 759 return self._type_registry.DartType(type_name) | 757 return self._type_registry.DartType(type_name) |
| 760 | 758 |
| 761 def _TypeInfo(self, type_name): | 759 def _TypeInfo(self, type_name): |
| 762 return self._type_registry.TypeInfo(type_name) | 760 return self._type_registry.TypeInfo(type_name) |
| OLD | NEW |