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

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

Issue 9500012: Get rid of GetIDLTypeInfoByName. (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 | « client/dom/scripts/generator.py ('k') | 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 the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 if operation.type.id == 'void': 66 if operation.type.id == 'void':
67 return_type = 'void' 67 return_type = 'void'
68 return_prefix = '' 68 return_prefix = ''
69 else: 69 else:
70 return_type = 'bool' 70 return_type = 'bool'
71 return_prefix = 'return ' 71 return_prefix = 'return '
72 72
73 parameters = [] 73 parameters = []
74 arguments = [] 74 arguments = []
75 for argument in operation.arguments: 75 for argument in operation.arguments:
76 argument_type_info = GetIDLTypeInfo(argument.type) 76 argument_type_info = GetIDLTypeInfo(argument.type.id)
77 parameters.append('%s %s' % (argument_type_info.parameter_type(), 77 parameters.append('%s %s' % (argument_type_info.parameter_type(),
78 argument.id)) 78 argument.id))
79 arguments.append(argument.id) 79 arguments.append(argument.id)
80 80
81 cpp_header_handlers_emitter.Emit( 81 cpp_header_handlers_emitter.Emit(
82 '\n' 82 '\n'
83 ' virtual $TYPE handleEvent($PARAMETERS);\n', 83 ' virtual $TYPE handleEvent($PARAMETERS);\n',
84 TYPE=return_type, PARAMETERS=', '.join(parameters)) 84 TYPE=return_type, PARAMETERS=', '.join(parameters))
85 85
86 cpp_impl_handlers_emitter.Emit( 86 cpp_impl_handlers_emitter.Emit(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 self._super_interface = super_interface 238 self._super_interface = super_interface
239 self._dart_impl_emitter = dart_impl_emitter 239 self._dart_impl_emitter = dart_impl_emitter
240 self._cpp_header_emitter = cpp_header_emitter 240 self._cpp_header_emitter = cpp_header_emitter
241 self._cpp_impl_emitter = cpp_impl_emitter 241 self._cpp_impl_emitter = cpp_impl_emitter
242 self._base_members = base_members 242 self._base_members = base_members
243 self._templates = templates 243 self._templates = templates
244 self._current_secondary_parent = None 244 self._current_secondary_parent = None
245 245
246 def StartInterface(self): 246 def StartInterface(self):
247 self._class_name = self._ImplClassName(self._interface.id) 247 self._class_name = self._ImplClassName(self._interface.id)
248 self._interface_type_info = GetIDLTypeInfoByName(self._interface.id) 248 self._interface_type_info = GetIDLTypeInfo(self._interface.id)
249 self._members_emitter = emitter.Emitter() 249 self._members_emitter = emitter.Emitter()
250 self._cpp_declarations_emitter = emitter.Emitter() 250 self._cpp_declarations_emitter = emitter.Emitter()
251 self._cpp_impl_includes = {} 251 self._cpp_impl_includes = {}
252 self._cpp_definitions_emitter = emitter.Emitter() 252 self._cpp_definitions_emitter = emitter.Emitter()
253 self._cpp_resolver_emitter = emitter.Emitter() 253 self._cpp_resolver_emitter = emitter.Emitter()
254 254
255 self._GenerateConstructors() 255 self._GenerateConstructors()
256 256
257 def _GenerateConstructors(self): 257 def _GenerateConstructors(self):
258 if not self._IsConstructable(): 258 if not self._IsConstructable():
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 else: 304 else:
305 raise Exception('Unsupported CallWith=%s attribute' % call_with) 305 raise Exception('Unsupported CallWith=%s attribute' % call_with)
306 306
307 # Process constructor arguments. 307 # Process constructor arguments.
308 for (i, arg) in enumerate(constructor_info.idl_args): 308 for (i, arg) in enumerate(constructor_info.idl_args):
309 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1) 309 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1)
310 arguments.append(arg.id) 310 arguments.append(arg.id)
311 311
312 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 312 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
313 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 313 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
314 self._interface, self._interface.ext_attrs, raises_dom_exceptions) 314 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
315 self._GenerateNativeCallback(callback_name='constructorCallback', 315 self._GenerateNativeCallback(callback_name='constructorCallback',
316 parameter_definitions=parameter_definitions_emitter.Fragments(), 316 parameter_definitions=parameter_definitions_emitter.Fragments(),
317 needs_receiver=False, invocation=invocation, 317 needs_receiver=False, invocation=invocation,
318 raises_exceptions=raises_dart_exceptions) 318 raises_exceptions=raises_dart_exceptions)
319 319
320 def _ImplClassName(self, interface_name): 320 def _ImplClassName(self, interface_name):
321 return interface_name + 'Implementation' 321 return interface_name + 'Implementation'
322 322
323 def _IsConstructable(self): 323 def _IsConstructable(self):
324 # FIXME: support ConstructorTemplate. 324 # FIXME: support ConstructorTemplate.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (self._interface.id in classes_with_unsupported_custom_getters and 397 if (self._interface.id in classes_with_unsupported_custom_getters and
398 getter and set(['Custom', 'CustomGetter']) & set(getter.ext_attrs)): 398 getter and set(['Custom', 'CustomGetter']) & set(getter.ext_attrs)):
399 return 399 return
400 400
401 if getter: 401 if getter:
402 self._AddGetter(getter) 402 self._AddGetter(getter)
403 if setter: 403 if setter:
404 self._AddSetter(setter) 404 self._AddSetter(setter)
405 405
406 def _AddGetter(self, attr): 406 def _AddGetter(self, attr):
407 type_info = GetIDLTypeInfo(attr.type) 407 type_info = GetIDLTypeInfo(attr.type.id)
408 dart_declaration = '%s get %s()' % (type_info.dart_type(), attr.id) 408 dart_declaration = '%s get %s()' % (type_info.dart_type(), attr.id)
409 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs 409 is_custom = 'Custom' in attr.ext_attrs or 'CustomGetter' in attr.ext_attrs
410 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1, 410 cpp_callback_name = self._GenerateNativeBinding(attr.id, 1,
411 dart_declaration, 'Getter', is_custom) 411 dart_declaration, 'Getter', is_custom)
412 if is_custom: 412 if is_custom:
413 return 413 return
414 414
415 arguments = [] 415 arguments = []
416 if 'Reflect' in attr.ext_attrs: 416 if 'Reflect' in attr.ext_attrs:
417 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_getter_name() 417 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_getter_name()
418 if 'URL' in attr.ext_attrs: 418 if 'URL' in attr.ext_attrs:
419 if 'NonEmpty' in attr.ext_attrs: 419 if 'NonEmpty' in attr.ext_attrs:
420 webcore_function_name = 'getNonEmptyURLAttribute' 420 webcore_function_name = 'getNonEmptyURLAttribute'
421 else: 421 else:
422 webcore_function_name = 'getURLAttribute' 422 webcore_function_name = 'getURLAttribute'
423 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 423 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
424 else: 424 else:
425 if attr.id == 'operator': 425 if attr.id == 'operator':
426 webcore_function_name = '_operator' 426 webcore_function_name = '_operator'
427 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 427 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
428 webcore_function_name = 'svgTarget' 428 webcore_function_name = 'svgTarget'
429 else: 429 else:
430 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)', 430 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)',
431 lambda s: s.group(1).lower(), 431 lambda s: s.group(1).lower(),
432 attr.id) 432 attr.id)
433 webcore_function_name = re.sub(r'^(create|exclusive)', 433 webcore_function_name = re.sub(r'^(create|exclusive)',
434 lambda s: 'is' + s.group(1).capitalize(), 434 lambda s: 'is' + s.group(1).capitalize(),
435 webcore_function_name) 435 webcore_function_name)
436 if attr.type.id.startswith('SVGAnimated'): 436 if attr.type.id.startswith('SVGAnimated'):
437 webcore_function_name += 'Animated' 437 webcore_function_name += 'Animated'
438 438
439 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 439 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
440 invocation = self._GenerateWebCoreInvocation(function_expression, 440 invocation = self._GenerateWebCoreInvocation(function_expression,
441 arguments, attr.type, attr.ext_attrs, attr.get_raises) 441 arguments, attr.type.id, attr.ext_attrs, attr.get_raises)
442 self._GenerateNativeCallback(cpp_callback_name, '', True, invocation, 442 self._GenerateNativeCallback(cpp_callback_name, '', True, invocation,
443 raises_exceptions=attr.get_raises) 443 raises_exceptions=attr.get_raises)
444 444
445 def _AddSetter(self, attr): 445 def _AddSetter(self, attr):
446 type_info = GetIDLTypeInfo(attr.type) 446 type_info = GetIDLTypeInfo(attr.type.id)
447 dart_declaration = 'void set %s(%s)' % (attr.id, type_info.dart_type()) 447 dart_declaration = 'void set %s(%s)' % (attr.id, type_info.dart_type())
448 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs) 448 is_custom = set(['Custom', 'CustomSetter', 'V8CustomSetter']) & set(attr.ext _attrs)
449 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2, 449 cpp_callback_name = self._GenerateNativeBinding(attr.id, 2,
450 dart_declaration, 'Setter', is_custom) 450 dart_declaration, 'Setter', is_custom)
451 if is_custom: 451 if is_custom:
452 return 452 return
453 453
454 arguments = [] 454 arguments = []
455 if 'Reflect' in attr.ext_attrs: 455 if 'Reflect' in attr.ext_attrs:
456 webcore_function_name = GetIDLTypeInfo(attr.type).webcore_setter_name() 456 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_setter_name()
457 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 457 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
458 else: 458 else:
459 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 459 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)',
460 lambda s: s.group(1).upper(), 460 lambda s: s.group(1).upper(),
461 attr.id) 461 attr.id)
462 webcore_function_name = 'set%s' % webcore_function_name 462 webcore_function_name = 'set%s' % webcore_function_name
463 if attr.type.id.startswith('SVGAnimated'): 463 if attr.type.id.startswith('SVGAnimated'):
464 webcore_function_name += 'Animated' 464 webcore_function_name += 'Animated'
465 465
466 arguments.append(attr.id) 466 arguments.append(attr.id)
467 467
468 parameter_definitions_emitter = emitter.Emitter() 468 parameter_definitions_emitter = emitter.Emitter()
469 self._GenerateParameterAdapter(parameter_definitions_emitter, attr, 0) 469 self._GenerateParameterAdapter(parameter_definitions_emitter, attr, 0)
470 parameter_definitions = parameter_definitions_emitter.Fragments() 470 parameter_definitions = parameter_definitions_emitter.Fragments()
471 471
472 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 472 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
473 invocation = self._GenerateWebCoreInvocation(function_expression, 473 invocation = self._GenerateWebCoreInvocation(function_expression,
474 arguments, None, attr.ext_attrs, attr.set_raises) 474 arguments, 'void', attr.ext_attrs, attr.set_raises)
475 475
476 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions, 476 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions,
477 True, invocation, raises_exceptions=True) 477 True, invocation, raises_exceptions=True)
478 478
479 def _HasNativeIndexGetter(self, interface): 479 def _HasNativeIndexGetter(self, interface):
480 return ('CustomIndexedGetter' in interface.ext_attrs or 480 return ('CustomIndexedGetter' in interface.ext_attrs or
481 'NumericIndexedGetter' in interface.ext_attrs) 481 'NumericIndexedGetter' in interface.ext_attrs)
482 482
483 def _EmitNativeIndexGetter(self, interface, element_type): 483 def _EmitNativeIndexGetter(self, interface, element_type):
484 dart_declaration = '%s operator[](int index)' % element_type 484 dart_declaration = '%s operator[](int index)' % element_type
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart 619 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart
620 # idl, but is not optional in webcore implementation. 620 # idl, but is not optional in webcore implementation.
621 if len(operation.arguments) == 2: 621 if len(operation.arguments) == 2:
622 arguments.append('String()') 622 arguments.append('String()')
623 623
624 if 'NeedsUserGestureCheck' in operation.ext_attrs: 624 if 'NeedsUserGestureCheck' in operation.ext_attrs:
625 arguments.append('DartUtilities::processingUserGesture') 625 arguments.append('DartUtilities::processingUserGesture')
626 626
627 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation) 627 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, operation)
628 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 628 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
629 operation.type, operation.ext_attrs, operation.raises) 629 operation.type.id, operation.ext_attrs, operation.raises)
630 self._GenerateNativeCallback(cpp_callback_name, 630 self._GenerateNativeCallback(cpp_callback_name,
631 parameter_definitions=parameter_definitions_emitter.Fragments(), 631 parameter_definitions=parameter_definitions_emitter.Fragments(),
632 needs_receiver=True, invocation=invocation, 632 needs_receiver=True, invocation=invocation,
633 raises_exceptions=raises_dart_exceptions) 633 raises_exceptions=raises_dart_exceptions)
634 634
635 def _GenerateNativeCallback(self, callback_name, parameter_definitions, 635 def _GenerateNativeCallback(self, callback_name, parameter_definitions,
636 needs_receiver, invocation, raises_exceptions): 636 needs_receiver, invocation, raises_exceptions):
637 637
638 if needs_receiver: 638 if needs_receiver:
639 parameter_definitions = emitter.Format( 639 parameter_definitions = emitter.Format(
(...skipping 25 matching lines...) Expand all
665 '\n' 665 '\n'
666 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' 666 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n'
667 '{\n' 667 '{\n'
668 ' DartApiScope dartApiScope;\n' 668 ' DartApiScope dartApiScope;\n'
669 '$BODY' 669 '$BODY'
670 '}\n', 670 '}\n',
671 CALLBACK_NAME=callback_name, 671 CALLBACK_NAME=callback_name,
672 BODY=body) 672 BODY=body)
673 673
674 def _GenerateParameterAdapter(self, emitter, idl_argument, index): 674 def _GenerateParameterAdapter(self, emitter, idl_argument, index):
675 type_info = GetIDLTypeInfo(idl_argument.type) 675 type_info = GetIDLTypeInfo(idl_argument.type.id)
676 (adapter_type, include_name) = type_info.parameter_adapter_info() 676 (adapter_type, include_name) = type_info.parameter_adapter_info()
677 if include_name: 677 if include_name:
678 self._cpp_impl_includes[include_name] = 1 678 self._cpp_impl_includes[include_name] = 1
679 flags = '' 679 flags = ''
680 if (idl_argument.ext_attrs.get('Optional') == 'DefaultIsNullString' or 680 if (idl_argument.ext_attrs.get('Optional') == 'DefaultIsNullString' or
681 ('Optional' in idl_argument.ext_attrs and 'Callback' in idl_argument.ext _attrs)): 681 ('Optional' in idl_argument.ext_attrs and 'Callback' in idl_argument.ext _attrs)):
682 flags = ', DartUtilities::ConvertNullToDefaultValue' 682 flags = ', DartUtilities::ConvertNullToDefaultValue'
683 emitter.Emit( 683 emitter.Emit(
684 '\n' 684 '\n'
685 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' 685 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n'
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 730 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
731 731
732 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): 732 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node):
733 if 'ImplementedBy' in idl_node.ext_attrs: 733 if 'ImplementedBy' in idl_node.ext_attrs:
734 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) 734 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name)
735 return '%s%s' % (self._interface_type_info.receiver(), function_name) 735 return '%s%s' % (self._interface_type_info.receiver(), function_name)
736 736
737 def _GenerateWebCoreInvocation(self, function_expression, arguments, 737 def _GenerateWebCoreInvocation(self, function_expression, arguments,
738 idl_return_type, attributes, raises_dom_exceptions): 738 idl_return_type, attributes, raises_dom_exceptions):
739 invocation_template = ' $FUNCTION_CALL;\n' 739 invocation_template = ' $FUNCTION_CALL;\n'
740 if idl_return_type and idl_return_type.id != 'void': 740 if idl_return_type != 'void':
741 return_type_info = GetIDLTypeInfo(idl_return_type) 741 return_type_info = GetIDLTypeInfo(idl_return_type)
742 if return_type_info.conversion_include(): 742 if return_type_info.conversion_include():
743 self._cpp_impl_includes[return_type_info.conversion_include()] = 1 743 self._cpp_impl_includes[return_type_info.conversion_include()] = 1
744 744
745 # Generate C++ cast based on idl return type. 745 # Generate C++ cast based on idl return type.
746 conversion_cast = return_type_info.conversion_cast('$FUNCTION_CALL') 746 conversion_cast = return_type_info.conversion_cast('$FUNCTION_CALL')
747 if isinstance(return_type_info, SVGTearOffIDLTypeInfo): 747 if isinstance(return_type_info, SVGTearOffIDLTypeInfo):
748 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix', 748 svg_primitive_types = ['SVGAngle', 'SVGLength', 'SVGMatrix',
749 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform'] 749 'SVGNumber', 'SVGPoint', 'SVGRect', 'SVGTransform']
750 conversion_cast = '%s::create($FUNCTION_CALL)' 750 conversion_cast = '%s::create($FUNCTION_CALL)'
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ' goto fail;\n' 783 ' goto fail;\n'
784 ' }\n', 784 ' }\n',
785 INVOCATION=invocation_template) 785 INVOCATION=invocation_template)
786 786
787 if 'ImplementedBy' in attributes: 787 if 'ImplementedBy' in attributes:
788 arguments.insert(0, 'receiver') 788 arguments.insert(0, 'receiver')
789 self._cpp_impl_includes[attributes['ImplementedBy']] = 1 789 self._cpp_impl_includes[attributes['ImplementedBy']] = 1
790 790
791 return emitter.Format(invocation_template, 791 return emitter.Format(invocation_template,
792 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) 792 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
OLDNEW
« no previous file with comments | « client/dom/scripts/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698