| 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 model | 8 import model |
| 9 import os | 9 import os |
| 10 | 10 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 c.Append() | 153 c.Append() |
| 154 return c | 154 return c |
| 155 | 155 |
| 156 def _GenerateType(self, type_): | 156 def _GenerateType(self, type_): |
| 157 """Generates a struct for a type. | 157 """Generates a struct for a type. |
| 158 """ | 158 """ |
| 159 classname = cpp_util.Classname(type_.name) | 159 classname = cpp_util.Classname(type_.name) |
| 160 c = Code() | 160 c = Code() |
| 161 | 161 |
| 162 if type_.functions: | 162 if type_.functions: |
| 163 # Types with functions are not instantiable in C++ because they are | |
| 164 # handled in pure Javascript and hence have no properties or | |
| 165 # additionalProperties. | |
| 166 if type_.properties: | |
| 167 raise NotImplementedError('\n'.join(model.GetModelHierarchy(type_)) + | |
| 168 '\nCannot generate both functions and properties on a type') | |
| 169 c.Sblock('namespace %(classname)s {') | 163 c.Sblock('namespace %(classname)s {') |
| 170 for function in type_.functions.values(): | 164 for function in type_.functions.values(): |
| 171 (c.Concat(self._GenerateFunction(function)) | 165 (c.Concat(self._GenerateFunction(function)) |
| 172 .Append() | 166 .Append() |
| 173 ) | 167 ) |
| 174 c.Eblock('}') | 168 c.Eblock('}') |
| 175 elif type_.type_ == PropertyType.ARRAY: | 169 elif type_.type_ == PropertyType.ARRAY: |
| 176 if type_.description: | 170 if type_.description: |
| 177 c.Comment(type_.description) | 171 c.Comment(type_.description) |
| 178 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') | 172 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 c.Comment(param.description) | 295 c.Comment(param.description) |
| 302 if param.type_ == PropertyType.ANY: | 296 if param.type_ == PropertyType.ANY: |
| 303 c.Comment("Value* Result::Create(Value*) not generated " | 297 c.Comment("Value* Result::Create(Value*) not generated " |
| 304 "because it's redundant.") | 298 "because it's redundant.") |
| 305 continue | 299 continue |
| 306 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( | 300 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( |
| 307 param, self._cpp_type_generator.GetType(param))) | 301 param, self._cpp_type_generator.GetType(param))) |
| 308 c.Eblock('};') | 302 c.Eblock('};') |
| 309 | 303 |
| 310 return c | 304 return c |
| OLD | NEW |