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

Side by Side Diff: sky/engine/bindings2/scripts/dart_callback_interface.py

Issue 915293003: Rename sky/engine/bindings2 to sky/engine/bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: more better Created 5 years, 10 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
OLDNEW
(Empty)
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 """Generate template values for a callback interface.
30
31 Extends IdlType with property |callback_cpp_type|.
32
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """
35
36 from idl_types import IdlType, IdlTypeBase
37 import dart_types
38 from dart_utilities import DartUtilities
39 from v8_globals import includes
40
41 CALLBACK_INTERFACE_H_INCLUDES = frozenset([
42 'bindings2/dart_callback.h',
43 ])
44
45 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
46 'wtf/GetPtr.h',
47 'wtf/RefPtr.h',
48 ])
49
50 def cpp_type(idl_type):
51 # FIXME: remove this function by making callback types consistent
52 # (always use usual v8_types.cpp_type)
53 idl_type_name = idl_type.name
54 if idl_type_name == 'String':
55 return 'const String&'
56 if idl_type_name == 'void':
57 return 'void'
58 # Callbacks use raw pointers, so raw_type=True
59 usual_cpp_type = idl_type.cpp_type_args(raw_type=True)
60 if usual_cpp_type.startswith(('Vector', 'HeapVector', 'WillBeHeapVector')):
61 return 'const %s&' % usual_cpp_type
62 return usual_cpp_type
63
64 IdlTypeBase.callback_cpp_type = property(cpp_type)
65
66
67 def generate_callback_interface(callback_interface):
68 includes.clear()
69 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
70 name = callback_interface.name
71
72 methods = [generate_method(operation)
73 for operation in callback_interface.operations]
74 template_contents = {
75 'cpp_class': name,
76 'dart_class': dart_types.dart_type(callback_interface.name),
77 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
78 'methods': methods,
79 }
80 return template_contents
81
82
83 def add_includes_for_operation(operation):
84 operation.idl_type.add_includes_for_type()
85 for argument in operation.arguments:
86 argument.idl_type.add_includes_for_type()
87
88
89 def generate_method(operation):
90 extended_attributes = operation.extended_attributes
91 idl_type = operation.idl_type
92 idl_type_str = str(idl_type)
93 if idl_type_str not in ['boolean', 'void']:
94 raise Exception('We only support callbacks that return boolean or void v alues.')
95 is_custom = 'Custom' in extended_attributes
96 if not is_custom:
97 add_includes_for_operation(operation)
98 call_with = extended_attributes.get('CallWith')
99 call_with_this_handle = DartUtilities.extended_attribute_value_contains(call _with, 'ThisValue')
100 contents = {
101 'call_with_this_handle': call_with_this_handle,
102 'cpp_type': idl_type.callback_cpp_type,
103 'custom': is_custom,
104 'idl_type': idl_type_str,
105 'name': operation.name,
106 }
107 contents.update(generate_arguments_contents(operation.arguments, call_with_t his_handle))
108 return contents
109
110
111 def generate_arguments_contents(arguments, call_with_this_handle):
112 def generate_argument(argument):
113 creation_context = ''
114 if argument.idl_type.native_array_element_type is not None:
115 creation_context = '<Dart%s>' % argument.idl_type.native_array_eleme nt_type
116 return {
117 'handle': '%sHandle' % argument.name,
118 'cpp_value_to_dart_value': argument.idl_type.cpp_value_to_dart_value (argument.name,
119 creation_context=creation_context),
120 }
121
122 argument_declarations = [
123 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
124 for argument in arguments]
125 if call_with_this_handle:
126 argument_declarations.insert(0, 'ScriptValue thisValue')
127 return {
128 'argument_declarations': argument_declarations,
129 'arguments': [generate_argument(argument) for argument in arguments],
130 }
OLDNEW
« no previous file with comments | « sky/engine/bindings2/scripts/dart_attributes.py ('k') | sky/engine/bindings2/scripts/dart_compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698