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

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

Issue 260893013: JSON Schema Compiler: Following r267534, properly convert arrays of enums (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/json_schema_compiler/util.h » ('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 10
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 elif underlying_type.property_type == PropertyType.ENUM: 493 elif underlying_type.property_type == PropertyType.ENUM:
494 return 'new base::StringValue(ToString(%s))' % var 494 return 'new base::StringValue(ToString(%s))' % var
495 elif underlying_type.property_type == PropertyType.BINARY: 495 elif underlying_type.property_type == PropertyType.BINARY:
496 if is_ptr: 496 if is_ptr:
497 vardot = var + '->' 497 vardot = var + '->'
498 else: 498 else:
499 vardot = var + '.' 499 vardot = var + '.'
500 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % 500 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' %
501 (vardot, vardot)) 501 (vardot, vardot))
502 elif underlying_type.property_type == PropertyType.ARRAY: 502 elif underlying_type.property_type == PropertyType.ARRAY:
503 item_type = underlying_type.item_type
504 # Any enum will only have a namespace if it's not a ref, hence the lack
505 # of FollowRef(item_type) here and just directly comparing to ENUM.
506 enum_namespace = None
507 if item_type.property_type == PropertyType.ENUM:
508 enum_namespace = cpp_namespace
503 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( 509 return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
504 cpp_namespace,
505 underlying_type,
506 var, 510 var,
507 is_ptr) 511 optional=is_ptr,
512 is_enum=self._type_helper.FollowRef(item_type).property_type ==
513 PropertyType.ENUM,
514 enum_namespace=enum_namespace)
508 elif underlying_type.property_type.is_fundamental: 515 elif underlying_type.property_type.is_fundamental:
509 if is_ptr: 516 if is_ptr:
510 var = '*%s' % var 517 var = '*%s' % var
511 if underlying_type.property_type == PropertyType.STRING: 518 if underlying_type.property_type == PropertyType.STRING:
512 return 'new base::StringValue(%s)' % var 519 return 'new base::StringValue(%s)' % var
513 else: 520 else:
514 return 'new base::FundamentalValue(%s)' % var 521 return 'new base::FundamentalValue(%s)' % var
515 else: 522 else:
516 raise NotImplementedError('Conversion of %s to base::Value not ' 523 raise NotImplementedError('Conversion of %s to base::Value not '
517 'implemented' % repr(type_.type_)) 524 'implemented' % repr(type_.type_))
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 if self._generate_error_messages: 1012 if self._generate_error_messages:
1006 params = list(params) + ['base::string16* error'] 1013 params = list(params) + ['base::string16* error']
1007 return ', '.join(str(p) for p in params) 1014 return ', '.join(str(p) for p in params)
1008 1015
1009 def _GenerateArgs(self, args): 1016 def _GenerateArgs(self, args):
1010 """Builds the argument list for a function, given an array of arguments. 1017 """Builds the argument list for a function, given an array of arguments.
1011 """ 1018 """
1012 if self._generate_error_messages: 1019 if self._generate_error_messages:
1013 args = list(args) + ['error'] 1020 args = list(args) + ['error']
1014 return ', '.join(str(a) for a in args) 1021 return ', '.join(str(a) for a in args)
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698