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

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

Issue 1471043004: Convert various vector_as_array calls to vector::data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « remoting/host/touch_injector_win.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 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 25 matching lines...) Expand all
36 self._namespace.environment.namespace_pattern, 36 self._namespace.environment.namespace_pattern,
37 self._namespace.unix_name) 37 self._namespace.unix_name)
38 38
39 c = Code() 39 c = Code()
40 (c.Append(cpp_util.CHROMIUM_LICENSE) 40 (c.Append(cpp_util.CHROMIUM_LICENSE)
41 .Append() 41 .Append()
42 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file) 42 .Append(cpp_util.GENERATED_FILE_MESSAGE % self._namespace.source_file)
43 .Append() 43 .Append()
44 .Append(self._util_cc_helper.GetIncludePath()) 44 .Append(self._util_cc_helper.GetIncludePath())
45 .Append('#include "base/logging.h"') 45 .Append('#include "base/logging.h"')
46 .Append('#include "base/stl_util.h"')
47 .Append('#include "base/strings/string_number_conversions.h"') 46 .Append('#include "base/strings/string_number_conversions.h"')
48 .Append('#include "base/strings/utf_string_conversions.h"') 47 .Append('#include "base/strings/utf_string_conversions.h"')
49 .Append('#include "%s/%s.h"' % 48 .Append('#include "%s/%s.h"' %
50 (self._namespace.source_file_dir, self._namespace.short_filename)) 49 (self._namespace.source_file_dir, self._namespace.short_filename))
51 .Append('#include <set>') 50 .Append('#include <set>')
52 .Cblock(self._type_helper.GenerateIncludes(include_soft=True)) 51 .Cblock(self._type_helper.GenerateIncludes(include_soft=True))
53 .Append() 52 .Append()
54 .Append('using base::UTF8ToUTF16;') 53 .Append('using base::UTF8ToUTF16;')
55 .Append() 54 .Append()
56 .Concat(cpp_util.OpenNamespace(cpp_namespace)) 55 .Concat(cpp_util.OpenNamespace(cpp_namespace))
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 vardot = '(%s).' % var 549 vardot = '(%s).' % var
551 return '%sDeepCopy()' % vardot 550 return '%sDeepCopy()' % vardot
552 elif underlying_type.property_type == PropertyType.ENUM: 551 elif underlying_type.property_type == PropertyType.ENUM:
553 maybe_namespace = '' 552 maybe_namespace = ''
554 if type_.property_type == PropertyType.REF: 553 if type_.property_type == PropertyType.REF:
555 maybe_namespace = '%s::' % underlying_type.namespace.unix_name 554 maybe_namespace = '%s::' % underlying_type.namespace.unix_name
556 return 'new base::StringValue(%sToString(%s))' % (maybe_namespace, var) 555 return 'new base::StringValue(%sToString(%s))' % (maybe_namespace, var)
557 elif underlying_type.property_type == PropertyType.BINARY: 556 elif underlying_type.property_type == PropertyType.BINARY:
558 if is_ptr: 557 if is_ptr:
559 vardot = var + '->' 558 vardot = var + '->'
560 ref = var + '.get()'
561 else: 559 else:
562 vardot = var + '.' 560 vardot = var + '.'
563 ref = '&' + var 561 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(),'
564 return ('base::BinaryValue::CreateWithCopiedBuffer(vector_as_array(%s),' 562 ' %ssize())' % (vardot, vardot))
565 ' %ssize())' % (ref, vardot))
566 elif underlying_type.property_type == PropertyType.ARRAY: 563 elif underlying_type.property_type == PropertyType.ARRAY:
567 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( 564 return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
568 var, 565 var,
569 is_ptr) 566 is_ptr)
570 elif underlying_type.property_type.is_fundamental: 567 elif underlying_type.property_type.is_fundamental:
571 if is_ptr: 568 if is_ptr:
572 var = '*%s' % var 569 var = '*%s' % var
573 if underlying_type.property_type == PropertyType.STRING: 570 if underlying_type.property_type == PropertyType.STRING:
574 return 'new base::StringValue(%s)' % var 571 return 'new base::StringValue(%s)' % var
575 else: 572 else:
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 if self._generate_error_messages: 1070 if self._generate_error_messages:
1074 params = list(params) + ['base::string16* error'] 1071 params = list(params) + ['base::string16* error']
1075 return ', '.join(str(p) for p in params) 1072 return ', '.join(str(p) for p in params)
1076 1073
1077 def _GenerateArgs(self, args): 1074 def _GenerateArgs(self, args):
1078 """Builds the argument list for a function, given an array of arguments. 1075 """Builds the argument list for a function, given an array of arguments.
1079 """ 1076 """
1080 if self._generate_error_messages: 1077 if self._generate_error_messages:
1081 args = list(args) + ['error'] 1078 args = list(args) + ['error']
1082 return ', '.join(str(a) for a in args) 1079 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « remoting/host/touch_injector_win.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698