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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return "mojo::internal::Handle_Data" | 170 return "mojo::internal::Handle_Data" |
171 return _kind_to_cpp_type[kind] | 171 return _kind_to_cpp_type[kind] |
172 | 172 |
173 def GetCppPodType(kind): | 173 def GetCppPodType(kind): |
174 if mojom.IsStringKind(kind): | 174 if mojom.IsStringKind(kind): |
175 return "char*" | 175 return "char*" |
176 return _kind_to_cpp_type[kind] | 176 return _kind_to_cpp_type[kind] |
177 | 177 |
178 def GetCppArrayArgWrapperType(kind): | 178 def GetCppArrayArgWrapperType(kind): |
179 if IsTypemappedKind(kind): | 179 if IsTypemappedKind(kind): |
180 if mojom.IsStructKind(kind) and kind.native_only: | 180 return GetNativeTypeName(kind) |
181 return GetNativeTypeName(kind) | |
182 else: | |
183 raise Exception( | |
184 "Cannot serialize containers of non-native typemapped structs yet!") | |
185 if mojom.IsEnumKind(kind): | 181 if mojom.IsEnumKind(kind): |
186 return GetNameForKind(kind) | 182 return GetNameForKind(kind) |
187 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): | 183 if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind): |
188 return "%sPtr" % GetNameForKind(kind) | 184 return "%sPtr" % GetNameForKind(kind) |
189 if mojom.IsArrayKind(kind): | 185 if mojom.IsArrayKind(kind): |
190 pattern = "mojo::WTFArray<%s>" if _for_blink else "mojo::Array<%s>" | 186 pattern = "mojo::WTFArray<%s>" if _for_blink else "mojo::Array<%s>" |
191 return pattern % GetCppArrayArgWrapperType(kind.kind) | 187 return pattern % GetCppArrayArgWrapperType(kind.kind) |
192 if mojom.IsMapKind(kind): | 188 if mojom.IsMapKind(kind): |
193 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), | 189 return "mojo::Map<%s, %s> " % (GetCppArrayArgWrapperType(kind.key_kind), |
194 GetCppArrayArgWrapperType(kind.value_kind)) | 190 GetCppArrayArgWrapperType(kind.value_kind)) |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 _for_blink = self.for_blink | 596 _for_blink = self.for_blink |
601 global _variant | 597 global _variant |
602 _variant = self.variant | 598 _variant = self.variant |
603 suffix = "-%s" % self.variant if self.variant else "" | 599 suffix = "-%s" % self.variant if self.variant else "" |
604 self.Write(self.GenerateModuleHeader(), | 600 self.Write(self.GenerateModuleHeader(), |
605 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 601 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
606 self.Write(self.GenerateModuleInternalHeader(), | 602 self.Write(self.GenerateModuleInternalHeader(), |
607 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) | 603 self.MatchMojomFilePath("%s%s-internal.h" % (self.module.name, suffix))) |
608 self.Write(self.GenerateModuleSource(), | 604 self.Write(self.GenerateModuleSource(), |
609 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 605 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
OLD | NEW |