| Index: tools/json_schema_compiler/h_generator.py
|
| diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
|
| index 619763b8b1676dbc8a97159ac72ad6c1c631f1cc..bc74aa7d07e48d02bde95f4ab59499b34ed9f9d4 100644
|
| --- a/tools/json_schema_compiler/h_generator.py
|
| +++ b/tools/json_schema_compiler/h_generator.py
|
| @@ -5,7 +5,6 @@
|
| from model import PropertyType
|
| import code
|
| import cpp_util
|
| -import os
|
|
|
| class HGenerator(object):
|
| """A .h generator for a namespace.
|
| @@ -35,6 +34,7 @@ class HGenerator(object):
|
| .Append('#include <vector>')
|
| .Append()
|
| .Append('#include "base/basictypes.h"')
|
| + .Append('#include "base/memory/linked_ptr.h"')
|
| .Append('#include "base/memory/scoped_ptr.h"')
|
| .Append('#include "base/values.h"')
|
| .Append()
|
| @@ -44,13 +44,15 @@ class HGenerator(object):
|
| .Append()
|
| )
|
|
|
| - includes = self._cpp_type_generator.GenerateCppIncludes()
|
| - if not includes.IsEmpty():
|
| - (c.Concat(includes)
|
| + c.Concat(self._cpp_type_generator.GetRootNamespaceStart())
|
| + forward_declarations = self._cpp_type_generator.GenerateForwardDeclarations();
|
| + if not forward_declarations.IsEmpty():
|
| + (c.Append()
|
| + .Concat(forward_declarations)
|
| .Append()
|
| )
|
|
|
| - (c.Concat(self._cpp_type_generator.GetCppNamespaceStart())
|
| + (c.Concat(self._cpp_type_generator.GetNamespaceStart())
|
| .Append()
|
| .Append('//')
|
| .Append('// Types')
|
| @@ -71,8 +73,8 @@ class HGenerator(object):
|
| .Append()
|
| )
|
| (c.Append()
|
| - .Append()
|
| - .Concat(self._cpp_type_generator.GetCppNamespaceEnd())
|
| + .Concat(self._cpp_type_generator.GetNamespaceEnd())
|
| + .Concat(self._cpp_type_generator.GetRootNamespaceEnd())
|
| .Append()
|
| .Append('#endif // %s' % ifndef_name)
|
| .Append()
|
| @@ -82,7 +84,7 @@ class HGenerator(object):
|
| def _GenerateType(self, type_, serializable=True):
|
| """Generates a struct for a type.
|
| """
|
| - classname = cpp_util.CppName(type_.name)
|
| + classname = cpp_util.Classname(type_.name)
|
| c = code.Code()
|
| if type_.description:
|
| c.Comment(type_.description)
|
| @@ -95,13 +97,8 @@ class HGenerator(object):
|
| for prop in type_.properties.values():
|
| if prop.description:
|
| c.Comment(prop.description)
|
| - if prop.optional:
|
| - c.Append('scoped_ptr<%s> %s;' %
|
| - (self._cpp_type_generator.GetType(prop, pad_for_generics=True),
|
| - prop.name))
|
| - else:
|
| - c.Append('%s %s;' %
|
| - (self._cpp_type_generator.GetType(prop), prop.name))
|
| + c.Append('%s %s;' %
|
| + (self._cpp_type_generator.GetType(prop, wrap_optional=True), prop.unix_name))
|
| c.Append()
|
|
|
| (c.Comment('Populates a %(classname)s object from a Value. Returns'
|
| @@ -128,7 +125,7 @@ class HGenerator(object):
|
| """Generates the structs for a function.
|
| """
|
| c = code.Code()
|
| - (c.Sblock('namespace %s {' % cpp_util.CppName(function.name))
|
| + (c.Sblock('namespace %s {' % cpp_util.Classname(function.name))
|
| .Concat(self._GenerateFunctionParams(function))
|
| .Append()
|
| .Concat(self._GenerateFunctionResult(function))
|
| @@ -152,7 +149,7 @@ class HGenerator(object):
|
| c.Append()
|
| for param in function.params:
|
| c.Append('%s %s;' %
|
| - (self._cpp_type_generator.GetType(param), param.name))
|
| + (self._cpp_type_generator.GetType(param, wrap_optional=True), param.unix_name))
|
|
|
| (c.Append()
|
| .Append('~Params();')
|
| @@ -163,42 +160,40 @@ class HGenerator(object):
|
| .Append('Params();')
|
| .Append()
|
| .Append('DISALLOW_COPY_AND_ASSIGN(Params);')
|
| + .Eblock('};')
|
| )
|
|
|
| - c.Eblock('};')
|
| -
|
| return c
|
|
|
| def _GenerateFunctionResult(self, function):
|
| """Generates the struct for passing a function's result back.
|
| """
|
| - # TODO(calamity): Handle returning an object
|
| c = code.Code()
|
|
|
| - param = function.callback.param
|
| - # TODO(calamity): Put this description comment in less stupid place
|
| - if param.description:
|
| - c.Comment(param.description)
|
| (c.Append('class Result {')
|
| .Sblock(' public:')
|
| )
|
| - arg = ''
|
| - # TODO(calamity): handle object
|
| - if param:
|
| - if param.type_ == PropertyType.REF:
|
| - arg = 'const %(type)s& %(name)s'
|
| - else:
|
| - arg = 'const %(type)s %(name)s'
|
| - arg = arg % {
|
| + params = function.callback.params
|
| + if not params:
|
| + c.Append('static Value* Create();')
|
| + else:
|
| + for param in params:
|
| + sub = {
|
| 'type': self._cpp_type_generator.GetType(param),
|
| - 'name': param.name
|
| - }
|
| - (c.Append('static Value* Create(%s);' % arg)
|
| - .Eblock()
|
| - .Sblock(' private:')
|
| - .Append('Result() {};')
|
| - .Append('DISALLOW_COPY_AND_ASSIGN(Result);')
|
| - .Eblock('};')
|
| + 'name': param.unix_name,
|
| + }
|
| + arg = 'const %(type)s %(name)s'
|
| + if param.type_ == PropertyType.REF:
|
| + arg = 'const %(type)s& %(name)s'
|
| + arg = arg % sub
|
| + if param.description:
|
| + c.Comment(param.description)
|
| + c.Append('static Value* Create(%s);' % arg)
|
| + (c.Eblock()
|
| + .Sblock(' private:')
|
| + .Append('Result() {};')
|
| + .Append('DISALLOW_COPY_AND_ASSIGN(Result);')
|
| + .Eblock('};')
|
| )
|
|
|
| return c
|
| @@ -208,7 +203,7 @@ class HGenerator(object):
|
|
|
| e.g chrome/extensions/gen, file.h becomes CHROME_EXTENSIONS_GEN_FILE_H__.
|
| """
|
| - return (('%s_%s_H__' %
|
| + return (('%s/%s_H__' %
|
| (self._namespace.source_file_dir, self._target_namespace))
|
| - .upper().replace(os.sep, '_'))
|
| + .upper().replace('/', '_'))
|
|
|
|
|