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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 elif t == PropertyType.BOOLEAN: | 145 elif t == PropertyType.BOOLEAN: |
146 items.append('%s(false)' % prop.unix_name) | 146 items.append('%s(false)' % prop.unix_name) |
147 elif t == PropertyType.BINARY: | 147 elif t == PropertyType.BINARY: |
148 items.append('%s(NULL)' % prop.unix_name) | 148 items.append('%s(NULL)' % prop.unix_name) |
149 elif (t == PropertyType.ADDITIONAL_PROPERTIES or | 149 elif (t == PropertyType.ADDITIONAL_PROPERTIES or |
150 t == PropertyType.ANY or | 150 t == PropertyType.ANY or |
151 t == PropertyType.ARRAY or | 151 t == PropertyType.ARRAY or |
152 t == PropertyType.CHOICES or | 152 t == PropertyType.CHOICES or |
153 t == PropertyType.ENUM or | 153 t == PropertyType.ENUM or |
154 t == PropertyType.OBJECT or | 154 t == PropertyType.OBJECT or |
| 155 t == PropertyType.FUNCTION or |
155 t == PropertyType.REF or | 156 t == PropertyType.REF or |
156 t == PropertyType.STRING): | 157 t == PropertyType.STRING): |
157 # TODO(miket): It would be nice to initialize CHOICES and ENUM, but we | 158 # TODO(miket): It would be nice to initialize CHOICES and ENUM, but we |
158 # don't presently have the semantics to indicate which one of a set | 159 # don't presently have the semantics to indicate which one of a set |
159 # should be the default. | 160 # should be the default. |
160 continue | 161 continue |
161 else: | 162 else: |
162 sys.exit("Unhandled PropertyType: %s" % t) | 163 sys.exit("Unhandled PropertyType: %s" % t) |
163 | 164 |
164 if items: | 165 if items: |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return 'Get%sChoiceValue().release()' % cpp_util.Classname(prop.name) | 310 return 'Get%sChoiceValue().release()' % cpp_util.Classname(prop.name) |
310 elif self._IsObjectOrObjectRef(prop): | 311 elif self._IsObjectOrObjectRef(prop): |
311 if prop.optional: | 312 if prop.optional: |
312 return '%s->ToValue().release()' % var | 313 return '%s->ToValue().release()' % var |
313 else: | 314 else: |
314 return '%s.ToValue().release()' % var | 315 return '%s.ToValue().release()' % var |
315 elif prop.type_ == PropertyType.ANY: | 316 elif prop.type_ == PropertyType.ANY: |
316 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var) | 317 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var) |
317 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES: | 318 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES: |
318 return '%s.DeepCopy()' % var | 319 return '%s.DeepCopy()' % var |
| 320 elif prop.type_ == PropertyType.FUNCTION: |
| 321 if prop.optional: |
| 322 vardot = var + '->' |
| 323 else: |
| 324 vardot = var + '.' |
| 325 return '%sDeepCopy()' % vardot |
319 elif prop.type_ == PropertyType.ENUM: | 326 elif prop.type_ == PropertyType.ENUM: |
320 return 'CreateEnumValue(%s).release()' % var | 327 return 'CreateEnumValue(%s).release()' % var |
321 elif prop.type_ == PropertyType.BINARY: | 328 elif prop.type_ == PropertyType.BINARY: |
322 if prop.optional: | 329 if prop.optional: |
323 vardot = var + '->' | 330 vardot = var + '->' |
324 else: | 331 else: |
325 vardot = var + '.' | 332 vardot = var + '.' |
326 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % | 333 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % |
327 (vardot, vardot)) | 334 (vardot, vardot)) |
328 elif self._IsArrayOrArrayRef(prop): | 335 elif self._IsArrayOrArrayRef(prop): |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 .Append('%(dst)s->%(name)s = temp.Pass();') | 469 .Append('%(dst)s->%(name)s = temp.Pass();') |
463 ) | 470 ) |
464 else: | 471 else: |
465 (c.Append('base::DictionaryValue* dictionary = NULL;') | 472 (c.Append('base::DictionaryValue* dictionary = NULL;') |
466 .Append('if (!%(value_var)s->GetAsDictionary(&dictionary))') | 473 .Append('if (!%(value_var)s->GetAsDictionary(&dictionary))') |
467 .Append(' return %(failure_value)s;') | 474 .Append(' return %(failure_value)s;') |
468 .Append( | 475 .Append( |
469 'if (!%(ctype)s::Populate(*dictionary, &%(dst)s->%(name)s))') | 476 'if (!%(ctype)s::Populate(*dictionary, &%(dst)s->%(name)s))') |
470 .Append(' return %(failure_value)s;') | 477 .Append(' return %(failure_value)s;') |
471 ) | 478 ) |
| 479 elif prop.type_ == PropertyType.FUNCTION: |
| 480 if prop.optional: |
| 481 c.Append('%(dst)s->%(name)s.reset(new base::DictionaryValue());') |
472 elif prop.type_ == PropertyType.ANY: | 482 elif prop.type_ == PropertyType.ANY: |
473 if prop.optional: | 483 if prop.optional: |
474 c.Append('%(dst)s->%(name)s.reset(new ' + any_helper.ANY_CLASS + '());') | 484 c.Append('%(dst)s->%(name)s.reset(new ' + any_helper.ANY_CLASS + '());') |
475 c.Append(self._any_helper.Init(prop, value_var, dst) + ';') | 485 c.Append(self._any_helper.Init(prop, value_var, dst) + ';') |
476 elif self._IsArrayOrArrayRef(prop): | 486 elif self._IsArrayOrArrayRef(prop): |
477 # util_cc_helper deals with optional and required arrays | 487 # util_cc_helper deals with optional and required arrays |
478 (c.Append('base::ListValue* list = NULL;') | 488 (c.Append('base::ListValue* list = NULL;') |
479 .Append('if (!%(value_var)s->GetAsList(&list))') | 489 .Append('if (!%(value_var)s->GetAsList(&list))') |
480 .Append(' return %(failure_value)s;')) | 490 .Append(' return %(failure_value)s;')) |
481 if prop.item_type.type_ == PropertyType.ENUM: | 491 if prop.item_type.type_ == PropertyType.ENUM: |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 """ | 761 """ |
752 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == | 762 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == |
753 PropertyType.ARRAY) | 763 PropertyType.ARRAY) |
754 | 764 |
755 def _IsFundamentalOrFundamentalRef(self, prop): | 765 def _IsFundamentalOrFundamentalRef(self, prop): |
756 """Determines if this property is a Fundamental type or is a ref to a | 766 """Determines if this property is a Fundamental type or is a ref to a |
757 Fundamental type. | 767 Fundamental type. |
758 """ | 768 """ |
759 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. | 769 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. |
760 is_fundamental) | 770 is_fundamental) |
OLD | NEW |