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

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

Issue 10822009: Refactor invocation emission. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 797
798 if self._interface.id == 'CSSStyleDeclaration' and node.id == 'setProperty': 798 if self._interface.id == 'CSSStyleDeclaration' and node.id == 'setProperty':
799 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart 799 # CSSStyleDeclaration.setProperty priority parameter is optional in Dart
800 # idl, but is not optional in webcore implementation. 800 # idl, but is not optional in webcore implementation.
801 if len(arguments) == 2: 801 if len(arguments) == 2:
802 cpp_arguments.append('String()') 802 cpp_arguments.append('String()')
803 803
804 if 'NeedsUserGestureCheck' in ext_attrs: 804 if 'NeedsUserGestureCheck' in ext_attrs:
805 cpp_arguments.append('DartUtilities::processingUserGesture'); 805 cpp_arguments.append('DartUtilities::processingUserGesture');
806 806
807 invocation = self._GenerateWebCoreInvocation( 807 invocation_emitter = head_emitter
808 function_expression, cpp_arguments, return_type, ext_attrs, raises_dom_e xception) 808 if raises_dom_exception:
809 cpp_arguments.append('ec')
810 invocation_emitter = head_emitter.Emit(
811 ' ExceptionCode ec = 0;\n'
812 '$!INVOCATION'
813 ' if (UNLIKELY(ec)) {\n'
814 ' exception = DartDOMWrapper::exceptionCodeToDartException(ec );\n'
815 ' goto fail;\n'
816 ' }\n')
817
818 function_call = '%s(%s)' % (function_expression, ', '.join(cpp_arguments))
819 if return_type == 'void':
820 invocation_emitter.Emit(
821 ' $FUNCTION_CALL;\n',
822 FUNCTION_CALL=function_call)
823 else:
824 return_type_info = self._TypeInfo(return_type)
825 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
826
827 # Generate to Dart conversion of C++ value.
828 to_dart_conversion = return_type_info.to_dart_conversion(function_call, se lf._interface.id, ext_attrs)
829 invocation_emitter.Emit(
830 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n'
831 ' if (returnValue)\n'
832 ' Dart_SetReturnValue(args, returnValue);\n',
833 TO_DART_CONVERSION=to_dart_conversion)
809 834
810 body = emitter.Format( 835 body = emitter.Format(
811 ' {\n' 836 ' {\n'
812 '$HEAD' 837 '$HEAD'
813 '$INVOCATION'
814 ' return;\n' 838 ' return;\n'
815 ' }\n', 839 ' }\n',
816 HEAD=head_emitter.Fragments(), 840 HEAD=head_emitter.Fragments())
817 INVOCATION=invocation)
818 841
819 if raises_exceptions: 842 if raises_exceptions:
820 body = emitter.Format( 843 body = emitter.Format(
821 ' Dart_Handle exception = 0;\n' 844 ' Dart_Handle exception = 0;\n'
822 '$BODY' 845 '$BODY'
823 '\n' 846 '\n'
824 'fail:\n' 847 'fail:\n'
825 ' Dart_ThrowException(exception);\n' 848 ' Dart_ThrowException(exception);\n'
826 ' ASSERT_NOT_REACHED();\n', 849 ' ASSERT_NOT_REACHED();\n',
827 BODY=body) 850 BODY=body)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower() 909 attribute_name = attr.ext_attrs['Reflect'] or attr.id.lower()
887 return 'WebCore::%s::%sAttr' % (namespace, attribute_name) 910 return 'WebCore::%s::%sAttr' % (namespace, attribute_name)
888 911
889 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node): 912 def _GenerateWebCoreFunctionExpression(self, function_name, idl_node):
890 if 'ImplementedBy' in idl_node.ext_attrs: 913 if 'ImplementedBy' in idl_node.ext_attrs:
891 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name) 914 return '%s::%s' % (idl_node.ext_attrs['ImplementedBy'], function_name)
892 if idl_node.is_static: 915 if idl_node.is_static:
893 return '%s::%s' % (self._interface_type_info.idl_type(), function_name) 916 return '%s::%s' % (self._interface_type_info.idl_type(), function_name)
894 return '%s%s' % (self._interface_type_info.receiver(), function_name) 917 return '%s%s' % (self._interface_type_info.receiver(), function_name)
895 918
896 def _GenerateWebCoreInvocation(self, function_expression, arguments,
897 idl_return_type, attributes, raises_dom_exceptions):
898 invocation_template = ' $FUNCTION_CALL;\n'
899 if idl_return_type != 'void':
900 return_type_info = self._TypeInfo(idl_return_type)
901 self._cpp_impl_includes |= set(return_type_info.conversion_includes())
902
903 # Generate to Dart conversion of C++ value.
904 to_dart_conversion = return_type_info.to_dart_conversion('$FUNCTION_CALL', self._interface.id, attributes)
905 invocation_template = emitter.Format(
906 ' Dart_Handle returnValue = $TO_DART_CONVERSION;\n'
907 ' if (returnValue)\n'
908 ' Dart_SetReturnValue(args, returnValue);\n',
909 TO_DART_CONVERSION=to_dart_conversion)
910
911 if raises_dom_exceptions:
912 # Add 'ec' argument to WebCore invocation and convert DOM exception to Dar t exception.
913 arguments.append('ec')
914 invocation_template = emitter.Format(
915 ' ExceptionCode ec = 0;\n'
916 '$INVOCATION'
917 ' if (UNLIKELY(ec)) {\n'
918 ' exception = DartDOMWrapper::exceptionCodeToDartException( ec);\n'
919 ' goto fail;\n'
920 ' }\n',
921 INVOCATION=invocation_template)
922
923 return emitter.Format(invocation_template,
924 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
925
926 def _TypeInfo(self, type_name): 919 def _TypeInfo(self, type_name):
927 return self._system._type_registry.TypeInfo(type_name) 920 return self._system._type_registry.TypeInfo(type_name)
928 921
929 922
930 def _GenerateCPPIncludes(includes): 923 def _GenerateCPPIncludes(includes):
931 return ''.join(['#include %s\n' % include for include in sorted(includes)]) 924 return ''.join(['#include %s\n' % include for include in sorted(includes)])
932 925
933 def _FindInHierarchy(database, interface, test): 926 def _FindInHierarchy(database, interface, test):
934 if test(interface): 927 if test(interface):
935 return interface 928 return interface
936 for parent in interface.parents: 929 for parent in interface.parents:
937 parent_name = parent.type.id 930 parent_name = parent.type.id
938 if not database.HasInterface(parent.type.id): 931 if not database.HasInterface(parent.type.id):
939 continue 932 continue
940 parent_interface = database.GetInterface(parent.type.id) 933 parent_interface = database.GetInterface(parent.type.id)
941 parent_interface = _FindInHierarchy(database, parent_interface, test) 934 parent_interface = _FindInHierarchy(database, parent_interface, test)
942 if parent_interface: 935 if parent_interface:
943 return parent_interface 936 return parent_interface
944 937
945 def _IsArgumentOptionalInWebCore(argument): 938 def _IsArgumentOptionalInWebCore(argument):
946 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 939 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
947 940
948 def _ToWebKitName(name): 941 def _ToWebKitName(name):
949 name = name[0].lower() + name[1:] 942 name = name[0].lower() + name[1:]
950 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 943 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
951 name) 944 name)
952 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 945 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
953 name) 946 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