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, Type | 6 from model import PropertyType, Type |
7 import cpp_util | 7 import cpp_util |
8 import model | 8 import model |
9 import schema_util | 9 import schema_util |
10 import sys | 10 import sys |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 .Append('} // namespace %s' % event_namespace) | 428 .Append('} // namespace %s' % event_namespace) |
429 ) | 429 ) |
430 return c | 430 return c |
431 | 431 |
432 def _CreateValueFromType(self, type_, var, is_ptr=False): | 432 def _CreateValueFromType(self, type_, var, is_ptr=False): |
433 """Creates a base::Value given a type. Generated code passes ownership | 433 """Creates a base::Value given a type. Generated code passes ownership |
434 to caller. | 434 to caller. |
435 | 435 |
436 var: variable or variable* | 436 var: variable or variable* |
437 | 437 |
438 E.g for std::string, generate base::Value::CreateStringValue(var) | 438 E.g for std::string, generate new base::StringValue(var) |
439 """ | 439 """ |
440 underlying_type = self._type_helper.FollowRef(type_) | 440 underlying_type = self._type_helper.FollowRef(type_) |
441 if (underlying_type.property_type == PropertyType.CHOICES or | 441 if (underlying_type.property_type == PropertyType.CHOICES or |
442 underlying_type.property_type == PropertyType.OBJECT): | 442 underlying_type.property_type == PropertyType.OBJECT): |
443 if is_ptr: | 443 if is_ptr: |
444 return '(%s)->ToValue().release()' % var | 444 return '(%s)->ToValue().release()' % var |
445 else: | 445 else: |
446 return '(%s).ToValue().release()' % var | 446 return '(%s).ToValue().release()' % var |
447 elif (underlying_type.property_type == PropertyType.ANY or | 447 elif (underlying_type.property_type == PropertyType.ANY or |
448 underlying_type.property_type == PropertyType.FUNCTION): | 448 underlying_type.property_type == PropertyType.FUNCTION): |
449 if is_ptr: | 449 if is_ptr: |
450 vardot = '(%s)->' % var | 450 vardot = '(%s)->' % var |
451 else: | 451 else: |
452 vardot = '(%s).' % var | 452 vardot = '(%s).' % var |
453 return '%sDeepCopy()' % vardot | 453 return '%sDeepCopy()' % vardot |
454 elif underlying_type.property_type == PropertyType.ENUM: | 454 elif underlying_type.property_type == PropertyType.ENUM: |
455 return 'base::Value::CreateStringValue(ToString(%s))' % var | 455 return 'new base::StringValue(ToString(%s))' % var |
456 elif underlying_type.property_type == PropertyType.BINARY: | 456 elif underlying_type.property_type == PropertyType.BINARY: |
457 if is_ptr: | 457 if is_ptr: |
458 vardot = var + '->' | 458 vardot = var + '->' |
459 else: | 459 else: |
460 vardot = var + '.' | 460 vardot = var + '.' |
461 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % | 461 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % |
462 (vardot, vardot)) | 462 (vardot, vardot)) |
463 elif underlying_type.property_type == PropertyType.ARRAY: | 463 elif underlying_type.property_type == PropertyType.ARRAY: |
464 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( | 464 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( |
465 underlying_type, | 465 underlying_type, |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 """ | 843 """ |
844 c = Code() | 844 c = Code() |
845 underlying_type = self._type_helper.FollowRef(prop.type_) | 845 underlying_type = self._type_helper.FollowRef(prop.type_) |
846 if (underlying_type.property_type == PropertyType.ENUM and | 846 if (underlying_type.property_type == PropertyType.ENUM and |
847 prop.optional): | 847 prop.optional): |
848 c.Append('%s->%s = %s;' % ( | 848 c.Append('%s->%s = %s;' % ( |
849 dst, | 849 dst, |
850 prop.unix_name, | 850 prop.unix_name, |
851 self._type_helper.GetEnumNoneValue(prop.type_))) | 851 self._type_helper.GetEnumNoneValue(prop.type_))) |
852 return c | 852 return c |
OLD | NEW |