| OLD | NEW |
| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if mojom.IsDataPipeProducerKind(kind): | 161 if mojom.IsDataPipeProducerKind(kind): |
| 162 return "mojo::ScopedDataPipeProducerHandle" | 162 return "mojo::ScopedDataPipeProducerHandle" |
| 163 if mojom.IsMessagePipeKind(kind): | 163 if mojom.IsMessagePipeKind(kind): |
| 164 return "mojo::ScopedMessagePipeHandle" | 164 return "mojo::ScopedMessagePipeHandle" |
| 165 if mojom.IsSharedBufferKind(kind): | 165 if mojom.IsSharedBufferKind(kind): |
| 166 return "mojo::ScopedSharedBufferHandle" | 166 return "mojo::ScopedSharedBufferHandle" |
| 167 return _kind_to_cpp_type[kind] | 167 return _kind_to_cpp_type[kind] |
| 168 | 168 |
| 169 def GetCppResultWrapperType(kind): | 169 def GetCppResultWrapperType(kind): |
| 170 if IsTypemappedKind(kind): | 170 if IsTypemappedKind(kind): |
| 171 return "const %s&" % GetNativeTypeName(kind) | 171 if mojom.IsEnumKind(kind): |
| 172 return GetNativeTypeName(kind) |
| 173 else: |
| 174 assert mojom.IsStructKind(kind) |
| 175 return "const %s&" % GetNativeTypeName(kind) |
| 172 if mojom.IsEnumKind(kind): | 176 if mojom.IsEnumKind(kind): |
| 173 return GetNameForKind(kind) | 177 return GetNameForKind(kind) |
| 174 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 178 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 175 return "%sPtr" % GetNameForKind(kind) | 179 return "%sPtr" % GetNameForKind(kind) |
| 176 if mojom.IsArrayKind(kind): | 180 if mojom.IsArrayKind(kind): |
| 177 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 181 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 178 if mojom.IsMapKind(kind): | 182 if mojom.IsMapKind(kind): |
| 179 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 183 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 180 GetCppArrayArgWrapperType(kind.value_kind)) | 184 GetCppArrayArgWrapperType(kind.value_kind)) |
| 181 if mojom.IsInterfaceKind(kind): | 185 if mojom.IsInterfaceKind(kind): |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 if mojom.IsDataPipeProducerKind(kind): | 239 if mojom.IsDataPipeProducerKind(kind): |
| 236 return "mojo::ScopedDataPipeProducerHandle" | 240 return "mojo::ScopedDataPipeProducerHandle" |
| 237 if mojom.IsMessagePipeKind(kind): | 241 if mojom.IsMessagePipeKind(kind): |
| 238 return "mojo::ScopedMessagePipeHandle" | 242 return "mojo::ScopedMessagePipeHandle" |
| 239 if mojom.IsSharedBufferKind(kind): | 243 if mojom.IsSharedBufferKind(kind): |
| 240 return "mojo::ScopedSharedBufferHandle" | 244 return "mojo::ScopedSharedBufferHandle" |
| 241 return _kind_to_cpp_type[kind] | 245 return _kind_to_cpp_type[kind] |
| 242 | 246 |
| 243 def GetCppConstWrapperType(kind): | 247 def GetCppConstWrapperType(kind): |
| 244 if IsTypemappedKind(kind): | 248 if IsTypemappedKind(kind): |
| 245 return "const %s&" % GetNativeTypeName(kind) | 249 if mojom.IsEnumKind(kind): |
| 250 return GetNativeTypeName(kind) |
| 251 else: |
| 252 assert mojom.IsStructKind(kind) |
| 253 return "const %s&" % GetNativeTypeName(kind) |
| 246 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 254 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 247 return "%sPtr" % GetNameForKind(kind) | 255 return "%sPtr" % GetNameForKind(kind) |
| 248 if mojom.IsArrayKind(kind): | 256 if mojom.IsArrayKind(kind): |
| 249 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 257 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 250 if mojom.IsMapKind(kind): | 258 if mojom.IsMapKind(kind): |
| 251 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 259 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 252 GetCppArrayArgWrapperType(kind.value_kind)) | 260 GetCppArrayArgWrapperType(kind.value_kind)) |
| 253 if mojom.IsInterfaceKind(kind): | 261 if mojom.IsInterfaceKind(kind): |
| 254 return "%sPtr" % GetNameForKind(kind) | 262 return "%sPtr" % GetNameForKind(kind) |
| 255 if mojom.IsInterfaceRequestKind(kind): | 263 if mojom.IsInterfaceRequestKind(kind): |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 def GenerateFiles(self, args): | 517 def GenerateFiles(self, args): |
| 510 global _current_typemap | 518 global _current_typemap |
| 511 _current_typemap = self.typemap | 519 _current_typemap = self.typemap |
| 512 suffix = "-%s" % self.variant if self.variant else "" | 520 suffix = "-%s" % self.variant if self.variant else "" |
| 513 self.Write(self.GenerateModuleHeader(), | 521 self.Write(self.GenerateModuleHeader(), |
| 514 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 522 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 515 self.Write(self.GenerateModuleInternalHeader(), | 523 self.Write(self.GenerateModuleInternalHeader(), |
| 516 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 524 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
| 517 self.Write(self.GenerateModuleSource(), | 525 self.Write(self.GenerateModuleSource(), |
| 518 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 526 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |