Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: tools/json_schema_compiler/cc_generator.py

Issue 22885002: c/b/extensions, json_schema_compiler: Do not use Value::Create*. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed C-style casts. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/menu_manager_unittest.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager_unittest.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698