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

Side by Side Diff: tools/json_schema_compiler/h_generator.py

Issue 10907151: Extensions Docs Server: Enum values do not show up if enum is a type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add back braces Created 8 years, 3 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
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 code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import schema_util 8 import schema_util
9 9
10 class HGenerator(object): 10 class HGenerator(object):
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 for type_ in self._namespace.types.values(): 128 for type_ in self._namespace.types.values():
129 ExpandType([], type_) 129 ExpandType([], type_)
130 return dependency_order 130 return dependency_order
131 131
132 def _GenerateEnumDeclaration(self, enum_name, prop, values): 132 def _GenerateEnumDeclaration(self, enum_name, prop, values):
133 """Generate the declaration of a C++ enum for the given property and 133 """Generate the declaration of a C++ enum for the given property and
134 values. 134 values.
135 """ 135 """
136 c = Code() 136 c = Code()
137 c.Sblock('enum %s {' % enum_name) 137 c.Sblock('enum %s {' % enum_name)
138 if prop.optional: 138 c.Append(self._cpp_type_generator.GetEnumNoneValue(prop) + ',')
139 c.Append(self._cpp_type_generator.GetEnumNoneValue(prop) + ',')
140 for value in values: 139 for value in values:
141 c.Append(self._cpp_type_generator.GetEnumValue(prop, value) + ',') 140 c.Append(self._cpp_type_generator.GetEnumValue(prop, value) + ',')
142 (c.Eblock('};') 141 (c.Eblock('};')
143 .Append() 142 .Append()
144 ) 143 )
145 return c 144 return c
146 145
147 def _GenerateFields(self, props): 146 def _GenerateFields(self, props):
148 """Generates the field declarations when declaring a type. 147 """Generates the field declarations when declaring a type.
149 """ 148 """
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 self._cpp_type_generator.GetCompiledType(type_.item_type, 185 self._cpp_type_generator.GetCompiledType(type_.item_type,
187 wrap_optional=True)}) 186 wrap_optional=True)})
188 elif type_.type_ == PropertyType.STRING: 187 elif type_.type_ == PropertyType.STRING:
189 if type_.description: 188 if type_.description:
190 c.Comment(type_.description) 189 c.Comment(type_.description)
191 c.Append('typedef std::string %(classname)s;') 190 c.Append('typedef std::string %(classname)s;')
192 elif type_.type_ == PropertyType.ENUM: 191 elif type_.type_ == PropertyType.ENUM:
193 if type_.description: 192 if type_.description:
194 c.Comment(type_.description) 193 c.Comment(type_.description)
195 c.Sblock('enum %(classname)s {') 194 c.Sblock('enum %(classname)s {')
195 c.Append('%s_NONE,' % classname.upper())
196 for value in type_.enum_values: 196 for value in type_.enum_values:
197 c.Append('%s_%s,' % (classname.upper(), value.upper())) 197 c.Append('%s_%s,' % (classname.upper(), value.upper()))
198 (c.Eblock('};') 198 (c.Eblock('};')
199 .Append() 199 .Append()
200 .Append('scoped_ptr<base::Value> CreateEnumValue(%s %s);' % 200 .Append('scoped_ptr<base::Value> CreateEnumValue(%s %s);' %
201 (classname, classname.lower())) 201 (classname, classname.lower()))
202 .Append('bool GetEnumFromString(const std::string& enum_string,'
203 ' %s* %s);' % (classname, classname.lower()))
202 ) 204 )
203 else: 205 else:
204 if type_.description: 206 if type_.description:
205 c.Comment(type_.description) 207 c.Comment(type_.description)
206 (c.Sblock('struct %(classname)s {') 208 (c.Sblock('struct %(classname)s {')
207 .Append('~%(classname)s();') 209 .Append('~%(classname)s();')
208 .Append('%(classname)s();') 210 .Append('%(classname)s();')
209 .Append() 211 .Append()
210 .Concat(self._GeneratePropertyStructures(type_.properties.values())) 212 .Concat(self._GeneratePropertyStructures(type_.properties.values()))
211 .Concat(self._GenerateFields(type_.properties.values())) 213 .Concat(self._GenerateFields(type_.properties.values()))
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 361
360 def _GenerateFunctionResults(self, callback): 362 def _GenerateFunctionResults(self, callback):
361 """Generates namespace for passing a function's result back. 363 """Generates namespace for passing a function's result back.
362 """ 364 """
363 c = Code() 365 c = Code()
364 (c.Sblock('namespace Results {') 366 (c.Sblock('namespace Results {')
365 .Concat(self._GenerateCreateCallbackArguments(callback)) 367 .Concat(self._GenerateCreateCallbackArguments(callback))
366 .Eblock('};') 368 .Eblock('};')
367 ) 369 )
368 return c 370 return c
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698