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

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: comments 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..9383d35f90b5605540ece40504455a9c97d9b320 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,27 @@ class CppTypeGenerator(object):
self._root_namespace.
"""
c = Code()
- for namespace, types in sorted(self._NamespaceTypeDependencies().items()):
+ def NamespaceSortKey(namespace_types):
+ return namespace_types[0].name
not at google - send to devlin 2012/06/07 03:00:54 I think this would be easier to read like def Sor
benjhayden 2012/06/08 16:41:52 Done.
+ for namespace, types in sorted(self._NamespaceTypeDependencies().items(),
+ key=NamespaceSortKey):
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:
+ def StripNamespaceFromType(type_name):
+ return (schema_util.StripSchemaNamespace(type_name),
+ namespace.types[type_name])
+ # Sort by stripped_type_name.
+ for stripped_type_name, type_json in sorted(
not at google - send to devlin 2012/06/07 03:00:54 this isn't json, it's a type. So call this type_
benjhayden 2012/06/08 16:41:52 That makes it difficult to see how it's used becau
+ map(StripNamespaceFromType, types),
+ key=itemgetter(0)):
not at google - send to devlin 2012/06/07 03:00:54 I've been starting at this code for like 20 minute
benjhayden 2012/06/08 16:41:52 I wanted to avoid running StripSchemaNamespace twi
+ if type_json.type_ == PropertyType.STRING:
+ c.Append('typedef std::string %s;' % stripped_type_name)
+ elif type_json.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,
+ c.Substitute({'name': stripped_type_name, 'item_type':
+ self.GetType(type_json.item_type,
not at google - send to devlin 2012/06/07 03:00:54 mind fixing up this indentation while you're here?
benjhayden 2012/06/08 16:41:52 Done.
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 +208,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