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 96a5cd36144a3beb2521e7dbbfd6497843a65a08..9ce14ca9d835b61783b5ec1267b8165d69b139a0 100644 |
--- a/tools/json_schema_compiler/cpp_util.py |
+++ b/tools/json_schema_compiler/cpp_util.py |
@@ -1,11 +1,12 @@ |
# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+ |
"""Utilies and constants specific to Chromium C++ code. |
""" |
from datetime import datetime |
-from model import PropertyType |
+from model import Property, PropertyType, Type |
import os |
CHROMIUM_LICENSE = ( |
@@ -31,7 +32,7 @@ def Classname(s): |
""" |
return '_'.join([x[0].upper() + x[1:] for x in s.split('.')]) |
-def GetAsFundamentalValue(prop, src, dst): |
+def GetAsFundamentalValue(type_, src, dst): |
"""Returns the C++ code for retrieving a fundamental type from a |
Value into a variable. |
@@ -43,7 +44,7 @@ def GetAsFundamentalValue(prop, src, dst): |
PropertyType.BOOLEAN: '%s->GetAsBoolean(%s)', |
PropertyType.INTEGER: '%s->GetAsInteger(%s)', |
PropertyType.DOUBLE: '%s->GetAsDouble(%s)', |
- }[prop.type_] % (src, dst) |
+ }[type_.property_type] % (src, dst) |
def GetValueType(type_): |
"""Returns the Value::Type corresponding to the model.PropertyType. |
@@ -58,15 +59,18 @@ def GetValueType(type_): |
PropertyType.FUNCTION: 'Value::TYPE_DICTIONARY', |
PropertyType.ARRAY: 'Value::TYPE_LIST', |
PropertyType.BINARY: 'Value::TYPE_BINARY', |
- }[type_] |
+ }[type_.property_type] |
def GetParameterDeclaration(param, type_): |
"""Gets a parameter declaration of a given model.Property and its C++ |
type. |
""" |
- if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, |
- PropertyType.STRING, PropertyType.ANY): |
- arg = '%(type)s& %(name)s' |
+ if param.type_.property_type in (PropertyType.REF, |
+ PropertyType.OBJECT, |
+ PropertyType.ARRAY, |
+ PropertyType.STRING, |
+ PropertyType.ANY): |
+ arg = 'const %(type)s& %(name)s' |
else: |
arg = '%(type)s %(name)s' |
return arg % { |
@@ -82,40 +86,8 @@ def GenerateIfndefName(path, filename): |
return (('%s_%s_H__' % (path, filename)) |
.upper().replace(os.sep, '_').replace('/', '_')) |
-def GenerateTypeToCompiledTypeConversion(prop, from_, to): |
- try: |
- return _GenerateTypeConversionHelper(prop.type_, prop.compiled_type, from_, |
- to) |
- except KeyError: |
- raise NotImplementedError('Conversion from %s to %s in %s not supported' % |
- (prop.type_, prop.compiled_type, prop.name)) |
- |
-def GenerateCompiledTypeToTypeConversion(prop, from_, to): |
- try: |
- return _GenerateTypeConversionHelper(prop.compiled_type, prop.type_, from_, |
- to) |
- except KeyError: |
- raise NotImplementedError('Conversion from %s to %s in %s not supported' % |
- (prop.compiled_type, prop.type_, prop.name)) |
- |
-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. |
+def PadForGenerics(var): |
+ """Appends a space to |var| if it ends with a >, so that it can be compiled |
+ within generic types. |
""" |
- # TODO(mwrosen): Add support for more from/to combinations as necessary. |
- return { |
- PropertyType.STRING: { |
- PropertyType.INTEGER: 'base::StringToInt(%(from)s, &%(to)s)', |
- PropertyType.INT64: 'base::StringToInt64(%(from)s, &%(to)s)', |
- }, |
- PropertyType.INTEGER: { |
- PropertyType.STRING: '%(to)s = base::IntToString(%(from)s)', |
- }, |
- PropertyType.INT64: { |
- PropertyType.STRING: '%(to)s = base::Int64ToString(%(from)s)', |
- } |
- }[from_type][to_type] % {'from': from_, 'to': to} |
+ return ('%s ' % var) if var.endswith('>') else var |