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

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

Issue 221663004: mojo: add handle<shared_buffer> support to generator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | mojo/public/bindings/generators/mojom_js_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 from generate import mojom 7 from generate import mojom
8 from generate import mojom_pack 8 from generate import mojom_pack
9 from generate import mojom_generator 9 from generate import mojom_generator
10 10
11 from generate.template_expander import UseJinja 11 from generate.template_expander import UseJinja
12 12
13 13
14 _kind_to_cpp_type = { 14 _kind_to_cpp_type = {
15 mojom.BOOL: "bool", 15 mojom.BOOL: "bool",
16 mojom.INT8: "int8_t", 16 mojom.INT8: "int8_t",
17 mojom.UINT8: "uint8_t", 17 mojom.UINT8: "uint8_t",
18 mojom.INT16: "int16_t", 18 mojom.INT16: "int16_t",
19 mojom.UINT16: "uint16_t", 19 mojom.UINT16: "uint16_t",
20 mojom.INT32: "int32_t", 20 mojom.INT32: "int32_t",
21 mojom.UINT32: "uint32_t", 21 mojom.UINT32: "uint32_t",
22 mojom.FLOAT: "float", 22 mojom.FLOAT: "float",
23 mojom.HANDLE: "mojo::Handle", 23 mojom.HANDLE: "mojo::Handle",
24 mojom.DCPIPE: "mojo::DataPipeConsumerHandle", 24 mojom.DCPIPE: "mojo::DataPipeConsumerHandle",
25 mojom.DPPIPE: "mojo::DataPipeProducerHandle", 25 mojom.DPPIPE: "mojo::DataPipeProducerHandle",
26 mojom.MSGPIPE: "mojo::MessagePipeHandle", 26 mojom.MSGPIPE: "mojo::MessagePipeHandle",
27 mojom.INT64: "int64_t", 27 mojom.SHAREDBUFFER: "mojo::SharedBufferHandle",
28 mojom.UINT64: "uint64_t", 28 mojom.INT64: "int64_t",
29 mojom.DOUBLE: "double", 29 mojom.UINT64: "uint64_t",
30 mojom.DOUBLE: "double",
30 } 31 }
31 32
32 33
33 def GetNameForKind(kind, internal = False): 34 def GetNameForKind(kind, internal = False):
34 parts = [] 35 parts = []
35 if kind.imported_from: 36 if kind.imported_from:
36 parts.append(kind.imported_from["namespace"]) 37 parts.append(kind.imported_from["namespace"])
37 if internal: 38 if internal:
38 parts.append("internal") 39 parts.append("internal")
39 if kind.parent_kind: 40 if kind.parent_kind:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if kind.spec == 's': 76 if kind.spec == 's':
76 return "mojo::String" 77 return "mojo::String"
77 if kind.spec == 'h': 78 if kind.spec == 'h':
78 return "mojo::ScopedHandle" 79 return "mojo::ScopedHandle"
79 if kind.spec == 'h:d:c': 80 if kind.spec == 'h:d:c':
80 return "mojo::ScopedDataPipeConsumerHandle" 81 return "mojo::ScopedDataPipeConsumerHandle"
81 if kind.spec == 'h:d:p': 82 if kind.spec == 'h:d:p':
82 return "mojo::ScopedDataPipeProducerHandle" 83 return "mojo::ScopedDataPipeProducerHandle"
83 if kind.spec == 'h:m': 84 if kind.spec == 'h:m':
84 return "mojo::ScopedMessagePipeHandle" 85 return "mojo::ScopedMessagePipeHandle"
86 if kind.spec == 'h:s':
87 return "mojo::ScopedSharedBufferHandle"
85 return _kind_to_cpp_type[kind] 88 return _kind_to_cpp_type[kind]
86 89
87 def GetCppWrapperType(kind): 90 def GetCppWrapperType(kind):
88 if isinstance(kind, (mojom.Struct, mojom.Enum)): 91 if isinstance(kind, (mojom.Struct, mojom.Enum)):
89 return GetNameForKind(kind) 92 return GetNameForKind(kind)
90 if isinstance(kind, mojom.Array): 93 if isinstance(kind, mojom.Array):
91 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind) 94 return "mojo::Array<%s >" % GetCppArrayArgWrapperType(kind.kind)
92 if isinstance(kind, mojom.Interface): 95 if isinstance(kind, mojom.Interface):
93 return "mojo::Passable<%sHandle>" % kind.name 96 return "mojo::Passable<%sHandle>" % kind.name
94 if kind.spec == 's': 97 if kind.spec == 's':
(...skipping 14 matching lines...) Expand all
109 if kind.spec == 's': 112 if kind.spec == 's':
110 return "const mojo::String&" 113 return "const mojo::String&"
111 if kind.spec == 'h': 114 if kind.spec == 'h':
112 return "mojo::ScopedHandle" 115 return "mojo::ScopedHandle"
113 if kind.spec == 'h:d:c': 116 if kind.spec == 'h:d:c':
114 return "mojo::ScopedDataPipeConsumerHandle" 117 return "mojo::ScopedDataPipeConsumerHandle"
115 if kind.spec == 'h:d:p': 118 if kind.spec == 'h:d:p':
116 return "mojo::ScopedDataPipeProducerHandle" 119 return "mojo::ScopedDataPipeProducerHandle"
117 if kind.spec == 'h:m': 120 if kind.spec == 'h:m':
118 return "mojo::ScopedMessagePipeHandle" 121 return "mojo::ScopedMessagePipeHandle"
122 if kind.spec == 'h:s':
123 return "mojo::ScopedSharedBufferHandle"
119 if not kind in _kind_to_cpp_type: 124 if not kind in _kind_to_cpp_type:
120 print "missing:", kind.spec 125 print "missing:", kind.spec
121 return _kind_to_cpp_type[kind] 126 return _kind_to_cpp_type[kind]
122 127
123 def GetCppFieldType(kind): 128 def GetCppFieldType(kind):
124 if isinstance(kind, mojom.Struct): 129 if isinstance(kind, mojom.Struct):
125 return ("mojo::internal::StructPointer<%s_Data>" % 130 return ("mojo::internal::StructPointer<%s_Data>" %
126 GetNameForKind(kind, internal=True)) 131 GetNameForKind(kind, internal=True))
127 if isinstance(kind, mojom.Array): 132 if isinstance(kind, mojom.Array):
128 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) 133 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 210
206 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters) 211 @UseJinja("cpp_templates/module.cc.tmpl", filters=cpp_filters)
207 def GenerateModuleSource(self): 212 def GenerateModuleSource(self):
208 return self.GetJinjaExports() 213 return self.GetJinjaExports()
209 214
210 def GenerateFiles(self): 215 def GenerateFiles(self):
211 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name) 216 self.Write(self.GenerateModuleHeader(), "%s.h" % self.module.name)
212 self.Write(self.GenerateModuleInternalHeader(), 217 self.Write(self.GenerateModuleInternalHeader(),
213 "%s-internal.h" % self.module.name) 218 "%s-internal.h" % self.module.name)
214 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name) 219 self.Write(self.GenerateModuleSource(), "%s.cc" % self.module.name)
OLDNEW
« no previous file with comments | « no previous file | mojo/public/bindings/generators/mojom_js_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698