Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: tools/json_schema_compiler/cpp_type_generator.py

Issue 437883002: Make the root_namespace argument to json_schema_compiler.gypi a string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: un-escape %% for windows Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/cpp_type_generator.py
diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
index 75972faf04c914e143111456cde92a0add603935..de6d1306287511d5419ed199174aae6b1663ac17 100644
--- a/tools/json_schema_compiler/cpp_type_generator.py
+++ b/tools/json_schema_compiler/cpp_type_generator.py
@@ -35,24 +35,6 @@ class CppTypeGenerator(object):
self._default_namespace = model.namespaces.values()[0]
self._schema_loader = schema_loader
- def GetCppNamespaceName(self, namespace):
- """Gets the mapped C++ namespace name for the given namespace relative to
- the root namespace.
- """
- return namespace.unix_name
-
- def GetNamespaceStart(self):
- """Get opening self._default_namespace namespace declaration.
- """
- return Code().Append('namespace %s {' %
- self.GetCppNamespaceName(self._default_namespace))
-
- def GetNamespaceEnd(self):
- """Get closing self._default_namespace namespace declaration.
- """
- return Code().Append('} // %s' %
- self.GetCppNamespaceName(self._default_namespace))
-
def GetEnumNoneValue(self, type_):
"""Gets the enum value in the given model.Property indicating no value has
been set.
@@ -148,23 +130,26 @@ class CppTypeGenerator(object):
PropertyType.OBJECT,
PropertyType.CHOICES))
- def GenerateForwardDeclarations(self):
+ def GenerateForwardDeclarations(self, cpp_namespace_pattern):
"""Returns the forward declarations for self._default_namespace.
"""
c = Code()
-
- for namespace, dependencies in self._NamespaceTypeDependencies().items():
- c.Append('namespace %s {' % namespace.unix_name)
- for dependency in dependencies:
- # No point forward-declaring hard dependencies.
- if dependency.hard:
- continue
+ for namespace, deps in self._NamespaceTypeDependencies().iteritems():
+ filtered_deps = [
+ dep for dep in deps
# Add more ways to forward declare things as necessary.
- if dependency.type_.property_type in (PropertyType.CHOICES,
- PropertyType.OBJECT):
- c.Append('struct %s;' % dependency.type_.name)
- c.Append('}')
+ if (not dep.hard and
+ dep.type_.property_type in (PropertyType.CHOICES,
+ PropertyType.OBJECT))]
+ if not filtered_deps:
+ continue
+ cpp_namespace = cpp_util.GetCppNamespace(cpp_namespace_pattern,
+ namespace.unix_name)
+ c.Concat(cpp_util.OpenNamespace(cpp_namespace))
+ for dep in filtered_deps:
+ c.Append('struct %s;' % dep.type_.name)
+ c.Concat(cpp_util.CloseNamespace(cpp_namespace))
return c
def GenerateIncludes(self, include_soft=False):

Powered by Google App Engine
This is Rietveld 408576698