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

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

Issue 254463006: This CL contains all of the changes for splitting off all of the native (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Additional cleanup, eliminate now unused generality Created 6 years, 7 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/idlrenderer.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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 # TODO(antonm): use common dispatcher generation for this case as well. 498 # TODO(antonm): use common dispatcher generation for this case as well.
499 has_optional = any(param_info.is_optional 499 has_optional = any(param_info.is_optional
500 for param_info in constructor_info.param_infos) 500 for param_info in constructor_info.param_infos)
501 501
502 if not has_optional: 502 if not has_optional:
503 self._members_emitter.Emit( 503 self._members_emitter.Emit(
504 '\n $(METADATA)' 504 '\n $(METADATA)'
505 'factory $CTOR($PARAMS) => ' 505 'factory $CTOR($PARAMS) => '
506 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n', 506 '$FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n',
507 CTOR=constructor_info._ConstructorFullName(self._DartType), 507 CTOR=constructor_info._ConstructorFullName(self._DartType),
508 PARAMS=constructor_info.ParametersDeclaration(self._DartType), 508 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
509 FACTORY=factory_name, 509 FACTORY=factory_name,
510 METADATA=metadata, 510 METADATA=metadata,
511 CTOR_FACTORY_NAME=factory_constructor_name, 511 CTOR_FACTORY_NAME=factory_constructor_name,
512 FACTORY_PARAMS=factory_parameters) 512 FACTORY_PARAMS=factory_parameters)
513 else: 513 else:
514 inits = self._members_emitter.Emit( 514 inits = self._members_emitter.Emit(
515 '\n $(METADATA)' 515 '\n $(METADATA)'
516 'factory $CONSTRUCTOR($PARAMS) {\n' 516 'factory $CONSTRUCTOR($PARAMS) {\n'
517 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n' 517 ' var e = $FACTORY.$CTOR_FACTORY_NAME($FACTORY_PARAMS);\n'
518 '$!INITS' 518 '$!INITS'
519 ' return e;\n' 519 ' return e;\n'
520 ' }\n', 520 ' }\n',
521 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType), 521 CONSTRUCTOR=constructor_info._ConstructorFullName(self._DartType),
522 METADATA=metadata, 522 METADATA=metadata,
523 FACTORY=factory_name, 523 FACTORY=factory_name,
524 CTOR_FACTORY_NAME=factory_constructor_name, 524 CTOR_FACTORY_NAME=factory_constructor_name,
525 PARAMS=constructor_info.ParametersDeclaration(self._DartType), 525 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType),
526 FACTORY_PARAMS=factory_parameters) 526 FACTORY_PARAMS=factory_parameters)
527 527
528 for index, param_info in enumerate(constructor_info.param_infos): 528 for index, param_info in enumerate(constructor_info.param_infos):
529 if param_info.is_optional: 529 if param_info.is_optional:
530 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name) 530 inits.Emit(' if ($E != null) e.$E = $E;\n', E=param_info.name)
531 else: 531 else:
532 def GenerateCall( 532 def GenerateCall(
533 stmts_emitter, call_emitter, 533 stmts_emitter, call_emitter,
534 version, signature_index, argument_count): 534 version, signature_index, argument_count):
535 name = emitter.Format('_create_$VERSION', VERSION=version) 535 name = emitter.Format('_create_$VERSION', VERSION=version)
(...skipping 15 matching lines...) Expand all
551 self._GenerateOverloadDispatcher( 551 self._GenerateOverloadDispatcher(
552 constructor_info, 552 constructor_info,
553 constructor_info.idl_args, 553 constructor_info.idl_args,
554 False, 554 False,
555 emitter.Format('$(METADATA)$FACTORY_KEYWORD $CTOR($PARAMS)', 555 emitter.Format('$(METADATA)$FACTORY_KEYWORD $CTOR($PARAMS)',
556 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else 556 FACTORY_KEYWORD=('factory' if not custom_factory_ctr else
557 'static %s' % constructor_full_name), 557 'static %s' % constructor_full_name),
558 CTOR=(('' if not custom_factory_ctr else '_factory') 558 CTOR=(('' if not custom_factory_ctr else '_factory')
559 + constructor_full_name), 559 + constructor_full_name),
560 METADATA=metadata, 560 METADATA=metadata,
561 PARAMS=constructor_info.ParametersDeclaration(self._DartType)), 561 PARAMS=constructor_info.ParametersAsDeclaration(self._DartType)),
562 GenerateCall, 562 GenerateCall,
563 IsOptional) 563 IsOptional)
564 564
565 def _AddFutureifiedOperation(self, info, html_name): 565 def _AddFutureifiedOperation(self, info, html_name):
566 """Given a API function that uses callbacks, convert it to using Futures. 566 """Given a API function that uses callbacks, convert it to using Futures.
567 567
568 This conversion assumes the success callback is always provided before the 568 This conversion assumes the success callback is always provided before the
569 error callback (and so far in the DOM API, this is the case).""" 569 error callback (and so far in the DOM API, this is the case)."""
570 callback_info = GetCallbackInfo( 570 callback_info = GetCallbackInfo(
571 self._database.GetInterface(info.callback_args[0].type_id)) 571 self._database.GetInterface(info.callback_args[0].type_id))
(...skipping 10 matching lines...) Expand all
582 ' $ORIGINAL_FUNCTION($PARAMS_LIST\n' 582 ' $ORIGINAL_FUNCTION($PARAMS_LIST\n'
583 ' $NAMED_PARAM($VARIABLE_NAME) { ' 583 ' $NAMED_PARAM($VARIABLE_NAME) { '
584 'completer.complete($VARIABLE_NAME); }' 584 'completer.complete($VARIABLE_NAME); }'
585 '$ERROR_CALLBACK);\n' 585 '$ERROR_CALLBACK);\n'
586 ' return completer.future;\n' 586 ' return completer.future;\n'
587 ' }\n', 587 ' }\n',
588 METADATA=metadata, 588 METADATA=metadata,
589 MODIFIERS='static ' if info.IsStatic() else '', 589 MODIFIERS='static ' if info.IsStatic() else '',
590 TYPE=self.SecureOutputType(info.type_name), 590 TYPE=self.SecureOutputType(info.type_name),
591 NAME=html_name[1:], 591 NAME=html_name[1:],
592 PARAMS=info.ParametersDeclaration(self._NarrowInputType 592 PARAMS=info.ParametersAsDeclaration(self._NarrowInputType
593 if '_NarrowInputType' in dir(self) else self._DartType), 593 if '_NarrowInputType' in dir(self) else self._DartType),
594 PARAMS_LIST='' if param_list == '' else param_list + ',', 594 PARAMS_LIST='' if param_list == '' else param_list + ',',
595 NAMED_PARAM=('%s : ' % info.callback_args[0].name 595 NAMED_PARAM=('%s : ' % info.callback_args[0].name
596 if info.requires_named_arguments and 596 if info.requires_named_arguments and
597 info.callback_args[0].is_optional else ''), 597 info.callback_args[0].is_optional else ''),
598 VARIABLE_NAME= '' if len(callback_info.param_infos) == 0 else 'value', 598 VARIABLE_NAME= '' if len(callback_info.param_infos) == 0 else 'value',
599 ERROR_CALLBACK=('' if len(info.callback_args) == 1 else 599 ERROR_CALLBACK=('' if len(info.callback_args) == 1 else
600 (',\n %s(error) { completer.completeError(error); }' % 600 (',\n %s(error) { completer.completeError(error); }' %
601 ('%s : ' % info.callback_args[1].name 601 ('%s : ' % info.callback_args[1].name
602 if info.requires_named_arguments and 602 if info.requires_named_arguments and
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 Arguments: 634 Arguments:
635 operation - The operation to be declared. 635 operation - The operation to be declared.
636 return_type_name - The name of the return type. 636 return_type_name - The name of the return type.
637 method_name - The name of the method. 637 method_name - The name of the method.
638 """ 638 """
639 self._members_emitter.Emit( 639 self._members_emitter.Emit(
640 '\n' 640 '\n'
641 ' $TYPE $NAME($PARAMS);\n', 641 ' $TYPE $NAME($PARAMS);\n',
642 TYPE=return_type_name, 642 TYPE=return_type_name,
643 NAME=method_name, 643 NAME=method_name,
644 PARAMS=operation.ParametersDeclaration(self._DartType)) 644 PARAMS=operation.ParametersAsDeclaration(self._DartType))
645 645
646 def EmitListMixin(self, element_name): 646 def EmitListMixin(self, element_name):
647 # TODO(sra): Use separate mixins for mutable implementations of List<T>. 647 # TODO(sra): Use separate mixins for mutable implementations of List<T>.
648 # TODO(sra): Use separate mixins for typed array implementations of List<T>. 648 # TODO(sra): Use separate mixins for typed array implementations of List<T>.
649 template_file = 'immutable_list_mixin.darttemplate' 649 template_file = 'immutable_list_mixin.darttemplate'
650 has_length = False 650 has_length = False
651 has_length_setter = False 651 has_length_setter = False
652 652
653 def _HasExplicitIndexedGetter(self): 653 def _HasExplicitIndexedGetter(self):
654 return any(op.id == 'getItem' for op in self._interface.operations) 654 return any(op.id == 'getItem' for op in self._interface.operations)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 706
707 def SecureBaseName(self, type_name): 707 def SecureBaseName(self, type_name):
708 if type_name in _secure_base_types: 708 if type_name in _secure_base_types:
709 return _secure_base_types[type_name] 709 return _secure_base_types[type_name]
710 710
711 def _DartType(self, type_name): 711 def _DartType(self, type_name):
712 return self._type_registry.DartType(type_name) 712 return self._type_registry.DartType(type_name)
713 713
714 def _TypeInfo(self, type_name): 714 def _TypeInfo(self, type_name):
715 return self._type_registry.TypeInfo(type_name) 715 return self._type_registry.TypeInfo(type_name)
OLDNEW
« no previous file with comments | « tools/dom/scripts/generator.py ('k') | tools/dom/scripts/idlrenderer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698