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

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

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 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
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 """Utilies and constants specific to Chromium C++ code. 5 """Utilies and constants specific to Chromium C++ code.
6 """ 6 """
7 7
8 from code import Code 8 from code import Code
9 from datetime import datetime 9 from datetime import datetime
10 from model import PropertyType 10 from model import PropertyType
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 PropertyType.DOUBLE: '%s->GetAsDouble(%s)', 53 PropertyType.DOUBLE: '%s->GetAsDouble(%s)',
54 PropertyType.INTEGER: '%s->GetAsInteger(%s)', 54 PropertyType.INTEGER: '%s->GetAsInteger(%s)',
55 PropertyType.STRING: '%s->GetAsString(%s)', 55 PropertyType.STRING: '%s->GetAsString(%s)',
56 }[type_.property_type] % (src, dst) 56 }[type_.property_type] % (src, dst)
57 57
58 58
59 def GetValueType(type_): 59 def GetValueType(type_):
60 """Returns the Value::Type corresponding to the model.Type. 60 """Returns the Value::Type corresponding to the model.Type.
61 """ 61 """
62 return { 62 return {
63 PropertyType.ARRAY: 'base::Value::TYPE_LIST', 63 PropertyType.ARRAY: 'base::Value::Type::LIST',
64 PropertyType.BINARY: 'base::Value::TYPE_BINARY', 64 PropertyType.BINARY: 'base::Value::Type::BINARY',
65 PropertyType.BOOLEAN: 'base::Value::TYPE_BOOLEAN', 65 PropertyType.BOOLEAN: 'base::Value::Type::BOOLEAN',
66 # PropertyType.CHOICES can be any combination of types. 66 # PropertyType.CHOICES can be any combination of types.
67 PropertyType.DOUBLE: 'base::Value::TYPE_DOUBLE', 67 PropertyType.DOUBLE: 'base::Value::Type::DOUBLE',
68 PropertyType.ENUM: 'base::Value::TYPE_STRING', 68 PropertyType.ENUM: 'base::Value::Type::STRING',
69 PropertyType.FUNCTION: 'base::Value::TYPE_DICTIONARY', 69 PropertyType.FUNCTION: 'base::Value::Type::DICTIONARY',
70 PropertyType.INTEGER: 'base::Value::TYPE_INTEGER', 70 PropertyType.INTEGER: 'base::Value::Type::INTEGER',
71 PropertyType.OBJECT: 'base::Value::TYPE_DICTIONARY', 71 PropertyType.OBJECT: 'base::Value::Type::DICTIONARY',
72 PropertyType.STRING: 'base::Value::TYPE_STRING', 72 PropertyType.STRING: 'base::Value::Type::STRING',
73 }[type_.property_type] 73 }[type_.property_type]
74 74
75 75
76 def GetParameterDeclaration(param, type_): 76 def GetParameterDeclaration(param, type_):
77 """Gets a parameter declaration of a given model.Property and its C++ 77 """Gets a parameter declaration of a given model.Property and its C++
78 type. 78 type.
79 """ 79 """
80 if param.type_.property_type in (PropertyType.ANY, 80 if param.type_.property_type in (PropertyType.ANY,
81 PropertyType.ARRAY, 81 PropertyType.ARRAY,
82 PropertyType.BINARY, 82 PropertyType.BINARY,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 has been passed as a flag to compiler.py from GYP/GN. 152 has been passed as a flag to compiler.py from GYP/GN.
153 ''' 153 '''
154 # For some reason Windows builds escape the % characters, so unescape them. 154 # For some reason Windows builds escape the % characters, so unescape them.
155 # This means that %% can never appear legitimately within a pattern, but 155 # This means that %% can never appear legitimately within a pattern, but
156 # that's ok. It should never happen. 156 # that's ok. It should never happen.
157 cpp_namespace = pattern.replace('%%', '%') % { 'namespace': namespace } 157 cpp_namespace = pattern.replace('%%', '%') % { 'namespace': namespace }
158 assert '%' not in cpp_namespace, \ 158 assert '%' not in cpp_namespace, \
159 ('Did not manage to fully substitute namespace "%s" into pattern "%s"' 159 ('Did not manage to fully substitute namespace "%s" into pattern "%s"'
160 % (namespace, pattern)) 160 % (namespace, pattern))
161 return cpp_namespace 161 return cpp_namespace
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/test/idl_schemas_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698