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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 return True | 209 return True |
| 210 return Check(kind) | 210 return Check(kind) |
| 211 | 211 |
| 212 | 212 |
| 213 def GetNativeTypeName(typemapped_kind): | 213 def GetNativeTypeName(typemapped_kind): |
| 214 return _current_typemap[GetFullMojomNameForKind(typemapped_kind)]["typename"] | 214 return _current_typemap[GetFullMojomNameForKind(typemapped_kind)]["typename"] |
| 215 | 215 |
| 216 def GetCppPodType(kind): | 216 def GetCppPodType(kind): |
| 217 return _kind_to_cpp_type[kind] | 217 return _kind_to_cpp_type[kind] |
| 218 | 218 |
| 219 def FormatConstantDeclaration(constant, nested=False): | 219 def FormatConstantDeclaration(constant, nested=False, export_attribute=None): |
|
yzshen1
2017/02/28 23:13:09
Instead of having an export_attribute input, how a
sky
2017/02/28 23:45:04
Done.
| |
| 220 if mojom.IsStringKind(constant.kind): | 220 if mojom.IsStringKind(constant.kind): |
| 221 if nested: | 221 if nested: |
| 222 return "const char %s[]" % constant.name | 222 return "const char %s[]" % constant.name |
| 223 return "extern const char %s[]" % constant.name | 223 return "%sextern const char %s[]" % \ |
| 224 ((export_attribute + " ") if export_attribute else "", constant.name) | |
| 224 return "constexpr %s %s = %s" % (GetCppPodType(constant.kind), constant.name, | 225 return "constexpr %s %s = %s" % (GetCppPodType(constant.kind), constant.name, |
| 225 ConstantValue(constant)) | 226 ConstantValue(constant)) |
| 226 | 227 |
| 227 def GetCppWrapperType(kind, add_same_module_namespaces=False): | 228 def GetCppWrapperType(kind, add_same_module_namespaces=False): |
| 228 def _AddOptional(type_name): | 229 def _AddOptional(type_name): |
| 229 pattern = "WTF::Optional<%s>" if _for_blink else "base::Optional<%s>" | 230 pattern = "WTF::Optional<%s>" if _for_blink else "base::Optional<%s>" |
| 230 return pattern % type_name | 231 return pattern % type_name |
| 231 | 232 |
| 232 if IsTypemappedKind(kind): | 233 if IsTypemappedKind(kind): |
| 233 type_name = GetNativeTypeName(kind) | 234 type_name = GetNativeTypeName(kind) |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 729 global _use_once_callback | 730 global _use_once_callback |
| 730 _use_once_callback = self.use_once_callback | 731 _use_once_callback = self.use_once_callback |
| 731 global _variant | 732 global _variant |
| 732 _variant = self.variant | 733 _variant = self.variant |
| 733 suffix = "-%s" % self.variant if self.variant else "" | 734 suffix = "-%s" % self.variant if self.variant else "" |
| 734 self.Write(self.GenerateModuleHeader(), | 735 self.Write(self.GenerateModuleHeader(), |
| 735 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 736 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 736 self.Write( | 737 self.Write( |
| 737 self.GenerateModuleSource(), | 738 self.GenerateModuleSource(), |
| 738 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 739 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |