Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_) + ',') | 145 c.Append(self._type_helper.GetEnumNoneValue(type_) + ',') |
| 146 for value in type_.enum_values: | 146 for value in type_.enum_values: |
| 147 c.Append(self._type_helper.GetEnumValue(type_, value) + ',') | 147 c.Append(self._type_helper.GetEnumValue(type_, value['name']) + ',') |
|
not at google - send to devlin
2013/10/28 18:00:25
maybe GetEnumValue should take the enum not enum['
Sam McNally
2013/10/29 00:39:02
Done.
| |
| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_)) | 209 c.Append('%s,' % self._type_helper.GetEnumNoneValue(type_)) |
| 210 for value in type_.enum_values: | 210 for value in type_.enum_values: |
| 211 c.Append('%s,' % self._type_helper.GetEnumValue(type_, value)) | 211 c.Append('%s,' % self._type_helper.GetEnumValue(type_, value['name'])) |
| 212 # Top level enums are in a namespace scope so the methods shouldn't be | 212 # 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. | 213 # static. On the other hand, those declared inline (e.g. in an object) do. |
| 214 maybe_static = '' if is_toplevel else 'static ' | 214 maybe_static = '' if is_toplevel else 'static ' |
| 215 (c.Eblock('};') | 215 (c.Eblock('};') |
| 216 .Append() | 216 .Append() |
| 217 .Append('%sstd::string ToString(%s as_enum);' % | 217 .Append('%sstd::string ToString(%s as_enum);' % |
| 218 (maybe_static, classname)) | 218 (maybe_static, classname)) |
| 219 .Append('%s%s Parse%s(const std::string& as_string);' % | 219 .Append('%s%s Parse%s(const std::string& as_string);' % |
| 220 (maybe_static, classname, classname)) | 220 (maybe_static, classname, classname)) |
| 221 ) | 221 ) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 .Append('} // namespace Results') | 388 .Append('} // namespace Results') |
| 389 ) | 389 ) |
| 390 return c | 390 return c |
| 391 | 391 |
| 392 def _GenerateParams(self, params): | 392 def _GenerateParams(self, params): |
| 393 """Builds the parameter list for a function, given an array of parameters. | 393 """Builds the parameter list for a function, given an array of parameters. |
| 394 """ | 394 """ |
| 395 if self._generate_error_messages: | 395 if self._generate_error_messages: |
| 396 params += ('base::string16* error = NULL',) | 396 params += ('base::string16* error = NULL',) |
| 397 return ', '.join(str(p) for p in params) | 397 return ', '.join(str(p) for p in params) |
| OLD | NEW |