| Index: tools/json_schema_compiler/cpp_type_generator.py
|
| diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
|
| index 5afc91504e6ec22aaccb6ea41929a082e547da87..1d3ac303a327f42f9c379d7373b67ec1f47b6125 100644
|
| --- a/tools/json_schema_compiler/cpp_type_generator.py
|
| +++ b/tools/json_schema_compiler/cpp_type_generator.py
|
| @@ -6,6 +6,8 @@ from code import Code
|
| from model import PropertyType
|
| import any_helper
|
| import cpp_util
|
| +import schema_util
|
| +import string
|
|
|
| class CppTypeGenerator(object):
|
| """Manages the types of properties and provides utilities for getting the
|
| @@ -28,12 +30,10 @@ class CppTypeGenerator(object):
|
| beneath the root namespace.
|
| """
|
| for type_ in namespace.types:
|
| - qualified_name = self._QualifyName(namespace, type_)
|
| - if qualified_name in self._type_namespaces:
|
| + if type_ in self._type_namespaces:
|
| raise ValueError('Type %s is declared in both %s and %s' %
|
| - (qualified_name, namespace.name,
|
| - self._type_namespaces[qualified_name].name))
|
| - self._type_namespaces[qualified_name] = namespace
|
| + (type_, namespace.name, self._type_namespaces[type_].name))
|
| + self._type_namespaces[type_] = namespace
|
| self._cpp_namespaces[namespace] = cpp_namespace
|
|
|
| def GetExpandedChoicesInParams(self, params):
|
| @@ -125,9 +125,9 @@ class CppTypeGenerator(object):
|
| raise KeyError('Cannot find referenced type: %s' % prop.ref_type)
|
| if self._namespace != dependency_namespace:
|
| cpp_type = '%s::%s' % (self._cpp_namespaces[dependency_namespace],
|
| - prop.ref_type)
|
| + schema_util.StripSchemaNamespace(prop.ref_type))
|
| else:
|
| - cpp_type = prop.ref_type
|
| + cpp_type = schema_util.StripSchemaNamespace(prop.ref_type)
|
| elif prop.type_ == PropertyType.BOOLEAN:
|
| cpp_type = 'bool'
|
| elif prop.type_ == PropertyType.INTEGER:
|
| @@ -175,20 +175,21 @@ class CppTypeGenerator(object):
|
| for namespace, types in sorted(self._NamespaceTypeDependencies().items()):
|
| c.Append('namespace %s {' % namespace.name)
|
| for type_ in types:
|
| + type_name = schema_util.StripSchemaNamespace(type_)
|
| if namespace.types[type_].type_ == PropertyType.STRING:
|
| - c.Append('typedef std::string %s;' % type_)
|
| + c.Append('typedef std::string %s;' % type_name)
|
| elif namespace.types[type_].type_ == PropertyType.ARRAY:
|
| c.Append('typedef std::vector<%(item_type)s> %(name)s;')
|
| - c.Substitute({'name': type_, 'item_type':
|
| + c.Substitute({'name': type_name, 'item_type':
|
| self.GetType(namespace.types[type_].item_type,
|
| wrap_optional=True)})
|
| else:
|
| - c.Append('struct %s;' % type_)
|
| + c.Append('struct %s;' % type_name)
|
| c.Append('}')
|
| c.Concat(self.GetNamespaceStart())
|
| for (name, type_) in self._namespace.types.items():
|
| if not type_.functions and type_.type_ == PropertyType.OBJECT:
|
| - c.Append('struct %s;' % name)
|
| + c.Append('struct %s;' % schema_util.StripSchemaNamespace(name))
|
| c.Concat(self.GetNamespaceEnd())
|
| return c
|
|
|
| @@ -203,23 +204,13 @@ class CppTypeGenerator(object):
|
| return c
|
|
|
| def _ResolveTypeNamespace(self, ref_type):
|
| - """Resolves a type name to its enclosing namespace.
|
| -
|
| - Searches for the ref_type first as an explicitly qualified name, then within
|
| - the enclosing namespace, then within other namespaces that the current
|
| - namespace depends upon.
|
| + """Resolves a type, which must be explicitly qualified, to its enclosing
|
| + namespace.
|
| """
|
| if ref_type in self._type_namespaces:
|
| return self._type_namespaces[ref_type]
|
| -
|
| - qualified_name = self._QualifyName(self._namespace, ref_type)
|
| - if qualified_name in self._type_namespaces:
|
| - return self._type_namespaces[qualified_name]
|
| -
|
| - for (type_name, namespace) in self._type_namespaces.items():
|
| - if type_name == self._QualifyName(namespace, ref_type):
|
| - return namespace
|
| -
|
| + raise KeyError(('Cannot resolve type: %s.' % ref_type) +
|
| + 'Maybe it needs a namespace prefix if it comes from another namespace?')
|
| return None
|
|
|
| def GetReferencedProperty(self, prop):
|
| @@ -233,9 +224,6 @@ class CppTypeGenerator(object):
|
| return self._ResolveTypeNamespace(prop.ref_type).types.get(prop.ref_type,
|
| None)
|
|
|
| - def _QualifyName(self, namespace, name):
|
| - return '.'.join([namespace.name, name])
|
| -
|
| def _NamespaceTypeDependencies(self):
|
| """Returns a dict containing a mapping of model.Namespace to the C++ type
|
| of type dependencies for self._namespace.
|
|
|