| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 return "::".join(parts) | 68 return "::".join(parts) |
| 69 | 69 |
| 70 def GetCppType(kind): | 70 def GetCppType(kind): |
| 71 if mojom.IsArrayKind(kind): | 71 if mojom.IsArrayKind(kind): |
| 72 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) | 72 return "mojo::internal::Array_Data<%s>*" % GetCppType(kind.kind) |
| 73 if mojom.IsMapKind(kind): | 73 if mojom.IsMapKind(kind): |
| 74 return "mojo::internal::Map_Data<%s, %s>*" % ( | 74 return "mojo::internal::Map_Data<%s, %s>*" % ( |
| 75 GetCppType(kind.key_kind), GetCppType(kind.value_kind)) | 75 GetCppType(kind.key_kind), GetCppType(kind.value_kind)) |
| 76 if mojom.IsStructKind(kind): | 76 if mojom.IsStructKind(kind): |
| 77 return "%s_Data*" % GetNameForKind(kind, internal=True) | 77 return "%s_Data*" % GetNameForKind(kind, internal=True) |
| 78 if mojom.IsUnionKind(kind): |
| 79 return "%s_Data" % GetNameForKind(kind, internal=True) |
| 78 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): | 80 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): |
| 79 return "mojo::MessagePipeHandle" | 81 return "mojo::MessagePipeHandle" |
| 80 if mojom.IsEnumKind(kind): | 82 if mojom.IsEnumKind(kind): |
| 81 return "int32_t" | 83 return "int32_t" |
| 82 if mojom.IsStringKind(kind): | 84 if mojom.IsStringKind(kind): |
| 83 return "mojo::internal::String_Data*" | 85 return "mojo::internal::String_Data*" |
| 84 return _kind_to_cpp_type[kind] | 86 return _kind_to_cpp_type[kind] |
| 85 | 87 |
| 86 def GetCppPodType(kind): | 88 def GetCppPodType(kind): |
| 87 if mojom.IsStringKind(kind): | 89 if mojom.IsStringKind(kind): |
| 88 return "char*" | 90 return "char*" |
| 89 return _kind_to_cpp_type[kind] | 91 return _kind_to_cpp_type[kind] |
| 90 | 92 |
| 91 def GetCppArrayArgWrapperType(kind): | 93 def GetCppArrayArgWrapperType(kind): |
| 92 if mojom.IsEnumKind(kind): | 94 if mojom.IsEnumKind(kind): |
| 93 return GetNameForKind(kind) | 95 return GetNameForKind(kind) |
| 94 if mojom.IsStructKind(kind): | 96 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 95 return "%sPtr" % GetNameForKind(kind) | 97 return "%sPtr" % GetNameForKind(kind) |
| 96 if mojom.IsArrayKind(kind): | 98 if mojom.IsArrayKind(kind): |
| 97 return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) | 99 return "mojo::Array<%s> " % GetCppArrayArgWrapperType(kind.kind) |
| 98 if mojom.IsMapKind(kind): | 100 if mojom.IsMapKind(kind): |
| 99 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), | 101 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), |
| 100 GetCppArrayArgWrapperType(kind.value_kind)) | 102 GetCppArrayArgWrapperType(kind.value_kind)) |
| 101 if mojom.IsInterfaceKind(kind): | 103 if mojom.IsInterfaceKind(kind): |
| 102 raise Exception("Arrays of interfaces not yet supported!") | 104 raise Exception("Arrays of interfaces not yet supported!") |
| 103 if mojom.IsInterfaceRequestKind(kind): | 105 if mojom.IsInterfaceRequestKind(kind): |
| 104 raise Exception("Arrays of interface requests not yet supported!") | 106 raise Exception("Arrays of interface requests not yet supported!") |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return "mojo::ScopedDataPipeProducerHandle" | 142 return "mojo::ScopedDataPipeProducerHandle" |
| 141 if mojom.IsMessagePipeKind(kind): | 143 if mojom.IsMessagePipeKind(kind): |
| 142 return "mojo::ScopedMessagePipeHandle" | 144 return "mojo::ScopedMessagePipeHandle" |
| 143 if mojom.IsSharedBufferKind(kind): | 145 if mojom.IsSharedBufferKind(kind): |
| 144 return "mojo::ScopedSharedBufferHandle" | 146 return "mojo::ScopedSharedBufferHandle" |
| 145 return _kind_to_cpp_type[kind] | 147 return _kind_to_cpp_type[kind] |
| 146 | 148 |
| 147 def GetCppWrapperType(kind): | 149 def GetCppWrapperType(kind): |
| 148 if mojom.IsEnumKind(kind): | 150 if mojom.IsEnumKind(kind): |
| 149 return GetNameForKind(kind) | 151 return GetNameForKind(kind) |
| 150 if mojom.IsStructKind(kind): | 152 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 151 return "%sPtr" % GetNameForKind(kind) | 153 return "%sPtr" % GetNameForKind(kind) |
| 152 if mojom.IsArrayKind(kind): | 154 if mojom.IsArrayKind(kind): |
| 153 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 155 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 154 if mojom.IsMapKind(kind): | 156 if mojom.IsMapKind(kind): |
| 155 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 157 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 156 GetCppArrayArgWrapperType(kind.value_kind)) | 158 GetCppArrayArgWrapperType(kind.value_kind)) |
| 157 if mojom.IsInterfaceKind(kind): | 159 if mojom.IsInterfaceKind(kind): |
| 158 return "%sPtr" % GetNameForKind(kind) | 160 return "%sPtr" % GetNameForKind(kind) |
| 159 if mojom.IsInterfaceRequestKind(kind): | 161 if mojom.IsInterfaceRequestKind(kind): |
| 160 raise Exception("InterfaceRequest fields not supported!") | 162 raise Exception("InterfaceRequest fields not supported!") |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if mojom.IsSharedBufferKind(kind): | 201 if mojom.IsSharedBufferKind(kind): |
| 200 return "mojo::ScopedSharedBufferHandle" | 202 return "mojo::ScopedSharedBufferHandle" |
| 201 if not kind in _kind_to_cpp_type: | 203 if not kind in _kind_to_cpp_type: |
| 202 print "missing:", kind.spec | 204 print "missing:", kind.spec |
| 203 return _kind_to_cpp_type[kind] | 205 return _kind_to_cpp_type[kind] |
| 204 | 206 |
| 205 def GetCppFieldType(kind): | 207 def GetCppFieldType(kind): |
| 206 if mojom.IsStructKind(kind): | 208 if mojom.IsStructKind(kind): |
| 207 return ("mojo::internal::StructPointer<%s_Data>" % | 209 return ("mojo::internal::StructPointer<%s_Data>" % |
| 208 GetNameForKind(kind, internal=True)) | 210 GetNameForKind(kind, internal=True)) |
| 211 if mojom.IsUnionKind(kind): |
| 212 return "%s_Data" % GetNameForKind(kind, internal=True) |
| 209 if mojom.IsArrayKind(kind): | 213 if mojom.IsArrayKind(kind): |
| 210 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) | 214 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) |
| 211 if mojom.IsMapKind(kind): | 215 if mojom.IsMapKind(kind): |
| 212 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % | 216 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % |
| 213 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) | 217 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) |
| 214 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): | 218 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): |
| 215 return "mojo::MessagePipeHandle" | 219 return "mojo::MessagePipeHandle" |
| 216 if mojom.IsEnumKind(kind): | 220 if mojom.IsEnumKind(kind): |
| 217 return GetNameForKind(kind) | 221 return GetNameForKind(kind) |
| 218 if mojom.IsStringKind(kind): | 222 if mojom.IsStringKind(kind): |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 def GenerateModuleSource(self): | 387 def GenerateModuleSource(self): |
| 384 return self.GetJinjaExports() | 388 return self.GetJinjaExports() |
| 385 | 389 |
| 386 def GenerateFiles(self, args): | 390 def GenerateFiles(self, args): |
| 387 self.Write(self.GenerateModuleHeader(), | 391 self.Write(self.GenerateModuleHeader(), |
| 388 self.MatchMojomFilePath("%s.h" % self.module.name)) | 392 self.MatchMojomFilePath("%s.h" % self.module.name)) |
| 389 self.Write(self.GenerateModuleInternalHeader(), | 393 self.Write(self.GenerateModuleInternalHeader(), |
| 390 self.MatchMojomFilePath("%s-internal.h" % self.module.name)) | 394 self.MatchMojomFilePath("%s-internal.h" % self.module.name)) |
| 391 self.Write(self.GenerateModuleSource(), | 395 self.Write(self.GenerateModuleSource(), |
| 392 self.MatchMojomFilePath("%s.cc" % self.module.name)) | 396 self.MatchMojomFilePath("%s.cc" % self.module.name)) |
| OLD | NEW |