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

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

Issue 10206034: JSON schema compiler can't handle strings as types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Small style change Created 8 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
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 any_helper 7 import any_helper
8 import cpp_util 8 import cpp_util
9 import model 9 import model
10 import sys 10 import sys
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 elif prop.type_ == PropertyType.ANY: 347 elif prop.type_ == PropertyType.ANY:
348 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var) 348 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var)
349 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES: 349 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES:
350 return '%s.DeepCopy()' % var 350 return '%s.DeepCopy()' % var
351 elif prop.type_ == PropertyType.ENUM: 351 elif prop.type_ == PropertyType.ENUM:
352 return 'CreateEnumValue(%s).release()' % var 352 return 'CreateEnumValue(%s).release()' % var
353 elif self._IsArrayOrArrayRef(prop): 353 elif self._IsArrayOrArrayRef(prop):
354 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( 354 return '%s.release()' % self._util_cc_helper.CreateValueFromArray(
355 self._cpp_type_generator.GetReferencedProperty(prop), var, 355 self._cpp_type_generator.GetReferencedProperty(prop), var,
356 prop.optional) 356 prop.optional)
357 elif prop.type_.is_fundamental: 357 elif self._IsFundamentalOrFundamentalRef(prop):
358 if prop.optional: 358 if prop.optional:
359 var = '*' + var 359 var = '*' + var
360 return { 360 return {
361 PropertyType.STRING: 'Value::CreateStringValue(%s)', 361 PropertyType.STRING: 'Value::CreateStringValue(%s)',
362 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', 362 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)',
363 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', 363 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)',
364 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', 364 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)',
365 }[prop.type_] % var 365 }[prop.type_] % var
366 else: 366 else:
367 raise NotImplementedError('Conversion of %s to Value not ' 367 raise NotImplementedError('Conversion of %s to Value not '
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 """ 454 """
455 c = Code() 455 c = Code()
456 c.Sblock('{') 456 c.Sblock('{')
457 457
458 if check_type and prop.type_ not in ( 458 if check_type and prop.type_ not in (
459 PropertyType.CHOICES, PropertyType.ANY): 459 PropertyType.CHOICES, PropertyType.ANY):
460 (c.Append('if (!%(value_var)s->IsType(%(value_type)s))') 460 (c.Append('if (!%(value_var)s->IsType(%(value_type)s))')
461 .Append(' return %(failure_value)s;') 461 .Append(' return %(failure_value)s;')
462 ) 462 )
463 463
464 if prop.type_.is_fundamental: 464 if self._IsFundamentalOrFundamentalRef(prop):
465 if prop.optional: 465 if prop.optional:
466 (c.Append('%(ctype)s temp;') 466 (c.Append('%(ctype)s temp;')
467 .Append('if (%s)' % 467 .Append('if (%s)' %
468 cpp_util.GetAsFundamentalValue(prop, value_var, '&temp')) 468 cpp_util.GetAsFundamentalValue(
469 self._cpp_type_generator.GetReferencedProperty(prop),
470 value_var,
471 '&temp'))
469 .Append(' %(dst)s->%(name)s.reset(new %(ctype)s(temp));') 472 .Append(' %(dst)s->%(name)s.reset(new %(ctype)s(temp));')
470 ) 473 )
471 else: 474 else:
472 (c.Append('if (!%s)' % 475 (c.Append('if (!%s)' %
473 cpp_util.GetAsFundamentalValue( 476 cpp_util.GetAsFundamentalValue(
474 prop, value_var, '&%s->%s' % (dst, prop.unix_name))) 477 self._cpp_type_generator.GetReferencedProperty(prop),
478 value_var,
479 '&%s->%s' % (dst, prop.unix_name)))
475 .Append('return %(failure_value)s;') 480 .Append('return %(failure_value)s;')
476 ) 481 )
477 elif self._IsObjectOrObjectRef(prop): 482 elif self._IsObjectOrObjectRef(prop):
478 if prop.optional: 483 if prop.optional:
479 (c.Append('DictionaryValue* dictionary = NULL;') 484 (c.Append('DictionaryValue* dictionary = NULL;')
480 .Append('if (!%(value_var)s->GetAsDictionary(&dictionary))') 485 .Append('if (!%(value_var)s->GetAsDictionary(&dictionary))')
481 .Append(' return %(failure_value)s;') 486 .Append(' return %(failure_value)s;')
482 .Append('scoped_ptr<%(ctype)s> temp(new %(ctype)s());') 487 .Append('scoped_ptr<%(ctype)s> temp(new %(ctype)s());')
483 .Append('if (!%(ctype)s::Populate(*dictionary, temp.get()))') 488 .Append('if (!%(ctype)s::Populate(*dictionary, temp.get()))')
484 .Append(' return %(failure_value)s;') 489 .Append(' return %(failure_value)s;')
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 """Determines if this property is an Object or is a ref to an Object. 655 """Determines if this property is an Object or is a ref to an Object.
651 """ 656 """
652 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == 657 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ ==
653 PropertyType.OBJECT) 658 PropertyType.OBJECT)
654 659
655 def _IsArrayOrArrayRef(self, prop): 660 def _IsArrayOrArrayRef(self, prop):
656 """Determines if this property is an Array or is a ref to an Array. 661 """Determines if this property is an Array or is a ref to an Array.
657 """ 662 """
658 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == 663 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ ==
659 PropertyType.ARRAY) 664 PropertyType.ARRAY)
665
666 def _IsFundamentalOrFundamentalRef(self, prop):
667 """Determines if this property is a Fundamental type or is a ref to a
668 Fundamental type.
669 """
670 return (self._cpp_type_generator.GetReferencedProperty(prop).type_.
671 is_fundamental)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/experimental.fontSettings.html ('k') | tools/json_schema_compiler/compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698