Chromium Code Reviews| 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..e9fad3a96b0e98d178dc594212170bf8e95904e9 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,27 @@ 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 NotImplementedError("Circular dependencies of non-optional " + |
|
asargent_no_longer_on_chrome
2012/03/26 17:40:35
As discussed in person, I'm inclined to simply dis
|
| + "properties not implemented. Path: " + ", ".join(map( |
| + lambda x: x.name, path)) + ", referencing: " + type_.name) |
| + 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. |