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 any_helper | 7 import any_helper |
8 import cpp_util | 8 import cpp_util |
9 import model | 9 import model |
10 import schema_util | 10 import schema_util |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 def _GenerateReturnCase(self, case_value, return_value): | 673 def _GenerateReturnCase(self, case_value, return_value): |
674 """Generates a single return case for a switch block. | 674 """Generates a single return case for a switch block. |
675 """ | 675 """ |
676 c = Code() | 676 c = Code() |
677 (c.Append('case %s:' % case_value) | 677 (c.Append('case %s:' % case_value) |
678 .Append(' return %s;' % return_value) | 678 .Append(' return %s;' % return_value) |
679 ) | 679 ) |
680 return c | 680 return c |
681 | 681 |
682 def _GenerateCreateCallbackArguments(self, function_scope, callback): | 682 def _GenerateCreateCallbackArguments(self, function_scope, callback): |
683 """Generate all functions to create Value parameters for a callback. | 683 """Generate all functions to create Value parameters for a callback, and |
684 JSON from the Value. | |
not at google - send to devlin
2012/07/24 23:04:29
We should only generate these for events, not func
mitchellwrosen
2012/07/25 17:08:20
Done.
| |
684 | 685 |
685 E.g for function "Bar", generate Bar::Results::Create | 686 E.g for function "Bar", generate Bar::Results::Create |
686 E.g for event "Baz", generate Baz::Create | 687 E.g for event "Baz", generate Baz::Create |
687 | 688 |
688 function_scope: the function scope path, e.g. Foo::Bar for the function | 689 function_scope: the function scope path, e.g. Foo::Bar for the function |
689 Foo::Bar::Baz(). | 690 Foo::Bar::Baz(). |
690 callback: the Function object we are creating callback arguments for. | 691 callback: the Function object we are creating callback arguments for. |
691 """ | 692 """ |
692 c = Code() | 693 c = Code() |
693 params = callback.params | 694 params = callback.params |
(...skipping 13 matching lines...) Expand all Loading... | |
707 # scoped_ptr if it's optional. | 708 # scoped_ptr if it's optional. |
708 param_copy = param.Copy() | 709 param_copy = param.Copy() |
709 param_copy.optional = False | 710 param_copy.optional = False |
710 c.Append('create_results->Append(%s);' % | 711 c.Append('create_results->Append(%s);' % |
711 self._CreateValueFromProperty(param_copy, param_copy.unix_name)) | 712 self._CreateValueFromProperty(param_copy, param_copy.unix_name)) |
712 declaration_list.append("const %s" % cpp_util.GetParameterDeclaration( | 713 declaration_list.append("const %s" % cpp_util.GetParameterDeclaration( |
713 param_copy, self._cpp_type_generator.GetType(param_copy))) | 714 param_copy, self._cpp_type_generator.GetType(param_copy))) |
714 | 715 |
715 c.Append('return create_results.Pass();') | 716 c.Append('return create_results.Pass();') |
716 c.Eblock('}') | 717 c.Eblock('}') |
718 c.Append() | |
719 (c.Sblock('scoped_ptr<std::string> %(function_scope)s::' | |
not at google - send to devlin
2012/07/24 23:04:29
as I mentioned in the bug, only need to return a s
mitchellwrosen
2012/07/25 17:08:20
Done.
| |
720 'ToJson(%(declaration_list)s) {') | |
721 .Append('scoped_ptr<base::ListValue> create_results = ' | |
722 'Create(%(param_list)s);') | |
723 .Append('scoped_ptr<std::string> json(new std::string());') | |
724 .Append('base::JSONWriter::Write(create_results.get(), json.get());') | |
725 .Append('return json.Pass();') | |
726 ) | |
727 c.Eblock('}') | |
728 | |
717 c.Substitute({ | 729 c.Substitute({ |
718 'function_scope': function_scope, | 730 'function_scope': function_scope, |
719 'declaration_list': ', '.join(declaration_list) | 731 'declaration_list': ', '.join(declaration_list), |
732 'param_list': ', '.join([param.unix_name for param in param_list]) | |
720 }) | 733 }) |
721 | 734 |
722 return c | 735 return c |
723 | 736 |
724 def _InitializePropertyToDefault(self, prop, dst): | 737 def _InitializePropertyToDefault(self, prop, dst): |
725 """Initialize a model.Property to its default value inside an object. | 738 """Initialize a model.Property to its default value inside an object. |
726 | 739 |
727 E.g for optional enum "state", generate dst->state = STATE_NONE; | 740 E.g for optional enum "state", generate dst->state = STATE_NONE; |
728 | 741 |
729 dst: Type* | 742 dst: Type* |
(...skipping 21 matching lines...) Expand all Loading... | |
751 """ | 764 """ |
752 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == | 765 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == |
753 PropertyType.ARRAY) | 766 PropertyType.ARRAY) |
754 | 767 |
755 def _IsFundamentalOrFundamentalRef(self, prop): | 768 def _IsFundamentalOrFundamentalRef(self, prop): |
756 """Determines if this property is a Fundamental type or is a ref to a | 769 """Determines if this property is a Fundamental type or is a ref to a |
757 Fundamental type. | 770 Fundamental type. |
758 """ | 771 """ |
759 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. | 772 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. |
760 is_fundamental) | 773 is_fundamental) |
OLD | NEW |