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

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

Issue 10825029: Added JSON schema compiler support for serialized types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 """Utilies and constants specific to Chromium C++ code. 4 """Utilies and constants specific to Chromium C++ code.
5 """ 5 """
6 6
7 from datetime import datetime 7 from datetime import datetime
8 from model import PropertyType 8 from model import PropertyType
9 import os 9 import os
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 PropertyType.STRING): 67 PropertyType.STRING):
68 arg = '%(type)s& %(name)s' 68 arg = '%(type)s& %(name)s'
69 else: 69 else:
70 arg = '%(type)s %(name)s' 70 arg = '%(type)s %(name)s'
71 return arg % { 71 return arg % {
72 'type': type_, 72 'type': type_,
73 'name': param.unix_name, 73 'name': param.unix_name,
74 } 74 }
75 75
76 def GenerateIfndefName(path, filename): 76 def GenerateIfndefName(path, filename):
77 """Formats a path and filename as a #define name. 77 """Formats a path and filename as a #define name.
78 78
79 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__. 79 e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__.
80 """ 80 """
81 return (('%s_%s_H__' % (path, filename)) 81 return (('%s_%s_H__' % (path, filename))
82 .upper().replace(os.sep, '_').replace('/', '_')) 82 .upper().replace(os.sep, '_').replace('/', '_'))
83
84 def DoConversion(prop, from_, to):
85 """Converts from prop.type_ to prop.serialized_type.
not at google - send to devlin 2012/07/26 04:51:42 erm maybe a less ambiguous name, like GenerateType
mitchellwrosen 2012/07/26 20:00:27 Done.
86 """
87 # TODO(mwrosen): Add support for more from/to combinations as necessary.
88 return {
89 PropertyType.STRING: {
90 PropertyType.INTEGER: 'base::StringToInt(%s, %s)',
91 PropertyType.INT64: 'base::StringToInt64(%s, %s)'
92 }[prop.serialized_type] % (from_, to)
93 }[prop.type_]
not at google - send to devlin 2012/07/26 04:51:42 here and above, what happens if the types aren't s
mitchellwrosen 2012/07/26 20:00:27 It'll return a KeyError. Should I catch that and r
not at google - send to devlin 2012/07/27 04:14:28 Yeah, would be nice to include in the exception wh
mitchellwrosen 2012/07/30 20:52:45 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698