| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 # Add any non-explicit enum values last. |
| 148 c.Append(self._type_helper.GetEnumNoneValue(type_)) |
| 148 return c.Eblock('};') | 149 return c.Eblock('};') |
| 149 | 150 |
| 150 def _GenerateFields(self, props): | 151 def _GenerateFields(self, props): |
| 151 """Generates the field declarations when declaring a type. | 152 """Generates the field declarations when declaring a type. |
| 152 """ | 153 """ |
| 153 c = Code() | 154 c = Code() |
| 154 needs_blank_line = False | 155 needs_blank_line = False |
| 155 for prop in props: | 156 for prop in props: |
| 156 if needs_blank_line: | 157 if needs_blank_line: |
| 157 c.Append() | 158 c.Append() |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 ) | 200 ) |
| 200 elif type_.property_type == PropertyType.STRING: | 201 elif type_.property_type == PropertyType.STRING: |
| 201 if generate_typedefs: | 202 if generate_typedefs: |
| 202 if type_.description: | 203 if type_.description: |
| 203 c.Comment(type_.description) | 204 c.Comment(type_.description) |
| 204 c.Append('typedef std::string %(classname)s;') | 205 c.Append('typedef std::string %(classname)s;') |
| 205 elif type_.property_type == PropertyType.ENUM: | 206 elif type_.property_type == PropertyType.ENUM: |
| 206 if type_.description: | 207 if type_.description: |
| 207 c.Comment(type_.description) | 208 c.Comment(type_.description) |
| 208 c.Sblock('enum %(classname)s {') | 209 c.Sblock('enum %(classname)s {') |
| 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)) |
| 212 # Add any non-explicit enum values last. |
| 213 c.Append('%s,' % self._type_helper.GetEnumNoneValue(type_)) |
| 212 # Top level enums are in a namespace scope so the methods shouldn't be | 214 # 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. | 215 # static. On the other hand, those declared inline (e.g. in an object) do. |
| 214 maybe_static = '' if is_toplevel else 'static ' | 216 maybe_static = '' if is_toplevel else 'static ' |
| 215 (c.Eblock('};') | 217 (c.Eblock('};') |
| 216 .Append() | 218 .Append() |
| 217 .Append('%sstd::string ToString(%s as_enum);' % | 219 .Append('%sstd::string ToString(%s as_enum);' % |
| 218 (maybe_static, classname)) | 220 (maybe_static, classname)) |
| 219 .Append('%s%s Parse%s(const std::string& as_string);' % | 221 .Append('%s%s Parse%s(const std::string& as_string);' % |
| 220 (maybe_static, classname, classname)) | 222 (maybe_static, classname, classname)) |
| 221 ) | 223 ) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 .Append('} // namespace Results') | 390 .Append('} // namespace Results') |
| 389 ) | 391 ) |
| 390 return c | 392 return c |
| 391 | 393 |
| 392 def _GenerateParams(self, params): | 394 def _GenerateParams(self, params): |
| 393 """Builds the parameter list for a function, given an array of parameters. | 395 """Builds the parameter list for a function, given an array of parameters. |
| 394 """ | 396 """ |
| 395 if self._generate_error_messages: | 397 if self._generate_error_messages: |
| 396 params += ('base::string16* error = NULL',) | 398 params += ('base::string16* error = NULL',) |
| 397 return ', '.join(str(p) for p in params) | 399 return ', '.join(str(p) for p in params) |
| OLD | NEW |