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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 # Generate the enums needed for any fields with "choices" | 151 # Generate the enums needed for any fields with "choices" |
152 for prop in props: | 152 for prop in props: |
153 if prop.type_ == PropertyType.CHOICES: | 153 if prop.type_ == PropertyType.CHOICES: |
154 enum_name = self._cpp_type_generator.GetChoicesEnumType(prop) | 154 enum_name = self._cpp_type_generator.GetChoicesEnumType(prop) |
155 c.Append('%s %s_type;' % (enum_name, prop.unix_name)) | 155 c.Append('%s %s_type;' % (enum_name, prop.unix_name)) |
156 c.Append() | 156 c.Append() |
157 | 157 |
158 for prop in self._cpp_type_generator.ExpandParams(props): | 158 for prop in self._cpp_type_generator.ExpandParams(props): |
159 if prop.description: | 159 if prop.description: |
160 c.Comment(prop.description) | 160 c.Comment(prop.description) |
161 prop_name = prop.unix_name | |
Yoyo Zhou
2012/08/27 23:56:04
Is this needed?
chebert
2012/08/28 21:31:14
Done.
| |
162 wrap_optional = not self._cpp_type_generator.IsEnumOrEnumRef(prop) | |
Yoyo Zhou
2012/08/27 23:56:04
Can you document the reason for this in a comment?
chebert
2012/08/28 21:31:14
Better yet, I will just get rid of it.
On 2012/08/
| |
161 (c.Append('%s %s;' % ( | 163 (c.Append('%s %s;' % ( |
162 self._cpp_type_generator.GetCompiledType(prop, wrap_optional=True), | 164 self._cpp_type_generator.GetCompiledType(prop, |
163 prop.unix_name)) | 165 wrap_optional=wrap_optional), |
166 prop_name)) | |
164 .Append() | 167 .Append() |
165 ) | 168 ) |
166 return c | 169 return c |
167 | 170 |
168 def _GenerateType(self, type_): | 171 def _GenerateType(self, type_): |
169 """Generates a struct for a type. | 172 """Generates a struct for a type. |
170 """ | 173 """ |
171 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) | 174 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) |
172 c = Code() | 175 c = Code() |
173 | 176 |
174 if type_.functions: | 177 if type_.functions: |
175 c.Sblock('namespace %(classname)s {') | 178 c.Sblock('namespace %(classname)s {') |
176 for function in type_.functions.values(): | 179 for function in type_.functions.values(): |
177 (c.Concat(self._GenerateFunction(function)) | 180 (c.Concat(self._GenerateFunction(function)) |
178 .Append() | 181 .Append() |
179 ) | 182 ) |
180 c.Eblock('}') | 183 c.Eblock('}') |
181 elif type_.type_ == PropertyType.ARRAY: | 184 elif type_.type_ == PropertyType.ARRAY: |
182 if type_.description: | 185 if type_.description: |
183 c.Comment(type_.description) | 186 c.Comment(type_.description) |
184 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') | 187 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') |
185 c.Substitute({'classname': classname, 'item_type': | 188 c.Substitute({'classname': classname, 'item_type': |
186 self._cpp_type_generator.GetCompiledType(type_.item_type, | 189 self._cpp_type_generator.GetCompiledType(type_.item_type, |
187 wrap_optional=True)}) | 190 wrap_optional=True)}) |
188 elif type_.type_ == PropertyType.STRING: | 191 elif type_.type_ == PropertyType.STRING: |
189 if type_.description: | 192 if type_.description: |
190 c.Comment(type_.description) | 193 c.Comment(type_.description) |
191 c.Append('typedef std::string %(classname)s;') | 194 c.Append('typedef std::string %(classname)s;') |
195 elif type_.type_ == PropertyType.ENUM: | |
196 if type_.description: | |
197 c.Comment(type_.description) | |
198 c.Sblock('enum %(classname)s {') | |
199 for value in type_.enum_values: | |
200 c.Append('%s_%s,' % (classname.upper(), value.upper())) | |
201 (c.Eblock('};') | |
202 .Append() | |
203 .Append('scoped_ptr<base::Value> CreateEnumValue(%s %s);' % | |
204 (classname, classname.lower())) | |
205 ) | |
192 else: | 206 else: |
193 if type_.description: | 207 if type_.description: |
194 c.Comment(type_.description) | 208 c.Comment(type_.description) |
195 (c.Sblock('struct %(classname)s {') | 209 (c.Sblock('struct %(classname)s {') |
196 .Append('~%(classname)s();') | 210 .Append('~%(classname)s();') |
197 .Append('%(classname)s();') | 211 .Append('%(classname)s();') |
198 .Append() | 212 .Append() |
199 .Concat(self._GeneratePropertyStructures(type_.properties.values())) | 213 .Concat(self._GeneratePropertyStructures(type_.properties.values())) |
200 .Concat(self._GenerateFields(type_.properties.values())) | 214 .Concat(self._GenerateFields(type_.properties.values())) |
201 ) | 215 ) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 | 362 |
349 def _GenerateFunctionResults(self, callback): | 363 def _GenerateFunctionResults(self, callback): |
350 """Generates namespace for passing a function's result back. | 364 """Generates namespace for passing a function's result back. |
351 """ | 365 """ |
352 c = Code() | 366 c = Code() |
353 (c.Sblock('namespace Results {') | 367 (c.Sblock('namespace Results {') |
354 .Concat(self._GenerateCreateCallbackArguments(callback)) | 368 .Concat(self._GenerateCreateCallbackArguments(callback)) |
355 .Eblock('};') | 369 .Eblock('};') |
356 ) | 370 ) |
357 return c | 371 return c |
OLD | NEW |