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

Side by Side Diff: client/dom/scripts/generator.py

Issue 9843003: Proper handling of sequence<T> in IDLs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | « no previous file | no next file » | 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 systems to generate 6 """This module provides shared functionality for systems to generate
7 Dart APIs from the IDL database.""" 7 Dart APIs from the IDL database."""
8 8
9 import re 9 import re
10 10
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return '*' + javascript_binding_name 227 return '*' + javascript_binding_name
228 228
229 229
230 def MatchSourceFilter(filter, thing): 230 def MatchSourceFilter(filter, thing):
231 if not filter: 231 if not filter:
232 return True 232 return True
233 else: 233 else:
234 return any(token in thing.annotations for token in filter) 234 return any(token in thing.annotations for token in filter)
235 235
236 def DartType(idl_type_name): 236 def DartType(idl_type_name):
237 match = re.match(r'sequence<(\w*)>$', idl_type_name)
238 if match:
239 return 'List<%s>' % GetIDLTypeInfo(match.group(1)).dart_type()
240 return GetIDLTypeInfo(idl_type_name).dart_type() 237 return GetIDLTypeInfo(idl_type_name).dart_type()
241 238
242 # Given a list of overloaded arguments, render a dart argument. 239 # Given a list of overloaded arguments, render a dart argument.
243 def _DartArg(args, interface): 240 def _DartArg(args, interface):
244 # Given a list of overloaded arguments, choose a suitable name. 241 # Given a list of overloaded arguments, choose a suitable name.
245 def OverloadedName(args): 242 def OverloadedName(args):
246 return '_OR_'.join(sorted(set(arg.id for arg in args))) 243 return '_OR_'.join(sorted(set(arg.id for arg in args)))
247 244
248 # Given a list of overloaded arguments, choose a suitable type. 245 # Given a list of overloaded arguments, choose a suitable type.
249 def OverloadedType(args): 246 def OverloadedType(args):
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 self._conversion_template = conversion_template 477 self._conversion_template = conversion_template
481 self._custom_to_dart = custom_to_dart 478 self._custom_to_dart = custom_to_dart
482 self._conversion_includes = conversion_includes 479 self._conversion_includes = conversion_includes
483 480
484 def idl_type(self): 481 def idl_type(self):
485 return self._idl_type 482 return self._idl_type
486 483
487 def dart_type(self): 484 def dart_type(self):
488 if self._dart_type: 485 if self._dart_type:
489 return self._dart_type 486 return self._dart_type
487
488 match = re.match(r'sequence<(\w*)>$', self._idl_type)
489 if match:
490 return 'List<%s>' % DartType(match.group(1))
podivilov 2012/03/23 15:12:07 nit: should be GetIDLTypeInfo(match.group(1)).dart
Anton Muhin 2012/03/23 17:27:31 DartType is exactly this now, no?
491
490 return self._idl_type 492 return self._idl_type
491 493
492 def native_type(self): 494 def native_type(self):
493 if self._native_type: 495 if self._native_type:
494 return self._native_type 496 return self._native_type
495 return self._idl_type 497 return self._idl_type
496 498
497 def parameter_adapter_info(self): 499 def parameter_adapter_info(self):
498 native_type = self.native_type() 500 native_type = self.native_type()
499 if self._ref_counted: 501 if self._ref_counted:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if self._idl_type.startswith('SVGPathSeg'): 535 if self._idl_type.startswith('SVGPathSeg'):
534 include = self._idl_type.replace('Abs', '').replace('Rel', '') 536 include = self._idl_type.replace('Abs', '').replace('Rel', '')
535 else: 537 else:
536 include = self._idl_type 538 include = self._idl_type
537 return ['"%s.h"' % include] + _svg_supplemental_includes 539 return ['"%s.h"' % include] + _svg_supplemental_includes
538 540
539 def receiver(self): 541 def receiver(self):
540 return 'receiver->' 542 return 'receiver->'
541 543
542 def conversion_includes(self): 544 def conversion_includes(self):
543 return ['"Dart%s.h"' % include for include in [self.dart_type()] + self._con version_includes] 545 def NeededDartType(type_name):
546 match = re.match(r'List<(\w*)>$', type_name)
547 if match:
548 return NeededDartType(match.group(1))
549 return type_name
550
551 return ['"Dart%s.h"' % include for include in [NeededDartType(self.dart_type ())] + self._conversion_includes]
podivilov 2012/03/23 15:12:07 Please parse the type in constructor, so you don't
Anton Muhin 2012/03/23 17:27:31 Should I do it right now? If we're looking for op
544 552
545 def conversion_cast(self, expression): 553 def conversion_cast(self, expression):
546 if self._conversion_template: 554 if self._conversion_template:
547 return self._conversion_template % expression 555 return self._conversion_template % expression
548 return expression 556 return expression
549 557
550 def custom_to_dart(self): 558 def custom_to_dart(self):
551 return self._custom_to_dart 559 return self._custom_to_dart
552 560
553 class PrimitiveIDLTypeInfo(IDLTypeInfo): 561 class PrimitiveIDLTypeInfo(IDLTypeInfo):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 '"SVGAnimatedPropertyTearOff.h"', 684 '"SVGAnimatedPropertyTearOff.h"',
677 '"SVGAnimatedListPropertyTearOff.h"', 685 '"SVGAnimatedListPropertyTearOff.h"',
678 '"SVGStaticListPropertyTearOff.h"', 686 '"SVGStaticListPropertyTearOff.h"',
679 '"SVGAnimatedListPropertyTearOff.h"', 687 '"SVGAnimatedListPropertyTearOff.h"',
680 '"SVGTransformListPropertyTearOff.h"', 688 '"SVGTransformListPropertyTearOff.h"',
681 '"SVGPathSegListPropertyTearOff.h"', 689 '"SVGPathSegListPropertyTearOff.h"',
682 ] 690 ]
683 691
684 def GetIDLTypeInfo(idl_type_name): 692 def GetIDLTypeInfo(idl_type_name):
685 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) 693 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698