Chromium Code Reviews| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 | 358 |
| 359 metadata = self._metadata.GetFormattedMetadata( | 359 metadata = self._metadata.GetFormattedMetadata( |
| 360 self._library_name, self._interface.id, self._interface.id, ' ') | 360 self._library_name, self._interface.id, self._interface.id, ' ') |
| 361 | 361 |
| 362 if not factory_constructor_name: | 362 if not factory_constructor_name: |
| 363 factory_constructor_name = '_create' | 363 factory_constructor_name = '_create' |
| 364 factory_parameters = constructor_info.ParametersAsArgumentList() | 364 factory_parameters = constructor_info.ParametersAsArgumentList() |
| 365 has_factory_provider = True | 365 has_factory_provider = True |
| 366 else: | 366 else: |
| 367 factory_parameters = ', '.join(constructor_info.factory_parameters) | 367 factory_parameters = ', '.join(constructor_info.factory_parameters) |
| 368 has_factory_provider = False | 368 has_factory_provider = False |
|
blois
2013/05/08 22:59:05
Is has_factory_provider still being used?
Andrei Mouravski
2013/05/08 23:37:34
Done.
| |
| 369 | 369 |
| 370 if constructor_info.pure_dart_constructor: | 370 if constructor_info.pure_dart_constructor: |
| 371 # TODO(antonm): use common dispatcher generation for this case as well. | 371 # TODO(antonm): use common dispatcher generation for this case as well. |
| 372 has_optional = any(param_info.is_optional | 372 has_optional = any(param_info.is_optional |
| 373 for param_info in constructor_info.param_infos) | 373 for param_info in constructor_info.param_infos) |
| 374 | 374 |
| 375 if not has_optional: | 375 if not has_optional: |
| 376 self._members_emitter.Emit( | 376 self._members_emitter.Emit( |
| 377 '\n $(METADATA)' | 377 '\n $(METADATA)' |
| 378 'factory $CTOR($PARAMS) => ' | 378 'factory $CTOR($PARAMS) => ' |
| 379 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', | 379 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', |
| 380 CTOR=constructor_info._ConstructorFullName(self._DartType), | 380 CTOR=constructor_info._ConstructorFullName(self._DartType), |
| 381 PARAMS=constructor_info.ParametersDeclaration(self._DartType), | 381 PARAMS=constructor_info.ParametersDeclaration(self._DartType), |
| 382 FACTORY=factory_name, | 382 FACTORY=factory_name, |
| 383 METADATA=metadata, | 383 METADATA=metadata, |
| 384 CTOR_FACTORY_NAME=factory_constructor_name, | 384 CTOR_FACTORY_NAME=factory_constructor_name, |
| 385 FACTORY_PARAMS=factory_parameters) | 385 FACTORY_PARAMS=factory_parameters) |
| 386 else: | 386 else: |
| 387 if has_factory_provider: | 387 inits = self._members_emitter.Emit( |
| 388 dispatcher_emitter = self._members_emitter.Emit( | 388 '\n $(METADATA)' |
| 389 '\n $(METADATA)' | 389 'factory $CONSTRUCTOR($PARAMS) {\n' |
| 390 'factory $CTOR($PARAMS) {\n' | 390 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' |
| 391 '$!DISPATCHER' | 391 '$!INITS' |
| 392 ' return $FACTORY._create($FACTORY_PARAMS);\n' | 392 ' return e;\n' |
| 393 ' }\n', | 393 ' }\n', |
| 394 CTOR=constructor_info._ConstructorFullName(self._DartType), | 394 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), |
| 395 PARAMS=constructor_info.ParametersDeclaration(self._DartType), | 395 METADATA=metadata, |
| 396 FACTORY=factory_name, | 396 FACTORY=factory_name, |
| 397 METADATA=metadata, | 397 CTOR_FACTORY_NAME=factory_constructor_name, |
| 398 FACTORY_PARAMS=constructor_info.ParametersAsArgumentList()) | 398 PARAMS=constructor_info.ParametersDeclaration(self._DartType), |
| 399 FACTORY_PARAMS=factory_parameters) | |
| 399 | 400 |
| 400 for index, param_info in enumerate(constructor_info.param_infos): | 401 for index, param_info in enumerate(constructor_info.param_infos): |
| 401 if param_info.is_optional: | 402 if param_info.is_optional: |
| 402 dispatcher_emitter.Emit( | 403 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) |
| 403 ' if ($OPT_PARAM_NAME == null) {\n' | |
| 404 ' return $FACTORY._create($FACTORY_PARAMS);\n' | |
| 405 ' }\n', | |
| 406 OPT_PARAM_NAME=param_info.name, | |
| 407 FACTORY=factory_name, | |
| 408 FACTORY_PARAMS=constructor_info.ParametersAsArgumentList(index)) | |
| 409 else: | |
| 410 inits = self._members_emitter.Emit( | |
| 411 '\n $(METADATA)' | |
| 412 'factory $CONSTRUCTOR($PARAMS) {\n' | |
| 413 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' | |
| 414 '$!INITS' | |
| 415 ' return e;\n' | |
| 416 ' }\n', | |
| 417 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), | |
| 418 METADATA=metadata, | |
| 419 FACTORY=factory_name, | |
| 420 CTOR_FACTORY_NAME=factory_constructor_name, | |
| 421 PARAMS=constructor_info.ParametersDeclaration(self._DartType), | |
| 422 FACTORY_PARAMS=factory_parameters) | |
| 423 | |
| 424 for index, param_info in enumerate(constructor_info.param_infos): | |
| 425 if param_info.is_optional: | |
| 426 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) | |
| 427 else: | 404 else: |
| 428 def GenerateCall( | 405 def GenerateCall( |
| 429 stmts_emitter, call_emitter, | 406 stmts_emitter, call_emitter, |
| 430 version, signature_index, argument_count): | 407 version, signature_index, argument_count): |
| 431 name = emitter.Format('_create_$VERSION', VERSION=version) | 408 name = emitter.Format('_create_$VERSION', VERSION=version) |
| 432 call_emitter.Emit('$FACTORY.$NAME($FACTORY_PARAMS)', | 409 call_emitter.Emit('$FACTORY.$NAME($FACTORY_PARAMS)', |
| 433 FACTORY=factory_name, | 410 FACTORY=factory_name, |
| 434 NAME=name, | 411 NAME=name, |
| 435 FACTORY_PARAMS= \ | 412 FACTORY_PARAMS= \ |
| 436 constructor_info.ParametersAsArgumentList(argument_count)) | 413 constructor_info.ParametersAsArgumentList(argument_count)) |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 if interface.parents: | 574 if interface.parents: |
| 598 parent = interface.parents[0] | 575 parent = interface.parents[0] |
| 599 if IsPureInterface(parent.type.id): | 576 if IsPureInterface(parent.type.id): |
| 600 walk(interface.parents) | 577 walk(interface.parents) |
| 601 else: | 578 else: |
| 602 walk(interface.parents[1:]) | 579 walk(interface.parents[1:]) |
| 603 return result | 580 return result |
| 604 | 581 |
| 605 def _DartType(self, type_name): | 582 def _DartType(self, type_name): |
| 606 return self._type_registry.DartType(type_name) | 583 return self._type_registry.DartType(type_name) |
| OLD | NEW |