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

Unified Diff: tools/json_schema_compiler/cpp_type_generator.py

Issue 9617010: Move chrome.downloads out of experimental to dev (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 8a9960ea99df0c18e3269645cdd878289c920270..947eee1cd45455fb506033ba263631748fcf8222 100644
--- a/tools/json_schema_compiler/cpp_type_generator.py
+++ b/tools/json_schema_compiler/cpp_type_generator.py
@@ -4,10 +4,10 @@
from code import Code
from model import PropertyType
+from operator import itemgetter
import any_helper
import cpp_util
import schema_util
-import string
class CppTypeGenerator(object):
"""Manages the types of properties and provides utilities for getting the
@@ -175,19 +175,28 @@ class CppTypeGenerator(object):
self._root_namespace.
"""
c = Code()
- for namespace, types in sorted(self._NamespaceTypeDependencies().items()):
+ def SortByNamespace((namespace, types)):
+ return namespace.name
+ for namespace, types in sorted(self._NamespaceTypeDependencies().items(),
+ key=SortByNamespace):
c.Append('namespace %s {' % namespace.name)
- for type_ in types:
- type_name = schema_util.StripSchemaNamespace(type_)
- if namespace.types[type_].type_ == PropertyType.STRING:
- c.Append('typedef std::string %s;' % type_name)
- elif namespace.types[type_].type_ == PropertyType.ARRAY:
+ stripped_type_names = [
+ (schema_util.StripSchemaNamespace(type_name),
+ namespace.types[type_name])
+ for type_name in types]
+ # Sort by stripped_type_name.
+ for stripped_type_name, type_obj in sorted(stripped_type_names,
+ key=itemgetter(0)):
+ if type_obj.type_ == PropertyType.STRING:
+ c.Append('typedef std::string %s;' % stripped_type_name)
+ elif type_obj.type_ == PropertyType.ARRAY:
c.Append('typedef std::vector<%(item_type)s> %(name)s;')
- c.Substitute({'name': type_name, 'item_type':
- self.GetType(namespace.types[type_].item_type,
- wrap_optional=True)})
+ c.Substitute({
+ 'name': stripped_type_name,
+ 'item_type': self.GetType(type_obj.item_type, wrap_optional=True),
+ })
else:
- c.Append('struct %s;' % type_name)
+ c.Append('struct %s;' % stripped_type_name)
c.Append('}')
c.Concat(self.GetNamespaceStart())
for (name, type_) in self._namespace.types.items():
@@ -200,10 +209,13 @@ class CppTypeGenerator(object):
"""Returns the #include lines for self._namespace.
"""
c = Code()
- for dependency in sorted(self._NamespaceTypeDependencies().keys()):
- c.Append('#include "%s/%s.h"' % (
+ filenames = []
+ for dependency in self._NamespaceTypeDependencies().keys():
+ filenames.append('%s/%s.h' % (
dependency.source_file_dir,
self._cpp_namespaces[dependency]))
+ for filename in sorted(filenames):
+ c.Append('#include "%s"' % filename)
return c
def _ResolveTypeNamespace(self, ref_type):

Powered by Google App Engine
This is Rietveld 408576698