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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 .Eblock('};') | 222 .Eblock('};') |
223 ) | 223 ) |
224 c.Substitute({'classname': classname}) | 224 c.Substitute({'classname': classname}) |
225 return c | 225 return c |
226 | 226 |
227 def _GenerateEvent(self, event): | 227 def _GenerateEvent(self, event): |
228 """Generates the namespaces for an event. | 228 """Generates the namespaces for an event. |
229 """ | 229 """ |
230 c = Code() | 230 c = Code() |
231 (c.Sblock('namespace %s {' % cpp_util.Classname(event.name)) | 231 (c.Sblock('namespace %s {' % cpp_util.Classname(event.name)) |
232 .Concat(self._GenerateCreateCallbackArguments(event)) | 232 .Concat(self._GenerateCreateCallbackArguments(event, |
233 generate_to_json=True)) | |
233 .Eblock('};') | 234 .Eblock('};') |
234 ) | 235 ) |
235 return c | 236 return c |
236 | 237 |
237 def _GenerateFunction(self, function): | 238 def _GenerateFunction(self, function): |
238 """Generates the namespaces and structs for a function. | 239 """Generates the namespaces and structs for a function. |
239 """ | 240 """ |
240 c = Code() | 241 c = Code() |
241 (c.Sblock('namespace %s {' % cpp_util.Classname(function.name)) | 242 (c.Sblock('namespace %s {' % cpp_util.Classname(function.name)) |
242 .Concat(self._GenerateFunctionParams(function)) | 243 .Concat(self._GenerateFunctionParams(function)) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 if prop.type_ == PropertyType.ARRAY: | 317 if prop.type_ == PropertyType.ARRAY: |
317 c.Concat(self._GeneratePrivatePropertyStructures([prop.item_type])) | 318 c.Concat(self._GeneratePrivatePropertyStructures([prop.item_type])) |
318 c.Append() | 319 c.Append() |
319 elif prop.type_ == PropertyType.CHOICES: | 320 elif prop.type_ == PropertyType.CHOICES: |
320 # We only need GetChoiceValue() if there is a ToValue() method. | 321 # We only need GetChoiceValue() if there is a ToValue() method. |
321 if prop.from_client: | 322 if prop.from_client: |
322 c.Append('scoped_ptr<base::Value> Get%sChoiceValue() const;' % ( | 323 c.Append('scoped_ptr<base::Value> Get%sChoiceValue() const;' % ( |
323 cpp_util.Classname(prop.name))) | 324 cpp_util.Classname(prop.name))) |
324 return c | 325 return c |
325 | 326 |
326 def _GenerateCreateCallbackArguments(self, function): | 327 def _GenerateCreateCallbackArguments(self, function, generate_to_json=False): |
327 """Generates functions for passing paramaters to a callback. | 328 """Generates functions for passing paramaters to a callback. |
328 """ | 329 """ |
329 c = Code() | 330 c = Code() |
330 params = function.params | 331 params = function.params |
331 c.Concat(self._GeneratePropertyStructures(params)) | 332 c.Concat(self._GeneratePropertyStructures(params)) |
332 | 333 |
333 param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params) | 334 param_lists = self._cpp_type_generator.GetAllPossibleParameterLists(params) |
334 for param_list in param_lists: | 335 for param_list in param_lists: |
335 declaration_list = [] | 336 declaration_list = [] |
336 for param in param_list: | 337 for param in param_list: |
337 if param.description: | 338 if param.description: |
338 c.Comment(param.description) | 339 c.Comment(param.description) |
339 declaration_list.append('const %s' % cpp_util.GetParameterDeclaration( | 340 declaration_list.append('const %s' % cpp_util.GetParameterDeclaration( |
340 param, self._cpp_type_generator.GetType(param))) | 341 param, self._cpp_type_generator.GetType(param))) |
341 c.Append('scoped_ptr<base::ListValue> Create(%s);' % | 342 c.Append('scoped_ptr<base::ListValue> Create(%s);' % |
342 ', '.join(declaration_list)) | 343 ', '.join(declaration_list)) |
344 if is_event: | |
not at google - send to devlin
2012/07/26 02:39:58
I think this needs to be generate_to_json...
mitchellwrosen
2012/07/26 17:38:59
Oops! Done
| |
345 c.Append('std::string ToJson(%s);' % ', '.join(declaration_list)) | |
343 return c | 346 return c |
344 | 347 |
345 def _GenerateFunctionResults(self, callback): | 348 def _GenerateFunctionResults(self, callback): |
346 """Generates namespace for passing a function's result back. | 349 """Generates namespace for passing a function's result back. |
347 """ | 350 """ |
348 c = Code() | 351 c = Code() |
349 (c.Sblock('namespace Results {') | 352 (c.Sblock('namespace Results {') |
350 .Concat(self._GenerateCreateCallbackArguments(callback)) | 353 .Concat(self._GenerateCreateCallbackArguments(callback)) |
351 .Eblock('};') | 354 .Eblock('};') |
352 ) | 355 ) |
353 return c | 356 return c |
OLD | NEW |