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

Side by Side Diff: tools/json_schema_compiler/util_cc_helper.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 | « tools/json_schema_compiler/util.h ('k') | no next file » | 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 model import PropertyType 5 from model import PropertyType
6 6
7 7
8 _API_UTIL_NAMESPACE = 'json_schema_compiler::util' 8 _API_UTIL_NAMESPACE = 'json_schema_compiler::util'
9 9
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if optional: 48 if optional:
49 val = '%(namespace)s::PopulateOptionalArrayFromList(*%(src)s, &%(dst)s)' 49 val = '%(namespace)s::PopulateOptionalArrayFromList(*%(src)s, &%(dst)s)'
50 else: 50 else:
51 val = '%(namespace)s::PopulateArrayFromList(*%(src)s, &%(dst)s)' 51 val = '%(namespace)s::PopulateArrayFromList(*%(src)s, &%(dst)s)'
52 return val % { 52 return val % {
53 'namespace': _API_UTIL_NAMESPACE, 53 'namespace': _API_UTIL_NAMESPACE,
54 'src': src, 54 'src': src,
55 'dst': dst 55 'dst': dst
56 } 56 }
57 57
58 def CreateValueFromArray(self, cpp_namespace, type_, src, optional): 58 def CreateValueFromArray(self,
59 src,
60 optional=False,
61 is_enum=False,
62 enum_namespace=None):
59 """Generates code to create a scoped_pt<Value> from the array at src. 63 """Generates code to create a scoped_pt<Value> from the array at src.
60 64
61 |cpp_namespace| The namespace which contains |type_|. This is needed for 65 |enum_namespace| The namespace which contains |item_type|. This is needed
62 enum conversions, where the ToString method is on the containing 66 for enum conversions, where the ToString method is on the containing
63 namespace. 67 namespace.
64 |type_| The type of the values being converted. This is needed for enum 68 |item_type| The type of each array item of the values being converted.
65 conversions, to know whether to use the Enum form of conversion. 69 This is needed for enum conversions, to know whether to use the Enum
70 form of conversion.
66 |src| The variable to convert, either a vector or scoped_ptr<vector>. 71 |src| The variable to convert, either a vector or scoped_ptr<vector>.
67 |optional| Whether |type_| was optional. Optional types are pointers so 72 |optional| Whether the whole array was optional. Optional types are
68 must be treated differently. 73 pointers so must be treated differently.
74 |is_enum| Whether the values are enums. Enums are treated specially because
75 they need their ToString() values called, not an integer.
76 |enum_namespace| The namespace of the enum being converted, if any.
77 The enum might not necessarily have a namespace.
69 """ 78 """
70 if type_.item_type.property_type == PropertyType.ENUM: 79 if is_enum:
71 # Enums are treated specially because C++ templating thinks that they're 80 # Enums are treated specially because C++ templating thinks that they're
72 # ints, but really they're strings. 81 # ints, but really they're strings.
73 if optional: 82 if optional:
74 name = 'CreateValueFromOptionalEnumArray<%s>' % cpp_namespace 83 name = 'CreateValueFromOptionalEnumArray'
75 else: 84 else:
76 name = 'CreateValueFromEnumArray<%s>' % cpp_namespace 85 name = 'CreateValueFromEnumArray'
86 if enum_namespace:
87 name += '<%s>' % enum_namespace
88 else:
89 name += 'WithoutNamespace'
77 else: 90 else:
78 if optional: 91 if optional:
79 name = 'CreateValueFromOptionalArray' 92 name = 'CreateValueFromOptionalArray'
80 else: 93 else:
81 name = 'CreateValueFromArray' 94 name = 'CreateValueFromArray'
82 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src) 95 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src)
83 96
84 def GetIncludePath(self): 97 def GetIncludePath(self):
85 return '#include "tools/json_schema_compiler/util.h"' 98 return '#include "tools/json_schema_compiler/util.h"'
86 99
87 def GetValueTypeString(self, value, is_ptr=False): 100 def GetValueTypeString(self, value, is_ptr=False):
88 call = '.GetType()' 101 call = '.GetType()'
89 if is_ptr: 102 if is_ptr:
90 call = '->GetType()' 103 call = '->GetType()'
91 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call) 104 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call)
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698