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

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: 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 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 ValueError("Illegal circular dependency via cycle " +
99 ", ".join(map(lambda x: x.name, path + [type_])))
100 for prop in type_.properties.values():
101 if not prop.optional and prop.type_ == PropertyType.REF:
102 ExpandType(path + [type_], self._namespace.types[prop.ref_type])
103 if not type_ in dependency_order:
104 dependency_order.append(type_)
105
106 for type_ in self._namespace.types.values():
107 ExpandType([], type_)
108 return dependency_order
109
90 def _GenerateEnumDeclaration(self, enum_name, prop, values): 110 def _GenerateEnumDeclaration(self, enum_name, prop, values):
91 """Generate the declaration of a C++ enum for the given property and 111 """Generate the declaration of a C++ enum for the given property and
92 values. 112 values.
93 """ 113 """
94 c = code.Code() 114 c = code.Code()
95 c.Sblock('enum %s {' % enum_name) 115 c.Sblock('enum %s {' % enum_name)
96 if prop.optional: 116 if prop.optional:
97 c.Append(self._cpp_type_generator.GetEnumNoneValue(prop) + ',') 117 c.Append(self._cpp_type_generator.GetEnumNoneValue(prop) + ',')
98 for value in values: 118 for value in values:
99 c.Append(self._cpp_type_generator.GetEnumValue(prop, value) + ',') 119 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) 277 c.Comment(param.description)
258 if param.type_ == PropertyType.ANY: 278 if param.type_ == PropertyType.ANY:
259 c.Comment("Value* Result::Create(Value*) not generated " 279 c.Comment("Value* Result::Create(Value*) not generated "
260 "because it's redundant.") 280 "because it's redundant.")
261 continue 281 continue
262 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( 282 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration(
263 param, self._cpp_type_generator.GetType(param))) 283 param, self._cpp_type_generator.GetType(param)))
264 c.Eblock('};') 284 c.Eblock('};')
265 285
266 return c 286 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