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

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

Issue 10513004: Implement v8-like overload resolving. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 6 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 | « lib/dom/scripts/databasebuilder.py ('k') | lib/dom/scripts/systemnative.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 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 copy 9 import copy
10 import re 10 import re
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 new_operation.arguments = new_operation.arguments[:i] 251 new_operation.arguments = new_operation.arguments[:i]
252 split_operations.append(new_operation) 252 split_operations.append(new_operation)
253 split_operations.append(operation) 253 split_operations.append(operation)
254 254
255 # Zip together arguments from each overload by position, then convert 255 # Zip together arguments from each overload by position, then convert
256 # to a dart argument. 256 # to a dart argument.
257 args = map(lambda *args: _DartArg(args, interface), 257 args = map(lambda *args: _DartArg(args, interface),
258 *(op.arguments for op in split_operations)) 258 *(op.arguments for op in split_operations))
259 259
260 info = OperationInfo() 260 info = OperationInfo()
261 info.operations = operations
261 info.overloads = split_operations 262 info.overloads = split_operations
262 info.declared_name = operations[0].id 263 info.declared_name = operations[0].id
263 info.name = operations[0].ext_attrs.get('DartName', info.declared_name) 264 info.name = operations[0].ext_attrs.get('DartName', info.declared_name)
264 info.constructor_name = None 265 info.constructor_name = None
265 info.js_name = info.declared_name 266 info.js_name = info.declared_name
266 info.type_name = DartType(operations[0].type.id) # TODO: widen. 267 info.type_name = DartType(operations[0].type.id) # TODO: widen.
267 info.param_infos = args 268 info.param_infos = args
268 return info 269 return info
269 270
270 271
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 return self._idl_type 522 return self._idl_type
522 523
523 def dart_type(self): 524 def dart_type(self):
524 return self._dart_type or self._idl_type 525 return self._dart_type or self._idl_type
525 526
526 def native_type(self): 527 def native_type(self):
527 return self._native_type or self._idl_type 528 return self._native_type or self._idl_type
528 529
529 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): 530 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
530 if 'Callback' in idl_node.ext_attrs: 531 if 'Callback' in idl_node.ext_attrs:
531 if 'RequiredCppParameter' in idl_node.ext_attrs: 532 if set(['Optional', 'Callback']).issubset(idl_node.ext_attrs.keys()):
532 flag = 'DartUtilities::ConvertNullToDefaultValue' 533 flag = 'DartUtilities::ConvertNullToDefaultValue'
533 else: 534 else:
534 flag = 'DartUtilities::ConvertNone' 535 flag = 'DartUtilities::ConvertNone'
535 emitter.Emit( 536 emitter.Emit(
536 '\n' 537 '\n'
537 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc eption);\n' 538 ' RefPtr<$TYPE> $NAME = Dart$IDL_TYPE::create($HANDLE, $FLAG, exc eption);\n'
538 ' if (exception)\n' 539 ' if (exception)\n'
539 ' goto fail;\n', 540 ' goto fail;\n',
540 TYPE=self.native_type(), 541 TYPE=self.native_type(),
541 NAME=name, 542 NAME=name,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 def __init__(self, idl_type, dart_type, native_type=None, 631 def __init__(self, idl_type, dart_type, native_type=None,
631 webcore_getter_name='getAttribute', 632 webcore_getter_name='getAttribute',
632 webcore_setter_name='setAttribute'): 633 webcore_setter_name='setAttribute'):
633 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type, 634 super(PrimitiveIDLTypeInfo, self).__init__(idl_type, dart_type=dart_type,
634 native_type=native_type) 635 native_type=native_type)
635 self._webcore_getter_name = webcore_getter_name 636 self._webcore_getter_name = webcore_getter_name
636 self._webcore_setter_name = webcore_setter_name 637 self._webcore_setter_name = webcore_setter_name
637 638
638 def emit_to_native(self, emitter, idl_node, name, handle, interface_name): 639 def emit_to_native(self, emitter, idl_node, name, handle, interface_name):
639 arguments = [handle] 640 arguments = [handle]
640 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or 'RequiredC ppParameter' in idl_node.ext_attrs: 641 if idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString':
641 arguments.append('DartUtilities::ConvertNullToDefaultValue') 642 arguments.append('DartUtilities::ConvertNullToDefaultValue')
642 emitter.Emit( 643 emitter.Emit(
643 '\n' 644 '\n'
644 ' const ParameterAdapter<$TYPE> $NAME($ARGUMENTS);\n' 645 ' const ParameterAdapter<$TYPE> $NAME($ARGUMENTS);\n'
645 ' if (!$NAME.conversionSuccessful()) {\n' 646 ' if (!$NAME.conversionSuccessful()) {\n'
646 ' exception = $NAME.exception();\n' 647 ' exception = $NAME.exception();\n'
647 ' goto fail;\n' 648 ' goto fail;\n'
648 ' }\n', 649 ' }\n',
649 TYPE=self.native_type(), 650 TYPE=self.native_type(),
650 NAME=name, 651 NAME=name,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 '"SVGAnimatedListPropertyTearOff.h"', 796 '"SVGAnimatedListPropertyTearOff.h"',
796 '"SVGTransformListPropertyTearOff.h"', 797 '"SVGTransformListPropertyTearOff.h"',
797 '"SVGPathSegListPropertyTearOff.h"', 798 '"SVGPathSegListPropertyTearOff.h"',
798 ] 799 ]
799 800
800 def GetIDLTypeInfo(idl_type_name): 801 def GetIDLTypeInfo(idl_type_name):
801 match = re.match(r'sequence<(\w+)>$', idl_type_name) 802 match = re.match(r'sequence<(\w+)>$', idl_type_name)
802 if match: 803 if match:
803 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1))) 804 return SequenceIDLTypeInfo(idl_type_name, GetIDLTypeInfo(match.group(1)))
804 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name)) 805 return _idl_type_registry.get(idl_type_name, IDLTypeInfo(idl_type_name))
OLDNEW
« no previous file with comments | « lib/dom/scripts/databasebuilder.py ('k') | lib/dom/scripts/systemnative.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698