| 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 import util_cc_helper | 9 import util_cc_helper |
| 10 from cpp_namespace_environment import CppNamespaceEnvironment | 10 from cpp_namespace_environment import CppNamespaceEnvironment |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if type_.property_type == PropertyType.OBJECT: | 120 if type_.property_type == PropertyType.OBJECT: |
| 121 c.Cblock(self._GeneratePropertyFunctions(classname_in_namespace, | 121 c.Cblock(self._GeneratePropertyFunctions(classname_in_namespace, |
| 122 type_.properties.values())) | 122 type_.properties.values())) |
| 123 else: | 123 else: |
| 124 c.Cblock(self._GenerateTypes(classname_in_namespace, type_.choices)) | 124 c.Cblock(self._GenerateTypes(classname_in_namespace, type_.choices)) |
| 125 | 125 |
| 126 (c.Append('%s::%s()' % (classname_in_namespace, classname)) | 126 (c.Append('%s::%s()' % (classname_in_namespace, classname)) |
| 127 .Cblock(self._GenerateInitializersAndBody(type_)) | 127 .Cblock(self._GenerateInitializersAndBody(type_)) |
| 128 .Append('%s::~%s() {}' % (classname_in_namespace, classname)) | 128 .Append('%s::~%s() {}' % (classname_in_namespace, classname)) |
| 129 ) | 129 ) |
| 130 if 'use_movable_types' in type_.namespace.compiler_options: | 130 # Note: we use 'rhs' because some API objects have a member 'other'. |
| 131 # Note: we use 'rhs' because some API objects have a member 'other'. | 131 (c.Append('%s::%s(%s&& rhs)' % |
| 132 (c.Append('%s::%s(%s&& rhs)' % | 132 (classname_in_namespace, classname, classname)) |
| 133 (classname_in_namespace, classname, classname)) | 133 .Cblock(self._GenerateMoveCtor(type_)) |
| 134 .Cblock(self._GenerateMoveCtor(type_)) | 134 .Append('%s& %s::operator=(%s&& rhs)' % |
| 135 .Append('%s& %s::operator=(%s&& rhs)' % | 135 (classname_in_namespace, classname_in_namespace, |
| 136 (classname_in_namespace, classname_in_namespace, | 136 classname)) |
| 137 classname)) | 137 .Cblock(self._GenerateMoveAssignOperator(type_)) |
| 138 .Cblock(self._GenerateMoveAssignOperator(type_)) | 138 ) |
| 139 ) | |
| 140 if type_.origin.from_json: | 139 if type_.origin.from_json: |
| 141 c.Cblock(self._GenerateTypePopulate(classname_in_namespace, type_)) | 140 c.Cblock(self._GenerateTypePopulate(classname_in_namespace, type_)) |
| 142 if cpp_namespace is None: # only generate for top-level types | 141 if cpp_namespace is None: # only generate for top-level types |
| 143 c.Cblock(self._GenerateTypeFromValue(classname_in_namespace, type_)) | 142 c.Cblock(self._GenerateTypeFromValue(classname_in_namespace, type_)) |
| 144 if type_.origin.from_client: | 143 if type_.origin.from_client: |
| 145 c.Cblock(self._GenerateTypeToValue(classname_in_namespace, type_)) | 144 c.Cblock(self._GenerateTypeToValue(classname_in_namespace, type_)) |
| 146 elif type_.property_type == PropertyType.ENUM: | 145 elif type_.property_type == PropertyType.ENUM: |
| 147 (c.Cblock(self._GenerateEnumToString(cpp_namespace, type_)) | 146 (c.Cblock(self._GenerateEnumToString(cpp_namespace, type_)) |
| 148 .Cblock(self._GenerateEnumFromString(cpp_namespace, type_)) | 147 .Cblock(self._GenerateEnumFromString(cpp_namespace, type_)) |
| 149 ) | 148 ) |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 prop_var, | 475 prop_var, |
| 477 is_ptr=is_ptr)) | 476 is_ptr=is_ptr)) |
| 478 | 477 |
| 479 if prop.optional: | 478 if prop.optional: |
| 480 c.Eblock('}') | 479 c.Eblock('}') |
| 481 | 480 |
| 482 if type_.additional_properties is not None: | 481 if type_.additional_properties is not None: |
| 483 if type_.additional_properties.property_type == PropertyType.ANY: | 482 if type_.additional_properties.property_type == PropertyType.ANY: |
| 484 c.Append('value->MergeDictionary(&additional_properties);') | 483 c.Append('value->MergeDictionary(&additional_properties);') |
| 485 else: | 484 else: |
| 486 # Non-copyable types will be wrapped in a linked_ptr for inclusion in | |
| 487 # maps, so we need to unwrap them. | |
| 488 needs_unwrap = ( | |
| 489 not 'use_movable_types' in type_.namespace.compiler_options and | |
| 490 not self._type_helper.IsCopyable(type_.additional_properties)) | |
| 491 (c.Sblock('for (const auto& it : additional_properties) {') | 485 (c.Sblock('for (const auto& it : additional_properties) {') |
| 492 .Cblock(self._CreateValueFromType( | 486 .Cblock(self._CreateValueFromType( |
| 493 'value->SetWithoutPathExpansion(it.first, %s);', | 487 'value->SetWithoutPathExpansion(it.first, %s);', |
| 494 type_.additional_properties.name, | 488 type_.additional_properties.name, |
| 495 type_.additional_properties, | 489 type_.additional_properties, |
| 496 '%sit.second' % ('*' if needs_unwrap else ''))) | 490 'it.second')) |
| 497 .Eblock('}') | 491 .Eblock('}') |
| 498 ) | 492 ) |
| 499 | 493 |
| 500 return (c.Append() | 494 return (c.Append() |
| 501 .Append('return value;') | 495 .Append('return value;') |
| 502 .Eblock('}')) | 496 .Eblock('}')) |
| 503 | 497 |
| 504 def _GenerateChoiceTypeToValue(self, cpp_namespace, type_): | 498 def _GenerateChoiceTypeToValue(self, cpp_namespace, type_): |
| 505 """Generates a function that serializes a choice-representing type | 499 """Generates a function that serializes a choice-representing type |
| 506 into a base::Value. | 500 into a base::Value. |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 if self._generate_error_messages: | 1155 if self._generate_error_messages: |
| 1162 params = list(params) + ['base::string16* error'] | 1156 params = list(params) + ['base::string16* error'] |
| 1163 return ', '.join(str(p) for p in params) | 1157 return ', '.join(str(p) for p in params) |
| 1164 | 1158 |
| 1165 def _GenerateArgs(self, args): | 1159 def _GenerateArgs(self, args): |
| 1166 """Builds the argument list for a function, given an array of arguments. | 1160 """Builds the argument list for a function, given an array of arguments. |
| 1167 """ | 1161 """ |
| 1168 if self._generate_error_messages: | 1162 if self._generate_error_messages: |
| 1169 args = list(args) + ['error'] | 1163 args = list(args) + ['error'] |
| 1170 return ', '.join(str(a) for a in args) | 1164 return ', '.join(str(a) for a in args) |
| OLD | NEW |