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

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

Issue 143473003: Generate ax enums from idl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove trailing commas. Created 6 years, 11 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 135
136 for type_ in self._namespace.types.values(): 136 for type_ in self._namespace.types.values():
137 ExpandType([], type_) 137 ExpandType([], type_)
138 return dependency_order 138 return dependency_order
139 139
140 def _GenerateEnumDeclaration(self, enum_name, type_): 140 def _GenerateEnumDeclaration(self, enum_name, type_):
141 """Generate the declaration of a C++ enum. 141 """Generate the declaration of a C++ enum.
142 """ 142 """
143 c = Code() 143 c = Code()
144 c.Sblock('enum %s {' % enum_name) 144 c.Sblock('enum %s {' % enum_name)
145 c.Append(self._type_helper.GetEnumNoneValue(type_) + ',')
146 for value in type_.enum_values: 145 for value in type_.enum_values:
147 c.Append(self._type_helper.GetEnumValue(type_, value) + ',') 146 c.Append(self._type_helper.GetEnumValue(type_, value) + ',')
147 c.Append(self._type_helper.GetEnumNoneValue(type_))
148 return c.Eblock('};') 148 return c.Eblock('};')
149 149
150 def _GenerateFields(self, props): 150 def _GenerateFields(self, props):
151 """Generates the field declarations when declaring a type. 151 """Generates the field declarations when declaring a type.
152 """ 152 """
153 c = Code() 153 c = Code()
154 needs_blank_line = False 154 needs_blank_line = False
155 for prop in props: 155 for prop in props:
156 if needs_blank_line: 156 if needs_blank_line:
157 c.Append() 157 c.Append()
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 ) 199 )
200 elif type_.property_type == PropertyType.STRING: 200 elif type_.property_type == PropertyType.STRING:
201 if generate_typedefs: 201 if generate_typedefs:
202 if type_.description: 202 if type_.description:
203 c.Comment(type_.description) 203 c.Comment(type_.description)
204 c.Append('typedef std::string %(classname)s;') 204 c.Append('typedef std::string %(classname)s;')
205 elif type_.property_type == PropertyType.ENUM: 205 elif type_.property_type == PropertyType.ENUM:
206 if type_.description: 206 if type_.description:
207 c.Comment(type_.description) 207 c.Comment(type_.description)
208 c.Sblock('enum %(classname)s {') 208 c.Sblock('enum %(classname)s {')
209 c.Append('%s,' % self._type_helper.GetEnumNoneValue(type_))
210 for value in type_.enum_values: 209 for value in type_.enum_values:
211 c.Append('%s,' % self._type_helper.GetEnumValue(type_, value)) 210 c.Append('%s,' % self._type_helper.GetEnumValue(type_, value))
211 # Add any non-explicit enum values last.
212 c.Append('%s,' % self._type_helper.GetEnumNoneValue(type_))
not at google - send to devlin 2014/01/23 00:04:40 Explain this a bit more (why you need it last). I
David Tseng 2014/01/23 00:31:43 This is mostly paranoia on my part because of the
212 # Top level enums are in a namespace scope so the methods shouldn't be 213 # Top level enums are in a namespace scope so the methods shouldn't be
213 # static. On the other hand, those declared inline (e.g. in an object) do. 214 # static. On the other hand, those declared inline (e.g. in an object) do.
214 maybe_static = '' if is_toplevel else 'static ' 215 maybe_static = '' if is_toplevel else 'static '
215 (c.Eblock('};') 216 (c.Eblock('};')
216 .Append() 217 .Append()
217 .Append('%sstd::string ToString(%s as_enum);' % 218 .Append('%sstd::string ToString(%s as_enum);' %
218 (maybe_static, classname)) 219 (maybe_static, classname))
219 .Append('%s%s Parse%s(const std::string& as_string);' % 220 .Append('%s%s Parse%s(const std::string& as_string);' %
220 (maybe_static, classname, classname)) 221 (maybe_static, classname, classname))
221 ) 222 )
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 .Append('} // namespace Results') 389 .Append('} // namespace Results')
389 ) 390 )
390 return c 391 return c
391 392
392 def _GenerateParams(self, params): 393 def _GenerateParams(self, params):
393 """Builds the parameter list for a function, given an array of parameters. 394 """Builds the parameter list for a function, given an array of parameters.
394 """ 395 """
395 if self._generate_error_messages: 396 if self._generate_error_messages:
396 params += ('base::string16* error = NULL',) 397 params += ('base::string16* error = NULL',)
397 return ', '.join(str(p) for p in params) 398 return ', '.join(str(p) for p in params)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698