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

Side by Side Diff: mojo/public/tools/bindings/generators/mojom_cpp_generator.py

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generates C++ source files from a mojom.Module.""" 5 """Generates C++ source files from a mojom.Module."""
6 6
7 import mojom.generate.generator as generator 7 import mojom.generate.generator as generator
8 import mojom.generate.module as mojom 8 import mojom.generate.module as mojom
9 import mojom.generate.pack as pack 9 import mojom.generate.pack as pack
10 from mojom.generate.template_expander import UseJinja 10 from mojom.generate.template_expander import UseJinja
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 parts.append(kind.parent_kind.name) 43 parts.append(kind.parent_kind.name)
44 parts.append(kind.name) 44 parts.append(kind.name)
45 return "::".join(parts) 45 return "::".join(parts)
46 46
47 def GetCppType(kind): 47 def GetCppType(kind):
48 if isinstance(kind, mojom.Struct): 48 if isinstance(kind, mojom.Struct):
49 return "%s_Data*" % GetNameForKind(kind, internal=True) 49 return "%s_Data*" % GetNameForKind(kind, internal=True)
50 if isinstance(kind, mojom.Array): 50 if isinstance(kind, mojom.Array):
51 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) 51 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind)
52 if isinstance(kind, mojom.Interface): 52 if isinstance(kind, mojom.Interface):
53 return "%sHandle" % kind.name 53 return "mojo::MessagePipeHandle"
54 if isinstance(kind, mojom.Enum): 54 if isinstance(kind, mojom.Enum):
55 return "int32_t" 55 return "int32_t"
56 if kind.spec == 's': 56 if kind.spec == 's':
57 return "mojo::internal::String_Data*" 57 return "mojo::internal::String_Data*"
58 return _kind_to_cpp_type[kind] 58 return _kind_to_cpp_type[kind]
59 59
60 def GetCppArrayArgWrapperType(kind): 60 def GetCppArrayArgWrapperType(kind):
61 if isinstance(kind, (mojom.Struct, mojom.Enum)): 61 if isinstance(kind, (mojom.Struct, mojom.Enum)):
62 return GetNameForKind(kind) 62 return GetNameForKind(kind)
63 if isinstance(kind, mojom.Array): 63 if isinstance(kind, mojom.Array):
64 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind) 64 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
65 if isinstance(kind, mojom.Interface): 65 if isinstance(kind, mojom.Interface):
66 return "%sHandle" % kind.name 66 raise Exception("Arrays of interfaces not yet supported!")
67 if kind.spec == 's': 67 if kind.spec == 's':
68 return "mojo::String" 68 return "mojo::String"
69 return _kind_to_cpp_type[kind] 69 return _kind_to_cpp_type[kind]
70 70
71 def GetCppResultWrapperType(kind): 71 def GetCppResultWrapperType(kind):
72 if isinstance(kind, (mojom.Struct, mojom.Enum)): 72 if isinstance(kind, (mojom.Struct, mojom.Enum)):
73 return GetNameForKind(kind) 73 return GetNameForKind(kind)
74 if isinstance(kind, mojom.Array): 74 if isinstance(kind, mojom.Array):
75 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind) 75 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
76 if isinstance(kind, mojom.Interface): 76 if isinstance(kind, mojom.Interface):
77 return "Scoped%sHandle" % kind.name 77 return "%sPtr" % kind.name
78 if kind.spec == 's': 78 if kind.spec == 's':
79 return "mojo::String" 79 return "mojo::String"
80 if kind.spec == 'h': 80 if kind.spec == 'h':
81 return "mojo::ScopedHandle" 81 return "mojo::ScopedHandle"
82 if kind.spec == 'h:d:c': 82 if kind.spec == 'h:d:c':
83 return "mojo::ScopedDataPipeConsumerHandle" 83 return "mojo::ScopedDataPipeConsumerHandle"
84 if kind.spec == 'h:d:p': 84 if kind.spec == 'h:d:p':
85 return "mojo::ScopedDataPipeProducerHandle" 85 return "mojo::ScopedDataPipeProducerHandle"
86 if kind.spec == 'h:m': 86 if kind.spec == 'h:m':
87 return "mojo::ScopedMessagePipeHandle" 87 return "mojo::ScopedMessagePipeHandle"
88 if kind.spec == 'h:s': 88 if kind.spec == 'h:s':
89 return "mojo::ScopedSharedBufferHandle" 89 return "mojo::ScopedSharedBufferHandle"
90 return _kind_to_cpp_type[kind] 90 return _kind_to_cpp_type[kind]
91 91
92 def GetCppWrapperType(kind): 92 def GetCppWrapperType(kind):
93 if isinstance(kind, (mojom.Struct, mojom.Enum)): 93 if isinstance(kind, (mojom.Struct, mojom.Enum)):
94 return GetNameForKind(kind) 94 return GetNameForKind(kind)
95 if isinstance(kind, mojom.Array): 95 if isinstance(kind, mojom.Array):
96 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind) 96 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
97 if isinstance(kind, mojom.Interface): 97 if isinstance(kind, mojom.Interface):
98 return "mojo::Passable<%sHandle>" % kind.name 98 return "mojo::Passable<mojo::MessagePipeHandle>"
99 if kind.spec == 's': 99 if kind.spec == 's':
100 return "mojo::String" 100 return "mojo::String"
101 if generator.IsHandleKind(kind): 101 if generator.IsHandleKind(kind):
102 return "mojo::Passable<%s>" % _kind_to_cpp_type[kind] 102 return "mojo::Passable<%s>" % _kind_to_cpp_type[kind]
103 return _kind_to_cpp_type[kind] 103 return _kind_to_cpp_type[kind]
104 104
105 def GetCppConstWrapperType(kind): 105 def GetCppConstWrapperType(kind):
106 if isinstance(kind, mojom.Struct): 106 if isinstance(kind, mojom.Struct):
107 return "const %s&" % GetNameForKind(kind) 107 return "const %s&" % GetNameForKind(kind)
108 if isinstance(kind, mojom.Array): 108 if isinstance(kind, mojom.Array):
109 return "const mojo::Array<%s >&" % GetCppArrayArgWrapperType(kind.kind) 109 return "const mojo::Array<%s >&" % GetCppArrayArgWrapperType(kind.kind)
110 if isinstance(kind, mojom.Interface): 110 if isinstance(kind, mojom.Interface):
111 return "Scoped%sHandle" % kind.name 111 return "%sPtr" % kind.name
112 if isinstance(kind, mojom.Enum): 112 if isinstance(kind, mojom.Enum):
113 return GetNameForKind(kind) 113 return GetNameForKind(kind)
114 if kind.spec == 's': 114 if kind.spec == 's':
115 return "const mojo::String&" 115 return "const mojo::String&"
116 if kind.spec == 'h': 116 if kind.spec == 'h':
117 return "mojo::ScopedHandle" 117 return "mojo::ScopedHandle"
118 if kind.spec == 'h:d:c': 118 if kind.spec == 'h:d:c':
119 return "mojo::ScopedDataPipeConsumerHandle" 119 return "mojo::ScopedDataPipeConsumerHandle"
120 if kind.spec == 'h:d:p': 120 if kind.spec == 'h:d:p':
121 return "mojo::ScopedDataPipeProducerHandle" 121 return "mojo::ScopedDataPipeProducerHandle"
122 if kind.spec == 'h:m': 122 if kind.spec == 'h:m':
123 return "mojo::ScopedMessagePipeHandle" 123 return "mojo::ScopedMessagePipeHandle"
124 if kind.spec == 'h:s': 124 if kind.spec == 'h:s':
125 return "mojo::ScopedSharedBufferHandle" 125 return "mojo::ScopedSharedBufferHandle"
126 if not kind in _kind_to_cpp_type: 126 if not kind in _kind_to_cpp_type:
127 print "missing:", kind.spec 127 print "missing:", kind.spec
128 return _kind_to_cpp_type[kind] 128 return _kind_to_cpp_type[kind]
129 129
130 def GetCppFieldType(kind): 130 def GetCppFieldType(kind):
131 if isinstance(kind, mojom.Struct): 131 if isinstance(kind, mojom.Struct):
132 return ("mojo::internal::StructPointer<%s_Data>" % 132 return ("mojo::internal::StructPointer<%s_Data>" %
133 GetNameForKind(kind, internal=True)) 133 GetNameForKind(kind, internal=True))
134 if isinstance(kind, mojom.Array): 134 if isinstance(kind, mojom.Array):
135 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) 135 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind)
136 if isinstance(kind, mojom.Interface): 136 if isinstance(kind, mojom.Interface):
137 return "%sHandle" % kind.name 137 return "mojo::MessagePipeHandle"
138 if isinstance(kind, mojom.Enum): 138 if isinstance(kind, mojom.Enum):
139 return GetNameForKind(kind) 139 return GetNameForKind(kind)
140 if kind.spec == 's': 140 if kind.spec == 's':
141 return "mojo::internal::StringPointer" 141 return "mojo::internal::StringPointer"
142 return _kind_to_cpp_type[kind] 142 return _kind_to_cpp_type[kind]
143 143
144 def IsStructWithHandles(struct): 144 def IsStructWithHandles(struct):
145 for pf in struct.packed.packed_fields: 145 for pf in struct.packed.packed_fields:
146 if generator.IsHandleKind(pf.field.kind): 146 if generator.IsHandleKind(pf.field.kind):
147 return True 147 return True
(...skipping 25 matching lines...) Expand all
173 cpp_filters = { 173 cpp_filters = {
174 "cpp_const_wrapper_type": GetCppConstWrapperType, 174 "cpp_const_wrapper_type": GetCppConstWrapperType,
175 "cpp_field_type": GetCppFieldType, 175 "cpp_field_type": GetCppFieldType,
176 "cpp_type": GetCppType, 176 "cpp_type": GetCppType,
177 "cpp_result_type": GetCppResultWrapperType, 177 "cpp_result_type": GetCppResultWrapperType,
178 "cpp_wrapper_type": GetCppWrapperType, 178 "cpp_wrapper_type": GetCppWrapperType,
179 "expression_to_text": ExpressionToText, 179 "expression_to_text": ExpressionToText,
180 "get_pad": pack.GetPad, 180 "get_pad": pack.GetPad,
181 "is_enum_kind": generator.IsEnumKind, 181 "is_enum_kind": generator.IsEnumKind,
182 "is_handle_kind": generator.IsHandleKind, 182 "is_handle_kind": generator.IsHandleKind,
183 "is_interface_kind": generator.IsInterfaceKind,
183 "is_object_kind": generator.IsObjectKind, 184 "is_object_kind": generator.IsObjectKind,
184 "is_string_kind": generator.IsStringKind, 185 "is_string_kind": generator.IsStringKind,
185 "is_array_kind": lambda kind: isinstance(kind, mojom.Array), 186 "is_array_kind": lambda kind: isinstance(kind, mojom.Array),
186 "is_struct_with_handles": IsStructWithHandles, 187 "is_struct_with_handles": IsStructWithHandles,
187 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE, 188 "struct_size": lambda ps: ps.GetTotalSize() + _HEADER_SIZE,
188 "struct_from_method": generator.GetStructFromMethod, 189 "struct_from_method": generator.GetStructFromMethod,
189 "response_struct_from_method": generator.GetResponseStructFromMethod, 190 "response_struct_from_method": generator.GetResponseStructFromMethod,
190 "stylize_method": generator.StudlyCapsToCamel, 191 "stylize_method": generator.StudlyCapsToCamel,
191 "verify_token_type": generator.VerifyTokenType, 192 "verify_token_type": generator.VerifyTokenType,
192 } 193 }
(...skipping 20 matching lines...) Expand all
213 214
214 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) 215 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters)
215 def GenerateModuleSource(self): 216 def GenerateModuleSource(self):
216 return self.GetJinjaExports() 217 return self.GetJinjaExports()
217 218
218 def GenerateFiles(self): 219 def GenerateFiles(self):
219 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) 220 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name)
220 self.Write(self.GenerateModuleInternalHeader(), 221 self.Write(self.GenerateModuleInternalHeader(),
221 "%s-internal.h" % self.module.name) 222 "%s-internal.h" % self.module.name)
222 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) 223 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698