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

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

Issue 9692044: Parameter adapter name in setter should be 'value'. (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 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
11 import systemwrapping 11 import systemwrapping
12 from generator import * 12 from generator import *
13 from systembase import * 13 from systembase import *
14 14
15
16 _cpp_keywords = set(['default', 'operator'])
17
18 def CppSafeName(name):
19 """Returns version of name safe for use in cpp code, i.e. not a keyword."""
20 if name in _cpp_keywords:
21 return '_' + name
22 return name
23
24 class NativeImplementationSystem(System): 15 class NativeImplementationSystem(System):
25 16
26 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): 17 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir):
27 super(NativeImplementationSystem, self).__init__( 18 super(NativeImplementationSystem, self).__init__(
28 templates, database, emitters, output_dir) 19 templates, database, emitters, output_dir)
29 20
30 self._auxiliary_dir = auxiliary_dir 21 self._auxiliary_dir = auxiliary_dir
31 self._dom_public_files = [] 22 self._dom_public_files = []
32 self._dom_impl_files = [] 23 self._dom_impl_files = []
33 self._cpp_header_files = [] 24 self._cpp_header_files = []
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 ' if (!context) {\n' 273 ' if (!context) {\n'
283 ' exception = Dart_NewString("Failed to create an object" );\n' 274 ' exception = Dart_NewString("Failed to create an object" );\n'
284 ' goto fail;\n' 275 ' goto fail;\n'
285 ' }\n') 276 ' }\n')
286 arguments.append('context') 277 arguments.append('context')
287 else: 278 else:
288 raise Exception('Unsupported CallWith=%s attribute' % call_with) 279 raise Exception('Unsupported CallWith=%s attribute' % call_with)
289 280
290 # Process constructor arguments. 281 # Process constructor arguments.
291 for (i, arg) in enumerate(constructor_info.idl_args): 282 for (i, arg) in enumerate(constructor_info.idl_args):
292 cpp_arg_name = CppSafeName(arg.id) 283 self._GenerateParameterAdapter(parameter_definitions_emitter, arg, i - 1)
podivilov 2012/03/13 12:48:13 c++ keywords are never used as parameter names in
293 self._GenerateParameterAdapter( 284 arguments.append(arg.id)
294 parameter_definitions_emitter, arg, cpp_arg_name, i - 1)
295 arguments.append(cpp_arg_name)
296 285
297 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 286 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
298 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 287 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
299 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 288 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
300 self._GenerateNativeCallback(callback_name='constructorCallback', 289 self._GenerateNativeCallback(callback_name='constructorCallback',
301 parameter_definitions=parameter_definitions_emitter.Fragments(), 290 parameter_definitions=parameter_definitions_emitter.Fragments(),
302 needs_receiver=False, invocation=invocation, 291 needs_receiver=False, invocation=invocation,
303 raises_exceptions=raises_dart_exceptions) 292 raises_exceptions=raises_dart_exceptions)
304 293
305 def _ImplClassName(self, interface_name): 294 def _ImplClassName(self, interface_name):
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 arguments = [] 384 arguments = []
396 if 'Reflect' in attr.ext_attrs: 385 if 'Reflect' in attr.ext_attrs:
397 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_getter_name() 386 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_getter_name()
398 if 'URL' in attr.ext_attrs: 387 if 'URL' in attr.ext_attrs:
399 if 'NonEmpty' in attr.ext_attrs: 388 if 'NonEmpty' in attr.ext_attrs:
400 webcore_function_name = 'getNonEmptyURLAttribute' 389 webcore_function_name = 'getNonEmptyURLAttribute'
401 else: 390 else:
402 webcore_function_name = 'getURLAttribute' 391 webcore_function_name = 'getURLAttribute'
403 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 392 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
404 else: 393 else:
405 webcore_function_name = CppSafeName(attr.id) 394 if attr.id == 'operator':
podivilov 2012/03/13 12:48:13 operator -> _operator rename is rather just a spec
406 if attr.id == 'target' and attr.type.id == 'SVGAnimatedString': 395 webcore_function_name = '_operator'
396 elif attr.id == 'target' and attr.type.id == 'SVGAnimatedString':
407 webcore_function_name = 'svgTarget' 397 webcore_function_name = 'svgTarget'
408 else: 398 else:
409 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)', 399 webcore_function_name = re.sub(r'^(HTML|URL|JS|XML|XSLT|\w)',
410 lambda s: s.group(1).lower(), 400 lambda s: s.group(1).lower(),
411 webcore_function_name) 401 attr.id)
412 webcore_function_name = re.sub(r'^(create|exclusive)', 402 webcore_function_name = re.sub(r'^(create|exclusive)',
413 lambda s: 'is' + s.group(1).capitalize(), 403 lambda s: 'is' + s.group(1).capitalize(),
414 webcore_function_name) 404 webcore_function_name)
415 if attr.type.id.startswith('SVGAnimated'): 405 if attr.type.id.startswith('SVGAnimated'):
416 webcore_function_name += 'Animated' 406 webcore_function_name += 'Animated'
417 407
418 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 408 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
419 invocation = self._GenerateWebCoreInvocation(function_expression, 409 invocation = self._GenerateWebCoreInvocation(function_expression,
420 arguments, attr.type.id, attr.ext_attrs, attr.get_raises) 410 arguments, attr.type.id, attr.ext_attrs, attr.get_raises)
421 self._GenerateNativeCallback(cpp_callback_name, '', True, invocation, 411 self._GenerateNativeCallback(cpp_callback_name, '', True, invocation,
(...skipping 14 matching lines...) Expand all
436 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_setter_name() 426 webcore_function_name = GetIDLTypeInfo(attr.type.id).webcore_setter_name()
437 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr)) 427 arguments.append(self._GenerateWebCoreReflectionAttributeName(attr))
438 else: 428 else:
439 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)', 429 webcore_function_name = re.sub(r'^(xml(?=[A-Z])|\w)',
440 lambda s: s.group(1).upper(), 430 lambda s: s.group(1).upper(),
441 attr.id) 431 attr.id)
442 webcore_function_name = 'set%s' % webcore_function_name 432 webcore_function_name = 'set%s' % webcore_function_name
443 if attr.type.id.startswith('SVGAnimated'): 433 if attr.type.id.startswith('SVGAnimated'):
444 webcore_function_name += 'Animated' 434 webcore_function_name += 'Animated'
445 435
446 cpp_arg_name = CppSafeName(attr.id) 436 arguments.append('value')
447 arguments.append(cpp_arg_name)
448 437
449 parameter_definitions_emitter = emitter.Emitter() 438 parameter_definitions_emitter = emitter.Emitter()
450 self._GenerateParameterAdapter( 439 self._GenerateParameterAdapter(
451 parameter_definitions_emitter, attr, cpp_arg_name, 0) 440 parameter_definitions_emitter, attr, 0, adapter_name='value')
452 parameter_definitions = parameter_definitions_emitter.Fragments() 441 parameter_definitions = parameter_definitions_emitter.Fragments()
453 442
454 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr) 443 function_expression = self._GenerateWebCoreFunctionExpression(webcore_functi on_name, attr)
455 invocation = self._GenerateWebCoreInvocation(function_expression, 444 invocation = self._GenerateWebCoreInvocation(function_expression,
456 arguments, 'void', attr.ext_attrs, attr.set_raises) 445 arguments, 'void', attr.ext_attrs, attr.set_raises)
457 446
458 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions, 447 self._GenerateNativeCallback(cpp_callback_name, parameter_definitions,
459 True, invocation, raises_exceptions=True) 448 True, invocation, raises_exceptions=True)
460 449
461 def _HasNativeIndexGetter(self, interface): 450 def _HasNativeIndexGetter(self, interface):
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 arguments.extend(['scriptArguments', 'scriptCallStack']) 573 arguments.extend(['scriptArguments', 'scriptCallStack'])
585 574
586 # Process Dart arguments. 575 # Process Dart arguments.
587 for (i, argument) in enumerate(operation.arguments): 576 for (i, argument) in enumerate(operation.arguments):
588 if (i == len(operation.arguments) - 1 and 577 if (i == len(operation.arguments) - 1 and
589 self._interface.id == 'Console' and 578 self._interface.id == 'Console' and
590 argument.id == 'arg'): 579 argument.id == 'arg'):
591 # FIXME: we are skipping last argument here because it was added in 580 # FIXME: we are skipping last argument here because it was added in
592 # supplemental dart.idl. Cleanup dart.idl and remove this check. 581 # supplemental dart.idl. Cleanup dart.idl and remove this check.
593 break 582 break
594 cpp_arg_name = CppSafeName(argument.id) 583 self._GenerateParameterAdapter(parameter_definitions_emitter, argument, i)
podivilov 2012/03/13 12:48:13 ditto.
595 self._GenerateParameterAdapter( 584 arguments.append(argument.id)
596 parameter_definitions_emitter, argument, cpp_arg_name, i)
597 arguments.append(cpp_arg_name)
598 585
599 if operation.id in ['addEventListener', 'removeEventListener']: 586 if operation.id in ['addEventListener', 'removeEventListener']:
600 # addEventListener's and removeEventListener's last argument is marked 587 # addEventListener's and removeEventListener's last argument is marked
601 # as optional in idl, but is not optional in webcore implementation. 588 # as optional in idl, but is not optional in webcore implementation.
602 if len(operation.arguments) == 2: 589 if len(operation.arguments) == 2:
603 arguments.append('false') 590 arguments.append('false')
604 591
605 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty': 592 if self._interface.id == 'CSSStyleDeclaration' and operation.id == 'setPrope rty':
606 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart 593 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart
607 # idl, but is not optional in webcore implementation. 594 # idl, but is not optional in webcore implementation.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 self._cpp_definitions_emitter.Emit( 638 self._cpp_definitions_emitter.Emit(
652 '\n' 639 '\n'
653 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n' 640 'static void $CALLBACK_NAME(Dart_NativeArguments args)\n'
654 '{\n' 641 '{\n'
655 ' DartApiScope dartApiScope;\n' 642 ' DartApiScope dartApiScope;\n'
656 '$BODY' 643 '$BODY'
657 '}\n', 644 '}\n',
658 CALLBACK_NAME=callback_name, 645 CALLBACK_NAME=callback_name,
659 BODY=body) 646 BODY=body)
660 647
661 def _GenerateParameterAdapter(self, emitter, idl_node, name, index): 648 def _GenerateParameterAdapter(self, emitter, idl_node, index,
649 adapter_name=None):
662 """idl_node is IDLArgument or IDLAttribute.""" 650 """idl_node is IDLArgument or IDLAttribute."""
663 type_info = GetIDLTypeInfo(idl_node.type.id) 651 type_info = GetIDLTypeInfo(idl_node.type.id)
664 (adapter_type, include_name) = type_info.parameter_adapter_info() 652 (adapter_type, include_name) = type_info.parameter_adapter_info()
665 if include_name: 653 if include_name:
666 self._cpp_impl_includes.add(include_name) 654 self._cpp_impl_includes.add(include_name)
667 flags = '' 655 flags = ''
668 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or 656 if (idl_node.ext_attrs.get('Optional') == 'DefaultIsNullString' or
669 'RequiredCppParameter' in idl_node.ext_attrs): 657 'RequiredCppParameter' in idl_node.ext_attrs):
670 flags = ', DartUtilities::ConvertNullToDefaultValue' 658 flags = ', DartUtilities::ConvertNullToDefaultValue'
671 emitter.Emit( 659 emitter.Emit(
672 '\n' 660 '\n'
673 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n' 661 ' const $ADAPTER_TYPE $NAME(Dart_GetNativeArgument(args, $INDEX)$ FLAGS);\n'
674 ' if (!$NAME.conversionSuccessful()) {\n' 662 ' if (!$NAME.conversionSuccessful()) {\n'
675 ' exception = $NAME.exception();\n' 663 ' exception = $NAME.exception();\n'
676 ' goto fail;\n' 664 ' goto fail;\n'
677 ' }\n', 665 ' }\n',
678 ADAPTER_TYPE=adapter_type, 666 ADAPTER_TYPE=adapter_type,
679 NAME=name, 667 NAME=adapter_name or idl_node.id,
680 INDEX=index + 1, 668 INDEX=index + 1,
681 FLAGS=flags) 669 FLAGS=flags)
682 670
683 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration, 671 def _GenerateNativeBinding(self, idl_name, argument_count, dart_declaration,
684 native_suffix, is_custom): 672 native_suffix, is_custom):
685 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix) 673 native_binding = '%s_%s_%s' % (self._interface.id, idl_name, native_suffix)
686 self._members_emitter.Emit( 674 self._members_emitter.Emit(
687 '\n' 675 '\n'
688 ' $DART_DECLARATION native "$NATIVE_BINDING";\n', 676 ' $DART_DECLARATION native "$NATIVE_BINDING";\n',
689 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding) 677 DART_DECLARATION=dart_declaration, NATIVE_BINDING=native_binding)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 761
774 if 'ImplementedBy' in attributes: 762 if 'ImplementedBy' in attributes:
775 arguments.insert(0, 'receiver') 763 arguments.insert(0, 'receiver')
776 self._cpp_impl_includes.add(attributes['ImplementedBy']) 764 self._cpp_impl_includes.add(attributes['ImplementedBy'])
777 765
778 return emitter.Format(invocation_template, 766 return emitter.Format(invocation_template,
779 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) 767 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
780 768
781 def _GenerateCPPIncludes(includes): 769 def _GenerateCPPIncludes(includes):
782 return ''.join(['#include "%s.h"\n' % include for include in includes]) 770 return ''.join(['#include "%s.h"\n' % include for include in includes])
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