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

Side by Side 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: Do not generate forward declarations for non-struct types 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/json_schema_compiler/cpp_type_generator.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from model import PropertyType 5 from model import PropertyType
6 import code 6 import code
7 import cpp_util 7 import cpp_util
8 import model 8 import model
9 import os 9 import os
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 ) 58 )
59 59
60 c.Concat(self._cpp_type_generator.GetNamespaceStart()) 60 c.Concat(self._cpp_type_generator.GetNamespaceStart())
61 c.Append() 61 c.Append()
62 if self._namespace.types: 62 if self._namespace.types:
63 (c.Append('//') 63 (c.Append('//')
64 .Append('// Types') 64 .Append('// Types')
65 .Append('//') 65 .Append('//')
66 .Append() 66 .Append()
67 ) 67 )
68 for type_ in self._namespace.types.values(): 68 for type_ in self._FieldDependencyOrder():
69 (c.Concat(self._GenerateType(type_)) 69 (c.Concat(self._GenerateType(type_))
70 .Append() 70 .Append()
71 ) 71 )
72 if self._namespace.functions: 72 if self._namespace.functions:
73 (c.Append('//') 73 (c.Append('//')
74 .Append('// Functions') 74 .Append('// Functions')
75 .Append('//') 75 .Append('//')
76 .Append() 76 .Append()
77 ) 77 )
78 for function in self._namespace.functions.values(): 78 for function in self._namespace.functions.values():
79 (c.Concat(self._GenerateFunction(function)) 79 (c.Concat(self._GenerateFunction(function))
80 .Append() 80 .Append()
81 ) 81 )
82 (c.Concat(self._cpp_type_generator.GetNamespaceEnd()) 82 (c.Concat(self._cpp_type_generator.GetNamespaceEnd())
83 .Concat(self._cpp_type_generator.GetRootNamespaceEnd()) 83 .Concat(self._cpp_type_generator.GetRootNamespaceEnd())
84 .Append() 84 .Append()
85 .Append('#endif // %s' % ifndef_name) 85 .Append('#endif // %s' % ifndef_name)
86 .Append() 86 .Append()
87 ) 87 )
88 return c 88 return c
89 89
90 def _FieldDependencyOrder(self):
91 """Generates the list of types in the current namespace in an order in which
92 depended-upon types appear before types which depend on them.
93 """
94 dependency_order = []
95
96 def ExpandType(path, type_):
97 if type_ in path:
98 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
99 "properties not implemented. Path: " + ", ".join(map(
100 lambda x: x.name, path)) + ", referencing: " + type_.name)
101 for prop in type_.properties.values():
102 if not prop.optional and prop.type_ == PropertyType.REF:
103 ExpandType(path + [type_], self._namespace.types[prop.ref_type])
104 if not type_ in dependency_order:
105 dependency_order.append(type_)
106
107 for type_ in self._namespace.types.values():
108 ExpandType([], type_)
109 return dependency_order
110
90 def _GenerateEnumDeclaration(self, enum_name, prop, values): 111 def _GenerateEnumDeclaration(self, enum_name, prop, values):
91 """Generate the declaration of a C++ enum for the given property and 112 """Generate the declaration of a C++ enum for the given property and
92 values. 113 values.
93 """ 114 """
94 c = code.Code() 115 c = code.Code()
95 c.Sblock('enum %s {' % enum_name) 116 c.Sblock('enum %s {' % enum_name)
96 if prop.optional: 117 if prop.optional:
97 c.Append(self._cpp_type_generator.GetEnumNoneValue(prop) + ',') 118 c.Append(self._cpp_type_generator.GetEnumNoneValue(prop) + ',')
98 for value in values: 119 for value in values:
99 c.Append(self._cpp_type_generator.GetEnumValue(prop, value) + ',') 120 c.Append(self._cpp_type_generator.GetEnumValue(prop, value) + ',')
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 c.Comment(param.description) 278 c.Comment(param.description)
258 if param.type_ == PropertyType.ANY: 279 if param.type_ == PropertyType.ANY:
259 c.Comment("Value* Result::Create(Value*) not generated " 280 c.Comment("Value* Result::Create(Value*) not generated "
260 "because it's redundant.") 281 "because it's redundant.")
261 continue 282 continue
262 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( 283 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration(
263 param, self._cpp_type_generator.GetType(param))) 284 param, self._cpp_type_generator.GetType(param)))
264 c.Eblock('};') 285 c.Eblock('};')
265 286
266 return c 287 return c
OLDNEW
« 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