| 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 21 matching lines...) Expand all Loading... |
| 32 mojom.UINT64: "ULL", | 32 mojom.UINT64: "ULL", |
| 33 } | 33 } |
| 34 | 34 |
| 35 # TODO(rockot): Get rid of these globals. This requires some refactoring of the | 35 # TODO(rockot): Get rid of these globals. This requires some refactoring of the |
| 36 # generator library code so that filters can use the generator as context. | 36 # generator library code so that filters can use the generator as context. |
| 37 _current_typemap = {} | 37 _current_typemap = {} |
| 38 _for_blink = False | 38 _for_blink = False |
| 39 # TODO(rockot, yzshen): The variant handling is kind of a hack currently. Make | 39 # TODO(rockot, yzshen): The variant handling is kind of a hack currently. Make |
| 40 # it right. | 40 # it right. |
| 41 _variant = None | 41 _variant = None |
| 42 _export_attribute = None |
| 42 | 43 |
| 43 | 44 |
| 44 class _NameFormatter(object): | 45 class _NameFormatter(object): |
| 45 """A formatter for the names of kinds or values.""" | 46 """A formatter for the names of kinds or values.""" |
| 46 | 47 |
| 47 def __init__(self, token, variant): | 48 def __init__(self, token, variant): |
| 48 self._token = token | 49 self._token = token |
| 49 self._variant = variant | 50 self._variant = variant |
| 50 | 51 |
| 51 def Format(self, separator, prefixed=False, internal=False, | 52 def Format(self, separator, prefixed=False, internal=False, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 def GetNativeTypeName(typemapped_kind): | 214 def GetNativeTypeName(typemapped_kind): |
| 214 return _current_typemap[GetFullMojomNameForKind(typemapped_kind)]["typename"] | 215 return _current_typemap[GetFullMojomNameForKind(typemapped_kind)]["typename"] |
| 215 | 216 |
| 216 def GetCppPodType(kind): | 217 def GetCppPodType(kind): |
| 217 return _kind_to_cpp_type[kind] | 218 return _kind_to_cpp_type[kind] |
| 218 | 219 |
| 219 def FormatConstantDeclaration(constant, nested=False): | 220 def FormatConstantDeclaration(constant, nested=False): |
| 220 if mojom.IsStringKind(constant.kind): | 221 if mojom.IsStringKind(constant.kind): |
| 221 if nested: | 222 if nested: |
| 222 return "const char %s[]" % constant.name | 223 return "const char %s[]" % constant.name |
| 223 return "extern const char %s[]" % constant.name | 224 return "%sextern const char %s[]" % \ |
| 225 ((_export_attribute + " ") if _export_attribute else "", constant.name) |
| 224 return "constexpr %s %s = %s" % (GetCppPodType(constant.kind), constant.name, | 226 return "constexpr %s %s = %s" % (GetCppPodType(constant.kind), constant.name, |
| 225 ConstantValue(constant)) | 227 ConstantValue(constant)) |
| 226 | 228 |
| 227 def GetCppWrapperType(kind, add_same_module_namespaces=False): | 229 def GetCppWrapperType(kind, add_same_module_namespaces=False): |
| 228 def _AddOptional(type_name): | 230 def _AddOptional(type_name): |
| 229 pattern = "WTF::Optional<%s>" if _for_blink else "base::Optional<%s>" | 231 pattern = "WTF::Optional<%s>" if _for_blink else "base::Optional<%s>" |
| 230 return pattern % type_name | 232 return pattern % type_name |
| 231 | 233 |
| 232 if IsTypemappedKind(kind): | 234 if IsTypemappedKind(kind): |
| 233 type_name = GetNativeTypeName(kind) | 235 type_name = GetNativeTypeName(kind) |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 self.MatchMojomFilePath("%s-shared.cc" % self.module.name)) | 725 self.MatchMojomFilePath("%s-shared.cc" % self.module.name)) |
| 724 else: | 726 else: |
| 725 global _current_typemap | 727 global _current_typemap |
| 726 _current_typemap = self.typemap | 728 _current_typemap = self.typemap |
| 727 global _for_blink | 729 global _for_blink |
| 728 _for_blink = self.for_blink | 730 _for_blink = self.for_blink |
| 729 global _use_once_callback | 731 global _use_once_callback |
| 730 _use_once_callback = self.use_once_callback | 732 _use_once_callback = self.use_once_callback |
| 731 global _variant | 733 global _variant |
| 732 _variant = self.variant | 734 _variant = self.variant |
| 735 global _export_attribute |
| 736 _export_attribute = self.export_attribute |
| 733 suffix = "-%s" % self.variant if self.variant else "" | 737 suffix = "-%s" % self.variant if self.variant else "" |
| 734 self.Write(self.GenerateModuleHeader(), | 738 self.Write(self.GenerateModuleHeader(), |
| 735 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) | 739 self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |
| 736 self.Write( | 740 self.Write( |
| 737 self.GenerateModuleSource(), | 741 self.GenerateModuleSource(), |
| 738 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) | 742 self.MatchMojomFilePath("%s%s.cc" % (self.module.name, suffix))) |
| OLD | NEW |