| 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 model import PropertyType | 5 from model import PropertyType |
| 6 import code | 6 import code |
| 7 import cpp_util | 7 import cpp_util |
| 8 import os | 8 import os |
| 9 | 9 |
| 10 class HGenerator(object): | 10 class HGenerator(object): |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 self._cpp_type_generator.GetType(prop, wrap_optional=True), | 90 self._cpp_type_generator.GetType(prop, wrap_optional=True), |
| 91 prop.unix_name)) | 91 prop.unix_name)) |
| 92 c.Append() | 92 c.Append() |
| 93 # Generate the enums needed for any fields with "choices" | 93 # Generate the enums needed for any fields with "choices" |
| 94 for prop in props: | 94 for prop in props: |
| 95 if prop.type_ == PropertyType.CHOICES: | 95 if prop.type_ == PropertyType.CHOICES: |
| 96 c.Sblock('enum %(enum_type)s {') | 96 c.Sblock('enum %(enum_type)s {') |
| 97 c.Append(self._cpp_type_generator.GetChoiceEnumNoneValue(prop) + ',') | 97 c.Append(self._cpp_type_generator.GetChoiceEnumNoneValue(prop) + ',') |
| 98 for choice in prop.choices.values(): | 98 for choice in prop.choices.values(): |
| 99 c.Append( | 99 c.Append( |
| 100 self._cpp_type_generator.GetChoiceEnumValue( prop, choice.type_) | 100 self._cpp_type_generator.GetChoiceEnumValue(prop, choice.type_) |
| 101 + ',') | 101 + ',') |
| 102 (c.Eblock('};') | 102 (c.Eblock('};') |
| 103 .Append() | 103 .Append() |
| 104 .Append('%(enum_type)s %(name)s_type;') | 104 .Append('%(enum_type)s %(name)s_type;') |
| 105 ) | 105 ) |
| 106 c.Substitute({ | 106 c.Substitute({ |
| 107 'enum_type': self._cpp_type_generator.GetChoicesEnumType(prop), | 107 'enum_type': self._cpp_type_generator.GetChoicesEnumType(prop), |
| 108 'name': prop.unix_name | 108 'name': prop.unix_name |
| 109 }) | 109 }) |
| 110 return c | 110 return c |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if not params: | 189 if not params: |
| 190 c.Append('Value* Create();') | 190 c.Append('Value* Create();') |
| 191 else: | 191 else: |
| 192 # If there is a single parameter, this is straightforward. However, if | 192 # If there is a single parameter, this is straightforward. However, if |
| 193 # the callback parameter is of 'choices', this generates a Create method | 193 # the callback parameter is of 'choices', this generates a Create method |
| 194 # for each choice. This works because only 1 choice can be returned at a | 194 # for each choice. This works because only 1 choice can be returned at a |
| 195 # time. | 195 # time. |
| 196 for param in self._cpp_type_generator.GetExpandedChoicesInParams(params): | 196 for param in self._cpp_type_generator.GetExpandedChoicesInParams(params): |
| 197 if param.description: | 197 if param.description: |
| 198 c.Comment(param.description) | 198 c.Comment(param.description) |
| 199 c.Append('Value* Create(%s);' % | 199 if param.type_ == PropertyType.OBJECT: |
| 200 cpp_util.GetConstParameterDeclaration( | 200 raise NotImplementedError('OBJECT return type not supported') |
| 201 param, self._cpp_type_generator)) | 201 c.Append('Value* Create(%s);' % cpp_util.GetParameterDeclaration( |
| 202 param, self._cpp_type_generator.GetType(param))) |
| 202 c.Eblock('};') | 203 c.Eblock('};') |
| 203 | 204 |
| 204 return c | 205 return c |
| 205 | 206 |
| 206 def _GenerateIfndefName(self): | 207 def _GenerateIfndefName(self): |
| 207 """Formats a path and filename as a #define name. | 208 """Formats a path and filename as a #define name. |
| 208 | 209 |
| 209 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. | 210 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. |
| 210 """ | 211 """ |
| 211 return (('%s_%s_H__' % | 212 return (('%s_%s_H__' % |
| 212 (self._namespace.source_file_dir, self._target_namespace)) | 213 (self._namespace.source_file_dir, self._target_namespace)) |
| 213 .upper().replace(os.sep, '_')) | 214 .upper().replace(os.sep, '_')) |
| 214 | 215 |
| OLD | NEW |