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

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

Issue 10908284: Correct handling of return types for callbacks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 16 matching lines...) Expand all
27 self._interface = interface 27 self._interface = interface
28 28
29 if IsPureInterface(self._interface.id): 29 if IsPureInterface(self._interface.id):
30 return None 30 return None
31 31
32 cpp_impl_includes = set() 32 cpp_impl_includes = set()
33 cpp_header_handlers_emitter = emitter.Emitter() 33 cpp_header_handlers_emitter = emitter.Emitter()
34 cpp_impl_handlers_emitter = emitter.Emitter() 34 cpp_impl_handlers_emitter = emitter.Emitter()
35 class_name = 'Dart%s' % self._interface.id 35 class_name = 'Dart%s' % self._interface.id
36 for operation in interface.operations: 36 for operation in interface.operations:
37 if operation.type.id == 'void':
38 return_prefix = ''
39 error_return = ''
40 else:
41 return_prefix = 'return '
42 error_return = ' false'
43
44 parameters = [] 37 parameters = []
45 arguments = [] 38 arguments = []
46 conversion_includes = [] 39 conversion_includes = []
47 for argument in operation.arguments: 40 for argument in operation.arguments:
48 argument_type_info = self._type_registry.TypeInfo(argument.type.id) 41 argument_type_info = self._type_registry.TypeInfo(argument.type.id)
49 parameters.append('%s %s' % (argument_type_info.parameter_type(), 42 parameters.append('%s %s' % (argument_type_info.parameter_type(),
50 argument.id)) 43 argument.id))
51 arguments.append(argument_type_info.to_dart_conversion(argument.id)) 44 arguments.append(argument_type_info.to_dart_conversion(argument.id))
52 conversion_includes.extend(argument_type_info.conversion_includes()) 45 conversion_includes.extend(argument_type_info.conversion_includes())
53 46
54 native_return_type = self._type_registry.TypeInfo(operation.type.id).nativ e_type()
55 cpp_header_handlers_emitter.Emit( 47 cpp_header_handlers_emitter.Emit(
56 '\n' 48 '\n'
57 ' virtual $TYPE handleEvent($PARAMETERS);\n', 49 ' virtual bool handleEvent($PARAMETERS);\n',
58 TYPE=native_return_type, PARAMETERS=', '.join(parameters)) 50 PARAMETERS=', '.join(parameters))
59 51
60 if 'Custom' in operation.ext_attrs: 52 if 'Custom' in operation.ext_attrs:
61 continue 53 continue
62 54
63 cpp_impl_includes |= set(conversion_includes) 55 cpp_impl_includes |= set(conversion_includes)
64 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments) 56 arguments_declaration = 'Dart_Handle arguments[] = { %s }' % ', '.join(arg uments)
65 if not len(arguments): 57 if not len(arguments):
66 arguments_declaration = 'Dart_Handle* arguments = 0' 58 arguments_declaration = 'Dart_Handle* arguments = 0'
67 cpp_impl_handlers_emitter.Emit( 59 cpp_impl_handlers_emitter.Emit(
68 '\n' 60 '\n'
69 '$TYPE $CLASS_NAME::handleEvent($PARAMETERS)\n' 61 'bool $CLASS_NAME::handleEvent($PARAMETERS)\n'
70 '{\n' 62 '{\n'
71 ' if (!m_callback.isolate()->isAlive())\n' 63 ' if (!m_callback.isolate()->isAlive())\n'
72 ' return$ERROR_RETURN;\n' 64 ' return false;\n'
73 ' DartIsolate::Scope scope(m_callback.isolate());\n' 65 ' DartIsolate::Scope scope(m_callback.isolate());\n'
74 ' DartApiScope apiScope;\n' 66 ' DartApiScope apiScope;\n'
75 ' $ARGUMENTS_DECLARATION;\n' 67 ' $ARGUMENTS_DECLARATION;\n'
76 ' $(RETURN_PREFIX)m_callback.handleEvent($ARGUMENT_COUNT, arguments );\n' 68 ' return m_callback.handleEvent($ARGUMENT_COUNT, arguments);\n'
77 '}\n', 69 '}\n',
78 TYPE=native_return_type,
79 CLASS_NAME=class_name, 70 CLASS_NAME=class_name,
80 PARAMETERS=', '.join(parameters), 71 PARAMETERS=', '.join(parameters),
81 ERROR_RETURN=error_return,
82 RETURN_PREFIX=return_prefix,
83 ARGUMENTS_DECLARATION=arguments_declaration, 72 ARGUMENTS_DECLARATION=arguments_declaration,
84 ARGUMENT_COUNT=len(arguments)) 73 ARGUMENT_COUNT=len(arguments))
85 74
86 cpp_header_path = self._FilePathForCppHeader(self._interface.id) 75 cpp_header_path = self._FilePathForCppHeader(self._interface.id)
87 cpp_header_emitter = self._emitters.FileEmitter(cpp_header_path) 76 cpp_header_emitter = self._emitters.FileEmitter(cpp_header_path)
88 cpp_header_emitter.Emit( 77 cpp_header_emitter.Emit(
89 self._templates.Load('cpp_callback_header.template'), 78 self._templates.Load('cpp_callback_header.template'),
90 INTERFACE=self._interface.id, 79 INTERFACE=self._interface.id,
91 HANDLERS=cpp_header_handlers_emitter.Fragments()) 80 HANDLERS=cpp_header_handlers_emitter.Fragments())
92 81
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 parent_interface = _FindInHierarchy(database, parent_interface, test) 939 parent_interface = _FindInHierarchy(database, parent_interface, test)
951 if parent_interface: 940 if parent_interface:
952 return parent_interface 941 return parent_interface
953 942
954 def _ToWebKitName(name): 943 def _ToWebKitName(name):
955 name = name[0].lower() + name[1:] 944 name = name[0].lower() + name[1:]
956 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 945 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
957 name) 946 name)
958 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 947 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
959 name) 948 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