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

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

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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 | « tools/ipc_fuzzer/fuzzer/fuzzer.cc ('k') | tools/json_schema_compiler/test/any_unittest.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 6 from model import PropertyType
7 import cpp_util 7 import cpp_util
8 import schema_util 8 import schema_util
9 import util_cc_helper 9 import util_cc_helper
10 from cpp_namespace_environment import CppNamespaceEnvironment 10 from cpp_namespace_environment import CppNamespaceEnvironment
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 .Append('} // namespace %s' % event_namespace) 560 .Append('} // namespace %s' % event_namespace)
561 ) 561 )
562 return c 562 return c
563 563
564 def _CreateValueFromType(self, code, prop_name, type_, var, is_ptr=False): 564 def _CreateValueFromType(self, code, prop_name, type_, var, is_ptr=False):
565 """Creates a base::Value given a type. Generated code passes ownership 565 """Creates a base::Value given a type. Generated code passes ownership
566 to caller via std::unique_ptr. 566 to caller via std::unique_ptr.
567 567
568 var: variable or variable* 568 var: variable or variable*
569 569
570 E.g for std::string, generate new base::StringValue(var) 570 E.g for std::string, generate new base::Value(var)
571 """ 571 """
572 c = Code() 572 c = Code()
573 underlying_type = self._type_helper.FollowRef(type_) 573 underlying_type = self._type_helper.FollowRef(type_)
574 if underlying_type.property_type == PropertyType.ARRAY: 574 if underlying_type.property_type == PropertyType.ARRAY:
575 # Enums are treated specially because C++ templating thinks that they're 575 # Enums are treated specially because C++ templating thinks that they're
576 # ints, but really they're strings. So we create a vector of strings and 576 # ints, but really they're strings. So we create a vector of strings and
577 # populate it with the names of the enum in the array. The |ToString| 577 # populate it with the names of the enum in the array. The |ToString|
578 # function of the enum can be in another namespace when the enum is 578 # function of the enum can be in another namespace when the enum is
579 # referenced. Templates can not be used here because C++ templating does 579 # referenced. Templates can not be used here because C++ templating does
580 # not support passing a namespace as an argument. 580 # not support passing a namespace as an argument.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 underlying_type.property_type == PropertyType.FUNCTION): 624 underlying_type.property_type == PropertyType.FUNCTION):
625 if is_ptr: 625 if is_ptr:
626 vardot = '(%s)->' % var 626 vardot = '(%s)->' % var
627 else: 627 else:
628 vardot = '(%s).' % var 628 vardot = '(%s).' % var
629 return '%sCreateDeepCopy()' % vardot 629 return '%sCreateDeepCopy()' % vardot
630 elif underlying_type.property_type == PropertyType.ENUM: 630 elif underlying_type.property_type == PropertyType.ENUM:
631 maybe_namespace = '' 631 maybe_namespace = ''
632 if type_.property_type == PropertyType.REF: 632 if type_.property_type == PropertyType.REF:
633 maybe_namespace = '%s::' % underlying_type.namespace.unix_name 633 maybe_namespace = '%s::' % underlying_type.namespace.unix_name
634 return 'base::MakeUnique<base::StringValue>(%sToString(%s))' % ( 634 return 'base::MakeUnique<base::Value>(%sToString(%s))' % (
635 maybe_namespace, var) 635 maybe_namespace, var)
636 elif underlying_type.property_type == PropertyType.BINARY: 636 elif underlying_type.property_type == PropertyType.BINARY:
637 if is_ptr: 637 if is_ptr:
638 vardot = var + '->' 638 vardot = var + '->'
639 else: 639 else:
640 vardot = var + '.' 640 vardot = var + '.'
641 return ('base::BinaryValue::CreateWithCopiedBuffer(' 641 return ('base::BinaryValue::CreateWithCopiedBuffer('
642 '%sdata(), %ssize())' % (vardot, vardot)) 642 '%sdata(), %ssize())' % (vardot, vardot))
643 elif underlying_type.property_type == PropertyType.ARRAY: 643 elif underlying_type.property_type == PropertyType.ARRAY:
644 return '%s' % self._util_cc_helper.CreateValueFromArray( 644 return '%s' % self._util_cc_helper.CreateValueFromArray(
645 var, 645 var,
646 is_ptr) 646 is_ptr)
647 elif underlying_type.property_type.is_fundamental: 647 elif underlying_type.property_type.is_fundamental:
648 if is_ptr: 648 if is_ptr:
649 var = '*%s' % var 649 var = '*%s' % var
650 if underlying_type.property_type == PropertyType.STRING: 650 if underlying_type.property_type == PropertyType.STRING:
651 return 'base::MakeUnique<base::StringValue>(%s)' % var 651 return 'base::MakeUnique<base::Value>(%s)' % var
652 else: 652 else:
653 return 'base::MakeUnique<base::Value>(%s)' % var 653 return 'base::MakeUnique<base::Value>(%s)' % var
654 else: 654 else:
655 raise NotImplementedError('Conversion of %s to base::Value not ' 655 raise NotImplementedError('Conversion of %s to base::Value not '
656 'implemented' % repr(type_.type_)) 656 'implemented' % repr(type_.type_))
657 657
658 def _GenerateParamsCheck(self, function, var): 658 def _GenerateParamsCheck(self, function, var):
659 """Generates a check for the correct number of arguments when creating 659 """Generates a check for the correct number of arguments when creating
660 Params. 660 Params.
661 """ 661 """
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 if self._generate_error_messages: 1150 if self._generate_error_messages:
1151 params = list(params) + ['base::string16* error'] 1151 params = list(params) + ['base::string16* error']
1152 return ', '.join(str(p) for p in params) 1152 return ', '.join(str(p) for p in params)
1153 1153
1154 def _GenerateArgs(self, args): 1154 def _GenerateArgs(self, args):
1155 """Builds the argument list for a function, given an array of arguments. 1155 """Builds the argument list for a function, given an array of arguments.
1156 """ 1156 """
1157 if self._generate_error_messages: 1157 if self._generate_error_messages:
1158 args = list(args) + ['error'] 1158 args = list(args) + ['error']
1159 return ', '.join(str(a) for a in args) 1159 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « tools/ipc_fuzzer/fuzzer/fuzzer.cc ('k') | tools/json_schema_compiler/test/any_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698