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

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

Issue 10198005: Implement handling of binary data in JSON schema compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 8 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 | « no previous file | tools/json_schema_compiler/cpp_type_generator.py » ('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 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 26 matching lines...) Expand all
37 includes = self._cpp_type_generator.GenerateIncludes() 37 includes = self._cpp_type_generator.GenerateIncludes()
38 if not includes.IsEmpty(): 38 if not includes.IsEmpty():
39 (c.Concat(includes) 39 (c.Concat(includes)
40 .Append() 40 .Append()
41 ) 41 )
42 42
43 (c.Append() 43 (c.Append()
44 .Append('using base::Value;') 44 .Append('using base::Value;')
45 .Append('using base::DictionaryValue;') 45 .Append('using base::DictionaryValue;')
46 .Append('using base::ListValue;') 46 .Append('using base::ListValue;')
47 .Append('using base::BinaryValue;')
47 .Append('using %s;' % any_helper.ANY_CLASS) 48 .Append('using %s;' % any_helper.ANY_CLASS)
48 .Append() 49 .Append()
49 .Concat(self._cpp_type_generator.GetRootNamespaceStart()) 50 .Concat(self._cpp_type_generator.GetRootNamespaceStart())
50 .Concat(self._cpp_type_generator.GetNamespaceStart()) 51 .Concat(self._cpp_type_generator.GetNamespaceStart())
51 .Append() 52 .Append()
52 ) 53 )
53 if self._namespace.properties: 54 if self._namespace.properties:
54 (c.Append('//') 55 (c.Append('//')
55 .Append('// Properties') 56 .Append('// Properties')
56 .Append('//') 57 .Append('//')
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if prop.optional: 138 if prop.optional:
138 continue 139 continue
139 140
140 t = prop.type_ 141 t = prop.type_
141 if t == PropertyType.INTEGER: 142 if t == PropertyType.INTEGER:
142 items.append('%s(0)' % prop.unix_name) 143 items.append('%s(0)' % prop.unix_name)
143 elif t == PropertyType.DOUBLE: 144 elif t == PropertyType.DOUBLE:
144 items.append('%s(0.0)' % prop.unix_name) 145 items.append('%s(0.0)' % prop.unix_name)
145 elif t == PropertyType.BOOLEAN: 146 elif t == PropertyType.BOOLEAN:
146 items.append('%s(false)' % prop.unix_name) 147 items.append('%s(false)' % prop.unix_name)
148 elif t == PropertyType.BINARY:
149 items.append('%s(NULL)' % prop.unix_name)
147 elif (t == PropertyType.ADDITIONAL_PROPERTIES or 150 elif (t == PropertyType.ADDITIONAL_PROPERTIES or
148 t == PropertyType.ANY or 151 t == PropertyType.ANY or
149 t == PropertyType.ARRAY or 152 t == PropertyType.ARRAY or
150 t == PropertyType.CHOICES or 153 t == PropertyType.CHOICES or
151 t == PropertyType.ENUM or 154 t == PropertyType.ENUM or
152 t == PropertyType.OBJECT or 155 t == PropertyType.OBJECT or
153 t == PropertyType.REF or 156 t == PropertyType.REF or
154 t == PropertyType.STRING): 157 t == PropertyType.STRING):
155 # TODO(miket): It would be nice to initialize CHOICES and ENUM, but we 158 # TODO(miket): It would be nice to initialize CHOICES and ENUM, but we
156 # don't presently have the semantics to indicate which one of a set 159 # don't presently have the semantics to indicate which one of a set
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 ('if' if i == 0 else 'else if') + 533 ('if' if i == 0 else 'else if') +
531 '(enum_temp == "%s")' % enum_value) 534 '(enum_temp == "%s")' % enum_value)
532 .Append(' %s->%s = %s;' % ( 535 .Append(' %s->%s = %s;' % (
533 dst, 536 dst,
534 prop.unix_name, 537 prop.unix_name,
535 self._cpp_type_generator.GetEnumValue(prop, enum_value))) 538 self._cpp_type_generator.GetEnumValue(prop, enum_value)))
536 ) 539 )
537 (c.Append('else') 540 (c.Append('else')
538 .Append(' return %(failure_value)s;') 541 .Append(' return %(failure_value)s;')
539 ) 542 )
543 elif prop.type_ == PropertyType.BINARY:
544 # This is the same if the property is optional or not. We need a pointer
545 # to the BinaryValue to be able to populate it, so a scoped_ptr is used
546 # whether it is optional or required.
547 (c.Append('%(dst)s->%(name)s.reset(')
548 .Append(' static_cast<BinaryValue*>(%(value_var)s)->DeepCopy());')
549 )
540 else: 550 else:
541 raise NotImplementedError(prop.type_) 551 raise NotImplementedError(prop.type_)
542 c.Eblock('}') 552 c.Eblock('}')
543 sub = { 553 sub = {
544 'value_var': value_var, 554 'value_var': value_var,
545 'name': prop.unix_name, 555 'name': prop.unix_name,
546 'dst': dst, 556 'dst': dst,
547 'failure_value': failure_value, 557 'failure_value': failure_value,
548 } 558 }
549 if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY): 559 if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY):
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 """Determines if this property is an Object or is a ref to an Object. 648 """Determines if this property is an Object or is a ref to an Object.
639 """ 649 """
640 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == 650 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ ==
641 PropertyType.OBJECT) 651 PropertyType.OBJECT)
642 652
643 def _IsArrayOrArrayRef(self, prop): 653 def _IsArrayOrArrayRef(self, prop):
644 """Determines if this property is an Array or is a ref to an Array. 654 """Determines if this property is an Array or is a ref to an Array.
645 """ 655 """
646 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == 656 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ ==
647 PropertyType.ARRAY) 657 PropertyType.ARRAY)
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/cpp_type_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698