Index: mojo/public/tools/bindings/generators/mojom_cpp_generator.py |
diff --git a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py |
index 22e089ccae7483bb608b9b423f446690752a49f7..32ec5be40e5d7a58a8b385dbe0b91aec944643e5 100644 |
--- a/mojo/public/tools/bindings/generators/mojom_cpp_generator.py |
+++ b/mojo/public/tools/bindings/generators/mojom_cpp_generator.py |
@@ -42,9 +42,10 @@ _kind_to_cpp_literal_suffix = { |
mojom.UINT64: "ULL", |
} |
-# TODO(rockot): Get rid of this global. This requires some refactoring of the |
+# TODO(rockot): Get rid of these globals. This requires some refactoring of the |
# generator library code so that filters can use the generator as context. |
_current_typemap = {} |
+_use_wtf_types = False |
def ConstantValue(constant): |
@@ -56,9 +57,10 @@ def DefaultValue(field): |
assert field.default == "default" |
return "%s::New()" % GetNameForKind(field.kind) |
return ExpressionToText(field.default, kind=field.kind) |
- if (mojom.IsStringKind(field.kind) or mojom.IsArrayKind(field.kind) or |
- mojom.IsMapKind(field.kind)): |
+ if mojom.IsArrayKind(field.kind) or mojom.IsMapKind(field.kind): |
return "nullptr"; |
+ if mojom.IsStringKind(field.kind): |
+ return "" if _use_wtf_types else "nullptr" |
return "" |
def NamespaceToArray(namespace): |
@@ -184,7 +186,7 @@ def GetCppArrayArgWrapperType(kind): |
raise Exception("Arrays of associated interface requests not yet " |
"supported!") |
if mojom.IsStringKind(kind): |
- return "mojo::String" |
+ return "WTF::String" if _use_wtf_types else "mojo::String" |
if mojom.IsGenericHandleKind(kind): |
return "mojo::ScopedHandle" |
if mojom.IsDataPipeConsumerKind(kind): |
@@ -220,7 +222,7 @@ def GetCppResultWrapperType(kind): |
if mojom.IsAssociatedInterfaceRequestKind(kind): |
return "%sAssociatedRequest" % GetNameForKind(kind.kind) |
if mojom.IsStringKind(kind): |
- return "mojo::String" |
+ return "WTF::String" if _use_wtf_types else "mojo::String" |
if mojom.IsGenericHandleKind(kind): |
return "mojo::ScopedHandle" |
if mojom.IsDataPipeConsumerKind(kind): |
@@ -262,7 +264,7 @@ def GetCppWrapperType(kind): |
if mojom.IsAssociatedInterfaceRequestKind(kind): |
return "%sAssociatedRequest" % GetNameForKind(kind.kind) |
if mojom.IsStringKind(kind): |
- return "mojo::String" |
+ return "WTF::String" if _use_wtf_types else "mojo::String" |
if mojom.IsGenericHandleKind(kind): |
return "mojo::ScopedHandle" |
if mojom.IsDataPipeConsumerKind(kind): |
@@ -298,7 +300,7 @@ def GetCppConstWrapperType(kind): |
if mojom.IsEnumKind(kind): |
return GetNameForKind(kind) |
if mojom.IsStringKind(kind): |
- return "const mojo::String&" |
+ return "const WTF::String&" if _use_wtf_types else "const mojo::String&" |
if mojom.IsGenericHandleKind(kind): |
return "mojo::ScopedHandle" |
if mojom.IsDataPipeConsumerKind(kind): |
@@ -522,6 +524,7 @@ class Generator(generator.Generator): |
"interfaces": self.GetInterfaces(), |
"variant": self.variant, |
"extra_headers": self.GetExtraHeaders(), |
+ "use_wtf_types": self.use_wtf_types, |
} |
@staticmethod |
@@ -547,6 +550,8 @@ class Generator(generator.Generator): |
def GenerateFiles(self, args): |
global _current_typemap |
_current_typemap = self.typemap |
+ global _use_wtf_types |
+ _use_wtf_types = self.use_wtf_types |
suffix = "-%s" % self.variant if self.variant else "" |
self.Write(self.GenerateModuleHeader(), |
self.MatchMojomFilePath("%s%s.h" % (self.module.name, suffix))) |