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

Unified 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: Indent typo fix Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/cpp_util.py
diff --git a/tools/json_schema_compiler/cpp_util.py b/tools/json_schema_compiler/cpp_util.py
index 1229fb8597654e10b785f2b9836a00ccc15fbd32..771bdd877beb7b947e6b0601efb2a18109e25902 100644
--- a/tools/json_schema_compiler/cpp_util.py
+++ b/tools/json_schema_compiler/cpp_util.py
@@ -75,9 +75,42 @@ def GetParameterDeclaration(param, type_):
}
def GenerateIfndefName(path, filename):
- """Formats a path and filename as a #define name.
+ """Formats a path and filename as a #define name.
- e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__.
- """
- return (('%s_%s_H__' % (path, filename))
- .upper().replace(os.sep, '_').replace('/', '_'))
+ e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__.
+ """
+ return (('%s_%s_H__' % (path, filename))
+ .upper().replace(os.sep, '_').replace('/', '_'))
+
+def GenerateTypeToCompiledTypeConversion(prop, from_, to):
+ return _GenerateTypeConversionHelper(prop.type_, prop.compiled_type, from_,
+ to)
+
+def GenerateCompiledTypeToTypeConversion(prop, from_, to):
+ return _GenerateTypeConversionHelper(prop.compiled_type, prop.type_, from_,
+ to)
+
+def _GenerateTypeConversionHelper(from_type, to_type, from_, to):
+ """Converts from PropertyType from_type to PropertyType to_type.
+
+ from_type: The PropertyType to be converted from.
+ to_type: The PropertyType to be converted to.
+ from_: The variable name of the type to be converted from.
+ to: The variable name of the type to be converted to.
+ """
+ # TODO(mwrosen): Add support for more from/to combinations as necessary.
+ try:
+ return {
+ PropertyType.STRING: {
+ PropertyType.INTEGER: 'base::StringToInt(%(from)s, &%(to)s)',
+ PropertyType.INT_64: 'base::StringToInt64(%(from)s, &%(to)s)'
+ },
+ PropertyType.INTEGER: {
+ PropertyType.STRING: '%(to)s = base::IntToString(%(from)s)'
+ },
+ PropertyType.INT_64: {
+ PropertyType.STRING: '%(to)s = base::Int64ToString(%(from)s)'
+ }
+ }[from_type][to_type] % {'from': from_, 'to': to}
+ except KeyError:
+ raise NotImplementedError()
not at google - send to devlin 2012/07/31 06:37:41 Exception message? "Conversion from blah to blah i
mitchellwrosen 2012/07/31 17:50:25 Right, meant to go back and put that in. I had to

Powered by Google App Engine
This is Rietveld 408576698