| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 # TODO(calamity): Events | 93 # TODO(calamity): Events |
| 94 return c | 94 return c |
| 95 | 95 |
| 96 def _GenerateType(self, cpp_namespace, type_): | 96 def _GenerateType(self, cpp_namespace, type_): |
| 97 """Generates the function definitions for a type. | 97 """Generates the function definitions for a type. |
| 98 """ | 98 """ |
| 99 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) | 99 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) |
| 100 c = Code() | 100 c = Code() |
| 101 | 101 |
| 102 if type_.functions: | 102 if type_.functions: |
| 103 # Types with functions are not instantiable in C++ because they are |
| 104 # handled in pure Javascript and hence have no properties or |
| 105 # additionalProperties. |
| 106 if type_.properties: |
| 107 raise NotImplementedError('\n'.join(model.GetModelHierarchy(type_)) + |
| 108 '\nCannot generate both functions and properties on a type') |
| 103 for function in type_.functions.values(): | 109 for function in type_.functions.values(): |
| 104 (c.Concat( | 110 (c.Concat( |
| 105 self._GenerateFunction( | 111 self._GenerateFunction( |
| 106 cpp_namespace + '::' + cpp_util.Classname(function.name), | 112 cpp_namespace + '::' + cpp_util.Classname(function.name), |
| 107 function)) | 113 function)) |
| 108 .Append() | 114 .Append() |
| 109 ) | 115 ) |
| 110 elif type_.type_ == PropertyType.OBJECT: | 116 elif type_.type_ == PropertyType.OBJECT: |
| 111 (c.Concat(self._GeneratePropertyFunctions( | 117 (c.Concat(self._GeneratePropertyFunctions( |
| 112 cpp_namespace, type_.properties.values())) | 118 cpp_namespace, type_.properties.values())) |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 """ | 661 """ |
| 656 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == | 662 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == |
| 657 PropertyType.ARRAY) | 663 PropertyType.ARRAY) |
| 658 | 664 |
| 659 def _IsFundamentalOrFundamentalRef(self, prop): | 665 def _IsFundamentalOrFundamentalRef(self, prop): |
| 660 """Determines if this property is a Fundamental type or is a ref to a | 666 """Determines if this property is a Fundamental type or is a ref to a |
| 661 Fundamental type. | 667 Fundamental type. |
| 662 """ | 668 """ |
| 663 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. | 669 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. |
| 664 is_fundamental) | 670 is_fundamental) |
| OLD | NEW |