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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if type_.description: | 182 if type_.description: |
183 c.Comment(type_.description) | 183 c.Comment(type_.description) |
184 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') | 184 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') |
185 c.Substitute({'classname': classname, 'item_type': | 185 c.Substitute({'classname': classname, 'item_type': |
186 self._cpp_type_generator.GetCompiledType(type_.item_type, | 186 self._cpp_type_generator.GetCompiledType(type_.item_type, |
187 wrap_optional=True)}) | 187 wrap_optional=True)}) |
188 elif type_.type_ == PropertyType.STRING: | 188 elif type_.type_ == PropertyType.STRING: |
189 if type_.description: | 189 if type_.description: |
190 c.Comment(type_.description) | 190 c.Comment(type_.description) |
191 c.Append('typedef std::string %(classname)s;') | 191 c.Append('typedef std::string %(classname)s;') |
| 192 elif type_.type_ == PropertyType.ENUM: |
| 193 if type_.description: |
| 194 c.Comment(type_.description) |
| 195 c.Sblock('enum %(classname)s {') |
| 196 for value in type_.enum_values: |
| 197 c.Append('%s_%s,' % (classname.upper(), value.upper())) |
| 198 (c.Eblock('};') |
| 199 .Append() |
| 200 .Append('scoped_ptr<base::Value> CreateEnumValue(%s %s);' % |
| 201 (classname, classname.lower())) |
| 202 ) |
192 else: | 203 else: |
193 if type_.description: | 204 if type_.description: |
194 c.Comment(type_.description) | 205 c.Comment(type_.description) |
195 (c.Sblock('struct %(classname)s {') | 206 (c.Sblock('struct %(classname)s {') |
196 .Append('~%(classname)s();') | 207 .Append('~%(classname)s();') |
197 .Append('%(classname)s();') | 208 .Append('%(classname)s();') |
198 .Append() | 209 .Append() |
199 .Concat(self._GeneratePropertyStructures(type_.properties.values())) | 210 .Concat(self._GeneratePropertyStructures(type_.properties.values())) |
200 .Concat(self._GenerateFields(type_.properties.values())) | 211 .Concat(self._GenerateFields(type_.properties.values())) |
201 ) | 212 ) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 359 |
349 def _GenerateFunctionResults(self, callback): | 360 def _GenerateFunctionResults(self, callback): |
350 """Generates namespace for passing a function's result back. | 361 """Generates namespace for passing a function's result back. |
351 """ | 362 """ |
352 c = Code() | 363 c = Code() |
353 (c.Sblock('namespace Results {') | 364 (c.Sblock('namespace Results {') |
354 .Concat(self._GenerateCreateCallbackArguments(callback)) | 365 .Concat(self._GenerateCreateCallbackArguments(callback)) |
355 .Eblock('};') | 366 .Eblock('};') |
356 ) | 367 ) |
357 return c | 368 return c |
OLD | NEW |