Chromium Code Reviews| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 parts = [] | 60 parts = [] |
| 61 if kind.imported_from: | 61 if kind.imported_from: |
| 62 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) | 62 parts.extend(NamespaceToArray(kind.imported_from["namespace"])) |
| 63 if internal: | 63 if internal: |
| 64 parts.append("internal") | 64 parts.append("internal") |
| 65 if kind.parent_kind: | 65 if kind.parent_kind: |
| 66 parts.append(kind.parent_kind.name) | 66 parts.append(kind.parent_kind.name) |
| 67 parts.append(kind.name) | 67 parts.append(kind.name) |
| 68 return "::".join(parts) | 68 return "::".join(parts) |
| 69 | 69 |
| 70 def GetCppType(kind): | 70 def GetCppType(kind): |
|
yzshen1
2015/02/17 19:34:35
There are quite a few of GetXXXType(), they all ne
azani
2015/02/18 00:27:58
If that's ok with you, I would rather add them as
yzshen1
2015/02/25 21:06:59
I am a little concerned to leave these set of func
| |
| 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.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): | 78 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): |
| 79 return "mojo::MessagePipeHandle" | 79 return "mojo::MessagePipeHandle" |
| 80 if mojom.IsEnumKind(kind): | 80 if mojom.IsEnumKind(kind): |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 return "mojo::ScopedDataPipeProducerHandle" | 140 return "mojo::ScopedDataPipeProducerHandle" |
| 141 if mojom.IsMessagePipeKind(kind): | 141 if mojom.IsMessagePipeKind(kind): |
| 142 return "mojo::ScopedMessagePipeHandle" | 142 return "mojo::ScopedMessagePipeHandle" |
| 143 if mojom.IsSharedBufferKind(kind): | 143 if mojom.IsSharedBufferKind(kind): |
| 144 return "mojo::ScopedSharedBufferHandle" | 144 return "mojo::ScopedSharedBufferHandle" |
| 145 return _kind_to_cpp_type[kind] | 145 return _kind_to_cpp_type[kind] |
| 146 | 146 |
| 147 def GetCppWrapperType(kind): | 147 def GetCppWrapperType(kind): |
| 148 if mojom.IsEnumKind(kind): | 148 if mojom.IsEnumKind(kind): |
| 149 return GetNameForKind(kind) | 149 return GetNameForKind(kind) |
| 150 if mojom.IsStructKind(kind): | 150 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
| 151 return "%sPtr" % GetNameForKind(kind) | 151 return "%sPtr" % GetNameForKind(kind) |
| 152 if mojom.IsArrayKind(kind): | 152 if mojom.IsArrayKind(kind): |
| 153 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) | 153 return "mojo::Array<%s>" % GetCppArrayArgWrapperType(kind.kind) |
| 154 if mojom.IsMapKind(kind): | 154 if mojom.IsMapKind(kind): |
| 155 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), | 155 return "mojo::Map<%s, %s>" % (GetCppArrayArgWrapperType(kind.key_kind), |
| 156 GetCppArrayArgWrapperType(kind.value_kind)) | 156 GetCppArrayArgWrapperType(kind.value_kind)) |
| 157 if mojom.IsInterfaceKind(kind): | 157 if mojom.IsInterfaceKind(kind): |
| 158 return "%sPtr" % GetNameForKind(kind) | 158 return "%sPtr" % GetNameForKind(kind) |
| 159 if mojom.IsInterfaceRequestKind(kind): | 159 if mojom.IsInterfaceRequestKind(kind): |
| 160 raise Exception("InterfaceRequest fields not supported!") | 160 raise Exception("InterfaceRequest fields not supported!") |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 if mojom.IsSharedBufferKind(kind): | 199 if mojom.IsSharedBufferKind(kind): |
| 200 return "mojo::ScopedSharedBufferHandle" | 200 return "mojo::ScopedSharedBufferHandle" |
| 201 if not kind in _kind_to_cpp_type: | 201 if not kind in _kind_to_cpp_type: |
| 202 print "missing:", kind.spec | 202 print "missing:", kind.spec |
| 203 return _kind_to_cpp_type[kind] | 203 return _kind_to_cpp_type[kind] |
| 204 | 204 |
| 205 def GetCppFieldType(kind): | 205 def GetCppFieldType(kind): |
| 206 if mojom.IsStructKind(kind): | 206 if mojom.IsStructKind(kind): |
| 207 return ("mojo::internal::StructPointer<%s_Data>" % | 207 return ("mojo::internal::StructPointer<%s_Data>" % |
| 208 GetNameForKind(kind, internal=True)) | 208 GetNameForKind(kind, internal=True)) |
| 209 if mojom.IsUnionKind(kind): | |
| 210 return "%s_Data" % GetNameForKind(kind, internal=True) | |
| 209 if mojom.IsArrayKind(kind): | 211 if mojom.IsArrayKind(kind): |
| 210 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) | 212 return "mojo::internal::ArrayPointer<%s>" % GetCppType(kind.kind) |
| 211 if mojom.IsMapKind(kind): | 213 if mojom.IsMapKind(kind): |
| 212 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % | 214 return ("mojo::internal::StructPointer<mojo::internal::Map_Data<%s, %s>>" % |
| 213 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) | 215 (GetCppType(kind.key_kind), GetCppType(kind.value_kind))) |
| 214 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): | 216 if mojom.IsInterfaceKind(kind) or mojom.IsInterfaceRequestKind(kind): |
| 215 return "mojo::MessagePipeHandle" | 217 return "mojo::MessagePipeHandle" |
| 216 if mojom.IsEnumKind(kind): | 218 if mojom.IsEnumKind(kind): |
| 217 return GetNameForKind(kind) | 219 return GetNameForKind(kind) |
| 218 if mojom.IsStringKind(kind): | 220 if mojom.IsStringKind(kind): |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 def GenerateModuleSource(self): | 385 def GenerateModuleSource(self): |
| 384 return self.GetJinjaExports() | 386 return self.GetJinjaExports() |
| 385 | 387 |
| 386 def GenerateFiles(self, args): | 388 def GenerateFiles(self, args): |
| 387 self.Write(self.GenerateModuleHeader(), | 389 self.Write(self.GenerateModuleHeader(), |
| 388 self.MatchMojomFilePath("%s.h" % self.module.name)) | 390 self.MatchMojomFilePath("%s.h" % self.module.name)) |
| 389 self.Write(self.GenerateModuleInternalHeader(), | 391 self.Write(self.GenerateModuleInternalHeader(), |
| 390 self.MatchMojomFilePath("%s-internal.h" % self.module.name)) | 392 self.MatchMojomFilePath("%s-internal.h" % self.module.name)) |
| 391 self.Write(self.GenerateModuleSource(), | 393 self.Write(self.GenerateModuleSource(), |
| 392 self.MatchMojomFilePath("%s.cc" % self.module.name)) | 394 self.MatchMojomFilePath("%s.cc" % self.module.name)) |
| OLD | NEW |