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

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 9836078: Make json_schema_compiler output types in their dependency order. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changing error message to make it clear that circular dependencies are forbidden. Created 8 years, 9 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
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/h_generator.py
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index dfc99cbea489a9f0d4f26938a8231fe60685f783..5ae50bc0c0c36e5faec00c78b7fce2ed29e9f8df 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -65,7 +65,7 @@ class HGenerator(object):
.Append('//')
.Append()
)
- for type_ in self._namespace.types.values():
+ for type_ in self._FieldDependencyOrder():
(c.Concat(self._GenerateType(type_))
.Append()
)
@@ -87,6 +87,26 @@ class HGenerator(object):
)
return c
+ def _FieldDependencyOrder(self):
+ """Generates the list of types in the current namespace in an order in which
+ depended-upon types appear before types which depend on them.
+ """
+ dependency_order = []
+
+ def ExpandType(path, type_):
+ if type_ in path:
+ raise ValueError("Illegal circular dependency via cycle " +
+ ", ".join(map(lambda x: x.name, path + [type_])))
+ for prop in type_.properties.values():
+ if not prop.optional and prop.type_ == PropertyType.REF:
+ ExpandType(path + [type_], self._namespace.types[prop.ref_type])
+ if not type_ in dependency_order:
+ dependency_order.append(type_)
+
+ for type_ in self._namespace.types.values():
+ ExpandType([], type_)
+ return dependency_order
+
def _GenerateEnumDeclaration(self, enum_name, prop, values):
"""Generate the declaration of a C++ enum for the given property and
values.
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698